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 * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.711 2010/02/23 22:51:42 tgl Exp $
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);
139 %name-prefix="base_yy"
142 %parse-param {core_yyscan_t yyscanner}
143 %lex-param {core_yyscan_t yyscanner}
147 core_YYSTYPE core_yystype;
148 /* these fields must match core_YYSTYPE: */
156 DropBehavior dbehavior;
157 OnCommitAction oncommit;
163 FunctionParameter *fun_param;
164 FunctionParameterMode fun_param_mode;
165 FuncWithArgs *funwithargs;
177 struct PrivTarget *privtarget;
178 AccessPriv *accesspriv;
180 VariableSetStmt *vsetstmt;
183 %type <node> stmt schema_stmt
184 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterFdwStmt
185 AlterForeignServerStmt AlterGroupStmt
186 AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterTableStmt
187 AlterUserStmt AlterUserMappingStmt AlterUserSetStmt
188 AlterRoleStmt AlterRoleSetStmt
189 AlterDefaultPrivilegesStmt DefACLAction
190 AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
191 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
192 CreateDomainStmt CreateGroupStmt CreateOpClassStmt
193 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
194 CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
195 CreateFdwStmt CreateForeignServerStmt CreateAssertStmt CreateTrigStmt
196 CreateUserStmt CreateUserMappingStmt CreateRoleStmt
197 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
198 DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
199 DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
200 DropUserStmt DropdbStmt DropTableSpaceStmt DropFdwStmt
201 DropForeignServerStmt DropUserMappingStmt ExplainStmt FetchStmt
202 GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
203 LockStmt NotifyStmt ExplainableStmt PreparableStmt
204 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
205 RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
206 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
207 SelectStmt TransactionStmt TruncateStmt
208 UnlistenStmt UpdateStmt VacuumStmt
209 VariableResetStmt VariableSetStmt VariableShowStmt
210 ViewStmt CheckPointStmt CreateConversionStmt
211 DeallocateStmt PrepareStmt ExecuteStmt
212 DropOwnedStmt ReassignOwnedStmt
213 AlterTSConfigurationStmt AlterTSDictionaryStmt
215 %type <node> select_no_parens select_with_parens select_clause
216 simple_select values_clause
218 %type <node> alter_column_default opclass_item opclass_drop alter_using
219 %type <ival> add_drop opt_asc_desc opt_nulls_order
221 %type <node> alter_table_cmd
222 %type <list> alter_table_cmds
224 %type <dbehavior> opt_drop_behavior
226 %type <list> createdb_opt_list alterdb_opt_list copy_opt_list
227 transaction_mode_list
228 %type <defelt> createdb_opt_item alterdb_opt_item copy_opt_item
229 transaction_mode_item
231 %type <ival> opt_lock lock_type cast_context
232 %type <ival> vacuum_option_list vacuum_option_elem
233 %type <boolean> opt_force opt_or_replace
234 opt_grant_grant_option opt_grant_admin_option
235 opt_nowait opt_if_exists opt_with_data
237 %type <list> OptRoleList AlterOptRoleList
238 %type <defelt> CreateOptRoleElem AlterOptRoleElem
241 %type <str> foreign_server_version opt_foreign_server_version
242 %type <str> auth_ident
243 %type <str> opt_in_database
245 %type <str> OptSchemaName
246 %type <list> OptSchemaEltList
248 %type <boolean> TriggerActionTime TriggerForSpec opt_trusted opt_restart_seqs
250 %type <list> TriggerEvents TriggerOneEvent
251 %type <value> TriggerFuncArg
252 %type <node> TriggerWhen
254 %type <str> copy_file_name
255 database_name access_method_clause access_method attr_name
256 name cursor_name file_name
257 index_name opt_index_name cluster_index_specification
259 %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
260 opt_class opt_inline_handler opt_validator validator_clause
262 %type <range> qualified_name OptConstrFromTable
264 %type <str> all_Op MathOp
266 %type <str> iso_level opt_encoding
268 %type <list> grantee_list
269 %type <accesspriv> privilege
270 %type <list> privileges privilege_list
271 %type <privtarget> privilege_target
272 %type <funwithargs> function_with_argtypes
273 %type <list> function_with_argtypes_list
274 %type <ival> defacl_privilege_target
275 %type <defelt> DefACLOption
276 %type <list> DefACLOptionList
278 %type <list> stmtblock stmtmulti
279 OptTableElementList TableElementList OptInherit definition
280 OptTypedTableElementList TypedTableElementList
281 reloptions opt_reloptions
282 OptWith opt_distinct opt_definition func_args func_args_list
283 func_args_with_defaults func_args_with_defaults_list
284 func_as createfunc_opt_list alterfunc_opt_list
285 aggr_args old_aggr_definition old_aggr_list
286 oper_argtypes RuleActionList RuleActionMulti
287 opt_column_list columnList opt_name_list
288 sort_clause opt_sort_clause sortby_list index_params
289 name_list from_clause from_list opt_array_bounds
290 qualified_name_list any_name any_name_list
291 any_operator expr_list attrs
292 target_list insert_column_list set_target_list
293 set_clause_list set_clause multiple_set_clause
294 ctext_expr_list ctext_row def_list indirection opt_indirection
295 reloption_list group_clause TriggerFuncArgs select_limit
296 opt_select_limit opclass_item_list opclass_drop_list
297 opt_opfamily transaction_mode_list_or_empty
298 TableFuncElementList opt_type_modifiers
300 execute_param_clause using_clause returning_clause
301 opt_enum_val_list enum_val_list table_func_column_list
302 create_generic_options alter_generic_options
303 relation_expr_list dostmt_opt_list
305 %type <range> OptTempTableName
306 %type <into> into_clause create_as_target
308 %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
309 %type <fun_param> func_arg func_arg_with_default table_func_column
310 %type <fun_param_mode> arg_class
311 %type <typnam> func_return func_type
313 %type <boolean> TriggerForType OptTemp
314 %type <oncommit> OnCommitOption
316 %type <node> for_locking_item
317 %type <list> for_locking_clause opt_for_locking_clause for_locking_items
318 %type <list> locked_rels_list
319 %type <boolean> opt_all
321 %type <node> join_outer join_qual
322 %type <jtype> join_type
324 %type <list> extract_list overlay_list position_list
325 %type <list> substr_list trim_list
326 %type <list> opt_interval interval_second
327 %type <node> overlay_placing substr_from substr_for
329 %type <boolean> opt_instead
330 %type <boolean> opt_unique opt_concurrently opt_verbose opt_full
331 %type <boolean> opt_freeze opt_default opt_recheck
332 %type <defelt> opt_binary opt_oids copy_delimiter
334 %type <boolean> copy_from
336 %type <ival> opt_column event cursor_options opt_hold opt_set_data
337 %type <objtype> reindex_type drop_type comment_type
339 %type <node> fetch_args limit_clause select_limit_value
340 offset_clause select_offset_value
341 select_offset_value2 opt_select_fetch_first_value
342 %type <ival> row_or_rows first_or_next
344 %type <list> OptSeqOptList SeqOptList
345 %type <defelt> SeqOptElem
347 %type <istmt> insert_rest
349 %type <vsetstmt> set_rest SetResetClause
351 %type <node> TableElement TypedTableElement ConstraintElem TableFuncElement
352 %type <node> columnDef columnOptions
353 %type <defelt> def_elem reloption_elem old_aggr_elem
354 %type <node> def_arg columnElem where_clause where_or_current_clause
355 a_expr b_expr c_expr func_expr AexprConst indirection_el
356 columnref in_expr having_clause func_table array_expr
358 %type <list> ExclusionConstraintList ExclusionConstraintElem
359 %type <list> func_arg_list
360 %type <node> func_arg_expr
361 %type <list> row type_list array_expr_list
362 %type <node> case_expr case_arg when_clause case_default
363 %type <list> when_clause_list
364 %type <ival> sub_type
365 %type <list> OptCreateAs CreateAsList
366 %type <node> CreateAsElement ctext_expr
367 %type <value> NumericOnly
368 %type <alias> alias_clause
369 %type <sortby> sortby
370 %type <ielem> index_elem
371 %type <node> table_ref
372 %type <jexpr> joined_table
373 %type <range> relation_expr
374 %type <range> relation_expr_opt_alias
375 %type <target> target_el single_set_clause set_target insert_column_item
377 %type <str> generic_option_name
378 %type <node> generic_option_arg
379 %type <defelt> generic_option_elem alter_generic_option_elem
380 %type <list> generic_option_list alter_generic_option_list
381 %type <str> explain_option_name
382 %type <node> explain_option_arg
383 %type <defelt> explain_option_elem
384 %type <list> explain_option_list
385 %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
386 %type <defelt> copy_generic_opt_elem
387 %type <list> copy_generic_opt_list copy_generic_opt_arg_list
388 %type <list> copy_options
390 %type <typnam> Typename SimpleTypename ConstTypename
391 GenericType Numeric opt_float
392 Character ConstCharacter
393 CharacterWithLength CharacterWithoutLength
394 ConstDatetime ConstInterval
395 Bit ConstBit BitWithLength BitWithoutLength
396 %type <str> character
397 %type <str> extract_arg
398 %type <str> opt_charset
399 %type <boolean> opt_varying opt_timezone
401 %type <ival> Iconst SignedIconst
402 %type <list> Iconst_list
403 %type <str> Sconst comment_text notify_payload
404 %type <str> RoleId opt_granted_by opt_boolean ColId_or_Sconst
405 %type <list> var_list
406 %type <str> ColId ColLabel var_name type_function_name param_name
407 %type <node> var_value zone_value
409 %type <keyword> unreserved_keyword type_func_name_keyword
410 %type <keyword> col_name_keyword reserved_keyword
412 %type <node> TableConstraint TableLikeClause
413 %type <ival> TableLikeOptionList TableLikeOption
414 %type <list> ColQualList
415 %type <node> ColConstraint ColConstraintElem ConstraintAttr
416 %type <ival> key_actions key_delete key_match key_update key_action
417 %type <ival> ConstraintAttributeSpec ConstraintDeferrabilitySpec
420 %type <list> constraints_set_list
421 %type <boolean> constraints_set_mode
422 %type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
423 %type <list> opt_check_option
425 %type <target> xml_attribute_el
426 %type <list> xml_attribute_list xml_attributes
427 %type <node> xml_root_version opt_xml_root_standalone
428 %type <ival> document_or_content
429 %type <boolean> xml_whitespace_option
431 %type <node> common_table_expr
432 %type <with> with_clause
433 %type <list> cte_list
435 %type <list> window_clause window_definition_list opt_partition_clause
436 %type <windef> window_definition over_clause window_specification
437 opt_frame_clause frame_extent frame_bound
438 %type <str> opt_existing_window_name
442 * Non-keyword token types. These are hard-wired into the "flex" lexer.
443 * They must be listed first so that their numeric codes do not depend on
444 * the set of keywords. PL/pgsql depends on this so that it can share the
445 * same lexer. If you add/change tokens here, fix PL/pgsql to match!
447 * DOT_DOT and COLON_EQUALS are unused in the core SQL grammar, and so will
448 * always provoke parse errors. They are needed by PL/pgsql.
450 %token <str> IDENT FCONST SCONST BCONST XCONST Op
451 %token <ival> ICONST PARAM
452 %token TYPECAST DOT_DOT COLON_EQUALS
455 * If you want to make any keyword changes, update the keyword table in
456 * src/include/parser/kwlist.h and add new keywords to the appropriate one
457 * of the reserved-or-not-so-reserved keyword lists, below; search
458 * this file for "Keyword category lists".
461 /* ordinary key words in alphabetical order */
462 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
463 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
464 ASSERTION ASSIGNMENT ASYMMETRIC AT AUTHORIZATION
466 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
469 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
470 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
471 CLUSTER COALESCE COLLATE COLUMN COMMENT COMMENTS COMMIT
472 COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
473 CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
474 CREATEROLE CREATEUSER CROSS CSV CURRENT_P
475 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
476 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
478 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
479 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
480 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
482 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT
483 EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
485 FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOLLOWING FOR FORCE FOREIGN FORWARD
486 FREEZE FROM FULL FUNCTION FUNCTIONS
488 GLOBAL GRANT GRANTED GREATEST GROUP_P
490 HANDLER HAVING HEADER_P HOLD HOUR_P
492 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
493 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
494 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
495 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
501 LANGUAGE LARGE_P LAST_P LC_COLLATE_P LC_CTYPE_P LEADING
502 LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP
503 LOCATION LOCK_P LOGIN_P
505 MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
507 NAME_P NAMES NATIONAL NATURAL NCHAR NEXT NO NOCREATEDB
508 NOCREATEROLE NOCREATEUSER NOINHERIT NOLOGIN_P NONE NOSUPERUSER
509 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NULLS_P NUMERIC
511 OBJECT_P OF OFF OFFSET OIDS ON ONLY OPERATOR OPTION OPTIONS OR
512 ORDER OUT_P OUTER_P OVER OVERLAPS OVERLAY OWNED OWNER
514 PARSER PARTIAL PARTITION PASSWORD PLACING PLANS POSITION
515 PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
516 PRIOR PRIVILEGES PROCEDURAL PROCEDURE
520 RANGE READ REAL REASSIGN RECHECK RECURSIVE REFERENCES REINDEX
521 RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA RESET RESTART
522 RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROW ROWS RULE
524 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE SEQUENCES
525 SERIALIZABLE SERVER SESSION SESSION_USER SET SETOF SHARE
526 SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT
527 STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING SUPERUSER_P
528 SYMMETRIC SYSID SYSTEM_P
530 TABLE TABLES TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
531 TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
532 TRUNCATE TRUSTED TYPE_P
534 UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
537 VACUUM VALID VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
538 VERBOSE VERSION_P VIEW VOLATILE
540 WHEN WHERE WHITESPACE_P WINDOW WITH WITHOUT WORK WRAPPER WRITE
542 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLFOREST XMLPARSE
543 XMLPI XMLROOT XMLSERIALIZE
550 * The grammar thinks these are keywords, but they are not in the kwlist.h
551 * list and so can never be entered directly. The filter in parser.c
552 * creates these tokens when required.
554 %token NULLS_FIRST NULLS_LAST WITH_TIME
557 /* Precedence: lowest to highest */
558 %nonassoc SET /* see relation_expr_opt_alias */
566 %nonassoc LIKE ILIKE SIMILAR
571 %left POSTFIXOP /* dummy for postfix Op rules */
573 * To support target_el without AS, we must give IDENT an explicit priority
574 * between POSTFIXOP and Op. We can safely assign the same priority to
575 * various unreserved keywords as needed to resolve ambiguities (this can't
576 * have any bad effects since obviously the keywords will still behave the
577 * same as if they weren't keywords). We need to do this for PARTITION,
578 * RANGE, ROWS to support opt_existing_window_name; and for RANGE, ROWS
579 * so that they can follow a_expr without creating
580 * postfix-operator problems.
582 * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
583 * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
584 * there is no principled way to distinguish these from the productions
585 * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
586 * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
587 * appear to cause UNBOUNDED to be treated differently from other unreserved
588 * keywords anywhere else in the grammar, but it's definitely risky. We can
589 * blame any funny behavior of UNBOUNDED on the SQL standard, though.
591 %nonassoc UNBOUNDED /* ideally should have same precedence as IDENT */
592 %nonassoc IDENT PARTITION RANGE ROWS PRECEDING FOLLOWING
593 %left Op OPERATOR /* multi-character ops and user-defined operators */
596 %nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN /* sets precedence for IS NULL, etc */
600 /* Unary Operators */
601 %left AT ZONE /* sets precedence for AT TIME ZONE */
608 * These might seem to be low-precedence, but actually they are not part
609 * of the arithmetic hierarchy at all in their use as JOIN operators.
610 * We make them high-precedence to support their use as function names.
611 * They wouldn't be given a precedence at all, were it not that we need
612 * left-associativity among the JOIN rules themselves.
614 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
615 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
616 %right PRESERVE STRIP_P
621 * The target production for the whole parse.
625 pg_yyget_extra(yyscanner)->parsetree = $1;
629 /* the thrashing around here is to discard "empty" statements... */
630 stmtmulti: stmtmulti ';' stmt
633 $$ = lappend($1, $3);
648 | AlterDatabaseSetStmt
649 | AlterDefaultPrivilegesStmt
652 | AlterForeignServerStmt
655 | AlterObjectSchemaStmt
661 | AlterTSConfigurationStmt
662 | AlterTSDictionaryStmt
663 | AlterUserMappingStmt
676 | CreateConversionStmt
679 | CreateForeignServerStmt
689 | CreateTableSpaceStmt
693 | CreateUserMappingStmt
704 | DropForeignServerStmt
716 | DropUserMappingStmt
753 /*****************************************************************************
755 * Create a new Postgres DBMS role
757 *****************************************************************************/
760 CREATE ROLE RoleId opt_with OptRoleList
762 CreateRoleStmt *n = makeNode(CreateRoleStmt);
763 n->stmt_type = ROLESTMT_ROLE;
776 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
777 * for backwards compatibility). Note: the only option required by SQL99
778 * is "WITH ADMIN name".
781 OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
782 | /* EMPTY */ { $$ = NIL; }
786 AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
787 | /* EMPTY */ { $$ = NIL; }
793 $$ = makeDefElem("password",
794 (Node *)makeString($2));
798 $$ = makeDefElem("password", NULL);
800 | ENCRYPTED PASSWORD Sconst
802 $$ = makeDefElem("encryptedPassword",
803 (Node *)makeString($3));
805 | UNENCRYPTED PASSWORD Sconst
807 $$ = makeDefElem("unencryptedPassword",
808 (Node *)makeString($3));
812 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
816 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
820 $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE));
824 $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE));
828 $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
832 $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
836 $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE));
840 $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE));
844 /* For backwards compatibility, synonym for SUPERUSER */
845 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
849 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
853 $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE));
857 $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE));
859 | CONNECTION LIMIT SignedIconst
861 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3));
865 $$ = makeDefElem("validUntil", (Node *)makeString($3));
867 /* Supported but not documented for roles, for use by ALTER GROUP. */
870 $$ = makeDefElem("rolemembers", (Node *)$2);
875 AlterOptRoleElem { $$ = $1; }
876 /* The following are not supported by ALTER ROLE/USER/GROUP */
879 $$ = makeDefElem("sysid", (Node *)makeInteger($2));
883 $$ = makeDefElem("adminmembers", (Node *)$2);
887 $$ = makeDefElem("rolemembers", (Node *)$2);
889 | IN_P ROLE name_list
891 $$ = makeDefElem("addroleto", (Node *)$3);
893 | IN_P GROUP_P name_list
895 $$ = makeDefElem("addroleto", (Node *)$3);
900 /*****************************************************************************
902 * Create a new Postgres DBMS user (role with implied login ability)
904 *****************************************************************************/
907 CREATE USER RoleId opt_with OptRoleList
909 CreateRoleStmt *n = makeNode(CreateRoleStmt);
910 n->stmt_type = ROLESTMT_USER;
918 /*****************************************************************************
920 * Alter a postgresql DBMS role
922 *****************************************************************************/
925 ALTER ROLE RoleId opt_with AlterOptRoleList
927 AlterRoleStmt *n = makeNode(AlterRoleStmt);
929 n->action = +1; /* add, if there are members */
936 /* EMPTY */ { $$ = NULL; }
937 | IN_P DATABASE database_name { $$ = $3; }
941 ALTER ROLE RoleId opt_in_database SetResetClause
943 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
952 /*****************************************************************************
954 * Alter a postgresql DBMS user
956 *****************************************************************************/
959 ALTER USER RoleId opt_with AlterOptRoleList
961 AlterRoleStmt *n = makeNode(AlterRoleStmt);
963 n->action = +1; /* add, if there are members */
971 ALTER USER RoleId SetResetClause
973 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
982 /*****************************************************************************
984 * Drop a postgresql DBMS role
986 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
987 * might own objects in multiple databases, there is presently no way to
988 * implement either cascading or restricting. Caveat DBA.
989 *****************************************************************************/
994 DropRoleStmt *n = makeNode(DropRoleStmt);
995 n->missing_ok = FALSE;
999 | DROP ROLE IF_P EXISTS name_list
1001 DropRoleStmt *n = makeNode(DropRoleStmt);
1002 n->missing_ok = TRUE;
1008 /*****************************************************************************
1010 * Drop a postgresql DBMS user
1012 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
1013 * might own objects in multiple databases, there is presently no way to
1014 * implement either cascading or restricting. Caveat DBA.
1015 *****************************************************************************/
1020 DropRoleStmt *n = makeNode(DropRoleStmt);
1021 n->missing_ok = FALSE;
1025 | DROP USER IF_P EXISTS name_list
1027 DropRoleStmt *n = makeNode(DropRoleStmt);
1029 n->missing_ok = TRUE;
1035 /*****************************************************************************
1037 * Create a postgresql group (role without login ability)
1039 *****************************************************************************/
1042 CREATE GROUP_P RoleId opt_with OptRoleList
1044 CreateRoleStmt *n = makeNode(CreateRoleStmt);
1045 n->stmt_type = ROLESTMT_GROUP;
1053 /*****************************************************************************
1055 * Alter a postgresql group
1057 *****************************************************************************/
1060 ALTER GROUP_P RoleId add_drop USER name_list
1062 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1065 n->options = list_make1(makeDefElem("rolemembers",
1071 add_drop: ADD_P { $$ = +1; }
1076 /*****************************************************************************
1078 * Drop a postgresql group
1080 * XXX see above notes about cascading DROP USER; groups have same problem.
1081 *****************************************************************************/
1084 DROP GROUP_P name_list
1086 DropRoleStmt *n = makeNode(DropRoleStmt);
1087 n->missing_ok = FALSE;
1091 | DROP GROUP_P IF_P EXISTS name_list
1093 DropRoleStmt *n = makeNode(DropRoleStmt);
1094 n->missing_ok = TRUE;
1101 /*****************************************************************************
1103 * Manipulate a schema
1105 *****************************************************************************/
1108 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
1110 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1111 /* One can omit the schema name or the authorization id. */
1120 | CREATE SCHEMA ColId OptSchemaEltList
1122 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1123 /* ...but not both */
1133 | /* EMPTY */ { $$ = NULL; }
1137 OptSchemaEltList schema_stmt { $$ = lappend($1, $2); }
1138 | /* EMPTY */ { $$ = NIL; }
1142 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1143 * statement (in addition to by themselves).
1155 /*****************************************************************************
1157 * Set PG internal variable
1158 * SET name TO 'var_value'
1159 * Include SQL92 syntax (thomas 1997-10-22):
1160 * SET TIME ZONE 'var_value'
1162 *****************************************************************************/
1167 VariableSetStmt *n = $2;
1168 n->is_local = false;
1171 | SET LOCAL set_rest
1173 VariableSetStmt *n = $3;
1177 | SET SESSION set_rest
1179 VariableSetStmt *n = $3;
1180 n->is_local = false;
1185 set_rest: /* Generic SET syntaxes: */
1186 var_name TO var_list
1188 VariableSetStmt *n = makeNode(VariableSetStmt);
1189 n->kind = VAR_SET_VALUE;
1194 | var_name '=' var_list
1196 VariableSetStmt *n = makeNode(VariableSetStmt);
1197 n->kind = VAR_SET_VALUE;
1202 | var_name TO DEFAULT
1204 VariableSetStmt *n = makeNode(VariableSetStmt);
1205 n->kind = VAR_SET_DEFAULT;
1209 | var_name '=' DEFAULT
1211 VariableSetStmt *n = makeNode(VariableSetStmt);
1212 n->kind = VAR_SET_DEFAULT;
1216 | var_name FROM CURRENT_P
1218 VariableSetStmt *n = makeNode(VariableSetStmt);
1219 n->kind = VAR_SET_CURRENT;
1223 /* Special syntaxes mandated by SQL standard: */
1224 | TIME ZONE zone_value
1226 VariableSetStmt *n = makeNode(VariableSetStmt);
1227 n->kind = VAR_SET_VALUE;
1228 n->name = "timezone";
1230 n->args = list_make1($3);
1232 n->kind = VAR_SET_DEFAULT;
1235 | TRANSACTION transaction_mode_list
1237 VariableSetStmt *n = makeNode(VariableSetStmt);
1238 n->kind = VAR_SET_MULTI;
1239 n->name = "TRANSACTION";
1243 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1245 VariableSetStmt *n = makeNode(VariableSetStmt);
1246 n->kind = VAR_SET_MULTI;
1247 n->name = "SESSION CHARACTERISTICS";
1254 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1255 errmsg("current database cannot be changed"),
1256 parser_errposition(@2)));
1257 $$ = NULL; /*not reached*/
1261 VariableSetStmt *n = makeNode(VariableSetStmt);
1262 n->kind = VAR_SET_VALUE;
1263 n->name = "search_path";
1264 n->args = list_make1(makeStringConst($2, @2));
1267 | NAMES opt_encoding
1269 VariableSetStmt *n = makeNode(VariableSetStmt);
1270 n->kind = VAR_SET_VALUE;
1271 n->name = "client_encoding";
1273 n->args = list_make1(makeStringConst($2, @2));
1275 n->kind = VAR_SET_DEFAULT;
1278 | ROLE ColId_or_Sconst
1280 VariableSetStmt *n = makeNode(VariableSetStmt);
1281 n->kind = VAR_SET_VALUE;
1283 n->args = list_make1(makeStringConst($2, @2));
1286 | SESSION AUTHORIZATION ColId_or_Sconst
1288 VariableSetStmt *n = makeNode(VariableSetStmt);
1289 n->kind = VAR_SET_VALUE;
1290 n->name = "session_authorization";
1291 n->args = list_make1(makeStringConst($3, @3));
1294 | SESSION AUTHORIZATION DEFAULT
1296 VariableSetStmt *n = makeNode(VariableSetStmt);
1297 n->kind = VAR_SET_DEFAULT;
1298 n->name = "session_authorization";
1301 | XML_P OPTION document_or_content
1303 VariableSetStmt *n = makeNode(VariableSetStmt);
1304 n->kind = VAR_SET_VALUE;
1305 n->name = "xmloption";
1306 n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1311 var_name: ColId { $$ = $1; }
1312 | var_name '.' ColId
1314 $$ = palloc(strlen($1) + strlen($3) + 2);
1315 sprintf($$, "%s.%s", $1, $3);
1319 var_list: var_value { $$ = list_make1($1); }
1320 | var_list ',' var_value { $$ = lappend($1, $3); }
1323 var_value: opt_boolean
1324 { $$ = makeStringConst($1, @1); }
1326 { $$ = makeStringConst($1, @1); }
1328 { $$ = makeAConst($1, @1); }
1331 iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1332 | READ COMMITTED { $$ = "read committed"; }
1333 | REPEATABLE READ { $$ = "repeatable read"; }
1334 | SERIALIZABLE { $$ = "serializable"; }
1338 TRUE_P { $$ = "true"; }
1339 | FALSE_P { $$ = "false"; }
1341 | OFF { $$ = "off"; }
1344 /* Timezone values can be:
1345 * - a string such as 'pst8pdt'
1346 * - an identifier such as "pst8pdt"
1347 * - an integer or floating point number
1348 * - a time interval per SQL99
1349 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1350 * so use IDENT (meaning we reject anything that is a key word).
1355 $$ = makeStringConst($1, @1);
1359 $$ = makeStringConst($1, @1);
1361 | ConstInterval Sconst opt_interval
1366 A_Const *n = (A_Const *) linitial($3);
1367 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1369 (errcode(ERRCODE_SYNTAX_ERROR),
1370 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1371 parser_errposition(@3)));
1374 $$ = makeStringConstCast($2, @2, t);
1376 | ConstInterval '(' Iconst ')' Sconst opt_interval
1381 A_Const *n = (A_Const *) linitial($6);
1382 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1384 (errcode(ERRCODE_SYNTAX_ERROR),
1385 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1386 parser_errposition(@6)));
1387 if (list_length($6) != 1)
1389 (errcode(ERRCODE_SYNTAX_ERROR),
1390 errmsg("interval precision specified twice"),
1391 parser_errposition(@1)));
1392 t->typmods = lappend($6, makeIntConst($3, @3));
1395 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1396 makeIntConst($3, @3));
1397 $$ = makeStringConstCast($5, @5, t);
1399 | NumericOnly { $$ = makeAConst($1, @1); }
1400 | DEFAULT { $$ = NULL; }
1401 | LOCAL { $$ = NULL; }
1406 | DEFAULT { $$ = NULL; }
1407 | /*EMPTY*/ { $$ = NULL; }
1412 | Sconst { $$ = $1; }
1418 VariableSetStmt *n = makeNode(VariableSetStmt);
1419 n->kind = VAR_RESET;
1425 VariableSetStmt *n = makeNode(VariableSetStmt);
1426 n->kind = VAR_RESET;
1427 n->name = "timezone";
1430 | RESET TRANSACTION ISOLATION LEVEL
1432 VariableSetStmt *n = makeNode(VariableSetStmt);
1433 n->kind = VAR_RESET;
1434 n->name = "transaction_isolation";
1437 | RESET SESSION AUTHORIZATION
1439 VariableSetStmt *n = makeNode(VariableSetStmt);
1440 n->kind = VAR_RESET;
1441 n->name = "session_authorization";
1446 VariableSetStmt *n = makeNode(VariableSetStmt);
1447 n->kind = VAR_RESET_ALL;
1452 /* SetResetClause allows SET or RESET without LOCAL */
1454 SET set_rest { $$ = $2; }
1455 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1462 VariableShowStmt *n = makeNode(VariableShowStmt);
1468 VariableShowStmt *n = makeNode(VariableShowStmt);
1469 n->name = "timezone";
1472 | SHOW TRANSACTION ISOLATION LEVEL
1474 VariableShowStmt *n = makeNode(VariableShowStmt);
1475 n->name = "transaction_isolation";
1478 | SHOW SESSION AUTHORIZATION
1480 VariableShowStmt *n = makeNode(VariableShowStmt);
1481 n->name = "session_authorization";
1486 VariableShowStmt *n = makeNode(VariableShowStmt);
1494 SET CONSTRAINTS constraints_set_list constraints_set_mode
1496 ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
1497 n->constraints = $3;
1503 constraints_set_list:
1505 | qualified_name_list { $$ = $1; }
1508 constraints_set_mode:
1509 DEFERRED { $$ = TRUE; }
1510 | IMMEDIATE { $$ = FALSE; }
1515 * Checkpoint statement
1520 CheckPointStmt *n = makeNode(CheckPointStmt);
1526 /*****************************************************************************
1528 * DISCARD { ALL | TEMP | PLANS }
1530 *****************************************************************************/
1535 DiscardStmt *n = makeNode(DiscardStmt);
1536 n->target = DISCARD_ALL;
1541 DiscardStmt *n = makeNode(DiscardStmt);
1542 n->target = DISCARD_TEMP;
1547 DiscardStmt *n = makeNode(DiscardStmt);
1548 n->target = DISCARD_TEMP;
1553 DiscardStmt *n = makeNode(DiscardStmt);
1554 n->target = DISCARD_PLANS;
1560 /*****************************************************************************
1562 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations
1564 * Note: we accept all subcommands for each of the four variants, and sort
1565 * out what's really legal at execution time.
1566 *****************************************************************************/
1569 ALTER TABLE relation_expr alter_table_cmds
1571 AlterTableStmt *n = makeNode(AlterTableStmt);
1574 n->relkind = OBJECT_TABLE;
1577 | ALTER INDEX qualified_name alter_table_cmds
1579 AlterTableStmt *n = makeNode(AlterTableStmt);
1582 n->relkind = OBJECT_INDEX;
1585 | ALTER SEQUENCE qualified_name alter_table_cmds
1587 AlterTableStmt *n = makeNode(AlterTableStmt);
1590 n->relkind = OBJECT_SEQUENCE;
1593 | ALTER VIEW qualified_name alter_table_cmds
1595 AlterTableStmt *n = makeNode(AlterTableStmt);
1598 n->relkind = OBJECT_VIEW;
1604 alter_table_cmd { $$ = list_make1($1); }
1605 | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
1609 /* ALTER TABLE <name> ADD <coldef> */
1612 AlterTableCmd *n = makeNode(AlterTableCmd);
1613 n->subtype = AT_AddColumn;
1617 /* ALTER TABLE <name> ADD COLUMN <coldef> */
1618 | ADD_P COLUMN columnDef
1620 AlterTableCmd *n = makeNode(AlterTableCmd);
1621 n->subtype = AT_AddColumn;
1625 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1626 | ALTER opt_column ColId alter_column_default
1628 AlterTableCmd *n = makeNode(AlterTableCmd);
1629 n->subtype = AT_ColumnDefault;
1634 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1635 | ALTER opt_column ColId DROP NOT NULL_P
1637 AlterTableCmd *n = makeNode(AlterTableCmd);
1638 n->subtype = AT_DropNotNull;
1642 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1643 | ALTER opt_column ColId SET NOT NULL_P
1645 AlterTableCmd *n = makeNode(AlterTableCmd);
1646 n->subtype = AT_SetNotNull;
1650 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
1651 | ALTER opt_column ColId SET STATISTICS SignedIconst
1653 AlterTableCmd *n = makeNode(AlterTableCmd);
1654 n->subtype = AT_SetStatistics;
1656 n->def = (Node *) makeInteger($6);
1659 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
1660 | ALTER opt_column ColId SET reloptions
1662 AlterTableCmd *n = makeNode(AlterTableCmd);
1663 n->subtype = AT_SetOptions;
1665 n->def = (Node *) $5;
1668 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
1669 | ALTER opt_column ColId RESET reloptions
1671 AlterTableCmd *n = makeNode(AlterTableCmd);
1672 n->subtype = AT_ResetOptions;
1674 n->def = (Node *) $5;
1677 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1678 | ALTER opt_column ColId SET STORAGE ColId
1680 AlterTableCmd *n = makeNode(AlterTableCmd);
1681 n->subtype = AT_SetStorage;
1683 n->def = (Node *) makeString($6);
1686 /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
1687 | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
1689 AlterTableCmd *n = makeNode(AlterTableCmd);
1690 n->subtype = AT_DropColumn;
1693 n->missing_ok = TRUE;
1696 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1697 | DROP opt_column ColId opt_drop_behavior
1699 AlterTableCmd *n = makeNode(AlterTableCmd);
1700 n->subtype = AT_DropColumn;
1703 n->missing_ok = FALSE;
1707 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
1708 * [ USING <expression> ]
1710 | ALTER opt_column ColId opt_set_data TYPE_P Typename alter_using
1712 AlterTableCmd *n = makeNode(AlterTableCmd);
1713 n->subtype = AT_AlterColumnType;
1715 n->def = (Node *) $6;
1719 /* ALTER TABLE <name> ADD CONSTRAINT ... */
1720 | ADD_P TableConstraint
1722 AlterTableCmd *n = makeNode(AlterTableCmd);
1723 n->subtype = AT_AddConstraint;
1727 /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
1728 | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
1730 AlterTableCmd *n = makeNode(AlterTableCmd);
1731 n->subtype = AT_DropConstraint;
1734 n->missing_ok = TRUE;
1737 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1738 | DROP CONSTRAINT name opt_drop_behavior
1740 AlterTableCmd *n = makeNode(AlterTableCmd);
1741 n->subtype = AT_DropConstraint;
1744 n->missing_ok = FALSE;
1747 /* ALTER TABLE <name> SET WITH OIDS */
1750 AlterTableCmd *n = makeNode(AlterTableCmd);
1751 n->subtype = AT_AddOids;
1754 /* ALTER TABLE <name> SET WITHOUT OIDS */
1757 AlterTableCmd *n = makeNode(AlterTableCmd);
1758 n->subtype = AT_DropOids;
1761 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1764 AlterTableCmd *n = makeNode(AlterTableCmd);
1765 n->subtype = AT_ClusterOn;
1769 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1770 | SET WITHOUT CLUSTER
1772 AlterTableCmd *n = makeNode(AlterTableCmd);
1773 n->subtype = AT_DropCluster;
1777 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
1778 | ENABLE_P TRIGGER name
1780 AlterTableCmd *n = makeNode(AlterTableCmd);
1781 n->subtype = AT_EnableTrig;
1785 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
1786 | ENABLE_P ALWAYS TRIGGER name
1788 AlterTableCmd *n = makeNode(AlterTableCmd);
1789 n->subtype = AT_EnableAlwaysTrig;
1793 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
1794 | ENABLE_P REPLICA TRIGGER name
1796 AlterTableCmd *n = makeNode(AlterTableCmd);
1797 n->subtype = AT_EnableReplicaTrig;
1801 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
1802 | ENABLE_P TRIGGER ALL
1804 AlterTableCmd *n = makeNode(AlterTableCmd);
1805 n->subtype = AT_EnableTrigAll;
1808 /* ALTER TABLE <name> ENABLE TRIGGER USER */
1809 | ENABLE_P TRIGGER USER
1811 AlterTableCmd *n = makeNode(AlterTableCmd);
1812 n->subtype = AT_EnableTrigUser;
1815 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
1816 | DISABLE_P TRIGGER name
1818 AlterTableCmd *n = makeNode(AlterTableCmd);
1819 n->subtype = AT_DisableTrig;
1823 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
1824 | DISABLE_P TRIGGER ALL
1826 AlterTableCmd *n = makeNode(AlterTableCmd);
1827 n->subtype = AT_DisableTrigAll;
1830 /* ALTER TABLE <name> DISABLE TRIGGER USER */
1831 | DISABLE_P TRIGGER USER
1833 AlterTableCmd *n = makeNode(AlterTableCmd);
1834 n->subtype = AT_DisableTrigUser;
1837 /* ALTER TABLE <name> ENABLE RULE <rule> */
1838 | ENABLE_P RULE name
1840 AlterTableCmd *n = makeNode(AlterTableCmd);
1841 n->subtype = AT_EnableRule;
1845 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
1846 | ENABLE_P ALWAYS RULE name
1848 AlterTableCmd *n = makeNode(AlterTableCmd);
1849 n->subtype = AT_EnableAlwaysRule;
1853 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
1854 | ENABLE_P REPLICA RULE name
1856 AlterTableCmd *n = makeNode(AlterTableCmd);
1857 n->subtype = AT_EnableReplicaRule;
1861 /* ALTER TABLE <name> DISABLE RULE <rule> */
1862 | DISABLE_P RULE name
1864 AlterTableCmd *n = makeNode(AlterTableCmd);
1865 n->subtype = AT_DisableRule;
1869 /* ALTER TABLE <name> INHERIT <parent> */
1870 | INHERIT qualified_name
1872 AlterTableCmd *n = makeNode(AlterTableCmd);
1873 n->subtype = AT_AddInherit;
1874 n->def = (Node *) $2;
1877 /* ALTER TABLE <name> NO INHERIT <parent> */
1878 | NO INHERIT qualified_name
1880 AlterTableCmd *n = makeNode(AlterTableCmd);
1881 n->subtype = AT_DropInherit;
1882 n->def = (Node *) $3;
1885 /* ALTER TABLE <name> OWNER TO RoleId */
1888 AlterTableCmd *n = makeNode(AlterTableCmd);
1889 n->subtype = AT_ChangeOwner;
1893 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1894 | SET TABLESPACE name
1896 AlterTableCmd *n = makeNode(AlterTableCmd);
1897 n->subtype = AT_SetTableSpace;
1901 /* ALTER TABLE <name> SET (...) */
1904 AlterTableCmd *n = makeNode(AlterTableCmd);
1905 n->subtype = AT_SetRelOptions;
1906 n->def = (Node *)$2;
1909 /* ALTER TABLE <name> RESET (...) */
1912 AlterTableCmd *n = makeNode(AlterTableCmd);
1913 n->subtype = AT_ResetRelOptions;
1914 n->def = (Node *)$2;
1919 alter_column_default:
1920 SET DEFAULT a_expr { $$ = $3; }
1921 | DROP DEFAULT { $$ = NULL; }
1925 CASCADE { $$ = DROP_CASCADE; }
1926 | RESTRICT { $$ = DROP_RESTRICT; }
1927 | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1931 USING a_expr { $$ = $2; }
1932 | /* EMPTY */ { $$ = NULL; }
1936 '(' reloption_list ')' { $$ = $2; }
1939 opt_reloptions: WITH reloptions { $$ = $2; }
1940 | /* EMPTY */ { $$ = NIL; }
1944 reloption_elem { $$ = list_make1($1); }
1945 | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
1948 /* This should match def_elem and also allow qualified names */
1950 ColLabel '=' def_arg
1952 $$ = makeDefElem($1, (Node *) $3);
1956 $$ = makeDefElem($1, NULL);
1958 | ColLabel '.' ColLabel '=' def_arg
1960 $$ = makeDefElemExtended($1, $3, (Node *) $5,
1963 | ColLabel '.' ColLabel
1965 $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC);
1970 /*****************************************************************************
1973 * close <portalname>
1975 *****************************************************************************/
1980 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1986 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1987 n->portalname = NULL;
1993 /*****************************************************************************
1996 * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
1997 * COPY ( SELECT ... ) TO file [WITH] [(options)]
1999 * In the preferred syntax the options are comma-separated
2000 * and use generic identifiers instead of keywords. The pre-9.0
2001 * syntax had a hard-wired, space-separated set of options.
2003 * Really old syntax, from versions 7.2 and prior:
2004 * COPY [ BINARY ] table [ WITH OIDS ] FROM/TO file
2005 * [ [ USING ] DELIMITERS 'delimiter' ] ]
2006 * [ WITH NULL AS 'null string' ]
2007 * This option placement is not supported with COPY (SELECT...).
2009 *****************************************************************************/
2011 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
2012 copy_from copy_file_name copy_delimiter opt_with copy_options
2014 CopyStmt *n = makeNode(CopyStmt);
2022 /* Concatenate user-supplied flags */
2024 n->options = lappend(n->options, $2);
2026 n->options = lappend(n->options, $5);
2028 n->options = lappend(n->options, $8);
2030 n->options = list_concat(n->options, $10);
2033 | COPY select_with_parens TO copy_file_name opt_with copy_options
2035 CopyStmt *n = makeNode(CopyStmt);
2048 | TO { $$ = FALSE; }
2052 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
2053 * used depends on the direction. (It really doesn't make sense to copy from
2054 * stdout. We silently correct the "typo".) - AY 9/94
2058 | STDIN { $$ = NULL; }
2059 | STDOUT { $$ = NULL; }
2062 copy_options: copy_opt_list { $$ = $1; }
2063 | '(' copy_generic_opt_list ')' { $$ = $2; }
2066 /* old COPY option syntax */
2068 copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
2069 | /* EMPTY */ { $$ = NIL; }
2075 $$ = makeDefElem("format", (Node *)makeString("binary"));
2079 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2081 | DELIMITER opt_as Sconst
2083 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2085 | NULL_P opt_as Sconst
2087 $$ = makeDefElem("null", (Node *)makeString($3));
2091 $$ = makeDefElem("format", (Node *)makeString("csv"));
2095 $$ = makeDefElem("header", (Node *)makeInteger(TRUE));
2097 | QUOTE opt_as Sconst
2099 $$ = makeDefElem("quote", (Node *)makeString($3));
2101 | ESCAPE opt_as Sconst
2103 $$ = makeDefElem("escape", (Node *)makeString($3));
2105 | FORCE QUOTE columnList
2107 $$ = makeDefElem("force_quote", (Node *)$3);
2111 $$ = makeDefElem("force_quote", (Node *)makeNode(A_Star));
2113 | FORCE NOT NULL_P columnList
2115 $$ = makeDefElem("force_not_null", (Node *)$4);
2119 /* The following exist for backward compatibility with very old versions */
2124 $$ = makeDefElem("format", (Node *)makeString("binary"));
2126 | /*EMPTY*/ { $$ = NULL; }
2132 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2134 | /*EMPTY*/ { $$ = NULL; }
2138 opt_using DELIMITERS Sconst
2140 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2142 | /*EMPTY*/ { $$ = NULL; }
2150 /* new COPY option syntax */
2151 copy_generic_opt_list:
2152 copy_generic_opt_elem
2154 $$ = list_make1($1);
2156 | copy_generic_opt_list ',' copy_generic_opt_elem
2158 $$ = lappend($1, $3);
2162 copy_generic_opt_elem:
2163 ColLabel copy_generic_opt_arg
2165 $$ = makeDefElem($1, $2);
2169 copy_generic_opt_arg:
2170 opt_boolean { $$ = (Node *) makeString($1); }
2171 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
2172 | NumericOnly { $$ = (Node *) $1; }
2173 | '*' { $$ = (Node *) makeNode(A_Star); }
2174 | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
2175 | /* EMPTY */ { $$ = NULL; }
2178 copy_generic_opt_arg_list:
2179 copy_generic_opt_arg_list_item
2181 $$ = list_make1($1);
2183 | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
2185 $$ = lappend($1, $3);
2189 /* beware of emitting non-string list elements here; see commands/define.c */
2190 copy_generic_opt_arg_list_item:
2191 opt_boolean { $$ = (Node *) makeString($1); }
2192 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
2196 /*****************************************************************************
2199 * CREATE TABLE relname
2201 *****************************************************************************/
2203 CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
2204 OptInherit OptWith OnCommitOption OptTableSpace
2206 CreateStmt *n = makeNode(CreateStmt);
2210 n->inhRelations = $8;
2211 n->constraints = NIL;
2214 n->tablespacename = $11;
2217 | CREATE OptTemp TABLE qualified_name OF any_name
2218 OptTypedTableElementList OptWith OnCommitOption OptTableSpace
2220 CreateStmt *n = makeNode(CreateStmt);
2224 n->ofTypename = makeTypeNameFromNameList($6);
2225 n->ofTypename->location = @6;
2226 n->constraints = NIL;
2229 n->tablespacename = $10;
2235 * Redundancy here is needed to avoid shift/reduce conflicts,
2236 * since TEMP is not a reserved word. See also OptTempTableName.
2238 * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
2239 * the LOCAL keyword is really meaningless.
2241 OptTemp: TEMPORARY { $$ = TRUE; }
2242 | TEMP { $$ = TRUE; }
2243 | LOCAL TEMPORARY { $$ = TRUE; }
2244 | LOCAL TEMP { $$ = TRUE; }
2245 | GLOBAL TEMPORARY { $$ = TRUE; }
2246 | GLOBAL TEMP { $$ = TRUE; }
2247 | /*EMPTY*/ { $$ = FALSE; }
2250 OptTableElementList:
2251 TableElementList { $$ = $1; }
2252 | /*EMPTY*/ { $$ = NIL; }
2255 OptTypedTableElementList:
2256 '(' TypedTableElementList ')' { $$ = $2; }
2257 | /*EMPTY*/ { $$ = NIL; }
2263 $$ = list_make1($1);
2265 | TableElementList ',' TableElement
2267 $$ = lappend($1, $3);
2271 TypedTableElementList:
2274 $$ = list_make1($1);
2276 | TypedTableElementList ',' TypedTableElement
2278 $$ = lappend($1, $3);
2283 columnDef { $$ = $1; }
2284 | TableLikeClause { $$ = $1; }
2285 | TableConstraint { $$ = $1; }
2289 columnOptions { $$ = $1; }
2290 | TableConstraint { $$ = $1; }
2293 columnDef: ColId Typename ColQualList
2295 ColumnDef *n = makeNode(ColumnDef);
2298 n->constraints = $3;
2304 columnOptions: ColId WITH OPTIONS ColQualList
2306 ColumnDef *n = makeNode(ColumnDef);
2308 n->constraints = $4;
2315 ColQualList ColConstraint { $$ = lappend($1, $2); }
2316 | /*EMPTY*/ { $$ = NIL; }
2320 CONSTRAINT name ColConstraintElem
2322 Constraint *n = (Constraint *) $3;
2323 Assert(IsA(n, Constraint));
2328 | ColConstraintElem { $$ = $1; }
2329 | ConstraintAttr { $$ = $1; }
2332 /* DEFAULT NULL is already the default for Postgres.
2333 * But define it here and carry it forward into the system
2334 * to make it explicit.
2335 * - thomas 1998-09-13
2337 * WITH NULL and NULL are not SQL92-standard syntax elements,
2338 * so leave them out. Use DEFAULT NULL to explicitly indicate
2339 * that a column may have that value. WITH NULL leads to
2340 * shift/reduce conflicts with WITH TIME ZONE anyway.
2341 * - thomas 1999-01-08
2343 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
2344 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
2345 * or be part of a_expr NOT LIKE or similar constructs).
2350 Constraint *n = makeNode(Constraint);
2351 n->contype = CONSTR_NOTNULL;
2357 Constraint *n = makeNode(Constraint);
2358 n->contype = CONSTR_NULL;
2362 | UNIQUE opt_definition OptConsTableSpace
2364 Constraint *n = makeNode(Constraint);
2365 n->contype = CONSTR_UNIQUE;
2372 | PRIMARY KEY opt_definition OptConsTableSpace
2374 Constraint *n = makeNode(Constraint);
2375 n->contype = CONSTR_PRIMARY;
2382 | CHECK '(' a_expr ')'
2384 Constraint *n = makeNode(Constraint);
2385 n->contype = CONSTR_CHECK;
2388 n->cooked_expr = NULL;
2393 Constraint *n = makeNode(Constraint);
2394 n->contype = CONSTR_DEFAULT;
2397 n->cooked_expr = NULL;
2400 | REFERENCES qualified_name opt_column_list key_match key_actions
2402 Constraint *n = makeNode(Constraint);
2403 n->contype = CONSTR_FOREIGN;
2408 n->fk_matchtype = $4;
2409 n->fk_upd_action = (char) ($5 >> 8);
2410 n->fk_del_action = (char) ($5 & 0xFF);
2411 n->skip_validation = FALSE;
2417 * ConstraintAttr represents constraint attributes, which we parse as if
2418 * they were independent constraint clauses, in order to avoid shift/reduce
2419 * conflicts (since NOT might start either an independent NOT NULL clause
2420 * or an attribute). parse_utilcmd.c is responsible for attaching the
2421 * attribute information to the preceding "real" constraint node, and for
2422 * complaining if attribute clauses appear in the wrong place or wrong
2425 * See also ConstraintAttributeSpec, which can be used in places where
2426 * there is no parsing conflict.
2431 Constraint *n = makeNode(Constraint);
2432 n->contype = CONSTR_ATTR_DEFERRABLE;
2438 Constraint *n = makeNode(Constraint);
2439 n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
2443 | INITIALLY DEFERRED
2445 Constraint *n = makeNode(Constraint);
2446 n->contype = CONSTR_ATTR_DEFERRED;
2450 | INITIALLY IMMEDIATE
2452 Constraint *n = makeNode(Constraint);
2453 n->contype = CONSTR_ATTR_IMMEDIATE;
2461 * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2462 * This seems to be a poor man's inheritance capability, with the resulting
2463 * tables completely decoupled except for the original commonality in definitions.
2465 * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2466 * which is a part of SQL:2003.
2469 LIKE qualified_name TableLikeOptionList
2471 InhRelation *n = makeNode(InhRelation);
2478 TableLikeOptionList:
2479 TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
2480 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
2481 | /* EMPTY */ { $$ = 0; }
2485 DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
2486 | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
2487 | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
2488 | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
2489 | COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
2490 | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
2494 /* ConstraintElem specifies constraint syntax which is not embedded into
2495 * a column definition. ColConstraintElem specifies the embedded form.
2496 * - thomas 1997-12-03
2499 CONSTRAINT name ConstraintElem
2501 Constraint *n = (Constraint *) $3;
2502 Assert(IsA(n, Constraint));
2507 | ConstraintElem { $$ = $1; }
2511 CHECK '(' a_expr ')' ConstraintAttributeSpec
2513 Constraint *n = makeNode(Constraint);
2514 n->contype = CONSTR_CHECK;
2517 n->cooked_expr = NULL;
2520 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2521 errmsg("CHECK constraints cannot be deferred"),
2522 parser_errposition(@5)));
2525 | UNIQUE '(' columnList ')' opt_definition OptConsTableSpace
2526 ConstraintAttributeSpec
2528 Constraint *n = makeNode(Constraint);
2529 n->contype = CONSTR_UNIQUE;
2534 n->deferrable = ($7 & 1) != 0;
2535 n->initdeferred = ($7 & 2) != 0;
2538 | PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace
2539 ConstraintAttributeSpec
2541 Constraint *n = makeNode(Constraint);
2542 n->contype = CONSTR_PRIMARY;
2547 n->deferrable = ($8 & 1) != 0;
2548 n->initdeferred = ($8 & 2) != 0;
2551 | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
2552 opt_definition OptConsTableSpace ExclusionWhereClause
2553 ConstraintAttributeSpec
2555 Constraint *n = makeNode(Constraint);
2556 n->contype = CONSTR_EXCLUSION;
2558 n->access_method = $2;
2562 n->where_clause = $8;
2563 n->deferrable = ($9 & 1) != 0;
2564 n->initdeferred = ($9 & 2) != 0;
2567 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
2568 opt_column_list key_match key_actions ConstraintAttributeSpec
2570 Constraint *n = makeNode(Constraint);
2571 n->contype = CONSTR_FOREIGN;
2576 n->fk_matchtype = $9;
2577 n->fk_upd_action = (char) ($10 >> 8);
2578 n->fk_del_action = (char) ($10 & 0xFF);
2579 n->skip_validation = FALSE;
2580 n->deferrable = ($11 & 1) != 0;
2581 n->initdeferred = ($11 & 2) != 0;
2587 '(' columnList ')' { $$ = $2; }
2588 | /*EMPTY*/ { $$ = NIL; }
2592 columnElem { $$ = list_make1($1); }
2593 | columnList ',' columnElem { $$ = lappend($1, $3); }
2598 $$ = (Node *) makeString($1);
2602 key_match: MATCH FULL
2604 $$ = FKCONSTR_MATCH_FULL;
2609 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2610 errmsg("MATCH PARTIAL not yet implemented"),
2611 parser_errposition(@1)));
2612 $$ = FKCONSTR_MATCH_PARTIAL;
2616 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2620 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2624 ExclusionConstraintList:
2625 ExclusionConstraintElem { $$ = list_make1($1); }
2626 | ExclusionConstraintList ',' ExclusionConstraintElem
2627 { $$ = lappend($1, $3); }
2630 ExclusionConstraintElem: index_elem WITH any_operator
2632 $$ = list_make2($1, $3);
2634 /* allow OPERATOR() decoration for the benefit of ruleutils.c */
2635 | index_elem WITH OPERATOR '(' any_operator ')'
2637 $$ = list_make2($1, $5);
2641 ExclusionWhereClause:
2642 WHERE '(' a_expr ')' { $$ = $3; }
2643 | /*EMPTY*/ { $$ = NULL; }
2647 * We combine the update and delete actions into one value temporarily
2648 * for simplicity of parsing, and then break them down again in the
2649 * calling production. update is in the left 8 bits, delete in the right.
2650 * Note that NOACTION is the default.
2654 { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2656 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
2657 | key_update key_delete
2658 { $$ = ($1 << 8) | ($2 & 0xFF); }
2659 | key_delete key_update
2660 { $$ = ($2 << 8) | ($1 & 0xFF); }
2662 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2665 key_update: ON UPDATE key_action { $$ = $3; }
2668 key_delete: ON DELETE_P key_action { $$ = $3; }
2672 NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; }
2673 | RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; }
2674 | CASCADE { $$ = FKCONSTR_ACTION_CASCADE; }
2675 | SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; }
2676 | SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; }
2679 OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
2680 | /*EMPTY*/ { $$ = NIL; }
2683 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
2685 WITH reloptions { $$ = $2; }
2686 | WITH OIDS { $$ = list_make1(defWithOids(true)); }
2687 | WITHOUT OIDS { $$ = list_make1(defWithOids(false)); }
2688 | /*EMPTY*/ { $$ = NIL; }
2691 OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
2692 | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
2693 | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
2694 | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
2697 OptTableSpace: TABLESPACE name { $$ = $2; }
2698 | /*EMPTY*/ { $$ = NULL; }
2701 OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
2702 | /*EMPTY*/ { $$ = NULL; }
2707 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
2712 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
2715 * When the SelectStmt is a set-operation tree, we must
2716 * stuff the INTO information into the leftmost component
2717 * Select, because that's where analyze.c will expect
2718 * to find it. Similarly, the output column names must
2719 * be attached to that Select's target list.
2721 SelectStmt *n = findLeftmostSelect((SelectStmt *) $6);
2722 if (n->intoClause != NULL)
2724 (errcode(ERRCODE_SYNTAX_ERROR),
2725 errmsg("CREATE TABLE AS cannot specify INTO"),
2726 parser_errposition(exprLocation((Node *) n->intoClause))));
2727 $4->rel->istemp = $2;
2729 /* Implement WITH NO DATA by forcing top-level LIMIT 0 */
2731 ((SelectStmt *) $6)->limitCount = makeIntConst(0, -1);
2737 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
2739 $$ = makeNode(IntoClause);
2744 $$->tableSpaceName = $5;
2749 '(' CreateAsList ')' { $$ = $2; }
2750 | /*EMPTY*/ { $$ = NIL; }
2754 CreateAsElement { $$ = list_make1($1); }
2755 | CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); }
2761 ColumnDef *n = makeNode(ColumnDef);
2766 n->is_not_null = false;
2767 n->raw_default = NULL;
2768 n->cooked_default = NULL;
2769 n->constraints = NIL;
2775 WITH DATA_P { $$ = TRUE; }
2776 | WITH NO DATA_P { $$ = FALSE; }
2777 | /*EMPTY*/ { $$ = TRUE; }
2781 /*****************************************************************************
2784 * CREATE SEQUENCE seqname
2785 * ALTER SEQUENCE seqname
2787 *****************************************************************************/
2790 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
2792 CreateSeqStmt *n = makeNode(CreateSeqStmt);
2801 ALTER SEQUENCE qualified_name SeqOptList
2803 AlterSeqStmt *n = makeNode(AlterSeqStmt);
2810 OptSeqOptList: SeqOptList { $$ = $1; }
2811 | /*EMPTY*/ { $$ = NIL; }
2814 SeqOptList: SeqOptElem { $$ = list_make1($1); }
2815 | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
2818 SeqOptElem: CACHE NumericOnly
2820 $$ = makeDefElem("cache", (Node *)$2);
2824 $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE));
2828 $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE));
2830 | INCREMENT opt_by NumericOnly
2832 $$ = makeDefElem("increment", (Node *)$3);
2834 | MAXVALUE NumericOnly
2836 $$ = makeDefElem("maxvalue", (Node *)$2);
2838 | MINVALUE NumericOnly
2840 $$ = makeDefElem("minvalue", (Node *)$2);
2844 $$ = makeDefElem("maxvalue", NULL);
2848 $$ = makeDefElem("minvalue", NULL);
2852 $$ = makeDefElem("owned_by", (Node *)$3);
2854 | START opt_with NumericOnly
2856 $$ = makeDefElem("start", (Node *)$3);
2860 $$ = makeDefElem("restart", NULL);
2862 | RESTART opt_with NumericOnly
2864 $$ = makeDefElem("restart", (Node *)$3);
2873 FCONST { $$ = makeFloat($1); }
2879 | SignedIconst { $$ = makeInteger($1); }
2882 /*****************************************************************************
2885 * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
2886 * DROP [PROCEDURAL] LANGUAGE ...
2888 *****************************************************************************/
2891 CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2893 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2896 /* parameters are all to be supplied by system */
2899 n->plvalidator = NIL;
2900 n->pltrusted = false;
2903 | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2904 HANDLER handler_name opt_inline_handler opt_validator
2906 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2911 n->plvalidator = $10;
2918 TRUSTED { $$ = TRUE; }
2919 | /*EMPTY*/ { $$ = FALSE; }
2922 /* This ought to be just func_name, but that causes reduce/reduce conflicts
2923 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
2924 * Work around by using simple names, instead.
2927 name { $$ = list_make1(makeString($1)); }
2928 | name attrs { $$ = lcons(makeString($1), $2); }
2932 INLINE_P handler_name { $$ = $2; }
2933 | /*EMPTY*/ { $$ = NIL; }
2937 VALIDATOR handler_name { $$ = $2; }
2938 | NO VALIDATOR { $$ = NIL; }
2942 validator_clause { $$ = $1; }
2943 | /*EMPTY*/ { $$ = NIL; }
2947 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
2949 DropPLangStmt *n = makeNode(DropPLangStmt);
2952 n->missing_ok = false;
2955 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
2957 DropPLangStmt *n = makeNode(DropPLangStmt);
2960 n->missing_ok = true;
2970 /*****************************************************************************
2973 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
2975 *****************************************************************************/
2977 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
2979 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
2980 n->tablespacename = $3;
2987 OptTableSpaceOwner: OWNER name { $$ = $2; }
2988 | /*EMPTY */ { $$ = NULL; }
2991 /*****************************************************************************
2994 * DROP TABLESPACE <tablespace>
2996 * No need for drop behaviour as we cannot implement dependencies for
2997 * objects in other databases; we can only support RESTRICT.
2999 ****************************************************************************/
3001 DropTableSpaceStmt: DROP TABLESPACE name
3003 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
3004 n->tablespacename = $3;
3005 n->missing_ok = false;
3008 | DROP TABLESPACE IF_P EXISTS name
3010 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
3011 n->tablespacename = $5;
3012 n->missing_ok = true;
3017 /*****************************************************************************
3020 * CREATE FOREIGN DATA WRAPPER name [ VALIDATOR name ]
3022 *****************************************************************************/
3024 CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_validator create_generic_options
3026 CreateFdwStmt *n = makeNode(CreateFdwStmt);
3034 /*****************************************************************************
3037 * DROP FOREIGN DATA WRAPPER name
3039 ****************************************************************************/
3041 DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
3043 DropFdwStmt *n = makeNode(DropFdwStmt);
3045 n->missing_ok = false;
3049 | DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior
3051 DropFdwStmt *n = makeNode(DropFdwStmt);
3053 n->missing_ok = true;
3059 /*****************************************************************************
3062 * ALTER FOREIGN DATA WRAPPER name
3064 ****************************************************************************/
3066 AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name validator_clause alter_generic_options
3068 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3071 n->change_validator = true;
3075 | ALTER FOREIGN DATA_P WRAPPER name validator_clause
3077 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3080 n->change_validator = true;
3083 | ALTER FOREIGN DATA_P WRAPPER name alter_generic_options
3085 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3092 /* Options definition for CREATE FDW, SERVER and USER MAPPING */
3093 create_generic_options:
3094 OPTIONS '(' generic_option_list ')' { $$ = $3; }
3095 | /*EMPTY*/ { $$ = NIL; }
3098 generic_option_list:
3101 $$ = list_make1($1);
3103 | generic_option_list ',' generic_option_elem
3105 $$ = lappend($1, $3);
3109 /* Options definition for ALTER FDW, SERVER and USER MAPPING */
3110 alter_generic_options:
3111 OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
3114 alter_generic_option_list:
3115 alter_generic_option_elem
3117 $$ = list_make1($1);
3119 | alter_generic_option_list ',' alter_generic_option_elem
3121 $$ = lappend($1, $3);
3125 alter_generic_option_elem:
3130 | SET generic_option_elem
3133 $$->defaction = DEFELEM_SET;
3135 | ADD_P generic_option_elem
3138 $$->defaction = DEFELEM_ADD;
3140 | DROP generic_option_name
3142 $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP);
3146 generic_option_elem:
3147 generic_option_name generic_option_arg
3149 $$ = makeDefElem($1, $2);
3153 generic_option_name:
3154 ColLabel { $$ = $1; }
3157 /* We could use def_arg here, but the spec only requires string literals */
3159 Sconst { $$ = (Node *) makeString($1); }
3162 /*****************************************************************************
3165 * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
3167 *****************************************************************************/
3169 CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
3170 FOREIGN DATA_P WRAPPER name create_generic_options
3172 CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
3183 TYPE_P Sconst { $$ = $2; }
3184 | /*EMPTY*/ { $$ = NULL; }
3188 foreign_server_version:
3189 VERSION_P Sconst { $$ = $2; }
3190 | VERSION_P NULL_P { $$ = NULL; }
3193 opt_foreign_server_version:
3194 foreign_server_version { $$ = $1; }
3195 | /*EMPTY*/ { $$ = NULL; }
3198 /*****************************************************************************
3203 ****************************************************************************/
3205 DropForeignServerStmt: DROP SERVER name opt_drop_behavior
3207 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3209 n->missing_ok = false;
3213 | DROP SERVER IF_P EXISTS name opt_drop_behavior
3215 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3217 n->missing_ok = true;
3223 /*****************************************************************************
3226 * ALTER SERVER name [VERSION] [OPTIONS]
3228 ****************************************************************************/
3230 AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
3232 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3236 n->has_version = true;
3239 | ALTER SERVER name foreign_server_version
3241 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3244 n->has_version = true;
3247 | ALTER SERVER name alter_generic_options
3249 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3256 /*****************************************************************************
3259 * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
3261 *****************************************************************************/
3263 CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
3265 CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
3273 /* User mapping authorization identifier */
3275 CURRENT_USER { $$ = "current_user"; }
3276 | USER { $$ = "current_user"; }
3277 | RoleId { $$ = (strcmp($1, "public") == 0) ? NULL : $1; }
3280 /*****************************************************************************
3283 * DROP USER MAPPING FOR auth_ident SERVER name
3285 ****************************************************************************/
3287 DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
3289 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3292 n->missing_ok = false;
3295 | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
3297 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3300 n->missing_ok = true;
3305 /*****************************************************************************
3308 * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
3310 ****************************************************************************/
3312 AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
3314 AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
3322 /*****************************************************************************
3325 * CREATE TRIGGER ...
3328 *****************************************************************************/
3331 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
3332 qualified_name TriggerForSpec TriggerWhen
3333 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3335 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3342 n->events = intVal(linitial($5));
3343 n->columns = (List *) lsecond($5);
3345 n->isconstraint = FALSE;
3346 n->deferrable = FALSE;
3347 n->initdeferred = FALSE;
3348 n->constrrel = NULL;
3351 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
3352 qualified_name OptConstrFromTable ConstraintAttributeSpec
3353 FOR EACH ROW TriggerWhen
3354 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3356 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3363 n->events = intVal(linitial($6));
3364 n->columns = (List *) lsecond($6);
3365 n->whenClause = $14;
3366 n->isconstraint = TRUE;
3367 n->deferrable = ($10 & 1) != 0;
3368 n->initdeferred = ($10 & 2) != 0;
3375 BEFORE { $$ = TRUE; }
3376 | AFTER { $$ = FALSE; }
3382 | TriggerEvents OR TriggerOneEvent
3384 int events1 = intVal(linitial($1));
3385 int events2 = intVal(linitial($3));
3386 List *columns1 = (List *) lsecond($1);
3387 List *columns2 = (List *) lsecond($3);
3389 if (events1 & events2)
3390 parser_yyerror("duplicate trigger events specified");
3392 * concat'ing the columns lists loses information about
3393 * which columns went with which event, but so long as
3394 * only UPDATE carries columns and we disallow multiple
3395 * UPDATE items, it doesn't matter. Command execution
3396 * should just ignore the columns for non-UPDATE events.
3398 $$ = list_make2(makeInteger(events1 | events2),
3399 list_concat(columns1, columns2));
3405 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
3407 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
3409 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
3410 | UPDATE OF columnList
3411 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
3413 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
3417 FOR TriggerForOpt TriggerForType
3424 * If ROW/STATEMENT not specified, default to
3425 * STATEMENT, per SQL
3438 | STATEMENT { $$ = FALSE; }
3442 WHEN '(' a_expr ')' { $$ = $3; }
3443 | /*EMPTY*/ { $$ = NULL; }
3447 TriggerFuncArg { $$ = list_make1($1); }
3448 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
3449 | /*EMPTY*/ { $$ = NIL; }
3456 snprintf(buf, sizeof(buf), "%d", $1);
3457 $$ = makeString(pstrdup(buf));
3459 | FCONST { $$ = makeString($1); }
3460 | Sconst { $$ = makeString($1); }
3461 | BCONST { $$ = makeString($1); }
3462 | XCONST { $$ = makeString($1); }
3463 | ColId { $$ = makeString($1); }
3467 FROM qualified_name { $$ = $2; }
3468 | /*EMPTY*/ { $$ = NULL; }
3471 ConstraintAttributeSpec:
3472 ConstraintDeferrabilitySpec
3474 | ConstraintDeferrabilitySpec ConstraintTimeSpec
3476 if ($1 == 0 && $2 != 0)
3478 (errcode(ERRCODE_SYNTAX_ERROR),
3479 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3480 parser_errposition(@1)));
3483 | ConstraintTimeSpec
3490 | ConstraintTimeSpec ConstraintDeferrabilitySpec
3492 if ($2 == 0 && $1 != 0)
3494 (errcode(ERRCODE_SYNTAX_ERROR),
3495 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3496 parser_errposition(@1)));
3503 ConstraintDeferrabilitySpec:
3504 NOT DEFERRABLE { $$ = 0; }
3505 | DEFERRABLE { $$ = 1; }
3509 INITIALLY IMMEDIATE { $$ = 0; }
3510 | INITIALLY DEFERRED { $$ = 2; }
3515 DROP TRIGGER name ON qualified_name opt_drop_behavior
3517 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3521 n->removeType = OBJECT_TRIGGER;
3522 n->missing_ok = false;
3525 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
3527 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3531 n->removeType = OBJECT_TRIGGER;
3532 n->missing_ok = true;
3538 /*****************************************************************************
3541 * CREATE ASSERTION ...
3542 * DROP ASSERTION ...
3544 *****************************************************************************/
3547 CREATE ASSERTION name CHECK '(' a_expr ')'
3548 ConstraintAttributeSpec
3550 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3552 n->args = list_make1($6);
3553 n->isconstraint = TRUE;
3554 n->deferrable = ($8 & 1) != 0;
3555 n->initdeferred = ($8 & 2) != 0;
3558 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3559 errmsg("CREATE ASSERTION is not yet implemented")));
3566 DROP ASSERTION name opt_drop_behavior
3568 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3572 n->removeType = OBJECT_TRIGGER; /* XXX */
3574 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3575 errmsg("DROP ASSERTION is not yet implemented")));
3581 /*****************************************************************************
3584 * define (aggregate,operator,type)
3586 *****************************************************************************/
3589 CREATE AGGREGATE func_name aggr_args definition
3591 DefineStmt *n = makeNode(DefineStmt);
3592 n->kind = OBJECT_AGGREGATE;
3593 n->oldstyle = false;
3599 | CREATE AGGREGATE func_name old_aggr_definition
3601 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
3602 DefineStmt *n = makeNode(DefineStmt);
3603 n->kind = OBJECT_AGGREGATE;
3610 | CREATE OPERATOR any_operator definition
3612 DefineStmt *n = makeNode(DefineStmt);
3613 n->kind = OBJECT_OPERATOR;
3614 n->oldstyle = false;
3620 | CREATE TYPE_P any_name definition
3622 DefineStmt *n = makeNode(DefineStmt);
3623 n->kind = OBJECT_TYPE;
3624 n->oldstyle = false;
3630 | CREATE TYPE_P any_name
3632 /* Shell type (identified by lack of definition) */
3633 DefineStmt *n = makeNode(DefineStmt);
3634 n->kind = OBJECT_TYPE;
3635 n->oldstyle = false;
3638 n->definition = NIL;
3641 | CREATE TYPE_P any_name AS '(' TableFuncElementList ')'
3643 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
3644 RangeVar *r = makeNode(RangeVar);
3646 /* can't use qualified_name, sigh */
3647 switch (list_length($3))
3650 r->catalogname = NULL;
3651 r->schemaname = NULL;
3652 r->relname = strVal(linitial($3));
3655 r->catalogname = NULL;
3656 r->schemaname = strVal(linitial($3));
3657 r->relname = strVal(lsecond($3));
3660 r->catalogname = strVal(linitial($3));
3661 r->schemaname = strVal(lsecond($3));
3662 r->relname = strVal(lthird($3));
3666 (errcode(ERRCODE_SYNTAX_ERROR),
3667 errmsg("improper qualified name (too many dotted names): %s",
3668 NameListToString($3)),
3669 parser_errposition(@3)));
3677 | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
3679 CreateEnumStmt *n = makeNode(CreateEnumStmt);
3684 | CREATE TEXT_P SEARCH PARSER any_name definition
3686 DefineStmt *n = makeNode(DefineStmt);
3687 n->kind = OBJECT_TSPARSER;
3693 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
3695 DefineStmt *n = makeNode(DefineStmt);
3696 n->kind = OBJECT_TSDICTIONARY;
3702 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
3704 DefineStmt *n = makeNode(DefineStmt);
3705 n->kind = OBJECT_TSTEMPLATE;
3711 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
3713 DefineStmt *n = makeNode(DefineStmt);
3714 n->kind = OBJECT_TSCONFIGURATION;
3722 definition: '(' def_list ')' { $$ = $2; }
3725 def_list: def_elem { $$ = list_make1($1); }
3726 | def_list ',' def_elem { $$ = lappend($1, $3); }
3729 def_elem: ColLabel '=' def_arg
3731 $$ = makeDefElem($1, (Node *) $3);
3735 $$ = makeDefElem($1, NULL);
3739 /* Note: any simple identifier will be returned as a type name! */
3740 def_arg: func_type { $$ = (Node *)$1; }
3741 | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
3742 | qual_all_Op { $$ = (Node *)$1; }
3743 | NumericOnly { $$ = (Node *)$1; }
3744 | Sconst { $$ = (Node *)makeString($1); }
3747 aggr_args: '(' type_list ')' { $$ = $2; }
3748 | '(' '*' ')' { $$ = NIL; }
3751 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
3754 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
3755 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
3759 * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
3760 * the item names needed in old aggregate definitions are likely to become
3763 old_aggr_elem: IDENT '=' def_arg
3765 $$ = makeDefElem($1, (Node *)$3);
3770 enum_val_list { $$ = $1; }
3771 | /*EMPTY*/ { $$ = NIL; }
3774 enum_val_list: Sconst
3775 { $$ = list_make1(makeString($1)); }
3776 | enum_val_list ',' Sconst
3777 { $$ = lappend($1, makeString($3)); }
3781 /*****************************************************************************
3784 * CREATE OPERATOR CLASS ...
3785 * CREATE OPERATOR FAMILY ...
3786 * ALTER OPERATOR FAMILY ...
3787 * DROP OPERATOR CLASS ...
3788 * DROP OPERATOR FAMILY ...
3790 *****************************************************************************/
3793 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
3794 USING access_method opt_opfamily AS opclass_item_list
3796 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
3797 n->opclassname = $4;
3801 n->opfamilyname = $11;
3808 opclass_item { $$ = list_make1($1); }
3809 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
3813 OPERATOR Iconst any_operator opt_recheck
3815 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3816 n->itemtype = OPCLASS_ITEM_OPERATOR;
3822 | OPERATOR Iconst any_operator oper_argtypes opt_recheck
3824 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3825 n->itemtype = OPCLASS_ITEM_OPERATOR;
3831 | FUNCTION Iconst func_name func_args
3833 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3834 n->itemtype = OPCLASS_ITEM_FUNCTION;
3836 n->args = extractArgTypes($4);
3840 | FUNCTION Iconst '(' type_list ')' func_name func_args
3842 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3843 n->itemtype = OPCLASS_ITEM_FUNCTION;
3845 n->args = extractArgTypes($7);
3852 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3853 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
3859 opt_default: DEFAULT { $$ = TRUE; }
3860 | /*EMPTY*/ { $$ = FALSE; }
3863 opt_opfamily: FAMILY any_name { $$ = $2; }
3864 | /*EMPTY*/ { $$ = NIL; }
3867 opt_recheck: RECHECK
3870 * RECHECK no longer does anything in opclass definitions,
3871 * but we still accept it to ease porting of old database
3875 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3876 errmsg("RECHECK is no longer required"),
3877 errhint("Update your data type."),
3878 parser_errposition(@1)));
3881 | /*EMPTY*/ { $$ = FALSE; }
3886 CREATE OPERATOR FAMILY any_name USING access_method
3888 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
3889 n->opfamilyname = $4;
3896 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
3898 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3899 n->opfamilyname = $4;
3905 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
3907 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3908 n->opfamilyname = $4;
3917 opclass_drop { $$ = list_make1($1); }
3918 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
3922 OPERATOR Iconst '(' type_list ')'
3924 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3925 n->itemtype = OPCLASS_ITEM_OPERATOR;
3930 | FUNCTION Iconst '(' type_list ')'
3932 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3933 n->itemtype = OPCLASS_ITEM_FUNCTION;
3942 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
3944 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3945 n->opclassname = $4;
3948 n->missing_ok = false;
3951 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
3953 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3954 n->opclassname = $6;
3957 n->missing_ok = true;
3963 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
3965 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3966 n->opfamilyname = $4;
3969 n->missing_ok = false;
3972 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
3974 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3975 n->opfamilyname = $6;
3978 n->missing_ok = true;
3984 /*****************************************************************************
3988 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
3989 * REASSIGN OWNED BY username [, username ...] TO username
3991 *****************************************************************************/
3993 DROP OWNED BY name_list opt_drop_behavior
3995 DropOwnedStmt *n = makeNode(DropOwnedStmt);
4003 REASSIGN OWNED BY name_list TO name
4005 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
4012 /*****************************************************************************
4016 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
4017 * [ RESTRICT | CASCADE ]
4019 *****************************************************************************/
4021 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
4023 DropStmt *n = makeNode(DropStmt);
4025 n->missing_ok = TRUE;
4030 | DROP drop_type any_name_list opt_drop_behavior
4032 DropStmt *n = makeNode(DropStmt);
4034 n->missing_ok = FALSE;
4042 drop_type: TABLE { $$ = OBJECT_TABLE; }
4043 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4044 | VIEW { $$ = OBJECT_VIEW; }
4045 | INDEX { $$ = OBJECT_INDEX; }
4046 | TYPE_P { $$ = OBJECT_TYPE; }
4047 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
4048 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4049 | SCHEMA { $$ = OBJECT_SCHEMA; }
4050 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
4051 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
4052 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
4053 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
4057 any_name { $$ = list_make1($1); }
4058 | any_name_list ',' any_name { $$ = lappend($1, $3); }
4061 any_name: ColId { $$ = list_make1(makeString($1)); }
4062 | ColId attrs { $$ = lcons(makeString($1), $2); }
4065 attrs: '.' attr_name
4066 { $$ = list_make1(makeString($2)); }
4067 | attrs '.' attr_name
4068 { $$ = lappend($1, makeString($3)); }
4072 /*****************************************************************************
4075 * truncate table relname1, relname2, ...
4077 *****************************************************************************/
4080 TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
4082 TruncateStmt *n = makeNode(TruncateStmt);
4084 n->restart_seqs = $4;
4091 CONTINUE_P IDENTITY_P { $$ = false; }
4092 | RESTART IDENTITY_P { $$ = true; }
4093 | /* EMPTY */ { $$ = false; }
4096 /*****************************************************************************
4098 * The COMMENT ON statement can take different forms based upon the type of
4099 * the object associated with the comment. The form of the statement is:
4101 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
4102 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
4103 * CAST | COLUMN | SCHEMA | TABLESPACE | ROLE |
4104 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
4105 * TEXT SEARCH TEMPLATE |
4106 * TEXT SEARCH CONFIGURATION ] <objname> |
4107 * AGGREGATE <aggname> (arg1, ...) |
4108 * FUNCTION <funcname> (arg1, arg2, ...) |
4109 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
4110 * TRIGGER <triggername> ON <relname> |
4111 * CONSTRAINT <constraintname> ON <relname> |
4112 * RULE <rulename> ON <relname> ]
4115 *****************************************************************************/
4118 COMMENT ON comment_type any_name IS comment_text
4120 CommentStmt *n = makeNode(CommentStmt);
4127 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
4129 CommentStmt *n = makeNode(CommentStmt);
4130 n->objtype = OBJECT_AGGREGATE;
4136 | COMMENT ON FUNCTION func_name func_args IS comment_text
4138 CommentStmt *n = makeNode(CommentStmt);
4139 n->objtype = OBJECT_FUNCTION;
4141 n->objargs = extractArgTypes($5);
4145 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
4147 CommentStmt *n = makeNode(CommentStmt);
4148 n->objtype = OBJECT_OPERATOR;
4154 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
4156 CommentStmt *n = makeNode(CommentStmt);
4157 n->objtype = OBJECT_CONSTRAINT;
4158 n->objname = lappend($6, makeString($4));
4163 | COMMENT ON RULE name ON any_name IS comment_text
4165 CommentStmt *n = makeNode(CommentStmt);
4166 n->objtype = OBJECT_RULE;
4167 n->objname = lappend($6, makeString($4));
4172 | COMMENT ON RULE name IS comment_text
4174 /* Obsolete syntax supported for awhile for compatibility */
4175 CommentStmt *n = makeNode(CommentStmt);
4176 n->objtype = OBJECT_RULE;
4177 n->objname = list_make1(makeString($4));
4182 | COMMENT ON TRIGGER name ON any_name IS comment_text
4184 CommentStmt *n = makeNode(CommentStmt);
4185 n->objtype = OBJECT_TRIGGER;
4186 n->objname = lappend($6, makeString($4));
4191 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
4193 CommentStmt *n = makeNode(CommentStmt);
4194 n->objtype = OBJECT_OPCLASS;
4196 n->objargs = list_make1(makeString($7));
4200 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
4202 CommentStmt *n = makeNode(CommentStmt);
4203 n->objtype = OBJECT_OPFAMILY;
4205 n->objargs = list_make1(makeString($7));
4209 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
4211 CommentStmt *n = makeNode(CommentStmt);
4212 n->objtype = OBJECT_LARGEOBJECT;
4213 n->objname = list_make1($5);
4218 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
4220 CommentStmt *n = makeNode(CommentStmt);
4221 n->objtype = OBJECT_CAST;
4222 n->objname = list_make1($5);
4223 n->objargs = list_make1($7);
4227 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
4229 CommentStmt *n = makeNode(CommentStmt);
4230 n->objtype = OBJECT_LANGUAGE;
4236 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
4238 CommentStmt *n = makeNode(CommentStmt);
4239 n->objtype = OBJECT_TSPARSER;
4244 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
4246 CommentStmt *n = makeNode(CommentStmt);
4247 n->objtype = OBJECT_TSDICTIONARY;
4252 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
4254 CommentStmt *n = makeNode(CommentStmt);
4255 n->objtype = OBJECT_TSTEMPLATE;
4260 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
4262 CommentStmt *n = makeNode(CommentStmt);
4263 n->objtype = OBJECT_TSCONFIGURATION;
4271 COLUMN { $$ = OBJECT_COLUMN; }
4272 | DATABASE { $$ = OBJECT_DATABASE; }
4273 | SCHEMA { $$ = OBJECT_SCHEMA; }
4274 | INDEX { $$ = OBJECT_INDEX; }
4275 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4276 | TABLE { $$ = OBJECT_TABLE; }
4277 | DOMAIN_P { $$ = OBJECT_TYPE; }
4278 | TYPE_P { $$ = OBJECT_TYPE; }
4279 | VIEW { $$ = OBJECT_VIEW; }
4280 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4281 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
4282 | ROLE { $$ = OBJECT_ROLE; }
4287 | NULL_P { $$ = NULL; }
4290 /*****************************************************************************
4295 *****************************************************************************/
4297 FetchStmt: FETCH fetch_args
4299 FetchStmt *n = (FetchStmt *) $2;
4305 FetchStmt *n = (FetchStmt *) $2;
4311 fetch_args: cursor_name
4313 FetchStmt *n = makeNode(FetchStmt);
4315 n->direction = FETCH_FORWARD;
4319 | from_in cursor_name
4321 FetchStmt *n = makeNode(FetchStmt);
4323 n->direction = FETCH_FORWARD;
4327 | NEXT opt_from_in cursor_name
4329 FetchStmt *n = makeNode(FetchStmt);
4331 n->direction = FETCH_FORWARD;
4335 | PRIOR opt_from_in cursor_name
4337 FetchStmt *n = makeNode(FetchStmt);
4339 n->direction = FETCH_BACKWARD;
4343 | FIRST_P opt_from_in cursor_name
4345 FetchStmt *n = makeNode(FetchStmt);
4347 n->direction = FETCH_ABSOLUTE;
4351 | LAST_P opt_from_in cursor_name
4353 FetchStmt *n = makeNode(FetchStmt);
4355 n->direction = FETCH_ABSOLUTE;
4359 | ABSOLUTE_P SignedIconst opt_from_in cursor_name
4361 FetchStmt *n = makeNode(FetchStmt);
4363 n->direction = FETCH_ABSOLUTE;
4367 | RELATIVE_P SignedIconst opt_from_in cursor_name
4369 FetchStmt *n = makeNode(FetchStmt);
4371 n->direction = FETCH_RELATIVE;
4375 | SignedIconst opt_from_in cursor_name
4377 FetchStmt *n = makeNode(FetchStmt);
4379 n->direction = FETCH_FORWARD;
4383 | ALL opt_from_in cursor_name
4385 FetchStmt *n = makeNode(FetchStmt);
4387 n->direction = FETCH_FORWARD;
4388 n->howMany = FETCH_ALL;
4391 | FORWARD opt_from_in cursor_name
4393 FetchStmt *n = makeNode(FetchStmt);
4395 n->direction = FETCH_FORWARD;
4399 | FORWARD SignedIconst opt_from_in cursor_name
4401 FetchStmt *n = makeNode(FetchStmt);
4403 n->direction = FETCH_FORWARD;
4407 | FORWARD ALL opt_from_in cursor_name
4409 FetchStmt *n = makeNode(FetchStmt);
4411 n->direction = FETCH_FORWARD;
4412 n->howMany = FETCH_ALL;
4415 | BACKWARD opt_from_in cursor_name
4417 FetchStmt *n = makeNode(FetchStmt);
4419 n->direction = FETCH_BACKWARD;
4423 | BACKWARD SignedIconst opt_from_in cursor_name
4425 FetchStmt *n = makeNode(FetchStmt);
4427 n->direction = FETCH_BACKWARD;
4431 | BACKWARD ALL opt_from_in cursor_name
4433 FetchStmt *n = makeNode(FetchStmt);
4435 n->direction = FETCH_BACKWARD;
4436 n->howMany = FETCH_ALL;
4445 opt_from_in: from_in {}
4450 /*****************************************************************************
4452 * GRANT and REVOKE statements
4454 *****************************************************************************/
4456 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
4457 opt_grant_grant_option
4459 GrantStmt *n = makeNode(GrantStmt);
4462 n->targtype = ($4)->targtype;
4463 n->objtype = ($4)->objtype;
4464 n->objects = ($4)->objs;
4466 n->grant_option = $7;
4472 REVOKE privileges ON privilege_target
4473 FROM grantee_list opt_drop_behavior
4475 GrantStmt *n = makeNode(GrantStmt);
4476 n->is_grant = false;
4477 n->grant_option = false;
4479 n->targtype = ($4)->targtype;
4480 n->objtype = ($4)->objtype;
4481 n->objects = ($4)->objs;
4486 | REVOKE GRANT OPTION FOR privileges ON privilege_target
4487 FROM grantee_list opt_drop_behavior
4489 GrantStmt *n = makeNode(GrantStmt);
4490 n->is_grant = false;
4491 n->grant_option = true;
4493 n->targtype = ($7)->targtype;
4494 n->objtype = ($7)->objtype;
4495 n->objects = ($7)->objs;
4504 * Privilege names are represented as strings; the validity of the privilege
4505 * names gets checked at execution. This is a bit annoying but we have little
4506 * choice because of the syntactic conflict with lists of role names in
4507 * GRANT/REVOKE. What's more, we have to call out in the "privilege"
4508 * production any reserved keywords that need to be usable as privilege names.
4511 /* either ALL [PRIVILEGES] or a list of individual privileges */
4512 privileges: privilege_list
4518 | ALL '(' columnList ')'
4520 AccessPriv *n = makeNode(AccessPriv);
4521 n->priv_name = NULL;
4525 | ALL PRIVILEGES '(' columnList ')'
4527 AccessPriv *n = makeNode(AccessPriv);
4528 n->priv_name = NULL;
4534 privilege_list: privilege { $$ = list_make1($1); }
4535 | privilege_list ',' privilege { $$ = lappend($1, $3); }
4538 privilege: SELECT opt_column_list
4540 AccessPriv *n = makeNode(AccessPriv);
4541 n->priv_name = pstrdup($1);
4545 | REFERENCES opt_column_list
4547 AccessPriv *n = makeNode(AccessPriv);
4548 n->priv_name = pstrdup($1);
4552 | CREATE opt_column_list
4554 AccessPriv *n = makeNode(AccessPriv);
4555 n->priv_name = pstrdup($1);
4559 | ColId opt_column_list
4561 AccessPriv *n = makeNode(AccessPriv);
4569 /* Don't bother trying to fold the first two rules into one using
4570 * opt_table. You're going to get conflicts.
4575 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4576 n->targtype = ACL_TARGET_OBJECT;
4577 n->objtype = ACL_OBJECT_RELATION;
4581 | TABLE qualified_name_list
4583 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4584 n->targtype = ACL_TARGET_OBJECT;
4585 n->objtype = ACL_OBJECT_RELATION;
4589 | SEQUENCE qualified_name_list
4591 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4592 n->targtype = ACL_TARGET_OBJECT;
4593 n->objtype = ACL_OBJECT_SEQUENCE;
4597 | FOREIGN DATA_P WRAPPER name_list
4599 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4600 n->targtype = ACL_TARGET_OBJECT;
4601 n->objtype = ACL_OBJECT_FDW;
4605 | FOREIGN SERVER name_list
4607 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4608 n->targtype = ACL_TARGET_OBJECT;
4609 n->objtype = ACL_OBJECT_FOREIGN_SERVER;
4613 | FUNCTION function_with_argtypes_list
4615 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4616 n->targtype = ACL_TARGET_OBJECT;
4617 n->objtype = ACL_OBJECT_FUNCTION;
4621 | DATABASE name_list
4623 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4624 n->targtype = ACL_TARGET_OBJECT;
4625 n->objtype = ACL_OBJECT_DATABASE;
4629 | LANGUAGE name_list
4631 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4632 n->targtype = ACL_TARGET_OBJECT;
4633 n->objtype = ACL_OBJECT_LANGUAGE;
4637 | LARGE_P OBJECT_P Iconst_list
4639 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4640 n->targtype = ACL_TARGET_OBJECT;
4641 n->objtype = ACL_OBJECT_LARGEOBJECT;
4647 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4648 n->targtype = ACL_TARGET_OBJECT;
4649 n->objtype = ACL_OBJECT_NAMESPACE;
4653 | TABLESPACE name_list
4655 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4656 n->targtype = ACL_TARGET_OBJECT;
4657 n->objtype = ACL_OBJECT_TABLESPACE;
4661 | ALL TABLES IN_P SCHEMA name_list
4663 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4664 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4665 n->objtype = ACL_OBJECT_RELATION;
4669 | ALL SEQUENCES IN_P SCHEMA name_list
4671 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4672 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4673 n->objtype = ACL_OBJECT_SEQUENCE;
4677 | ALL FUNCTIONS IN_P SCHEMA name_list
4679 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4680 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4681 n->objtype = ACL_OBJECT_FUNCTION;
4689 grantee { $$ = list_make1($1); }
4690 | grantee_list ',' grantee { $$ = lappend($1, $3); }
4695 PrivGrantee *n = makeNode(PrivGrantee);
4696 /* This hack lets us avoid reserving PUBLIC as a keyword*/
4697 if (strcmp($1, "public") == 0)
4705 PrivGrantee *n = makeNode(PrivGrantee);
4706 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
4707 if (strcmp($2, "public") == 0)
4716 opt_grant_grant_option:
4717 WITH GRANT OPTION { $$ = TRUE; }
4718 | /*EMPTY*/ { $$ = FALSE; }
4721 function_with_argtypes_list:
4722 function_with_argtypes { $$ = list_make1($1); }
4723 | function_with_argtypes_list ',' function_with_argtypes
4724 { $$ = lappend($1, $3); }
4727 function_with_argtypes:
4730 FuncWithArgs *n = makeNode(FuncWithArgs);
4732 n->funcargs = extractArgTypes($2);
4737 /*****************************************************************************
4739 * GRANT and REVOKE ROLE statements
4741 *****************************************************************************/
4744 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4746 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4748 n->granted_roles = $2;
4749 n->grantee_roles = $4;
4757 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4759 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4760 n->is_grant = false;
4761 n->admin_opt = false;
4762 n->granted_roles = $2;
4763 n->grantee_roles = $4;
4767 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4769 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4770 n->is_grant = false;
4771 n->admin_opt = true;
4772 n->granted_roles = $5;
4773 n->grantee_roles = $7;
4779 opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
4780 | /*EMPTY*/ { $$ = FALSE; }
4783 opt_granted_by: GRANTED BY RoleId { $$ = $3; }
4784 | /*EMPTY*/ { $$ = NULL; }
4787 /*****************************************************************************
4789 * ALTER DEFAULT PRIVILEGES statement
4791 *****************************************************************************/
4793 AlterDefaultPrivilegesStmt:
4794 ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
4796 AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
4798 n->action = (GrantStmt *) $5;
4804 DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
4805 | /* EMPTY */ { $$ = NIL; }
4809 IN_P SCHEMA name_list
4811 $$ = makeDefElem("schemas", (Node *)$3);
4813 | FOR ROLE name_list
4815 $$ = makeDefElem("roles", (Node *)$3);
4817 | FOR USER name_list
4819 $$ = makeDefElem("roles", (Node *)$3);
4824 * This should match GRANT/REVOKE, except that individual target objects
4825 * are not mentioned and we only allow a subset of object types.
4828 GRANT privileges ON defacl_privilege_target TO grantee_list
4829 opt_grant_grant_option
4831 GrantStmt *n = makeNode(GrantStmt);
4834 n->targtype = ACL_TARGET_DEFAULTS;
4838 n->grant_option = $7;
4841 | REVOKE privileges ON defacl_privilege_target
4842 FROM grantee_list opt_drop_behavior
4844 GrantStmt *n = makeNode(GrantStmt);
4845 n->is_grant = false;
4846 n->grant_option = false;
4848 n->targtype = ACL_TARGET_DEFAULTS;
4855 | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
4856 FROM grantee_list opt_drop_behavior
4858 GrantStmt *n = makeNode(GrantStmt);
4859 n->is_grant = false;
4860 n->grant_option = true;
4862 n->targtype = ACL_TARGET_DEFAULTS;
4871 defacl_privilege_target:
4872 TABLES { $$ = ACL_OBJECT_RELATION; }
4873 | FUNCTIONS { $$ = ACL_OBJECT_FUNCTION; }
4874 | SEQUENCES { $$ = ACL_OBJECT_SEQUENCE; }
4878 /*****************************************************************************
4880 * QUERY: CREATE INDEX
4882 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
4883 * willing to make TABLESPACE a fully reserved word.
4884 *****************************************************************************/
4886 IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_index_name
4887 ON qualified_name access_method_clause '(' index_params ')'
4888 opt_reloptions OptTableSpace where_clause
4890 IndexStmt *n = makeNode(IndexStmt);
4895 n->accessMethod = $8;
4896 n->indexParams = $10;
4898 n->tableSpace = $13;
4899 n->whereClause = $14;
4905 UNIQUE { $$ = TRUE; }
4906 | /*EMPTY*/ { $$ = FALSE; }
4910 CONCURRENTLY { $$ = TRUE; }
4911 | /*EMPTY*/ { $$ = FALSE; }
4915 index_name { $$ = $1; }
4916 | /*EMPTY*/ { $$ = NULL; }
4919 access_method_clause:
4920 USING access_method { $$ = $2; }
4921 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
4924 index_params: index_elem { $$ = list_make1($1); }
4925 | index_params ',' index_elem { $$ = lappend($1, $3); }
4929 * Index attributes can be either simple column references, or arbitrary
4930 * expressions in parens. For backwards-compatibility reasons, we allow
4931 * an expression that's just a function call to be written without parens.
4933 index_elem: ColId opt_class opt_asc_desc opt_nulls_order
4935 $$ = makeNode(IndexElem);
4938 $$->indexcolname = NULL;
4941 $$->nulls_ordering = $4;
4943 | func_expr opt_class opt_asc_desc opt_nulls_order
4945 $$ = makeNode(IndexElem);
4948 $$->indexcolname = NULL;
4951 $$->nulls_ordering = $4;
4953 | '(' a_expr ')' opt_class opt_asc_desc opt_nulls_order
4955 $$ = makeNode(IndexElem);
4958 $$->indexcolname = NULL;
4961 $$->nulls_ordering = $6;
4965 opt_class: any_name { $$ = $1; }
4966 | USING any_name { $$ = $2; }
4967 | /*EMPTY*/ { $$ = NIL; }
4970 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
4971 | DESC { $$ = SORTBY_DESC; }
4972 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
4975 opt_nulls_order: NULLS_FIRST { $$ = SORTBY_NULLS_FIRST; }
4976 | NULLS_LAST { $$ = SORTBY_NULLS_LAST; }
4977 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
4981 /*****************************************************************************
4984 * create [or replace] function <fname>
4985 * [(<type-1> { , <type-n>})]
4987 * as <filename or code in language as appropriate>
4988 * language <lang> [with parameters]
4990 *****************************************************************************/
4993 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4994 RETURNS func_return createfunc_opt_list opt_definition
4996 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5005 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5006 RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
5008 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5011 n->parameters = mergeTableFuncParameters($5, $9);
5012 n->returnType = TableFuncTypeName($9);
5013 n->returnType->location = @7;
5015 n->withClause = $12;
5018 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5019 createfunc_opt_list opt_definition
5021 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5025 n->returnType = NULL;
5033 OR REPLACE { $$ = TRUE; }
5034 | /*EMPTY*/ { $$ = FALSE; }
5037 func_args: '(' func_args_list ')' { $$ = $2; }
5038 | '(' ')' { $$ = NIL; }
5042 func_arg { $$ = list_make1($1); }
5043 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
5047 * func_args_with_defaults is separate because we only want to accept
5048 * defaults in CREATE FUNCTION, not in ALTER etc.
5050 func_args_with_defaults:
5051 '(' func_args_with_defaults_list ')' { $$ = $2; }
5052 | '(' ')' { $$ = NIL; }
5055 func_args_with_defaults_list:
5056 func_arg_with_default { $$ = list_make1($1); }
5057 | func_args_with_defaults_list ',' func_arg_with_default
5058 { $$ = lappend($1, $3); }
5062 * The style with arg_class first is SQL99 standard, but Oracle puts
5063 * param_name first; accept both since it's likely people will try both
5064 * anyway. Don't bother trying to save productions by letting arg_class
5065 * have an empty alternative ... you'll get shift/reduce conflicts.
5067 * We can catch over-specified arguments here if we want to,
5068 * but for now better to silently swallow typmod, etc.
5069 * - thomas 2000-03-22
5072 arg_class param_name func_type
5074 FunctionParameter *n = makeNode(FunctionParameter);
5081 | param_name arg_class func_type
5083 FunctionParameter *n = makeNode(FunctionParameter);
5090 | param_name func_type
5092 FunctionParameter *n = makeNode(FunctionParameter);
5095 n->mode = FUNC_PARAM_IN;
5099 | arg_class func_type
5101 FunctionParameter *n = makeNode(FunctionParameter);
5110 FunctionParameter *n = makeNode(FunctionParameter);
5113 n->mode = FUNC_PARAM_IN;
5119 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
5120 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
5121 | OUT_P { $$ = FUNC_PARAM_OUT; }
5122 | INOUT { $$ = FUNC_PARAM_INOUT; }
5123 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
5124 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
5128 * Ideally param_name should be ColId, but that causes too many conflicts.
5130 param_name: type_function_name
5136 /* We can catch over-specified results here if we want to,
5137 * but for now better to silently swallow typmod, etc.
5138 * - thomas 2000-03-22
5145 * We would like to make the %TYPE productions here be ColId attrs etc,
5146 * but that causes reduce/reduce conflicts. type_function_name
5147 * is next best choice.
5149 func_type: Typename { $$ = $1; }
5150 | type_function_name attrs '%' TYPE_P
5152 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
5153 $$->pct_type = true;
5156 | SETOF type_function_name attrs '%' TYPE_P
5158 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
5159 $$->pct_type = true;
5165 func_arg_with_default:
5170 | func_arg DEFAULT a_expr
5175 | func_arg '=' a_expr
5183 createfunc_opt_list:
5184 /* Must be at least one to prevent conflict */
5185 createfunc_opt_item { $$ = list_make1($1); }
5186 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
5190 * Options common to both CREATE FUNCTION and ALTER FUNCTION
5192 common_func_opt_item:
5193 CALLED ON NULL_P INPUT_P
5195 $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
5197 | RETURNS NULL_P ON NULL_P INPUT_P
5199 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5203 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5207 $$ = makeDefElem("volatility", (Node *)makeString("immutable"));
5211 $$ = makeDefElem("volatility", (Node *)makeString("stable"));
5215 $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
5217 | EXTERNAL SECURITY DEFINER
5219 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5221 | EXTERNAL SECURITY INVOKER
5223 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5227 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5231 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5235 $$ = makeDefElem("cost", (Node *)$2);
5239 $$ = makeDefElem("rows", (Node *)$2);
5243 /* we abuse the normal content of a DefElem here */
5244 $$ = makeDefElem("set", (Node *)$1);
5248 createfunc_opt_item:
5251 $$ = makeDefElem("as", (Node *)$2);
5253 | LANGUAGE ColId_or_Sconst
5255 $$ = makeDefElem("language", (Node *)makeString($2));
5259 $$ = makeDefElem("window", (Node *)makeInteger(TRUE));
5261 | common_func_opt_item
5267 func_as: Sconst { $$ = list_make1(makeString($1)); }
5270 $$ = list_make2(makeString($1), makeString($3));
5275 WITH definition { $$ = $2; }
5276 | /*EMPTY*/ { $$ = NIL; }
5279 table_func_column: param_name func_type
5281 FunctionParameter *n = makeNode(FunctionParameter);
5284 n->mode = FUNC_PARAM_TABLE;
5290 table_func_column_list:
5293 $$ = list_make1($1);
5295 | table_func_column_list ',' table_func_column
5297 $$ = lappend($1, $3);
5301 /*****************************************************************************
5304 * RENAME and OWNER subcommands are already provided by the generic
5305 * ALTER infrastructure, here we just specify alterations that can
5306 * only be applied to functions.
5308 *****************************************************************************/
5310 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
5312 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
5320 /* At least one option must be specified */
5321 common_func_opt_item { $$ = list_make1($1); }
5322 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
5325 /* Ignored, merely for SQL compliance */
5332 /*****************************************************************************
5336 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
5337 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
5338 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
5340 *****************************************************************************/
5343 DROP FUNCTION func_name func_args opt_drop_behavior
5345 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5346 n->kind = OBJECT_FUNCTION;
5348 n->args = extractArgTypes($4);
5350 n->missing_ok = false;
5353 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
5355 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5356 n->kind = OBJECT_FUNCTION;
5358 n->args = extractArgTypes($6);
5360 n->missing_ok = true;
5366 DROP AGGREGATE func_name aggr_args opt_drop_behavior
5368 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5369 n->kind = OBJECT_AGGREGATE;
5373 n->missing_ok = false;
5376 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
5378 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5379 n->kind = OBJECT_AGGREGATE;
5383 n->missing_ok = true;
5389 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
5391 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5392 n->kind = OBJECT_OPERATOR;
5396 n->missing_ok = false;
5399 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
5401 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5402 n->kind = OBJECT_OPERATOR;
5406 n->missing_ok = true;
5415 (errcode(ERRCODE_SYNTAX_ERROR),
5416 errmsg("missing argument"),
5417 errhint("Use NONE to denote the missing argument of a unary operator."),
5418 parser_errposition(@3)));
5420 | '(' Typename ',' Typename ')'
5421 { $$ = list_make2($2, $4); }
5422 | '(' NONE ',' Typename ')' /* left unary */
5423 { $$ = list_make2(NULL, $4); }
5424 | '(' Typename ',' NONE ')' /* right unary */
5425 { $$ = list_make2($2, NULL); }
5430 { $$ = list_make1(makeString($1)); }
5431 | ColId '.' any_operator
5432 { $$ = lcons(makeString($1), $3); }
5435 /*****************************************************************************
5437 * DO <anonymous code block> [ LANGUAGE language ]
5439 * We use a DefElem list for future extensibility, and to allow flexibility
5440 * in the clause order.
5442 *****************************************************************************/
5444 DoStmt: DO dostmt_opt_list
5446 DoStmt *n = makeNode(DoStmt);
5453 dostmt_opt_item { $$ = list_make1($1); }
5454 | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
5460 $$ = makeDefElem("as", (Node *)makeString($1));
5462 | LANGUAGE ColId_or_Sconst
5464 $$ = makeDefElem("language", (Node *)makeString($2));
5468 /*****************************************************************************
5470 * CREATE CAST / DROP CAST
5472 *****************************************************************************/
5474 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
5475 WITH FUNCTION function_with_argtypes cast_context
5477 CreateCastStmt *n = makeNode(CreateCastStmt);
5481 n->context = (CoercionContext) $11;
5485 | CREATE CAST '(' Typename AS Typename ')'
5486 WITHOUT FUNCTION cast_context
5488 CreateCastStmt *n = makeNode(CreateCastStmt);
5492 n->context = (CoercionContext) $10;
5496 | CREATE CAST '(' Typename AS Typename ')'
5497 WITH INOUT cast_context
5499 CreateCastStmt *n = makeNode(CreateCastStmt);
5503 n->context = (CoercionContext) $10;
5509 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
5510 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
5511 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
5515 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
5517 DropCastStmt *n = makeNode(DropCastStmt);
5526 opt_if_exists: IF_P EXISTS { $$ = TRUE; }
5527 | /*EMPTY*/ { $$ = FALSE; }
5531 /*****************************************************************************
5535 * REINDEX type <name> [FORCE]
5537 * FORCE no longer does anything, but we accept it for backwards compatibility
5538 *****************************************************************************/
5541 REINDEX reindex_type qualified_name opt_force
5543 ReindexStmt *n = makeNode(ReindexStmt);
5549 | REINDEX SYSTEM_P name opt_force
5551 ReindexStmt *n = makeNode(ReindexStmt);
5552 n->kind = OBJECT_DATABASE;
5555 n->do_system = true;
5559 | REINDEX DATABASE name opt_force
5561 ReindexStmt *n = makeNode(ReindexStmt);
5562 n->kind = OBJECT_DATABASE;
5565 n->do_system = true;
5572 INDEX { $$ = OBJECT_INDEX; }
5573 | TABLE { $$ = OBJECT_TABLE; }
5576 opt_force: FORCE { $$ = TRUE; }
5577 | /* EMPTY */ { $$ = FALSE; }
5581 /*****************************************************************************
5583 * ALTER THING name RENAME TO newname
5585 *****************************************************************************/
5587 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
5589 RenameStmt *n = makeNode(RenameStmt);
5590 n->renameType = OBJECT_AGGREGATE;
5596 | ALTER CONVERSION_P any_name RENAME TO name
5598 RenameStmt *n = makeNode(RenameStmt);
5599 n->renameType = OBJECT_CONVERSION;
5604 | ALTER DATABASE database_name RENAME TO database_name
5606 RenameStmt *n = makeNode(RenameStmt);
5607 n->renameType = OBJECT_DATABASE;
5612 | ALTER FUNCTION function_with_argtypes RENAME TO name
5614 RenameStmt *n = makeNode(RenameStmt);
5615 n->renameType = OBJECT_FUNCTION;
5616 n->object = $3->funcname;
5617 n->objarg = $3->funcargs;
5621 | ALTER GROUP_P RoleId RENAME TO RoleId
5623 RenameStmt *n = makeNode(RenameStmt);
5624 n->renameType = OBJECT_ROLE;
5629 | ALTER opt_procedural LANGUAGE name RENAME TO name
5631 RenameStmt *n = makeNode(RenameStmt);
5632 n->renameType = OBJECT_LANGUAGE;
5637 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
5639 RenameStmt *n = makeNode(RenameStmt);
5640 n->renameType = OBJECT_OPCLASS;
5646 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
5648 RenameStmt *n = makeNode(RenameStmt);
5649 n->renameType = OBJECT_OPFAMILY;
5655 | ALTER SCHEMA name RENAME TO name
5657 RenameStmt *n = makeNode(RenameStmt);
5658 n->renameType = OBJECT_SCHEMA;
5663 | ALTER TABLE relation_expr RENAME TO name
5665 RenameStmt *n = makeNode(RenameStmt);
5666 n->renameType = OBJECT_TABLE;
5672 | ALTER SEQUENCE qualified_name RENAME TO name
5674 RenameStmt *n = makeNode(RenameStmt);
5675 n->renameType = OBJECT_SEQUENCE;
5681 | ALTER VIEW qualified_name RENAME TO name
5683 RenameStmt *n = makeNode(RenameStmt);
5684 n->renameType = OBJECT_VIEW;
5690 | ALTER INDEX qualified_name RENAME TO name
5692 RenameStmt *n = makeNode(RenameStmt);
5693 n->renameType = OBJECT_INDEX;
5699 | ALTER TABLE relation_expr RENAME opt_column name TO name
5701 RenameStmt *n = makeNode(RenameStmt);
5702 n->renameType = OBJECT_COLUMN;
5708 | ALTER TRIGGER name ON qualified_name RENAME TO name
5710 RenameStmt *n = makeNode(RenameStmt);
5711 n->renameType = OBJECT_TRIGGER;
5717 | ALTER ROLE RoleId RENAME TO RoleId
5719 RenameStmt *n = makeNode(RenameStmt);
5720 n->renameType = OBJECT_ROLE;
5725 | ALTER USER RoleId RENAME TO RoleId
5727 RenameStmt *n = makeNode(RenameStmt);
5728 n->renameType = OBJECT_ROLE;
5733 | ALTER TABLESPACE name RENAME TO name
5735 RenameStmt *n = makeNode(RenameStmt);
5736 n->renameType = OBJECT_TABLESPACE;
5741 | ALTER TABLESPACE name SET reloptions
5743 AlterTableSpaceOptionsStmt *n =
5744 makeNode(AlterTableSpaceOptionsStmt);
5745 n->tablespacename = $3;
5750 | ALTER TABLESPACE name RESET reloptions
5752 AlterTableSpaceOptionsStmt *n =
5753 makeNode(AlterTableSpaceOptionsStmt);
5754 n->tablespacename = $3;
5759 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
5761 RenameStmt *n = makeNode(RenameStmt);
5762 n->renameType = OBJECT_TSPARSER;
5767 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
5769 RenameStmt *n = makeNode(RenameStmt);
5770 n->renameType = OBJECT_TSDICTIONARY;
5775 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
5777 RenameStmt *n = makeNode(RenameStmt);
5778 n->renameType = OBJECT_TSTEMPLATE;
5783 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
5785 RenameStmt *n = makeNode(RenameStmt);
5786 n->renameType = OBJECT_TSCONFIGURATION;
5791 | ALTER TYPE_P any_name RENAME TO name
5793 RenameStmt *n = makeNode(RenameStmt);
5794 n->renameType = OBJECT_TYPE;
5801 opt_column: COLUMN { $$ = COLUMN; }
5802 | /*EMPTY*/ { $$ = 0; }
5805 opt_set_data: SET DATA_P { $$ = 1; }
5806 | /*EMPTY*/ { $$ = 0; }
5809 /*****************************************************************************
5811 * ALTER THING name SET SCHEMA name
5813 *****************************************************************************/
5815 AlterObjectSchemaStmt:
5816 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
5818 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5819 n->objectType = OBJECT_AGGREGATE;
5825 | ALTER DOMAIN_P any_name SET SCHEMA name
5827 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5828 n->objectType = OBJECT_DOMAIN;
5833 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
5835 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5836 n->objectType = OBJECT_FUNCTION;
5837 n->object = $3->funcname;
5838 n->objarg = $3->funcargs;
5842 | ALTER TABLE relation_expr SET SCHEMA name
5844 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5845 n->objectType = OBJECT_TABLE;
5850 | ALTER SEQUENCE qualified_name SET SCHEMA name
5852 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5853 n->objectType = OBJECT_SEQUENCE;
5858 | ALTER VIEW qualified_name SET SCHEMA name
5860 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5861 n->objectType = OBJECT_VIEW;
5866 | ALTER TYPE_P any_name SET SCHEMA name
5868 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5869 n->objectType = OBJECT_TYPE;
5876 /*****************************************************************************
5878 * ALTER THING name OWNER TO newname
5880 *****************************************************************************/
5882 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
5884 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5885 n->objectType = OBJECT_AGGREGATE;
5891 | ALTER CONVERSION_P any_name OWNER TO RoleId
5893 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5894 n->objectType = OBJECT_CONVERSION;
5899 | ALTER DATABASE database_name OWNER TO RoleId
5901 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5902 n->objectType = OBJECT_DATABASE;
5903 n->object = list_make1(makeString($3));
5907 | ALTER DOMAIN_P any_name OWNER TO RoleId
5909 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5910 n->objectType = OBJECT_DOMAIN;
5915 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
5917 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5918 n->objectType = OBJECT_FUNCTION;
5919 n->object = $3->funcname;
5920 n->objarg = $3->funcargs;
5924 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
5926 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5927 n->objectType = OBJECT_LANGUAGE;
5928 n->object = list_make1(makeString($4));
5932 | ALTER LARGE_P OBJECT_P Iconst OWNER TO RoleId
5934 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5935 n->objectType = OBJECT_LARGEOBJECT;
5936 n->object = list_make1(makeInteger($4));
5940 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
5942 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5943 n->objectType = OBJECT_OPERATOR;
5949 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
5951 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5952 n->objectType = OBJECT_OPCLASS;
5958 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
5960 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5961 n->objectType = OBJECT_OPFAMILY;
5967 | ALTER SCHEMA name OWNER TO RoleId
5969 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5970 n->objectType = OBJECT_SCHEMA;
5971 n->object = list_make1(makeString($3));
5975 | ALTER TYPE_P any_name OWNER TO RoleId
5977 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5978 n->objectType = OBJECT_TYPE;
5983 | ALTER TABLESPACE name OWNER TO RoleId
5985 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5986 n->objectType = OBJECT_TABLESPACE;
5987 n->object = list_make1(makeString($3));
5991 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
5993 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5994 n->objectType = OBJECT_TSDICTIONARY;
5999 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
6001 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6002 n->objectType = OBJECT_TSCONFIGURATION;
6007 | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleId
6009 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6010 n->objectType = OBJECT_FDW;
6011 n->object = list_make1(makeString($5));
6015 | ALTER SERVER name OWNER TO RoleId
6017 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6018 n->objectType = OBJECT_FOREIGN_SERVER;
6019 n->object = list_make1(makeString($3));
6026 /*****************************************************************************
6028 * QUERY: Define Rewrite Rule
6030 *****************************************************************************/
6032 RuleStmt: CREATE opt_or_replace RULE name AS
6033 ON event TO qualified_name where_clause
6034 DO opt_instead RuleActionList
6036 RuleStmt *n = makeNode(RuleStmt);
6040 n->whereClause = $10;
6049 NOTHING { $$ = NIL; }
6050 | RuleActionStmt { $$ = list_make1($1); }
6051 | '(' RuleActionMulti ')' { $$ = $2; }
6054 /* the thrashing around here is to discard "empty" statements... */
6056 RuleActionMulti ';' RuleActionStmtOrEmpty
6058 $$ = lappend($1, $3);
6062 | RuleActionStmtOrEmpty
6064 $$ = list_make1($1);
6078 RuleActionStmtOrEmpty:
6079 RuleActionStmt { $$ = $1; }
6080 | /*EMPTY*/ { $$ = NULL; }
6083 event: SELECT { $$ = CMD_SELECT; }
6084 | UPDATE { $$ = CMD_UPDATE; }
6085 | DELETE_P { $$ = CMD_DELETE; }
6086 | INSERT { $$ = CMD_INSERT; }
6090 INSTEAD { $$ = TRUE; }
6091 | ALSO { $$ = FALSE; }
6092 | /*EMPTY*/ { $$ = FALSE; }
6097 DROP RULE name ON qualified_name opt_drop_behavior
6099 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6103 n->removeType = OBJECT_RULE;
6104 n->missing_ok = false;
6107 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
6109 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6113 n->removeType = OBJECT_RULE;
6114 n->missing_ok = true;
6120 /*****************************************************************************
6123 * NOTIFY <identifier> can appear both in rule bodies and
6124 * as a query-level command
6126 *****************************************************************************/
6128 NotifyStmt: NOTIFY ColId notify_payload
6130 NotifyStmt *n = makeNode(NotifyStmt);
6131 n->conditionname = $2;
6138 ',' Sconst { $$ = $2; }
6139 | /*EMPTY*/ { $$ = NULL; }
6142 ListenStmt: LISTEN ColId
6144 ListenStmt *n = makeNode(ListenStmt);
6145 n->conditionname = $2;
6153 UnlistenStmt *n = makeNode(UnlistenStmt);
6154 n->conditionname = $2;
6159 UnlistenStmt *n = makeNode(UnlistenStmt);
6160 n->conditionname = NULL;
6166 /*****************************************************************************
6170 * BEGIN / COMMIT / ROLLBACK
6171 * (also older versions END / ABORT)
6173 *****************************************************************************/
6176 ABORT_P opt_transaction
6178 TransactionStmt *n = makeNode(TransactionStmt);
6179 n->kind = TRANS_STMT_ROLLBACK;
6183 | BEGIN_P opt_transaction transaction_mode_list_or_empty
6185 TransactionStmt *n = makeNode(TransactionStmt);
6186 n->kind = TRANS_STMT_BEGIN;
6190 | START TRANSACTION transaction_mode_list_or_empty
6192 TransactionStmt *n = makeNode(TransactionStmt);
6193 n->kind = TRANS_STMT_START;
6197 | COMMIT opt_transaction
6199 TransactionStmt *n = makeNode(TransactionStmt);
6200 n->kind = TRANS_STMT_COMMIT;
6204 | END_P opt_transaction
6206 TransactionStmt *n = makeNode(TransactionStmt);
6207 n->kind = TRANS_STMT_COMMIT;
6211 | ROLLBACK opt_transaction
6213 TransactionStmt *n = makeNode(TransactionStmt);
6214 n->kind = TRANS_STMT_ROLLBACK;
6220 TransactionStmt *n = makeNode(TransactionStmt);
6221 n->kind = TRANS_STMT_SAVEPOINT;
6222 n->options = list_make1(makeDefElem("savepoint_name",
6223 (Node *)makeString($2)));
6226 | RELEASE SAVEPOINT ColId
6228 TransactionStmt *n = makeNode(TransactionStmt);
6229 n->kind = TRANS_STMT_RELEASE;
6230 n->options = list_make1(makeDefElem("savepoint_name",
6231 (Node *)makeString($3)));
6236 TransactionStmt *n = makeNode(TransactionStmt);
6237 n->kind = TRANS_STMT_RELEASE;
6238 n->options = list_make1(makeDefElem("savepoint_name",
6239 (Node *)makeString($2)));
6242 | ROLLBACK opt_transaction TO SAVEPOINT ColId
6244 TransactionStmt *n = makeNode(TransactionStmt);
6245 n->kind = TRANS_STMT_ROLLBACK_TO;
6246 n->options = list_make1(makeDefElem("savepoint_name",
6247 (Node *)makeString($5)));
6250 | ROLLBACK opt_transaction TO ColId
6252 TransactionStmt *n = makeNode(TransactionStmt);
6253 n->kind = TRANS_STMT_ROLLBACK_TO;
6254 n->options = list_make1(makeDefElem("savepoint_name",
6255 (Node *)makeString($4)));
6258 | PREPARE TRANSACTION Sconst
6260 TransactionStmt *n = makeNode(TransactionStmt);
6261 n->kind = TRANS_STMT_PREPARE;
6265 | COMMIT PREPARED Sconst
6267 TransactionStmt *n = makeNode(TransactionStmt);
6268 n->kind = TRANS_STMT_COMMIT_PREPARED;
6272 | ROLLBACK PREPARED Sconst
6274 TransactionStmt *n = makeNode(TransactionStmt);
6275 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
6281 opt_transaction: WORK {}
6286 transaction_mode_item:
6287 ISOLATION LEVEL iso_level
6288 { $$ = makeDefElem("transaction_isolation",
6289 makeStringConst($3, @3)); }
6291 { $$ = makeDefElem("transaction_read_only",
6292 makeIntConst(TRUE, @1)); }
6294 { $$ = makeDefElem("transaction_read_only",
6295 makeIntConst(FALSE, @1)); }
6298 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
6299 transaction_mode_list:
6300 transaction_mode_item
6301 { $$ = list_make1($1); }
6302 | transaction_mode_list ',' transaction_mode_item
6303 { $$ = lappend($1, $3); }
6304 | transaction_mode_list transaction_mode_item
6305 { $$ = lappend($1, $2); }
6308 transaction_mode_list_or_empty:
6309 transaction_mode_list
6315 /*****************************************************************************
6318 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
6319 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
6321 *****************************************************************************/
6323 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
6324 AS SelectStmt opt_check_option
6326 ViewStmt *n = makeNode(ViewStmt);
6328 n->view->istemp = $2;
6334 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
6335 AS SelectStmt opt_check_option
6337 ViewStmt *n = makeNode(ViewStmt);
6339 n->view->istemp = $4;
6351 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6352 errmsg("WITH CHECK OPTION is not implemented")));
6354 | WITH CASCADED CHECK OPTION
6357 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6358 errmsg("WITH CHECK OPTION is not implemented")));
6360 | WITH LOCAL CHECK OPTION
6363 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6364 errmsg("WITH CHECK OPTION is not implemented")));
6366 | /* EMPTY */ { $$ = NIL; }
6369 /*****************************************************************************
6374 *****************************************************************************/
6376 LoadStmt: LOAD file_name
6378 LoadStmt *n = makeNode(LoadStmt);
6385 /*****************************************************************************
6389 *****************************************************************************/
6392 CREATE DATABASE database_name opt_with createdb_opt_list
6394 CreatedbStmt *n = makeNode(CreatedbStmt);
6402 createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
6403 | /* EMPTY */ { $$ = NIL; }
6407 TABLESPACE opt_equal name
6409 $$ = makeDefElem("tablespace", (Node *)makeString($3));
6411 | TABLESPACE opt_equal DEFAULT
6413 $$ = makeDefElem("tablespace", NULL);
6415 | LOCATION opt_equal Sconst
6417 $$ = makeDefElem("location", (Node *)makeString($3));
6419 | LOCATION opt_equal DEFAULT
6421 $$ = makeDefElem("location", NULL);
6423 | TEMPLATE opt_equal name
6425 $$ = makeDefElem("template", (Node *)makeString($3));
6427 | TEMPLATE opt_equal DEFAULT
6429 $$ = makeDefElem("template", NULL);
6431 | ENCODING opt_equal Sconst
6433 $$ = makeDefElem("encoding", (Node *)makeString($3));
6435 | ENCODING opt_equal Iconst
6437 $$ = makeDefElem("encoding", (Node *)makeInteger($3));
6439 | ENCODING opt_equal DEFAULT
6441 $$ = makeDefElem("encoding", NULL);
6443 | LC_COLLATE_P opt_equal Sconst
6445 $$ = makeDefElem("lc_collate", (Node *)makeString($3));
6447 | LC_COLLATE_P opt_equal DEFAULT
6449 $$ = makeDefElem("lc_collate", NULL);
6451 | LC_CTYPE_P opt_equal Sconst
6453 $$ = makeDefElem("lc_ctype", (Node *)makeString($3));
6455 | LC_CTYPE_P opt_equal DEFAULT
6457 $$ = makeDefElem("lc_ctype", NULL);
6459 | CONNECTION LIMIT opt_equal SignedIconst
6461 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6463 | OWNER opt_equal name
6465 $$ = makeDefElem("owner", (Node *)makeString($3));
6467 | OWNER opt_equal DEFAULT
6469 $$ = makeDefElem("owner", NULL);
6474 * Though the equals sign doesn't match other WITH options, pg_dump uses
6475 * equals for backward compatibility, and it doesn't seem worth removing it.
6482 /*****************************************************************************
6486 *****************************************************************************/
6489 ALTER DATABASE database_name opt_with alterdb_opt_list
6491 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6496 | ALTER DATABASE database_name SET TABLESPACE name
6498 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6500 n->options = list_make1(makeDefElem("tablespace",
6501 (Node *)makeString($6)));
6506 AlterDatabaseSetStmt:
6507 ALTER DATABASE database_name SetResetClause
6509 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
6518 alterdb_opt_list alterdb_opt_item { $$ = lappend($1, $2); }
6519 | /* EMPTY */ { $$ = NIL; }
6523 CONNECTION LIMIT opt_equal SignedIconst
6525 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6530 /*****************************************************************************
6532 * DROP DATABASE [ IF EXISTS ]
6534 * This is implicitly CASCADE, no need for drop behavior
6535 *****************************************************************************/
6537 DropdbStmt: DROP DATABASE database_name
6539 DropdbStmt *n = makeNode(DropdbStmt);
6541 n->missing_ok = FALSE;
6544 | DROP DATABASE IF_P EXISTS database_name
6546 DropdbStmt *n = makeNode(DropdbStmt);
6548 n->missing_ok = TRUE;
6554 /*****************************************************************************
6556 * Manipulate a domain
6558 *****************************************************************************/
6561 CREATE DOMAIN_P any_name opt_as Typename ColQualList
6563 CreateDomainStmt *n = makeNode(CreateDomainStmt);
6566 n->constraints = $6;
6572 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
6573 ALTER DOMAIN_P any_name alter_column_default
6575 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6581 /* ALTER DOMAIN <domain> DROP NOT NULL */
6582 | ALTER DOMAIN_P any_name DROP NOT NULL_P
6584 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6589 /* ALTER DOMAIN <domain> SET NOT NULL */
6590 | ALTER DOMAIN_P any_name SET NOT NULL_P
6592 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6597 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
6598 | ALTER DOMAIN_P any_name ADD_P TableConstraint
6600 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6606 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
6607 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
6609 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6623 /*****************************************************************************
6625 * Manipulate a text search dictionary or configuration
6627 *****************************************************************************/
6629 AlterTSDictionaryStmt:
6630 ALTER TEXT_P SEARCH DICTIONARY any_name definition
6632 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
6639 AlterTSConfigurationStmt:
6640 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
6642 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6646 n->override = false;
6650 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
6652 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6660 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
6662 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6665 n->dicts = list_make2($9,$11);
6666 n->override = false;
6670 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
6672 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6675 n->dicts = list_make2($11,$13);
6676 n->override = false;
6680 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
6682 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6685 n->missing_ok = false;
6688 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
6690 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6693 n->missing_ok = true;
6699 /*****************************************************************************
6701 * Manipulate a conversion
6703 * CREATE [DEFAULT] CONVERSION <conversion_name>
6704 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
6706 *****************************************************************************/
6708 CreateConversionStmt:
6709 CREATE opt_default CONVERSION_P any_name FOR Sconst
6710 TO Sconst FROM any_name
6712 CreateConversionStmt *n = makeNode(CreateConversionStmt);
6713 n->conversion_name = $4;
6714 n->for_encoding_name = $6;
6715 n->to_encoding_name = $8;
6722 /*****************************************************************************
6725 * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
6727 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
6729 *****************************************************************************/
6732 CLUSTER opt_verbose qualified_name cluster_index_specification
6734 ClusterStmt *n = makeNode(ClusterStmt);
6740 | CLUSTER opt_verbose
6742 ClusterStmt *n = makeNode(ClusterStmt);
6744 n->indexname = NULL;
6748 /* kept for pre-8.3 compatibility */
6749 | CLUSTER opt_verbose index_name ON qualified_name
6751 ClusterStmt *n = makeNode(ClusterStmt);
6759 cluster_index_specification:
6760 USING index_name { $$ = $2; }
6761 | /*EMPTY*/ { $$ = NULL; }
6765 /*****************************************************************************
6771 *****************************************************************************/
6773 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
6775 VacuumStmt *n = makeNode(VacuumStmt);
6776 n->options = VACOPT_VACUUM;
6778 n->options |= VACOPT_FULL;
6780 n->options |= VACOPT_VERBOSE;
6781 n->freeze_min_age = $3 ? 0 : -1;
6782 n->freeze_table_age = $3 ? 0 : -1;
6787 | VACUUM opt_full opt_freeze opt_verbose qualified_name
6789 VacuumStmt *n = makeNode(VacuumStmt);
6790 n->options = VACOPT_VACUUM;
6792 n->options |= VACOPT_FULL;
6794 n->options |= VACOPT_VERBOSE;
6795 n->freeze_min_age = $3 ? 0 : -1;
6796 n->freeze_table_age = $3 ? 0 : -1;
6801 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
6803 VacuumStmt *n = (VacuumStmt *) $5;
6804 n->options |= VACOPT_VACUUM;
6806 n->options |= VACOPT_FULL;
6808 n->options |= VACOPT_VERBOSE;
6809 n->freeze_min_age = $3 ? 0 : -1;
6810 n->freeze_table_age = $3 ? 0 : -1;
6813 | VACUUM '(' vacuum_option_list ')'
6815 VacuumStmt *n = makeNode(VacuumStmt);
6816 n->options = VACOPT_VACUUM | $3;
6817 if (n->options & VACOPT_FREEZE)
6818 n->freeze_min_age = n->freeze_table_age = 0;
6820 n->freeze_min_age = n->freeze_table_age = -1;
6825 | VACUUM '(' vacuum_option_list ')' qualified_name opt_name_list
6827 VacuumStmt *n = makeNode(VacuumStmt);
6828 n->options = VACOPT_VACUUM | $3;
6829 if (n->options & VACOPT_FREEZE)
6830 n->freeze_min_age = n->freeze_table_age = 0;
6832 n->freeze_min_age = n->freeze_table_age = -1;
6835 if (n->va_cols != NIL) /* implies analyze */
6836 n->options |= VACOPT_ANALYZE;
6842 vacuum_option_elem { $$ = $1; }
6843 | vacuum_option_list ',' vacuum_option_elem { $$ = $1 | $3; }
6847 analyze_keyword { $$ = VACOPT_ANALYZE; }
6848 | VERBOSE { $$ = VACOPT_VERBOSE; }
6849 | FREEZE { $$ = VACOPT_FREEZE; }
6850 | FULL { $$ = VACOPT_FULL; }
6854 analyze_keyword opt_verbose
6856 VacuumStmt *n = makeNode(VacuumStmt);
6857 n->options = VACOPT_ANALYZE;
6859 n->options |= VACOPT_VERBOSE;
6860 n->freeze_min_age = -1;
6861 n->freeze_table_age = -1;
6866 | analyze_keyword opt_verbose qualified_name opt_name_list
6868 VacuumStmt *n = makeNode(VacuumStmt);
6869 n->options = VACOPT_ANALYZE;
6871 n->options |= VACOPT_VERBOSE;
6872 n->freeze_min_age = -1;
6873 n->freeze_table_age = -1;
6882 | ANALYSE /* British */ {}
6886 VERBOSE { $$ = TRUE; }
6887 | /*EMPTY*/ { $$ = FALSE; }
6890 opt_full: FULL { $$ = TRUE; }
6891 | /*EMPTY*/ { $$ = FALSE; }
6894 opt_freeze: FREEZE { $$ = TRUE; }
6895 | /*EMPTY*/ { $$ = FALSE; }
6899 '(' name_list ')' { $$ = $2; }
6900 | /*EMPTY*/ { $$ = NIL; }
6904 /*****************************************************************************
6907 * EXPLAIN [ANALYZE] [VERBOSE] query
6908 * EXPLAIN ( options ) query
6910 *****************************************************************************/
6913 EXPLAIN ExplainableStmt
6915 ExplainStmt *n = makeNode(ExplainStmt);
6920 | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
6922 ExplainStmt *n = makeNode(ExplainStmt);
6924 n->options = list_make1(makeDefElem("analyze", NULL));
6926 n->options = lappend(n->options,
6927 makeDefElem("verbose", NULL));
6930 | EXPLAIN VERBOSE ExplainableStmt
6932 ExplainStmt *n = makeNode(ExplainStmt);
6934 n->options = list_make1(makeDefElem("verbose", NULL));
6937 | EXPLAIN '(' explain_option_list ')' ExplainableStmt
6939 ExplainStmt *n = makeNode(ExplainStmt);
6953 | ExecuteStmt /* by default all are $$=$1 */
6956 explain_option_list:
6959 $$ = list_make1($1);
6961 | explain_option_list ',' explain_option_elem
6963 $$ = lappend($1, $3);
6967 explain_option_elem:
6968 explain_option_name explain_option_arg
6970 $$ = makeDefElem($1, $2);
6974 explain_option_name:
6976 | analyze_keyword { $$ = "analyze"; }
6977 | VERBOSE { $$ = "verbose"; }
6981 opt_boolean { $$ = (Node *) makeString($1); }
6982 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
6983 | NumericOnly { $$ = (Node *) $1; }
6984 | /* EMPTY */ { $$ = NULL; }
6987 /*****************************************************************************
6990 * PREPARE <plan_name> [(args, ...)] AS <query>
6992 *****************************************************************************/
6994 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
6996 PrepareStmt *n = makeNode(PrepareStmt);
7004 prep_type_clause: '(' type_list ')' { $$ = $2; }
7005 | /* EMPTY */ { $$ = NIL; }
7012 | DeleteStmt /* by default all are $$=$1 */
7015 /*****************************************************************************
7017 * EXECUTE <plan_name> [(params, ...)]
7018 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
7020 *****************************************************************************/
7022 ExecuteStmt: EXECUTE name execute_param_clause
7024 ExecuteStmt *n = makeNode(ExecuteStmt);
7030 | CREATE OptTemp TABLE create_as_target AS
7031 EXECUTE name execute_param_clause
7033 ExecuteStmt *n = makeNode(ExecuteStmt);
7036 $4->rel->istemp = $2;
7040 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7041 errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
7042 /* ... because it's not implemented, but it could be */
7047 execute_param_clause: '(' expr_list ')' { $$ = $2; }
7048 | /* EMPTY */ { $$ = NIL; }
7051 /*****************************************************************************
7054 * DEALLOCATE [PREPARE] <plan_name>
7056 *****************************************************************************/
7058 DeallocateStmt: DEALLOCATE name
7060 DeallocateStmt *n = makeNode(DeallocateStmt);
7064 | DEALLOCATE PREPARE name
7066 DeallocateStmt *n = makeNode(DeallocateStmt);
7072 DeallocateStmt *n = makeNode(DeallocateStmt);
7076 | DEALLOCATE PREPARE ALL
7078 DeallocateStmt *n = makeNode(DeallocateStmt);
7084 /*****************************************************************************
7089 *****************************************************************************/
7092 INSERT INTO qualified_name insert_rest returning_clause
7095 $4->returningList = $5;
7103 $$ = makeNode(InsertStmt);
7105 $$->selectStmt = $1;
7107 | '(' insert_column_list ')' SelectStmt
7109 $$ = makeNode(InsertStmt);
7111 $$->selectStmt = $4;
7115 $$ = makeNode(InsertStmt);
7117 $$->selectStmt = NULL;
7123 { $$ = list_make1($1); }
7124 | insert_column_list ',' insert_column_item
7125 { $$ = lappend($1, $3); }
7129 ColId opt_indirection
7131 $$ = makeNode(ResTarget);
7133 $$->indirection = check_indirection($2, yyscanner);
7140 RETURNING target_list { $$ = $2; }
7141 | /* EMPTY */ { $$ = NIL; }
7145 /*****************************************************************************
7150 *****************************************************************************/
7152 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
7153 using_clause where_or_current_clause returning_clause
7155 DeleteStmt *n = makeNode(DeleteStmt);
7157 n->usingClause = $4;
7158 n->whereClause = $5;
7159 n->returningList = $6;
7165 USING from_list { $$ = $2; }
7166 | /*EMPTY*/ { $$ = NIL; }
7170 /*****************************************************************************
7175 *****************************************************************************/
7177 LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
7179 LockStmt *n = makeNode(LockStmt);
7188 opt_lock: IN_P lock_type MODE { $$ = $2; }
7189 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
7192 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
7193 | ROW SHARE { $$ = RowShareLock; }
7194 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
7195 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
7196 | SHARE { $$ = ShareLock; }
7197 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
7198 | EXCLUSIVE { $$ = ExclusiveLock; }
7199 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
7202 opt_nowait: NOWAIT { $$ = TRUE; }
7203 | /*EMPTY*/ { $$ = FALSE; }
7207 /*****************************************************************************
7210 * UpdateStmt (UPDATE)
7212 *****************************************************************************/
7214 UpdateStmt: UPDATE relation_expr_opt_alias
7217 where_or_current_clause
7220 UpdateStmt *n = makeNode(UpdateStmt);
7224 n->whereClause = $6;
7225 n->returningList = $7;
7231 set_clause { $$ = $1; }
7232 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
7236 single_set_clause { $$ = list_make1($1); }
7237 | multiple_set_clause { $$ = $1; }
7241 set_target '=' ctext_expr
7244 $$->val = (Node *) $3;
7248 multiple_set_clause:
7249 '(' set_target_list ')' '=' ctext_row
7255 * Break the ctext_row apart, merge individual expressions
7256 * into the destination ResTargets. XXX this approach
7257 * cannot work for general row expressions as sources.
7259 if (list_length($2) != list_length($5))
7261 (errcode(ERRCODE_SYNTAX_ERROR),
7262 errmsg("number of columns does not match number of values"),
7263 parser_errposition(@1)));
7264 forboth(col_cell, $2, val_cell, $5)
7266 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
7267 Node *res_val = (Node *) lfirst(val_cell);
7269 res_col->val = res_val;
7277 ColId opt_indirection
7279 $$ = makeNode(ResTarget);
7281 $$->indirection = check_indirection($2, yyscanner);
7282 $$->val = NULL; /* upper production sets this */
7288 set_target { $$ = list_make1($1); }
7289 | set_target_list ',' set_target { $$ = lappend($1,$3); }
7293 /*****************************************************************************
7298 *****************************************************************************/
7299 DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
7301 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
7303 /* currently we always set FAST_PLAN option */
7304 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
7310 cursor_name: name { $$ = $1; }
7313 cursor_options: /*EMPTY*/ { $$ = 0; }
7314 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
7315 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
7316 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
7317 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
7320 opt_hold: /* EMPTY */ { $$ = 0; }
7321 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
7322 | WITHOUT HOLD { $$ = 0; }
7325 /*****************************************************************************
7330 *****************************************************************************/
7332 /* A complete SELECT statement looks like this.
7334 * The rule returns either a single SelectStmt node or a tree of them,
7335 * representing a set-operation tree.
7337 * There is an ambiguity when a sub-SELECT is within an a_expr and there
7338 * are excess parentheses: do the parentheses belong to the sub-SELECT or
7339 * to the surrounding a_expr? We don't really care, but bison wants to know.
7340 * To resolve the ambiguity, we are careful to define the grammar so that
7341 * the decision is staved off as long as possible: as long as we can keep
7342 * absorbing parentheses into the sub-SELECT, we will do so, and only when
7343 * it's no longer possible to do that will we decide that parens belong to
7344 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
7345 * parentheses are treated as part of the sub-select. The necessity of doing
7346 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
7347 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
7348 * SELECT viewpoint when we see the UNION.
7350 * This approach is implemented by defining a nonterminal select_with_parens,
7351 * which represents a SELECT with at least one outer layer of parentheses,
7352 * and being careful to use select_with_parens, never '(' SelectStmt ')',
7353 * in the expression grammar. We will then have shift-reduce conflicts
7354 * which we can resolve in favor of always treating '(' <select> ')' as
7355 * a select_with_parens. To resolve the conflicts, the productions that
7356 * conflict with the select_with_parens productions are manually given
7357 * precedences lower than the precedence of ')', thereby ensuring that we
7358 * shift ')' (and then reduce to select_with_parens) rather than trying to
7359 * reduce the inner <select> nonterminal to something else. We use UMINUS
7360 * precedence for this, which is a fairly arbitrary choice.
7362 * To be able to define select_with_parens itself without ambiguity, we need
7363 * a nonterminal select_no_parens that represents a SELECT structure with no
7364 * outermost parentheses. This is a little bit tedious, but it works.
7366 * In non-expression contexts, we use SelectStmt which can represent a SELECT
7367 * with or without outer parentheses.
7370 SelectStmt: select_no_parens %prec UMINUS
7371 | select_with_parens %prec UMINUS
7375 '(' select_no_parens ')' { $$ = $2; }
7376 | '(' select_with_parens ')' { $$ = $2; }
7380 * This rule parses the equivalent of the standard's <query expression>.
7381 * The duplicative productions are annoying, but hard to get rid of without
7382 * creating shift/reduce conflicts.
7384 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
7385 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
7386 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
7390 simple_select { $$ = $1; }
7391 | select_clause sort_clause
7393 insertSelectOptions((SelectStmt *) $1, $2, NIL,
7398 | select_clause opt_sort_clause for_locking_clause opt_select_limit
7400 insertSelectOptions((SelectStmt *) $1, $2, $3,
7401 list_nth($4, 0), list_nth($4, 1),
7406 | select_clause opt_sort_clause select_limit opt_for_locking_clause
7408 insertSelectOptions((SelectStmt *) $1, $2, $4,
7409 list_nth($3, 0), list_nth($3, 1),
7414 | with_clause select_clause
7416 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
7422 | with_clause select_clause sort_clause
7424 insertSelectOptions((SelectStmt *) $2, $3, NIL,
7430 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
7432 insertSelectOptions((SelectStmt *) $2, $3, $4,
7433 list_nth($5, 0), list_nth($5, 1),
7438 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
7440 insertSelectOptions((SelectStmt *) $2, $3, $5,
7441 list_nth($4, 0), list_nth($4, 1),
7449 simple_select { $$ = $1; }
7450 | select_with_parens { $$ = $1; }
7454 * This rule parses SELECT statements that can appear within set operations,
7455 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
7456 * the ordering of the set operations. Without '(' and ')' we want the
7457 * operations to be ordered per the precedence specs at the head of this file.
7459 * As with select_no_parens, simple_select cannot have outer parentheses,
7460 * but can have parenthesized subclauses.
7462 * Note that sort clauses cannot be included at this level --- SQL92 requires
7463 * SELECT foo UNION SELECT bar ORDER BY baz
7465 * (SELECT foo UNION SELECT bar) ORDER BY baz
7467 * SELECT foo UNION (SELECT bar ORDER BY baz)
7468 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
7469 * described as part of the select_no_parens production, not simple_select.
7470 * This does not limit functionality, because you can reintroduce these
7471 * clauses inside parentheses.
7473 * NOTE: only the leftmost component SelectStmt should have INTO.
7474 * However, this is not checked by the grammar; parse analysis must check it.
7477 SELECT opt_distinct target_list
7478 into_clause from_clause where_clause
7479 group_clause having_clause window_clause
7481 SelectStmt *n = makeNode(SelectStmt);
7482 n->distinctClause = $2;
7486 n->whereClause = $6;
7487 n->groupClause = $7;
7488 n->havingClause = $8;
7489 n->windowClause = $9;
7492 | values_clause { $$ = $1; }
7493 | TABLE relation_expr
7495 /* same as SELECT * FROM relation_expr */
7496 ColumnRef *cr = makeNode(ColumnRef);
7497 ResTarget *rt = makeNode(ResTarget);
7498 SelectStmt *n = makeNode(SelectStmt);
7500 cr->fields = list_make1(makeNode(A_Star));
7504 rt->indirection = NIL;
7505 rt->val = (Node *)cr;
7508 n->targetList = list_make1(rt);
7509 n->fromClause = list_make1($2);
7512 | select_clause UNION opt_all select_clause
7514 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
7516 | select_clause INTERSECT opt_all select_clause
7518 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
7520 | select_clause EXCEPT opt_all select_clause
7522 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
7527 * SQL standard WITH clause looks like:
7529 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
7530 * AS (query) [ SEARCH or CYCLE clause ]
7532 * We don't currently support the SEARCH or CYCLE clause.
7537 $$ = makeNode(WithClause);
7539 $$->recursive = false;
7542 | WITH RECURSIVE cte_list
7544 $$ = makeNode(WithClause);
7546 $$->recursive = true;
7552 common_table_expr { $$ = list_make1($1); }
7553 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
7556 common_table_expr: name opt_name_list AS select_with_parens
7558 CommonTableExpr *n = makeNode(CommonTableExpr);
7560 n->aliascolnames = $2;
7568 INTO OptTempTableName
7570 $$ = makeNode(IntoClause);
7574 $$->onCommit = ONCOMMIT_NOOP;
7575 $$->tableSpaceName = NULL;
7582 * Redundancy here is needed to avoid shift/reduce conflicts,
7583 * since TEMP is not a reserved word. See also OptTemp.
7586 TEMPORARY opt_table qualified_name
7591 | TEMP opt_table qualified_name
7596 | LOCAL TEMPORARY opt_table qualified_name
7601 | LOCAL TEMP opt_table qualified_name
7606 | GLOBAL TEMPORARY opt_table qualified_name
7611 | GLOBAL TEMP opt_table qualified_name
7616 | TABLE qualified_name
7632 opt_all: ALL { $$ = TRUE; }
7633 | DISTINCT { $$ = FALSE; }
7634 | /*EMPTY*/ { $$ = FALSE; }
7637 /* We use (NIL) as a placeholder to indicate that all target expressions
7638 * should be placed in the DISTINCT list during parsetree analysis.
7641 DISTINCT { $$ = list_make1(NIL); }
7642 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
7644 | /*EMPTY*/ { $$ = NIL; }
7648 sort_clause { $$ = $1;}
7649 | /*EMPTY*/ { $$ = NIL; }
7653 ORDER BY sortby_list { $$ = $3; }
7657 sortby { $$ = list_make1($1); }
7658 | sortby_list ',' sortby { $$ = lappend($1, $3); }
7661 sortby: a_expr USING qual_all_Op opt_nulls_order
7663 $$ = makeNode(SortBy);
7665 $$->sortby_dir = SORTBY_USING;
7666 $$->sortby_nulls = $4;
7670 | a_expr opt_asc_desc opt_nulls_order
7672 $$ = makeNode(SortBy);
7674 $$->sortby_dir = $2;
7675 $$->sortby_nulls = $3;
7677 $$->location = -1; /* no operator */
7683 limit_clause offset_clause { $$ = list_make2($2, $1); }
7684 | offset_clause limit_clause { $$ = list_make2($1, $2); }
7685 | limit_clause { $$ = list_make2(NULL, $1); }
7686 | offset_clause { $$ = list_make2($1, NULL); }
7690 select_limit { $$ = $1; }
7691 | /* EMPTY */ { $$ = list_make2(NULL,NULL); }
7695 LIMIT select_limit_value
7697 | LIMIT select_limit_value ',' select_offset_value
7699 /* Disabled because it was too confusing, bjm 2002-02-18 */
7701 (errcode(ERRCODE_SYNTAX_ERROR),
7702 errmsg("LIMIT #,# syntax is not supported"),
7703 errhint("Use separate LIMIT and OFFSET clauses."),
7704 parser_errposition(@1)));
7706 /* SQL:2008 syntax */
7707 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
7712 OFFSET select_offset_value
7714 /* SQL:2008 syntax */
7715 | OFFSET select_offset_value2 row_or_rows
7723 /* LIMIT ALL is represented as a NULL constant */
7724 $$ = makeNullAConst(@1);
7728 select_offset_value:
7733 * Allowing full expressions without parentheses causes various parsing
7734 * problems with the trailing ROW/ROWS key words. SQL only calls for
7735 * constants, so we allow the rest only with parentheses. If omitted,
7738 opt_select_fetch_first_value:
7739 SignedIconst { $$ = makeIntConst($1, @1); }
7740 | '(' a_expr ')' { $$ = $2; }
7741 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
7745 * Again, the trailing ROW/ROWS in this case prevent the full expression
7746 * syntax. c_expr is the best we can do.
7748 select_offset_value2:
7753 row_or_rows: ROW { $$ = 0; }
7757 first_or_next: FIRST_P { $$ = 0; }
7763 GROUP_P BY expr_list { $$ = $3; }
7764 | /*EMPTY*/ { $$ = NIL; }
7768 HAVING a_expr { $$ = $2; }
7769 | /*EMPTY*/ { $$ = NULL; }
7773 for_locking_items { $$ = $1; }
7774 | FOR READ ONLY { $$ = NIL; }
7777 opt_for_locking_clause:
7778 for_locking_clause { $$ = $1; }
7779 | /* EMPTY */ { $$ = NIL; }
7783 for_locking_item { $$ = list_make1($1); }
7784 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
7788 FOR UPDATE locked_rels_list opt_nowait
7790 LockingClause *n = makeNode(LockingClause);
7792 n->forUpdate = TRUE;
7796 | FOR SHARE locked_rels_list opt_nowait
7798 LockingClause *n = makeNode(LockingClause);
7800 n->forUpdate = FALSE;
7807 OF qualified_name_list { $$ = $2; }
7808 | /* EMPTY */ { $$ = NIL; }
7815 SelectStmt *n = makeNode(SelectStmt);
7816 n->valuesLists = list_make1($2);
7819 | values_clause ',' ctext_row
7821 SelectStmt *n = (SelectStmt *) $1;
7822 n->valuesLists = lappend(n->valuesLists, $3);
7828 /*****************************************************************************
7830 * clauses common to all Optimizable Stmts:
7831 * from_clause - allow list of both JOIN expressions and table names
7832 * where_clause - qualifications for joins or restrictions
7834 *****************************************************************************/
7837 FROM from_list { $$ = $2; }
7838 | /*EMPTY*/ { $$ = NIL; }
7842 table_ref { $$ = list_make1($1); }
7843 | from_list ',' table_ref { $$ = lappend($1, $3); }
7847 * table_ref is where an alias clause can be attached. Note we cannot make
7848 * alias_clause have an empty production because that causes parse conflicts
7849 * between table_ref := '(' joined_table ')' alias_clause
7850 * and joined_table := '(' joined_table ')'. So, we must have the
7851 * redundant-looking productions here instead.
7853 table_ref: relation_expr
7857 | relation_expr alias_clause
7864 RangeFunction *n = makeNode(RangeFunction);
7865 n->funccallnode = $1;
7866 n->coldeflist = NIL;
7869 | func_table alias_clause
7871 RangeFunction *n = makeNode(RangeFunction);
7872 n->funccallnode = $1;
7874 n->coldeflist = NIL;
7877 | func_table AS '(' TableFuncElementList ')'
7879 RangeFunction *n = makeNode(RangeFunction);
7880 n->funccallnode = $1;
7884 | func_table AS ColId '(' TableFuncElementList ')'
7886 RangeFunction *n = makeNode(RangeFunction);
7887 Alias *a = makeNode(Alias);
7888 n->funccallnode = $1;
7894 | func_table ColId '(' TableFuncElementList ')'
7896 RangeFunction *n = makeNode(RangeFunction);
7897 Alias *a = makeNode(Alias);
7898 n->funccallnode = $1;
7904 | select_with_parens
7907 * The SQL spec does not permit a subselect
7908 * (<derived_table>) without an alias clause,
7909 * so we don't either. This avoids the problem
7910 * of needing to invent a unique refname for it.
7911 * That could be surmounted if there's sufficient
7912 * popular demand, but for now let's just implement
7913 * the spec and see if anyone complains.
7914 * However, it does seem like a good idea to emit
7915 * an error message that's better than "syntax error".
7917 if (IsA($1, SelectStmt) &&
7918 ((SelectStmt *) $1)->valuesLists)
7920 (errcode(ERRCODE_SYNTAX_ERROR),
7921 errmsg("VALUES in FROM must have an alias"),
7922 errhint("For example, FROM (VALUES ...) [AS] foo."),
7923 parser_errposition(@1)));
7926 (errcode(ERRCODE_SYNTAX_ERROR),
7927 errmsg("subquery in FROM must have an alias"),
7928 errhint("For example, FROM (SELECT ...) [AS] foo."),
7929 parser_errposition(@1)));
7932 | select_with_parens alias_clause
7934 RangeSubselect *n = makeNode(RangeSubselect);
7943 | '(' joined_table ')' alias_clause
7952 * It may seem silly to separate joined_table from table_ref, but there is
7953 * method in SQL92's madness: if you don't do it this way you get reduce-
7954 * reduce conflicts, because it's not clear to the parser generator whether
7955 * to expect alias_clause after ')' or not. For the same reason we must
7956 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
7957 * join_type to expand to empty; if we try it, the parser generator can't
7958 * figure out when to reduce an empty join_type right after table_ref.
7960 * Note that a CROSS JOIN is the same as an unqualified
7961 * INNER JOIN, and an INNER JOIN/ON has the same shape
7962 * but a qualification expression to limit membership.
7963 * A NATURAL JOIN implicitly matches column names between
7964 * tables and the shape is determined by which columns are
7965 * in common. We'll collect columns during the later transformations.
7969 '(' joined_table ')'
7973 | table_ref CROSS JOIN table_ref
7975 /* CROSS JOIN is same as unqualified inner join */
7976 JoinExpr *n = makeNode(JoinExpr);
7977 n->jointype = JOIN_INNER;
7978 n->isNatural = FALSE;
7981 n->usingClause = NIL;
7985 | table_ref join_type JOIN table_ref join_qual
7987 JoinExpr *n = makeNode(JoinExpr);
7989 n->isNatural = FALSE;
7992 if ($5 != NULL && IsA($5, List))
7993 n->usingClause = (List *) $5; /* USING clause */
7995 n->quals = $5; /* ON clause */
7998 | table_ref JOIN table_ref join_qual
8000 /* letting join_type reduce to empty doesn't work */
8001 JoinExpr *n = makeNode(JoinExpr);
8002 n->jointype = JOIN_INNER;
8003 n->isNatural = FALSE;
8006 if ($4 != NULL && IsA($4, List))
8007 n->usingClause = (List *) $4; /* USING clause */
8009 n->quals = $4; /* ON clause */
8012 | table_ref NATURAL join_type JOIN table_ref
8014 JoinExpr *n = makeNode(JoinExpr);
8016 n->isNatural = TRUE;
8019 n->usingClause = NIL; /* figure out which columns later... */
8020 n->quals = NULL; /* fill later */
8023 | table_ref NATURAL JOIN table_ref
8025 /* letting join_type reduce to empty doesn't work */
8026 JoinExpr *n = makeNode(JoinExpr);
8027 n->jointype = JOIN_INNER;
8028 n->isNatural = TRUE;
8031 n->usingClause = NIL; /* figure out which columns later... */
8032 n->quals = NULL; /* fill later */
8038 AS ColId '(' name_list ')'
8040 $$ = makeNode(Alias);
8046 $$ = makeNode(Alias);
8049 | ColId '(' name_list ')'
8051 $$ = makeNode(Alias);
8057 $$ = makeNode(Alias);
8062 join_type: FULL join_outer { $$ = JOIN_FULL; }
8063 | LEFT join_outer { $$ = JOIN_LEFT; }
8064 | RIGHT join_outer { $$ = JOIN_RIGHT; }
8065 | INNER_P { $$ = JOIN_INNER; }
8068 /* OUTER is just noise... */
8069 join_outer: OUTER_P { $$ = NULL; }
8070 | /*EMPTY*/ { $$ = NULL; }
8073 /* JOIN qualification clauses
8074 * Possibilities are:
8075 * USING ( column list ) allows only unqualified column names,
8076 * which must match between tables.
8077 * ON expr allows more general qualifications.
8079 * We return USING as a List node, while an ON-expr will not be a List.
8082 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
8083 | ON a_expr { $$ = $2; }
8090 /* default inheritance */
8092 $$->inhOpt = INH_DEFAULT;
8095 | qualified_name '*'
8097 /* inheritance query */
8099 $$->inhOpt = INH_YES;
8102 | ONLY qualified_name
8104 /* no inheritance */
8106 $$->inhOpt = INH_NO;
8109 | ONLY '(' qualified_name ')'
8111 /* no inheritance, SQL99-style syntax */
8113 $$->inhOpt = INH_NO;
8120 relation_expr { $$ = list_make1($1); }
8121 | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
8126 * Given "UPDATE foo set set ...", we have to decide without looking any
8127 * further ahead whether the first "set" is an alias or the UPDATE's SET
8128 * keyword. Since "set" is allowed as a column name both interpretations
8129 * are feasible. We resolve the shift/reduce conflict by giving the first
8130 * relation_expr_opt_alias production a higher precedence than the SET token
8131 * has, causing the parser to prefer to reduce, in effect assuming that the
8132 * SET is not an alias.
8134 relation_expr_opt_alias: relation_expr %prec UMINUS
8138 | relation_expr ColId
8140 Alias *alias = makeNode(Alias);
8141 alias->aliasname = $2;
8145 | relation_expr AS ColId
8147 Alias *alias = makeNode(Alias);
8148 alias->aliasname = $3;
8155 func_table: func_expr { $$ = $1; }
8160 WHERE a_expr { $$ = $2; }
8161 | /*EMPTY*/ { $$ = NULL; }
8164 /* variant for UPDATE and DELETE */
8165 where_or_current_clause:
8166 WHERE a_expr { $$ = $2; }
8167 | WHERE CURRENT_P OF name
8169 CurrentOfExpr *n = makeNode(CurrentOfExpr);
8170 /* cvarno is filled in by parse analysis */
8171 n->cursor_name = $4;
8172 n->cursor_param = 0;
8175 | /*EMPTY*/ { $$ = NULL; }
8179 TableFuncElementList:
8182 $$ = list_make1($1);
8184 | TableFuncElementList ',' TableFuncElement
8186 $$ = lappend($1, $3);
8190 TableFuncElement: ColId Typename
8192 ColumnDef *n = makeNode(ColumnDef);
8195 n->constraints = NIL;
8201 /*****************************************************************************
8204 * SQL92 introduces a large amount of type-specific syntax.
8205 * Define individual clauses to handle these cases, and use
8206 * the generic case to handle regular type-extensible Postgres syntax.
8207 * - thomas 1997-10-10
8209 *****************************************************************************/
8211 Typename: SimpleTypename opt_array_bounds
8214 $$->arrayBounds = $2;
8216 | SETOF SimpleTypename opt_array_bounds
8219 $$->arrayBounds = $3;
8222 /* SQL standard syntax, currently only one-dimensional */
8223 | SimpleTypename ARRAY '[' Iconst ']'
8226 $$->arrayBounds = list_make1(makeInteger($4));
8228 | SETOF SimpleTypename ARRAY '[' Iconst ']'
8231 $$->arrayBounds = list_make1(makeInteger($5));
8234 | SimpleTypename ARRAY
8237 $$->arrayBounds = list_make1(makeInteger(-1));
8239 | SETOF SimpleTypename ARRAY
8242 $$->arrayBounds = list_make1(makeInteger(-1));
8248 opt_array_bounds '[' ']'
8249 { $$ = lappend($1, makeInteger(-1)); }
8250 | opt_array_bounds '[' Iconst ']'
8251 { $$ = lappend($1, makeInteger($3)); }
8257 GenericType { $$ = $1; }
8258 | Numeric { $$ = $1; }
8260 | Character { $$ = $1; }
8261 | ConstDatetime { $$ = $1; }
8262 | ConstInterval opt_interval
8267 | ConstInterval '(' Iconst ')' opt_interval
8272 if (list_length($5) != 1)
8274 (errcode(ERRCODE_SYNTAX_ERROR),
8275 errmsg("interval precision specified twice"),
8276 parser_errposition(@1)));
8277 $$->typmods = lappend($5, makeIntConst($3, @3));
8280 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
8281 makeIntConst($3, @3));
8285 /* We have a separate ConstTypename to allow defaulting fixed-length
8286 * types such as CHAR() and BIT() to an unspecified length.
8287 * SQL9x requires that these default to a length of one, but this
8288 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
8289 * where there is an obvious better choice to make.
8290 * Note that ConstInterval is not included here since it must
8291 * be pushed up higher in the rules to accomodate the postfix
8292 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
8293 * the generic-type-name case in AExprConst to avoid premature
8294 * reduce/reduce conflicts against function names.
8297 Numeric { $$ = $1; }
8298 | ConstBit { $$ = $1; }
8299 | ConstCharacter { $$ = $1; }
8300 | ConstDatetime { $$ = $1; }
8304 * GenericType covers all type names that don't have special syntax mandated
8305 * by the standard, including qualified names. We also allow type modifiers.
8306 * To avoid parsing conflicts against function invocations, the modifiers
8307 * have to be shown as expr_list here, but parse analysis will only accept
8308 * constants for them.
8311 type_function_name opt_type_modifiers
8313 $$ = makeTypeName($1);
8317 | type_function_name attrs opt_type_modifiers
8319 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8325 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
8326 | /* EMPTY */ { $$ = NIL; }
8330 * SQL92 numeric data types
8334 $$ = SystemTypeName("int4");
8339 $$ = SystemTypeName("int4");
8344 $$ = SystemTypeName("int2");
8349 $$ = SystemTypeName("int8");
8354 $$ = SystemTypeName("float4");
8362 | DOUBLE_P PRECISION
8364 $$ = SystemTypeName("float8");
8367 | DECIMAL_P opt_type_modifiers
8369 $$ = SystemTypeName("numeric");
8373 | DEC opt_type_modifiers
8375 $$ = SystemTypeName("numeric");
8379 | NUMERIC opt_type_modifiers
8381 $$ = SystemTypeName("numeric");
8387 $$ = SystemTypeName("bool");
8392 opt_float: '(' Iconst ')'
8395 * Check FLOAT() precision limits assuming IEEE floating
8396 * types - thomas 1997-09-18
8400 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8401 errmsg("precision for type float must be at least 1 bit"),
8402 parser_errposition(@2)));
8404 $$ = SystemTypeName("float4");
8406 $$ = SystemTypeName("float8");
8409 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8410 errmsg("precision for type float must be less than 54 bits"),
8411 parser_errposition(@2)));
8415 $$ = SystemTypeName("float8");
8420 * SQL92 bit-field data types
8421 * The following implements BIT() and BIT VARYING().
8433 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
8434 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
8435 ConstBit: BitWithLength
8447 BIT opt_varying '(' expr_list ')'
8451 typname = $2 ? "varbit" : "bit";
8452 $$ = SystemTypeName(typname);
8461 /* bit defaults to bit(1), varbit to no limit */
8464 $$ = SystemTypeName("varbit");
8468 $$ = SystemTypeName("bit");
8469 $$->typmods = list_make1(makeIntConst(1, -1));
8477 * SQL92 character data types
8478 * The following implements CHAR() and VARCHAR().
8480 Character: CharacterWithLength
8484 | CharacterWithoutLength
8490 ConstCharacter: CharacterWithLength
8494 | CharacterWithoutLength
8496 /* Length was not specified so allow to be unrestricted.
8497 * This handles problems with fixed-length (bpchar) strings
8498 * which in column definitions must default to a length
8499 * of one, but should not be constrained if the length
8500 * was not specified.
8507 CharacterWithLength: character '(' Iconst ')' opt_charset
8509 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
8513 type = palloc(strlen($1) + 1 + strlen($5) + 1);
8520 $$ = SystemTypeName($1);
8521 $$->typmods = list_make1(makeIntConst($3, @3));
8526 CharacterWithoutLength: character opt_charset
8528 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
8532 type = palloc(strlen($1) + 1 + strlen($2) + 1);
8539 $$ = SystemTypeName($1);
8541 /* char defaults to char(1), varchar to no limit */
8542 if (strcmp($1, "bpchar") == 0)
8543 $$->typmods = list_make1(makeIntConst(1, -1));
8549 character: CHARACTER opt_varying
8550 { $$ = $2 ? "varchar": "bpchar"; }
8551 | CHAR_P opt_varying
8552 { $$ = $2 ? "varchar": "bpchar"; }
8555 | NATIONAL CHARACTER opt_varying
8556 { $$ = $3 ? "varchar": "bpchar"; }
8557 | NATIONAL CHAR_P opt_varying
8558 { $$ = $3 ? "varchar": "bpchar"; }
8560 { $$ = $2 ? "varchar": "bpchar"; }
8564 VARYING { $$ = TRUE; }
8565 | /*EMPTY*/ { $$ = FALSE; }
8569 CHARACTER SET ColId { $$ = $3; }
8570 | /*EMPTY*/ { $$ = NULL; }
8574 * SQL92 date/time types
8577 TIMESTAMP '(' Iconst ')' opt_timezone
8580 $$ = SystemTypeName("timestamptz");
8582 $$ = SystemTypeName("timestamp");
8583 $$->typmods = list_make1(makeIntConst($3, @3));
8586 | TIMESTAMP opt_timezone
8589 $$ = SystemTypeName("timestamptz");
8591 $$ = SystemTypeName("timestamp");
8594 | TIME '(' Iconst ')' opt_timezone
8597 $$ = SystemTypeName("timetz");
8599 $$ = SystemTypeName("time");
8600 $$->typmods = list_make1(makeIntConst($3, @3));
8606 $$ = SystemTypeName("timetz");
8608 $$ = SystemTypeName("time");
8616 $$ = SystemTypeName("interval");
8622 WITH_TIME ZONE { $$ = TRUE; }
8623 | WITHOUT TIME ZONE { $$ = FALSE; }
8624 | /*EMPTY*/ { $$ = FALSE; }
8629 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
8631 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
8633 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
8635 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
8637 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
8642 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
8643 INTERVAL_MASK(MONTH), @1));
8647 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8648 INTERVAL_MASK(HOUR), @1));
8652 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8653 INTERVAL_MASK(HOUR) |
8654 INTERVAL_MASK(MINUTE), @1));
8656 | DAY_P TO interval_second
8659 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
8660 INTERVAL_MASK(HOUR) |
8661 INTERVAL_MASK(MINUTE) |
8662 INTERVAL_MASK(SECOND), @1);
8664 | HOUR_P TO MINUTE_P
8666 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
8667 INTERVAL_MASK(MINUTE), @1));
8669 | HOUR_P TO interval_second
8672 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
8673 INTERVAL_MASK(MINUTE) |
8674 INTERVAL_MASK(SECOND), @1);
8676 | MINUTE_P TO interval_second
8679 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
8680 INTERVAL_MASK(SECOND), @1);
8689 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
8691 | SECOND_P '(' Iconst ')'
8693 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
8694 makeIntConst($3, @3));
8699 /*****************************************************************************
8701 * expression grammar
8703 *****************************************************************************/
8706 * General expressions
8707 * This is the heart of the expression syntax.
8709 * We have two expression types: a_expr is the unrestricted kind, and
8710 * b_expr is a subset that must be used in some places to avoid shift/reduce
8711 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
8712 * because that use of AND conflicts with AND as a boolean operator. So,
8713 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
8715 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
8716 * always be used by surrounding it with parens.
8718 * c_expr is all the productions that are common to a_expr and b_expr;
8719 * it's factored out just to eliminate redundant coding.
8721 a_expr: c_expr { $$ = $1; }
8722 | a_expr TYPECAST Typename
8723 { $$ = makeTypeCast($1, $3, @2); }
8724 | a_expr AT TIME ZONE a_expr
8726 FuncCall *n = makeNode(FuncCall);
8727 n->funcname = SystemFuncName("timezone");
8728 n->args = list_make2($5, $1);
8730 n->agg_star = FALSE;
8731 n->agg_distinct = FALSE;
8732 n->func_variadic = FALSE;
8738 * These operators must be called out explicitly in order to make use
8739 * of bison's automatic operator-precedence handling. All other
8740 * operator names are handled by the generic productions using "Op",
8741 * below; and all those operators will have the same precedence.
8743 * If you add more explicitly-known operators, be sure to add them
8744 * also to b_expr and to the MathOp list above.
8746 | '+' a_expr %prec UMINUS
8747 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
8748 | '-' a_expr %prec UMINUS
8749 { $$ = doNegate($2, @1); }
8751 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
8753 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
8755 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
8757 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
8759 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
8761 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
8763 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
8765 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
8767 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
8769 | a_expr qual_Op a_expr %prec Op
8770 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
8771 | qual_Op a_expr %prec Op
8772 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
8773 | a_expr qual_Op %prec POSTFIXOP
8774 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
8777 { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
8779 { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
8781 { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
8783 | a_expr LIKE a_expr
8784 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
8785 | a_expr LIKE a_expr ESCAPE a_expr
8787 FuncCall *n = makeNode(FuncCall);
8788 n->funcname = SystemFuncName("like_escape");
8789 n->args = list_make2($3, $5);
8791 n->agg_star = FALSE;
8792 n->agg_distinct = FALSE;
8793 n->func_variadic = FALSE;
8796 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
8798 | a_expr NOT LIKE a_expr
8799 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
8800 | a_expr NOT LIKE a_expr ESCAPE a_expr
8802 FuncCall *n = makeNode(FuncCall);
8803 n->funcname = SystemFuncName("like_escape");
8804 n->args = list_make2($4, $6);
8806 n->agg_star = FALSE;
8807 n->agg_distinct = FALSE;
8808 n->func_variadic = FALSE;
8811 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
8813 | a_expr ILIKE a_expr
8814 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
8815 | a_expr ILIKE a_expr ESCAPE a_expr
8817 FuncCall *n = makeNode(FuncCall);
8818 n->funcname = SystemFuncName("like_escape");
8819 n->args = list_make2($3, $5);
8821 n->agg_star = FALSE;
8822 n->agg_distinct = FALSE;
8823 n->func_variadic = FALSE;
8826 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n, @2);
8828 | a_expr NOT ILIKE a_expr
8829 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
8830 | a_expr NOT ILIKE a_expr ESCAPE a_expr
8832 FuncCall *n = makeNode(FuncCall);
8833 n->funcname = SystemFuncName("like_escape");
8834 n->args = list_make2($4, $6);
8836 n->agg_star = FALSE;
8837 n->agg_distinct = FALSE;
8838 n->func_variadic = FALSE;
8841 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n, @2);
8844 | a_expr SIMILAR TO a_expr %prec SIMILAR
8846 FuncCall *n = makeNode(FuncCall);
8847 n->funcname = SystemFuncName("similar_escape");
8848 n->args = list_make2($4, makeNullAConst(-1));
8850 n->agg_star = FALSE;
8851 n->agg_distinct = FALSE;
8852 n->func_variadic = FALSE;
8855 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8857 | a_expr SIMILAR TO a_expr ESCAPE a_expr
8859 FuncCall *n = makeNode(FuncCall);
8860 n->funcname = SystemFuncName("similar_escape");
8861 n->args = list_make2($4, $6);
8863 n->agg_star = FALSE;
8864 n->agg_distinct = FALSE;
8865 n->func_variadic = FALSE;
8868 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8870 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
8872 FuncCall *n = makeNode(FuncCall);
8873 n->funcname = SystemFuncName("similar_escape");
8874 n->args = list_make2($5, makeNullAConst(-1));
8876 n->agg_star = FALSE;
8877 n->agg_distinct = FALSE;
8878 n->func_variadic = FALSE;
8881 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8883 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
8885 FuncCall *n = makeNode(FuncCall);
8886 n->funcname = SystemFuncName("similar_escape");
8887 n->args = list_make2($5, $7);
8889 n->agg_star = FALSE;
8890 n->agg_distinct = FALSE;
8891 n->func_variadic = FALSE;
8894 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8898 * Define SQL92-style Null test clause.
8899 * Allow two forms described in the standard:
8902 * Allow two SQL extensions
8908 NullTest *n = makeNode(NullTest);
8909 n->arg = (Expr *) $1;
8910 n->nulltesttype = IS_NULL;
8915 NullTest *n = makeNode(NullTest);
8916 n->arg = (Expr *) $1;
8917 n->nulltesttype = IS_NULL;
8920 | a_expr IS NOT NULL_P
8922 NullTest *n = makeNode(NullTest);
8923 n->arg = (Expr *) $1;
8924 n->nulltesttype = IS_NOT_NULL;
8929 NullTest *n = makeNode(NullTest);
8930 n->arg = (Expr *) $1;
8931 n->nulltesttype = IS_NOT_NULL;
8936 $$ = (Node *)makeOverlaps($1, $3, @2, yyscanner);
8940 BooleanTest *b = makeNode(BooleanTest);
8941 b->arg = (Expr *) $1;
8942 b->booltesttype = IS_TRUE;
8945 | a_expr IS NOT TRUE_P
8947 BooleanTest *b = makeNode(BooleanTest);
8948 b->arg = (Expr *) $1;
8949 b->booltesttype = IS_NOT_TRUE;
8954 BooleanTest *b = makeNode(BooleanTest);
8955 b->arg = (Expr *) $1;
8956 b->booltesttype = IS_FALSE;
8959 | a_expr IS NOT FALSE_P
8961 BooleanTest *b = makeNode(BooleanTest);
8962 b->arg = (Expr *) $1;
8963 b->booltesttype = IS_NOT_FALSE;
8968 BooleanTest *b = makeNode(BooleanTest);
8969 b->arg = (Expr *) $1;
8970 b->booltesttype = IS_UNKNOWN;
8973 | a_expr IS NOT UNKNOWN
8975 BooleanTest *b = makeNode(BooleanTest);
8976 b->arg = (Expr *) $1;
8977 b->booltesttype = IS_NOT_UNKNOWN;
8980 | a_expr IS DISTINCT FROM a_expr %prec IS
8982 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
8984 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
8986 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8987 (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
8992 | a_expr IS OF '(' type_list ')' %prec IS
8994 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
8996 | a_expr IS NOT OF '(' type_list ')' %prec IS
8998 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
9001 * Ideally we would not use hard-wired operators below but
9002 * instead use opclasses. However, mixed data types and other
9003 * issues make this difficult:
9004 * http://archives.postgresql.org/pgsql-hackers/2008-08/msg01142.php
9006 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
9008 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
9009 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
9010 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
9013 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
9015 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
9016 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
9017 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
9020 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
9022 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
9023 (Node *) makeA_Expr(AEXPR_AND, NIL,
9024 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
9025 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
9027 (Node *) makeA_Expr(AEXPR_AND, NIL,
9028 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
9029 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
9033 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
9035 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
9036 (Node *) makeA_Expr(AEXPR_OR, NIL,
9037 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
9038 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
9040 (Node *) makeA_Expr(AEXPR_OR, NIL,
9041 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
9042 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
9046 | a_expr IN_P in_expr
9048 /* in_expr returns a SubLink or a list of a_exprs */
9049 if (IsA($3, SubLink))
9051 /* generate foo = ANY (subquery) */
9052 SubLink *n = (SubLink *) $3;
9053 n->subLinkType = ANY_SUBLINK;
9055 n->operName = list_make1(makeString("="));
9061 /* generate scalar IN expression */
9062 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
9065 | a_expr NOT IN_P in_expr
9067 /* in_expr returns a SubLink or a list of a_exprs */
9068 if (IsA($4, SubLink))
9070 /* generate NOT (foo = ANY (subquery)) */
9071 /* Make an = ANY node */
9072 SubLink *n = (SubLink *) $4;
9073 n->subLinkType = ANY_SUBLINK;
9075 n->operName = list_make1(makeString("="));
9077 /* Stick a NOT on top */
9078 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
9082 /* generate scalar NOT IN expression */
9083 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
9086 | a_expr subquery_Op sub_type select_with_parens %prec Op
9088 SubLink *n = makeNode(SubLink);
9089 n->subLinkType = $3;
9096 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
9098 if ($3 == ANY_SUBLINK)
9099 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
9101 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
9103 | UNIQUE select_with_parens
9105 /* Not sure how to get rid of the parentheses
9106 * but there are lots of shift/reduce errors without them.
9108 * Should be able to implement this by plopping the entire
9109 * select into a node, then transforming the target expressions
9110 * from whatever they are into count(*), and testing the
9111 * entire result equal to one.
9112 * But, will probably implement a separate node in the executor.
9115 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9116 errmsg("UNIQUE predicate is not yet implemented"),
9117 parser_errposition(@1)));
9119 | a_expr IS DOCUMENT_P %prec IS
9121 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9122 list_make1($1), @2);
9124 | a_expr IS NOT DOCUMENT_P %prec IS
9126 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9127 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9128 list_make1($1), @2),
9134 * Restricted expressions
9136 * b_expr is a subset of the complete expression syntax defined by a_expr.
9138 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
9139 * cause trouble in the places where b_expr is used. For simplicity, we
9140 * just eliminate all the boolean-keyword-operator productions from b_expr.
9144 | b_expr TYPECAST Typename
9145 { $$ = makeTypeCast($1, $3, @2); }
9146 | '+' b_expr %prec UMINUS
9147 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
9148 | '-' b_expr %prec UMINUS
9149 { $$ = doNegate($2, @1); }
9151 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
9153 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
9155 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
9157 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
9159 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
9161 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
9163 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
9165 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
9167 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
9168 | b_expr qual_Op b_expr %prec Op
9169 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
9170 | qual_Op b_expr %prec Op
9171 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
9172 | b_expr qual_Op %prec POSTFIXOP
9173 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
9174 | b_expr IS DISTINCT FROM b_expr %prec IS
9176 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
9178 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
9180 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
9181 NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
9183 | b_expr IS OF '(' type_list ')' %prec IS
9185 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
9187 | b_expr IS NOT OF '(' type_list ')' %prec IS
9189 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
9191 | b_expr IS DOCUMENT_P %prec IS
9193 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9194 list_make1($1), @2);
9196 | b_expr IS NOT DOCUMENT_P %prec IS
9198 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9199 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9200 list_make1($1), @2),
9206 * Productions that can be used in both a_expr and b_expr.
9208 * Note: productions that refer recursively to a_expr or b_expr mostly
9209 * cannot appear here. However, it's OK to refer to a_exprs that occur
9210 * inside parentheses, such as function arguments; that cannot introduce
9211 * ambiguity to the b_expr syntax.
9213 c_expr: columnref { $$ = $1; }
9214 | AexprConst { $$ = $1; }
9215 | PARAM opt_indirection
9217 ParamRef *p = makeNode(ParamRef);
9222 A_Indirection *n = makeNode(A_Indirection);
9223 n->arg = (Node *) p;
9224 n->indirection = check_indirection($2, yyscanner);
9230 | '(' a_expr ')' opt_indirection
9234 A_Indirection *n = makeNode(A_Indirection);
9236 n->indirection = check_indirection($4, yyscanner);
9246 | select_with_parens %prec UMINUS
9248 SubLink *n = makeNode(SubLink);
9249 n->subLinkType = EXPR_SUBLINK;
9256 | EXISTS select_with_parens
9258 SubLink *n = makeNode(SubLink);
9259 n->subLinkType = EXISTS_SUBLINK;
9266 | ARRAY select_with_parens
9268 SubLink *n = makeNode(SubLink);
9269 n->subLinkType = ARRAY_SUBLINK;
9278 A_ArrayExpr *n = (A_ArrayExpr *) $2;
9279 Assert(IsA(n, A_ArrayExpr));
9280 /* point outermost A_ArrayExpr to the ARRAY keyword */
9286 RowExpr *r = makeNode(RowExpr);
9288 r->row_typeid = InvalidOid; /* not analyzed yet */
9295 * func_expr is split out from c_expr just so that we have a classification
9296 * for "everything that is a function call or looks like one". This isn't
9297 * very important, but it saves us having to document which variants are
9298 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
9299 * (Note that many of the special SQL functions wouldn't actually make any
9300 * sense as functional index entries, but we ignore that consideration here.)
9302 func_expr: func_name '(' ')' over_clause
9304 FuncCall *n = makeNode(FuncCall);
9308 n->agg_star = FALSE;
9309 n->agg_distinct = FALSE;
9310 n->func_variadic = FALSE;
9315 | func_name '(' func_arg_list ')' over_clause
9317 FuncCall *n = makeNode(FuncCall);
9321 n->agg_star = FALSE;
9322 n->agg_distinct = FALSE;
9323 n->func_variadic = FALSE;
9328 | func_name '(' VARIADIC func_arg_expr ')' over_clause
9330 FuncCall *n = makeNode(FuncCall);
9332 n->args = list_make1($4);
9334 n->agg_star = FALSE;
9335 n->agg_distinct = FALSE;
9336 n->func_variadic = TRUE;
9341 | func_name '(' func_arg_list ',' VARIADIC func_arg_expr ')' over_clause
9343 FuncCall *n = makeNode(FuncCall);
9345 n->args = lappend($3, $6);
9347 n->agg_star = FALSE;
9348 n->agg_distinct = FALSE;
9349 n->func_variadic = TRUE;
9354 | func_name '(' func_arg_list sort_clause ')' over_clause
9356 FuncCall *n = makeNode(FuncCall);
9360 n->agg_star = FALSE;
9361 n->agg_distinct = FALSE;
9362 n->func_variadic = FALSE;
9367 | func_name '(' ALL func_arg_list opt_sort_clause ')' over_clause
9369 FuncCall *n = makeNode(FuncCall);
9373 n->agg_star = FALSE;
9374 n->agg_distinct = FALSE;
9375 /* Ideally we'd mark the FuncCall node to indicate
9376 * "must be an aggregate", but there's no provision
9377 * for that in FuncCall at the moment.
9379 n->func_variadic = FALSE;
9384 | func_name '(' DISTINCT func_arg_list opt_sort_clause ')' over_clause
9386 FuncCall *n = makeNode(FuncCall);
9390 n->agg_star = FALSE;
9391 n->agg_distinct = TRUE;
9392 n->func_variadic = FALSE;
9397 | func_name '(' '*' ')' over_clause
9400 * We consider AGGREGATE(*) to invoke a parameterless
9401 * aggregate. This does the right thing for COUNT(*),
9402 * and there are no other aggregates in SQL92 that accept
9405 * The FuncCall node is also marked agg_star = true,
9406 * so that later processing can detect what the argument
9409 FuncCall *n = makeNode(FuncCall);
9414 n->agg_distinct = FALSE;
9415 n->func_variadic = FALSE;
9423 * Translate as "'now'::text::date".
9425 * We cannot use "'now'::date" because coerce_type() will
9426 * immediately reduce that to a constant representing
9427 * today's date. We need to delay the conversion until
9428 * runtime, else the wrong things will happen when
9429 * CURRENT_DATE is used in a column default value or rule.
9431 * This could be simplified if we had a way to generate
9432 * an expression tree representing runtime application
9433 * of type-input conversion functions. (As of PG 7.3
9434 * that is actually possible, but not clear that we want
9438 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9439 $$ = makeTypeCast(n, SystemTypeName("date"), -1);
9444 * Translate as "'now'::text::timetz".
9445 * See comments for CURRENT_DATE.
9448 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9449 $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
9451 | CURRENT_TIME '(' Iconst ')'
9454 * Translate as "'now'::text::timetz(n)".
9455 * See comments for CURRENT_DATE.
9459 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9460 d = SystemTypeName("timetz");
9461 d->typmods = list_make1(makeIntConst($3, @3));
9462 $$ = makeTypeCast(n, d, -1);
9467 * Translate as "now()", since we have a function that
9468 * does exactly what is needed.
9470 FuncCall *n = makeNode(FuncCall);
9471 n->funcname = SystemFuncName("now");
9474 n->agg_star = FALSE;
9475 n->agg_distinct = FALSE;
9476 n->func_variadic = FALSE;
9481 | CURRENT_TIMESTAMP '(' Iconst ')'
9484 * Translate as "'now'::text::timestamptz(n)".
9485 * See comments for CURRENT_DATE.
9489 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9490 d = SystemTypeName("timestamptz");
9491 d->typmods = list_make1(makeIntConst($3, @3));
9492 $$ = makeTypeCast(n, d, -1);
9497 * Translate as "'now'::text::time".
9498 * See comments for CURRENT_DATE.
9501 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9502 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
9504 | LOCALTIME '(' Iconst ')'
9507 * Translate as "'now'::text::time(n)".
9508 * See comments for CURRENT_DATE.
9512 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9513 d = SystemTypeName("time");
9514 d->typmods = list_make1(makeIntConst($3, @3));
9515 $$ = makeTypeCast((Node *)n, d, -1);
9520 * Translate as "'now'::text::timestamp".
9521 * See comments for CURRENT_DATE.
9524 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9525 $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
9527 | LOCALTIMESTAMP '(' Iconst ')'
9530 * Translate as "'now'::text::timestamp(n)".
9531 * See comments for CURRENT_DATE.
9535 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9536 d = SystemTypeName("timestamp");
9537 d->typmods = list_make1(makeIntConst($3, @3));
9538 $$ = makeTypeCast(n, d, -1);
9542 FuncCall *n = makeNode(FuncCall);
9543 n->funcname = SystemFuncName("current_user");
9546 n->agg_star = FALSE;
9547 n->agg_distinct = FALSE;
9548 n->func_variadic = FALSE;
9555 FuncCall *n = makeNode(FuncCall);
9556 n->funcname = SystemFuncName("current_user");
9559 n->agg_star = FALSE;
9560 n->agg_distinct = FALSE;
9561 n->func_variadic = FALSE;
9568 FuncCall *n = makeNode(FuncCall);
9569 n->funcname = SystemFuncName("session_user");
9572 n->agg_star = FALSE;
9573 n->agg_distinct = FALSE;
9574 n->func_variadic = FALSE;
9581 FuncCall *n = makeNode(FuncCall);
9582 n->funcname = SystemFuncName("current_user");
9585 n->agg_star = FALSE;
9586 n->agg_distinct = FALSE;
9587 n->func_variadic = FALSE;
9594 FuncCall *n = makeNode(FuncCall);
9595 n->funcname = SystemFuncName("current_database");
9598 n->agg_star = FALSE;
9599 n->agg_distinct = FALSE;
9600 n->func_variadic = FALSE;
9607 FuncCall *n = makeNode(FuncCall);
9608 n->funcname = SystemFuncName("current_schema");
9611 n->agg_star = FALSE;
9612 n->agg_distinct = FALSE;
9613 n->func_variadic = FALSE;
9618 | CAST '(' a_expr AS Typename ')'
9619 { $$ = makeTypeCast($3, $5, @1); }
9620 | EXTRACT '(' extract_list ')'
9622 FuncCall *n = makeNode(FuncCall);
9623 n->funcname = SystemFuncName("date_part");
9626 n->agg_star = FALSE;
9627 n->agg_distinct = FALSE;
9628 n->func_variadic = FALSE;
9633 | OVERLAY '(' overlay_list ')'
9635 /* overlay(A PLACING B FROM C FOR D) is converted to
9636 * overlay(A, B, C, D)
9637 * overlay(A PLACING B FROM C) is converted to
9640 FuncCall *n = makeNode(FuncCall);
9641 n->funcname = SystemFuncName("overlay");
9644 n->agg_star = FALSE;
9645 n->agg_distinct = FALSE;
9646 n->func_variadic = FALSE;
9651 | POSITION '(' position_list ')'
9653 /* position(A in B) is converted to position(B, A) */
9654 FuncCall *n = makeNode(FuncCall);
9655 n->funcname = SystemFuncName("position");
9658 n->agg_star = FALSE;
9659 n->agg_distinct = FALSE;
9660 n->func_variadic = FALSE;
9665 | SUBSTRING '(' substr_list ')'
9667 /* substring(A from B for C) is converted to
9668 * substring(A, B, C) - thomas 2000-11-28
9670 FuncCall *n = makeNode(FuncCall);
9671 n->funcname = SystemFuncName("substring");
9674 n->agg_star = FALSE;
9675 n->agg_distinct = FALSE;
9676 n->func_variadic = FALSE;
9681 | TREAT '(' a_expr AS Typename ')'
9683 /* TREAT(expr AS target) converts expr of a particular type to target,
9684 * which is defined to be a subtype of the original expression.
9685 * In SQL99, this is intended for use with structured UDTs,
9686 * but let's make this a generally useful form allowing stronger
9687 * coercions than are handled by implicit casting.
9689 FuncCall *n = makeNode(FuncCall);
9690 /* Convert SystemTypeName() to SystemFuncName() even though
9691 * at the moment they result in the same thing.
9693 n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
9694 n->args = list_make1($3);
9696 n->agg_star = FALSE;
9697 n->agg_distinct = FALSE;
9698 n->func_variadic = FALSE;
9703 | TRIM '(' BOTH trim_list ')'
9705 /* various trim expressions are defined in SQL92
9706 * - thomas 1997-07-19
9708 FuncCall *n = makeNode(FuncCall);
9709 n->funcname = SystemFuncName("btrim");
9712 n->agg_star = FALSE;
9713 n->agg_distinct = FALSE;
9714 n->func_variadic = FALSE;
9719 | TRIM '(' LEADING trim_list ')'
9721 FuncCall *n = makeNode(FuncCall);
9722 n->funcname = SystemFuncName("ltrim");
9725 n->agg_star = FALSE;
9726 n->agg_distinct = FALSE;
9727 n->func_variadic = FALSE;
9732 | TRIM '(' TRAILING trim_list ')'
9734 FuncCall *n = makeNode(FuncCall);
9735 n->funcname = SystemFuncName("rtrim");
9738 n->agg_star = FALSE;
9739 n->agg_distinct = FALSE;
9740 n->func_variadic = FALSE;
9745 | TRIM '(' trim_list ')'
9747 FuncCall *n = makeNode(FuncCall);
9748 n->funcname = SystemFuncName("btrim");
9751 n->agg_star = FALSE;
9752 n->agg_distinct = FALSE;
9753 n->func_variadic = FALSE;
9758 | NULLIF '(' a_expr ',' a_expr ')'
9760 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
9762 | COALESCE '(' expr_list ')'
9764 CoalesceExpr *c = makeNode(CoalesceExpr);
9769 | GREATEST '(' expr_list ')'
9771 MinMaxExpr *v = makeNode(MinMaxExpr);
9773 v->op = IS_GREATEST;
9777 | LEAST '(' expr_list ')'
9779 MinMaxExpr *v = makeNode(MinMaxExpr);
9785 | XMLCONCAT '(' expr_list ')'
9787 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
9789 | XMLELEMENT '(' NAME_P ColLabel ')'
9791 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
9793 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
9795 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
9797 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
9799 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
9801 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
9803 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
9805 | XMLFOREST '(' xml_attribute_list ')'
9807 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
9809 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
9811 XmlExpr *x = (XmlExpr *)
9812 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
9813 list_make2($4, makeBoolAConst($5, -1)),
9818 | XMLPI '(' NAME_P ColLabel ')'
9820 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
9822 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
9824 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
9826 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
9828 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
9829 list_make3($3, $5, $6), @1);
9831 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
9833 XmlSerialize *n = makeNode(XmlSerialize);
9845 xml_root_version: VERSION_P a_expr
9847 | VERSION_P NO VALUE_P
9848 { $$ = makeNullAConst(-1); }
9851 opt_xml_root_standalone: ',' STANDALONE_P YES_P
9852 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
9853 | ',' STANDALONE_P NO
9854 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
9855 | ',' STANDALONE_P NO VALUE_P
9856 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
9858 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
9861 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
9864 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
9865 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
9868 xml_attribute_el: a_expr AS ColLabel
9870 $$ = makeNode(ResTarget);
9872 $$->indirection = NIL;
9873 $$->val = (Node *) $1;
9878 $$ = makeNode(ResTarget);
9880 $$->indirection = NIL;
9881 $$->val = (Node *) $1;
9886 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
9887 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
9890 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
9891 | STRIP_P WHITESPACE_P { $$ = FALSE; }
9892 | /*EMPTY*/ { $$ = FALSE; }
9896 * Window Definitions
9899 WINDOW window_definition_list { $$ = $2; }
9900 | /*EMPTY*/ { $$ = NIL; }
9903 window_definition_list:
9904 window_definition { $$ = list_make1($1); }
9905 | window_definition_list ',' window_definition
9906 { $$ = lappend($1, $3); }
9910 ColId AS window_specification
9918 over_clause: OVER window_specification
9922 WindowDef *n = makeNode(WindowDef);
9925 n->partitionClause = NIL;
9926 n->orderClause = NIL;
9927 n->frameOptions = FRAMEOPTION_DEFAULTS;
9928 n->startOffset = NULL;
9929 n->endOffset = NULL;
9937 window_specification: '(' opt_existing_window_name opt_partition_clause
9938 opt_sort_clause opt_frame_clause ')'
9940 WindowDef *n = makeNode(WindowDef);
9943 n->partitionClause = $3;
9944 n->orderClause = $4;
9945 /* copy relevant fields of opt_frame_clause */
9946 n->frameOptions = $5->frameOptions;
9947 n->startOffset = $5->startOffset;
9948 n->endOffset = $5->endOffset;
9955 * If we see PARTITION, RANGE, or ROWS as the first token after the '('
9956 * of a window_specification, we want the assumption to be that there is
9957 * no existing_window_name; but those keywords are unreserved and so could
9958 * be ColIds. We fix this by making them have the same precedence as IDENT
9959 * and giving the empty production here a slightly higher precedence, so
9960 * that the shift/reduce conflict is resolved in favor of reducing the rule.
9961 * These keywords are thus precluded from being an existing_window_name but
9962 * are not reserved for any other purpose.
9964 opt_existing_window_name: ColId { $$ = $1; }
9965 | /*EMPTY*/ %prec Op { $$ = NULL; }
9968 opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
9969 | /*EMPTY*/ { $$ = NIL; }
9973 * For frame clauses, we return a WindowDef, but only some fields are used:
9974 * frameOptions, startOffset, and endOffset.
9976 * This is only a subset of the full SQL:2008 frame_clause grammar.
9977 * We don't support <window frame exclusion> yet.
9983 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
9984 if (n->frameOptions & (FRAMEOPTION_START_VALUE_PRECEDING |
9985 FRAMEOPTION_END_VALUE_PRECEDING))
9987 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9988 errmsg("RANGE PRECEDING is only supported with UNBOUNDED"),
9989 parser_errposition(@1)));
9990 if (n->frameOptions & (FRAMEOPTION_START_VALUE_FOLLOWING |
9991 FRAMEOPTION_END_VALUE_FOLLOWING))
9993 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9994 errmsg("RANGE FOLLOWING is only supported with UNBOUNDED"),
9995 parser_errposition(@1)));
10001 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
10006 WindowDef *n = makeNode(WindowDef);
10007 n->frameOptions = FRAMEOPTION_DEFAULTS;
10008 n->startOffset = NULL;
10009 n->endOffset = NULL;
10014 frame_extent: frame_bound
10017 /* reject invalid cases */
10018 if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
10020 (errcode(ERRCODE_WINDOWING_ERROR),
10021 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
10022 parser_errposition(@1)));
10023 if (n->frameOptions & FRAMEOPTION_START_VALUE_FOLLOWING)
10025 (errcode(ERRCODE_WINDOWING_ERROR),
10026 errmsg("frame starting from following row cannot end with current row"),
10027 parser_errposition(@1)));
10028 n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
10031 | BETWEEN frame_bound AND frame_bound
10033 WindowDef *n1 = $2;
10034 WindowDef *n2 = $4;
10035 /* form merged options */
10036 int frameOptions = n1->frameOptions;
10037 /* shift converts START_ options to END_ options */
10038 frameOptions |= n2->frameOptions << 1;
10039 frameOptions |= FRAMEOPTION_BETWEEN;
10040 /* reject invalid cases */
10041 if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
10043 (errcode(ERRCODE_WINDOWING_ERROR),
10044 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
10045 parser_errposition(@2)));
10046 if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
10048 (errcode(ERRCODE_WINDOWING_ERROR),
10049 errmsg("frame end cannot be UNBOUNDED PRECEDING"),
10050 parser_errposition(@4)));
10051 if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
10052 (frameOptions & FRAMEOPTION_END_VALUE_PRECEDING))
10054 (errcode(ERRCODE_WINDOWING_ERROR),
10055 errmsg("frame starting from current row cannot have preceding rows"),
10056 parser_errposition(@4)));
10057 if ((frameOptions & FRAMEOPTION_START_VALUE_FOLLOWING) &&
10058 (frameOptions & (FRAMEOPTION_END_VALUE_PRECEDING |
10059 FRAMEOPTION_END_CURRENT_ROW)))
10061 (errcode(ERRCODE_WINDOWING_ERROR),
10062 errmsg("frame starting from following row cannot have preceding rows"),
10063 parser_errposition(@4)));
10064 n1->frameOptions = frameOptions;
10065 n1->endOffset = n2->startOffset;
10071 * This is used for both frame start and frame end, with output set up on
10072 * the assumption it's frame start; the frame_extent productions must reject
10076 UNBOUNDED PRECEDING
10078 WindowDef *n = makeNode(WindowDef);
10079 n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
10080 n->startOffset = NULL;
10081 n->endOffset = NULL;
10084 | UNBOUNDED FOLLOWING
10086 WindowDef *n = makeNode(WindowDef);
10087 n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
10088 n->startOffset = NULL;
10089 n->endOffset = NULL;
10094 WindowDef *n = makeNode(WindowDef);
10095 n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
10096 n->startOffset = NULL;
10097 n->endOffset = NULL;
10102 WindowDef *n = makeNode(WindowDef);
10103 n->frameOptions = FRAMEOPTION_START_VALUE_PRECEDING;
10104 n->startOffset = $1;
10105 n->endOffset = NULL;
10110 WindowDef *n = makeNode(WindowDef);
10111 n->frameOptions = FRAMEOPTION_START_VALUE_FOLLOWING;
10112 n->startOffset = $1;
10113 n->endOffset = NULL;
10120 * Supporting nonterminals for expressions.
10123 /* Explicit row production.
10125 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
10126 * without conflicting with the parenthesized a_expr production. Without the
10127 * ROW keyword, there must be more than one a_expr inside the parens.
10129 row: ROW '(' expr_list ')' { $$ = $3; }
10130 | ROW '(' ')' { $$ = NIL; }
10131 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
10134 sub_type: ANY { $$ = ANY_SUBLINK; }
10135 | SOME { $$ = ANY_SUBLINK; }
10136 | ALL { $$ = ALL_SUBLINK; }
10139 all_Op: Op { $$ = $1; }
10140 | MathOp { $$ = $1; }
10143 MathOp: '+' { $$ = "+"; }
10144 | '-' { $$ = "-"; }
10145 | '*' { $$ = "*"; }
10146 | '/' { $$ = "/"; }
10147 | '%' { $$ = "%"; }
10148 | '^' { $$ = "^"; }
10149 | '<' { $$ = "<"; }
10150 | '>' { $$ = ">"; }
10151 | '=' { $$ = "="; }
10155 { $$ = list_make1(makeString($1)); }
10156 | OPERATOR '(' any_operator ')'
10162 { $$ = list_make1(makeString($1)); }
10163 | OPERATOR '(' any_operator ')'
10169 { $$ = list_make1(makeString($1)); }
10170 | OPERATOR '(' any_operator ')'
10173 { $$ = list_make1(makeString("~~")); }
10175 { $$ = list_make1(makeString("!~~")); }
10177 { $$ = list_make1(makeString("~~*")); }
10179 { $$ = list_make1(makeString("!~~*")); }
10180 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
10181 * the regular expression is preprocessed by a function (similar_escape),
10182 * and the ~ operator for posix regular expressions is used.
10183 * x SIMILAR TO y -> x ~ similar_escape(y)
10184 * this transformation is made on the fly by the parser upwards.
10185 * however the SubLink structure which handles any/some/all stuff
10186 * is not ready for such a thing.
10192 $$ = list_make1($1);
10194 | expr_list ',' a_expr
10196 $$ = lappend($1, $3);
10200 /* function arguments can have names */
10201 func_arg_list: func_arg_expr
10203 $$ = list_make1($1);
10205 | func_arg_list ',' func_arg_expr
10207 $$ = lappend($1, $3);
10211 func_arg_expr: a_expr
10215 | a_expr AS param_name
10217 NamedArgExpr *na = makeNode(NamedArgExpr);
10218 na->arg = (Expr *) $1;
10220 na->argnumber = -1; /* until determined */
10226 type_list: Typename { $$ = list_make1($1); }
10227 | type_list ',' Typename { $$ = lappend($1, $3); }
10230 array_expr: '[' expr_list ']'
10232 $$ = makeAArrayExpr($2, @1);
10234 | '[' array_expr_list ']'
10236 $$ = makeAArrayExpr($2, @1);
10240 $$ = makeAArrayExpr(NIL, @1);
10244 array_expr_list: array_expr { $$ = list_make1($1); }
10245 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
10250 extract_arg FROM a_expr
10252 $$ = list_make2(makeStringConst($1, @1), $3);
10254 | /*EMPTY*/ { $$ = NIL; }
10257 /* Allow delimited string Sconst in extract_arg as an SQL extension.
10258 * - thomas 2001-04-12
10262 | YEAR_P { $$ = "year"; }
10263 | MONTH_P { $$ = "month"; }
10264 | DAY_P { $$ = "day"; }
10265 | HOUR_P { $$ = "hour"; }
10266 | MINUTE_P { $$ = "minute"; }
10267 | SECOND_P { $$ = "second"; }
10268 | Sconst { $$ = $1; }
10271 /* OVERLAY() arguments
10272 * SQL99 defines the OVERLAY() function:
10273 * o overlay(text placing text from int for int)
10274 * o overlay(text placing text from int)
10275 * and similarly for binary strings
10278 a_expr overlay_placing substr_from substr_for
10280 $$ = list_make4($1, $2, $3, $4);
10282 | a_expr overlay_placing substr_from
10284 $$ = list_make3($1, $2, $3);
10293 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
10296 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
10297 | /*EMPTY*/ { $$ = NIL; }
10300 /* SUBSTRING() arguments
10301 * SQL9x defines a specific syntax for arguments to SUBSTRING():
10302 * o substring(text from int for int)
10303 * o substring(text from int) get entire string from starting point "int"
10304 * o substring(text for int) get first "int" characters of string
10305 * o substring(text from pattern) get entire string matching pattern
10306 * o substring(text from pattern for escape) same with specified escape char
10307 * We also want to support generic substring functions which accept
10308 * the usual generic list of arguments. So we will accept both styles
10309 * here, and convert the SQL9x style to the generic list for further
10310 * processing. - thomas 2000-11-28
10313 a_expr substr_from substr_for
10315 $$ = list_make3($1, $2, $3);
10317 | a_expr substr_for substr_from
10319 /* not legal per SQL99, but might as well allow it */
10320 $$ = list_make3($1, $3, $2);
10322 | a_expr substr_from
10324 $$ = list_make2($1, $2);
10326 | a_expr substr_for
10329 * Since there are no cases where this syntax allows
10330 * a textual FOR value, we forcibly cast the argument
10331 * to int4. The possible matches in pg_proc are
10332 * substring(text,int4) and substring(text,text),
10333 * and we don't want the parser to choose the latter,
10334 * which it is likely to do if the second argument
10335 * is unknown or doesn't have an implicit cast to int4.
10337 $$ = list_make3($1, makeIntConst(1, -1),
10339 SystemTypeName("int4"), -1));
10350 FROM a_expr { $$ = $2; }
10353 substr_for: FOR a_expr { $$ = $2; }
10356 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
10357 | FROM expr_list { $$ = $2; }
10358 | expr_list { $$ = $1; }
10361 in_expr: select_with_parens
10363 SubLink *n = makeNode(SubLink);
10365 /* other fields will be filled later */
10368 | '(' expr_list ')' { $$ = (Node *)$2; }
10372 * Define SQL92-style case clause.
10373 * - Full specification
10374 * CASE WHEN a = b THEN c ... ELSE d END
10375 * - Implicit argument
10376 * CASE a WHEN b THEN c ... ELSE d END
10378 case_expr: CASE case_arg when_clause_list case_default END_P
10380 CaseExpr *c = makeNode(CaseExpr);
10381 c->casetype = InvalidOid; /* not analyzed yet */
10382 c->arg = (Expr *) $2;
10384 c->defresult = (Expr *) $4;
10391 /* There must be at least one */
10392 when_clause { $$ = list_make1($1); }
10393 | when_clause_list when_clause { $$ = lappend($1, $2); }
10397 WHEN a_expr THEN a_expr
10399 CaseWhen *w = makeNode(CaseWhen);
10400 w->expr = (Expr *) $2;
10401 w->result = (Expr *) $4;
10408 ELSE a_expr { $$ = $2; }
10409 | /*EMPTY*/ { $$ = NULL; }
10412 case_arg: a_expr { $$ = $1; }
10413 | /*EMPTY*/ { $$ = NULL; }
10418 $$ = makeColumnRef($1, NIL, @1, yyscanner);
10420 | ColId indirection
10422 $$ = makeColumnRef($1, $2, @1, yyscanner);
10429 $$ = (Node *) makeString($2);
10433 $$ = (Node *) makeNode(A_Star);
10437 A_Indices *ai = makeNode(A_Indices);
10442 | '[' a_expr ':' a_expr ']'
10444 A_Indices *ai = makeNode(A_Indices);
10452 indirection_el { $$ = list_make1($1); }
10453 | indirection indirection_el { $$ = lappend($1, $2); }
10457 /*EMPTY*/ { $$ = NIL; }
10458 | opt_indirection indirection_el { $$ = lappend($1, $2); }
10461 opt_asymmetric: ASYMMETRIC
10466 * The SQL spec defines "contextually typed value expressions" and
10467 * "contextually typed row value constructors", which for our purposes
10468 * are the same as "a_expr" and "row" except that DEFAULT can appear at
10473 a_expr { $$ = (Node *) $1; }
10476 SetToDefault *n = makeNode(SetToDefault);
10483 ctext_expr { $$ = list_make1($1); }
10484 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
10488 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
10489 * making VALUES a fully reserved word, which will probably break more apps
10490 * than allowing the noise-word is worth.
10492 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
10496 /*****************************************************************************
10498 * target list for SELECT
10500 *****************************************************************************/
10503 target_el { $$ = list_make1($1); }
10504 | target_list ',' target_el { $$ = lappend($1, $3); }
10507 target_el: a_expr AS ColLabel
10509 $$ = makeNode(ResTarget);
10511 $$->indirection = NIL;
10512 $$->val = (Node *)$1;
10516 * We support omitting AS only for column labels that aren't
10517 * any known keyword. There is an ambiguity against postfix
10518 * operators: is "a ! b" an infix expression, or a postfix
10519 * expression and a column label? We prefer to resolve this
10520 * as an infix expression, which we accomplish by assigning
10521 * IDENT a precedence higher than POSTFIXOP.
10525 $$ = makeNode(ResTarget);
10527 $$->indirection = NIL;
10528 $$->val = (Node *)$1;
10533 $$ = makeNode(ResTarget);
10535 $$->indirection = NIL;
10536 $$->val = (Node *)$1;
10541 ColumnRef *n = makeNode(ColumnRef);
10542 n->fields = list_make1(makeNode(A_Star));
10545 $$ = makeNode(ResTarget);
10547 $$->indirection = NIL;
10548 $$->val = (Node *)n;
10554 /*****************************************************************************
10556 * Names and constants
10558 *****************************************************************************/
10560 qualified_name_list:
10561 qualified_name { $$ = list_make1($1); }
10562 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
10566 * The production for a qualified relation name has to exactly match the
10567 * production for a qualified func_name, because in a FROM clause we cannot
10568 * tell which we are parsing until we see what comes after it ('(' for a
10569 * func_name, something else for a relation). Therefore we allow 'indirection'
10570 * which may contain subscripts, and reject that case in the C code.
10575 $$ = makeNode(RangeVar);
10576 $$->catalogname = NULL;
10577 $$->schemaname = NULL;
10581 | ColId indirection
10583 check_qualified_name($2, yyscanner);
10584 $$ = makeNode(RangeVar);
10585 switch (list_length($2))
10588 $$->catalogname = NULL;
10589 $$->schemaname = $1;
10590 $$->relname = strVal(linitial($2));
10593 $$->catalogname = $1;
10594 $$->schemaname = strVal(linitial($2));
10595 $$->relname = strVal(lsecond($2));
10599 (errcode(ERRCODE_SYNTAX_ERROR),
10600 errmsg("improper qualified name (too many dotted names): %s",
10601 NameListToString(lcons(makeString($1), $2))),
10602 parser_errposition(@1)));
10610 { $$ = list_make1(makeString($1)); }
10611 | name_list ',' name
10612 { $$ = lappend($1, makeString($3)); }
10616 name: ColId { $$ = $1; };
10619 ColId { $$ = $1; };
10622 ColId { $$ = $1; };
10624 attr_name: ColLabel { $$ = $1; };
10626 index_name: ColId { $$ = $1; };
10628 file_name: Sconst { $$ = $1; };
10631 * The production for a qualified func_name has to exactly match the
10632 * production for a qualified columnref, because we cannot tell which we
10633 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
10634 * anything else for a columnref). Therefore we allow 'indirection' which
10635 * may contain subscripts, and reject that case in the C code. (If we
10636 * ever implement SQL99-like methods, such syntax may actually become legal!)
10638 func_name: type_function_name
10639 { $$ = list_make1(makeString($1)); }
10640 | ColId indirection
10642 $$ = check_func_name(lcons(makeString($1), $2),
10653 $$ = makeIntConst($1, @1);
10657 $$ = makeFloatConst($1, @1);
10661 $$ = makeStringConst($1, @1);
10665 $$ = makeBitStringConst($1, @1);
10669 /* This is a bit constant per SQL99:
10670 * Without Feature F511, "BIT data type",
10671 * a <general literal> shall not be a
10672 * <bit string literal> or a <hex string literal>.
10674 $$ = makeBitStringConst($1, @1);
10678 /* generic type 'literal' syntax */
10679 TypeName *t = makeTypeNameFromNameList($1);
10681 $$ = makeStringConstCast($2, @2, t);
10683 | func_name '(' func_arg_list ')' Sconst
10685 /* generic syntax with a type modifier */
10686 TypeName *t = makeTypeNameFromNameList($1);
10690 * We must use func_arg_list in the production to avoid
10691 * reduce/reduce conflicts, but we don't actually wish
10692 * to allow NamedArgExpr in this context.
10696 NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
10698 if (IsA(arg, NamedArgExpr))
10700 (errcode(ERRCODE_SYNTAX_ERROR),
10701 errmsg("type modifier cannot have AS name"),
10702 parser_errposition(arg->location)));
10706 $$ = makeStringConstCast($5, @5, t);
10708 | ConstTypename Sconst
10710 $$ = makeStringConstCast($2, @2, $1);
10712 | ConstInterval Sconst opt_interval
10716 $$ = makeStringConstCast($2, @2, t);
10718 | ConstInterval '(' Iconst ')' Sconst opt_interval
10723 if (list_length($6) != 1)
10725 (errcode(ERRCODE_SYNTAX_ERROR),
10726 errmsg("interval precision specified twice"),
10727 parser_errposition(@1)));
10728 t->typmods = lappend($6, makeIntConst($3, @3));
10731 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
10732 makeIntConst($3, @3));
10733 $$ = makeStringConstCast($5, @5, t);
10737 $$ = makeBoolAConst(TRUE, @1);
10741 $$ = makeBoolAConst(FALSE, @1);
10745 $$ = makeNullAConst(@1);
10749 Iconst: ICONST { $$ = $1; };
10750 Sconst: SCONST { $$ = $1; };
10751 RoleId: ColId { $$ = $1; };
10753 SignedIconst: Iconst { $$ = $1; }
10754 | '+' Iconst { $$ = + $2; }
10755 | '-' Iconst { $$ = - $2; }
10758 Iconst_list: Iconst { $$ = list_make1(makeInteger($1)); }
10759 | Iconst_list ',' Iconst { $$ = lappend($1, makeInteger($3)); }
10763 * Name classification hierarchy.
10765 * IDENT is the lexeme returned by the lexer for identifiers that match
10766 * no known keyword. In most cases, we can accept certain keywords as
10767 * names, not only IDENTs. We prefer to accept as many such keywords
10768 * as possible to minimize the impact of "reserved words" on programmers.
10769 * So, we divide names into several possible classes. The classification
10770 * is chosen in part to make keywords acceptable as names wherever possible.
10773 /* Column identifier --- names that can be column, table, etc names.
10775 ColId: IDENT { $$ = $1; }
10776 | unreserved_keyword { $$ = pstrdup($1); }
10777 | col_name_keyword { $$ = pstrdup($1); }
10780 /* Type/function identifier --- names that can be type or function names.
10782 type_function_name: IDENT { $$ = $1; }
10783 | unreserved_keyword { $$ = pstrdup($1); }
10784 | type_func_name_keyword { $$ = pstrdup($1); }
10787 /* Column label --- allowed labels in "AS" clauses.
10788 * This presently includes *all* Postgres keywords.
10790 ColLabel: IDENT { $$ = $1; }
10791 | unreserved_keyword { $$ = pstrdup($1); }
10792 | col_name_keyword { $$ = pstrdup($1); }
10793 | type_func_name_keyword { $$ = pstrdup($1); }
10794 | reserved_keyword { $$ = pstrdup($1); }
10799 * Keyword category lists. Generally, every keyword present in
10800 * the Postgres grammar should appear in exactly one of these lists.
10802 * Put a new keyword into the first list that it can go into without causing
10803 * shift or reduce conflicts. The earlier lists define "less reserved"
10804 * categories of keywords.
10806 * Make sure that each keyword's category in keywords.c matches where
10807 * it is listed here. (Someday we may be able to generate these lists and
10808 * keywords.c's table from a common master list.)
10811 /* "Unreserved" keywords --- available for use as any kind of name.
10813 unreserved_keyword:
11066 /* Column identifier --- keywords that can be column, table, etc names.
11068 * Many of these keywords will in fact be recognized as type or function
11069 * names too; but they have special productions for the purpose, and so
11070 * can't be treated as "generic" type or function names.
11072 * The type names appearing here are not usable as function names
11073 * because they can be followed by '(' in typename productions, which
11074 * looks too much like a function call for an LR(1) parser.
11125 /* Type/function identifier --- keywords that can be type or function names.
11127 * Most of these are keywords that are used as operators in expressions;
11128 * in general such keywords can't be column names because they would be
11129 * ambiguous with variables, but they are unambiguous as function identifiers.
11131 * Do not include POSITION, SUBSTRING, etc here since they have explicit
11132 * productions in a_expr to support the goofy SQL9x argument syntax.
11133 * - thomas 2000-11-28
11135 type_func_name_keyword:
11160 /* Reserved keyword --- these keywords are usable only as a ColLabel.
11162 * Keywords appear here if they could not be distinguished from variable,
11163 * type, or function names in some contexts. Don't put things here unless
11188 | CURRENT_TIMESTAMP
11249 * The signature of this function is required by bison. However, we
11250 * ignore the passed yylloc and instead use the last token position
11251 * available from the scanner.
11254 base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
11256 parser_yyerror(msg);
11260 makeColumnRef(char *colname, List *indirection,
11261 int location, core_yyscan_t yyscanner)
11264 * Generate a ColumnRef node, with an A_Indirection node added if there
11265 * is any subscripting in the specified indirection list. However,
11266 * any field selection at the start of the indirection list must be
11267 * transposed into the "fields" part of the ColumnRef node.
11269 ColumnRef *c = makeNode(ColumnRef);
11273 c->location = location;
11274 foreach(l, indirection)
11276 if (IsA(lfirst(l), A_Indices))
11278 A_Indirection *i = makeNode(A_Indirection);
11282 /* easy case - all indirection goes to A_Indirection */
11283 c->fields = list_make1(makeString(colname));
11284 i->indirection = check_indirection(indirection, yyscanner);
11288 /* got to split the list in two */
11289 i->indirection = check_indirection(list_copy_tail(indirection,
11292 indirection = list_truncate(indirection, nfields);
11293 c->fields = lcons(makeString(colname), indirection);
11295 i->arg = (Node *) c;
11298 else if (IsA(lfirst(l), A_Star))
11300 /* We only allow '*' at the end of a ColumnRef */
11301 if (lnext(l) != NULL)
11302 parser_yyerror("improper use of \"*\"");
11306 /* No subscripting, so all indirection gets added to field list */
11307 c->fields = lcons(makeString(colname), indirection);
11312 makeTypeCast(Node *arg, TypeName *typename, int location)
11314 TypeCast *n = makeNode(TypeCast);
11316 n->typeName = typename;
11317 n->location = location;
11322 makeStringConst(char *str, int location)
11324 A_Const *n = makeNode(A_Const);
11326 n->val.type = T_String;
11327 n->val.val.str = str;
11328 n->location = location;
11334 makeStringConstCast(char *str, int location, TypeName *typename)
11336 Node *s = makeStringConst(str, location);
11338 return makeTypeCast(s, typename, -1);
11342 makeIntConst(int val, int location)
11344 A_Const *n = makeNode(A_Const);
11346 n->val.type = T_Integer;
11347 n->val.val.ival = val;
11348 n->location = location;
11354 makeFloatConst(char *str, int location)
11356 A_Const *n = makeNode(A_Const);
11358 n->val.type = T_Float;
11359 n->val.val.str = str;
11360 n->location = location;
11366 makeBitStringConst(char *str, int location)
11368 A_Const *n = makeNode(A_Const);
11370 n->val.type = T_BitString;
11371 n->val.val.str = str;
11372 n->location = location;
11378 makeNullAConst(int location)
11380 A_Const *n = makeNode(A_Const);
11382 n->val.type = T_Null;
11383 n->location = location;
11389 makeAConst(Value *v, int location)
11396 n = makeFloatConst(v->val.str, location);
11400 n = makeIntConst(v->val.ival, location);
11405 n = makeStringConst(v->val.str, location);
11412 /* makeBoolAConst()
11413 * Create an A_Const string node and put it inside a boolean cast.
11416 makeBoolAConst(bool state, int location)
11418 A_Const *n = makeNode(A_Const);
11420 n->val.type = T_String;
11421 n->val.val.str = (state ? "t" : "f");
11422 n->location = location;
11424 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
11428 * Create and populate a FuncCall node to support the OVERLAPS operator.
11431 makeOverlaps(List *largs, List *rargs, int location, core_yyscan_t yyscanner)
11433 FuncCall *n = makeNode(FuncCall);
11435 n->funcname = SystemFuncName("overlaps");
11436 if (list_length(largs) == 1)
11437 largs = lappend(largs, largs);
11438 else if (list_length(largs) != 2)
11440 (errcode(ERRCODE_SYNTAX_ERROR),
11441 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
11442 parser_errposition(location)));
11443 if (list_length(rargs) == 1)
11444 rargs = lappend(rargs, rargs);
11445 else if (list_length(rargs) != 2)
11447 (errcode(ERRCODE_SYNTAX_ERROR),
11448 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
11449 parser_errposition(location)));
11450 n->args = list_concat(largs, rargs);
11451 n->agg_order = NIL;
11452 n->agg_star = FALSE;
11453 n->agg_distinct = FALSE;
11454 n->func_variadic = FALSE;
11456 n->location = location;
11460 /* check_qualified_name --- check the result of qualified_name production
11462 * It's easiest to let the grammar production for qualified_name allow
11463 * subscripts and '*', which we then must reject here.
11466 check_qualified_name(List *names, core_yyscan_t yyscanner)
11472 if (!IsA(lfirst(i), String))
11473 parser_yyerror("syntax error");
11477 /* check_func_name --- check the result of func_name production
11479 * It's easiest to let the grammar production for func_name allow subscripts
11480 * and '*', which we then must reject here.
11483 check_func_name(List *names, core_yyscan_t yyscanner)
11489 if (!IsA(lfirst(i), String))
11490 parser_yyerror("syntax error");
11495 /* check_indirection --- check the result of indirection production
11497 * We only allow '*' at the end of the list, but it's hard to enforce that
11498 * in the grammar, so do it here.
11501 check_indirection(List *indirection, core_yyscan_t yyscanner)
11505 foreach(l, indirection)
11507 if (IsA(lfirst(l), A_Star))
11509 if (lnext(l) != NULL)
11510 parser_yyerror("improper use of \"*\"");
11513 return indirection;
11516 /* extractArgTypes()
11517 * Given a list of FunctionParameter nodes, extract a list of just the
11518 * argument types (TypeNames) for input parameters only. This is what
11519 * is needed to look up an existing function, which is what is wanted by
11520 * the productions that use this call.
11523 extractArgTypes(List *parameters)
11525 List *result = NIL;
11528 foreach(i, parameters)
11530 FunctionParameter *p = (FunctionParameter *) lfirst(i);
11532 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
11533 result = lappend(result, p->argType);
11538 /* findLeftmostSelect()
11539 * Find the leftmost component SelectStmt in a set-operation parsetree.
11541 static SelectStmt *
11542 findLeftmostSelect(SelectStmt *node)
11544 while (node && node->op != SETOP_NONE)
11546 Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
11550 /* insertSelectOptions()
11551 * Insert ORDER BY, etc into an already-constructed SelectStmt.
11553 * This routine is just to avoid duplicating code in SelectStmt productions.
11556 insertSelectOptions(SelectStmt *stmt,
11557 List *sortClause, List *lockingClause,
11558 Node *limitOffset, Node *limitCount,
11559 WithClause *withClause,
11560 core_yyscan_t yyscanner)
11562 Assert(IsA(stmt, SelectStmt));
11565 * Tests here are to reject constructs like
11566 * (SELECT foo ORDER BY bar) ORDER BY baz
11570 if (stmt->sortClause)
11572 (errcode(ERRCODE_SYNTAX_ERROR),
11573 errmsg("multiple ORDER BY clauses not allowed"),
11574 parser_errposition(exprLocation((Node *) sortClause))));
11575 stmt->sortClause = sortClause;
11577 /* We can handle multiple locking clauses, though */
11578 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
11581 if (stmt->limitOffset)
11583 (errcode(ERRCODE_SYNTAX_ERROR),
11584 errmsg("multiple OFFSET clauses not allowed"),
11585 parser_errposition(exprLocation(limitOffset))));
11586 stmt->limitOffset = limitOffset;
11590 if (stmt->limitCount)
11592 (errcode(ERRCODE_SYNTAX_ERROR),
11593 errmsg("multiple LIMIT clauses not allowed"),
11594 parser_errposition(exprLocation(limitCount))));
11595 stmt->limitCount = limitCount;
11599 if (stmt->withClause)
11601 (errcode(ERRCODE_SYNTAX_ERROR),
11602 errmsg("multiple WITH clauses not allowed"),
11603 parser_errposition(exprLocation((Node *) withClause))));
11604 stmt->withClause = withClause;
11609 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
11611 SelectStmt *n = makeNode(SelectStmt);
11615 n->larg = (SelectStmt *) larg;
11616 n->rarg = (SelectStmt *) rarg;
11620 /* SystemFuncName()
11621 * Build a properly-qualified reference to a built-in function.
11624 SystemFuncName(char *name)
11626 return list_make2(makeString("pg_catalog"), makeString(name));
11629 /* SystemTypeName()
11630 * Build a properly-qualified reference to a built-in type.
11632 * typmod is defaulted, but may be changed afterwards by caller.
11633 * Likewise for the location.
11636 SystemTypeName(char *name)
11638 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
11639 makeString(name)));
11643 * Handle negation of a numeric constant.
11645 * Formerly, we did this here because the optimizer couldn't cope with
11646 * indexquals that looked like "var = -4" --- it wants "var = const"
11647 * and a unary minus operator applied to a constant didn't qualify.
11648 * As of Postgres 7.0, that problem doesn't exist anymore because there
11649 * is a constant-subexpression simplifier in the optimizer. However,
11650 * there's still a good reason for doing this here, which is that we can
11651 * postpone committing to a particular internal representation for simple
11652 * negative constants. It's better to leave "-123.456" in string form
11653 * until we know what the desired type is.
11656 doNegate(Node *n, int location)
11658 if (IsA(n, A_Const))
11660 A_Const *con = (A_Const *)n;
11662 /* report the constant's location as that of the '-' sign */
11663 con->location = location;
11665 if (con->val.type == T_Integer)
11667 con->val.val.ival = -con->val.val.ival;
11670 if (con->val.type == T_Float)
11672 doNegateFloat(&con->val);
11677 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
11681 doNegateFloat(Value *v)
11683 char *oldval = v->val.str;
11685 Assert(IsA(v, Float));
11686 if (*oldval == '+')
11688 if (*oldval == '-')
11689 v->val.str = oldval+1; /* just strip the '-' */
11692 char *newval = (char *) palloc(strlen(oldval) + 2);
11695 strcpy(newval+1, oldval);
11696 v->val.str = newval;
11701 makeAArrayExpr(List *elements, int location)
11703 A_ArrayExpr *n = makeNode(A_ArrayExpr);
11705 n->elements = elements;
11706 n->location = location;
11711 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
11714 XmlExpr *x = makeNode(XmlExpr);
11719 * named_args is a list of ResTarget; it'll be split apart into separate
11720 * expression and name lists in transformXmlExpr().
11722 x->named_args = named_args;
11723 x->arg_names = NIL;
11725 /* xmloption, if relevant, must be filled in by caller */
11726 /* type and typmod will be filled in during parse analysis */
11727 x->location = location;
11732 * Initialize to parse one query string
11735 parser_init(base_yy_extra_type *yyext)
11737 yyext->parsetree = NIL; /* in case grammar forgets to set it */
11741 * Merge the input and output parameters of a table function.
11744 mergeTableFuncParameters(List *func_args, List *columns)
11748 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
11749 foreach(lc, func_args)
11751 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
11753 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
11755 (errcode(ERRCODE_SYNTAX_ERROR),
11756 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
11759 return list_concat(func_args, columns);
11763 * Determine return type of a TABLE function. A single result column
11764 * returns setof that column's type; otherwise return setof record.
11767 TableFuncTypeName(List *columns)
11771 if (list_length(columns) == 1)
11773 FunctionParameter *p = (FunctionParameter *) linitial(columns);
11775 result = (TypeName *) copyObject(p->argType);
11778 result = SystemTypeName("record");
11780 result->setof = true;
11786 * Must undefine this stuff before including scan.c, since it has different
11787 * definitions for these macros.