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.708 2010/02/12 17:33:20 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
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-8.5
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 PROCEDURAL LANGUAGE ...
2886 * DROP PROCEDURAL LANGUAGE ...
2888 *****************************************************************************/
2891 CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2893 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2895 /* parameters are all to be supplied by system */
2898 n->plvalidator = NIL;
2899 n->pltrusted = false;
2902 | CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2903 HANDLER handler_name opt_inline_handler opt_validator
2905 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2909 n->plvalidator = $9;
2916 TRUSTED { $$ = TRUE; }
2917 | /*EMPTY*/ { $$ = FALSE; }
2920 /* This ought to be just func_name, but that causes reduce/reduce conflicts
2921 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
2922 * Work around by using simple names, instead.
2925 name { $$ = list_make1(makeString($1)); }
2926 | name attrs { $$ = lcons(makeString($1), $2); }
2930 INLINE_P handler_name { $$ = $2; }
2931 | /*EMPTY*/ { $$ = NIL; }
2935 VALIDATOR handler_name { $$ = $2; }
2936 | NO VALIDATOR { $$ = NIL; }
2940 validator_clause { $$ = $1; }
2941 | /*EMPTY*/ { $$ = NIL; }
2945 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
2947 DropPLangStmt *n = makeNode(DropPLangStmt);
2950 n->missing_ok = false;
2953 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
2955 DropPLangStmt *n = makeNode(DropPLangStmt);
2958 n->missing_ok = true;
2968 /*****************************************************************************
2971 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
2973 *****************************************************************************/
2975 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
2977 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
2978 n->tablespacename = $3;
2985 OptTableSpaceOwner: OWNER name { $$ = $2; }
2986 | /*EMPTY */ { $$ = NULL; }
2989 /*****************************************************************************
2992 * DROP TABLESPACE <tablespace>
2994 * No need for drop behaviour as we cannot implement dependencies for
2995 * objects in other databases; we can only support RESTRICT.
2997 ****************************************************************************/
2999 DropTableSpaceStmt: DROP TABLESPACE name
3001 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
3002 n->tablespacename = $3;
3003 n->missing_ok = false;
3006 | DROP TABLESPACE IF_P EXISTS name
3008 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
3009 n->tablespacename = $5;
3010 n->missing_ok = true;
3015 /*****************************************************************************
3018 * CREATE FOREIGN DATA WRAPPER name [ VALIDATOR name ]
3020 *****************************************************************************/
3022 CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_validator create_generic_options
3024 CreateFdwStmt *n = makeNode(CreateFdwStmt);
3032 /*****************************************************************************
3035 * DROP FOREIGN DATA WRAPPER name
3037 ****************************************************************************/
3039 DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
3041 DropFdwStmt *n = makeNode(DropFdwStmt);
3043 n->missing_ok = false;
3047 | DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior
3049 DropFdwStmt *n = makeNode(DropFdwStmt);
3051 n->missing_ok = true;
3057 /*****************************************************************************
3060 * ALTER FOREIGN DATA WRAPPER name
3062 ****************************************************************************/
3064 AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name validator_clause alter_generic_options
3066 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3069 n->change_validator = true;
3073 | ALTER FOREIGN DATA_P WRAPPER name validator_clause
3075 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3078 n->change_validator = true;
3081 | ALTER FOREIGN DATA_P WRAPPER name alter_generic_options
3083 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3090 /* Options definition for CREATE FDW, SERVER and USER MAPPING */
3091 create_generic_options:
3092 OPTIONS '(' generic_option_list ')' { $$ = $3; }
3093 | /*EMPTY*/ { $$ = NIL; }
3096 generic_option_list:
3099 $$ = list_make1($1);
3101 | generic_option_list ',' generic_option_elem
3103 $$ = lappend($1, $3);
3107 /* Options definition for ALTER FDW, SERVER and USER MAPPING */
3108 alter_generic_options:
3109 OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
3112 alter_generic_option_list:
3113 alter_generic_option_elem
3115 $$ = list_make1($1);
3117 | alter_generic_option_list ',' alter_generic_option_elem
3119 $$ = lappend($1, $3);
3123 alter_generic_option_elem:
3128 | SET generic_option_elem
3131 $$->defaction = DEFELEM_SET;
3133 | ADD_P generic_option_elem
3136 $$->defaction = DEFELEM_ADD;
3138 | DROP generic_option_name
3140 $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP);
3144 generic_option_elem:
3145 generic_option_name generic_option_arg
3147 $$ = makeDefElem($1, $2);
3151 generic_option_name:
3152 ColLabel { $$ = $1; }
3155 /* We could use def_arg here, but the spec only requires string literals */
3157 Sconst { $$ = (Node *) makeString($1); }
3160 /*****************************************************************************
3163 * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
3165 *****************************************************************************/
3167 CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
3168 FOREIGN DATA_P WRAPPER name create_generic_options
3170 CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
3181 TYPE_P Sconst { $$ = $2; }
3182 | /*EMPTY*/ { $$ = NULL; }
3186 foreign_server_version:
3187 VERSION_P Sconst { $$ = $2; }
3188 | VERSION_P NULL_P { $$ = NULL; }
3191 opt_foreign_server_version:
3192 foreign_server_version { $$ = $1; }
3193 | /*EMPTY*/ { $$ = NULL; }
3196 /*****************************************************************************
3201 ****************************************************************************/
3203 DropForeignServerStmt: DROP SERVER name opt_drop_behavior
3205 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3207 n->missing_ok = false;
3211 | DROP SERVER IF_P EXISTS name opt_drop_behavior
3213 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3215 n->missing_ok = true;
3221 /*****************************************************************************
3224 * ALTER SERVER name [VERSION] [OPTIONS]
3226 ****************************************************************************/
3228 AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
3230 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3234 n->has_version = true;
3237 | ALTER SERVER name foreign_server_version
3239 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3242 n->has_version = true;
3245 | ALTER SERVER name alter_generic_options
3247 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3254 /*****************************************************************************
3257 * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
3259 *****************************************************************************/
3261 CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
3263 CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
3271 /* User mapping authorization identifier */
3273 CURRENT_USER { $$ = "current_user"; }
3274 | USER { $$ = "current_user"; }
3275 | RoleId { $$ = (strcmp($1, "public") == 0) ? NULL : $1; }
3278 /*****************************************************************************
3281 * DROP USER MAPPING FOR auth_ident SERVER name
3283 ****************************************************************************/
3285 DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
3287 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3290 n->missing_ok = false;
3293 | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
3295 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3298 n->missing_ok = true;
3303 /*****************************************************************************
3306 * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
3308 ****************************************************************************/
3310 AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
3312 AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
3320 /*****************************************************************************
3323 * CREATE TRIGGER ...
3326 *****************************************************************************/
3329 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
3330 qualified_name TriggerForSpec TriggerWhen
3331 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3333 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3340 n->events = intVal(linitial($5));
3341 n->columns = (List *) lsecond($5);
3343 n->isconstraint = FALSE;
3344 n->deferrable = FALSE;
3345 n->initdeferred = FALSE;
3346 n->constrrel = NULL;
3349 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
3350 qualified_name OptConstrFromTable ConstraintAttributeSpec
3351 FOR EACH ROW TriggerWhen
3352 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3354 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3361 n->events = intVal(linitial($6));
3362 n->columns = (List *) lsecond($6);
3363 n->whenClause = $14;
3364 n->isconstraint = TRUE;
3365 n->deferrable = ($10 & 1) != 0;
3366 n->initdeferred = ($10 & 2) != 0;
3373 BEFORE { $$ = TRUE; }
3374 | AFTER { $$ = FALSE; }
3380 | TriggerEvents OR TriggerOneEvent
3382 int events1 = intVal(linitial($1));
3383 int events2 = intVal(linitial($3));
3384 List *columns1 = (List *) lsecond($1);
3385 List *columns2 = (List *) lsecond($3);
3387 if (events1 & events2)
3388 parser_yyerror("duplicate trigger events specified");
3390 * concat'ing the columns lists loses information about
3391 * which columns went with which event, but so long as
3392 * only UPDATE carries columns and we disallow multiple
3393 * UPDATE items, it doesn't matter. Command execution
3394 * should just ignore the columns for non-UPDATE events.
3396 $$ = list_make2(makeInteger(events1 | events2),
3397 list_concat(columns1, columns2));
3403 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
3405 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
3407 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
3408 | UPDATE OF columnList
3409 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
3411 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
3415 FOR TriggerForOpt TriggerForType
3422 * If ROW/STATEMENT not specified, default to
3423 * STATEMENT, per SQL
3436 | STATEMENT { $$ = FALSE; }
3440 WHEN '(' a_expr ')' { $$ = $3; }
3441 | /*EMPTY*/ { $$ = NULL; }
3445 TriggerFuncArg { $$ = list_make1($1); }
3446 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
3447 | /*EMPTY*/ { $$ = NIL; }
3454 snprintf(buf, sizeof(buf), "%d", $1);
3455 $$ = makeString(pstrdup(buf));
3457 | FCONST { $$ = makeString($1); }
3458 | Sconst { $$ = makeString($1); }
3459 | BCONST { $$ = makeString($1); }
3460 | XCONST { $$ = makeString($1); }
3461 | ColId { $$ = makeString($1); }
3465 FROM qualified_name { $$ = $2; }
3466 | /*EMPTY*/ { $$ = NULL; }
3469 ConstraintAttributeSpec:
3470 ConstraintDeferrabilitySpec
3472 | ConstraintDeferrabilitySpec ConstraintTimeSpec
3474 if ($1 == 0 && $2 != 0)
3476 (errcode(ERRCODE_SYNTAX_ERROR),
3477 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3478 parser_errposition(@1)));
3481 | ConstraintTimeSpec
3488 | ConstraintTimeSpec ConstraintDeferrabilitySpec
3490 if ($2 == 0 && $1 != 0)
3492 (errcode(ERRCODE_SYNTAX_ERROR),
3493 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3494 parser_errposition(@1)));
3501 ConstraintDeferrabilitySpec:
3502 NOT DEFERRABLE { $$ = 0; }
3503 | DEFERRABLE { $$ = 1; }
3507 INITIALLY IMMEDIATE { $$ = 0; }
3508 | INITIALLY DEFERRED { $$ = 2; }
3513 DROP TRIGGER name ON qualified_name opt_drop_behavior
3515 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3519 n->removeType = OBJECT_TRIGGER;
3520 n->missing_ok = false;
3523 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
3525 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3529 n->removeType = OBJECT_TRIGGER;
3530 n->missing_ok = true;
3536 /*****************************************************************************
3539 * CREATE ASSERTION ...
3540 * DROP ASSERTION ...
3542 *****************************************************************************/
3545 CREATE ASSERTION name CHECK '(' a_expr ')'
3546 ConstraintAttributeSpec
3548 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3550 n->args = list_make1($6);
3551 n->isconstraint = TRUE;
3552 n->deferrable = ($8 & 1) != 0;
3553 n->initdeferred = ($8 & 2) != 0;
3556 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3557 errmsg("CREATE ASSERTION is not yet implemented")));
3564 DROP ASSERTION name opt_drop_behavior
3566 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3570 n->removeType = OBJECT_TRIGGER; /* XXX */
3572 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3573 errmsg("DROP ASSERTION is not yet implemented")));
3579 /*****************************************************************************
3582 * define (aggregate,operator,type)
3584 *****************************************************************************/
3587 CREATE AGGREGATE func_name aggr_args definition
3589 DefineStmt *n = makeNode(DefineStmt);
3590 n->kind = OBJECT_AGGREGATE;
3591 n->oldstyle = false;
3597 | CREATE AGGREGATE func_name old_aggr_definition
3599 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
3600 DefineStmt *n = makeNode(DefineStmt);
3601 n->kind = OBJECT_AGGREGATE;
3608 | CREATE OPERATOR any_operator definition
3610 DefineStmt *n = makeNode(DefineStmt);
3611 n->kind = OBJECT_OPERATOR;
3612 n->oldstyle = false;
3618 | CREATE TYPE_P any_name definition
3620 DefineStmt *n = makeNode(DefineStmt);
3621 n->kind = OBJECT_TYPE;
3622 n->oldstyle = false;
3628 | CREATE TYPE_P any_name
3630 /* Shell type (identified by lack of definition) */
3631 DefineStmt *n = makeNode(DefineStmt);
3632 n->kind = OBJECT_TYPE;
3633 n->oldstyle = false;
3636 n->definition = NIL;
3639 | CREATE TYPE_P any_name AS '(' TableFuncElementList ')'
3641 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
3642 RangeVar *r = makeNode(RangeVar);
3644 /* can't use qualified_name, sigh */
3645 switch (list_length($3))
3648 r->catalogname = NULL;
3649 r->schemaname = NULL;
3650 r->relname = strVal(linitial($3));
3653 r->catalogname = NULL;
3654 r->schemaname = strVal(linitial($3));
3655 r->relname = strVal(lsecond($3));
3658 r->catalogname = strVal(linitial($3));
3659 r->schemaname = strVal(lsecond($3));
3660 r->relname = strVal(lthird($3));
3664 (errcode(ERRCODE_SYNTAX_ERROR),
3665 errmsg("improper qualified name (too many dotted names): %s",
3666 NameListToString($3)),
3667 parser_errposition(@3)));
3675 | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
3677 CreateEnumStmt *n = makeNode(CreateEnumStmt);
3682 | CREATE TEXT_P SEARCH PARSER any_name definition
3684 DefineStmt *n = makeNode(DefineStmt);
3685 n->kind = OBJECT_TSPARSER;
3691 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
3693 DefineStmt *n = makeNode(DefineStmt);
3694 n->kind = OBJECT_TSDICTIONARY;
3700 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
3702 DefineStmt *n = makeNode(DefineStmt);
3703 n->kind = OBJECT_TSTEMPLATE;
3709 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
3711 DefineStmt *n = makeNode(DefineStmt);
3712 n->kind = OBJECT_TSCONFIGURATION;
3720 definition: '(' def_list ')' { $$ = $2; }
3723 def_list: def_elem { $$ = list_make1($1); }
3724 | def_list ',' def_elem { $$ = lappend($1, $3); }
3727 def_elem: ColLabel '=' def_arg
3729 $$ = makeDefElem($1, (Node *) $3);
3733 $$ = makeDefElem($1, NULL);
3737 /* Note: any simple identifier will be returned as a type name! */
3738 def_arg: func_type { $$ = (Node *)$1; }
3739 | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
3740 | qual_all_Op { $$ = (Node *)$1; }
3741 | NumericOnly { $$ = (Node *)$1; }
3742 | Sconst { $$ = (Node *)makeString($1); }
3745 aggr_args: '(' type_list ')' { $$ = $2; }
3746 | '(' '*' ')' { $$ = NIL; }
3749 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
3752 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
3753 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
3757 * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
3758 * the item names needed in old aggregate definitions are likely to become
3761 old_aggr_elem: IDENT '=' def_arg
3763 $$ = makeDefElem($1, (Node *)$3);
3768 enum_val_list { $$ = $1; }
3769 | /*EMPTY*/ { $$ = NIL; }
3772 enum_val_list: Sconst
3773 { $$ = list_make1(makeString($1)); }
3774 | enum_val_list ',' Sconst
3775 { $$ = lappend($1, makeString($3)); }
3779 /*****************************************************************************
3782 * CREATE OPERATOR CLASS ...
3783 * CREATE OPERATOR FAMILY ...
3784 * ALTER OPERATOR FAMILY ...
3785 * DROP OPERATOR CLASS ...
3786 * DROP OPERATOR FAMILY ...
3788 *****************************************************************************/
3791 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
3792 USING access_method opt_opfamily AS opclass_item_list
3794 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
3795 n->opclassname = $4;
3799 n->opfamilyname = $11;
3806 opclass_item { $$ = list_make1($1); }
3807 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
3811 OPERATOR Iconst any_operator opt_recheck
3813 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3814 n->itemtype = OPCLASS_ITEM_OPERATOR;
3820 | OPERATOR Iconst any_operator oper_argtypes opt_recheck
3822 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3823 n->itemtype = OPCLASS_ITEM_OPERATOR;
3829 | FUNCTION Iconst func_name func_args
3831 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3832 n->itemtype = OPCLASS_ITEM_FUNCTION;
3834 n->args = extractArgTypes($4);
3838 | FUNCTION Iconst '(' type_list ')' func_name func_args
3840 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3841 n->itemtype = OPCLASS_ITEM_FUNCTION;
3843 n->args = extractArgTypes($7);
3850 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3851 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
3857 opt_default: DEFAULT { $$ = TRUE; }
3858 | /*EMPTY*/ { $$ = FALSE; }
3861 opt_opfamily: FAMILY any_name { $$ = $2; }
3862 | /*EMPTY*/ { $$ = NIL; }
3865 opt_recheck: RECHECK
3868 * RECHECK no longer does anything in opclass definitions,
3869 * but we still accept it to ease porting of old database
3873 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3874 errmsg("RECHECK is no longer required"),
3875 errhint("Update your data type."),
3876 parser_errposition(@1)));
3879 | /*EMPTY*/ { $$ = FALSE; }
3884 CREATE OPERATOR FAMILY any_name USING access_method
3886 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
3887 n->opfamilyname = $4;
3894 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
3896 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3897 n->opfamilyname = $4;
3903 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
3905 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3906 n->opfamilyname = $4;
3915 opclass_drop { $$ = list_make1($1); }
3916 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
3920 OPERATOR Iconst '(' type_list ')'
3922 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3923 n->itemtype = OPCLASS_ITEM_OPERATOR;
3928 | FUNCTION Iconst '(' type_list ')'
3930 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3931 n->itemtype = OPCLASS_ITEM_FUNCTION;
3940 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
3942 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3943 n->opclassname = $4;
3946 n->missing_ok = false;
3949 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
3951 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3952 n->opclassname = $6;
3955 n->missing_ok = true;
3961 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
3963 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3964 n->opfamilyname = $4;
3967 n->missing_ok = false;
3970 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
3972 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3973 n->opfamilyname = $6;
3976 n->missing_ok = true;
3982 /*****************************************************************************
3986 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
3987 * REASSIGN OWNED BY username [, username ...] TO username
3989 *****************************************************************************/
3991 DROP OWNED BY name_list opt_drop_behavior
3993 DropOwnedStmt *n = makeNode(DropOwnedStmt);
4001 REASSIGN OWNED BY name_list TO name
4003 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
4010 /*****************************************************************************
4014 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
4015 * [ RESTRICT | CASCADE ]
4017 *****************************************************************************/
4019 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
4021 DropStmt *n = makeNode(DropStmt);
4023 n->missing_ok = TRUE;
4028 | DROP drop_type any_name_list opt_drop_behavior
4030 DropStmt *n = makeNode(DropStmt);
4032 n->missing_ok = FALSE;
4040 drop_type: TABLE { $$ = OBJECT_TABLE; }
4041 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4042 | VIEW { $$ = OBJECT_VIEW; }
4043 | INDEX { $$ = OBJECT_INDEX; }
4044 | TYPE_P { $$ = OBJECT_TYPE; }
4045 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
4046 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4047 | SCHEMA { $$ = OBJECT_SCHEMA; }
4048 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
4049 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
4050 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
4051 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
4055 any_name { $$ = list_make1($1); }
4056 | any_name_list ',' any_name { $$ = lappend($1, $3); }
4059 any_name: ColId { $$ = list_make1(makeString($1)); }
4060 | ColId attrs { $$ = lcons(makeString($1), $2); }
4063 attrs: '.' attr_name
4064 { $$ = list_make1(makeString($2)); }
4065 | attrs '.' attr_name
4066 { $$ = lappend($1, makeString($3)); }
4070 /*****************************************************************************
4073 * truncate table relname1, relname2, ...
4075 *****************************************************************************/
4078 TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
4080 TruncateStmt *n = makeNode(TruncateStmt);
4082 n->restart_seqs = $4;
4089 CONTINUE_P IDENTITY_P { $$ = false; }
4090 | RESTART IDENTITY_P { $$ = true; }
4091 | /* EMPTY */ { $$ = false; }
4094 /*****************************************************************************
4096 * The COMMENT ON statement can take different forms based upon the type of
4097 * the object associated with the comment. The form of the statement is:
4099 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
4100 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
4101 * CAST | COLUMN | SCHEMA | TABLESPACE | ROLE |
4102 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
4103 * TEXT SEARCH TEMPLATE |
4104 * TEXT SEARCH CONFIGURATION ] <objname> |
4105 * AGGREGATE <aggname> (arg1, ...) |
4106 * FUNCTION <funcname> (arg1, arg2, ...) |
4107 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
4108 * TRIGGER <triggername> ON <relname> |
4109 * CONSTRAINT <constraintname> ON <relname> |
4110 * RULE <rulename> ON <relname> ]
4113 *****************************************************************************/
4116 COMMENT ON comment_type any_name IS comment_text
4118 CommentStmt *n = makeNode(CommentStmt);
4125 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
4127 CommentStmt *n = makeNode(CommentStmt);
4128 n->objtype = OBJECT_AGGREGATE;
4134 | COMMENT ON FUNCTION func_name func_args IS comment_text
4136 CommentStmt *n = makeNode(CommentStmt);
4137 n->objtype = OBJECT_FUNCTION;
4139 n->objargs = extractArgTypes($5);
4143 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
4145 CommentStmt *n = makeNode(CommentStmt);
4146 n->objtype = OBJECT_OPERATOR;
4152 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
4154 CommentStmt *n = makeNode(CommentStmt);
4155 n->objtype = OBJECT_CONSTRAINT;
4156 n->objname = lappend($6, makeString($4));
4161 | COMMENT ON RULE name ON any_name IS comment_text
4163 CommentStmt *n = makeNode(CommentStmt);
4164 n->objtype = OBJECT_RULE;
4165 n->objname = lappend($6, makeString($4));
4170 | COMMENT ON RULE name IS comment_text
4172 /* Obsolete syntax supported for awhile for compatibility */
4173 CommentStmt *n = makeNode(CommentStmt);
4174 n->objtype = OBJECT_RULE;
4175 n->objname = list_make1(makeString($4));
4180 | COMMENT ON TRIGGER name ON any_name IS comment_text
4182 CommentStmt *n = makeNode(CommentStmt);
4183 n->objtype = OBJECT_TRIGGER;
4184 n->objname = lappend($6, makeString($4));
4189 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
4191 CommentStmt *n = makeNode(CommentStmt);
4192 n->objtype = OBJECT_OPCLASS;
4194 n->objargs = list_make1(makeString($7));
4198 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
4200 CommentStmt *n = makeNode(CommentStmt);
4201 n->objtype = OBJECT_OPFAMILY;
4203 n->objargs = list_make1(makeString($7));
4207 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
4209 CommentStmt *n = makeNode(CommentStmt);
4210 n->objtype = OBJECT_LARGEOBJECT;
4211 n->objname = list_make1($5);
4216 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
4218 CommentStmt *n = makeNode(CommentStmt);
4219 n->objtype = OBJECT_CAST;
4220 n->objname = list_make1($5);
4221 n->objargs = list_make1($7);
4225 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
4227 CommentStmt *n = makeNode(CommentStmt);
4228 n->objtype = OBJECT_LANGUAGE;
4234 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
4236 CommentStmt *n = makeNode(CommentStmt);
4237 n->objtype = OBJECT_TSPARSER;
4242 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
4244 CommentStmt *n = makeNode(CommentStmt);
4245 n->objtype = OBJECT_TSDICTIONARY;
4250 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
4252 CommentStmt *n = makeNode(CommentStmt);
4253 n->objtype = OBJECT_TSTEMPLATE;
4258 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
4260 CommentStmt *n = makeNode(CommentStmt);
4261 n->objtype = OBJECT_TSCONFIGURATION;
4269 COLUMN { $$ = OBJECT_COLUMN; }
4270 | DATABASE { $$ = OBJECT_DATABASE; }
4271 | SCHEMA { $$ = OBJECT_SCHEMA; }
4272 | INDEX { $$ = OBJECT_INDEX; }
4273 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4274 | TABLE { $$ = OBJECT_TABLE; }
4275 | DOMAIN_P { $$ = OBJECT_TYPE; }
4276 | TYPE_P { $$ = OBJECT_TYPE; }
4277 | VIEW { $$ = OBJECT_VIEW; }
4278 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4279 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
4280 | ROLE { $$ = OBJECT_ROLE; }
4285 | NULL_P { $$ = NULL; }
4288 /*****************************************************************************
4293 *****************************************************************************/
4295 FetchStmt: FETCH fetch_args
4297 FetchStmt *n = (FetchStmt *) $2;
4303 FetchStmt *n = (FetchStmt *) $2;
4309 fetch_args: cursor_name
4311 FetchStmt *n = makeNode(FetchStmt);
4313 n->direction = FETCH_FORWARD;
4317 | from_in cursor_name
4319 FetchStmt *n = makeNode(FetchStmt);
4321 n->direction = FETCH_FORWARD;
4325 | NEXT opt_from_in cursor_name
4327 FetchStmt *n = makeNode(FetchStmt);
4329 n->direction = FETCH_FORWARD;
4333 | PRIOR opt_from_in cursor_name
4335 FetchStmt *n = makeNode(FetchStmt);
4337 n->direction = FETCH_BACKWARD;
4341 | FIRST_P opt_from_in cursor_name
4343 FetchStmt *n = makeNode(FetchStmt);
4345 n->direction = FETCH_ABSOLUTE;
4349 | LAST_P opt_from_in cursor_name
4351 FetchStmt *n = makeNode(FetchStmt);
4353 n->direction = FETCH_ABSOLUTE;
4357 | ABSOLUTE_P SignedIconst opt_from_in cursor_name
4359 FetchStmt *n = makeNode(FetchStmt);
4361 n->direction = FETCH_ABSOLUTE;
4365 | RELATIVE_P SignedIconst opt_from_in cursor_name
4367 FetchStmt *n = makeNode(FetchStmt);
4369 n->direction = FETCH_RELATIVE;
4373 | SignedIconst opt_from_in cursor_name
4375 FetchStmt *n = makeNode(FetchStmt);
4377 n->direction = FETCH_FORWARD;
4381 | ALL opt_from_in cursor_name
4383 FetchStmt *n = makeNode(FetchStmt);
4385 n->direction = FETCH_FORWARD;
4386 n->howMany = FETCH_ALL;
4389 | FORWARD opt_from_in cursor_name
4391 FetchStmt *n = makeNode(FetchStmt);
4393 n->direction = FETCH_FORWARD;
4397 | FORWARD SignedIconst opt_from_in cursor_name
4399 FetchStmt *n = makeNode(FetchStmt);
4401 n->direction = FETCH_FORWARD;
4405 | FORWARD ALL opt_from_in cursor_name
4407 FetchStmt *n = makeNode(FetchStmt);
4409 n->direction = FETCH_FORWARD;
4410 n->howMany = FETCH_ALL;
4413 | BACKWARD opt_from_in cursor_name
4415 FetchStmt *n = makeNode(FetchStmt);
4417 n->direction = FETCH_BACKWARD;
4421 | BACKWARD SignedIconst opt_from_in cursor_name
4423 FetchStmt *n = makeNode(FetchStmt);
4425 n->direction = FETCH_BACKWARD;
4429 | BACKWARD ALL opt_from_in cursor_name
4431 FetchStmt *n = makeNode(FetchStmt);
4433 n->direction = FETCH_BACKWARD;
4434 n->howMany = FETCH_ALL;
4443 opt_from_in: from_in {}
4448 /*****************************************************************************
4450 * GRANT and REVOKE statements
4452 *****************************************************************************/
4454 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
4455 opt_grant_grant_option
4457 GrantStmt *n = makeNode(GrantStmt);
4460 n->targtype = ($4)->targtype;
4461 n->objtype = ($4)->objtype;
4462 n->objects = ($4)->objs;
4464 n->grant_option = $7;
4470 REVOKE privileges ON privilege_target
4471 FROM grantee_list opt_drop_behavior
4473 GrantStmt *n = makeNode(GrantStmt);
4474 n->is_grant = false;
4475 n->grant_option = false;
4477 n->targtype = ($4)->targtype;
4478 n->objtype = ($4)->objtype;
4479 n->objects = ($4)->objs;
4484 | REVOKE GRANT OPTION FOR privileges ON privilege_target
4485 FROM grantee_list opt_drop_behavior
4487 GrantStmt *n = makeNode(GrantStmt);
4488 n->is_grant = false;
4489 n->grant_option = true;
4491 n->targtype = ($7)->targtype;
4492 n->objtype = ($7)->objtype;
4493 n->objects = ($7)->objs;
4502 * Privilege names are represented as strings; the validity of the privilege
4503 * names gets checked at execution. This is a bit annoying but we have little
4504 * choice because of the syntactic conflict with lists of role names in
4505 * GRANT/REVOKE. What's more, we have to call out in the "privilege"
4506 * production any reserved keywords that need to be usable as privilege names.
4509 /* either ALL [PRIVILEGES] or a list of individual privileges */
4510 privileges: privilege_list
4516 | ALL '(' columnList ')'
4518 AccessPriv *n = makeNode(AccessPriv);
4519 n->priv_name = NULL;
4523 | ALL PRIVILEGES '(' columnList ')'
4525 AccessPriv *n = makeNode(AccessPriv);
4526 n->priv_name = NULL;
4532 privilege_list: privilege { $$ = list_make1($1); }
4533 | privilege_list ',' privilege { $$ = lappend($1, $3); }
4536 privilege: SELECT opt_column_list
4538 AccessPriv *n = makeNode(AccessPriv);
4539 n->priv_name = pstrdup($1);
4543 | REFERENCES opt_column_list
4545 AccessPriv *n = makeNode(AccessPriv);
4546 n->priv_name = pstrdup($1);
4550 | CREATE opt_column_list
4552 AccessPriv *n = makeNode(AccessPriv);
4553 n->priv_name = pstrdup($1);
4557 | ColId opt_column_list
4559 AccessPriv *n = makeNode(AccessPriv);
4567 /* Don't bother trying to fold the first two rules into one using
4568 * opt_table. You're going to get conflicts.
4573 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4574 n->targtype = ACL_TARGET_OBJECT;
4575 n->objtype = ACL_OBJECT_RELATION;
4579 | TABLE qualified_name_list
4581 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4582 n->targtype = ACL_TARGET_OBJECT;
4583 n->objtype = ACL_OBJECT_RELATION;
4587 | SEQUENCE qualified_name_list
4589 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4590 n->targtype = ACL_TARGET_OBJECT;
4591 n->objtype = ACL_OBJECT_SEQUENCE;
4595 | FOREIGN DATA_P WRAPPER name_list
4597 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4598 n->targtype = ACL_TARGET_OBJECT;
4599 n->objtype = ACL_OBJECT_FDW;
4603 | FOREIGN SERVER name_list
4605 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4606 n->targtype = ACL_TARGET_OBJECT;
4607 n->objtype = ACL_OBJECT_FOREIGN_SERVER;
4611 | FUNCTION function_with_argtypes_list
4613 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4614 n->targtype = ACL_TARGET_OBJECT;
4615 n->objtype = ACL_OBJECT_FUNCTION;
4619 | DATABASE name_list
4621 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4622 n->targtype = ACL_TARGET_OBJECT;
4623 n->objtype = ACL_OBJECT_DATABASE;
4627 | LANGUAGE name_list
4629 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4630 n->targtype = ACL_TARGET_OBJECT;
4631 n->objtype = ACL_OBJECT_LANGUAGE;
4635 | LARGE_P OBJECT_P Iconst_list
4637 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4638 n->targtype = ACL_TARGET_OBJECT;
4639 n->objtype = ACL_OBJECT_LARGEOBJECT;
4645 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4646 n->targtype = ACL_TARGET_OBJECT;
4647 n->objtype = ACL_OBJECT_NAMESPACE;
4651 | TABLESPACE name_list
4653 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4654 n->targtype = ACL_TARGET_OBJECT;
4655 n->objtype = ACL_OBJECT_TABLESPACE;
4659 | ALL TABLES IN_P SCHEMA name_list
4661 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4662 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4663 n->objtype = ACL_OBJECT_RELATION;
4667 | ALL SEQUENCES IN_P SCHEMA name_list
4669 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4670 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4671 n->objtype = ACL_OBJECT_SEQUENCE;
4675 | ALL FUNCTIONS IN_P SCHEMA name_list
4677 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4678 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4679 n->objtype = ACL_OBJECT_FUNCTION;
4687 grantee { $$ = list_make1($1); }
4688 | grantee_list ',' grantee { $$ = lappend($1, $3); }
4693 PrivGrantee *n = makeNode(PrivGrantee);
4694 /* This hack lets us avoid reserving PUBLIC as a keyword*/
4695 if (strcmp($1, "public") == 0)
4703 PrivGrantee *n = makeNode(PrivGrantee);
4704 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
4705 if (strcmp($2, "public") == 0)
4714 opt_grant_grant_option:
4715 WITH GRANT OPTION { $$ = TRUE; }
4716 | /*EMPTY*/ { $$ = FALSE; }
4719 function_with_argtypes_list:
4720 function_with_argtypes { $$ = list_make1($1); }
4721 | function_with_argtypes_list ',' function_with_argtypes
4722 { $$ = lappend($1, $3); }
4725 function_with_argtypes:
4728 FuncWithArgs *n = makeNode(FuncWithArgs);
4730 n->funcargs = extractArgTypes($2);
4735 /*****************************************************************************
4737 * GRANT and REVOKE ROLE statements
4739 *****************************************************************************/
4742 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4744 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4746 n->granted_roles = $2;
4747 n->grantee_roles = $4;
4755 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4757 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4758 n->is_grant = false;
4759 n->admin_opt = false;
4760 n->granted_roles = $2;
4761 n->grantee_roles = $4;
4765 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4767 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4768 n->is_grant = false;
4769 n->admin_opt = true;
4770 n->granted_roles = $5;
4771 n->grantee_roles = $7;
4777 opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
4778 | /*EMPTY*/ { $$ = FALSE; }
4781 opt_granted_by: GRANTED BY RoleId { $$ = $3; }
4782 | /*EMPTY*/ { $$ = NULL; }
4785 /*****************************************************************************
4787 * ALTER DEFAULT PRIVILEGES statement
4789 *****************************************************************************/
4791 AlterDefaultPrivilegesStmt:
4792 ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
4794 AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
4796 n->action = (GrantStmt *) $5;
4802 DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
4803 | /* EMPTY */ { $$ = NIL; }
4807 IN_P SCHEMA name_list
4809 $$ = makeDefElem("schemas", (Node *)$3);
4811 | FOR ROLE name_list
4813 $$ = makeDefElem("roles", (Node *)$3);
4815 | FOR USER name_list
4817 $$ = makeDefElem("roles", (Node *)$3);
4822 * This should match GRANT/REVOKE, except that individual target objects
4823 * are not mentioned and we only allow a subset of object types.
4826 GRANT privileges ON defacl_privilege_target TO grantee_list
4827 opt_grant_grant_option
4829 GrantStmt *n = makeNode(GrantStmt);
4832 n->targtype = ACL_TARGET_DEFAULTS;
4836 n->grant_option = $7;
4839 | REVOKE privileges ON defacl_privilege_target
4840 FROM grantee_list opt_drop_behavior
4842 GrantStmt *n = makeNode(GrantStmt);
4843 n->is_grant = false;
4844 n->grant_option = false;
4846 n->targtype = ACL_TARGET_DEFAULTS;
4853 | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
4854 FROM grantee_list opt_drop_behavior
4856 GrantStmt *n = makeNode(GrantStmt);
4857 n->is_grant = false;
4858 n->grant_option = true;
4860 n->targtype = ACL_TARGET_DEFAULTS;
4869 defacl_privilege_target:
4870 TABLES { $$ = ACL_OBJECT_RELATION; }
4871 | FUNCTIONS { $$ = ACL_OBJECT_FUNCTION; }
4872 | SEQUENCES { $$ = ACL_OBJECT_SEQUENCE; }
4876 /*****************************************************************************
4878 * QUERY: CREATE INDEX
4880 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
4881 * willing to make TABLESPACE a fully reserved word.
4882 *****************************************************************************/
4884 IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_index_name
4885 ON qualified_name access_method_clause '(' index_params ')'
4886 opt_reloptions OptTableSpace where_clause
4888 IndexStmt *n = makeNode(IndexStmt);
4893 n->accessMethod = $8;
4894 n->indexParams = $10;
4896 n->tableSpace = $13;
4897 n->whereClause = $14;
4903 UNIQUE { $$ = TRUE; }
4904 | /*EMPTY*/ { $$ = FALSE; }
4908 CONCURRENTLY { $$ = TRUE; }
4909 | /*EMPTY*/ { $$ = FALSE; }
4913 index_name { $$ = $1; }
4914 | /*EMPTY*/ { $$ = NULL; }
4917 access_method_clause:
4918 USING access_method { $$ = $2; }
4919 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
4922 index_params: index_elem { $$ = list_make1($1); }
4923 | index_params ',' index_elem { $$ = lappend($1, $3); }
4927 * Index attributes can be either simple column references, or arbitrary
4928 * expressions in parens. For backwards-compatibility reasons, we allow
4929 * an expression that's just a function call to be written without parens.
4931 index_elem: ColId opt_class opt_asc_desc opt_nulls_order
4933 $$ = makeNode(IndexElem);
4936 $$->indexcolname = NULL;
4939 $$->nulls_ordering = $4;
4941 | func_expr opt_class opt_asc_desc opt_nulls_order
4943 $$ = makeNode(IndexElem);
4946 $$->indexcolname = NULL;
4949 $$->nulls_ordering = $4;
4951 | '(' a_expr ')' opt_class opt_asc_desc opt_nulls_order
4953 $$ = makeNode(IndexElem);
4956 $$->indexcolname = NULL;
4959 $$->nulls_ordering = $6;
4963 opt_class: any_name { $$ = $1; }
4964 | USING any_name { $$ = $2; }
4965 | /*EMPTY*/ { $$ = NIL; }
4968 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
4969 | DESC { $$ = SORTBY_DESC; }
4970 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
4973 opt_nulls_order: NULLS_FIRST { $$ = SORTBY_NULLS_FIRST; }
4974 | NULLS_LAST { $$ = SORTBY_NULLS_LAST; }
4975 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
4979 /*****************************************************************************
4982 * create [or replace] function <fname>
4983 * [(<type-1> { , <type-n>})]
4985 * as <filename or code in language as appropriate>
4986 * language <lang> [with parameters]
4988 *****************************************************************************/
4991 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4992 RETURNS func_return createfunc_opt_list opt_definition
4994 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5003 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5004 RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
5006 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5009 n->parameters = mergeTableFuncParameters($5, $9);
5010 n->returnType = TableFuncTypeName($9);
5011 n->returnType->location = @7;
5013 n->withClause = $12;
5016 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5017 createfunc_opt_list opt_definition
5019 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5023 n->returnType = NULL;
5031 OR REPLACE { $$ = TRUE; }
5032 | /*EMPTY*/ { $$ = FALSE; }
5035 func_args: '(' func_args_list ')' { $$ = $2; }
5036 | '(' ')' { $$ = NIL; }
5040 func_arg { $$ = list_make1($1); }
5041 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
5045 * func_args_with_defaults is separate because we only want to accept
5046 * defaults in CREATE FUNCTION, not in ALTER etc.
5048 func_args_with_defaults:
5049 '(' func_args_with_defaults_list ')' { $$ = $2; }
5050 | '(' ')' { $$ = NIL; }
5053 func_args_with_defaults_list:
5054 func_arg_with_default { $$ = list_make1($1); }
5055 | func_args_with_defaults_list ',' func_arg_with_default
5056 { $$ = lappend($1, $3); }
5060 * The style with arg_class first is SQL99 standard, but Oracle puts
5061 * param_name first; accept both since it's likely people will try both
5062 * anyway. Don't bother trying to save productions by letting arg_class
5063 * have an empty alternative ... you'll get shift/reduce conflicts.
5065 * We can catch over-specified arguments here if we want to,
5066 * but for now better to silently swallow typmod, etc.
5067 * - thomas 2000-03-22
5070 arg_class param_name func_type
5072 FunctionParameter *n = makeNode(FunctionParameter);
5079 | param_name arg_class func_type
5081 FunctionParameter *n = makeNode(FunctionParameter);
5088 | param_name func_type
5090 FunctionParameter *n = makeNode(FunctionParameter);
5093 n->mode = FUNC_PARAM_IN;
5097 | arg_class func_type
5099 FunctionParameter *n = makeNode(FunctionParameter);
5108 FunctionParameter *n = makeNode(FunctionParameter);
5111 n->mode = FUNC_PARAM_IN;
5117 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
5118 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
5119 | OUT_P { $$ = FUNC_PARAM_OUT; }
5120 | INOUT { $$ = FUNC_PARAM_INOUT; }
5121 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
5122 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
5126 * Ideally param_name should be ColId, but that causes too many conflicts.
5128 param_name: type_function_name
5134 /* We can catch over-specified results here if we want to,
5135 * but for now better to silently swallow typmod, etc.
5136 * - thomas 2000-03-22
5143 * We would like to make the %TYPE productions here be ColId attrs etc,
5144 * but that causes reduce/reduce conflicts. type_function_name
5145 * is next best choice.
5147 func_type: Typename { $$ = $1; }
5148 | type_function_name attrs '%' TYPE_P
5150 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
5151 $$->pct_type = true;
5154 | SETOF type_function_name attrs '%' TYPE_P
5156 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
5157 $$->pct_type = true;
5163 func_arg_with_default:
5168 | func_arg DEFAULT a_expr
5173 | func_arg '=' a_expr
5181 createfunc_opt_list:
5182 /* Must be at least one to prevent conflict */
5183 createfunc_opt_item { $$ = list_make1($1); }
5184 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
5188 * Options common to both CREATE FUNCTION and ALTER FUNCTION
5190 common_func_opt_item:
5191 CALLED ON NULL_P INPUT_P
5193 $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
5195 | RETURNS NULL_P ON NULL_P INPUT_P
5197 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5201 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5205 $$ = makeDefElem("volatility", (Node *)makeString("immutable"));
5209 $$ = makeDefElem("volatility", (Node *)makeString("stable"));
5213 $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
5215 | EXTERNAL SECURITY DEFINER
5217 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5219 | EXTERNAL SECURITY INVOKER
5221 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5225 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5229 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5233 $$ = makeDefElem("cost", (Node *)$2);
5237 $$ = makeDefElem("rows", (Node *)$2);
5241 /* we abuse the normal content of a DefElem here */
5242 $$ = makeDefElem("set", (Node *)$1);
5246 createfunc_opt_item:
5249 $$ = makeDefElem("as", (Node *)$2);
5251 | LANGUAGE ColId_or_Sconst
5253 $$ = makeDefElem("language", (Node *)makeString($2));
5257 $$ = makeDefElem("window", (Node *)makeInteger(TRUE));
5259 | common_func_opt_item
5265 func_as: Sconst { $$ = list_make1(makeString($1)); }
5268 $$ = list_make2(makeString($1), makeString($3));
5273 WITH definition { $$ = $2; }
5274 | /*EMPTY*/ { $$ = NIL; }
5277 table_func_column: param_name func_type
5279 FunctionParameter *n = makeNode(FunctionParameter);
5282 n->mode = FUNC_PARAM_TABLE;
5288 table_func_column_list:
5291 $$ = list_make1($1);
5293 | table_func_column_list ',' table_func_column
5295 $$ = lappend($1, $3);
5299 /*****************************************************************************
5302 * RENAME and OWNER subcommands are already provided by the generic
5303 * ALTER infrastructure, here we just specify alterations that can
5304 * only be applied to functions.
5306 *****************************************************************************/
5308 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
5310 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
5318 /* At least one option must be specified */
5319 common_func_opt_item { $$ = list_make1($1); }
5320 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
5323 /* Ignored, merely for SQL compliance */
5330 /*****************************************************************************
5334 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
5335 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
5336 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
5338 *****************************************************************************/
5341 DROP FUNCTION func_name func_args opt_drop_behavior
5343 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5344 n->kind = OBJECT_FUNCTION;
5346 n->args = extractArgTypes($4);
5348 n->missing_ok = false;
5351 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
5353 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5354 n->kind = OBJECT_FUNCTION;
5356 n->args = extractArgTypes($6);
5358 n->missing_ok = true;
5364 DROP AGGREGATE func_name aggr_args opt_drop_behavior
5366 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5367 n->kind = OBJECT_AGGREGATE;
5371 n->missing_ok = false;
5374 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
5376 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5377 n->kind = OBJECT_AGGREGATE;
5381 n->missing_ok = true;
5387 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
5389 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5390 n->kind = OBJECT_OPERATOR;
5394 n->missing_ok = false;
5397 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
5399 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5400 n->kind = OBJECT_OPERATOR;
5404 n->missing_ok = true;
5413 (errcode(ERRCODE_SYNTAX_ERROR),
5414 errmsg("missing argument"),
5415 errhint("Use NONE to denote the missing argument of a unary operator."),
5416 parser_errposition(@3)));
5418 | '(' Typename ',' Typename ')'
5419 { $$ = list_make2($2, $4); }
5420 | '(' NONE ',' Typename ')' /* left unary */
5421 { $$ = list_make2(NULL, $4); }
5422 | '(' Typename ',' NONE ')' /* right unary */
5423 { $$ = list_make2($2, NULL); }
5428 { $$ = list_make1(makeString($1)); }
5429 | ColId '.' any_operator
5430 { $$ = lcons(makeString($1), $3); }
5433 /*****************************************************************************
5435 * DO <anonymous code block> [ LANGUAGE language ]
5437 * We use a DefElem list for future extensibility, and to allow flexibility
5438 * in the clause order.
5440 *****************************************************************************/
5442 DoStmt: DO dostmt_opt_list
5444 DoStmt *n = makeNode(DoStmt);
5451 dostmt_opt_item { $$ = list_make1($1); }
5452 | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
5458 $$ = makeDefElem("as", (Node *)makeString($1));
5460 | LANGUAGE ColId_or_Sconst
5462 $$ = makeDefElem("language", (Node *)makeString($2));
5466 /*****************************************************************************
5468 * CREATE CAST / DROP CAST
5470 *****************************************************************************/
5472 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
5473 WITH FUNCTION function_with_argtypes cast_context
5475 CreateCastStmt *n = makeNode(CreateCastStmt);
5479 n->context = (CoercionContext) $11;
5483 | CREATE CAST '(' Typename AS Typename ')'
5484 WITHOUT FUNCTION cast_context
5486 CreateCastStmt *n = makeNode(CreateCastStmt);
5490 n->context = (CoercionContext) $10;
5494 | CREATE CAST '(' Typename AS Typename ')'
5495 WITH INOUT cast_context
5497 CreateCastStmt *n = makeNode(CreateCastStmt);
5501 n->context = (CoercionContext) $10;
5507 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
5508 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
5509 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
5513 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
5515 DropCastStmt *n = makeNode(DropCastStmt);
5524 opt_if_exists: IF_P EXISTS { $$ = TRUE; }
5525 | /*EMPTY*/ { $$ = FALSE; }
5529 /*****************************************************************************
5533 * REINDEX type <name> [FORCE]
5535 * FORCE no longer does anything, but we accept it for backwards compatibility
5536 *****************************************************************************/
5539 REINDEX reindex_type qualified_name opt_force
5541 ReindexStmt *n = makeNode(ReindexStmt);
5547 | REINDEX SYSTEM_P name opt_force
5549 ReindexStmt *n = makeNode(ReindexStmt);
5550 n->kind = OBJECT_DATABASE;
5553 n->do_system = true;
5557 | REINDEX DATABASE name opt_force
5559 ReindexStmt *n = makeNode(ReindexStmt);
5560 n->kind = OBJECT_DATABASE;
5563 n->do_system = true;
5570 INDEX { $$ = OBJECT_INDEX; }
5571 | TABLE { $$ = OBJECT_TABLE; }
5574 opt_force: FORCE { $$ = TRUE; }
5575 | /* EMPTY */ { $$ = FALSE; }
5579 /*****************************************************************************
5581 * ALTER THING name RENAME TO newname
5583 *****************************************************************************/
5585 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
5587 RenameStmt *n = makeNode(RenameStmt);
5588 n->renameType = OBJECT_AGGREGATE;
5594 | ALTER CONVERSION_P any_name RENAME TO name
5596 RenameStmt *n = makeNode(RenameStmt);
5597 n->renameType = OBJECT_CONVERSION;
5602 | ALTER DATABASE database_name RENAME TO database_name
5604 RenameStmt *n = makeNode(RenameStmt);
5605 n->renameType = OBJECT_DATABASE;
5610 | ALTER FUNCTION function_with_argtypes RENAME TO name
5612 RenameStmt *n = makeNode(RenameStmt);
5613 n->renameType = OBJECT_FUNCTION;
5614 n->object = $3->funcname;
5615 n->objarg = $3->funcargs;
5619 | ALTER GROUP_P RoleId RENAME TO RoleId
5621 RenameStmt *n = makeNode(RenameStmt);
5622 n->renameType = OBJECT_ROLE;
5627 | ALTER opt_procedural LANGUAGE name RENAME TO name
5629 RenameStmt *n = makeNode(RenameStmt);
5630 n->renameType = OBJECT_LANGUAGE;
5635 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
5637 RenameStmt *n = makeNode(RenameStmt);
5638 n->renameType = OBJECT_OPCLASS;
5644 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
5646 RenameStmt *n = makeNode(RenameStmt);
5647 n->renameType = OBJECT_OPFAMILY;
5653 | ALTER SCHEMA name RENAME TO name
5655 RenameStmt *n = makeNode(RenameStmt);
5656 n->renameType = OBJECT_SCHEMA;
5661 | ALTER TABLE relation_expr RENAME TO name
5663 RenameStmt *n = makeNode(RenameStmt);
5664 n->renameType = OBJECT_TABLE;
5670 | ALTER SEQUENCE qualified_name RENAME TO name
5672 RenameStmt *n = makeNode(RenameStmt);
5673 n->renameType = OBJECT_SEQUENCE;
5679 | ALTER VIEW qualified_name RENAME TO name
5681 RenameStmt *n = makeNode(RenameStmt);
5682 n->renameType = OBJECT_VIEW;
5688 | ALTER INDEX qualified_name RENAME TO name
5690 RenameStmt *n = makeNode(RenameStmt);
5691 n->renameType = OBJECT_INDEX;
5697 | ALTER TABLE relation_expr RENAME opt_column name TO name
5699 RenameStmt *n = makeNode(RenameStmt);
5700 n->renameType = OBJECT_COLUMN;
5706 | ALTER TRIGGER name ON qualified_name RENAME TO name
5708 RenameStmt *n = makeNode(RenameStmt);
5709 n->renameType = OBJECT_TRIGGER;
5715 | ALTER ROLE RoleId RENAME TO RoleId
5717 RenameStmt *n = makeNode(RenameStmt);
5718 n->renameType = OBJECT_ROLE;
5723 | ALTER USER RoleId RENAME TO RoleId
5725 RenameStmt *n = makeNode(RenameStmt);
5726 n->renameType = OBJECT_ROLE;
5731 | ALTER TABLESPACE name RENAME TO name
5733 RenameStmt *n = makeNode(RenameStmt);
5734 n->renameType = OBJECT_TABLESPACE;
5739 | ALTER TABLESPACE name SET reloptions
5741 AlterTableSpaceOptionsStmt *n =
5742 makeNode(AlterTableSpaceOptionsStmt);
5743 n->tablespacename = $3;
5748 | ALTER TABLESPACE name RESET reloptions
5750 AlterTableSpaceOptionsStmt *n =
5751 makeNode(AlterTableSpaceOptionsStmt);
5752 n->tablespacename = $3;
5757 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
5759 RenameStmt *n = makeNode(RenameStmt);
5760 n->renameType = OBJECT_TSPARSER;
5765 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
5767 RenameStmt *n = makeNode(RenameStmt);
5768 n->renameType = OBJECT_TSDICTIONARY;
5773 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
5775 RenameStmt *n = makeNode(RenameStmt);
5776 n->renameType = OBJECT_TSTEMPLATE;
5781 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
5783 RenameStmt *n = makeNode(RenameStmt);
5784 n->renameType = OBJECT_TSCONFIGURATION;
5789 | ALTER TYPE_P any_name RENAME TO name
5791 RenameStmt *n = makeNode(RenameStmt);
5792 n->renameType = OBJECT_TYPE;
5799 opt_column: COLUMN { $$ = COLUMN; }
5800 | /*EMPTY*/ { $$ = 0; }
5803 opt_set_data: SET DATA_P { $$ = 1; }
5804 | /*EMPTY*/ { $$ = 0; }
5807 /*****************************************************************************
5809 * ALTER THING name SET SCHEMA name
5811 *****************************************************************************/
5813 AlterObjectSchemaStmt:
5814 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
5816 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5817 n->objectType = OBJECT_AGGREGATE;
5823 | ALTER DOMAIN_P any_name SET SCHEMA name
5825 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5826 n->objectType = OBJECT_DOMAIN;
5831 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
5833 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5834 n->objectType = OBJECT_FUNCTION;
5835 n->object = $3->funcname;
5836 n->objarg = $3->funcargs;
5840 | ALTER TABLE relation_expr SET SCHEMA name
5842 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5843 n->objectType = OBJECT_TABLE;
5848 | ALTER SEQUENCE qualified_name SET SCHEMA name
5850 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5851 n->objectType = OBJECT_SEQUENCE;
5856 | ALTER VIEW qualified_name SET SCHEMA name
5858 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5859 n->objectType = OBJECT_VIEW;
5864 | ALTER TYPE_P any_name SET SCHEMA name
5866 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5867 n->objectType = OBJECT_TYPE;
5874 /*****************************************************************************
5876 * ALTER THING name OWNER TO newname
5878 *****************************************************************************/
5880 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
5882 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5883 n->objectType = OBJECT_AGGREGATE;
5889 | ALTER CONVERSION_P any_name OWNER TO RoleId
5891 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5892 n->objectType = OBJECT_CONVERSION;
5897 | ALTER DATABASE database_name OWNER TO RoleId
5899 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5900 n->objectType = OBJECT_DATABASE;
5901 n->object = list_make1(makeString($3));
5905 | ALTER DOMAIN_P any_name OWNER TO RoleId
5907 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5908 n->objectType = OBJECT_DOMAIN;
5913 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
5915 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5916 n->objectType = OBJECT_FUNCTION;
5917 n->object = $3->funcname;
5918 n->objarg = $3->funcargs;
5922 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
5924 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5925 n->objectType = OBJECT_LANGUAGE;
5926 n->object = list_make1(makeString($4));
5930 | ALTER LARGE_P OBJECT_P Iconst OWNER TO RoleId
5932 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5933 n->objectType = OBJECT_LARGEOBJECT;
5934 n->object = list_make1(makeInteger($4));
5938 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
5940 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5941 n->objectType = OBJECT_OPERATOR;
5947 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
5949 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5950 n->objectType = OBJECT_OPCLASS;
5956 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
5958 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5959 n->objectType = OBJECT_OPFAMILY;
5965 | ALTER SCHEMA name OWNER TO RoleId
5967 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5968 n->objectType = OBJECT_SCHEMA;
5969 n->object = list_make1(makeString($3));
5973 | ALTER TYPE_P any_name OWNER TO RoleId
5975 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5976 n->objectType = OBJECT_TYPE;
5981 | ALTER TABLESPACE name OWNER TO RoleId
5983 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5984 n->objectType = OBJECT_TABLESPACE;
5985 n->object = list_make1(makeString($3));
5989 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
5991 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5992 n->objectType = OBJECT_TSDICTIONARY;
5997 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
5999 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6000 n->objectType = OBJECT_TSCONFIGURATION;
6005 | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleId
6007 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6008 n->objectType = OBJECT_FDW;
6009 n->object = list_make1(makeString($5));
6013 | ALTER SERVER name OWNER TO RoleId
6015 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6016 n->objectType = OBJECT_FOREIGN_SERVER;
6017 n->object = list_make1(makeString($3));
6024 /*****************************************************************************
6026 * QUERY: Define Rewrite Rule
6028 *****************************************************************************/
6030 RuleStmt: CREATE opt_or_replace RULE name AS
6031 ON event TO qualified_name where_clause
6032 DO opt_instead RuleActionList
6034 RuleStmt *n = makeNode(RuleStmt);
6038 n->whereClause = $10;
6047 NOTHING { $$ = NIL; }
6048 | RuleActionStmt { $$ = list_make1($1); }
6049 | '(' RuleActionMulti ')' { $$ = $2; }
6052 /* the thrashing around here is to discard "empty" statements... */
6054 RuleActionMulti ';' RuleActionStmtOrEmpty
6056 $$ = lappend($1, $3);
6060 | RuleActionStmtOrEmpty
6062 $$ = list_make1($1);
6076 RuleActionStmtOrEmpty:
6077 RuleActionStmt { $$ = $1; }
6078 | /*EMPTY*/ { $$ = NULL; }
6081 event: SELECT { $$ = CMD_SELECT; }
6082 | UPDATE { $$ = CMD_UPDATE; }
6083 | DELETE_P { $$ = CMD_DELETE; }
6084 | INSERT { $$ = CMD_INSERT; }
6088 INSTEAD { $$ = TRUE; }
6089 | ALSO { $$ = FALSE; }
6090 | /*EMPTY*/ { $$ = FALSE; }
6095 DROP RULE name ON qualified_name opt_drop_behavior
6097 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6101 n->removeType = OBJECT_RULE;
6102 n->missing_ok = false;
6105 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
6107 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6111 n->removeType = OBJECT_RULE;
6112 n->missing_ok = true;
6118 /*****************************************************************************
6121 * NOTIFY <identifier> can appear both in rule bodies and
6122 * as a query-level command
6124 *****************************************************************************/
6126 NotifyStmt: NOTIFY ColId
6128 NotifyStmt *n = makeNode(NotifyStmt);
6129 n->conditionname = $2;
6134 ListenStmt: LISTEN ColId
6136 ListenStmt *n = makeNode(ListenStmt);
6137 n->conditionname = $2;
6145 UnlistenStmt *n = makeNode(UnlistenStmt);
6146 n->conditionname = $2;
6151 UnlistenStmt *n = makeNode(UnlistenStmt);
6152 n->conditionname = NULL;
6158 /*****************************************************************************
6162 * BEGIN / COMMIT / ROLLBACK
6163 * (also older versions END / ABORT)
6165 *****************************************************************************/
6168 ABORT_P opt_transaction
6170 TransactionStmt *n = makeNode(TransactionStmt);
6171 n->kind = TRANS_STMT_ROLLBACK;
6175 | BEGIN_P opt_transaction transaction_mode_list_or_empty
6177 TransactionStmt *n = makeNode(TransactionStmt);
6178 n->kind = TRANS_STMT_BEGIN;
6182 | START TRANSACTION transaction_mode_list_or_empty
6184 TransactionStmt *n = makeNode(TransactionStmt);
6185 n->kind = TRANS_STMT_START;
6189 | COMMIT opt_transaction
6191 TransactionStmt *n = makeNode(TransactionStmt);
6192 n->kind = TRANS_STMT_COMMIT;
6196 | END_P opt_transaction
6198 TransactionStmt *n = makeNode(TransactionStmt);
6199 n->kind = TRANS_STMT_COMMIT;
6203 | ROLLBACK opt_transaction
6205 TransactionStmt *n = makeNode(TransactionStmt);
6206 n->kind = TRANS_STMT_ROLLBACK;
6212 TransactionStmt *n = makeNode(TransactionStmt);
6213 n->kind = TRANS_STMT_SAVEPOINT;
6214 n->options = list_make1(makeDefElem("savepoint_name",
6215 (Node *)makeString($2)));
6218 | RELEASE SAVEPOINT ColId
6220 TransactionStmt *n = makeNode(TransactionStmt);
6221 n->kind = TRANS_STMT_RELEASE;
6222 n->options = list_make1(makeDefElem("savepoint_name",
6223 (Node *)makeString($3)));
6228 TransactionStmt *n = makeNode(TransactionStmt);
6229 n->kind = TRANS_STMT_RELEASE;
6230 n->options = list_make1(makeDefElem("savepoint_name",
6231 (Node *)makeString($2)));
6234 | ROLLBACK opt_transaction TO SAVEPOINT ColId
6236 TransactionStmt *n = makeNode(TransactionStmt);
6237 n->kind = TRANS_STMT_ROLLBACK_TO;
6238 n->options = list_make1(makeDefElem("savepoint_name",
6239 (Node *)makeString($5)));
6242 | ROLLBACK opt_transaction TO ColId
6244 TransactionStmt *n = makeNode(TransactionStmt);
6245 n->kind = TRANS_STMT_ROLLBACK_TO;
6246 n->options = list_make1(makeDefElem("savepoint_name",
6247 (Node *)makeString($4)));
6250 | PREPARE TRANSACTION Sconst
6252 TransactionStmt *n = makeNode(TransactionStmt);
6253 n->kind = TRANS_STMT_PREPARE;
6257 | COMMIT PREPARED Sconst
6259 TransactionStmt *n = makeNode(TransactionStmt);
6260 n->kind = TRANS_STMT_COMMIT_PREPARED;
6264 | ROLLBACK PREPARED Sconst
6266 TransactionStmt *n = makeNode(TransactionStmt);
6267 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
6273 opt_transaction: WORK {}
6278 transaction_mode_item:
6279 ISOLATION LEVEL iso_level
6280 { $$ = makeDefElem("transaction_isolation",
6281 makeStringConst($3, @3)); }
6283 { $$ = makeDefElem("transaction_read_only",
6284 makeIntConst(TRUE, @1)); }
6286 { $$ = makeDefElem("transaction_read_only",
6287 makeIntConst(FALSE, @1)); }
6290 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
6291 transaction_mode_list:
6292 transaction_mode_item
6293 { $$ = list_make1($1); }
6294 | transaction_mode_list ',' transaction_mode_item
6295 { $$ = lappend($1, $3); }
6296 | transaction_mode_list transaction_mode_item
6297 { $$ = lappend($1, $2); }
6300 transaction_mode_list_or_empty:
6301 transaction_mode_list
6307 /*****************************************************************************
6310 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
6311 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
6313 *****************************************************************************/
6315 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
6316 AS SelectStmt opt_check_option
6318 ViewStmt *n = makeNode(ViewStmt);
6320 n->view->istemp = $2;
6326 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
6327 AS SelectStmt opt_check_option
6329 ViewStmt *n = makeNode(ViewStmt);
6331 n->view->istemp = $4;
6343 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6344 errmsg("WITH CHECK OPTION is not implemented")));
6346 | WITH CASCADED CHECK OPTION
6349 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6350 errmsg("WITH CHECK OPTION is not implemented")));
6352 | WITH LOCAL CHECK OPTION
6355 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6356 errmsg("WITH CHECK OPTION is not implemented")));
6358 | /* EMPTY */ { $$ = NIL; }
6361 /*****************************************************************************
6366 *****************************************************************************/
6368 LoadStmt: LOAD file_name
6370 LoadStmt *n = makeNode(LoadStmt);
6377 /*****************************************************************************
6381 *****************************************************************************/
6384 CREATE DATABASE database_name opt_with createdb_opt_list
6386 CreatedbStmt *n = makeNode(CreatedbStmt);
6394 createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
6395 | /* EMPTY */ { $$ = NIL; }
6399 TABLESPACE opt_equal name
6401 $$ = makeDefElem("tablespace", (Node *)makeString($3));
6403 | TABLESPACE opt_equal DEFAULT
6405 $$ = makeDefElem("tablespace", NULL);
6407 | LOCATION opt_equal Sconst
6409 $$ = makeDefElem("location", (Node *)makeString($3));
6411 | LOCATION opt_equal DEFAULT
6413 $$ = makeDefElem("location", NULL);
6415 | TEMPLATE opt_equal name
6417 $$ = makeDefElem("template", (Node *)makeString($3));
6419 | TEMPLATE opt_equal DEFAULT
6421 $$ = makeDefElem("template", NULL);
6423 | ENCODING opt_equal Sconst
6425 $$ = makeDefElem("encoding", (Node *)makeString($3));
6427 | ENCODING opt_equal Iconst
6429 $$ = makeDefElem("encoding", (Node *)makeInteger($3));
6431 | ENCODING opt_equal DEFAULT
6433 $$ = makeDefElem("encoding", NULL);
6435 | LC_COLLATE_P opt_equal Sconst
6437 $$ = makeDefElem("lc_collate", (Node *)makeString($3));
6439 | LC_COLLATE_P opt_equal DEFAULT
6441 $$ = makeDefElem("lc_collate", NULL);
6443 | LC_CTYPE_P opt_equal Sconst
6445 $$ = makeDefElem("lc_ctype", (Node *)makeString($3));
6447 | LC_CTYPE_P opt_equal DEFAULT
6449 $$ = makeDefElem("lc_ctype", NULL);
6451 | CONNECTION LIMIT opt_equal SignedIconst
6453 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6455 | OWNER opt_equal name
6457 $$ = makeDefElem("owner", (Node *)makeString($3));
6459 | OWNER opt_equal DEFAULT
6461 $$ = makeDefElem("owner", NULL);
6466 * Though the equals sign doesn't match other WITH options, pg_dump uses
6467 * equals for backward compatibility, and it doesn't seem worth removing it.
6474 /*****************************************************************************
6478 *****************************************************************************/
6481 ALTER DATABASE database_name opt_with alterdb_opt_list
6483 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6488 | ALTER DATABASE database_name SET TABLESPACE name
6490 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6492 n->options = list_make1(makeDefElem("tablespace",
6493 (Node *)makeString($6)));
6498 AlterDatabaseSetStmt:
6499 ALTER DATABASE database_name SetResetClause
6501 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
6510 alterdb_opt_list alterdb_opt_item { $$ = lappend($1, $2); }
6511 | /* EMPTY */ { $$ = NIL; }
6515 CONNECTION LIMIT opt_equal SignedIconst
6517 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6522 /*****************************************************************************
6524 * DROP DATABASE [ IF EXISTS ]
6526 * This is implicitly CASCADE, no need for drop behavior
6527 *****************************************************************************/
6529 DropdbStmt: DROP DATABASE database_name
6531 DropdbStmt *n = makeNode(DropdbStmt);
6533 n->missing_ok = FALSE;
6536 | DROP DATABASE IF_P EXISTS database_name
6538 DropdbStmt *n = makeNode(DropdbStmt);
6540 n->missing_ok = TRUE;
6546 /*****************************************************************************
6548 * Manipulate a domain
6550 *****************************************************************************/
6553 CREATE DOMAIN_P any_name opt_as Typename ColQualList
6555 CreateDomainStmt *n = makeNode(CreateDomainStmt);
6558 n->constraints = $6;
6564 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
6565 ALTER DOMAIN_P any_name alter_column_default
6567 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6573 /* ALTER DOMAIN <domain> DROP NOT NULL */
6574 | ALTER DOMAIN_P any_name DROP NOT NULL_P
6576 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6581 /* ALTER DOMAIN <domain> SET NOT NULL */
6582 | ALTER DOMAIN_P any_name SET NOT NULL_P
6584 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6589 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
6590 | ALTER DOMAIN_P any_name ADD_P TableConstraint
6592 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6598 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
6599 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
6601 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6615 /*****************************************************************************
6617 * Manipulate a text search dictionary or configuration
6619 *****************************************************************************/
6621 AlterTSDictionaryStmt:
6622 ALTER TEXT_P SEARCH DICTIONARY any_name definition
6624 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
6631 AlterTSConfigurationStmt:
6632 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
6634 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6638 n->override = false;
6642 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
6644 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6652 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
6654 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6657 n->dicts = list_make2($9,$11);
6658 n->override = false;
6662 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
6664 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6667 n->dicts = list_make2($11,$13);
6668 n->override = false;
6672 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
6674 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6677 n->missing_ok = false;
6680 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
6682 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6685 n->missing_ok = true;
6691 /*****************************************************************************
6693 * Manipulate a conversion
6695 * CREATE [DEFAULT] CONVERSION <conversion_name>
6696 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
6698 *****************************************************************************/
6700 CreateConversionStmt:
6701 CREATE opt_default CONVERSION_P any_name FOR Sconst
6702 TO Sconst FROM any_name
6704 CreateConversionStmt *n = makeNode(CreateConversionStmt);
6705 n->conversion_name = $4;
6706 n->for_encoding_name = $6;
6707 n->to_encoding_name = $8;
6714 /*****************************************************************************
6717 * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
6719 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
6721 *****************************************************************************/
6724 CLUSTER opt_verbose qualified_name cluster_index_specification
6726 ClusterStmt *n = makeNode(ClusterStmt);
6732 | CLUSTER opt_verbose
6734 ClusterStmt *n = makeNode(ClusterStmt);
6736 n->indexname = NULL;
6740 /* kept for pre-8.3 compatibility */
6741 | CLUSTER opt_verbose index_name ON qualified_name
6743 ClusterStmt *n = makeNode(ClusterStmt);
6751 cluster_index_specification:
6752 USING index_name { $$ = $2; }
6753 | /*EMPTY*/ { $$ = NULL; }
6757 /*****************************************************************************
6763 *****************************************************************************/
6765 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
6767 VacuumStmt *n = makeNode(VacuumStmt);
6768 n->options = VACOPT_VACUUM;
6770 n->options |= VACOPT_FULL;
6772 n->options |= VACOPT_VERBOSE;
6773 n->freeze_min_age = $3 ? 0 : -1;
6774 n->freeze_table_age = $3 ? 0 : -1;
6779 | VACUUM opt_full opt_freeze opt_verbose qualified_name
6781 VacuumStmt *n = makeNode(VacuumStmt);
6782 n->options = VACOPT_VACUUM;
6784 n->options |= VACOPT_FULL;
6786 n->options |= VACOPT_VERBOSE;
6787 n->freeze_min_age = $3 ? 0 : -1;
6788 n->freeze_table_age = $3 ? 0 : -1;
6793 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
6795 VacuumStmt *n = (VacuumStmt *) $5;
6796 n->options |= VACOPT_VACUUM;
6798 n->options |= VACOPT_FULL;
6800 n->options |= VACOPT_VERBOSE;
6801 n->freeze_min_age = $3 ? 0 : -1;
6802 n->freeze_table_age = $3 ? 0 : -1;
6805 | VACUUM '(' vacuum_option_list ')'
6807 VacuumStmt *n = makeNode(VacuumStmt);
6808 n->options = VACOPT_VACUUM | $3;
6809 if (n->options & VACOPT_FREEZE)
6810 n->freeze_min_age = n->freeze_table_age = 0;
6812 n->freeze_min_age = n->freeze_table_age = -1;
6817 | VACUUM '(' vacuum_option_list ')' qualified_name opt_name_list
6819 VacuumStmt *n = makeNode(VacuumStmt);
6820 n->options = VACOPT_VACUUM | $3;
6821 if (n->options & VACOPT_FREEZE)
6822 n->freeze_min_age = n->freeze_table_age = 0;
6824 n->freeze_min_age = n->freeze_table_age = -1;
6827 if (n->va_cols != NIL) /* implies analyze */
6828 n->options |= VACOPT_ANALYZE;
6834 vacuum_option_elem { $$ = $1; }
6835 | vacuum_option_list ',' vacuum_option_elem { $$ = $1 | $3; }
6839 analyze_keyword { $$ = VACOPT_ANALYZE; }
6840 | VERBOSE { $$ = VACOPT_VERBOSE; }
6841 | FREEZE { $$ = VACOPT_FREEZE; }
6842 | FULL { $$ = VACOPT_FULL; }
6846 analyze_keyword opt_verbose
6848 VacuumStmt *n = makeNode(VacuumStmt);
6849 n->options = VACOPT_ANALYZE;
6851 n->options |= VACOPT_VERBOSE;
6852 n->freeze_min_age = -1;
6853 n->freeze_table_age = -1;
6858 | analyze_keyword opt_verbose qualified_name opt_name_list
6860 VacuumStmt *n = makeNode(VacuumStmt);
6861 n->options = VACOPT_ANALYZE;
6863 n->options |= VACOPT_VERBOSE;
6864 n->freeze_min_age = -1;
6865 n->freeze_table_age = -1;
6874 | ANALYSE /* British */ {}
6878 VERBOSE { $$ = TRUE; }
6879 | /*EMPTY*/ { $$ = FALSE; }
6882 opt_full: FULL { $$ = TRUE; }
6883 | /*EMPTY*/ { $$ = FALSE; }
6886 opt_freeze: FREEZE { $$ = TRUE; }
6887 | /*EMPTY*/ { $$ = FALSE; }
6891 '(' name_list ')' { $$ = $2; }
6892 | /*EMPTY*/ { $$ = NIL; }
6896 /*****************************************************************************
6899 * EXPLAIN [ANALYZE] [VERBOSE] query
6900 * EXPLAIN ( options ) query
6902 *****************************************************************************/
6905 EXPLAIN ExplainableStmt
6907 ExplainStmt *n = makeNode(ExplainStmt);
6912 | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
6914 ExplainStmt *n = makeNode(ExplainStmt);
6916 n->options = list_make1(makeDefElem("analyze", NULL));
6918 n->options = lappend(n->options,
6919 makeDefElem("verbose", NULL));
6922 | EXPLAIN VERBOSE ExplainableStmt
6924 ExplainStmt *n = makeNode(ExplainStmt);
6926 n->options = list_make1(makeDefElem("verbose", NULL));
6929 | EXPLAIN '(' explain_option_list ')' ExplainableStmt
6931 ExplainStmt *n = makeNode(ExplainStmt);
6945 | ExecuteStmt /* by default all are $$=$1 */
6948 explain_option_list:
6951 $$ = list_make1($1);
6953 | explain_option_list ',' explain_option_elem
6955 $$ = lappend($1, $3);
6959 explain_option_elem:
6960 explain_option_name explain_option_arg
6962 $$ = makeDefElem($1, $2);
6966 explain_option_name:
6968 | analyze_keyword { $$ = "analyze"; }
6969 | VERBOSE { $$ = "verbose"; }
6973 opt_boolean { $$ = (Node *) makeString($1); }
6974 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
6975 | NumericOnly { $$ = (Node *) $1; }
6976 | /* EMPTY */ { $$ = NULL; }
6979 /*****************************************************************************
6982 * PREPARE <plan_name> [(args, ...)] AS <query>
6984 *****************************************************************************/
6986 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
6988 PrepareStmt *n = makeNode(PrepareStmt);
6996 prep_type_clause: '(' type_list ')' { $$ = $2; }
6997 | /* EMPTY */ { $$ = NIL; }
7004 | DeleteStmt /* by default all are $$=$1 */
7007 /*****************************************************************************
7009 * EXECUTE <plan_name> [(params, ...)]
7010 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
7012 *****************************************************************************/
7014 ExecuteStmt: EXECUTE name execute_param_clause
7016 ExecuteStmt *n = makeNode(ExecuteStmt);
7022 | CREATE OptTemp TABLE create_as_target AS
7023 EXECUTE name execute_param_clause
7025 ExecuteStmt *n = makeNode(ExecuteStmt);
7028 $4->rel->istemp = $2;
7032 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7033 errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
7034 /* ... because it's not implemented, but it could be */
7039 execute_param_clause: '(' expr_list ')' { $$ = $2; }
7040 | /* EMPTY */ { $$ = NIL; }
7043 /*****************************************************************************
7046 * DEALLOCATE [PREPARE] <plan_name>
7048 *****************************************************************************/
7050 DeallocateStmt: DEALLOCATE name
7052 DeallocateStmt *n = makeNode(DeallocateStmt);
7056 | DEALLOCATE PREPARE name
7058 DeallocateStmt *n = makeNode(DeallocateStmt);
7064 DeallocateStmt *n = makeNode(DeallocateStmt);
7068 | DEALLOCATE PREPARE ALL
7070 DeallocateStmt *n = makeNode(DeallocateStmt);
7076 /*****************************************************************************
7081 *****************************************************************************/
7084 INSERT INTO qualified_name insert_rest returning_clause
7087 $4->returningList = $5;
7095 $$ = makeNode(InsertStmt);
7097 $$->selectStmt = $1;
7099 | '(' insert_column_list ')' SelectStmt
7101 $$ = makeNode(InsertStmt);
7103 $$->selectStmt = $4;
7107 $$ = makeNode(InsertStmt);
7109 $$->selectStmt = NULL;
7115 { $$ = list_make1($1); }
7116 | insert_column_list ',' insert_column_item
7117 { $$ = lappend($1, $3); }
7121 ColId opt_indirection
7123 $$ = makeNode(ResTarget);
7125 $$->indirection = check_indirection($2, yyscanner);
7132 RETURNING target_list { $$ = $2; }
7133 | /* EMPTY */ { $$ = NIL; }
7137 /*****************************************************************************
7142 *****************************************************************************/
7144 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
7145 using_clause where_or_current_clause returning_clause
7147 DeleteStmt *n = makeNode(DeleteStmt);
7149 n->usingClause = $4;
7150 n->whereClause = $5;
7151 n->returningList = $6;
7157 USING from_list { $$ = $2; }
7158 | /*EMPTY*/ { $$ = NIL; }
7162 /*****************************************************************************
7167 *****************************************************************************/
7169 LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
7171 LockStmt *n = makeNode(LockStmt);
7180 opt_lock: IN_P lock_type MODE { $$ = $2; }
7181 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
7184 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
7185 | ROW SHARE { $$ = RowShareLock; }
7186 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
7187 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
7188 | SHARE { $$ = ShareLock; }
7189 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
7190 | EXCLUSIVE { $$ = ExclusiveLock; }
7191 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
7194 opt_nowait: NOWAIT { $$ = TRUE; }
7195 | /*EMPTY*/ { $$ = FALSE; }
7199 /*****************************************************************************
7202 * UpdateStmt (UPDATE)
7204 *****************************************************************************/
7206 UpdateStmt: UPDATE relation_expr_opt_alias
7209 where_or_current_clause
7212 UpdateStmt *n = makeNode(UpdateStmt);
7216 n->whereClause = $6;
7217 n->returningList = $7;
7223 set_clause { $$ = $1; }
7224 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
7228 single_set_clause { $$ = list_make1($1); }
7229 | multiple_set_clause { $$ = $1; }
7233 set_target '=' ctext_expr
7236 $$->val = (Node *) $3;
7240 multiple_set_clause:
7241 '(' set_target_list ')' '=' ctext_row
7247 * Break the ctext_row apart, merge individual expressions
7248 * into the destination ResTargets. XXX this approach
7249 * cannot work for general row expressions as sources.
7251 if (list_length($2) != list_length($5))
7253 (errcode(ERRCODE_SYNTAX_ERROR),
7254 errmsg("number of columns does not match number of values"),
7255 parser_errposition(@1)));
7256 forboth(col_cell, $2, val_cell, $5)
7258 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
7259 Node *res_val = (Node *) lfirst(val_cell);
7261 res_col->val = res_val;
7269 ColId opt_indirection
7271 $$ = makeNode(ResTarget);
7273 $$->indirection = check_indirection($2, yyscanner);
7274 $$->val = NULL; /* upper production sets this */
7280 set_target { $$ = list_make1($1); }
7281 | set_target_list ',' set_target { $$ = lappend($1,$3); }
7285 /*****************************************************************************
7290 *****************************************************************************/
7291 DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
7293 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
7295 /* currently we always set FAST_PLAN option */
7296 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
7302 cursor_name: name { $$ = $1; }
7305 cursor_options: /*EMPTY*/ { $$ = 0; }
7306 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
7307 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
7308 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
7309 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
7312 opt_hold: /* EMPTY */ { $$ = 0; }
7313 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
7314 | WITHOUT HOLD { $$ = 0; }
7317 /*****************************************************************************
7322 *****************************************************************************/
7324 /* A complete SELECT statement looks like this.
7326 * The rule returns either a single SelectStmt node or a tree of them,
7327 * representing a set-operation tree.
7329 * There is an ambiguity when a sub-SELECT is within an a_expr and there
7330 * are excess parentheses: do the parentheses belong to the sub-SELECT or
7331 * to the surrounding a_expr? We don't really care, but bison wants to know.
7332 * To resolve the ambiguity, we are careful to define the grammar so that
7333 * the decision is staved off as long as possible: as long as we can keep
7334 * absorbing parentheses into the sub-SELECT, we will do so, and only when
7335 * it's no longer possible to do that will we decide that parens belong to
7336 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
7337 * parentheses are treated as part of the sub-select. The necessity of doing
7338 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
7339 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
7340 * SELECT viewpoint when we see the UNION.
7342 * This approach is implemented by defining a nonterminal select_with_parens,
7343 * which represents a SELECT with at least one outer layer of parentheses,
7344 * and being careful to use select_with_parens, never '(' SelectStmt ')',
7345 * in the expression grammar. We will then have shift-reduce conflicts
7346 * which we can resolve in favor of always treating '(' <select> ')' as
7347 * a select_with_parens. To resolve the conflicts, the productions that
7348 * conflict with the select_with_parens productions are manually given
7349 * precedences lower than the precedence of ')', thereby ensuring that we
7350 * shift ')' (and then reduce to select_with_parens) rather than trying to
7351 * reduce the inner <select> nonterminal to something else. We use UMINUS
7352 * precedence for this, which is a fairly arbitrary choice.
7354 * To be able to define select_with_parens itself without ambiguity, we need
7355 * a nonterminal select_no_parens that represents a SELECT structure with no
7356 * outermost parentheses. This is a little bit tedious, but it works.
7358 * In non-expression contexts, we use SelectStmt which can represent a SELECT
7359 * with or without outer parentheses.
7362 SelectStmt: select_no_parens %prec UMINUS
7363 | select_with_parens %prec UMINUS
7367 '(' select_no_parens ')' { $$ = $2; }
7368 | '(' select_with_parens ')' { $$ = $2; }
7372 * This rule parses the equivalent of the standard's <query expression>.
7373 * The duplicative productions are annoying, but hard to get rid of without
7374 * creating shift/reduce conflicts.
7376 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
7377 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
7378 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
7382 simple_select { $$ = $1; }
7383 | select_clause sort_clause
7385 insertSelectOptions((SelectStmt *) $1, $2, NIL,
7390 | select_clause opt_sort_clause for_locking_clause opt_select_limit
7392 insertSelectOptions((SelectStmt *) $1, $2, $3,
7393 list_nth($4, 0), list_nth($4, 1),
7398 | select_clause opt_sort_clause select_limit opt_for_locking_clause
7400 insertSelectOptions((SelectStmt *) $1, $2, $4,
7401 list_nth($3, 0), list_nth($3, 1),
7406 | with_clause select_clause
7408 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
7414 | with_clause select_clause sort_clause
7416 insertSelectOptions((SelectStmt *) $2, $3, NIL,
7422 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
7424 insertSelectOptions((SelectStmt *) $2, $3, $4,
7425 list_nth($5, 0), list_nth($5, 1),
7430 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
7432 insertSelectOptions((SelectStmt *) $2, $3, $5,
7433 list_nth($4, 0), list_nth($4, 1),
7441 simple_select { $$ = $1; }
7442 | select_with_parens { $$ = $1; }
7446 * This rule parses SELECT statements that can appear within set operations,
7447 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
7448 * the ordering of the set operations. Without '(' and ')' we want the
7449 * operations to be ordered per the precedence specs at the head of this file.
7451 * As with select_no_parens, simple_select cannot have outer parentheses,
7452 * but can have parenthesized subclauses.
7454 * Note that sort clauses cannot be included at this level --- SQL92 requires
7455 * SELECT foo UNION SELECT bar ORDER BY baz
7457 * (SELECT foo UNION SELECT bar) ORDER BY baz
7459 * SELECT foo UNION (SELECT bar ORDER BY baz)
7460 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
7461 * described as part of the select_no_parens production, not simple_select.
7462 * This does not limit functionality, because you can reintroduce these
7463 * clauses inside parentheses.
7465 * NOTE: only the leftmost component SelectStmt should have INTO.
7466 * However, this is not checked by the grammar; parse analysis must check it.
7469 SELECT opt_distinct target_list
7470 into_clause from_clause where_clause
7471 group_clause having_clause window_clause
7473 SelectStmt *n = makeNode(SelectStmt);
7474 n->distinctClause = $2;
7478 n->whereClause = $6;
7479 n->groupClause = $7;
7480 n->havingClause = $8;
7481 n->windowClause = $9;
7484 | values_clause { $$ = $1; }
7485 | TABLE relation_expr
7487 /* same as SELECT * FROM relation_expr */
7488 ColumnRef *cr = makeNode(ColumnRef);
7489 ResTarget *rt = makeNode(ResTarget);
7490 SelectStmt *n = makeNode(SelectStmt);
7492 cr->fields = list_make1(makeNode(A_Star));
7496 rt->indirection = NIL;
7497 rt->val = (Node *)cr;
7500 n->targetList = list_make1(rt);
7501 n->fromClause = list_make1($2);
7504 | select_clause UNION opt_all select_clause
7506 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
7508 | select_clause INTERSECT opt_all select_clause
7510 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
7512 | select_clause EXCEPT opt_all select_clause
7514 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
7519 * SQL standard WITH clause looks like:
7521 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
7522 * AS (query) [ SEARCH or CYCLE clause ]
7524 * We don't currently support the SEARCH or CYCLE clause.
7529 $$ = makeNode(WithClause);
7531 $$->recursive = false;
7534 | WITH RECURSIVE cte_list
7536 $$ = makeNode(WithClause);
7538 $$->recursive = true;
7544 common_table_expr { $$ = list_make1($1); }
7545 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
7548 common_table_expr: name opt_name_list AS select_with_parens
7550 CommonTableExpr *n = makeNode(CommonTableExpr);
7552 n->aliascolnames = $2;
7560 INTO OptTempTableName
7562 $$ = makeNode(IntoClause);
7566 $$->onCommit = ONCOMMIT_NOOP;
7567 $$->tableSpaceName = NULL;
7574 * Redundancy here is needed to avoid shift/reduce conflicts,
7575 * since TEMP is not a reserved word. See also OptTemp.
7578 TEMPORARY opt_table qualified_name
7583 | TEMP opt_table qualified_name
7588 | LOCAL TEMPORARY opt_table qualified_name
7593 | LOCAL TEMP opt_table qualified_name
7598 | GLOBAL TEMPORARY opt_table qualified_name
7603 | GLOBAL TEMP opt_table qualified_name
7608 | TABLE qualified_name
7624 opt_all: ALL { $$ = TRUE; }
7625 | DISTINCT { $$ = FALSE; }
7626 | /*EMPTY*/ { $$ = FALSE; }
7629 /* We use (NIL) as a placeholder to indicate that all target expressions
7630 * should be placed in the DISTINCT list during parsetree analysis.
7633 DISTINCT { $$ = list_make1(NIL); }
7634 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
7636 | /*EMPTY*/ { $$ = NIL; }
7640 sort_clause { $$ = $1;}
7641 | /*EMPTY*/ { $$ = NIL; }
7645 ORDER BY sortby_list { $$ = $3; }
7649 sortby { $$ = list_make1($1); }
7650 | sortby_list ',' sortby { $$ = lappend($1, $3); }
7653 sortby: a_expr USING qual_all_Op opt_nulls_order
7655 $$ = makeNode(SortBy);
7657 $$->sortby_dir = SORTBY_USING;
7658 $$->sortby_nulls = $4;
7662 | a_expr opt_asc_desc opt_nulls_order
7664 $$ = makeNode(SortBy);
7666 $$->sortby_dir = $2;
7667 $$->sortby_nulls = $3;
7669 $$->location = -1; /* no operator */
7675 limit_clause offset_clause { $$ = list_make2($2, $1); }
7676 | offset_clause limit_clause { $$ = list_make2($1, $2); }
7677 | limit_clause { $$ = list_make2(NULL, $1); }
7678 | offset_clause { $$ = list_make2($1, NULL); }
7682 select_limit { $$ = $1; }
7683 | /* EMPTY */ { $$ = list_make2(NULL,NULL); }
7687 LIMIT select_limit_value
7689 | LIMIT select_limit_value ',' select_offset_value
7691 /* Disabled because it was too confusing, bjm 2002-02-18 */
7693 (errcode(ERRCODE_SYNTAX_ERROR),
7694 errmsg("LIMIT #,# syntax is not supported"),
7695 errhint("Use separate LIMIT and OFFSET clauses."),
7696 parser_errposition(@1)));
7698 /* SQL:2008 syntax */
7699 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
7704 OFFSET select_offset_value
7706 /* SQL:2008 syntax */
7707 | OFFSET select_offset_value2 row_or_rows
7715 /* LIMIT ALL is represented as a NULL constant */
7716 $$ = makeNullAConst(@1);
7720 select_offset_value:
7725 * Allowing full expressions without parentheses causes various parsing
7726 * problems with the trailing ROW/ROWS key words. SQL only calls for
7727 * constants, so we allow the rest only with parentheses. If omitted,
7730 opt_select_fetch_first_value:
7731 SignedIconst { $$ = makeIntConst($1, @1); }
7732 | '(' a_expr ')' { $$ = $2; }
7733 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
7737 * Again, the trailing ROW/ROWS in this case prevent the full expression
7738 * syntax. c_expr is the best we can do.
7740 select_offset_value2:
7745 row_or_rows: ROW { $$ = 0; }
7749 first_or_next: FIRST_P { $$ = 0; }
7755 GROUP_P BY expr_list { $$ = $3; }
7756 | /*EMPTY*/ { $$ = NIL; }
7760 HAVING a_expr { $$ = $2; }
7761 | /*EMPTY*/ { $$ = NULL; }
7765 for_locking_items { $$ = $1; }
7766 | FOR READ ONLY { $$ = NIL; }
7769 opt_for_locking_clause:
7770 for_locking_clause { $$ = $1; }
7771 | /* EMPTY */ { $$ = NIL; }
7775 for_locking_item { $$ = list_make1($1); }
7776 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
7780 FOR UPDATE locked_rels_list opt_nowait
7782 LockingClause *n = makeNode(LockingClause);
7784 n->forUpdate = TRUE;
7788 | FOR SHARE locked_rels_list opt_nowait
7790 LockingClause *n = makeNode(LockingClause);
7792 n->forUpdate = FALSE;
7799 OF qualified_name_list { $$ = $2; }
7800 | /* EMPTY */ { $$ = NIL; }
7807 SelectStmt *n = makeNode(SelectStmt);
7808 n->valuesLists = list_make1($2);
7811 | values_clause ',' ctext_row
7813 SelectStmt *n = (SelectStmt *) $1;
7814 n->valuesLists = lappend(n->valuesLists, $3);
7820 /*****************************************************************************
7822 * clauses common to all Optimizable Stmts:
7823 * from_clause - allow list of both JOIN expressions and table names
7824 * where_clause - qualifications for joins or restrictions
7826 *****************************************************************************/
7829 FROM from_list { $$ = $2; }
7830 | /*EMPTY*/ { $$ = NIL; }
7834 table_ref { $$ = list_make1($1); }
7835 | from_list ',' table_ref { $$ = lappend($1, $3); }
7839 * table_ref is where an alias clause can be attached. Note we cannot make
7840 * alias_clause have an empty production because that causes parse conflicts
7841 * between table_ref := '(' joined_table ')' alias_clause
7842 * and joined_table := '(' joined_table ')'. So, we must have the
7843 * redundant-looking productions here instead.
7845 table_ref: relation_expr
7849 | relation_expr alias_clause
7856 RangeFunction *n = makeNode(RangeFunction);
7857 n->funccallnode = $1;
7858 n->coldeflist = NIL;
7861 | func_table alias_clause
7863 RangeFunction *n = makeNode(RangeFunction);
7864 n->funccallnode = $1;
7866 n->coldeflist = NIL;
7869 | func_table AS '(' TableFuncElementList ')'
7871 RangeFunction *n = makeNode(RangeFunction);
7872 n->funccallnode = $1;
7876 | func_table AS ColId '(' TableFuncElementList ')'
7878 RangeFunction *n = makeNode(RangeFunction);
7879 Alias *a = makeNode(Alias);
7880 n->funccallnode = $1;
7886 | func_table ColId '(' TableFuncElementList ')'
7888 RangeFunction *n = makeNode(RangeFunction);
7889 Alias *a = makeNode(Alias);
7890 n->funccallnode = $1;
7896 | select_with_parens
7899 * The SQL spec does not permit a subselect
7900 * (<derived_table>) without an alias clause,
7901 * so we don't either. This avoids the problem
7902 * of needing to invent a unique refname for it.
7903 * That could be surmounted if there's sufficient
7904 * popular demand, but for now let's just implement
7905 * the spec and see if anyone complains.
7906 * However, it does seem like a good idea to emit
7907 * an error message that's better than "syntax error".
7909 if (IsA($1, SelectStmt) &&
7910 ((SelectStmt *) $1)->valuesLists)
7912 (errcode(ERRCODE_SYNTAX_ERROR),
7913 errmsg("VALUES in FROM must have an alias"),
7914 errhint("For example, FROM (VALUES ...) [AS] foo."),
7915 parser_errposition(@1)));
7918 (errcode(ERRCODE_SYNTAX_ERROR),
7919 errmsg("subquery in FROM must have an alias"),
7920 errhint("For example, FROM (SELECT ...) [AS] foo."),
7921 parser_errposition(@1)));
7924 | select_with_parens alias_clause
7926 RangeSubselect *n = makeNode(RangeSubselect);
7935 | '(' joined_table ')' alias_clause
7944 * It may seem silly to separate joined_table from table_ref, but there is
7945 * method in SQL92's madness: if you don't do it this way you get reduce-
7946 * reduce conflicts, because it's not clear to the parser generator whether
7947 * to expect alias_clause after ')' or not. For the same reason we must
7948 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
7949 * join_type to expand to empty; if we try it, the parser generator can't
7950 * figure out when to reduce an empty join_type right after table_ref.
7952 * Note that a CROSS JOIN is the same as an unqualified
7953 * INNER JOIN, and an INNER JOIN/ON has the same shape
7954 * but a qualification expression to limit membership.
7955 * A NATURAL JOIN implicitly matches column names between
7956 * tables and the shape is determined by which columns are
7957 * in common. We'll collect columns during the later transformations.
7961 '(' joined_table ')'
7965 | table_ref CROSS JOIN table_ref
7967 /* CROSS JOIN is same as unqualified inner join */
7968 JoinExpr *n = makeNode(JoinExpr);
7969 n->jointype = JOIN_INNER;
7970 n->isNatural = FALSE;
7973 n->usingClause = NIL;
7977 | table_ref join_type JOIN table_ref join_qual
7979 JoinExpr *n = makeNode(JoinExpr);
7981 n->isNatural = FALSE;
7984 if ($5 != NULL && IsA($5, List))
7985 n->usingClause = (List *) $5; /* USING clause */
7987 n->quals = $5; /* ON clause */
7990 | table_ref JOIN table_ref join_qual
7992 /* letting join_type reduce to empty doesn't work */
7993 JoinExpr *n = makeNode(JoinExpr);
7994 n->jointype = JOIN_INNER;
7995 n->isNatural = FALSE;
7998 if ($4 != NULL && IsA($4, List))
7999 n->usingClause = (List *) $4; /* USING clause */
8001 n->quals = $4; /* ON clause */
8004 | table_ref NATURAL join_type JOIN table_ref
8006 JoinExpr *n = makeNode(JoinExpr);
8008 n->isNatural = TRUE;
8011 n->usingClause = NIL; /* figure out which columns later... */
8012 n->quals = NULL; /* fill later */
8015 | table_ref NATURAL JOIN table_ref
8017 /* letting join_type reduce to empty doesn't work */
8018 JoinExpr *n = makeNode(JoinExpr);
8019 n->jointype = JOIN_INNER;
8020 n->isNatural = TRUE;
8023 n->usingClause = NIL; /* figure out which columns later... */
8024 n->quals = NULL; /* fill later */
8030 AS ColId '(' name_list ')'
8032 $$ = makeNode(Alias);
8038 $$ = makeNode(Alias);
8041 | ColId '(' name_list ')'
8043 $$ = makeNode(Alias);
8049 $$ = makeNode(Alias);
8054 join_type: FULL join_outer { $$ = JOIN_FULL; }
8055 | LEFT join_outer { $$ = JOIN_LEFT; }
8056 | RIGHT join_outer { $$ = JOIN_RIGHT; }
8057 | INNER_P { $$ = JOIN_INNER; }
8060 /* OUTER is just noise... */
8061 join_outer: OUTER_P { $$ = NULL; }
8062 | /*EMPTY*/ { $$ = NULL; }
8065 /* JOIN qualification clauses
8066 * Possibilities are:
8067 * USING ( column list ) allows only unqualified column names,
8068 * which must match between tables.
8069 * ON expr allows more general qualifications.
8071 * We return USING as a List node, while an ON-expr will not be a List.
8074 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
8075 | ON a_expr { $$ = $2; }
8082 /* default inheritance */
8084 $$->inhOpt = INH_DEFAULT;
8087 | qualified_name '*'
8089 /* inheritance query */
8091 $$->inhOpt = INH_YES;
8094 | ONLY qualified_name
8096 /* no inheritance */
8098 $$->inhOpt = INH_NO;
8101 | ONLY '(' qualified_name ')'
8103 /* no inheritance, SQL99-style syntax */
8105 $$->inhOpt = INH_NO;
8112 relation_expr { $$ = list_make1($1); }
8113 | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
8118 * Given "UPDATE foo set set ...", we have to decide without looking any
8119 * further ahead whether the first "set" is an alias or the UPDATE's SET
8120 * keyword. Since "set" is allowed as a column name both interpretations
8121 * are feasible. We resolve the shift/reduce conflict by giving the first
8122 * relation_expr_opt_alias production a higher precedence than the SET token
8123 * has, causing the parser to prefer to reduce, in effect assuming that the
8124 * SET is not an alias.
8126 relation_expr_opt_alias: relation_expr %prec UMINUS
8130 | relation_expr ColId
8132 Alias *alias = makeNode(Alias);
8133 alias->aliasname = $2;
8137 | relation_expr AS ColId
8139 Alias *alias = makeNode(Alias);
8140 alias->aliasname = $3;
8147 func_table: func_expr { $$ = $1; }
8152 WHERE a_expr { $$ = $2; }
8153 | /*EMPTY*/ { $$ = NULL; }
8156 /* variant for UPDATE and DELETE */
8157 where_or_current_clause:
8158 WHERE a_expr { $$ = $2; }
8159 | WHERE CURRENT_P OF name
8161 CurrentOfExpr *n = makeNode(CurrentOfExpr);
8162 /* cvarno is filled in by parse analysis */
8163 n->cursor_name = $4;
8164 n->cursor_param = 0;
8167 | /*EMPTY*/ { $$ = NULL; }
8171 TableFuncElementList:
8174 $$ = list_make1($1);
8176 | TableFuncElementList ',' TableFuncElement
8178 $$ = lappend($1, $3);
8182 TableFuncElement: ColId Typename
8184 ColumnDef *n = makeNode(ColumnDef);
8187 n->constraints = NIL;
8193 /*****************************************************************************
8196 * SQL92 introduces a large amount of type-specific syntax.
8197 * Define individual clauses to handle these cases, and use
8198 * the generic case to handle regular type-extensible Postgres syntax.
8199 * - thomas 1997-10-10
8201 *****************************************************************************/
8203 Typename: SimpleTypename opt_array_bounds
8206 $$->arrayBounds = $2;
8208 | SETOF SimpleTypename opt_array_bounds
8211 $$->arrayBounds = $3;
8214 /* SQL standard syntax, currently only one-dimensional */
8215 | SimpleTypename ARRAY '[' Iconst ']'
8218 $$->arrayBounds = list_make1(makeInteger($4));
8220 | SETOF SimpleTypename ARRAY '[' Iconst ']'
8223 $$->arrayBounds = list_make1(makeInteger($5));
8226 | SimpleTypename ARRAY
8229 $$->arrayBounds = list_make1(makeInteger(-1));
8231 | SETOF SimpleTypename ARRAY
8234 $$->arrayBounds = list_make1(makeInteger(-1));
8240 opt_array_bounds '[' ']'
8241 { $$ = lappend($1, makeInteger(-1)); }
8242 | opt_array_bounds '[' Iconst ']'
8243 { $$ = lappend($1, makeInteger($3)); }
8249 GenericType { $$ = $1; }
8250 | Numeric { $$ = $1; }
8252 | Character { $$ = $1; }
8253 | ConstDatetime { $$ = $1; }
8254 | ConstInterval opt_interval
8259 | ConstInterval '(' Iconst ')' opt_interval
8264 if (list_length($5) != 1)
8266 (errcode(ERRCODE_SYNTAX_ERROR),
8267 errmsg("interval precision specified twice"),
8268 parser_errposition(@1)));
8269 $$->typmods = lappend($5, makeIntConst($3, @3));
8272 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
8273 makeIntConst($3, @3));
8277 /* We have a separate ConstTypename to allow defaulting fixed-length
8278 * types such as CHAR() and BIT() to an unspecified length.
8279 * SQL9x requires that these default to a length of one, but this
8280 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
8281 * where there is an obvious better choice to make.
8282 * Note that ConstInterval is not included here since it must
8283 * be pushed up higher in the rules to accomodate the postfix
8284 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
8285 * the generic-type-name case in AExprConst to avoid premature
8286 * reduce/reduce conflicts against function names.
8289 Numeric { $$ = $1; }
8290 | ConstBit { $$ = $1; }
8291 | ConstCharacter { $$ = $1; }
8292 | ConstDatetime { $$ = $1; }
8296 * GenericType covers all type names that don't have special syntax mandated
8297 * by the standard, including qualified names. We also allow type modifiers.
8298 * To avoid parsing conflicts against function invocations, the modifiers
8299 * have to be shown as expr_list here, but parse analysis will only accept
8300 * constants for them.
8303 type_function_name opt_type_modifiers
8305 $$ = makeTypeName($1);
8309 | type_function_name attrs opt_type_modifiers
8311 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8317 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
8318 | /* EMPTY */ { $$ = NIL; }
8322 * SQL92 numeric data types
8326 $$ = SystemTypeName("int4");
8331 $$ = SystemTypeName("int4");
8336 $$ = SystemTypeName("int2");
8341 $$ = SystemTypeName("int8");
8346 $$ = SystemTypeName("float4");
8354 | DOUBLE_P PRECISION
8356 $$ = SystemTypeName("float8");
8359 | DECIMAL_P opt_type_modifiers
8361 $$ = SystemTypeName("numeric");
8365 | DEC opt_type_modifiers
8367 $$ = SystemTypeName("numeric");
8371 | NUMERIC opt_type_modifiers
8373 $$ = SystemTypeName("numeric");
8379 $$ = SystemTypeName("bool");
8384 opt_float: '(' Iconst ')'
8387 * Check FLOAT() precision limits assuming IEEE floating
8388 * types - thomas 1997-09-18
8392 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8393 errmsg("precision for type float must be at least 1 bit"),
8394 parser_errposition(@2)));
8396 $$ = SystemTypeName("float4");
8398 $$ = SystemTypeName("float8");
8401 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8402 errmsg("precision for type float must be less than 54 bits"),
8403 parser_errposition(@2)));
8407 $$ = SystemTypeName("float8");
8412 * SQL92 bit-field data types
8413 * The following implements BIT() and BIT VARYING().
8425 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
8426 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
8427 ConstBit: BitWithLength
8439 BIT opt_varying '(' expr_list ')'
8443 typname = $2 ? "varbit" : "bit";
8444 $$ = SystemTypeName(typname);
8453 /* bit defaults to bit(1), varbit to no limit */
8456 $$ = SystemTypeName("varbit");
8460 $$ = SystemTypeName("bit");
8461 $$->typmods = list_make1(makeIntConst(1, -1));
8469 * SQL92 character data types
8470 * The following implements CHAR() and VARCHAR().
8472 Character: CharacterWithLength
8476 | CharacterWithoutLength
8482 ConstCharacter: CharacterWithLength
8486 | CharacterWithoutLength
8488 /* Length was not specified so allow to be unrestricted.
8489 * This handles problems with fixed-length (bpchar) strings
8490 * which in column definitions must default to a length
8491 * of one, but should not be constrained if the length
8492 * was not specified.
8499 CharacterWithLength: character '(' Iconst ')' opt_charset
8501 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
8505 type = palloc(strlen($1) + 1 + strlen($5) + 1);
8512 $$ = SystemTypeName($1);
8513 $$->typmods = list_make1(makeIntConst($3, @3));
8518 CharacterWithoutLength: character opt_charset
8520 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
8524 type = palloc(strlen($1) + 1 + strlen($2) + 1);
8531 $$ = SystemTypeName($1);
8533 /* char defaults to char(1), varchar to no limit */
8534 if (strcmp($1, "bpchar") == 0)
8535 $$->typmods = list_make1(makeIntConst(1, -1));
8541 character: CHARACTER opt_varying
8542 { $$ = $2 ? "varchar": "bpchar"; }
8543 | CHAR_P opt_varying
8544 { $$ = $2 ? "varchar": "bpchar"; }
8547 | NATIONAL CHARACTER opt_varying
8548 { $$ = $3 ? "varchar": "bpchar"; }
8549 | NATIONAL CHAR_P opt_varying
8550 { $$ = $3 ? "varchar": "bpchar"; }
8552 { $$ = $2 ? "varchar": "bpchar"; }
8556 VARYING { $$ = TRUE; }
8557 | /*EMPTY*/ { $$ = FALSE; }
8561 CHARACTER SET ColId { $$ = $3; }
8562 | /*EMPTY*/ { $$ = NULL; }
8566 * SQL92 date/time types
8569 TIMESTAMP '(' Iconst ')' opt_timezone
8572 $$ = SystemTypeName("timestamptz");
8574 $$ = SystemTypeName("timestamp");
8575 $$->typmods = list_make1(makeIntConst($3, @3));
8578 | TIMESTAMP opt_timezone
8581 $$ = SystemTypeName("timestamptz");
8583 $$ = SystemTypeName("timestamp");
8586 | TIME '(' Iconst ')' opt_timezone
8589 $$ = SystemTypeName("timetz");
8591 $$ = SystemTypeName("time");
8592 $$->typmods = list_make1(makeIntConst($3, @3));
8598 $$ = SystemTypeName("timetz");
8600 $$ = SystemTypeName("time");
8608 $$ = SystemTypeName("interval");
8614 WITH_TIME ZONE { $$ = TRUE; }
8615 | WITHOUT TIME ZONE { $$ = FALSE; }
8616 | /*EMPTY*/ { $$ = FALSE; }
8621 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
8623 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
8625 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
8627 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
8629 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
8634 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
8635 INTERVAL_MASK(MONTH), @1));
8639 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8640 INTERVAL_MASK(HOUR), @1));
8644 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8645 INTERVAL_MASK(HOUR) |
8646 INTERVAL_MASK(MINUTE), @1));
8648 | DAY_P TO interval_second
8651 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
8652 INTERVAL_MASK(HOUR) |
8653 INTERVAL_MASK(MINUTE) |
8654 INTERVAL_MASK(SECOND), @1);
8656 | HOUR_P TO MINUTE_P
8658 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
8659 INTERVAL_MASK(MINUTE), @1));
8661 | HOUR_P TO interval_second
8664 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
8665 INTERVAL_MASK(MINUTE) |
8666 INTERVAL_MASK(SECOND), @1);
8668 | MINUTE_P TO interval_second
8671 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
8672 INTERVAL_MASK(SECOND), @1);
8681 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
8683 | SECOND_P '(' Iconst ')'
8685 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
8686 makeIntConst($3, @3));
8691 /*****************************************************************************
8693 * expression grammar
8695 *****************************************************************************/
8698 * General expressions
8699 * This is the heart of the expression syntax.
8701 * We have two expression types: a_expr is the unrestricted kind, and
8702 * b_expr is a subset that must be used in some places to avoid shift/reduce
8703 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
8704 * because that use of AND conflicts with AND as a boolean operator. So,
8705 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
8707 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
8708 * always be used by surrounding it with parens.
8710 * c_expr is all the productions that are common to a_expr and b_expr;
8711 * it's factored out just to eliminate redundant coding.
8713 a_expr: c_expr { $$ = $1; }
8714 | a_expr TYPECAST Typename
8715 { $$ = makeTypeCast($1, $3, @2); }
8716 | a_expr AT TIME ZONE a_expr
8718 FuncCall *n = makeNode(FuncCall);
8719 n->funcname = SystemFuncName("timezone");
8720 n->args = list_make2($5, $1);
8722 n->agg_star = FALSE;
8723 n->agg_distinct = FALSE;
8724 n->func_variadic = FALSE;
8730 * These operators must be called out explicitly in order to make use
8731 * of bison's automatic operator-precedence handling. All other
8732 * operator names are handled by the generic productions using "Op",
8733 * below; and all those operators will have the same precedence.
8735 * If you add more explicitly-known operators, be sure to add them
8736 * also to b_expr and to the MathOp list above.
8738 | '+' a_expr %prec UMINUS
8739 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
8740 | '-' a_expr %prec UMINUS
8741 { $$ = doNegate($2, @1); }
8743 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
8745 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
8747 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
8749 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
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 | a_expr qual_Op a_expr %prec Op
8762 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
8763 | qual_Op a_expr %prec Op
8764 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
8765 | a_expr qual_Op %prec POSTFIXOP
8766 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
8769 { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
8771 { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
8773 { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
8775 | a_expr LIKE a_expr
8776 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
8777 | a_expr LIKE a_expr ESCAPE a_expr
8779 FuncCall *n = makeNode(FuncCall);
8780 n->funcname = SystemFuncName("like_escape");
8781 n->args = list_make2($3, $5);
8783 n->agg_star = FALSE;
8784 n->agg_distinct = FALSE;
8785 n->func_variadic = FALSE;
8788 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
8790 | a_expr NOT LIKE a_expr
8791 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
8792 | a_expr NOT LIKE a_expr ESCAPE a_expr
8794 FuncCall *n = makeNode(FuncCall);
8795 n->funcname = SystemFuncName("like_escape");
8796 n->args = list_make2($4, $6);
8798 n->agg_star = FALSE;
8799 n->agg_distinct = FALSE;
8800 n->func_variadic = FALSE;
8803 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
8805 | a_expr ILIKE a_expr
8806 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
8807 | a_expr ILIKE a_expr ESCAPE a_expr
8809 FuncCall *n = makeNode(FuncCall);
8810 n->funcname = SystemFuncName("like_escape");
8811 n->args = list_make2($3, $5);
8813 n->agg_star = FALSE;
8814 n->agg_distinct = FALSE;
8815 n->func_variadic = FALSE;
8818 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n, @2);
8820 | a_expr NOT ILIKE a_expr
8821 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
8822 | a_expr NOT ILIKE a_expr ESCAPE a_expr
8824 FuncCall *n = makeNode(FuncCall);
8825 n->funcname = SystemFuncName("like_escape");
8826 n->args = list_make2($4, $6);
8828 n->agg_star = FALSE;
8829 n->agg_distinct = FALSE;
8830 n->func_variadic = FALSE;
8833 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n, @2);
8836 | a_expr SIMILAR TO a_expr %prec SIMILAR
8838 FuncCall *n = makeNode(FuncCall);
8839 n->funcname = SystemFuncName("similar_escape");
8840 n->args = list_make2($4, makeNullAConst(-1));
8842 n->agg_star = FALSE;
8843 n->agg_distinct = FALSE;
8844 n->func_variadic = FALSE;
8847 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8849 | a_expr SIMILAR TO a_expr ESCAPE a_expr
8851 FuncCall *n = makeNode(FuncCall);
8852 n->funcname = SystemFuncName("similar_escape");
8853 n->args = list_make2($4, $6);
8855 n->agg_star = FALSE;
8856 n->agg_distinct = FALSE;
8857 n->func_variadic = FALSE;
8860 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8862 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
8864 FuncCall *n = makeNode(FuncCall);
8865 n->funcname = SystemFuncName("similar_escape");
8866 n->args = list_make2($5, makeNullAConst(-1));
8868 n->agg_star = FALSE;
8869 n->agg_distinct = FALSE;
8870 n->func_variadic = FALSE;
8873 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8875 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
8877 FuncCall *n = makeNode(FuncCall);
8878 n->funcname = SystemFuncName("similar_escape");
8879 n->args = list_make2($5, $7);
8881 n->agg_star = FALSE;
8882 n->agg_distinct = FALSE;
8883 n->func_variadic = FALSE;
8886 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8890 * Define SQL92-style Null test clause.
8891 * Allow two forms described in the standard:
8894 * Allow two SQL extensions
8900 NullTest *n = makeNode(NullTest);
8901 n->arg = (Expr *) $1;
8902 n->nulltesttype = IS_NULL;
8907 NullTest *n = makeNode(NullTest);
8908 n->arg = (Expr *) $1;
8909 n->nulltesttype = IS_NULL;
8912 | a_expr IS NOT NULL_P
8914 NullTest *n = makeNode(NullTest);
8915 n->arg = (Expr *) $1;
8916 n->nulltesttype = IS_NOT_NULL;
8921 NullTest *n = makeNode(NullTest);
8922 n->arg = (Expr *) $1;
8923 n->nulltesttype = IS_NOT_NULL;
8928 $$ = (Node *)makeOverlaps($1, $3, @2, yyscanner);
8932 BooleanTest *b = makeNode(BooleanTest);
8933 b->arg = (Expr *) $1;
8934 b->booltesttype = IS_TRUE;
8937 | a_expr IS NOT TRUE_P
8939 BooleanTest *b = makeNode(BooleanTest);
8940 b->arg = (Expr *) $1;
8941 b->booltesttype = IS_NOT_TRUE;
8946 BooleanTest *b = makeNode(BooleanTest);
8947 b->arg = (Expr *) $1;
8948 b->booltesttype = IS_FALSE;
8951 | a_expr IS NOT FALSE_P
8953 BooleanTest *b = makeNode(BooleanTest);
8954 b->arg = (Expr *) $1;
8955 b->booltesttype = IS_NOT_FALSE;
8960 BooleanTest *b = makeNode(BooleanTest);
8961 b->arg = (Expr *) $1;
8962 b->booltesttype = IS_UNKNOWN;
8965 | a_expr IS NOT UNKNOWN
8967 BooleanTest *b = makeNode(BooleanTest);
8968 b->arg = (Expr *) $1;
8969 b->booltesttype = IS_NOT_UNKNOWN;
8972 | a_expr IS DISTINCT FROM a_expr %prec IS
8974 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
8976 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
8978 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8979 (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
8984 | a_expr IS OF '(' type_list ')' %prec IS
8986 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
8988 | a_expr IS NOT OF '(' type_list ')' %prec IS
8990 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
8993 * Ideally we would not use hard-wired operators below but
8994 * instead use opclasses. However, mixed data types and other
8995 * issues make this difficult:
8996 * http://archives.postgresql.org/pgsql-hackers/2008-08/msg01142.php
8998 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
9000 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
9001 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
9002 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
9005 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
9007 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
9008 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
9009 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
9012 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
9014 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
9015 (Node *) makeA_Expr(AEXPR_AND, NIL,
9016 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
9017 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
9019 (Node *) makeA_Expr(AEXPR_AND, NIL,
9020 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
9021 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
9025 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
9027 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
9028 (Node *) makeA_Expr(AEXPR_OR, NIL,
9029 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
9030 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
9032 (Node *) makeA_Expr(AEXPR_OR, NIL,
9033 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
9034 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
9038 | a_expr IN_P in_expr
9040 /* in_expr returns a SubLink or a list of a_exprs */
9041 if (IsA($3, SubLink))
9043 /* generate foo = ANY (subquery) */
9044 SubLink *n = (SubLink *) $3;
9045 n->subLinkType = ANY_SUBLINK;
9047 n->operName = list_make1(makeString("="));
9053 /* generate scalar IN expression */
9054 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
9057 | a_expr NOT IN_P in_expr
9059 /* in_expr returns a SubLink or a list of a_exprs */
9060 if (IsA($4, SubLink))
9062 /* generate NOT (foo = ANY (subquery)) */
9063 /* Make an = ANY node */
9064 SubLink *n = (SubLink *) $4;
9065 n->subLinkType = ANY_SUBLINK;
9067 n->operName = list_make1(makeString("="));
9069 /* Stick a NOT on top */
9070 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
9074 /* generate scalar NOT IN expression */
9075 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
9078 | a_expr subquery_Op sub_type select_with_parens %prec Op
9080 SubLink *n = makeNode(SubLink);
9081 n->subLinkType = $3;
9088 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
9090 if ($3 == ANY_SUBLINK)
9091 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
9093 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
9095 | UNIQUE select_with_parens
9097 /* Not sure how to get rid of the parentheses
9098 * but there are lots of shift/reduce errors without them.
9100 * Should be able to implement this by plopping the entire
9101 * select into a node, then transforming the target expressions
9102 * from whatever they are into count(*), and testing the
9103 * entire result equal to one.
9104 * But, will probably implement a separate node in the executor.
9107 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9108 errmsg("UNIQUE predicate is not yet implemented"),
9109 parser_errposition(@1)));
9111 | a_expr IS DOCUMENT_P %prec IS
9113 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9114 list_make1($1), @2);
9116 | a_expr IS NOT DOCUMENT_P %prec IS
9118 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9119 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9120 list_make1($1), @2),
9126 * Restricted expressions
9128 * b_expr is a subset of the complete expression syntax defined by a_expr.
9130 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
9131 * cause trouble in the places where b_expr is used. For simplicity, we
9132 * just eliminate all the boolean-keyword-operator productions from b_expr.
9136 | b_expr TYPECAST Typename
9137 { $$ = makeTypeCast($1, $3, @2); }
9138 | '+' b_expr %prec UMINUS
9139 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
9140 | '-' b_expr %prec UMINUS
9141 { $$ = doNegate($2, @1); }
9143 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
9145 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
9147 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
9149 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
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); }
9160 | b_expr qual_Op b_expr %prec Op
9161 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
9162 | qual_Op b_expr %prec Op
9163 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
9164 | b_expr qual_Op %prec POSTFIXOP
9165 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
9166 | b_expr IS DISTINCT FROM b_expr %prec IS
9168 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
9170 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
9172 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
9173 NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
9175 | b_expr IS OF '(' type_list ')' %prec IS
9177 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
9179 | b_expr IS NOT OF '(' type_list ')' %prec IS
9181 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
9183 | b_expr IS DOCUMENT_P %prec IS
9185 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9186 list_make1($1), @2);
9188 | b_expr IS NOT DOCUMENT_P %prec IS
9190 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9191 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9192 list_make1($1), @2),
9198 * Productions that can be used in both a_expr and b_expr.
9200 * Note: productions that refer recursively to a_expr or b_expr mostly
9201 * cannot appear here. However, it's OK to refer to a_exprs that occur
9202 * inside parentheses, such as function arguments; that cannot introduce
9203 * ambiguity to the b_expr syntax.
9205 c_expr: columnref { $$ = $1; }
9206 | AexprConst { $$ = $1; }
9207 | PARAM opt_indirection
9209 ParamRef *p = makeNode(ParamRef);
9214 A_Indirection *n = makeNode(A_Indirection);
9215 n->arg = (Node *) p;
9216 n->indirection = check_indirection($2, yyscanner);
9222 | '(' a_expr ')' opt_indirection
9226 A_Indirection *n = makeNode(A_Indirection);
9228 n->indirection = check_indirection($4, yyscanner);
9238 | select_with_parens %prec UMINUS
9240 SubLink *n = makeNode(SubLink);
9241 n->subLinkType = EXPR_SUBLINK;
9248 | EXISTS select_with_parens
9250 SubLink *n = makeNode(SubLink);
9251 n->subLinkType = EXISTS_SUBLINK;
9258 | ARRAY select_with_parens
9260 SubLink *n = makeNode(SubLink);
9261 n->subLinkType = ARRAY_SUBLINK;
9270 A_ArrayExpr *n = (A_ArrayExpr *) $2;
9271 Assert(IsA(n, A_ArrayExpr));
9272 /* point outermost A_ArrayExpr to the ARRAY keyword */
9278 RowExpr *r = makeNode(RowExpr);
9280 r->row_typeid = InvalidOid; /* not analyzed yet */
9287 * func_expr is split out from c_expr just so that we have a classification
9288 * for "everything that is a function call or looks like one". This isn't
9289 * very important, but it saves us having to document which variants are
9290 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
9291 * (Note that many of the special SQL functions wouldn't actually make any
9292 * sense as functional index entries, but we ignore that consideration here.)
9294 func_expr: func_name '(' ')' over_clause
9296 FuncCall *n = makeNode(FuncCall);
9300 n->agg_star = FALSE;
9301 n->agg_distinct = FALSE;
9302 n->func_variadic = FALSE;
9307 | func_name '(' func_arg_list ')' over_clause
9309 FuncCall *n = makeNode(FuncCall);
9313 n->agg_star = FALSE;
9314 n->agg_distinct = FALSE;
9315 n->func_variadic = FALSE;
9320 | func_name '(' VARIADIC func_arg_expr ')' over_clause
9322 FuncCall *n = makeNode(FuncCall);
9324 n->args = list_make1($4);
9326 n->agg_star = FALSE;
9327 n->agg_distinct = FALSE;
9328 n->func_variadic = TRUE;
9333 | func_name '(' func_arg_list ',' VARIADIC func_arg_expr ')' over_clause
9335 FuncCall *n = makeNode(FuncCall);
9337 n->args = lappend($3, $6);
9339 n->agg_star = FALSE;
9340 n->agg_distinct = FALSE;
9341 n->func_variadic = TRUE;
9346 | func_name '(' func_arg_list sort_clause ')' over_clause
9348 FuncCall *n = makeNode(FuncCall);
9352 n->agg_star = FALSE;
9353 n->agg_distinct = FALSE;
9354 n->func_variadic = FALSE;
9359 | func_name '(' ALL func_arg_list opt_sort_clause ')' over_clause
9361 FuncCall *n = makeNode(FuncCall);
9365 n->agg_star = FALSE;
9366 n->agg_distinct = FALSE;
9367 /* Ideally we'd mark the FuncCall node to indicate
9368 * "must be an aggregate", but there's no provision
9369 * for that in FuncCall at the moment.
9371 n->func_variadic = FALSE;
9376 | func_name '(' DISTINCT func_arg_list opt_sort_clause ')' over_clause
9378 FuncCall *n = makeNode(FuncCall);
9382 n->agg_star = FALSE;
9383 n->agg_distinct = TRUE;
9384 n->func_variadic = FALSE;
9389 | func_name '(' '*' ')' over_clause
9392 * We consider AGGREGATE(*) to invoke a parameterless
9393 * aggregate. This does the right thing for COUNT(*),
9394 * and there are no other aggregates in SQL92 that accept
9397 * The FuncCall node is also marked agg_star = true,
9398 * so that later processing can detect what the argument
9401 FuncCall *n = makeNode(FuncCall);
9406 n->agg_distinct = FALSE;
9407 n->func_variadic = FALSE;
9415 * Translate as "'now'::text::date".
9417 * We cannot use "'now'::date" because coerce_type() will
9418 * immediately reduce that to a constant representing
9419 * today's date. We need to delay the conversion until
9420 * runtime, else the wrong things will happen when
9421 * CURRENT_DATE is used in a column default value or rule.
9423 * This could be simplified if we had a way to generate
9424 * an expression tree representing runtime application
9425 * of type-input conversion functions. (As of PG 7.3
9426 * that is actually possible, but not clear that we want
9430 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9431 $$ = makeTypeCast(n, SystemTypeName("date"), -1);
9436 * Translate as "'now'::text::timetz".
9437 * See comments for CURRENT_DATE.
9440 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9441 $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
9443 | CURRENT_TIME '(' Iconst ')'
9446 * Translate as "'now'::text::timetz(n)".
9447 * See comments for CURRENT_DATE.
9451 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9452 d = SystemTypeName("timetz");
9453 d->typmods = list_make1(makeIntConst($3, @3));
9454 $$ = makeTypeCast(n, d, -1);
9459 * Translate as "now()", since we have a function that
9460 * does exactly what is needed.
9462 FuncCall *n = makeNode(FuncCall);
9463 n->funcname = SystemFuncName("now");
9466 n->agg_star = FALSE;
9467 n->agg_distinct = FALSE;
9468 n->func_variadic = FALSE;
9473 | CURRENT_TIMESTAMP '(' Iconst ')'
9476 * Translate as "'now'::text::timestamptz(n)".
9477 * See comments for CURRENT_DATE.
9481 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9482 d = SystemTypeName("timestamptz");
9483 d->typmods = list_make1(makeIntConst($3, @3));
9484 $$ = makeTypeCast(n, d, -1);
9489 * Translate as "'now'::text::time".
9490 * See comments for CURRENT_DATE.
9493 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9494 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
9496 | LOCALTIME '(' Iconst ')'
9499 * Translate as "'now'::text::time(n)".
9500 * See comments for CURRENT_DATE.
9504 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9505 d = SystemTypeName("time");
9506 d->typmods = list_make1(makeIntConst($3, @3));
9507 $$ = makeTypeCast((Node *)n, d, -1);
9512 * Translate as "'now'::text::timestamp".
9513 * See comments for CURRENT_DATE.
9516 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9517 $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
9519 | LOCALTIMESTAMP '(' Iconst ')'
9522 * Translate as "'now'::text::timestamp(n)".
9523 * See comments for CURRENT_DATE.
9527 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9528 d = SystemTypeName("timestamp");
9529 d->typmods = list_make1(makeIntConst($3, @3));
9530 $$ = makeTypeCast(n, d, -1);
9534 FuncCall *n = makeNode(FuncCall);
9535 n->funcname = SystemFuncName("current_user");
9538 n->agg_star = FALSE;
9539 n->agg_distinct = FALSE;
9540 n->func_variadic = FALSE;
9547 FuncCall *n = makeNode(FuncCall);
9548 n->funcname = SystemFuncName("current_user");
9551 n->agg_star = FALSE;
9552 n->agg_distinct = FALSE;
9553 n->func_variadic = FALSE;
9560 FuncCall *n = makeNode(FuncCall);
9561 n->funcname = SystemFuncName("session_user");
9564 n->agg_star = FALSE;
9565 n->agg_distinct = FALSE;
9566 n->func_variadic = FALSE;
9573 FuncCall *n = makeNode(FuncCall);
9574 n->funcname = SystemFuncName("current_user");
9577 n->agg_star = FALSE;
9578 n->agg_distinct = FALSE;
9579 n->func_variadic = FALSE;
9586 FuncCall *n = makeNode(FuncCall);
9587 n->funcname = SystemFuncName("current_database");
9590 n->agg_star = FALSE;
9591 n->agg_distinct = FALSE;
9592 n->func_variadic = FALSE;
9599 FuncCall *n = makeNode(FuncCall);
9600 n->funcname = SystemFuncName("current_schema");
9603 n->agg_star = FALSE;
9604 n->agg_distinct = FALSE;
9605 n->func_variadic = FALSE;
9610 | CAST '(' a_expr AS Typename ')'
9611 { $$ = makeTypeCast($3, $5, @1); }
9612 | EXTRACT '(' extract_list ')'
9614 FuncCall *n = makeNode(FuncCall);
9615 n->funcname = SystemFuncName("date_part");
9618 n->agg_star = FALSE;
9619 n->agg_distinct = FALSE;
9620 n->func_variadic = FALSE;
9625 | OVERLAY '(' overlay_list ')'
9627 /* overlay(A PLACING B FROM C FOR D) is converted to
9628 * overlay(A, B, C, D)
9629 * overlay(A PLACING B FROM C) is converted to
9632 FuncCall *n = makeNode(FuncCall);
9633 n->funcname = SystemFuncName("overlay");
9636 n->agg_star = FALSE;
9637 n->agg_distinct = FALSE;
9638 n->func_variadic = FALSE;
9643 | POSITION '(' position_list ')'
9645 /* position(A in B) is converted to position(B, A) */
9646 FuncCall *n = makeNode(FuncCall);
9647 n->funcname = SystemFuncName("position");
9650 n->agg_star = FALSE;
9651 n->agg_distinct = FALSE;
9652 n->func_variadic = FALSE;
9657 | SUBSTRING '(' substr_list ')'
9659 /* substring(A from B for C) is converted to
9660 * substring(A, B, C) - thomas 2000-11-28
9662 FuncCall *n = makeNode(FuncCall);
9663 n->funcname = SystemFuncName("substring");
9666 n->agg_star = FALSE;
9667 n->agg_distinct = FALSE;
9668 n->func_variadic = FALSE;
9673 | TREAT '(' a_expr AS Typename ')'
9675 /* TREAT(expr AS target) converts expr of a particular type to target,
9676 * which is defined to be a subtype of the original expression.
9677 * In SQL99, this is intended for use with structured UDTs,
9678 * but let's make this a generally useful form allowing stronger
9679 * coercions than are handled by implicit casting.
9681 FuncCall *n = makeNode(FuncCall);
9682 /* Convert SystemTypeName() to SystemFuncName() even though
9683 * at the moment they result in the same thing.
9685 n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
9686 n->args = list_make1($3);
9688 n->agg_star = FALSE;
9689 n->agg_distinct = FALSE;
9690 n->func_variadic = FALSE;
9695 | TRIM '(' BOTH trim_list ')'
9697 /* various trim expressions are defined in SQL92
9698 * - thomas 1997-07-19
9700 FuncCall *n = makeNode(FuncCall);
9701 n->funcname = SystemFuncName("btrim");
9704 n->agg_star = FALSE;
9705 n->agg_distinct = FALSE;
9706 n->func_variadic = FALSE;
9711 | TRIM '(' LEADING trim_list ')'
9713 FuncCall *n = makeNode(FuncCall);
9714 n->funcname = SystemFuncName("ltrim");
9717 n->agg_star = FALSE;
9718 n->agg_distinct = FALSE;
9719 n->func_variadic = FALSE;
9724 | TRIM '(' TRAILING trim_list ')'
9726 FuncCall *n = makeNode(FuncCall);
9727 n->funcname = SystemFuncName("rtrim");
9730 n->agg_star = FALSE;
9731 n->agg_distinct = FALSE;
9732 n->func_variadic = FALSE;
9737 | TRIM '(' trim_list ')'
9739 FuncCall *n = makeNode(FuncCall);
9740 n->funcname = SystemFuncName("btrim");
9743 n->agg_star = FALSE;
9744 n->agg_distinct = FALSE;
9745 n->func_variadic = FALSE;
9750 | NULLIF '(' a_expr ',' a_expr ')'
9752 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
9754 | COALESCE '(' expr_list ')'
9756 CoalesceExpr *c = makeNode(CoalesceExpr);
9761 | GREATEST '(' expr_list ')'
9763 MinMaxExpr *v = makeNode(MinMaxExpr);
9765 v->op = IS_GREATEST;
9769 | LEAST '(' expr_list ')'
9771 MinMaxExpr *v = makeNode(MinMaxExpr);
9777 | XMLCONCAT '(' expr_list ')'
9779 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
9781 | XMLELEMENT '(' NAME_P ColLabel ')'
9783 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
9785 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
9787 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
9789 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
9791 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
9793 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
9795 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
9797 | XMLFOREST '(' xml_attribute_list ')'
9799 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
9801 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
9803 XmlExpr *x = (XmlExpr *)
9804 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
9805 list_make2($4, makeBoolAConst($5, -1)),
9810 | XMLPI '(' NAME_P ColLabel ')'
9812 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
9814 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
9816 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
9818 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
9820 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
9821 list_make3($3, $5, $6), @1);
9823 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
9825 XmlSerialize *n = makeNode(XmlSerialize);
9837 xml_root_version: VERSION_P a_expr
9839 | VERSION_P NO VALUE_P
9840 { $$ = makeNullAConst(-1); }
9843 opt_xml_root_standalone: ',' STANDALONE_P YES_P
9844 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
9845 | ',' STANDALONE_P NO
9846 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
9847 | ',' STANDALONE_P NO VALUE_P
9848 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
9850 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
9853 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
9856 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
9857 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
9860 xml_attribute_el: a_expr AS ColLabel
9862 $$ = makeNode(ResTarget);
9864 $$->indirection = NIL;
9865 $$->val = (Node *) $1;
9870 $$ = makeNode(ResTarget);
9872 $$->indirection = NIL;
9873 $$->val = (Node *) $1;
9878 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
9879 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
9882 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
9883 | STRIP_P WHITESPACE_P { $$ = FALSE; }
9884 | /*EMPTY*/ { $$ = FALSE; }
9888 * Window Definitions
9891 WINDOW window_definition_list { $$ = $2; }
9892 | /*EMPTY*/ { $$ = NIL; }
9895 window_definition_list:
9896 window_definition { $$ = list_make1($1); }
9897 | window_definition_list ',' window_definition
9898 { $$ = lappend($1, $3); }
9902 ColId AS window_specification
9910 over_clause: OVER window_specification
9914 WindowDef *n = makeNode(WindowDef);
9917 n->partitionClause = NIL;
9918 n->orderClause = NIL;
9919 n->frameOptions = FRAMEOPTION_DEFAULTS;
9920 n->startOffset = NULL;
9921 n->endOffset = NULL;
9929 window_specification: '(' opt_existing_window_name opt_partition_clause
9930 opt_sort_clause opt_frame_clause ')'
9932 WindowDef *n = makeNode(WindowDef);
9935 n->partitionClause = $3;
9936 n->orderClause = $4;
9937 /* copy relevant fields of opt_frame_clause */
9938 n->frameOptions = $5->frameOptions;
9939 n->startOffset = $5->startOffset;
9940 n->endOffset = $5->endOffset;
9947 * If we see PARTITION, RANGE, or ROWS as the first token after the '('
9948 * of a window_specification, we want the assumption to be that there is
9949 * no existing_window_name; but those keywords are unreserved and so could
9950 * be ColIds. We fix this by making them have the same precedence as IDENT
9951 * and giving the empty production here a slightly higher precedence, so
9952 * that the shift/reduce conflict is resolved in favor of reducing the rule.
9953 * These keywords are thus precluded from being an existing_window_name but
9954 * are not reserved for any other purpose.
9956 opt_existing_window_name: ColId { $$ = $1; }
9957 | /*EMPTY*/ %prec Op { $$ = NULL; }
9960 opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
9961 | /*EMPTY*/ { $$ = NIL; }
9965 * For frame clauses, we return a WindowDef, but only some fields are used:
9966 * frameOptions, startOffset, and endOffset.
9968 * This is only a subset of the full SQL:2008 frame_clause grammar.
9969 * We don't support <window frame exclusion> yet.
9975 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
9976 if (n->frameOptions & (FRAMEOPTION_START_VALUE_PRECEDING |
9977 FRAMEOPTION_END_VALUE_PRECEDING))
9979 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9980 errmsg("RANGE PRECEDING is only supported with UNBOUNDED"),
9981 parser_errposition(@1)));
9982 if (n->frameOptions & (FRAMEOPTION_START_VALUE_FOLLOWING |
9983 FRAMEOPTION_END_VALUE_FOLLOWING))
9985 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9986 errmsg("RANGE FOLLOWING is only supported with UNBOUNDED"),
9987 parser_errposition(@1)));
9993 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
9998 WindowDef *n = makeNode(WindowDef);
9999 n->frameOptions = FRAMEOPTION_DEFAULTS;
10000 n->startOffset = NULL;
10001 n->endOffset = NULL;
10006 frame_extent: frame_bound
10009 /* reject invalid cases */
10010 if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
10012 (errcode(ERRCODE_WINDOWING_ERROR),
10013 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
10014 parser_errposition(@1)));
10015 if (n->frameOptions & FRAMEOPTION_START_VALUE_FOLLOWING)
10017 (errcode(ERRCODE_WINDOWING_ERROR),
10018 errmsg("frame starting from following row cannot end with current row"),
10019 parser_errposition(@1)));
10020 n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
10023 | BETWEEN frame_bound AND frame_bound
10025 WindowDef *n1 = $2;
10026 WindowDef *n2 = $4;
10027 /* form merged options */
10028 int frameOptions = n1->frameOptions;
10029 /* shift converts START_ options to END_ options */
10030 frameOptions |= n2->frameOptions << 1;
10031 frameOptions |= FRAMEOPTION_BETWEEN;
10032 /* reject invalid cases */
10033 if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
10035 (errcode(ERRCODE_WINDOWING_ERROR),
10036 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
10037 parser_errposition(@2)));
10038 if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
10040 (errcode(ERRCODE_WINDOWING_ERROR),
10041 errmsg("frame end cannot be UNBOUNDED PRECEDING"),
10042 parser_errposition(@4)));
10043 if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
10044 (frameOptions & FRAMEOPTION_END_VALUE_PRECEDING))
10046 (errcode(ERRCODE_WINDOWING_ERROR),
10047 errmsg("frame starting from current row cannot have preceding rows"),
10048 parser_errposition(@4)));
10049 if ((frameOptions & FRAMEOPTION_START_VALUE_FOLLOWING) &&
10050 (frameOptions & (FRAMEOPTION_END_VALUE_PRECEDING |
10051 FRAMEOPTION_END_CURRENT_ROW)))
10053 (errcode(ERRCODE_WINDOWING_ERROR),
10054 errmsg("frame starting from following row cannot have preceding rows"),
10055 parser_errposition(@4)));
10056 n1->frameOptions = frameOptions;
10057 n1->endOffset = n2->startOffset;
10063 * This is used for both frame start and frame end, with output set up on
10064 * the assumption it's frame start; the frame_extent productions must reject
10068 UNBOUNDED PRECEDING
10070 WindowDef *n = makeNode(WindowDef);
10071 n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
10072 n->startOffset = NULL;
10073 n->endOffset = NULL;
10076 | UNBOUNDED FOLLOWING
10078 WindowDef *n = makeNode(WindowDef);
10079 n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
10080 n->startOffset = NULL;
10081 n->endOffset = NULL;
10086 WindowDef *n = makeNode(WindowDef);
10087 n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
10088 n->startOffset = NULL;
10089 n->endOffset = NULL;
10094 WindowDef *n = makeNode(WindowDef);
10095 n->frameOptions = FRAMEOPTION_START_VALUE_PRECEDING;
10096 n->startOffset = $1;
10097 n->endOffset = NULL;
10102 WindowDef *n = makeNode(WindowDef);
10103 n->frameOptions = FRAMEOPTION_START_VALUE_FOLLOWING;
10104 n->startOffset = $1;
10105 n->endOffset = NULL;
10112 * Supporting nonterminals for expressions.
10115 /* Explicit row production.
10117 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
10118 * without conflicting with the parenthesized a_expr production. Without the
10119 * ROW keyword, there must be more than one a_expr inside the parens.
10121 row: ROW '(' expr_list ')' { $$ = $3; }
10122 | ROW '(' ')' { $$ = NIL; }
10123 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
10126 sub_type: ANY { $$ = ANY_SUBLINK; }
10127 | SOME { $$ = ANY_SUBLINK; }
10128 | ALL { $$ = ALL_SUBLINK; }
10131 all_Op: Op { $$ = $1; }
10132 | MathOp { $$ = $1; }
10135 MathOp: '+' { $$ = "+"; }
10136 | '-' { $$ = "-"; }
10137 | '*' { $$ = "*"; }
10138 | '/' { $$ = "/"; }
10139 | '%' { $$ = "%"; }
10140 | '^' { $$ = "^"; }
10141 | '<' { $$ = "<"; }
10142 | '>' { $$ = ">"; }
10143 | '=' { $$ = "="; }
10147 { $$ = list_make1(makeString($1)); }
10148 | OPERATOR '(' any_operator ')'
10154 { $$ = list_make1(makeString($1)); }
10155 | OPERATOR '(' any_operator ')'
10161 { $$ = list_make1(makeString($1)); }
10162 | OPERATOR '(' any_operator ')'
10165 { $$ = list_make1(makeString("~~")); }
10167 { $$ = list_make1(makeString("!~~")); }
10169 { $$ = list_make1(makeString("~~*")); }
10171 { $$ = list_make1(makeString("!~~*")); }
10172 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
10173 * the regular expression is preprocessed by a function (similar_escape),
10174 * and the ~ operator for posix regular expressions is used.
10175 * x SIMILAR TO y -> x ~ similar_escape(y)
10176 * this transformation is made on the fly by the parser upwards.
10177 * however the SubLink structure which handles any/some/all stuff
10178 * is not ready for such a thing.
10184 $$ = list_make1($1);
10186 | expr_list ',' a_expr
10188 $$ = lappend($1, $3);
10192 /* function arguments can have names */
10193 func_arg_list: func_arg_expr
10195 $$ = list_make1($1);
10197 | func_arg_list ',' func_arg_expr
10199 $$ = lappend($1, $3);
10203 func_arg_expr: a_expr
10207 | a_expr AS param_name
10209 NamedArgExpr *na = makeNode(NamedArgExpr);
10210 na->arg = (Expr *) $1;
10212 na->argnumber = -1; /* until determined */
10218 type_list: Typename { $$ = list_make1($1); }
10219 | type_list ',' Typename { $$ = lappend($1, $3); }
10222 array_expr: '[' expr_list ']'
10224 $$ = makeAArrayExpr($2, @1);
10226 | '[' array_expr_list ']'
10228 $$ = makeAArrayExpr($2, @1);
10232 $$ = makeAArrayExpr(NIL, @1);
10236 array_expr_list: array_expr { $$ = list_make1($1); }
10237 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
10242 extract_arg FROM a_expr
10244 $$ = list_make2(makeStringConst($1, @1), $3);
10246 | /*EMPTY*/ { $$ = NIL; }
10249 /* Allow delimited string Sconst in extract_arg as an SQL extension.
10250 * - thomas 2001-04-12
10254 | YEAR_P { $$ = "year"; }
10255 | MONTH_P { $$ = "month"; }
10256 | DAY_P { $$ = "day"; }
10257 | HOUR_P { $$ = "hour"; }
10258 | MINUTE_P { $$ = "minute"; }
10259 | SECOND_P { $$ = "second"; }
10260 | Sconst { $$ = $1; }
10263 /* OVERLAY() arguments
10264 * SQL99 defines the OVERLAY() function:
10265 * o overlay(text placing text from int for int)
10266 * o overlay(text placing text from int)
10267 * and similarly for binary strings
10270 a_expr overlay_placing substr_from substr_for
10272 $$ = list_make4($1, $2, $3, $4);
10274 | a_expr overlay_placing substr_from
10276 $$ = list_make3($1, $2, $3);
10285 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
10288 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
10289 | /*EMPTY*/ { $$ = NIL; }
10292 /* SUBSTRING() arguments
10293 * SQL9x defines a specific syntax for arguments to SUBSTRING():
10294 * o substring(text from int for int)
10295 * o substring(text from int) get entire string from starting point "int"
10296 * o substring(text for int) get first "int" characters of string
10297 * o substring(text from pattern) get entire string matching pattern
10298 * o substring(text from pattern for escape) same with specified escape char
10299 * We also want to support generic substring functions which accept
10300 * the usual generic list of arguments. So we will accept both styles
10301 * here, and convert the SQL9x style to the generic list for further
10302 * processing. - thomas 2000-11-28
10305 a_expr substr_from substr_for
10307 $$ = list_make3($1, $2, $3);
10309 | a_expr substr_for substr_from
10311 /* not legal per SQL99, but might as well allow it */
10312 $$ = list_make3($1, $3, $2);
10314 | a_expr substr_from
10316 $$ = list_make2($1, $2);
10318 | a_expr substr_for
10321 * Since there are no cases where this syntax allows
10322 * a textual FOR value, we forcibly cast the argument
10323 * to int4. The possible matches in pg_proc are
10324 * substring(text,int4) and substring(text,text),
10325 * and we don't want the parser to choose the latter,
10326 * which it is likely to do if the second argument
10327 * is unknown or doesn't have an implicit cast to int4.
10329 $$ = list_make3($1, makeIntConst(1, -1),
10331 SystemTypeName("int4"), -1));
10342 FROM a_expr { $$ = $2; }
10345 substr_for: FOR a_expr { $$ = $2; }
10348 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
10349 | FROM expr_list { $$ = $2; }
10350 | expr_list { $$ = $1; }
10353 in_expr: select_with_parens
10355 SubLink *n = makeNode(SubLink);
10357 /* other fields will be filled later */
10360 | '(' expr_list ')' { $$ = (Node *)$2; }
10364 * Define SQL92-style case clause.
10365 * - Full specification
10366 * CASE WHEN a = b THEN c ... ELSE d END
10367 * - Implicit argument
10368 * CASE a WHEN b THEN c ... ELSE d END
10370 case_expr: CASE case_arg when_clause_list case_default END_P
10372 CaseExpr *c = makeNode(CaseExpr);
10373 c->casetype = InvalidOid; /* not analyzed yet */
10374 c->arg = (Expr *) $2;
10376 c->defresult = (Expr *) $4;
10383 /* There must be at least one */
10384 when_clause { $$ = list_make1($1); }
10385 | when_clause_list when_clause { $$ = lappend($1, $2); }
10389 WHEN a_expr THEN a_expr
10391 CaseWhen *w = makeNode(CaseWhen);
10392 w->expr = (Expr *) $2;
10393 w->result = (Expr *) $4;
10400 ELSE a_expr { $$ = $2; }
10401 | /*EMPTY*/ { $$ = NULL; }
10404 case_arg: a_expr { $$ = $1; }
10405 | /*EMPTY*/ { $$ = NULL; }
10410 $$ = makeColumnRef($1, NIL, @1, yyscanner);
10412 | ColId indirection
10414 $$ = makeColumnRef($1, $2, @1, yyscanner);
10421 $$ = (Node *) makeString($2);
10425 $$ = (Node *) makeNode(A_Star);
10429 A_Indices *ai = makeNode(A_Indices);
10434 | '[' a_expr ':' a_expr ']'
10436 A_Indices *ai = makeNode(A_Indices);
10444 indirection_el { $$ = list_make1($1); }
10445 | indirection indirection_el { $$ = lappend($1, $2); }
10449 /*EMPTY*/ { $$ = NIL; }
10450 | opt_indirection indirection_el { $$ = lappend($1, $2); }
10453 opt_asymmetric: ASYMMETRIC
10458 * The SQL spec defines "contextually typed value expressions" and
10459 * "contextually typed row value constructors", which for our purposes
10460 * are the same as "a_expr" and "row" except that DEFAULT can appear at
10465 a_expr { $$ = (Node *) $1; }
10468 SetToDefault *n = makeNode(SetToDefault);
10475 ctext_expr { $$ = list_make1($1); }
10476 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
10480 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
10481 * making VALUES a fully reserved word, which will probably break more apps
10482 * than allowing the noise-word is worth.
10484 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
10488 /*****************************************************************************
10490 * target list for SELECT
10492 *****************************************************************************/
10495 target_el { $$ = list_make1($1); }
10496 | target_list ',' target_el { $$ = lappend($1, $3); }
10499 target_el: a_expr AS ColLabel
10501 $$ = makeNode(ResTarget);
10503 $$->indirection = NIL;
10504 $$->val = (Node *)$1;
10508 * We support omitting AS only for column labels that aren't
10509 * any known keyword. There is an ambiguity against postfix
10510 * operators: is "a ! b" an infix expression, or a postfix
10511 * expression and a column label? We prefer to resolve this
10512 * as an infix expression, which we accomplish by assigning
10513 * IDENT a precedence higher than POSTFIXOP.
10517 $$ = makeNode(ResTarget);
10519 $$->indirection = NIL;
10520 $$->val = (Node *)$1;
10525 $$ = makeNode(ResTarget);
10527 $$->indirection = NIL;
10528 $$->val = (Node *)$1;
10533 ColumnRef *n = makeNode(ColumnRef);
10534 n->fields = list_make1(makeNode(A_Star));
10537 $$ = makeNode(ResTarget);
10539 $$->indirection = NIL;
10540 $$->val = (Node *)n;
10546 /*****************************************************************************
10548 * Names and constants
10550 *****************************************************************************/
10552 qualified_name_list:
10553 qualified_name { $$ = list_make1($1); }
10554 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
10558 * The production for a qualified relation name has to exactly match the
10559 * production for a qualified func_name, because in a FROM clause we cannot
10560 * tell which we are parsing until we see what comes after it ('(' for a
10561 * func_name, something else for a relation). Therefore we allow 'indirection'
10562 * which may contain subscripts, and reject that case in the C code.
10567 $$ = makeNode(RangeVar);
10568 $$->catalogname = NULL;
10569 $$->schemaname = NULL;
10573 | ColId indirection
10575 check_qualified_name($2, yyscanner);
10576 $$ = makeNode(RangeVar);
10577 switch (list_length($2))
10580 $$->catalogname = NULL;
10581 $$->schemaname = $1;
10582 $$->relname = strVal(linitial($2));
10585 $$->catalogname = $1;
10586 $$->schemaname = strVal(linitial($2));
10587 $$->relname = strVal(lsecond($2));
10591 (errcode(ERRCODE_SYNTAX_ERROR),
10592 errmsg("improper qualified name (too many dotted names): %s",
10593 NameListToString(lcons(makeString($1), $2))),
10594 parser_errposition(@1)));
10602 { $$ = list_make1(makeString($1)); }
10603 | name_list ',' name
10604 { $$ = lappend($1, makeString($3)); }
10608 name: ColId { $$ = $1; };
10611 ColId { $$ = $1; };
10614 ColId { $$ = $1; };
10616 attr_name: ColLabel { $$ = $1; };
10618 index_name: ColId { $$ = $1; };
10620 file_name: Sconst { $$ = $1; };
10623 * The production for a qualified func_name has to exactly match the
10624 * production for a qualified columnref, because we cannot tell which we
10625 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
10626 * anything else for a columnref). Therefore we allow 'indirection' which
10627 * may contain subscripts, and reject that case in the C code. (If we
10628 * ever implement SQL99-like methods, such syntax may actually become legal!)
10630 func_name: type_function_name
10631 { $$ = list_make1(makeString($1)); }
10632 | ColId indirection
10634 $$ = check_func_name(lcons(makeString($1), $2),
10645 $$ = makeIntConst($1, @1);
10649 $$ = makeFloatConst($1, @1);
10653 $$ = makeStringConst($1, @1);
10657 $$ = makeBitStringConst($1, @1);
10661 /* This is a bit constant per SQL99:
10662 * Without Feature F511, "BIT data type",
10663 * a <general literal> shall not be a
10664 * <bit string literal> or a <hex string literal>.
10666 $$ = makeBitStringConst($1, @1);
10670 /* generic type 'literal' syntax */
10671 TypeName *t = makeTypeNameFromNameList($1);
10673 $$ = makeStringConstCast($2, @2, t);
10675 | func_name '(' func_arg_list ')' Sconst
10677 /* generic syntax with a type modifier */
10678 TypeName *t = makeTypeNameFromNameList($1);
10682 * We must use func_arg_list in the production to avoid
10683 * reduce/reduce conflicts, but we don't actually wish
10684 * to allow NamedArgExpr in this context.
10688 NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
10690 if (IsA(arg, NamedArgExpr))
10692 (errcode(ERRCODE_SYNTAX_ERROR),
10693 errmsg("type modifier cannot have AS name"),
10694 parser_errposition(arg->location)));
10698 $$ = makeStringConstCast($5, @5, t);
10700 | ConstTypename Sconst
10702 $$ = makeStringConstCast($2, @2, $1);
10704 | ConstInterval Sconst opt_interval
10708 $$ = makeStringConstCast($2, @2, t);
10710 | ConstInterval '(' Iconst ')' Sconst opt_interval
10715 if (list_length($6) != 1)
10717 (errcode(ERRCODE_SYNTAX_ERROR),
10718 errmsg("interval precision specified twice"),
10719 parser_errposition(@1)));
10720 t->typmods = lappend($6, makeIntConst($3, @3));
10723 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
10724 makeIntConst($3, @3));
10725 $$ = makeStringConstCast($5, @5, t);
10729 $$ = makeBoolAConst(TRUE, @1);
10733 $$ = makeBoolAConst(FALSE, @1);
10737 $$ = makeNullAConst(@1);
10741 Iconst: ICONST { $$ = $1; };
10742 Sconst: SCONST { $$ = $1; };
10743 RoleId: ColId { $$ = $1; };
10745 SignedIconst: Iconst { $$ = $1; }
10746 | '+' Iconst { $$ = + $2; }
10747 | '-' Iconst { $$ = - $2; }
10750 Iconst_list: Iconst { $$ = list_make1(makeInteger($1)); }
10751 | Iconst_list ',' Iconst { $$ = lappend($1, makeInteger($3)); }
10755 * Name classification hierarchy.
10757 * IDENT is the lexeme returned by the lexer for identifiers that match
10758 * no known keyword. In most cases, we can accept certain keywords as
10759 * names, not only IDENTs. We prefer to accept as many such keywords
10760 * as possible to minimize the impact of "reserved words" on programmers.
10761 * So, we divide names into several possible classes. The classification
10762 * is chosen in part to make keywords acceptable as names wherever possible.
10765 /* Column identifier --- names that can be column, table, etc names.
10767 ColId: IDENT { $$ = $1; }
10768 | unreserved_keyword { $$ = pstrdup($1); }
10769 | col_name_keyword { $$ = pstrdup($1); }
10772 /* Type/function identifier --- names that can be type or function names.
10774 type_function_name: IDENT { $$ = $1; }
10775 | unreserved_keyword { $$ = pstrdup($1); }
10776 | type_func_name_keyword { $$ = pstrdup($1); }
10779 /* Column label --- allowed labels in "AS" clauses.
10780 * This presently includes *all* Postgres keywords.
10782 ColLabel: IDENT { $$ = $1; }
10783 | unreserved_keyword { $$ = pstrdup($1); }
10784 | col_name_keyword { $$ = pstrdup($1); }
10785 | type_func_name_keyword { $$ = pstrdup($1); }
10786 | reserved_keyword { $$ = pstrdup($1); }
10791 * Keyword category lists. Generally, every keyword present in
10792 * the Postgres grammar should appear in exactly one of these lists.
10794 * Put a new keyword into the first list that it can go into without causing
10795 * shift or reduce conflicts. The earlier lists define "less reserved"
10796 * categories of keywords.
10798 * Make sure that each keyword's category in keywords.c matches where
10799 * it is listed here. (Someday we may be able to generate these lists and
10800 * keywords.c's table from a common master list.)
10803 /* "Unreserved" keywords --- available for use as any kind of name.
10805 unreserved_keyword:
11058 /* Column identifier --- keywords that can be column, table, etc names.
11060 * Many of these keywords will in fact be recognized as type or function
11061 * names too; but they have special productions for the purpose, and so
11062 * can't be treated as "generic" type or function names.
11064 * The type names appearing here are not usable as function names
11065 * because they can be followed by '(' in typename productions, which
11066 * looks too much like a function call for an LR(1) parser.
11117 /* Type/function identifier --- keywords that can be type or function names.
11119 * Most of these are keywords that are used as operators in expressions;
11120 * in general such keywords can't be column names because they would be
11121 * ambiguous with variables, but they are unambiguous as function identifiers.
11123 * Do not include POSITION, SUBSTRING, etc here since they have explicit
11124 * productions in a_expr to support the goofy SQL9x argument syntax.
11125 * - thomas 2000-11-28
11127 type_func_name_keyword:
11152 /* Reserved keyword --- these keywords are usable only as a ColLabel.
11154 * Keywords appear here if they could not be distinguished from variable,
11155 * type, or function names in some contexts. Don't put things here unless
11180 | CURRENT_TIMESTAMP
11241 * The signature of this function is required by bison. However, we
11242 * ignore the passed yylloc and instead use the last token position
11243 * available from the scanner.
11246 base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
11248 parser_yyerror(msg);
11252 makeColumnRef(char *colname, List *indirection,
11253 int location, core_yyscan_t yyscanner)
11256 * Generate a ColumnRef node, with an A_Indirection node added if there
11257 * is any subscripting in the specified indirection list. However,
11258 * any field selection at the start of the indirection list must be
11259 * transposed into the "fields" part of the ColumnRef node.
11261 ColumnRef *c = makeNode(ColumnRef);
11265 c->location = location;
11266 foreach(l, indirection)
11268 if (IsA(lfirst(l), A_Indices))
11270 A_Indirection *i = makeNode(A_Indirection);
11274 /* easy case - all indirection goes to A_Indirection */
11275 c->fields = list_make1(makeString(colname));
11276 i->indirection = check_indirection(indirection, yyscanner);
11280 /* got to split the list in two */
11281 i->indirection = check_indirection(list_copy_tail(indirection,
11284 indirection = list_truncate(indirection, nfields);
11285 c->fields = lcons(makeString(colname), indirection);
11287 i->arg = (Node *) c;
11290 else if (IsA(lfirst(l), A_Star))
11292 /* We only allow '*' at the end of a ColumnRef */
11293 if (lnext(l) != NULL)
11294 parser_yyerror("improper use of \"*\"");
11298 /* No subscripting, so all indirection gets added to field list */
11299 c->fields = lcons(makeString(colname), indirection);
11304 makeTypeCast(Node *arg, TypeName *typename, int location)
11306 TypeCast *n = makeNode(TypeCast);
11308 n->typeName = typename;
11309 n->location = location;
11314 makeStringConst(char *str, int location)
11316 A_Const *n = makeNode(A_Const);
11318 n->val.type = T_String;
11319 n->val.val.str = str;
11320 n->location = location;
11326 makeStringConstCast(char *str, int location, TypeName *typename)
11328 Node *s = makeStringConst(str, location);
11330 return makeTypeCast(s, typename, -1);
11334 makeIntConst(int val, int location)
11336 A_Const *n = makeNode(A_Const);
11338 n->val.type = T_Integer;
11339 n->val.val.ival = val;
11340 n->location = location;
11346 makeFloatConst(char *str, int location)
11348 A_Const *n = makeNode(A_Const);
11350 n->val.type = T_Float;
11351 n->val.val.str = str;
11352 n->location = location;
11358 makeBitStringConst(char *str, int location)
11360 A_Const *n = makeNode(A_Const);
11362 n->val.type = T_BitString;
11363 n->val.val.str = str;
11364 n->location = location;
11370 makeNullAConst(int location)
11372 A_Const *n = makeNode(A_Const);
11374 n->val.type = T_Null;
11375 n->location = location;
11381 makeAConst(Value *v, int location)
11388 n = makeFloatConst(v->val.str, location);
11392 n = makeIntConst(v->val.ival, location);
11397 n = makeStringConst(v->val.str, location);
11404 /* makeBoolAConst()
11405 * Create an A_Const string node and put it inside a boolean cast.
11408 makeBoolAConst(bool state, int location)
11410 A_Const *n = makeNode(A_Const);
11412 n->val.type = T_String;
11413 n->val.val.str = (state ? "t" : "f");
11414 n->location = location;
11416 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
11420 * Create and populate a FuncCall node to support the OVERLAPS operator.
11423 makeOverlaps(List *largs, List *rargs, int location, core_yyscan_t yyscanner)
11425 FuncCall *n = makeNode(FuncCall);
11427 n->funcname = SystemFuncName("overlaps");
11428 if (list_length(largs) == 1)
11429 largs = lappend(largs, largs);
11430 else if (list_length(largs) != 2)
11432 (errcode(ERRCODE_SYNTAX_ERROR),
11433 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
11434 parser_errposition(location)));
11435 if (list_length(rargs) == 1)
11436 rargs = lappend(rargs, rargs);
11437 else if (list_length(rargs) != 2)
11439 (errcode(ERRCODE_SYNTAX_ERROR),
11440 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
11441 parser_errposition(location)));
11442 n->args = list_concat(largs, rargs);
11443 n->agg_order = NIL;
11444 n->agg_star = FALSE;
11445 n->agg_distinct = FALSE;
11446 n->func_variadic = FALSE;
11448 n->location = location;
11452 /* check_qualified_name --- check the result of qualified_name production
11454 * It's easiest to let the grammar production for qualified_name allow
11455 * subscripts and '*', which we then must reject here.
11458 check_qualified_name(List *names, core_yyscan_t yyscanner)
11464 if (!IsA(lfirst(i), String))
11465 parser_yyerror("syntax error");
11469 /* check_func_name --- check the result of func_name production
11471 * It's easiest to let the grammar production for func_name allow subscripts
11472 * and '*', which we then must reject here.
11475 check_func_name(List *names, core_yyscan_t yyscanner)
11481 if (!IsA(lfirst(i), String))
11482 parser_yyerror("syntax error");
11487 /* check_indirection --- check the result of indirection production
11489 * We only allow '*' at the end of the list, but it's hard to enforce that
11490 * in the grammar, so do it here.
11493 check_indirection(List *indirection, core_yyscan_t yyscanner)
11497 foreach(l, indirection)
11499 if (IsA(lfirst(l), A_Star))
11501 if (lnext(l) != NULL)
11502 parser_yyerror("improper use of \"*\"");
11505 return indirection;
11508 /* extractArgTypes()
11509 * Given a list of FunctionParameter nodes, extract a list of just the
11510 * argument types (TypeNames) for input parameters only. This is what
11511 * is needed to look up an existing function, which is what is wanted by
11512 * the productions that use this call.
11515 extractArgTypes(List *parameters)
11517 List *result = NIL;
11520 foreach(i, parameters)
11522 FunctionParameter *p = (FunctionParameter *) lfirst(i);
11524 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
11525 result = lappend(result, p->argType);
11530 /* findLeftmostSelect()
11531 * Find the leftmost component SelectStmt in a set-operation parsetree.
11533 static SelectStmt *
11534 findLeftmostSelect(SelectStmt *node)
11536 while (node && node->op != SETOP_NONE)
11538 Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
11542 /* insertSelectOptions()
11543 * Insert ORDER BY, etc into an already-constructed SelectStmt.
11545 * This routine is just to avoid duplicating code in SelectStmt productions.
11548 insertSelectOptions(SelectStmt *stmt,
11549 List *sortClause, List *lockingClause,
11550 Node *limitOffset, Node *limitCount,
11551 WithClause *withClause,
11552 core_yyscan_t yyscanner)
11554 Assert(IsA(stmt, SelectStmt));
11557 * Tests here are to reject constructs like
11558 * (SELECT foo ORDER BY bar) ORDER BY baz
11562 if (stmt->sortClause)
11564 (errcode(ERRCODE_SYNTAX_ERROR),
11565 errmsg("multiple ORDER BY clauses not allowed"),
11566 parser_errposition(exprLocation((Node *) sortClause))));
11567 stmt->sortClause = sortClause;
11569 /* We can handle multiple locking clauses, though */
11570 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
11573 if (stmt->limitOffset)
11575 (errcode(ERRCODE_SYNTAX_ERROR),
11576 errmsg("multiple OFFSET clauses not allowed"),
11577 parser_errposition(exprLocation(limitOffset))));
11578 stmt->limitOffset = limitOffset;
11582 if (stmt->limitCount)
11584 (errcode(ERRCODE_SYNTAX_ERROR),
11585 errmsg("multiple LIMIT clauses not allowed"),
11586 parser_errposition(exprLocation(limitCount))));
11587 stmt->limitCount = limitCount;
11591 if (stmt->withClause)
11593 (errcode(ERRCODE_SYNTAX_ERROR),
11594 errmsg("multiple WITH clauses not allowed"),
11595 parser_errposition(exprLocation((Node *) withClause))));
11596 stmt->withClause = withClause;
11601 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
11603 SelectStmt *n = makeNode(SelectStmt);
11607 n->larg = (SelectStmt *) larg;
11608 n->rarg = (SelectStmt *) rarg;
11612 /* SystemFuncName()
11613 * Build a properly-qualified reference to a built-in function.
11616 SystemFuncName(char *name)
11618 return list_make2(makeString("pg_catalog"), makeString(name));
11621 /* SystemTypeName()
11622 * Build a properly-qualified reference to a built-in type.
11624 * typmod is defaulted, but may be changed afterwards by caller.
11625 * Likewise for the location.
11628 SystemTypeName(char *name)
11630 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
11631 makeString(name)));
11635 * Handle negation of a numeric constant.
11637 * Formerly, we did this here because the optimizer couldn't cope with
11638 * indexquals that looked like "var = -4" --- it wants "var = const"
11639 * and a unary minus operator applied to a constant didn't qualify.
11640 * As of Postgres 7.0, that problem doesn't exist anymore because there
11641 * is a constant-subexpression simplifier in the optimizer. However,
11642 * there's still a good reason for doing this here, which is that we can
11643 * postpone committing to a particular internal representation for simple
11644 * negative constants. It's better to leave "-123.456" in string form
11645 * until we know what the desired type is.
11648 doNegate(Node *n, int location)
11650 if (IsA(n, A_Const))
11652 A_Const *con = (A_Const *)n;
11654 /* report the constant's location as that of the '-' sign */
11655 con->location = location;
11657 if (con->val.type == T_Integer)
11659 con->val.val.ival = -con->val.val.ival;
11662 if (con->val.type == T_Float)
11664 doNegateFloat(&con->val);
11669 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
11673 doNegateFloat(Value *v)
11675 char *oldval = v->val.str;
11677 Assert(IsA(v, Float));
11678 if (*oldval == '+')
11680 if (*oldval == '-')
11681 v->val.str = oldval+1; /* just strip the '-' */
11684 char *newval = (char *) palloc(strlen(oldval) + 2);
11687 strcpy(newval+1, oldval);
11688 v->val.str = newval;
11693 makeAArrayExpr(List *elements, int location)
11695 A_ArrayExpr *n = makeNode(A_ArrayExpr);
11697 n->elements = elements;
11698 n->location = location;
11703 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
11706 XmlExpr *x = makeNode(XmlExpr);
11711 * named_args is a list of ResTarget; it'll be split apart into separate
11712 * expression and name lists in transformXmlExpr().
11714 x->named_args = named_args;
11715 x->arg_names = NIL;
11717 /* xmloption, if relevant, must be filled in by caller */
11718 /* type and typmod will be filled in during parse analysis */
11719 x->location = location;
11724 * Initialize to parse one query string
11727 parser_init(base_yy_extra_type *yyext)
11729 yyext->parsetree = NIL; /* in case grammar forgets to set it */
11733 * Merge the input and output parameters of a table function.
11736 mergeTableFuncParameters(List *func_args, List *columns)
11740 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
11741 foreach(lc, func_args)
11743 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
11745 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
11747 (errcode(ERRCODE_SYNTAX_ERROR),
11748 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
11751 return list_concat(func_args, columns);
11755 * Determine return type of a TABLE function. A single result column
11756 * returns setof that column's type; otherwise return setof record.
11759 TableFuncTypeName(List *columns)
11763 if (list_length(columns) == 1)
11765 FunctionParameter *p = (FunctionParameter *) linitial(columns);
11767 result = (TypeName *) copyObject(p->argType);
11770 result = SystemTypeName("record");
11772 result->setof = true;
11778 * Must undefine this stuff before including scan.c, since it has different
11779 * definitions for these macros.