4 /*-------------------------------------------------------------------------
7 * POSTGRES SQL YACC rules/actions
9 * Portions Copyright (c) 1996-2008, 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.636 2008/11/12 15:50:20 meskes 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 "commands/defrem.h"
57 #include "nodes/makefuncs.h"
58 #include "nodes/nodeFuncs.h"
59 #include "parser/gramparse.h"
60 #include "storage/lmgr.h"
61 #include "utils/date.h"
62 #include "utils/datetime.h"
63 #include "utils/numeric.h"
64 #include "utils/xml.h"
67 /* Location tracking support --- simpler than bison's default */
68 #define YYLLOC_DEFAULT(Current, Rhs, N) \
71 (Current) = (Rhs)[1]; \
73 (Current) = (Rhs)[0]; \
77 * The %name-prefix option below will make bison call base_yylex, but we
78 * really want it to call filtered_base_yylex (see parser.c).
80 #define base_yylex filtered_base_yylex
83 * Bison doesn't allocate anything that needs to live across parser calls,
84 * so we can easily have it use palloc instead of malloc. This prevents
85 * memory leaks if we error out during parsing. Note this only works with
86 * bison >= 2.0. However, in bison 1.875 the default is to use alloca()
87 * if possible, so there's not really much problem anyhow, at least if
88 * you're building with gcc.
90 #define YYMALLOC palloc
93 extern List *parsetree; /* final parse result is delivered here */
95 static bool QueryIsRule = FALSE;
98 * If you need access to certain yacc-generated variables and find that
99 * they're static by default, uncomment the next line. (this is not a
102 /*#define __YYSCLASS*/
104 static Node *makeColumnRef(char *colname, List *indirection, int location);
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, int location);
115 static void check_qualified_name(List *names);
116 static List *check_func_name(List *names);
117 static List *check_indirection(List *indirection);
118 static List *extractArgTypes(List *parameters);
119 static SelectStmt *findLeftmostSelect(SelectStmt *node);
120 static void insertSelectOptions(SelectStmt *stmt,
121 List *sortClause, List *lockingClause,
122 Node *limitOffset, Node *limitCount,
123 WithClause *withClause);
124 static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
125 static Node *doNegate(Node *n, int location);
126 static void doNegateFloat(Value *v);
127 static Node *makeAArrayExpr(List *elements, int location);
128 static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
129 List *args, int location);
130 static List *mergeTableFuncParameters(List *func_args, List *columns);
131 static TypeName *TableFuncTypeName(List *columns);
135 %name-prefix="base_yy"
146 DropBehavior dbehavior;
147 OnCommitAction oncommit;
154 FunctionParameter *fun_param;
155 FunctionParameterMode fun_param_mode;
156 FuncWithArgs *funwithargs;
167 PrivTarget *privtarget;
170 VariableSetStmt *vsetstmt;
173 %type <node> stmt schema_stmt
174 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterGroupStmt
175 AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterTableStmt
176 AlterUserStmt AlterUserSetStmt AlterRoleStmt AlterRoleSetStmt
177 AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
178 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
179 CreateDomainStmt CreateGroupStmt CreateOpClassStmt
180 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
181 CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
182 CreateAssertStmt CreateTrigStmt CreateUserStmt CreateRoleStmt
183 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt
184 DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
185 DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
186 DropUserStmt DropdbStmt DropTableSpaceStmt ExplainStmt FetchStmt
187 GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
188 LockStmt NotifyStmt ExplainableStmt PreparableStmt
189 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
190 RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
191 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
192 SelectStmt TransactionStmt TruncateStmt
193 UnlistenStmt UpdateStmt VacuumStmt
194 VariableResetStmt VariableSetStmt VariableShowStmt
195 ViewStmt CheckPointStmt CreateConversionStmt
196 DeallocateStmt PrepareStmt ExecuteStmt
197 DropOwnedStmt ReassignOwnedStmt
198 AlterTSConfigurationStmt AlterTSDictionaryStmt
200 %type <node> select_no_parens select_with_parens select_clause
201 simple_select values_clause
203 %type <node> alter_column_default opclass_item opclass_drop alter_using
204 %type <ival> add_drop opt_asc_desc opt_nulls_order
206 %type <node> alter_table_cmd
207 %type <list> alter_table_cmds
209 %type <dbehavior> opt_drop_behavior
211 %type <list> createdb_opt_list alterdb_opt_list copy_opt_list
212 transaction_mode_list
213 %type <defelt> createdb_opt_item alterdb_opt_item copy_opt_item
214 transaction_mode_item
216 %type <ival> opt_lock lock_type cast_context
217 %type <boolean> opt_force opt_or_replace
218 opt_grant_grant_option opt_grant_admin_option
219 opt_nowait opt_if_exists opt_with_data
221 %type <list> OptRoleList
222 %type <defelt> OptRoleElem
224 %type <str> OptSchemaName
225 %type <list> OptSchemaEltList
227 %type <boolean> TriggerActionTime TriggerForSpec opt_trusted opt_restart_seqs
228 %type <str> opt_lancompiler
230 %type <str> TriggerEvents
231 %type <value> TriggerFuncArg
233 %type <str> relation_name copy_file_name
234 database_name access_method_clause access_method attr_name
235 index_name name file_name cluster_index_specification
237 %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
238 opt_class opt_validator
240 %type <range> qualified_name OptConstrFromTable
242 %type <str> all_Op MathOp SpecialRuleRelation
244 %type <str> iso_level opt_encoding
246 %type <list> grantee_list
247 %type <str> privilege
248 %type <list> privileges privilege_list
249 %type <privtarget> privilege_target
250 %type <funwithargs> function_with_argtypes
251 %type <list> function_with_argtypes_list
252 %type <chr> TriggerOneEvent
254 %type <list> stmtblock stmtmulti
255 OptTableElementList TableElementList OptInherit definition
256 OptWith opt_distinct opt_definition func_args func_args_list
257 func_as createfunc_opt_list alterfunc_opt_list
258 aggr_args old_aggr_definition old_aggr_list
259 oper_argtypes RuleActionList RuleActionMulti
260 opt_column_list columnList opt_name_list
261 sort_clause opt_sort_clause sortby_list index_params
262 name_list from_clause from_list opt_array_bounds
263 qualified_name_list any_name any_name_list
264 any_operator expr_list attrs
265 target_list insert_column_list set_target_list
266 set_clause_list set_clause multiple_set_clause
267 ctext_expr_list ctext_row def_list indirection opt_indirection
268 group_clause TriggerFuncArgs select_limit
269 opt_select_limit opclass_item_list opclass_drop_list
270 opt_opfamily transaction_mode_list_or_empty
271 TableFuncElementList opt_type_modifiers
273 execute_param_clause using_clause returning_clause
274 enum_val_list table_func_column_list
276 %type <range> OptTempTableName
277 %type <into> into_clause create_as_target
279 %type <defelt> createfunc_opt_item common_func_opt_item
280 %type <fun_param> func_arg table_func_column
281 %type <fun_param_mode> arg_class
282 %type <typnam> func_return func_type
284 %type <boolean> TriggerForType OptTemp
285 %type <oncommit> OnCommitOption
287 %type <node> for_locking_item
288 %type <list> for_locking_clause opt_for_locking_clause for_locking_items
289 %type <list> locked_rels_list
290 %type <boolean> opt_all
292 %type <node> join_outer join_qual
293 %type <jtype> join_type
295 %type <list> extract_list overlay_list position_list
296 %type <list> substr_list trim_list
297 %type <list> opt_interval interval_second
298 %type <node> overlay_placing substr_from substr_for
300 %type <boolean> opt_instead opt_analyze
301 %type <boolean> index_opt_unique opt_verbose opt_full
302 %type <boolean> opt_freeze opt_default opt_recheck
303 %type <defelt> opt_binary opt_oids copy_delimiter
305 %type <boolean> copy_from
307 %type <ival> opt_column event cursor_options opt_hold opt_set_data
308 %type <objtype> reindex_type drop_type comment_type
310 %type <node> fetch_direction select_limit_value select_offset_value
311 select_offset_value2 opt_select_fetch_first_value
312 %type <ival> row_or_rows first_or_next
314 %type <list> OptSeqOptList SeqOptList
315 %type <defelt> SeqOptElem
317 %type <istmt> insert_rest
319 %type <vsetstmt> set_rest SetResetClause
321 %type <node> TableElement ConstraintElem TableFuncElement
322 %type <node> columnDef
323 %type <defelt> def_elem old_aggr_elem
324 %type <node> def_arg columnElem where_clause where_or_current_clause
325 a_expr b_expr c_expr func_expr AexprConst indirection_el
326 columnref in_expr having_clause func_table array_expr
327 %type <list> row type_list array_expr_list
328 %type <node> case_expr case_arg when_clause case_default
329 %type <list> when_clause_list
330 %type <ival> sub_type
331 %type <list> OptCreateAs CreateAsList
332 %type <node> CreateAsElement ctext_expr
333 %type <value> NumericOnly FloatOnly IntegerOnly
334 %type <alias> alias_clause
335 %type <sortby> sortby
336 %type <ielem> index_elem
337 %type <node> table_ref
338 %type <jexpr> joined_table
339 %type <range> relation_expr
340 %type <range> relation_expr_opt_alias
341 %type <target> target_el single_set_clause set_target insert_column_item
343 %type <typnam> Typename SimpleTypename ConstTypename
344 GenericType Numeric opt_float
345 Character ConstCharacter
346 CharacterWithLength CharacterWithoutLength
347 ConstDatetime ConstInterval
348 Bit ConstBit BitWithLength BitWithoutLength
349 %type <str> character
350 %type <str> extract_arg
351 %type <str> opt_charset
352 %type <boolean> opt_varying opt_timezone
354 %type <ival> Iconst SignedIconst
355 %type <str> Sconst comment_text
356 %type <str> RoleId opt_granted_by opt_boolean ColId_or_Sconst
357 %type <list> var_list
358 %type <str> ColId ColLabel var_name type_function_name param_name
359 %type <node> var_value zone_value
361 %type <keyword> unreserved_keyword type_func_name_keyword
362 %type <keyword> col_name_keyword reserved_keyword
364 %type <node> TableConstraint TableLikeClause
365 %type <list> TableLikeOptionList
366 %type <ival> TableLikeOption
367 %type <list> ColQualList
368 %type <node> ColConstraint ColConstraintElem ConstraintAttr
369 %type <ival> key_actions key_delete key_match key_update key_action
370 %type <ival> ConstraintAttributeSpec ConstraintDeferrabilitySpec
373 %type <list> constraints_set_list
374 %type <boolean> constraints_set_mode
375 %type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
376 %type <list> opt_check_option
378 %type <target> xml_attribute_el
379 %type <list> xml_attribute_list xml_attributes
380 %type <node> xml_root_version opt_xml_root_standalone
381 %type <ival> document_or_content
382 %type <boolean> xml_whitespace_option
384 %type <node> common_table_expr
385 %type <with> with_clause
386 %type <list> cte_list
390 * If you make any token changes, update the keyword table in
391 * parser/keywords.c and add new keywords to the appropriate one of
392 * the reserved-or-not-so-reserved keyword lists, below; search
393 * this file for "Name classification hierarchy".
396 /* ordinary key words in alphabetical order */
397 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
398 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
399 ASSERTION ASSIGNMENT ASYMMETRIC AT AUTHORIZATION
401 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
404 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
405 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
406 CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT
407 COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
408 CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
409 CREATEROLE CREATEUSER CROSS CSV CTYPE CURRENT_P
410 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
411 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
413 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
414 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
415 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
417 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT EXCLUDING
418 EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
420 FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOR FORCE FOREIGN FORWARD
421 FREEZE FROM FULL FUNCTION
423 GLOBAL GRANT GRANTED GREATEST GROUP_P
425 HANDLER HAVING HEADER_P HOLD HOUR_P
427 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
428 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY
429 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
430 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
436 LANCOMPILER LANGUAGE LARGE_P LAST_P LEADING LEAST LEFT LEVEL
437 LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP LOCATION
440 MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
442 NAME_P NAMES NATIONAL NATURAL NCHAR NEW NEXT NO NOCREATEDB
443 NOCREATEROLE NOCREATEUSER NOINHERIT NOLOGIN_P NONE NOSUPERUSER
444 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NULLS_P NUMERIC
446 OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OR
447 ORDER OUT_P OUTER_P OVERLAPS OVERLAY OWNED OWNER
449 PARSER PARTIAL PASSWORD PLACING PLANS POSITION
450 PRECISION PRESERVE PREPARE PREPARED PRIMARY
451 PRIOR PRIVILEGES PROCEDURAL PROCEDURE
455 READ REAL REASSIGN RECHECK RECURSIVE REFERENCES REINDEX RELATIVE_P RELEASE
456 RENAME REPEATABLE REPLACE REPLICA RESET RESTART RESTRICT RETURNING RETURNS
457 REVOKE RIGHT ROLE ROLLBACK ROW ROWS RULE
459 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE
460 SERIALIZABLE SESSION SESSION_USER SET SETOF SHARE
461 SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT
462 STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING SUPERUSER_P
463 SYMMETRIC SYSID SYSTEM_P
465 TABLE TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
466 TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
467 TRUNCATE TRUSTED TYPE_P
469 UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
472 VACUUM VALID VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
473 VERBOSE VERSION_P VIEW VOLATILE
475 WHEN WHERE WHITESPACE_P WITH WITHOUT WORK WRITE
477 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLFOREST XMLPARSE
478 XMLPI XMLROOT XMLSERIALIZE
484 /* The grammar thinks these are keywords, but they are not in the keywords.c
485 * list and so can never be entered directly. The filter in parser.c
486 * creates these tokens when required.
488 %token NULLS_FIRST NULLS_LAST WITH_TIME
490 /* Special token types, not actually keywords - see the "lex" file */
491 %token <str> IDENT FCONST SCONST BCONST XCONST Op
492 %token <ival> ICONST PARAM
494 /* precedence: lowest to highest */
495 %nonassoc SET /* see relation_expr_opt_alias */
503 %nonassoc LIKE ILIKE SIMILAR
508 %left POSTFIXOP /* dummy for postfix Op rules */
509 %nonassoc IDENT /* to support target_el without AS */
510 %left Op OPERATOR /* multi-character ops and user-defined operators */
513 %nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN /* sets precedence for IS NULL, etc */
517 /* Unary Operators */
518 %left AT ZONE /* sets precedence for AT TIME ZONE */
525 * These might seem to be low-precedence, but actually they are not part
526 * of the arithmetic hierarchy at all in their use as JOIN operators.
527 * We make them high-precedence to support their use as function names.
528 * They wouldn't be given a precedence at all, were it not that we need
529 * left-associativity among the JOIN rules themselves.
531 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
532 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
533 %right PRESERVE STRIP_P
537 * Handle comment-only lines, and ;; SELECT * FROM pg_class ;;;
538 * psql already handles such cases, but other interfaces don't.
541 stmtblock: stmtmulti { parsetree = $1; }
544 /* the thrashing around here is to discard "empty" statements... */
545 stmtmulti: stmtmulti ';' stmt
547 $$ = lappend($1, $3);
561 | AlterDatabaseSetStmt
565 | AlterObjectSchemaStmt
571 | AlterTSConfigurationStmt
572 | AlterTSDictionaryStmt
585 | CreateConversionStmt
596 | CreateTableSpaceStmt
655 /*****************************************************************************
657 * Create a new Postgres DBMS role
659 *****************************************************************************/
662 CREATE ROLE RoleId opt_with OptRoleList
664 CreateRoleStmt *n = makeNode(CreateRoleStmt);
665 n->stmt_type = ROLESTMT_ROLE;
678 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
679 * for backwards compatibility). Note: the only option required by SQL99
680 * is "WITH ADMIN name".
683 OptRoleList OptRoleElem { $$ = lappend($1, $2); }
684 | /* EMPTY */ { $$ = NIL; }
690 $$ = makeDefElem("password",
691 (Node *)makeString($2));
695 $$ = makeDefElem("password", NULL);
697 | ENCRYPTED PASSWORD Sconst
699 $$ = makeDefElem("encryptedPassword",
700 (Node *)makeString($3));
702 | UNENCRYPTED PASSWORD Sconst
704 $$ = makeDefElem("unencryptedPassword",
705 (Node *)makeString($3));
709 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
713 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
717 $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE));
721 $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE));
725 $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
729 $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
733 $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE));
737 $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE));
741 /* For backwards compatibility, synonym for SUPERUSER */
742 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
746 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
750 $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE));
754 $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE));
756 | CONNECTION LIMIT SignedIconst
758 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3));
762 $$ = makeDefElem("validUntil", (Node *)makeString($3));
764 /* Supported but not documented for roles, for use by ALTER GROUP. */
767 $$ = makeDefElem("rolemembers", (Node *)$2);
769 /* The following are not supported by ALTER ROLE/USER/GROUP */
772 $$ = makeDefElem("sysid", (Node *)makeInteger($2));
776 $$ = makeDefElem("adminmembers", (Node *)$2);
780 $$ = makeDefElem("rolemembers", (Node *)$2);
782 | IN_P ROLE name_list
784 $$ = makeDefElem("addroleto", (Node *)$3);
786 | IN_P GROUP_P name_list
788 $$ = makeDefElem("addroleto", (Node *)$3);
793 /*****************************************************************************
795 * Create a new Postgres DBMS user (role with implied login ability)
797 *****************************************************************************/
800 CREATE USER RoleId opt_with OptRoleList
802 CreateRoleStmt *n = makeNode(CreateRoleStmt);
803 n->stmt_type = ROLESTMT_USER;
811 /*****************************************************************************
813 * Alter a postgresql DBMS role
815 *****************************************************************************/
818 ALTER ROLE RoleId opt_with OptRoleList
820 AlterRoleStmt *n = makeNode(AlterRoleStmt);
822 n->action = +1; /* add, if there are members */
829 ALTER ROLE RoleId SetResetClause
831 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
839 /*****************************************************************************
841 * Alter a postgresql DBMS user
843 *****************************************************************************/
846 ALTER USER RoleId opt_with OptRoleList
848 AlterRoleStmt *n = makeNode(AlterRoleStmt);
850 n->action = +1; /* add, if there are members */
858 ALTER USER RoleId SetResetClause
860 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
868 /*****************************************************************************
870 * Drop a postgresql DBMS role
872 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
873 * might own objects in multiple databases, there is presently no way to
874 * implement either cascading or restricting. Caveat DBA.
875 *****************************************************************************/
880 DropRoleStmt *n = makeNode(DropRoleStmt);
881 n->missing_ok = FALSE;
885 | DROP ROLE IF_P EXISTS name_list
887 DropRoleStmt *n = makeNode(DropRoleStmt);
888 n->missing_ok = TRUE;
894 /*****************************************************************************
896 * Drop a postgresql DBMS user
898 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
899 * might own objects in multiple databases, there is presently no way to
900 * implement either cascading or restricting. Caveat DBA.
901 *****************************************************************************/
906 DropRoleStmt *n = makeNode(DropRoleStmt);
907 n->missing_ok = FALSE;
911 | DROP USER IF_P EXISTS name_list
913 DropRoleStmt *n = makeNode(DropRoleStmt);
915 n->missing_ok = TRUE;
921 /*****************************************************************************
923 * Create a postgresql group (role without login ability)
925 *****************************************************************************/
928 CREATE GROUP_P RoleId opt_with OptRoleList
930 CreateRoleStmt *n = makeNode(CreateRoleStmt);
931 n->stmt_type = ROLESTMT_GROUP;
939 /*****************************************************************************
941 * Alter a postgresql group
943 *****************************************************************************/
946 ALTER GROUP_P RoleId add_drop USER name_list
948 AlterRoleStmt *n = makeNode(AlterRoleStmt);
951 n->options = list_make1(makeDefElem("rolemembers",
957 add_drop: ADD_P { $$ = +1; }
962 /*****************************************************************************
964 * Drop a postgresql group
966 * XXX see above notes about cascading DROP USER; groups have same problem.
967 *****************************************************************************/
970 DROP GROUP_P name_list
972 DropRoleStmt *n = makeNode(DropRoleStmt);
973 n->missing_ok = FALSE;
977 | DROP GROUP_P IF_P EXISTS name_list
979 DropRoleStmt *n = makeNode(DropRoleStmt);
980 n->missing_ok = TRUE;
987 /*****************************************************************************
989 * Manipulate a schema
991 *****************************************************************************/
994 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
996 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
997 /* One can omit the schema name or the authorization id. */
1006 | CREATE SCHEMA ColId OptSchemaEltList
1008 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1009 /* ...but not both */
1019 | /* EMPTY */ { $$ = NULL; }
1023 OptSchemaEltList schema_stmt { $$ = lappend($1, $2); }
1024 | /* EMPTY */ { $$ = NIL; }
1028 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1029 * statement (in addition to by themselves).
1041 /*****************************************************************************
1043 * Set PG internal variable
1044 * SET name TO 'var_value'
1045 * Include SQL92 syntax (thomas 1997-10-22):
1046 * SET TIME ZONE 'var_value'
1048 *****************************************************************************/
1053 VariableSetStmt *n = $2;
1054 n->is_local = false;
1057 | SET LOCAL set_rest
1059 VariableSetStmt *n = $3;
1063 | SET SESSION set_rest
1065 VariableSetStmt *n = $3;
1066 n->is_local = false;
1071 set_rest: /* Generic SET syntaxes: */
1072 var_name TO var_list
1074 VariableSetStmt *n = makeNode(VariableSetStmt);
1075 n->kind = VAR_SET_VALUE;
1080 | var_name '=' var_list
1082 VariableSetStmt *n = makeNode(VariableSetStmt);
1083 n->kind = VAR_SET_VALUE;
1088 | var_name TO DEFAULT
1090 VariableSetStmt *n = makeNode(VariableSetStmt);
1091 n->kind = VAR_SET_DEFAULT;
1095 | var_name '=' DEFAULT
1097 VariableSetStmt *n = makeNode(VariableSetStmt);
1098 n->kind = VAR_SET_DEFAULT;
1102 | var_name FROM CURRENT_P
1104 VariableSetStmt *n = makeNode(VariableSetStmt);
1105 n->kind = VAR_SET_CURRENT;
1109 /* Special syntaxes mandated by SQL standard: */
1110 | TIME ZONE zone_value
1112 VariableSetStmt *n = makeNode(VariableSetStmt);
1113 n->kind = VAR_SET_VALUE;
1114 n->name = "timezone";
1116 n->args = list_make1($3);
1118 n->kind = VAR_SET_DEFAULT;
1121 | TRANSACTION transaction_mode_list
1123 VariableSetStmt *n = makeNode(VariableSetStmt);
1124 n->kind = VAR_SET_MULTI;
1125 n->name = "TRANSACTION";
1129 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1131 VariableSetStmt *n = makeNode(VariableSetStmt);
1132 n->kind = VAR_SET_MULTI;
1133 n->name = "SESSION CHARACTERISTICS";
1140 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1141 errmsg("current database cannot be changed"),
1142 scanner_errposition(@2)));
1143 $$ = NULL; /*not reached*/
1147 VariableSetStmt *n = makeNode(VariableSetStmt);
1148 n->kind = VAR_SET_VALUE;
1149 n->name = "search_path";
1150 n->args = list_make1(makeStringConst($2, @2));
1153 | NAMES opt_encoding
1155 VariableSetStmt *n = makeNode(VariableSetStmt);
1156 n->kind = VAR_SET_VALUE;
1157 n->name = "client_encoding";
1159 n->args = list_make1(makeStringConst($2, @2));
1161 n->kind = VAR_SET_DEFAULT;
1164 | ROLE ColId_or_Sconst
1166 VariableSetStmt *n = makeNode(VariableSetStmt);
1167 n->kind = VAR_SET_VALUE;
1169 n->args = list_make1(makeStringConst($2, @2));
1172 | SESSION AUTHORIZATION ColId_or_Sconst
1174 VariableSetStmt *n = makeNode(VariableSetStmt);
1175 n->kind = VAR_SET_VALUE;
1176 n->name = "session_authorization";
1177 n->args = list_make1(makeStringConst($3, @3));
1180 | SESSION AUTHORIZATION DEFAULT
1182 VariableSetStmt *n = makeNode(VariableSetStmt);
1183 n->kind = VAR_SET_DEFAULT;
1184 n->name = "session_authorization";
1187 | XML_P OPTION document_or_content
1189 VariableSetStmt *n = makeNode(VariableSetStmt);
1190 n->kind = VAR_SET_VALUE;
1191 n->name = "xmloption";
1192 n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1197 var_name: ColId { $$ = $1; }
1198 | var_name '.' ColId
1200 $$ = palloc(strlen($1) + strlen($3) + 2);
1201 sprintf($$, "%s.%s", $1, $3);
1205 var_list: var_value { $$ = list_make1($1); }
1206 | var_list ',' var_value { $$ = lappend($1, $3); }
1209 var_value: opt_boolean
1210 { $$ = makeStringConst($1, @1); }
1212 { $$ = makeStringConst($1, @1); }
1214 { $$ = makeAConst($1, @1); }
1217 iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1218 | READ COMMITTED { $$ = "read committed"; }
1219 | REPEATABLE READ { $$ = "repeatable read"; }
1220 | SERIALIZABLE { $$ = "serializable"; }
1224 TRUE_P { $$ = "true"; }
1225 | FALSE_P { $$ = "false"; }
1227 | OFF { $$ = "off"; }
1230 /* Timezone values can be:
1231 * - a string such as 'pst8pdt'
1232 * - an identifier such as "pst8pdt"
1233 * - an integer or floating point number
1234 * - a time interval per SQL99
1235 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1236 * so use IDENT and reject anything which is a reserved word.
1241 $$ = makeStringConst($1, @1);
1245 $$ = makeStringConst($1, @1);
1247 | ConstInterval Sconst opt_interval
1252 A_Const *n = (A_Const *) linitial($3);
1253 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1255 (errcode(ERRCODE_SYNTAX_ERROR),
1256 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1257 scanner_errposition(@3)));
1260 $$ = makeStringConstCast($2, @2, t);
1262 | ConstInterval '(' Iconst ')' Sconst opt_interval
1267 A_Const *n = (A_Const *) linitial($6);
1268 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1270 (errcode(ERRCODE_SYNTAX_ERROR),
1271 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1272 scanner_errposition(@6)));
1273 if (list_length($6) != 1)
1275 (errcode(ERRCODE_SYNTAX_ERROR),
1276 errmsg("interval precision specified twice"),
1277 scanner_errposition(@1)));
1278 t->typmods = lappend($6, makeIntConst($3, @3));
1281 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1282 makeIntConst($3, @3));
1283 $$ = makeStringConstCast($5, @5, t);
1285 | NumericOnly { $$ = makeAConst($1, @1); }
1286 | DEFAULT { $$ = NULL; }
1287 | LOCAL { $$ = NULL; }
1292 | DEFAULT { $$ = NULL; }
1293 | /*EMPTY*/ { $$ = NULL; }
1298 | Sconst { $$ = $1; }
1304 VariableSetStmt *n = makeNode(VariableSetStmt);
1305 n->kind = VAR_RESET;
1311 VariableSetStmt *n = makeNode(VariableSetStmt);
1312 n->kind = VAR_RESET;
1313 n->name = "timezone";
1316 | RESET TRANSACTION ISOLATION LEVEL
1318 VariableSetStmt *n = makeNode(VariableSetStmt);
1319 n->kind = VAR_RESET;
1320 n->name = "transaction_isolation";
1323 | RESET SESSION AUTHORIZATION
1325 VariableSetStmt *n = makeNode(VariableSetStmt);
1326 n->kind = VAR_RESET;
1327 n->name = "session_authorization";
1332 VariableSetStmt *n = makeNode(VariableSetStmt);
1333 n->kind = VAR_RESET_ALL;
1338 /* SetResetClause allows SET or RESET without LOCAL */
1340 SET set_rest { $$ = $2; }
1341 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1348 VariableShowStmt *n = makeNode(VariableShowStmt);
1354 VariableShowStmt *n = makeNode(VariableShowStmt);
1355 n->name = "timezone";
1358 | SHOW TRANSACTION ISOLATION LEVEL
1360 VariableShowStmt *n = makeNode(VariableShowStmt);
1361 n->name = "transaction_isolation";
1364 | SHOW SESSION AUTHORIZATION
1366 VariableShowStmt *n = makeNode(VariableShowStmt);
1367 n->name = "session_authorization";
1372 VariableShowStmt *n = makeNode(VariableShowStmt);
1380 SET CONSTRAINTS constraints_set_list constraints_set_mode
1382 ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
1383 n->constraints = $3;
1389 constraints_set_list:
1391 | qualified_name_list { $$ = $1; }
1394 constraints_set_mode:
1395 DEFERRED { $$ = TRUE; }
1396 | IMMEDIATE { $$ = FALSE; }
1401 * Checkpoint statement
1406 CheckPointStmt *n = makeNode(CheckPointStmt);
1412 /*****************************************************************************
1414 * DISCARD { ALL | TEMP | PLANS }
1416 *****************************************************************************/
1421 DiscardStmt *n = makeNode(DiscardStmt);
1422 n->target = DISCARD_ALL;
1427 DiscardStmt *n = makeNode(DiscardStmt);
1428 n->target = DISCARD_TEMP;
1433 DiscardStmt *n = makeNode(DiscardStmt);
1434 n->target = DISCARD_TEMP;
1439 DiscardStmt *n = makeNode(DiscardStmt);
1440 n->target = DISCARD_PLANS;
1446 /*****************************************************************************
1448 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations
1450 * Note: we accept all subcommands for each of the four variants, and sort
1451 * out what's really legal at execution time.
1452 *****************************************************************************/
1455 ALTER TABLE relation_expr alter_table_cmds
1457 AlterTableStmt *n = makeNode(AlterTableStmt);
1460 n->relkind = OBJECT_TABLE;
1463 | ALTER INDEX relation_expr alter_table_cmds
1465 AlterTableStmt *n = makeNode(AlterTableStmt);
1468 n->relkind = OBJECT_INDEX;
1471 | ALTER SEQUENCE relation_expr alter_table_cmds
1473 AlterTableStmt *n = makeNode(AlterTableStmt);
1476 n->relkind = OBJECT_SEQUENCE;
1479 | ALTER VIEW relation_expr alter_table_cmds
1481 AlterTableStmt *n = makeNode(AlterTableStmt);
1484 n->relkind = OBJECT_VIEW;
1490 alter_table_cmd { $$ = list_make1($1); }
1491 | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
1495 /* ALTER TABLE <name> ADD [COLUMN] <coldef> */
1496 ADD_P opt_column columnDef
1498 AlterTableCmd *n = makeNode(AlterTableCmd);
1499 n->subtype = AT_AddColumn;
1503 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1504 | ALTER opt_column ColId alter_column_default
1506 AlterTableCmd *n = makeNode(AlterTableCmd);
1507 n->subtype = AT_ColumnDefault;
1512 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1513 | ALTER opt_column ColId DROP NOT NULL_P
1515 AlterTableCmd *n = makeNode(AlterTableCmd);
1516 n->subtype = AT_DropNotNull;
1520 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1521 | ALTER opt_column ColId SET NOT NULL_P
1523 AlterTableCmd *n = makeNode(AlterTableCmd);
1524 n->subtype = AT_SetNotNull;
1528 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <IntegerOnly> */
1529 | ALTER opt_column ColId SET STATISTICS IntegerOnly
1531 AlterTableCmd *n = makeNode(AlterTableCmd);
1532 n->subtype = AT_SetStatistics;
1534 n->def = (Node *) $6;
1537 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1538 | ALTER opt_column ColId SET STORAGE ColId
1540 AlterTableCmd *n = makeNode(AlterTableCmd);
1541 n->subtype = AT_SetStorage;
1543 n->def = (Node *) makeString($6);
1546 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1547 | DROP opt_column ColId opt_drop_behavior
1549 AlterTableCmd *n = makeNode(AlterTableCmd);
1550 n->subtype = AT_DropColumn;
1556 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
1557 * [ USING <expression> ]
1559 | ALTER opt_column ColId opt_set_data TYPE_P Typename alter_using
1561 AlterTableCmd *n = makeNode(AlterTableCmd);
1562 n->subtype = AT_AlterColumnType;
1564 n->def = (Node *) $6;
1568 /* ALTER TABLE <name> ADD CONSTRAINT ... */
1569 | ADD_P TableConstraint
1571 AlterTableCmd *n = makeNode(AlterTableCmd);
1572 n->subtype = AT_AddConstraint;
1576 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1577 | DROP CONSTRAINT name opt_drop_behavior
1579 AlterTableCmd *n = makeNode(AlterTableCmd);
1580 n->subtype = AT_DropConstraint;
1585 /* ALTER TABLE <name> SET WITHOUT OIDS */
1588 AlterTableCmd *n = makeNode(AlterTableCmd);
1589 n->subtype = AT_DropOids;
1592 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1595 AlterTableCmd *n = makeNode(AlterTableCmd);
1596 n->subtype = AT_ClusterOn;
1600 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1601 | SET WITHOUT CLUSTER
1603 AlterTableCmd *n = makeNode(AlterTableCmd);
1604 n->subtype = AT_DropCluster;
1608 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
1609 | ENABLE_P TRIGGER name
1611 AlterTableCmd *n = makeNode(AlterTableCmd);
1612 n->subtype = AT_EnableTrig;
1616 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
1617 | ENABLE_P ALWAYS TRIGGER name
1619 AlterTableCmd *n = makeNode(AlterTableCmd);
1620 n->subtype = AT_EnableAlwaysTrig;
1624 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
1625 | ENABLE_P REPLICA TRIGGER name
1627 AlterTableCmd *n = makeNode(AlterTableCmd);
1628 n->subtype = AT_EnableReplicaTrig;
1632 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
1633 | ENABLE_P TRIGGER ALL
1635 AlterTableCmd *n = makeNode(AlterTableCmd);
1636 n->subtype = AT_EnableTrigAll;
1639 /* ALTER TABLE <name> ENABLE TRIGGER USER */
1640 | ENABLE_P TRIGGER USER
1642 AlterTableCmd *n = makeNode(AlterTableCmd);
1643 n->subtype = AT_EnableTrigUser;
1646 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
1647 | DISABLE_P TRIGGER name
1649 AlterTableCmd *n = makeNode(AlterTableCmd);
1650 n->subtype = AT_DisableTrig;
1654 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
1655 | DISABLE_P TRIGGER ALL
1657 AlterTableCmd *n = makeNode(AlterTableCmd);
1658 n->subtype = AT_DisableTrigAll;
1661 /* ALTER TABLE <name> DISABLE TRIGGER USER */
1662 | DISABLE_P TRIGGER USER
1664 AlterTableCmd *n = makeNode(AlterTableCmd);
1665 n->subtype = AT_DisableTrigUser;
1668 /* ALTER TABLE <name> ENABLE RULE <rule> */
1669 | ENABLE_P RULE name
1671 AlterTableCmd *n = makeNode(AlterTableCmd);
1672 n->subtype = AT_EnableRule;
1676 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
1677 | ENABLE_P ALWAYS RULE name
1679 AlterTableCmd *n = makeNode(AlterTableCmd);
1680 n->subtype = AT_EnableAlwaysRule;
1684 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
1685 | ENABLE_P REPLICA RULE name
1687 AlterTableCmd *n = makeNode(AlterTableCmd);
1688 n->subtype = AT_EnableReplicaRule;
1692 /* ALTER TABLE <name> DISABLE RULE <rule> */
1693 | DISABLE_P RULE name
1695 AlterTableCmd *n = makeNode(AlterTableCmd);
1696 n->subtype = AT_DisableRule;
1700 /* ALTER TABLE <name> INHERIT <parent> */
1701 | INHERIT qualified_name
1703 AlterTableCmd *n = makeNode(AlterTableCmd);
1704 n->subtype = AT_AddInherit;
1705 n->def = (Node *) $2;
1708 /* ALTER TABLE <name> NO INHERIT <parent> */
1709 | NO INHERIT qualified_name
1711 AlterTableCmd *n = makeNode(AlterTableCmd);
1712 n->subtype = AT_DropInherit;
1713 n->def = (Node *) $3;
1716 /* ALTER TABLE <name> OWNER TO RoleId */
1719 AlterTableCmd *n = makeNode(AlterTableCmd);
1720 n->subtype = AT_ChangeOwner;
1724 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1725 | SET TABLESPACE name
1727 AlterTableCmd *n = makeNode(AlterTableCmd);
1728 n->subtype = AT_SetTableSpace;
1732 /* ALTER TABLE <name> SET (...) */
1735 AlterTableCmd *n = makeNode(AlterTableCmd);
1736 n->subtype = AT_SetRelOptions;
1737 n->def = (Node *)$2;
1740 /* ALTER TABLE <name> RESET (...) */
1743 AlterTableCmd *n = makeNode(AlterTableCmd);
1744 n->subtype = AT_ResetRelOptions;
1745 n->def = (Node *)$2;
1750 alter_column_default:
1751 SET DEFAULT a_expr { $$ = $3; }
1752 | DROP DEFAULT { $$ = NULL; }
1756 CASCADE { $$ = DROP_CASCADE; }
1757 | RESTRICT { $$ = DROP_RESTRICT; }
1758 | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1762 USING a_expr { $$ = $2; }
1763 | /* EMPTY */ { $$ = NULL; }
1768 /*****************************************************************************
1771 * close <portalname>
1773 *****************************************************************************/
1778 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1784 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1785 n->portalname = NULL;
1791 /*****************************************************************************
1794 * COPY relname ['(' columnList ')'] FROM/TO file [WITH options]
1796 * BINARY, OIDS, and DELIMITERS kept in old locations
1797 * for backward compatibility. 2002-06-18
1799 * COPY ( SELECT ... ) TO file [WITH options]
1800 * This form doesn't have the backwards-compatible option
1803 *****************************************************************************/
1805 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
1806 copy_from copy_file_name copy_delimiter opt_with copy_opt_list
1808 CopyStmt *n = makeNode(CopyStmt);
1816 /* Concatenate user-supplied flags */
1818 n->options = lappend(n->options, $2);
1820 n->options = lappend(n->options, $5);
1822 n->options = lappend(n->options, $8);
1824 n->options = list_concat(n->options, $10);
1827 | COPY select_with_parens TO copy_file_name opt_with
1830 CopyStmt *n = makeNode(CopyStmt);
1843 | TO { $$ = FALSE; }
1847 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
1848 * used depends on the direction. (It really doesn't make sense to copy from
1849 * stdout. We silently correct the "typo".) - AY 9/94
1853 | STDIN { $$ = NULL; }
1854 | STDOUT { $$ = NULL; }
1860 copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
1861 | /* EMPTY */ { $$ = NIL; }
1868 $$ = makeDefElem("binary", (Node *)makeInteger(TRUE));
1872 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
1874 | DELIMITER opt_as Sconst
1876 $$ = makeDefElem("delimiter", (Node *)makeString($3));
1878 | NULL_P opt_as Sconst
1880 $$ = makeDefElem("null", (Node *)makeString($3));
1884 $$ = makeDefElem("csv", (Node *)makeInteger(TRUE));
1888 $$ = makeDefElem("header", (Node *)makeInteger(TRUE));
1890 | QUOTE opt_as Sconst
1892 $$ = makeDefElem("quote", (Node *)makeString($3));
1894 | ESCAPE opt_as Sconst
1896 $$ = makeDefElem("escape", (Node *)makeString($3));
1898 | FORCE QUOTE columnList
1900 $$ = makeDefElem("force_quote", (Node *)$3);
1902 | FORCE NOT NULL_P columnList
1904 $$ = makeDefElem("force_notnull", (Node *)$4);
1908 /* The following exist for backward compatibility */
1913 $$ = makeDefElem("binary", (Node *)makeInteger(TRUE));
1915 | /*EMPTY*/ { $$ = NULL; }
1921 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
1923 | /*EMPTY*/ { $$ = NULL; }
1927 /* USING DELIMITERS kept for backward compatibility. 2002-06-15 */
1928 opt_using DELIMITERS Sconst
1930 $$ = makeDefElem("delimiter", (Node *)makeString($3));
1932 | /*EMPTY*/ { $$ = NULL; }
1941 /*****************************************************************************
1944 * CREATE TABLE relname
1946 *****************************************************************************/
1948 CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
1949 OptInherit OptWith OnCommitOption OptTableSpace
1951 CreateStmt *n = makeNode(CreateStmt);
1955 n->inhRelations = $8;
1956 n->constraints = NIL;
1959 n->tablespacename = $11;
1962 | CREATE OptTemp TABLE qualified_name OF qualified_name
1963 '(' OptTableElementList ')' OptWith OnCommitOption OptTableSpace
1965 /* SQL99 CREATE TABLE OF <UDT> (cols) seems to be satisfied
1966 * by our inheritance capabilities. Let's try it...
1968 CreateStmt *n = makeNode(CreateStmt);
1972 n->inhRelations = list_make1($6);
1973 n->constraints = NIL;
1976 n->tablespacename = $12;
1982 * Redundancy here is needed to avoid shift/reduce conflicts,
1983 * since TEMP is not a reserved word. See also OptTempTableName.
1985 * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
1986 * the LOCAL keyword is really meaningless.
1988 OptTemp: TEMPORARY { $$ = TRUE; }
1989 | TEMP { $$ = TRUE; }
1990 | LOCAL TEMPORARY { $$ = TRUE; }
1991 | LOCAL TEMP { $$ = TRUE; }
1992 | GLOBAL TEMPORARY { $$ = TRUE; }
1993 | GLOBAL TEMP { $$ = TRUE; }
1994 | /*EMPTY*/ { $$ = FALSE; }
1997 OptTableElementList:
1998 TableElementList { $$ = $1; }
1999 | /*EMPTY*/ { $$ = NIL; }
2005 $$ = list_make1($1);
2007 | TableElementList ',' TableElement
2009 $$ = lappend($1, $3);
2014 columnDef { $$ = $1; }
2015 | TableLikeClause { $$ = $1; }
2016 | TableConstraint { $$ = $1; }
2019 columnDef: ColId Typename ColQualList
2021 ColumnDef *n = makeNode(ColumnDef);
2024 n->constraints = $3;
2031 ColQualList ColConstraint { $$ = lappend($1, $2); }
2032 | /*EMPTY*/ { $$ = NIL; }
2036 CONSTRAINT name ColConstraintElem
2038 switch (nodeTag($3))
2042 Constraint *n = (Constraint *)$3;
2046 case T_FkConstraint:
2048 FkConstraint *n = (FkConstraint *)$3;
2049 n->constr_name = $2;
2057 | ColConstraintElem { $$ = $1; }
2058 | ConstraintAttr { $$ = $1; }
2061 /* DEFAULT NULL is already the default for Postgres.
2062 * But define it here and carry it forward into the system
2063 * to make it explicit.
2064 * - thomas 1998-09-13
2066 * WITH NULL and NULL are not SQL92-standard syntax elements,
2067 * so leave them out. Use DEFAULT NULL to explicitly indicate
2068 * that a column may have that value. WITH NULL leads to
2069 * shift/reduce conflicts with WITH TIME ZONE anyway.
2070 * - thomas 1999-01-08
2072 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
2073 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
2074 * or be part of a_expr NOT LIKE or similar constructs).
2079 Constraint *n = makeNode(Constraint);
2080 n->contype = CONSTR_NOTNULL;
2083 n->cooked_expr = NULL;
2085 n->indexspace = NULL;
2090 Constraint *n = makeNode(Constraint);
2091 n->contype = CONSTR_NULL;
2094 n->cooked_expr = NULL;
2096 n->indexspace = NULL;
2099 | UNIQUE opt_definition OptConsTableSpace
2101 Constraint *n = makeNode(Constraint);
2102 n->contype = CONSTR_UNIQUE;
2105 n->cooked_expr = NULL;
2111 | PRIMARY KEY opt_definition OptConsTableSpace
2113 Constraint *n = makeNode(Constraint);
2114 n->contype = CONSTR_PRIMARY;
2117 n->cooked_expr = NULL;
2123 | CHECK '(' a_expr ')'
2125 Constraint *n = makeNode(Constraint);
2126 n->contype = CONSTR_CHECK;
2129 n->cooked_expr = NULL;
2131 n->indexspace = NULL;
2136 Constraint *n = makeNode(Constraint);
2137 n->contype = CONSTR_DEFAULT;
2140 n->cooked_expr = NULL;
2142 n->indexspace = NULL;
2145 | REFERENCES qualified_name opt_column_list key_match key_actions
2147 FkConstraint *n = makeNode(FkConstraint);
2148 n->constr_name = NULL;
2152 n->fk_matchtype = $4;
2153 n->fk_upd_action = (char) ($5 >> 8);
2154 n->fk_del_action = (char) ($5 & 0xFF);
2155 n->deferrable = FALSE;
2156 n->initdeferred = FALSE;
2162 * ConstraintAttr represents constraint attributes, which we parse as if
2163 * they were independent constraint clauses, in order to avoid shift/reduce
2164 * conflicts (since NOT might start either an independent NOT NULL clause
2165 * or an attribute). parse_utilcmd.c is responsible for attaching the
2166 * attribute information to the preceding "real" constraint node, and for
2167 * complaining if attribute clauses appear in the wrong place or wrong
2170 * See also ConstraintAttributeSpec, which can be used in places where
2171 * there is no parsing conflict.
2176 Constraint *n = makeNode(Constraint);
2177 n->contype = CONSTR_ATTR_DEFERRABLE;
2182 Constraint *n = makeNode(Constraint);
2183 n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
2186 | INITIALLY DEFERRED
2188 Constraint *n = makeNode(Constraint);
2189 n->contype = CONSTR_ATTR_DEFERRED;
2192 | INITIALLY IMMEDIATE
2194 Constraint *n = makeNode(Constraint);
2195 n->contype = CONSTR_ATTR_IMMEDIATE;
2202 * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2203 * This seems to be a poor man's inheritance capability, with the resulting
2204 * tables completely decoupled except for the original commonality in definitions.
2206 * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2207 * which is a part of SQL:2003.
2210 LIKE qualified_name TableLikeOptionList
2212 InhRelation *n = makeNode(InhRelation);
2219 TableLikeOptionList:
2220 TableLikeOptionList TableLikeOption { $$ = lappend_int($1, $2); }
2221 | /* EMPTY */ { $$ = NIL; }
2225 INCLUDING DEFAULTS { $$ = CREATE_TABLE_LIKE_INCLUDING_DEFAULTS; }
2226 | EXCLUDING DEFAULTS { $$ = CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS; }
2227 | INCLUDING CONSTRAINTS { $$ = CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS; }
2228 | EXCLUDING CONSTRAINTS { $$ = CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS; }
2229 | INCLUDING INDEXES { $$ = CREATE_TABLE_LIKE_INCLUDING_INDEXES; }
2230 | EXCLUDING INDEXES { $$ = CREATE_TABLE_LIKE_EXCLUDING_INDEXES; }
2234 /* ConstraintElem specifies constraint syntax which is not embedded into
2235 * a column definition. ColConstraintElem specifies the embedded form.
2236 * - thomas 1997-12-03
2239 CONSTRAINT name ConstraintElem
2241 switch (nodeTag($3))
2245 Constraint *n = (Constraint *)$3;
2249 case T_FkConstraint:
2251 FkConstraint *n = (FkConstraint *)$3;
2252 n->constr_name = $2;
2260 | ConstraintElem { $$ = $1; }
2264 CHECK '(' a_expr ')'
2266 Constraint *n = makeNode(Constraint);
2267 n->contype = CONSTR_CHECK;
2270 n->cooked_expr = NULL;
2271 n->indexspace = NULL;
2274 | UNIQUE '(' columnList ')' opt_definition OptConsTableSpace
2276 Constraint *n = makeNode(Constraint);
2277 n->contype = CONSTR_UNIQUE;
2280 n->cooked_expr = NULL;
2286 | PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace
2288 Constraint *n = makeNode(Constraint);
2289 n->contype = CONSTR_PRIMARY;
2292 n->cooked_expr = NULL;
2298 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
2299 opt_column_list key_match key_actions ConstraintAttributeSpec
2301 FkConstraint *n = makeNode(FkConstraint);
2302 n->constr_name = NULL;
2306 n->fk_matchtype = $9;
2307 n->fk_upd_action = (char) ($10 >> 8);
2308 n->fk_del_action = (char) ($10 & 0xFF);
2309 n->deferrable = ($11 & 1) != 0;
2310 n->initdeferred = ($11 & 2) != 0;
2316 '(' columnList ')' { $$ = $2; }
2317 | /*EMPTY*/ { $$ = NIL; }
2321 columnElem { $$ = list_make1($1); }
2322 | columnList ',' columnElem { $$ = lappend($1, $3); }
2327 $$ = (Node *) makeString($1);
2331 key_match: MATCH FULL
2333 $$ = FKCONSTR_MATCH_FULL;
2338 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2339 errmsg("MATCH PARTIAL not yet implemented"),
2340 scanner_errposition(@1)));
2341 $$ = FKCONSTR_MATCH_PARTIAL;
2345 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2349 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2354 * We combine the update and delete actions into one value temporarily
2355 * for simplicity of parsing, and then break them down again in the
2356 * calling production. update is in the left 8 bits, delete in the right.
2357 * Note that NOACTION is the default.
2361 { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2363 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
2364 | key_update key_delete
2365 { $$ = ($1 << 8) | ($2 & 0xFF); }
2366 | key_delete key_update
2367 { $$ = ($2 << 8) | ($1 & 0xFF); }
2369 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2372 key_update: ON UPDATE key_action { $$ = $3; }
2375 key_delete: ON DELETE_P key_action { $$ = $3; }
2379 NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; }
2380 | RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; }
2381 | CASCADE { $$ = FKCONSTR_ACTION_CASCADE; }
2382 | SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; }
2383 | SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; }
2386 OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
2387 | /*EMPTY*/ { $$ = NIL; }
2390 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
2392 WITH definition { $$ = $2; }
2393 | WITH OIDS { $$ = list_make1(defWithOids(true)); }
2394 | WITHOUT OIDS { $$ = list_make1(defWithOids(false)); }
2395 | /*EMPTY*/ { $$ = NIL; }
2398 OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
2399 | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
2400 | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
2401 | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
2404 OptTableSpace: TABLESPACE name { $$ = $2; }
2405 | /*EMPTY*/ { $$ = NULL; }
2408 OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
2409 | /*EMPTY*/ { $$ = NULL; }
2414 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
2419 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
2422 * When the SelectStmt is a set-operation tree, we must
2423 * stuff the INTO information into the leftmost component
2424 * Select, because that's where analyze.c will expect
2425 * to find it. Similarly, the output column names must
2426 * be attached to that Select's target list.
2428 SelectStmt *n = findLeftmostSelect((SelectStmt *) $6);
2429 if (n->intoClause != NULL)
2431 (errcode(ERRCODE_SYNTAX_ERROR),
2432 errmsg("CREATE TABLE AS cannot specify INTO"),
2433 scanner_errposition(exprLocation((Node *) n->intoClause))));
2434 $4->rel->istemp = $2;
2436 /* Implement WITH NO DATA by forcing top-level LIMIT 0 */
2438 ((SelectStmt *) $6)->limitCount = makeIntConst(0, -1);
2444 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
2446 $$ = makeNode(IntoClause);
2451 $$->tableSpaceName = $5;
2456 '(' CreateAsList ')' { $$ = $2; }
2457 | /*EMPTY*/ { $$ = NIL; }
2461 CreateAsElement { $$ = list_make1($1); }
2462 | CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); }
2468 ColumnDef *n = makeNode(ColumnDef);
2473 n->is_not_null = false;
2474 n->raw_default = NULL;
2475 n->cooked_default = NULL;
2476 n->constraints = NIL;
2482 WITH DATA_P { $$ = TRUE; }
2483 | WITH NO DATA_P { $$ = FALSE; }
2484 | /*EMPTY*/ { $$ = TRUE; }
2488 /*****************************************************************************
2491 * CREATE SEQUENCE seqname
2492 * ALTER SEQUENCE seqname
2494 *****************************************************************************/
2497 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
2499 CreateSeqStmt *n = makeNode(CreateSeqStmt);
2508 ALTER SEQUENCE relation_expr SeqOptList
2510 AlterSeqStmt *n = makeNode(AlterSeqStmt);
2517 OptSeqOptList: SeqOptList { $$ = $1; }
2518 | /*EMPTY*/ { $$ = NIL; }
2521 SeqOptList: SeqOptElem { $$ = list_make1($1); }
2522 | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
2525 SeqOptElem: CACHE NumericOnly
2527 $$ = makeDefElem("cache", (Node *)$2);
2531 $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE));
2535 $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE));
2537 | INCREMENT opt_by NumericOnly
2539 $$ = makeDefElem("increment", (Node *)$3);
2541 | MAXVALUE NumericOnly
2543 $$ = makeDefElem("maxvalue", (Node *)$2);
2545 | MINVALUE NumericOnly
2547 $$ = makeDefElem("minvalue", (Node *)$2);
2551 $$ = makeDefElem("maxvalue", NULL);
2555 $$ = makeDefElem("minvalue", NULL);
2559 $$ = makeDefElem("owned_by", (Node *)$3);
2561 | START opt_with NumericOnly
2563 $$ = makeDefElem("start", (Node *)$3);
2567 $$ = makeDefElem("restart", NULL);
2569 | RESTART opt_with NumericOnly
2571 $$ = makeDefElem("restart", (Node *)$3);
2580 FloatOnly { $$ = $1; }
2581 | IntegerOnly { $$ = $1; }
2584 FloatOnly: FCONST { $$ = makeFloat($1); }
2592 IntegerOnly: SignedIconst { $$ = makeInteger($1); };
2595 /*****************************************************************************
2598 * CREATE PROCEDURAL LANGUAGE ...
2599 * DROP PROCEDURAL LANGUAGE ...
2601 *****************************************************************************/
2604 CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2606 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2608 /* parameters are all to be supplied by system */
2610 n->plvalidator = NIL;
2611 n->pltrusted = false;
2614 | CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2615 HANDLER handler_name opt_validator opt_lancompiler
2617 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2620 n->plvalidator = $8;
2622 /* LANCOMPILER is now ignored entirely */
2628 TRUSTED { $$ = TRUE; }
2629 | /*EMPTY*/ { $$ = FALSE; }
2632 /* This ought to be just func_name, but that causes reduce/reduce conflicts
2633 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
2634 * Work around by using simple names, instead.
2637 name { $$ = list_make1(makeString($1)); }
2638 | name attrs { $$ = lcons(makeString($1), $2); }
2642 VALIDATOR handler_name { $$ = $2; }
2643 | /*EMPTY*/ { $$ = NIL; }
2647 LANCOMPILER Sconst { $$ = $2; }
2648 | /*EMPTY*/ { $$ = NULL; }
2652 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
2654 DropPLangStmt *n = makeNode(DropPLangStmt);
2657 n->missing_ok = false;
2660 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
2662 DropPLangStmt *n = makeNode(DropPLangStmt);
2665 n->missing_ok = true;
2675 /*****************************************************************************
2678 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
2680 *****************************************************************************/
2682 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
2684 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
2685 n->tablespacename = $3;
2692 OptTableSpaceOwner: OWNER name { $$ = $2; }
2693 | /*EMPTY */ { $$ = NULL; }
2696 /*****************************************************************************
2699 * DROP TABLESPACE <tablespace>
2701 * No need for drop behaviour as we cannot implement dependencies for
2702 * objects in other databases; we can only support RESTRICT.
2704 ****************************************************************************/
2706 DropTableSpaceStmt: DROP TABLESPACE name
2708 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2709 n->tablespacename = $3;
2710 n->missing_ok = false;
2713 | DROP TABLESPACE IF_P EXISTS name
2715 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2716 n->tablespacename = $5;
2717 n->missing_ok = true;
2722 /*****************************************************************************
2725 * CREATE TRIGGER ...
2728 *****************************************************************************/
2731 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
2732 qualified_name TriggerForSpec EXECUTE PROCEDURE
2733 func_name '(' TriggerFuncArgs ')'
2735 CreateTrigStmt *n = makeNode(CreateTrigStmt);
2742 memcpy(n->actions, $5, 4);
2743 n->isconstraint = FALSE;
2744 n->deferrable = FALSE;
2745 n->initdeferred = FALSE;
2746 n->constrrel = NULL;
2749 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
2750 qualified_name OptConstrFromTable
2751 ConstraintAttributeSpec
2752 FOR EACH ROW EXECUTE PROCEDURE
2753 func_name '(' TriggerFuncArgs ')'
2755 CreateTrigStmt *n = makeNode(CreateTrigStmt);
2762 memcpy(n->actions, $6, 4);
2763 n->isconstraint = TRUE;
2764 n->deferrable = ($10 & 1) != 0;
2765 n->initdeferred = ($10 & 2) != 0;
2773 BEFORE { $$ = TRUE; }
2774 | AFTER { $$ = FALSE; }
2780 char *e = palloc(4);
2781 e[0] = $1; e[1] = '\0';
2784 | TriggerOneEvent OR TriggerOneEvent
2786 char *e = palloc(4);
2787 e[0] = $1; e[1] = $3; e[2] = '\0';
2790 | TriggerOneEvent OR TriggerOneEvent OR TriggerOneEvent
2792 char *e = palloc(4);
2793 e[0] = $1; e[1] = $3; e[2] = $5; e[3] = '\0';
2799 INSERT { $$ = 'i'; }
2800 | DELETE_P { $$ = 'd'; }
2801 | UPDATE { $$ = 'u'; }
2802 | TRUNCATE { $$ = 't'; }
2806 FOR TriggerForOpt TriggerForType
2813 * If ROW/STATEMENT not specified, default to
2814 * STATEMENT, per SQL
2827 | STATEMENT { $$ = FALSE; }
2831 TriggerFuncArg { $$ = list_make1($1); }
2832 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
2833 | /*EMPTY*/ { $$ = NIL; }
2840 snprintf(buf, sizeof(buf), "%d", $1);
2841 $$ = makeString(pstrdup(buf));
2843 | FCONST { $$ = makeString($1); }
2844 | Sconst { $$ = makeString($1); }
2845 | BCONST { $$ = makeString($1); }
2846 | XCONST { $$ = makeString($1); }
2847 | ColId { $$ = makeString($1); }
2851 FROM qualified_name { $$ = $2; }
2852 | /*EMPTY*/ { $$ = NULL; }
2855 ConstraintAttributeSpec:
2856 ConstraintDeferrabilitySpec
2858 | ConstraintDeferrabilitySpec ConstraintTimeSpec
2860 if ($1 == 0 && $2 != 0)
2862 (errcode(ERRCODE_SYNTAX_ERROR),
2863 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
2864 scanner_errposition(@1)));
2867 | ConstraintTimeSpec
2874 | ConstraintTimeSpec ConstraintDeferrabilitySpec
2876 if ($2 == 0 && $1 != 0)
2878 (errcode(ERRCODE_SYNTAX_ERROR),
2879 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
2880 scanner_errposition(@1)));
2887 ConstraintDeferrabilitySpec:
2888 NOT DEFERRABLE { $$ = 0; }
2889 | DEFERRABLE { $$ = 1; }
2893 INITIALLY IMMEDIATE { $$ = 0; }
2894 | INITIALLY DEFERRED { $$ = 2; }
2899 DROP TRIGGER name ON qualified_name opt_drop_behavior
2901 DropPropertyStmt *n = makeNode(DropPropertyStmt);
2905 n->removeType = OBJECT_TRIGGER;
2906 n->missing_ok = false;
2909 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
2911 DropPropertyStmt *n = makeNode(DropPropertyStmt);
2915 n->removeType = OBJECT_TRIGGER;
2916 n->missing_ok = true;
2922 /*****************************************************************************
2925 * CREATE ASSERTION ...
2926 * DROP ASSERTION ...
2928 *****************************************************************************/
2931 CREATE ASSERTION name CHECK '(' a_expr ')'
2932 ConstraintAttributeSpec
2934 CreateTrigStmt *n = makeNode(CreateTrigStmt);
2936 n->args = list_make1($6);
2937 n->isconstraint = TRUE;
2938 n->deferrable = ($8 & 1) != 0;
2939 n->initdeferred = ($8 & 2) != 0;
2942 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2943 errmsg("CREATE ASSERTION is not yet implemented")));
2950 DROP ASSERTION name opt_drop_behavior
2952 DropPropertyStmt *n = makeNode(DropPropertyStmt);
2956 n->removeType = OBJECT_TRIGGER; /* XXX */
2958 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2959 errmsg("DROP ASSERTION is not yet implemented")));
2965 /*****************************************************************************
2968 * define (aggregate,operator,type)
2970 *****************************************************************************/
2973 CREATE AGGREGATE func_name aggr_args definition
2975 DefineStmt *n = makeNode(DefineStmt);
2976 n->kind = OBJECT_AGGREGATE;
2977 n->oldstyle = false;
2983 | CREATE AGGREGATE func_name old_aggr_definition
2985 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
2986 DefineStmt *n = makeNode(DefineStmt);
2987 n->kind = OBJECT_AGGREGATE;
2994 | CREATE OPERATOR any_operator definition
2996 DefineStmt *n = makeNode(DefineStmt);
2997 n->kind = OBJECT_OPERATOR;
2998 n->oldstyle = false;
3004 | CREATE TYPE_P any_name definition
3006 DefineStmt *n = makeNode(DefineStmt);
3007 n->kind = OBJECT_TYPE;
3008 n->oldstyle = false;
3014 | CREATE TYPE_P any_name
3016 /* Shell type (identified by lack of definition) */
3017 DefineStmt *n = makeNode(DefineStmt);
3018 n->kind = OBJECT_TYPE;
3019 n->oldstyle = false;
3022 n->definition = NIL;
3025 | CREATE TYPE_P any_name AS '(' TableFuncElementList ')'
3027 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
3028 RangeVar *r = makeNode(RangeVar);
3030 /* can't use qualified_name, sigh */
3031 switch (list_length($3))
3034 r->catalogname = NULL;
3035 r->schemaname = NULL;
3036 r->relname = strVal(linitial($3));
3039 r->catalogname = NULL;
3040 r->schemaname = strVal(linitial($3));
3041 r->relname = strVal(lsecond($3));
3044 r->catalogname = strVal(linitial($3));
3045 r->schemaname = strVal(lsecond($3));
3046 r->relname = strVal(lthird($3));
3050 (errcode(ERRCODE_SYNTAX_ERROR),
3051 errmsg("improper qualified name (too many dotted names): %s",
3052 NameListToString($3)),
3053 scanner_errposition(@3)));
3061 | CREATE TYPE_P any_name AS ENUM_P '(' enum_val_list ')'
3063 CreateEnumStmt *n = makeNode(CreateEnumStmt);
3068 | CREATE TEXT_P SEARCH PARSER any_name definition
3070 DefineStmt *n = makeNode(DefineStmt);
3071 n->kind = OBJECT_TSPARSER;
3077 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
3079 DefineStmt *n = makeNode(DefineStmt);
3080 n->kind = OBJECT_TSDICTIONARY;
3086 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
3088 DefineStmt *n = makeNode(DefineStmt);
3089 n->kind = OBJECT_TSTEMPLATE;
3095 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
3097 DefineStmt *n = makeNode(DefineStmt);
3098 n->kind = OBJECT_TSCONFIGURATION;
3106 definition: '(' def_list ')' { $$ = $2; }
3109 def_list: def_elem { $$ = list_make1($1); }
3110 | def_list ',' def_elem { $$ = lappend($1, $3); }
3113 def_elem: ColLabel '=' def_arg
3115 $$ = makeDefElem($1, (Node *)$3);
3119 $$ = makeDefElem($1, NULL);
3123 /* Note: any simple identifier will be returned as a type name! */
3124 def_arg: func_type { $$ = (Node *)$1; }
3125 | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
3126 | qual_all_Op { $$ = (Node *)$1; }
3127 | NumericOnly { $$ = (Node *)$1; }
3128 | Sconst { $$ = (Node *)makeString($1); }
3131 aggr_args: '(' type_list ')' { $$ = $2; }
3132 | '(' '*' ')' { $$ = NIL; }
3135 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
3138 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
3139 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
3142 old_aggr_elem: IDENT '=' def_arg
3144 $$ = makeDefElem($1, (Node *)$3);
3148 enum_val_list: Sconst
3149 { $$ = list_make1(makeString($1)); }
3150 | enum_val_list ',' Sconst
3151 { $$ = lappend($1, makeString($3)); }
3155 /*****************************************************************************
3158 * CREATE OPERATOR CLASS ...
3159 * CREATE OPERATOR FAMILY ...
3160 * ALTER OPERATOR FAMILY ...
3161 * DROP OPERATOR CLASS ...
3162 * DROP OPERATOR FAMILY ...
3164 *****************************************************************************/
3167 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
3168 USING access_method opt_opfamily AS opclass_item_list
3170 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
3171 n->opclassname = $4;
3175 n->opfamilyname = $11;
3182 opclass_item { $$ = list_make1($1); }
3183 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
3187 OPERATOR Iconst any_operator opt_recheck
3189 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3190 n->itemtype = OPCLASS_ITEM_OPERATOR;
3196 | OPERATOR Iconst any_operator oper_argtypes opt_recheck
3198 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3199 n->itemtype = OPCLASS_ITEM_OPERATOR;
3205 | FUNCTION Iconst func_name func_args
3207 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3208 n->itemtype = OPCLASS_ITEM_FUNCTION;
3210 n->args = extractArgTypes($4);
3214 | FUNCTION Iconst '(' type_list ')' func_name func_args
3216 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3217 n->itemtype = OPCLASS_ITEM_FUNCTION;
3219 n->args = extractArgTypes($7);
3226 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3227 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
3233 opt_default: DEFAULT { $$ = TRUE; }
3234 | /*EMPTY*/ { $$ = FALSE; }
3237 opt_opfamily: FAMILY any_name { $$ = $2; }
3238 | /*EMPTY*/ { $$ = NIL; }
3241 opt_recheck: RECHECK
3244 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3245 errmsg("RECHECK is no longer supported"),
3246 errhint("Update your data type."),
3247 scanner_errposition(@1)));
3250 | /*EMPTY*/ { $$ = FALSE; }
3255 CREATE OPERATOR FAMILY any_name USING access_method
3257 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
3258 n->opfamilyname = $4;
3265 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
3267 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3268 n->opfamilyname = $4;
3274 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
3276 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3277 n->opfamilyname = $4;
3286 opclass_drop { $$ = list_make1($1); }
3287 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
3291 OPERATOR Iconst '(' type_list ')'
3293 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3294 n->itemtype = OPCLASS_ITEM_OPERATOR;
3299 | FUNCTION Iconst '(' type_list ')'
3301 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3302 n->itemtype = OPCLASS_ITEM_FUNCTION;
3311 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
3313 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3314 n->opclassname = $4;
3317 n->missing_ok = false;
3320 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
3322 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3323 n->opclassname = $6;
3326 n->missing_ok = true;
3332 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
3334 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3335 n->opfamilyname = $4;
3338 n->missing_ok = false;
3341 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
3343 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3344 n->opfamilyname = $6;
3347 n->missing_ok = true;
3353 /*****************************************************************************
3357 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
3358 * REASSIGN OWNED BY username [, username ...] TO username
3360 *****************************************************************************/
3362 DROP OWNED BY name_list opt_drop_behavior
3364 DropOwnedStmt *n = makeNode(DropOwnedStmt);
3372 REASSIGN OWNED BY name_list TO name
3374 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
3381 /*****************************************************************************
3385 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
3386 * [ RESTRICT | CASCADE ]
3388 *****************************************************************************/
3390 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
3392 DropStmt *n = makeNode(DropStmt);
3394 n->missing_ok = TRUE;
3399 | DROP drop_type any_name_list opt_drop_behavior
3401 DropStmt *n = makeNode(DropStmt);
3403 n->missing_ok = FALSE;
3411 drop_type: TABLE { $$ = OBJECT_TABLE; }
3412 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
3413 | VIEW { $$ = OBJECT_VIEW; }
3414 | INDEX { $$ = OBJECT_INDEX; }
3415 | TYPE_P { $$ = OBJECT_TYPE; }
3416 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
3417 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
3418 | SCHEMA { $$ = OBJECT_SCHEMA; }
3419 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
3420 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
3421 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
3422 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
3426 any_name { $$ = list_make1($1); }
3427 | any_name_list ',' any_name { $$ = lappend($1, $3); }
3430 any_name: ColId { $$ = list_make1(makeString($1)); }
3431 | ColId attrs { $$ = lcons(makeString($1), $2); }
3434 attrs: '.' attr_name
3435 { $$ = list_make1(makeString($2)); }
3436 | attrs '.' attr_name
3437 { $$ = lappend($1, makeString($3)); }
3441 /*****************************************************************************
3444 * truncate table relname1, relname2, ...
3446 *****************************************************************************/
3449 TRUNCATE opt_table qualified_name_list opt_restart_seqs opt_drop_behavior
3451 TruncateStmt *n = makeNode(TruncateStmt);
3453 n->restart_seqs = $4;
3460 CONTINUE_P IDENTITY_P { $$ = false; }
3461 | RESTART IDENTITY_P { $$ = true; }
3462 | /* EMPTY */ { $$ = false; }
3465 /*****************************************************************************
3467 * The COMMENT ON statement can take different forms based upon the type of
3468 * the object associated with the comment. The form of the statement is:
3470 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
3471 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
3472 * CAST | COLUMN | SCHEMA | TABLESPACE | ROLE |
3473 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
3474 * TEXT SEARCH TEMPLATE |
3475 * TEXT SEARCH CONFIGURATION ] <objname> |
3476 * AGGREGATE <aggname> (arg1, ...) |
3477 * FUNCTION <funcname> (arg1, arg2, ...) |
3478 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
3479 * TRIGGER <triggername> ON <relname> |
3480 * CONSTRAINT <constraintname> ON <relname> |
3481 * RULE <rulename> ON <relname> ]
3484 *****************************************************************************/
3487 COMMENT ON comment_type any_name IS comment_text
3489 CommentStmt *n = makeNode(CommentStmt);
3496 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
3498 CommentStmt *n = makeNode(CommentStmt);
3499 n->objtype = OBJECT_AGGREGATE;
3505 | COMMENT ON FUNCTION func_name func_args IS comment_text
3507 CommentStmt *n = makeNode(CommentStmt);
3508 n->objtype = OBJECT_FUNCTION;
3510 n->objargs = extractArgTypes($5);
3514 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
3516 CommentStmt *n = makeNode(CommentStmt);
3517 n->objtype = OBJECT_OPERATOR;
3523 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
3525 CommentStmt *n = makeNode(CommentStmt);
3526 n->objtype = OBJECT_CONSTRAINT;
3527 n->objname = lappend($6, makeString($4));
3532 | COMMENT ON RULE name ON any_name IS comment_text
3534 CommentStmt *n = makeNode(CommentStmt);
3535 n->objtype = OBJECT_RULE;
3536 n->objname = lappend($6, makeString($4));
3541 | COMMENT ON RULE name IS comment_text
3543 /* Obsolete syntax supported for awhile for compatibility */
3544 CommentStmt *n = makeNode(CommentStmt);
3545 n->objtype = OBJECT_RULE;
3546 n->objname = list_make1(makeString($4));
3551 | COMMENT ON TRIGGER name ON any_name IS comment_text
3553 CommentStmt *n = makeNode(CommentStmt);
3554 n->objtype = OBJECT_TRIGGER;
3555 n->objname = lappend($6, makeString($4));
3560 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
3562 CommentStmt *n = makeNode(CommentStmt);
3563 n->objtype = OBJECT_OPCLASS;
3565 n->objargs = list_make1(makeString($7));
3569 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
3571 CommentStmt *n = makeNode(CommentStmt);
3572 n->objtype = OBJECT_OPFAMILY;
3574 n->objargs = list_make1(makeString($7));
3578 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
3580 CommentStmt *n = makeNode(CommentStmt);
3581 n->objtype = OBJECT_LARGEOBJECT;
3582 n->objname = list_make1($5);
3587 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
3589 CommentStmt *n = makeNode(CommentStmt);
3590 n->objtype = OBJECT_CAST;
3591 n->objname = list_make1($5);
3592 n->objargs = list_make1($7);
3596 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
3598 CommentStmt *n = makeNode(CommentStmt);
3599 n->objtype = OBJECT_LANGUAGE;
3605 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
3607 CommentStmt *n = makeNode(CommentStmt);
3608 n->objtype = OBJECT_TSPARSER;
3613 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
3615 CommentStmt *n = makeNode(CommentStmt);
3616 n->objtype = OBJECT_TSDICTIONARY;
3621 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
3623 CommentStmt *n = makeNode(CommentStmt);
3624 n->objtype = OBJECT_TSTEMPLATE;
3629 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
3631 CommentStmt *n = makeNode(CommentStmt);
3632 n->objtype = OBJECT_TSCONFIGURATION;
3640 COLUMN { $$ = OBJECT_COLUMN; }
3641 | DATABASE { $$ = OBJECT_DATABASE; }
3642 | SCHEMA { $$ = OBJECT_SCHEMA; }
3643 | INDEX { $$ = OBJECT_INDEX; }
3644 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
3645 | TABLE { $$ = OBJECT_TABLE; }
3646 | DOMAIN_P { $$ = OBJECT_TYPE; }
3647 | TYPE_P { $$ = OBJECT_TYPE; }
3648 | VIEW { $$ = OBJECT_VIEW; }
3649 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
3650 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
3651 | ROLE { $$ = OBJECT_ROLE; }
3656 | NULL_P { $$ = NULL; }
3659 /*****************************************************************************
3664 *****************************************************************************/
3666 FetchStmt: FETCH fetch_direction from_in name
3668 FetchStmt *n = (FetchStmt *) $2;
3675 FetchStmt *n = makeNode(FetchStmt);
3676 n->direction = FETCH_FORWARD;
3682 | MOVE fetch_direction from_in name
3684 FetchStmt *n = (FetchStmt *) $2;
3691 FetchStmt *n = makeNode(FetchStmt);
3692 n->direction = FETCH_FORWARD;
3703 FetchStmt *n = makeNode(FetchStmt);
3704 n->direction = FETCH_FORWARD;
3710 FetchStmt *n = makeNode(FetchStmt);
3711 n->direction = FETCH_FORWARD;
3717 FetchStmt *n = makeNode(FetchStmt);
3718 n->direction = FETCH_BACKWARD;
3724 FetchStmt *n = makeNode(FetchStmt);
3725 n->direction = FETCH_ABSOLUTE;
3731 FetchStmt *n = makeNode(FetchStmt);
3732 n->direction = FETCH_ABSOLUTE;
3736 | ABSOLUTE_P SignedIconst
3738 FetchStmt *n = makeNode(FetchStmt);
3739 n->direction = FETCH_ABSOLUTE;
3743 | RELATIVE_P SignedIconst
3745 FetchStmt *n = makeNode(FetchStmt);
3746 n->direction = FETCH_RELATIVE;
3752 FetchStmt *n = makeNode(FetchStmt);
3753 n->direction = FETCH_FORWARD;
3759 FetchStmt *n = makeNode(FetchStmt);
3760 n->direction = FETCH_FORWARD;
3761 n->howMany = FETCH_ALL;
3766 FetchStmt *n = makeNode(FetchStmt);
3767 n->direction = FETCH_FORWARD;
3771 | FORWARD SignedIconst
3773 FetchStmt *n = makeNode(FetchStmt);
3774 n->direction = FETCH_FORWARD;
3780 FetchStmt *n = makeNode(FetchStmt);
3781 n->direction = FETCH_FORWARD;
3782 n->howMany = FETCH_ALL;
3787 FetchStmt *n = makeNode(FetchStmt);
3788 n->direction = FETCH_BACKWARD;
3792 | BACKWARD SignedIconst
3794 FetchStmt *n = makeNode(FetchStmt);
3795 n->direction = FETCH_BACKWARD;
3801 FetchStmt *n = makeNode(FetchStmt);
3802 n->direction = FETCH_BACKWARD;
3803 n->howMany = FETCH_ALL;
3813 /*****************************************************************************
3815 * GRANT and REVOKE statements
3817 *****************************************************************************/
3819 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
3820 opt_grant_grant_option
3822 GrantStmt *n = makeNode(GrantStmt);
3825 n->objtype = ($4)->objtype;
3826 n->objects = ($4)->objs;
3828 n->grant_option = $7;
3834 REVOKE privileges ON privilege_target
3835 FROM grantee_list opt_drop_behavior
3837 GrantStmt *n = makeNode(GrantStmt);
3838 n->is_grant = false;
3839 n->grant_option = false;
3841 n->objtype = ($4)->objtype;
3842 n->objects = ($4)->objs;
3847 | REVOKE GRANT OPTION FOR privileges ON privilege_target
3848 FROM grantee_list opt_drop_behavior
3850 GrantStmt *n = makeNode(GrantStmt);
3851 n->is_grant = false;
3852 n->grant_option = true;
3854 n->objtype = ($7)->objtype;
3855 n->objects = ($7)->objs;
3864 * A privilege list is represented as a list of strings; the validity of
3865 * the privilege names gets checked at execution. This is a bit annoying
3866 * but we have little choice because of the syntactic conflict with lists
3867 * of role names in GRANT/REVOKE. What's more, we have to call out in
3868 * the "privilege" production any reserved keywords that need to be usable
3869 * as privilege names.
3872 /* either ALL [PRIVILEGES] or a list of individual privileges */
3873 privileges: privilege_list
3881 privilege_list: privilege
3882 { $$ = list_make1(makeString($1)); }
3883 | privilege_list ',' privilege
3884 { $$ = lappend($1, makeString($3)); }
3887 privilege: SELECT { $$ = pstrdup($1); }
3888 | REFERENCES { $$ = pstrdup($1); }
3889 | CREATE { $$ = pstrdup($1); }
3890 | ColId { $$ = $1; }
3894 /* Don't bother trying to fold the first two rules into one using
3895 * opt_table. You're going to get conflicts.
3900 PrivTarget *n = makeNode(PrivTarget);
3901 n->objtype = ACL_OBJECT_RELATION;
3905 | TABLE qualified_name_list
3907 PrivTarget *n = makeNode(PrivTarget);
3908 n->objtype = ACL_OBJECT_RELATION;
3912 | SEQUENCE qualified_name_list
3914 PrivTarget *n = makeNode(PrivTarget);
3915 n->objtype = ACL_OBJECT_SEQUENCE;
3919 | FUNCTION function_with_argtypes_list
3921 PrivTarget *n = makeNode(PrivTarget);
3922 n->objtype = ACL_OBJECT_FUNCTION;
3926 | DATABASE name_list
3928 PrivTarget *n = makeNode(PrivTarget);
3929 n->objtype = ACL_OBJECT_DATABASE;
3933 | LANGUAGE name_list
3935 PrivTarget *n = makeNode(PrivTarget);
3936 n->objtype = ACL_OBJECT_LANGUAGE;
3942 PrivTarget *n = makeNode(PrivTarget);
3943 n->objtype = ACL_OBJECT_NAMESPACE;
3947 | TABLESPACE name_list
3949 PrivTarget *n = makeNode(PrivTarget);
3950 n->objtype = ACL_OBJECT_TABLESPACE;
3958 grantee { $$ = list_make1($1); }
3959 | grantee_list ',' grantee { $$ = lappend($1, $3); }
3964 PrivGrantee *n = makeNode(PrivGrantee);
3965 /* This hack lets us avoid reserving PUBLIC as a keyword*/
3966 if (strcmp($1, "public") == 0)
3974 PrivGrantee *n = makeNode(PrivGrantee);
3975 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
3976 if (strcmp($2, "public") == 0)
3985 opt_grant_grant_option:
3986 WITH GRANT OPTION { $$ = TRUE; }
3987 | /*EMPTY*/ { $$ = FALSE; }
3990 function_with_argtypes_list:
3991 function_with_argtypes { $$ = list_make1($1); }
3992 | function_with_argtypes_list ',' function_with_argtypes
3993 { $$ = lappend($1, $3); }
3996 function_with_argtypes:
3999 FuncWithArgs *n = makeNode(FuncWithArgs);
4001 n->funcargs = extractArgTypes($2);
4006 /*****************************************************************************
4008 * GRANT and REVOKE ROLE statements
4010 *****************************************************************************/
4013 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4015 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4017 n->granted_roles = $2;
4018 n->grantee_roles = $4;
4026 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4028 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4029 n->is_grant = false;
4030 n->admin_opt = false;
4031 n->granted_roles = $2;
4032 n->grantee_roles = $4;
4036 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4038 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4039 n->is_grant = false;
4040 n->admin_opt = true;
4041 n->granted_roles = $5;
4042 n->grantee_roles = $7;
4048 opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
4049 | /*EMPTY*/ { $$ = FALSE; }
4052 opt_granted_by: GRANTED BY RoleId { $$ = $3; }
4053 | /*EMPTY*/ { $$ = NULL; }
4057 /*****************************************************************************
4059 * QUERY: CREATE INDEX
4061 * Note: we can't factor CONCURRENTLY into a separate production without
4062 * making it a reserved word.
4064 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
4065 * willing to make TABLESPACE a fully reserved word.
4066 *****************************************************************************/
4068 IndexStmt: CREATE index_opt_unique INDEX index_name
4069 ON qualified_name access_method_clause '(' index_params ')'
4070 opt_definition OptTableSpace where_clause
4072 IndexStmt *n = makeNode(IndexStmt);
4074 n->concurrent = false;
4077 n->accessMethod = $7;
4078 n->indexParams = $9;
4080 n->tableSpace = $12;
4081 n->whereClause = $13;
4084 | CREATE index_opt_unique INDEX CONCURRENTLY index_name
4085 ON qualified_name access_method_clause '(' index_params ')'
4086 opt_definition OptTableSpace where_clause
4088 IndexStmt *n = makeNode(IndexStmt);
4090 n->concurrent = true;
4093 n->accessMethod = $8;
4094 n->indexParams = $10;
4096 n->tableSpace = $13;
4097 n->whereClause = $14;
4103 UNIQUE { $$ = TRUE; }
4104 | /*EMPTY*/ { $$ = FALSE; }
4107 access_method_clause:
4108 USING access_method { $$ = $2; }
4109 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
4112 index_params: index_elem { $$ = list_make1($1); }
4113 | index_params ',' index_elem { $$ = lappend($1, $3); }
4117 * Index attributes can be either simple column references, or arbitrary
4118 * expressions in parens. For backwards-compatibility reasons, we allow
4119 * an expression that's just a function call to be written without parens.
4121 index_elem: ColId opt_class opt_asc_desc opt_nulls_order
4123 $$ = makeNode(IndexElem);
4128 $$->nulls_ordering = $4;
4130 | func_expr opt_class opt_asc_desc opt_nulls_order
4132 $$ = makeNode(IndexElem);
4137 $$->nulls_ordering = $4;
4139 | '(' a_expr ')' opt_class opt_asc_desc opt_nulls_order
4141 $$ = makeNode(IndexElem);
4146 $$->nulls_ordering = $6;
4150 opt_class: any_name { $$ = $1; }
4151 | USING any_name { $$ = $2; }
4152 | /*EMPTY*/ { $$ = NIL; }
4155 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
4156 | DESC { $$ = SORTBY_DESC; }
4157 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
4160 opt_nulls_order: NULLS_FIRST { $$ = SORTBY_NULLS_FIRST; }
4161 | NULLS_LAST { $$ = SORTBY_NULLS_LAST; }
4162 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
4166 /*****************************************************************************
4169 * create [or replace] function <fname>
4170 * [(<type-1> { , <type-n>})]
4172 * as <filename or code in language as appropriate>
4173 * language <lang> [with parameters]
4175 *****************************************************************************/
4178 CREATE opt_or_replace FUNCTION func_name func_args
4179 RETURNS func_return createfunc_opt_list opt_definition
4181 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4190 | CREATE opt_or_replace FUNCTION func_name func_args
4191 RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
4193 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4196 n->parameters = mergeTableFuncParameters($5, $9);
4197 n->returnType = TableFuncTypeName($9);
4198 n->returnType->location = @7;
4200 n->withClause = $12;
4203 | CREATE opt_or_replace FUNCTION func_name func_args
4204 createfunc_opt_list opt_definition
4206 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4210 n->returnType = NULL;
4218 OR REPLACE { $$ = TRUE; }
4219 | /*EMPTY*/ { $$ = FALSE; }
4222 func_args: '(' func_args_list ')' { $$ = $2; }
4223 | '(' ')' { $$ = NIL; }
4227 func_arg { $$ = list_make1($1); }
4228 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
4232 * The style with arg_class first is SQL99 standard, but Oracle puts
4233 * param_name first; accept both since it's likely people will try both
4234 * anyway. Don't bother trying to save productions by letting arg_class
4235 * have an empty alternative ... you'll get shift/reduce conflicts.
4237 * We can catch over-specified arguments here if we want to,
4238 * but for now better to silently swallow typmod, etc.
4239 * - thomas 2000-03-22
4242 arg_class param_name func_type
4244 FunctionParameter *n = makeNode(FunctionParameter);
4250 | param_name arg_class func_type
4252 FunctionParameter *n = makeNode(FunctionParameter);
4258 | param_name func_type
4260 FunctionParameter *n = makeNode(FunctionParameter);
4263 n->mode = FUNC_PARAM_IN;
4266 | arg_class func_type
4268 FunctionParameter *n = makeNode(FunctionParameter);
4276 FunctionParameter *n = makeNode(FunctionParameter);
4279 n->mode = FUNC_PARAM_IN;
4284 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
4285 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
4286 | OUT_P { $$ = FUNC_PARAM_OUT; }
4287 | INOUT { $$ = FUNC_PARAM_INOUT; }
4288 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
4289 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
4293 * Ideally param_name should be ColId, but that causes too many conflicts.
4295 param_name: type_function_name
4301 /* We can catch over-specified results here if we want to,
4302 * but for now better to silently swallow typmod, etc.
4303 * - thomas 2000-03-22
4310 * We would like to make the %TYPE productions here be ColId attrs etc,
4311 * but that causes reduce/reduce conflicts. type_function_name
4312 * is next best choice.
4314 func_type: Typename { $$ = $1; }
4315 | type_function_name attrs '%' TYPE_P
4317 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
4318 $$->pct_type = true;
4321 | SETOF type_function_name attrs '%' TYPE_P
4323 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
4324 $$->pct_type = true;
4331 createfunc_opt_list:
4332 /* Must be at least one to prevent conflict */
4333 createfunc_opt_item { $$ = list_make1($1); }
4334 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
4338 * Options common to both CREATE FUNCTION and ALTER FUNCTION
4340 common_func_opt_item:
4341 CALLED ON NULL_P INPUT_P
4343 $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
4345 | RETURNS NULL_P ON NULL_P INPUT_P
4347 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
4351 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
4355 $$ = makeDefElem("volatility", (Node *)makeString("immutable"));
4359 $$ = makeDefElem("volatility", (Node *)makeString("stable"));
4363 $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
4365 | EXTERNAL SECURITY DEFINER
4367 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
4369 | EXTERNAL SECURITY INVOKER
4371 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
4375 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
4379 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
4383 $$ = makeDefElem("cost", (Node *)$2);
4387 $$ = makeDefElem("rows", (Node *)$2);
4391 /* we abuse the normal content of a DefElem here */
4392 $$ = makeDefElem("set", (Node *)$1);
4396 createfunc_opt_item:
4399 $$ = makeDefElem("as", (Node *)$2);
4401 | LANGUAGE ColId_or_Sconst
4403 $$ = makeDefElem("language", (Node *)makeString($2));
4405 | common_func_opt_item
4411 func_as: Sconst { $$ = list_make1(makeString($1)); }
4414 $$ = list_make2(makeString($1), makeString($3));
4419 WITH definition { $$ = $2; }
4420 | /*EMPTY*/ { $$ = NIL; }
4423 table_func_column: param_name func_type
4425 FunctionParameter *n = makeNode(FunctionParameter);
4428 n->mode = FUNC_PARAM_TABLE;
4433 table_func_column_list:
4436 $$ = list_make1($1);
4438 | table_func_column_list ',' table_func_column
4440 $$ = lappend($1, $3);
4444 /*****************************************************************************
4447 * RENAME and OWNER subcommands are already provided by the generic
4448 * ALTER infrastructure, here we just specify alterations that can
4449 * only be applied to functions.
4451 *****************************************************************************/
4453 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
4455 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
4463 /* At least one option must be specified */
4464 common_func_opt_item { $$ = list_make1($1); }
4465 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
4468 /* Ignored, merely for SQL compliance */
4475 /*****************************************************************************
4479 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
4480 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
4481 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
4483 *****************************************************************************/
4486 DROP FUNCTION func_name func_args opt_drop_behavior
4488 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4489 n->kind = OBJECT_FUNCTION;
4491 n->args = extractArgTypes($4);
4493 n->missing_ok = false;
4496 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
4498 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4499 n->kind = OBJECT_FUNCTION;
4501 n->args = extractArgTypes($6);
4503 n->missing_ok = true;
4509 DROP AGGREGATE func_name aggr_args opt_drop_behavior
4511 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4512 n->kind = OBJECT_AGGREGATE;
4516 n->missing_ok = false;
4519 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
4521 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4522 n->kind = OBJECT_AGGREGATE;
4526 n->missing_ok = true;
4532 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
4534 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4535 n->kind = OBJECT_OPERATOR;
4539 n->missing_ok = false;
4542 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
4544 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4545 n->kind = OBJECT_OPERATOR;
4549 n->missing_ok = true;
4558 (errcode(ERRCODE_SYNTAX_ERROR),
4559 errmsg("missing argument"),
4560 errhint("Use NONE to denote the missing argument of a unary operator."),
4561 scanner_errposition(@3)));
4563 | '(' Typename ',' Typename ')'
4564 { $$ = list_make2($2, $4); }
4565 | '(' NONE ',' Typename ')' /* left unary */
4566 { $$ = list_make2(NULL, $4); }
4567 | '(' Typename ',' NONE ')' /* right unary */
4568 { $$ = list_make2($2, NULL); }
4573 { $$ = list_make1(makeString($1)); }
4574 | ColId '.' any_operator
4575 { $$ = lcons(makeString($1), $3); }
4579 /*****************************************************************************
4581 * CREATE CAST / DROP CAST
4583 *****************************************************************************/
4585 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
4586 WITH FUNCTION function_with_argtypes cast_context
4588 CreateCastStmt *n = makeNode(CreateCastStmt);
4592 n->context = (CoercionContext) $11;
4596 | CREATE CAST '(' Typename AS Typename ')'
4597 WITHOUT FUNCTION cast_context
4599 CreateCastStmt *n = makeNode(CreateCastStmt);
4603 n->context = (CoercionContext) $10;
4607 | CREATE CAST '(' Typename AS Typename ')'
4608 WITH INOUT cast_context
4610 CreateCastStmt *n = makeNode(CreateCastStmt);
4614 n->context = (CoercionContext) $10;
4620 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
4621 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
4622 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
4626 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
4628 DropCastStmt *n = makeNode(DropCastStmt);
4637 opt_if_exists: IF_P EXISTS { $$ = TRUE; }
4638 | /*EMPTY*/ { $$ = FALSE; }
4642 /*****************************************************************************
4646 * REINDEX type <name> [FORCE]
4648 * FORCE no longer does anything, but we accept it for backwards compatibility
4649 *****************************************************************************/
4652 REINDEX reindex_type qualified_name opt_force
4654 ReindexStmt *n = makeNode(ReindexStmt);
4660 | REINDEX SYSTEM_P name opt_force
4662 ReindexStmt *n = makeNode(ReindexStmt);
4663 n->kind = OBJECT_DATABASE;
4666 n->do_system = true;
4670 | REINDEX DATABASE name opt_force
4672 ReindexStmt *n = makeNode(ReindexStmt);
4673 n->kind = OBJECT_DATABASE;
4676 n->do_system = true;
4683 INDEX { $$ = OBJECT_INDEX; }
4684 | TABLE { $$ = OBJECT_TABLE; }
4687 opt_force: FORCE { $$ = TRUE; }
4688 | /* EMPTY */ { $$ = FALSE; }
4692 /*****************************************************************************
4694 * ALTER THING name RENAME TO newname
4696 *****************************************************************************/
4698 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
4700 RenameStmt *n = makeNode(RenameStmt);
4701 n->renameType = OBJECT_AGGREGATE;
4707 | ALTER CONVERSION_P any_name RENAME TO name
4709 RenameStmt *n = makeNode(RenameStmt);
4710 n->renameType = OBJECT_CONVERSION;
4715 | ALTER DATABASE database_name RENAME TO database_name
4717 RenameStmt *n = makeNode(RenameStmt);
4718 n->renameType = OBJECT_DATABASE;
4723 | ALTER FUNCTION function_with_argtypes RENAME TO name
4725 RenameStmt *n = makeNode(RenameStmt);
4726 n->renameType = OBJECT_FUNCTION;
4727 n->object = $3->funcname;
4728 n->objarg = $3->funcargs;
4732 | ALTER GROUP_P RoleId RENAME TO RoleId
4734 RenameStmt *n = makeNode(RenameStmt);
4735 n->renameType = OBJECT_ROLE;
4740 | ALTER opt_procedural LANGUAGE name RENAME TO name
4742 RenameStmt *n = makeNode(RenameStmt);
4743 n->renameType = OBJECT_LANGUAGE;
4748 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
4750 RenameStmt *n = makeNode(RenameStmt);
4751 n->renameType = OBJECT_OPCLASS;
4757 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
4759 RenameStmt *n = makeNode(RenameStmt);
4760 n->renameType = OBJECT_OPFAMILY;
4766 | ALTER SCHEMA name RENAME TO name
4768 RenameStmt *n = makeNode(RenameStmt);
4769 n->renameType = OBJECT_SCHEMA;
4774 | ALTER TABLE relation_expr RENAME TO name
4776 RenameStmt *n = makeNode(RenameStmt);
4777 n->renameType = OBJECT_TABLE;
4783 | ALTER SEQUENCE relation_expr RENAME TO name
4785 RenameStmt *n = makeNode(RenameStmt);
4786 n->renameType = OBJECT_SEQUENCE;
4792 | ALTER VIEW relation_expr RENAME TO name
4794 RenameStmt *n = makeNode(RenameStmt);
4795 n->renameType = OBJECT_VIEW;
4801 | ALTER INDEX relation_expr RENAME TO name
4803 RenameStmt *n = makeNode(RenameStmt);
4804 n->renameType = OBJECT_INDEX;
4810 | ALTER TABLE relation_expr RENAME opt_column name TO name
4812 RenameStmt *n = makeNode(RenameStmt);
4813 n->renameType = OBJECT_COLUMN;
4819 | ALTER TRIGGER name ON relation_expr RENAME TO name
4821 RenameStmt *n = makeNode(RenameStmt);
4822 n->renameType = OBJECT_TRIGGER;
4828 | ALTER ROLE RoleId RENAME TO RoleId
4830 RenameStmt *n = makeNode(RenameStmt);
4831 n->renameType = OBJECT_ROLE;
4836 | ALTER USER RoleId RENAME TO RoleId
4838 RenameStmt *n = makeNode(RenameStmt);
4839 n->renameType = OBJECT_ROLE;
4844 | ALTER TABLESPACE name RENAME TO name
4846 RenameStmt *n = makeNode(RenameStmt);
4847 n->renameType = OBJECT_TABLESPACE;
4852 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
4854 RenameStmt *n = makeNode(RenameStmt);
4855 n->renameType = OBJECT_TSPARSER;
4860 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
4862 RenameStmt *n = makeNode(RenameStmt);
4863 n->renameType = OBJECT_TSDICTIONARY;
4868 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
4870 RenameStmt *n = makeNode(RenameStmt);
4871 n->renameType = OBJECT_TSTEMPLATE;
4876 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
4878 RenameStmt *n = makeNode(RenameStmt);
4879 n->renameType = OBJECT_TSCONFIGURATION;
4884 | ALTER TYPE_P any_name RENAME TO name
4886 RenameStmt *n = makeNode(RenameStmt);
4887 n->renameType = OBJECT_TYPE;
4894 opt_column: COLUMN { $$ = COLUMN; }
4895 | /*EMPTY*/ { $$ = 0; }
4898 opt_set_data: SET DATA_P { $$ = 1; }
4899 | /*EMPTY*/ { $$ = 0; }
4902 /*****************************************************************************
4904 * ALTER THING name SET SCHEMA name
4906 *****************************************************************************/
4908 AlterObjectSchemaStmt:
4909 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
4911 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4912 n->objectType = OBJECT_AGGREGATE;
4918 | ALTER DOMAIN_P any_name SET SCHEMA name
4920 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4921 n->objectType = OBJECT_DOMAIN;
4926 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
4928 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4929 n->objectType = OBJECT_FUNCTION;
4930 n->object = $3->funcname;
4931 n->objarg = $3->funcargs;
4935 | ALTER TABLE relation_expr SET SCHEMA name
4937 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4938 n->objectType = OBJECT_TABLE;
4943 | ALTER SEQUENCE relation_expr SET SCHEMA name
4945 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4946 n->objectType = OBJECT_SEQUENCE;
4951 | ALTER VIEW relation_expr SET SCHEMA name
4953 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4954 n->objectType = OBJECT_VIEW;
4959 | ALTER TYPE_P any_name SET SCHEMA name
4961 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4962 n->objectType = OBJECT_TYPE;
4969 /*****************************************************************************
4971 * ALTER THING name OWNER TO newname
4973 *****************************************************************************/
4975 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
4977 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
4978 n->objectType = OBJECT_AGGREGATE;
4984 | ALTER CONVERSION_P any_name OWNER TO RoleId
4986 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
4987 n->objectType = OBJECT_CONVERSION;
4992 | ALTER DATABASE database_name OWNER TO RoleId
4994 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
4995 n->objectType = OBJECT_DATABASE;
4996 n->object = list_make1(makeString($3));
5000 | ALTER DOMAIN_P any_name OWNER TO RoleId
5002 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5003 n->objectType = OBJECT_DOMAIN;
5008 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
5010 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5011 n->objectType = OBJECT_FUNCTION;
5012 n->object = $3->funcname;
5013 n->objarg = $3->funcargs;
5017 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
5019 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5020 n->objectType = OBJECT_LANGUAGE;
5021 n->object = list_make1(makeString($4));
5025 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
5027 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5028 n->objectType = OBJECT_OPERATOR;
5034 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
5036 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5037 n->objectType = OBJECT_OPCLASS;
5043 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
5045 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5046 n->objectType = OBJECT_OPFAMILY;
5052 | ALTER SCHEMA name OWNER TO RoleId
5054 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5055 n->objectType = OBJECT_SCHEMA;
5056 n->object = list_make1(makeString($3));
5060 | ALTER TYPE_P any_name OWNER TO RoleId
5062 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5063 n->objectType = OBJECT_TYPE;
5068 | ALTER TABLESPACE name OWNER TO RoleId
5070 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5071 n->objectType = OBJECT_TABLESPACE;
5072 n->object = list_make1(makeString($3));
5076 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
5078 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5079 n->objectType = OBJECT_TSDICTIONARY;
5084 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
5086 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5087 n->objectType = OBJECT_TSCONFIGURATION;
5095 /*****************************************************************************
5097 * QUERY: Define Rewrite Rule
5099 *****************************************************************************/
5101 RuleStmt: CREATE opt_or_replace RULE name AS
5102 { QueryIsRule=TRUE; }
5103 ON event TO qualified_name where_clause
5104 DO opt_instead RuleActionList
5106 RuleStmt *n = makeNode(RuleStmt);
5110 n->whereClause = $11;
5120 NOTHING { $$ = NIL; }
5121 | RuleActionStmt { $$ = list_make1($1); }
5122 | '(' RuleActionMulti ')' { $$ = $2; }
5125 /* the thrashing around here is to discard "empty" statements... */
5127 RuleActionMulti ';' RuleActionStmtOrEmpty
5129 $$ = lappend($1, $3);
5133 | RuleActionStmtOrEmpty
5135 $$ = list_make1($1);
5149 RuleActionStmtOrEmpty:
5150 RuleActionStmt { $$ = $1; }
5151 | /*EMPTY*/ { $$ = NULL; }
5154 event: SELECT { $$ = CMD_SELECT; }
5155 | UPDATE { $$ = CMD_UPDATE; }
5156 | DELETE_P { $$ = CMD_DELETE; }
5157 | INSERT { $$ = CMD_INSERT; }
5161 INSTEAD { $$ = TRUE; }
5162 | ALSO { $$ = FALSE; }
5163 | /*EMPTY*/ { $$ = FALSE; }
5168 DROP RULE name ON qualified_name opt_drop_behavior
5170 DropPropertyStmt *n = makeNode(DropPropertyStmt);
5174 n->removeType = OBJECT_RULE;
5175 n->missing_ok = false;
5178 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
5180 DropPropertyStmt *n = makeNode(DropPropertyStmt);
5184 n->removeType = OBJECT_RULE;
5185 n->missing_ok = true;
5191 /*****************************************************************************
5194 * NOTIFY <identifier> can appear both in rule bodies and
5195 * as a query-level command
5197 *****************************************************************************/
5199 NotifyStmt: NOTIFY ColId
5201 NotifyStmt *n = makeNode(NotifyStmt);
5202 n->conditionname = $2;
5207 ListenStmt: LISTEN ColId
5209 ListenStmt *n = makeNode(ListenStmt);
5210 n->conditionname = $2;
5218 UnlistenStmt *n = makeNode(UnlistenStmt);
5219 n->conditionname = $2;
5224 UnlistenStmt *n = makeNode(UnlistenStmt);
5225 n->conditionname = NULL;
5231 /*****************************************************************************
5235 * BEGIN / COMMIT / ROLLBACK
5236 * (also older versions END / ABORT)
5238 *****************************************************************************/
5241 ABORT_P opt_transaction
5243 TransactionStmt *n = makeNode(TransactionStmt);
5244 n->kind = TRANS_STMT_ROLLBACK;
5248 | BEGIN_P opt_transaction transaction_mode_list_or_empty
5250 TransactionStmt *n = makeNode(TransactionStmt);
5251 n->kind = TRANS_STMT_BEGIN;
5255 | START TRANSACTION transaction_mode_list_or_empty
5257 TransactionStmt *n = makeNode(TransactionStmt);
5258 n->kind = TRANS_STMT_START;
5262 | COMMIT opt_transaction
5264 TransactionStmt *n = makeNode(TransactionStmt);
5265 n->kind = TRANS_STMT_COMMIT;
5269 | END_P opt_transaction
5271 TransactionStmt *n = makeNode(TransactionStmt);
5272 n->kind = TRANS_STMT_COMMIT;
5276 | ROLLBACK opt_transaction
5278 TransactionStmt *n = makeNode(TransactionStmt);
5279 n->kind = TRANS_STMT_ROLLBACK;
5285 TransactionStmt *n = makeNode(TransactionStmt);
5286 n->kind = TRANS_STMT_SAVEPOINT;
5287 n->options = list_make1(makeDefElem("savepoint_name",
5288 (Node *)makeString($2)));
5291 | RELEASE SAVEPOINT ColId
5293 TransactionStmt *n = makeNode(TransactionStmt);
5294 n->kind = TRANS_STMT_RELEASE;
5295 n->options = list_make1(makeDefElem("savepoint_name",
5296 (Node *)makeString($3)));
5301 TransactionStmt *n = makeNode(TransactionStmt);
5302 n->kind = TRANS_STMT_RELEASE;
5303 n->options = list_make1(makeDefElem("savepoint_name",
5304 (Node *)makeString($2)));
5307 | ROLLBACK opt_transaction TO SAVEPOINT ColId
5309 TransactionStmt *n = makeNode(TransactionStmt);
5310 n->kind = TRANS_STMT_ROLLBACK_TO;
5311 n->options = list_make1(makeDefElem("savepoint_name",
5312 (Node *)makeString($5)));
5315 | ROLLBACK opt_transaction TO ColId
5317 TransactionStmt *n = makeNode(TransactionStmt);
5318 n->kind = TRANS_STMT_ROLLBACK_TO;
5319 n->options = list_make1(makeDefElem("savepoint_name",
5320 (Node *)makeString($4)));
5323 | PREPARE TRANSACTION Sconst
5325 TransactionStmt *n = makeNode(TransactionStmt);
5326 n->kind = TRANS_STMT_PREPARE;
5330 | COMMIT PREPARED Sconst
5332 TransactionStmt *n = makeNode(TransactionStmt);
5333 n->kind = TRANS_STMT_COMMIT_PREPARED;
5337 | ROLLBACK PREPARED Sconst
5339 TransactionStmt *n = makeNode(TransactionStmt);
5340 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
5346 opt_transaction: WORK {}
5351 transaction_mode_item:
5352 ISOLATION LEVEL iso_level
5353 { $$ = makeDefElem("transaction_isolation",
5354 makeStringConst($3, @3)); }
5356 { $$ = makeDefElem("transaction_read_only",
5357 makeIntConst(TRUE, @1)); }
5359 { $$ = makeDefElem("transaction_read_only",
5360 makeIntConst(FALSE, @1)); }
5363 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
5364 transaction_mode_list:
5365 transaction_mode_item
5366 { $$ = list_make1($1); }
5367 | transaction_mode_list ',' transaction_mode_item
5368 { $$ = lappend($1, $3); }
5369 | transaction_mode_list transaction_mode_item
5370 { $$ = lappend($1, $2); }
5373 transaction_mode_list_or_empty:
5374 transaction_mode_list
5380 /*****************************************************************************
5383 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
5384 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
5386 *****************************************************************************/
5388 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
5389 AS SelectStmt opt_check_option
5391 ViewStmt *n = makeNode(ViewStmt);
5393 n->view->istemp = $2;
5399 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
5400 AS SelectStmt opt_check_option
5402 ViewStmt *n = makeNode(ViewStmt);
5404 n->view->istemp = $4;
5416 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5417 errmsg("WITH CHECK OPTION is not implemented")));
5419 | WITH CASCADED CHECK OPTION
5422 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5423 errmsg("WITH CHECK OPTION is not implemented")));
5425 | WITH LOCAL CHECK OPTION
5428 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5429 errmsg("WITH CHECK OPTION is not implemented")));
5431 | /* EMPTY */ { $$ = NIL; }
5434 /*****************************************************************************
5439 *****************************************************************************/
5441 LoadStmt: LOAD file_name
5443 LoadStmt *n = makeNode(LoadStmt);
5450 /*****************************************************************************
5454 *****************************************************************************/
5457 CREATE DATABASE database_name opt_with createdb_opt_list
5459 CreatedbStmt *n = makeNode(CreatedbStmt);
5467 createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
5468 | /* EMPTY */ { $$ = NIL; }
5472 TABLESPACE opt_equal name
5474 $$ = makeDefElem("tablespace", (Node *)makeString($3));
5476 | TABLESPACE opt_equal DEFAULT
5478 $$ = makeDefElem("tablespace", NULL);
5480 | LOCATION opt_equal Sconst
5482 $$ = makeDefElem("location", (Node *)makeString($3));
5484 | LOCATION opt_equal DEFAULT
5486 $$ = makeDefElem("location", NULL);
5488 | TEMPLATE opt_equal name
5490 $$ = makeDefElem("template", (Node *)makeString($3));
5492 | TEMPLATE opt_equal DEFAULT
5494 $$ = makeDefElem("template", NULL);
5496 | ENCODING opt_equal Sconst
5498 $$ = makeDefElem("encoding", (Node *)makeString($3));
5500 | ENCODING opt_equal Iconst
5502 $$ = makeDefElem("encoding", (Node *)makeInteger($3));
5504 | ENCODING opt_equal DEFAULT
5506 $$ = makeDefElem("encoding", NULL);
5508 | COLLATE opt_equal Sconst
5510 $$ = makeDefElem("collate", (Node *)makeString($3));
5512 | COLLATE opt_equal DEFAULT
5514 $$ = makeDefElem("collate", NULL);
5516 | CTYPE opt_equal Sconst
5518 $$ = makeDefElem("ctype", (Node *)makeString($3));
5520 | CTYPE opt_equal DEFAULT
5522 $$ = makeDefElem("ctype", NULL);
5524 | CONNECTION LIMIT opt_equal SignedIconst
5526 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
5528 | OWNER opt_equal name
5530 $$ = makeDefElem("owner", (Node *)makeString($3));
5532 | OWNER opt_equal DEFAULT
5534 $$ = makeDefElem("owner", NULL);
5539 * Though the equals sign doesn't match other WITH options, pg_dump uses
5540 * equals for backward compatibility, and it doesn't seem worth removing it.
5547 /*****************************************************************************
5551 *****************************************************************************/
5554 ALTER DATABASE database_name opt_with alterdb_opt_list
5556 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
5561 | ALTER DATABASE database_name SET TABLESPACE name
5563 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
5565 n->options = list_make1(makeDefElem("tablespace",
5566 (Node *)makeString($6)));
5571 AlterDatabaseSetStmt:
5572 ALTER DATABASE database_name SetResetClause
5574 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
5583 alterdb_opt_list alterdb_opt_item { $$ = lappend($1, $2); }
5584 | /* EMPTY */ { $$ = NIL; }
5588 CONNECTION LIMIT opt_equal SignedIconst
5590 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
5595 /*****************************************************************************
5597 * DROP DATABASE [ IF EXISTS ]
5599 * This is implicitly CASCADE, no need for drop behavior
5600 *****************************************************************************/
5602 DropdbStmt: DROP DATABASE database_name
5604 DropdbStmt *n = makeNode(DropdbStmt);
5606 n->missing_ok = FALSE;
5609 | DROP DATABASE IF_P EXISTS database_name
5611 DropdbStmt *n = makeNode(DropdbStmt);
5613 n->missing_ok = TRUE;
5619 /*****************************************************************************
5621 * Manipulate a domain
5623 *****************************************************************************/
5626 CREATE DOMAIN_P any_name opt_as Typename ColQualList
5628 CreateDomainStmt *n = makeNode(CreateDomainStmt);
5631 n->constraints = $6;
5637 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
5638 ALTER DOMAIN_P any_name alter_column_default
5640 AlterDomainStmt *n = makeNode(AlterDomainStmt);
5646 /* ALTER DOMAIN <domain> DROP NOT NULL */
5647 | ALTER DOMAIN_P any_name DROP NOT NULL_P
5649 AlterDomainStmt *n = makeNode(AlterDomainStmt);
5654 /* ALTER DOMAIN <domain> SET NOT NULL */
5655 | ALTER DOMAIN_P any_name SET NOT NULL_P
5657 AlterDomainStmt *n = makeNode(AlterDomainStmt);
5662 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
5663 | ALTER DOMAIN_P any_name ADD_P TableConstraint
5665 AlterDomainStmt *n = makeNode(AlterDomainStmt);
5671 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
5672 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
5674 AlterDomainStmt *n = makeNode(AlterDomainStmt);
5688 /*****************************************************************************
5690 * Manipulate a text search dictionary or configuration
5692 *****************************************************************************/
5694 AlterTSDictionaryStmt:
5695 ALTER TEXT_P SEARCH DICTIONARY any_name definition
5697 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
5704 AlterTSConfigurationStmt:
5705 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
5707 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5711 n->override = false;
5715 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
5717 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5725 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
5727 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5730 n->dicts = list_make2($9,$11);
5731 n->override = false;
5735 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
5737 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5740 n->dicts = list_make2($11,$13);
5741 n->override = false;
5745 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
5747 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5750 n->missing_ok = false;
5753 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
5755 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5758 n->missing_ok = true;
5764 /*****************************************************************************
5766 * Manipulate a conversion
5768 * CREATE [DEFAULT] CONVERSION <conversion_name>
5769 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
5771 *****************************************************************************/
5773 CreateConversionStmt:
5774 CREATE opt_default CONVERSION_P any_name FOR Sconst
5775 TO Sconst FROM any_name
5777 CreateConversionStmt *n = makeNode(CreateConversionStmt);
5778 n->conversion_name = $4;
5779 n->for_encoding_name = $6;
5780 n->to_encoding_name = $8;
5787 /*****************************************************************************
5790 * CLUSTER <qualified_name> [ USING <index_name> ]
5792 * CLUSTER <index_name> ON <qualified_name> (for pre-8.3)
5794 *****************************************************************************/
5797 CLUSTER qualified_name cluster_index_specification
5799 ClusterStmt *n = makeNode(ClusterStmt);
5806 ClusterStmt *n = makeNode(ClusterStmt);
5808 n->indexname = NULL;
5811 /* kept for pre-8.3 compatibility */
5812 | CLUSTER index_name ON qualified_name
5814 ClusterStmt *n = makeNode(ClusterStmt);
5821 cluster_index_specification:
5822 USING index_name { $$ = $2; }
5823 | /*EMPTY*/ { $$ = NULL; }
5827 /*****************************************************************************
5833 *****************************************************************************/
5835 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
5837 VacuumStmt *n = makeNode(VacuumStmt);
5841 n->freeze_min_age = $3 ? 0 : -1;
5847 | VACUUM opt_full opt_freeze opt_verbose qualified_name
5849 VacuumStmt *n = makeNode(VacuumStmt);
5853 n->freeze_min_age = $3 ? 0 : -1;
5859 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
5861 VacuumStmt *n = (VacuumStmt *) $5;
5864 n->freeze_min_age = $3 ? 0 : -1;
5871 analyze_keyword opt_verbose
5873 VacuumStmt *n = makeNode(VacuumStmt);
5877 n->freeze_min_age = -1;
5883 | analyze_keyword opt_verbose qualified_name opt_name_list
5885 VacuumStmt *n = makeNode(VacuumStmt);
5889 n->freeze_min_age = -1;
5899 | ANALYSE /* British */ {}
5903 VERBOSE { $$ = TRUE; }
5904 | /*EMPTY*/ { $$ = FALSE; }
5907 opt_full: FULL { $$ = TRUE; }
5908 | /*EMPTY*/ { $$ = FALSE; }
5911 opt_freeze: FREEZE { $$ = TRUE; }
5912 | /*EMPTY*/ { $$ = FALSE; }
5916 '(' name_list ')' { $$ = $2; }
5917 | /*EMPTY*/ { $$ = NIL; }
5921 /*****************************************************************************
5924 * EXPLAIN [ANALYZE] [VERBOSE] query
5926 *****************************************************************************/
5928 ExplainStmt: EXPLAIN opt_analyze opt_verbose ExplainableStmt
5930 ExplainStmt *n = makeNode(ExplainStmt);
5945 | ExecuteStmt /* by default all are $$=$1 */
5949 analyze_keyword { $$ = TRUE; }
5950 | /* EMPTY */ { $$ = FALSE; }
5953 /*****************************************************************************
5956 * PREPARE <plan_name> [(args, ...)] AS <query>
5958 *****************************************************************************/
5960 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
5962 PrepareStmt *n = makeNode(PrepareStmt);
5970 prep_type_clause: '(' type_list ')' { $$ = $2; }
5971 | /* EMPTY */ { $$ = NIL; }
5978 | DeleteStmt /* by default all are $$=$1 */
5981 /*****************************************************************************
5983 * EXECUTE <plan_name> [(params, ...)]
5984 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
5986 *****************************************************************************/
5988 ExecuteStmt: EXECUTE name execute_param_clause
5990 ExecuteStmt *n = makeNode(ExecuteStmt);
5996 | CREATE OptTemp TABLE create_as_target AS
5997 EXECUTE name execute_param_clause
5999 ExecuteStmt *n = makeNode(ExecuteStmt);
6002 $4->rel->istemp = $2;
6006 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6007 errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
6008 /* ... because it's not implemented, but it could be */
6013 execute_param_clause: '(' expr_list ')' { $$ = $2; }
6014 | /* EMPTY */ { $$ = NIL; }
6017 /*****************************************************************************
6020 * DEALLOCATE [PREPARE] <plan_name>
6022 *****************************************************************************/
6024 DeallocateStmt: DEALLOCATE name
6026 DeallocateStmt *n = makeNode(DeallocateStmt);
6030 | DEALLOCATE PREPARE name
6032 DeallocateStmt *n = makeNode(DeallocateStmt);
6038 DeallocateStmt *n = makeNode(DeallocateStmt);
6042 | DEALLOCATE PREPARE ALL
6044 DeallocateStmt *n = makeNode(DeallocateStmt);
6050 /*****************************************************************************
6055 *****************************************************************************/
6058 INSERT INTO qualified_name insert_rest returning_clause
6061 $4->returningList = $5;
6069 $$ = makeNode(InsertStmt);
6071 $$->selectStmt = $1;
6073 | '(' insert_column_list ')' SelectStmt
6075 $$ = makeNode(InsertStmt);
6077 $$->selectStmt = $4;
6081 $$ = makeNode(InsertStmt);
6083 $$->selectStmt = NULL;
6089 { $$ = list_make1($1); }
6090 | insert_column_list ',' insert_column_item
6091 { $$ = lappend($1, $3); }
6095 ColId opt_indirection
6097 $$ = makeNode(ResTarget);
6099 $$->indirection = check_indirection($2);
6106 RETURNING target_list { $$ = $2; }
6107 | /* EMPTY */ { $$ = NIL; }
6111 /*****************************************************************************
6116 *****************************************************************************/
6118 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
6119 using_clause where_or_current_clause returning_clause
6121 DeleteStmt *n = makeNode(DeleteStmt);
6123 n->usingClause = $4;
6124 n->whereClause = $5;
6125 n->returningList = $6;
6131 USING from_list { $$ = $2; }
6132 | /*EMPTY*/ { $$ = NIL; }
6135 LockStmt: LOCK_P opt_table qualified_name_list opt_lock opt_nowait
6137 LockStmt *n = makeNode(LockStmt);
6146 opt_lock: IN_P lock_type MODE { $$ = $2; }
6147 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
6150 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
6151 | ROW SHARE { $$ = RowShareLock; }
6152 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
6153 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
6154 | SHARE { $$ = ShareLock; }
6155 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
6156 | EXCLUSIVE { $$ = ExclusiveLock; }
6157 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
6160 opt_nowait: NOWAIT { $$ = TRUE; }
6161 | /*EMPTY*/ { $$ = FALSE; }
6165 /*****************************************************************************
6168 * UpdateStmt (UPDATE)
6170 *****************************************************************************/
6172 UpdateStmt: UPDATE relation_expr_opt_alias
6175 where_or_current_clause
6178 UpdateStmt *n = makeNode(UpdateStmt);
6182 n->whereClause = $6;
6183 n->returningList = $7;
6189 set_clause { $$ = $1; }
6190 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
6194 single_set_clause { $$ = list_make1($1); }
6195 | multiple_set_clause { $$ = $1; }
6199 set_target '=' ctext_expr
6202 $$->val = (Node *) $3;
6206 multiple_set_clause:
6207 '(' set_target_list ')' '=' ctext_row
6213 * Break the ctext_row apart, merge individual expressions
6214 * into the destination ResTargets. XXX this approach
6215 * cannot work for general row expressions as sources.
6217 if (list_length($2) != list_length($5))
6219 (errcode(ERRCODE_SYNTAX_ERROR),
6220 errmsg("number of columns does not match number of values"),
6221 scanner_errposition(@1)));
6222 forboth(col_cell, $2, val_cell, $5)
6224 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
6225 Node *res_val = (Node *) lfirst(val_cell);
6227 res_col->val = res_val;
6235 ColId opt_indirection
6237 $$ = makeNode(ResTarget);
6239 $$->indirection = check_indirection($2);
6240 $$->val = NULL; /* upper production sets this */
6246 set_target { $$ = list_make1($1); }
6247 | set_target_list ',' set_target { $$ = lappend($1,$3); }
6251 /*****************************************************************************
6256 *****************************************************************************/
6257 DeclareCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR SelectStmt
6259 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
6261 /* currently we always set FAST_PLAN option */
6262 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
6268 cursor_options: /*EMPTY*/ { $$ = 0; }
6269 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
6270 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
6271 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
6272 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
6275 opt_hold: /* EMPTY */ { $$ = 0; }
6276 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
6277 | WITHOUT HOLD { $$ = 0; }
6280 /*****************************************************************************
6285 *****************************************************************************/
6287 /* A complete SELECT statement looks like this.
6289 * The rule returns either a single SelectStmt node or a tree of them,
6290 * representing a set-operation tree.
6292 * There is an ambiguity when a sub-SELECT is within an a_expr and there
6293 * are excess parentheses: do the parentheses belong to the sub-SELECT or
6294 * to the surrounding a_expr? We don't really care, but yacc wants to know.
6295 * To resolve the ambiguity, we are careful to define the grammar so that
6296 * the decision is staved off as long as possible: as long as we can keep
6297 * absorbing parentheses into the sub-SELECT, we will do so, and only when
6298 * it's no longer possible to do that will we decide that parens belong to
6299 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
6300 * parentheses are treated as part of the sub-select. The necessity of doing
6301 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
6302 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
6303 * SELECT viewpoint when we see the UNION.
6305 * This approach is implemented by defining a nonterminal select_with_parens,
6306 * which represents a SELECT with at least one outer layer of parentheses,
6307 * and being careful to use select_with_parens, never '(' SelectStmt ')',
6308 * in the expression grammar. We will then have shift-reduce conflicts
6309 * which we can resolve in favor of always treating '(' <select> ')' as
6310 * a select_with_parens. To resolve the conflicts, the productions that
6311 * conflict with the select_with_parens productions are manually given
6312 * precedences lower than the precedence of ')', thereby ensuring that we
6313 * shift ')' (and then reduce to select_with_parens) rather than trying to
6314 * reduce the inner <select> nonterminal to something else. We use UMINUS
6315 * precedence for this, which is a fairly arbitrary choice.
6317 * To be able to define select_with_parens itself without ambiguity, we need
6318 * a nonterminal select_no_parens that represents a SELECT structure with no
6319 * outermost parentheses. This is a little bit tedious, but it works.
6321 * In non-expression contexts, we use SelectStmt which can represent a SELECT
6322 * with or without outer parentheses.
6325 SelectStmt: select_no_parens %prec UMINUS
6326 | select_with_parens %prec UMINUS
6330 '(' select_no_parens ')' { $$ = $2; }
6331 | '(' select_with_parens ')' { $$ = $2; }
6335 * This rule parses the equivalent of the standard's <query expression>.
6336 * The duplicative productions are annoying, but hard to get rid of without
6337 * creating shift/reduce conflicts.
6339 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
6340 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
6341 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
6345 simple_select { $$ = $1; }
6346 | select_clause sort_clause
6348 insertSelectOptions((SelectStmt *) $1, $2, NIL,
6352 | select_clause opt_sort_clause for_locking_clause opt_select_limit
6354 insertSelectOptions((SelectStmt *) $1, $2, $3,
6355 list_nth($4, 0), list_nth($4, 1),
6359 | select_clause opt_sort_clause select_limit opt_for_locking_clause
6361 insertSelectOptions((SelectStmt *) $1, $2, $4,
6362 list_nth($3, 0), list_nth($3, 1),
6366 | with_clause simple_select
6368 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
6373 | with_clause select_clause sort_clause
6375 insertSelectOptions((SelectStmt *) $2, $3, NIL,
6380 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
6382 insertSelectOptions((SelectStmt *) $2, $3, $4,
6383 list_nth($5, 0), list_nth($5, 1),
6387 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
6389 insertSelectOptions((SelectStmt *) $2, $3, $5,
6390 list_nth($4, 0), list_nth($4, 1),
6397 simple_select { $$ = $1; }
6398 | select_with_parens { $$ = $1; }
6402 * This rule parses SELECT statements that can appear within set operations,
6403 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
6404 * the ordering of the set operations. Without '(' and ')' we want the
6405 * operations to be ordered per the precedence specs at the head of this file.
6407 * As with select_no_parens, simple_select cannot have outer parentheses,
6408 * but can have parenthesized subclauses.
6410 * Note that sort clauses cannot be included at this level --- SQL92 requires
6411 * SELECT foo UNION SELECT bar ORDER BY baz
6413 * (SELECT foo UNION SELECT bar) ORDER BY baz
6415 * SELECT foo UNION (SELECT bar ORDER BY baz)
6416 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
6417 * described as part of the select_no_parens production, not simple_select.
6418 * This does not limit functionality, because you can reintroduce these
6419 * clauses inside parentheses.
6421 * NOTE: only the leftmost component SelectStmt should have INTO.
6422 * However, this is not checked by the grammar; parse analysis must check it.
6425 SELECT opt_distinct target_list
6426 into_clause from_clause where_clause
6427 group_clause having_clause
6429 SelectStmt *n = makeNode(SelectStmt);
6430 n->distinctClause = $2;
6434 n->whereClause = $6;
6435 n->groupClause = $7;
6436 n->havingClause = $8;
6439 | values_clause { $$ = $1; }
6440 | select_clause UNION opt_all select_clause
6442 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
6444 | select_clause INTERSECT opt_all select_clause
6446 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
6448 | select_clause EXCEPT opt_all select_clause
6450 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
6455 * SQL standard WITH clause looks like:
6457 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
6458 * AS (query) [ SEARCH or CYCLE clause ]
6460 * We don't currently support the SEARCH or CYCLE clause.
6465 $$ = makeNode(WithClause);
6467 $$->recursive = false;
6470 | WITH RECURSIVE cte_list
6472 $$ = makeNode(WithClause);
6474 $$->recursive = true;
6480 common_table_expr { $$ = list_make1($1); }
6481 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
6484 common_table_expr: name opt_name_list AS select_with_parens
6486 CommonTableExpr *n = makeNode(CommonTableExpr);
6488 n->aliascolnames = $2;
6496 INTO OptTempTableName
6498 $$ = makeNode(IntoClause);
6502 $$->onCommit = ONCOMMIT_NOOP;
6503 $$->tableSpaceName = NULL;
6510 * Redundancy here is needed to avoid shift/reduce conflicts,
6511 * since TEMP is not a reserved word. See also OptTemp.
6514 TEMPORARY opt_table qualified_name
6519 | TEMP opt_table qualified_name
6524 | LOCAL TEMPORARY opt_table qualified_name
6529 | LOCAL TEMP opt_table qualified_name
6534 | GLOBAL TEMPORARY opt_table qualified_name
6539 | GLOBAL TEMP opt_table qualified_name
6544 | TABLE qualified_name
6560 opt_all: ALL { $$ = TRUE; }
6561 | DISTINCT { $$ = FALSE; }
6562 | /*EMPTY*/ { $$ = FALSE; }
6565 /* We use (NIL) as a placeholder to indicate that all target expressions
6566 * should be placed in the DISTINCT list during parsetree analysis.
6569 DISTINCT { $$ = list_make1(NIL); }
6570 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
6572 | /*EMPTY*/ { $$ = NIL; }
6576 sort_clause { $$ = $1;}
6577 | /*EMPTY*/ { $$ = NIL; }
6581 ORDER BY sortby_list { $$ = $3; }
6585 sortby { $$ = list_make1($1); }
6586 | sortby_list ',' sortby { $$ = lappend($1, $3); }
6589 sortby: a_expr USING qual_all_Op opt_nulls_order
6591 $$ = makeNode(SortBy);
6593 $$->sortby_dir = SORTBY_USING;
6594 $$->sortby_nulls = $4;
6598 | a_expr opt_asc_desc opt_nulls_order
6600 $$ = makeNode(SortBy);
6602 $$->sortby_dir = $2;
6603 $$->sortby_nulls = $3;
6605 $$->location = -1; /* no operator */
6611 LIMIT select_limit_value OFFSET select_offset_value
6612 { $$ = list_make2($4, $2); }
6613 | OFFSET select_offset_value LIMIT select_limit_value
6614 { $$ = list_make2($2, $4); }
6615 | LIMIT select_limit_value
6616 { $$ = list_make2(NULL, $2); }
6617 | OFFSET select_offset_value
6618 { $$ = list_make2($2, NULL); }
6619 | LIMIT select_limit_value ',' select_offset_value
6621 /* Disabled because it was too confusing, bjm 2002-02-18 */
6623 (errcode(ERRCODE_SYNTAX_ERROR),
6624 errmsg("LIMIT #,# syntax is not supported"),
6625 errhint("Use separate LIMIT and OFFSET clauses."),
6626 scanner_errposition(@1)));
6628 /* SQL:2008 syntax variants */
6629 | OFFSET select_offset_value2 row_or_rows
6630 { $$ = list_make2($2, NULL); }
6631 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
6632 { $$ = list_make2(NULL, $3); }
6633 | OFFSET select_offset_value2 row_or_rows FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
6634 { $$ = list_make2($2, $6); }
6638 select_limit { $$ = $1; }
6640 { $$ = list_make2(NULL,NULL); }
6647 /* LIMIT ALL is represented as a NULL constant */
6648 $$ = makeNullAConst(@1);
6653 * Allowing full expressions without parentheses causes various parsing
6654 * problems with the trailing ROW/ROWS key words. SQL only calls for
6655 * constants, so we allow the rest only with parentheses.
6657 opt_select_fetch_first_value:
6658 SignedIconst { $$ = makeIntConst($1, @1); }
6659 | '(' a_expr ')' { $$ = $2; }
6660 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
6663 select_offset_value:
6668 * Again, the trailing ROW/ROWS in this case prevent the full expression
6669 * syntax. c_expr is the best we can do.
6671 select_offset_value2:
6688 GROUP_P BY expr_list { $$ = $3; }
6689 | /*EMPTY*/ { $$ = NIL; }
6693 HAVING a_expr { $$ = $2; }
6694 | /*EMPTY*/ { $$ = NULL; }
6698 for_locking_items { $$ = $1; }
6699 | FOR READ ONLY { $$ = NIL; }
6702 opt_for_locking_clause:
6703 for_locking_clause { $$ = $1; }
6704 | /* EMPTY */ { $$ = NIL; }
6708 for_locking_item { $$ = list_make1($1); }
6709 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
6713 FOR UPDATE locked_rels_list opt_nowait
6715 LockingClause *n = makeNode(LockingClause);
6717 n->forUpdate = TRUE;
6721 | FOR SHARE locked_rels_list opt_nowait
6723 LockingClause *n = makeNode(LockingClause);
6725 n->forUpdate = FALSE;
6732 OF qualified_name_list { $$ = $2; }
6733 | /* EMPTY */ { $$ = NIL; }
6740 SelectStmt *n = makeNode(SelectStmt);
6741 n->valuesLists = list_make1($2);
6744 | values_clause ',' ctext_row
6746 SelectStmt *n = (SelectStmt *) $1;
6747 n->valuesLists = lappend(n->valuesLists, $3);
6753 /*****************************************************************************
6755 * clauses common to all Optimizable Stmts:
6756 * from_clause - allow list of both JOIN expressions and table names
6757 * where_clause - qualifications for joins or restrictions
6759 *****************************************************************************/
6762 FROM from_list { $$ = $2; }
6763 | /*EMPTY*/ { $$ = NIL; }
6767 table_ref { $$ = list_make1($1); }
6768 | from_list ',' table_ref { $$ = lappend($1, $3); }
6772 * table_ref is where an alias clause can be attached. Note we cannot make
6773 * alias_clause have an empty production because that causes parse conflicts
6774 * between table_ref := '(' joined_table ')' alias_clause
6775 * and joined_table := '(' joined_table ')'. So, we must have the
6776 * redundant-looking productions here instead.
6778 table_ref: relation_expr
6782 | relation_expr alias_clause
6789 RangeFunction *n = makeNode(RangeFunction);
6790 n->funccallnode = $1;
6791 n->coldeflist = NIL;
6794 | func_table alias_clause
6796 RangeFunction *n = makeNode(RangeFunction);
6797 n->funccallnode = $1;
6799 n->coldeflist = NIL;
6802 | func_table AS '(' TableFuncElementList ')'
6804 RangeFunction *n = makeNode(RangeFunction);
6805 n->funccallnode = $1;
6809 | func_table AS ColId '(' TableFuncElementList ')'
6811 RangeFunction *n = makeNode(RangeFunction);
6812 Alias *a = makeNode(Alias);
6813 n->funccallnode = $1;
6819 | func_table ColId '(' TableFuncElementList ')'
6821 RangeFunction *n = makeNode(RangeFunction);
6822 Alias *a = makeNode(Alias);
6823 n->funccallnode = $1;
6829 | select_with_parens
6832 * The SQL spec does not permit a subselect
6833 * (<derived_table>) without an alias clause,
6834 * so we don't either. This avoids the problem
6835 * of needing to invent a unique refname for it.
6836 * That could be surmounted if there's sufficient
6837 * popular demand, but for now let's just implement
6838 * the spec and see if anyone complains.
6839 * However, it does seem like a good idea to emit
6840 * an error message that's better than "syntax error".
6842 if (IsA($1, SelectStmt) &&
6843 ((SelectStmt *) $1)->valuesLists)
6845 (errcode(ERRCODE_SYNTAX_ERROR),
6846 errmsg("VALUES in FROM must have an alias"),
6847 errhint("For example, FROM (VALUES ...) [AS] foo."),
6848 scanner_errposition(@1)));
6851 (errcode(ERRCODE_SYNTAX_ERROR),
6852 errmsg("subquery in FROM must have an alias"),
6853 errhint("For example, FROM (SELECT ...) [AS] foo."),
6854 scanner_errposition(@1)));
6857 | select_with_parens alias_clause
6859 RangeSubselect *n = makeNode(RangeSubselect);
6868 | '(' joined_table ')' alias_clause
6877 * It may seem silly to separate joined_table from table_ref, but there is
6878 * method in SQL92's madness: if you don't do it this way you get reduce-
6879 * reduce conflicts, because it's not clear to the parser generator whether
6880 * to expect alias_clause after ')' or not. For the same reason we must
6881 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
6882 * join_type to expand to empty; if we try it, the parser generator can't
6883 * figure out when to reduce an empty join_type right after table_ref.
6885 * Note that a CROSS JOIN is the same as an unqualified
6886 * INNER JOIN, and an INNER JOIN/ON has the same shape
6887 * but a qualification expression to limit membership.
6888 * A NATURAL JOIN implicitly matches column names between
6889 * tables and the shape is determined by which columns are
6890 * in common. We'll collect columns during the later transformations.
6894 '(' joined_table ')'
6898 | table_ref CROSS JOIN table_ref
6900 /* CROSS JOIN is same as unqualified inner join */
6901 JoinExpr *n = makeNode(JoinExpr);
6902 n->jointype = JOIN_INNER;
6903 n->isNatural = FALSE;
6910 | table_ref join_type JOIN table_ref join_qual
6912 JoinExpr *n = makeNode(JoinExpr);
6914 n->isNatural = FALSE;
6917 if ($5 != NULL && IsA($5, List))
6918 n->using = (List *) $5; /* USING clause */
6920 n->quals = $5; /* ON clause */
6923 | table_ref JOIN table_ref join_qual
6925 /* letting join_type reduce to empty doesn't work */
6926 JoinExpr *n = makeNode(JoinExpr);
6927 n->jointype = JOIN_INNER;
6928 n->isNatural = FALSE;
6931 if ($4 != NULL && IsA($4, List))
6932 n->using = (List *) $4; /* USING clause */
6934 n->quals = $4; /* ON clause */
6937 | table_ref NATURAL join_type JOIN table_ref
6939 JoinExpr *n = makeNode(JoinExpr);
6941 n->isNatural = TRUE;
6944 n->using = NIL; /* figure out which columns later... */
6945 n->quals = NULL; /* fill later */
6948 | table_ref NATURAL JOIN table_ref
6950 /* letting join_type reduce to empty doesn't work */
6951 JoinExpr *n = makeNode(JoinExpr);
6952 n->jointype = JOIN_INNER;
6953 n->isNatural = TRUE;
6956 n->using = NIL; /* figure out which columns later... */
6957 n->quals = NULL; /* fill later */
6963 AS ColId '(' name_list ')'
6965 $$ = makeNode(Alias);
6971 $$ = makeNode(Alias);
6974 | ColId '(' name_list ')'
6976 $$ = makeNode(Alias);
6982 $$ = makeNode(Alias);
6987 join_type: FULL join_outer { $$ = JOIN_FULL; }
6988 | LEFT join_outer { $$ = JOIN_LEFT; }
6989 | RIGHT join_outer { $$ = JOIN_RIGHT; }
6990 | INNER_P { $$ = JOIN_INNER; }
6993 /* OUTER is just noise... */
6994 join_outer: OUTER_P { $$ = NULL; }
6995 | /*EMPTY*/ { $$ = NULL; }
6998 /* JOIN qualification clauses
6999 * Possibilities are:
7000 * USING ( column list ) allows only unqualified column names,
7001 * which must match between tables.
7002 * ON expr allows more general qualifications.
7004 * We return USING as a List node, while an ON-expr will not be a List.
7007 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
7008 | ON a_expr { $$ = $2; }
7015 /* default inheritance */
7017 $$->inhOpt = INH_DEFAULT;
7020 | qualified_name '*'
7022 /* inheritance query */
7024 $$->inhOpt = INH_YES;
7027 | ONLY qualified_name
7029 /* no inheritance */
7031 $$->inhOpt = INH_NO;
7034 | ONLY '(' qualified_name ')'
7036 /* no inheritance, SQL99-style syntax */
7038 $$->inhOpt = INH_NO;
7045 * Given "UPDATE foo set set ...", we have to decide without looking any
7046 * further ahead whether the first "set" is an alias or the UPDATE's SET
7047 * keyword. Since "set" is allowed as a column name both interpretations
7048 * are feasible. We resolve the shift/reduce conflict by giving the first
7049 * relation_expr_opt_alias production a higher precedence than the SET token
7050 * has, causing the parser to prefer to reduce, in effect assuming that the
7051 * SET is not an alias.
7053 relation_expr_opt_alias: relation_expr %prec UMINUS
7057 | relation_expr ColId
7059 Alias *alias = makeNode(Alias);
7060 alias->aliasname = $2;
7064 | relation_expr AS ColId
7066 Alias *alias = makeNode(Alias);
7067 alias->aliasname = $3;
7074 func_table: func_expr { $$ = $1; }
7079 WHERE a_expr { $$ = $2; }
7080 | /*EMPTY*/ { $$ = NULL; }
7083 /* variant for UPDATE and DELETE */
7084 where_or_current_clause:
7085 WHERE a_expr { $$ = $2; }
7086 | WHERE CURRENT_P OF name
7088 CurrentOfExpr *n = makeNode(CurrentOfExpr);
7089 /* cvarno is filled in by parse analysis */
7090 n->cursor_name = $4;
7091 n->cursor_param = 0;
7094 | WHERE CURRENT_P OF PARAM
7096 CurrentOfExpr *n = makeNode(CurrentOfExpr);
7097 /* cvarno is filled in by parse analysis */
7098 n->cursor_name = NULL;
7099 n->cursor_param = $4;
7102 | /*EMPTY*/ { $$ = NULL; }
7106 TableFuncElementList:
7109 $$ = list_make1($1);
7111 | TableFuncElementList ',' TableFuncElement
7113 $$ = lappend($1, $3);
7117 TableFuncElement: ColId Typename
7119 ColumnDef *n = makeNode(ColumnDef);
7122 n->constraints = NIL;
7128 /*****************************************************************************
7131 * SQL92 introduces a large amount of type-specific syntax.
7132 * Define individual clauses to handle these cases, and use
7133 * the generic case to handle regular type-extensible Postgres syntax.
7134 * - thomas 1997-10-10
7136 *****************************************************************************/
7138 Typename: SimpleTypename opt_array_bounds
7141 $$->arrayBounds = $2;
7143 | SETOF SimpleTypename opt_array_bounds
7146 $$->arrayBounds = $3;
7149 /* SQL standard syntax, currently only one-dimensional */
7150 | SimpleTypename ARRAY '[' Iconst ']'
7153 $$->arrayBounds = list_make1(makeInteger($4));
7155 | SETOF SimpleTypename ARRAY '[' Iconst ']'
7158 $$->arrayBounds = list_make1(makeInteger($5));
7161 | SimpleTypename ARRAY
7164 $$->arrayBounds = list_make1(makeInteger(-1));
7166 | SETOF SimpleTypename ARRAY
7169 $$->arrayBounds = list_make1(makeInteger(-1));
7175 opt_array_bounds '[' ']'
7176 { $$ = lappend($1, makeInteger(-1)); }
7177 | opt_array_bounds '[' Iconst ']'
7178 { $$ = lappend($1, makeInteger($3)); }
7184 GenericType { $$ = $1; }
7185 | Numeric { $$ = $1; }
7187 | Character { $$ = $1; }
7188 | ConstDatetime { $$ = $1; }
7189 | ConstInterval opt_interval
7194 | ConstInterval '(' Iconst ')' opt_interval
7199 if (list_length($5) != 1)
7201 (errcode(ERRCODE_SYNTAX_ERROR),
7202 errmsg("interval precision specified twice"),
7203 scanner_errposition(@1)));
7204 $$->typmods = lappend($5, makeIntConst($3, @3));
7207 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
7208 makeIntConst($3, @3));
7212 /* We have a separate ConstTypename to allow defaulting fixed-length
7213 * types such as CHAR() and BIT() to an unspecified length.
7214 * SQL9x requires that these default to a length of one, but this
7215 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
7216 * where there is an obvious better choice to make.
7217 * Note that ConstInterval is not included here since it must
7218 * be pushed up higher in the rules to accomodate the postfix
7219 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
7220 * the generic-type-name case in AExprConst to avoid premature
7221 * reduce/reduce conflicts against function names.
7224 Numeric { $$ = $1; }
7225 | ConstBit { $$ = $1; }
7226 | ConstCharacter { $$ = $1; }
7227 | ConstDatetime { $$ = $1; }
7231 * GenericType covers all type names that don't have special syntax mandated
7232 * by the standard, including qualified names. We also allow type modifiers.
7233 * To avoid parsing conflicts against function invocations, the modifiers
7234 * have to be shown as expr_list here, but parse analysis will only accept
7235 * constants for them.
7238 type_function_name opt_type_modifiers
7240 $$ = makeTypeName($1);
7244 | type_function_name attrs opt_type_modifiers
7246 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
7252 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
7253 | /* EMPTY */ { $$ = NIL; }
7257 * SQL92 numeric data types
7261 $$ = SystemTypeName("int4");
7266 $$ = SystemTypeName("int4");
7271 $$ = SystemTypeName("int2");
7276 $$ = SystemTypeName("int8");
7281 $$ = SystemTypeName("float4");
7289 | DOUBLE_P PRECISION
7291 $$ = SystemTypeName("float8");
7294 | DECIMAL_P opt_type_modifiers
7296 $$ = SystemTypeName("numeric");
7300 | DEC opt_type_modifiers
7302 $$ = SystemTypeName("numeric");
7306 | NUMERIC opt_type_modifiers
7308 $$ = SystemTypeName("numeric");
7314 $$ = SystemTypeName("bool");
7319 opt_float: '(' Iconst ')'
7322 * Check FLOAT() precision limits assuming IEEE floating
7323 * types - thomas 1997-09-18
7327 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7328 errmsg("precision for type float must be at least 1 bit"),
7329 scanner_errposition(@2)));
7331 $$ = SystemTypeName("float4");
7333 $$ = SystemTypeName("float8");
7336 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7337 errmsg("precision for type float must be less than 54 bits"),
7338 scanner_errposition(@2)));
7342 $$ = SystemTypeName("float8");
7347 * SQL92 bit-field data types
7348 * The following implements BIT() and BIT VARYING().
7360 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
7361 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
7362 ConstBit: BitWithLength
7374 BIT opt_varying '(' expr_list ')'
7378 typname = $2 ? "varbit" : "bit";
7379 $$ = SystemTypeName(typname);
7388 /* bit defaults to bit(1), varbit to no limit */
7391 $$ = SystemTypeName("varbit");
7395 $$ = SystemTypeName("bit");
7396 $$->typmods = list_make1(makeIntConst(1, -1));
7404 * SQL92 character data types
7405 * The following implements CHAR() and VARCHAR().
7407 Character: CharacterWithLength
7411 | CharacterWithoutLength
7417 ConstCharacter: CharacterWithLength
7421 | CharacterWithoutLength
7423 /* Length was not specified so allow to be unrestricted.
7424 * This handles problems with fixed-length (bpchar) strings
7425 * which in column definitions must default to a length
7426 * of one, but should not be constrained if the length
7427 * was not specified.
7434 CharacterWithLength: character '(' Iconst ')' opt_charset
7436 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
7440 type = palloc(strlen($1) + 1 + strlen($5) + 1);
7447 $$ = SystemTypeName($1);
7448 $$->typmods = list_make1(makeIntConst($3, @3));
7453 CharacterWithoutLength: character opt_charset
7455 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
7459 type = palloc(strlen($1) + 1 + strlen($2) + 1);
7466 $$ = SystemTypeName($1);
7468 /* char defaults to char(1), varchar to no limit */
7469 if (strcmp($1, "bpchar") == 0)
7470 $$->typmods = list_make1(makeIntConst(1, -1));
7476 character: CHARACTER opt_varying
7477 { $$ = $2 ? "varchar": "bpchar"; }
7478 | CHAR_P opt_varying
7479 { $$ = $2 ? "varchar": "bpchar"; }
7482 | NATIONAL CHARACTER opt_varying
7483 { $$ = $3 ? "varchar": "bpchar"; }
7484 | NATIONAL CHAR_P opt_varying
7485 { $$ = $3 ? "varchar": "bpchar"; }
7487 { $$ = $2 ? "varchar": "bpchar"; }
7491 VARYING { $$ = TRUE; }
7492 | /*EMPTY*/ { $$ = FALSE; }
7496 CHARACTER SET ColId { $$ = $3; }
7497 | /*EMPTY*/ { $$ = NULL; }
7501 * SQL92 date/time types
7504 TIMESTAMP '(' Iconst ')' opt_timezone
7507 $$ = SystemTypeName("timestamptz");
7509 $$ = SystemTypeName("timestamp");
7510 $$->typmods = list_make1(makeIntConst($3, @3));
7513 | TIMESTAMP opt_timezone
7516 $$ = SystemTypeName("timestamptz");
7518 $$ = SystemTypeName("timestamp");
7521 | TIME '(' Iconst ')' opt_timezone
7524 $$ = SystemTypeName("timetz");
7526 $$ = SystemTypeName("time");
7527 $$->typmods = list_make1(makeIntConst($3, @3));
7533 $$ = SystemTypeName("timetz");
7535 $$ = SystemTypeName("time");
7543 $$ = SystemTypeName("interval");
7549 WITH_TIME ZONE { $$ = TRUE; }
7550 | WITHOUT TIME ZONE { $$ = FALSE; }
7551 | /*EMPTY*/ { $$ = FALSE; }
7556 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
7558 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
7560 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
7562 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
7564 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
7569 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
7570 INTERVAL_MASK(MONTH), @1));
7574 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
7575 INTERVAL_MASK(HOUR), @1));
7579 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
7580 INTERVAL_MASK(HOUR) |
7581 INTERVAL_MASK(MINUTE), @1));
7583 | DAY_P TO interval_second
7586 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
7587 INTERVAL_MASK(HOUR) |
7588 INTERVAL_MASK(MINUTE) |
7589 INTERVAL_MASK(SECOND), @1);
7591 | HOUR_P TO MINUTE_P
7593 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
7594 INTERVAL_MASK(MINUTE), @1));
7596 | HOUR_P TO interval_second
7599 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
7600 INTERVAL_MASK(MINUTE) |
7601 INTERVAL_MASK(SECOND), @1);
7603 | MINUTE_P TO interval_second
7606 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
7607 INTERVAL_MASK(SECOND), @1);
7616 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
7618 | SECOND_P '(' Iconst ')'
7620 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
7621 makeIntConst($3, @3));
7626 /*****************************************************************************
7628 * expression grammar
7630 *****************************************************************************/
7633 * General expressions
7634 * This is the heart of the expression syntax.
7636 * We have two expression types: a_expr is the unrestricted kind, and
7637 * b_expr is a subset that must be used in some places to avoid shift/reduce
7638 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
7639 * because that use of AND conflicts with AND as a boolean operator. So,
7640 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
7642 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
7643 * always be used by surrounding it with parens.
7645 * c_expr is all the productions that are common to a_expr and b_expr;
7646 * it's factored out just to eliminate redundant coding.
7648 a_expr: c_expr { $$ = $1; }
7649 | a_expr TYPECAST Typename
7650 { $$ = makeTypeCast($1, $3, @2); }
7651 | a_expr AT TIME ZONE a_expr
7653 FuncCall *n = makeNode(FuncCall);
7654 n->funcname = SystemFuncName("timezone");
7655 n->args = list_make2($5, $1);
7656 n->agg_star = FALSE;
7657 n->agg_distinct = FALSE;
7658 n->func_variadic = FALSE;
7663 * These operators must be called out explicitly in order to make use
7664 * of yacc/bison's automatic operator-precedence handling. All other
7665 * operator names are handled by the generic productions using "Op",
7666 * below; and all those operators will have the same precedence.
7668 * If you add more explicitly-known operators, be sure to add them
7669 * also to b_expr and to the MathOp list above.
7671 | '+' a_expr %prec UMINUS
7672 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
7673 | '-' a_expr %prec UMINUS
7674 { $$ = doNegate($2, @1); }
7676 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
7678 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
7680 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
7682 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
7684 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
7686 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
7688 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
7690 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
7692 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
7694 | a_expr qual_Op a_expr %prec Op
7695 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
7696 | qual_Op a_expr %prec Op
7697 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
7698 | a_expr qual_Op %prec POSTFIXOP
7699 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
7702 { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
7704 { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
7706 { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
7708 | a_expr LIKE a_expr
7709 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
7710 | a_expr LIKE a_expr ESCAPE a_expr
7712 FuncCall *n = makeNode(FuncCall);
7713 n->funcname = SystemFuncName("like_escape");
7714 n->args = list_make2($3, $5);
7715 n->agg_star = FALSE;
7716 n->agg_distinct = FALSE;
7717 n->func_variadic = FALSE;
7719 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
7721 | a_expr NOT LIKE a_expr
7722 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
7723 | a_expr NOT LIKE a_expr ESCAPE a_expr
7725 FuncCall *n = makeNode(FuncCall);
7726 n->funcname = SystemFuncName("like_escape");
7727 n->args = list_make2($4, $6);
7728 n->agg_star = FALSE;
7729 n->agg_distinct = FALSE;
7730 n->func_variadic = FALSE;
7732 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
7734 | a_expr ILIKE a_expr
7735 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
7736 | a_expr ILIKE a_expr ESCAPE a_expr
7738 FuncCall *n = makeNode(FuncCall);
7739 n->funcname = SystemFuncName("like_escape");
7740 n->args = list_make2($3, $5);
7741 n->agg_star = FALSE;
7742 n->agg_distinct = FALSE;
7743 n->func_variadic = FALSE;
7745 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n, @2);
7747 | a_expr NOT ILIKE a_expr
7748 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
7749 | a_expr NOT ILIKE a_expr ESCAPE a_expr
7751 FuncCall *n = makeNode(FuncCall);
7752 n->funcname = SystemFuncName("like_escape");
7753 n->args = list_make2($4, $6);
7754 n->agg_star = FALSE;
7755 n->agg_distinct = FALSE;
7756 n->func_variadic = FALSE;
7758 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n, @2);
7761 | a_expr SIMILAR TO a_expr %prec SIMILAR
7763 FuncCall *n = makeNode(FuncCall);
7764 n->funcname = SystemFuncName("similar_escape");
7765 n->args = list_make2($4, makeNullAConst(-1));
7766 n->agg_star = FALSE;
7767 n->agg_distinct = FALSE;
7768 n->func_variadic = FALSE;
7770 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
7772 | a_expr SIMILAR TO a_expr ESCAPE a_expr
7774 FuncCall *n = makeNode(FuncCall);
7775 n->funcname = SystemFuncName("similar_escape");
7776 n->args = list_make2($4, $6);
7777 n->agg_star = FALSE;
7778 n->agg_distinct = FALSE;
7779 n->func_variadic = FALSE;
7781 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
7783 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
7785 FuncCall *n = makeNode(FuncCall);
7786 n->funcname = SystemFuncName("similar_escape");
7787 n->args = list_make2($5, makeNullAConst(-1));
7788 n->agg_star = FALSE;
7789 n->agg_distinct = FALSE;
7790 n->func_variadic = FALSE;
7792 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
7794 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
7796 FuncCall *n = makeNode(FuncCall);
7797 n->funcname = SystemFuncName("similar_escape");
7798 n->args = list_make2($5, $7);
7799 n->agg_star = FALSE;
7800 n->agg_distinct = FALSE;
7801 n->func_variadic = FALSE;
7803 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
7807 * Define SQL92-style Null test clause.
7808 * Allow two forms described in the standard:
7811 * Allow two SQL extensions
7817 NullTest *n = makeNode(NullTest);
7818 n->arg = (Expr *) $1;
7819 n->nulltesttype = IS_NULL;
7824 NullTest *n = makeNode(NullTest);
7825 n->arg = (Expr *) $1;
7826 n->nulltesttype = IS_NULL;
7829 | a_expr IS NOT NULL_P
7831 NullTest *n = makeNode(NullTest);
7832 n->arg = (Expr *) $1;
7833 n->nulltesttype = IS_NOT_NULL;
7838 NullTest *n = makeNode(NullTest);
7839 n->arg = (Expr *) $1;
7840 n->nulltesttype = IS_NOT_NULL;
7845 $$ = (Node *)makeOverlaps($1, $3, @2);
7849 BooleanTest *b = makeNode(BooleanTest);
7850 b->arg = (Expr *) $1;
7851 b->booltesttype = IS_TRUE;
7854 | a_expr IS NOT TRUE_P
7856 BooleanTest *b = makeNode(BooleanTest);
7857 b->arg = (Expr *) $1;
7858 b->booltesttype = IS_NOT_TRUE;
7863 BooleanTest *b = makeNode(BooleanTest);
7864 b->arg = (Expr *) $1;
7865 b->booltesttype = IS_FALSE;
7868 | a_expr IS NOT FALSE_P
7870 BooleanTest *b = makeNode(BooleanTest);
7871 b->arg = (Expr *) $1;
7872 b->booltesttype = IS_NOT_FALSE;
7877 BooleanTest *b = makeNode(BooleanTest);
7878 b->arg = (Expr *) $1;
7879 b->booltesttype = IS_UNKNOWN;
7882 | a_expr IS NOT UNKNOWN
7884 BooleanTest *b = makeNode(BooleanTest);
7885 b->arg = (Expr *) $1;
7886 b->booltesttype = IS_NOT_UNKNOWN;
7889 | a_expr IS DISTINCT FROM a_expr %prec IS
7891 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
7893 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
7895 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
7896 (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
7901 | a_expr IS OF '(' type_list ')' %prec IS
7903 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
7905 | a_expr IS NOT OF '(' type_list ')' %prec IS
7907 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
7909 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
7911 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
7912 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
7913 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
7916 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
7918 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
7919 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
7920 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
7923 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
7925 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
7926 (Node *) makeA_Expr(AEXPR_AND, NIL,
7927 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
7928 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
7930 (Node *) makeA_Expr(AEXPR_AND, NIL,
7931 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
7932 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
7936 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
7938 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
7939 (Node *) makeA_Expr(AEXPR_OR, NIL,
7940 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
7941 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
7943 (Node *) makeA_Expr(AEXPR_OR, NIL,
7944 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
7945 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
7949 | a_expr IN_P in_expr
7951 /* in_expr returns a SubLink or a list of a_exprs */
7952 if (IsA($3, SubLink))
7954 /* generate foo = ANY (subquery) */
7955 SubLink *n = (SubLink *) $3;
7956 n->subLinkType = ANY_SUBLINK;
7958 n->operName = list_make1(makeString("="));
7964 /* generate scalar IN expression */
7965 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
7968 | a_expr NOT IN_P in_expr
7970 /* in_expr returns a SubLink or a list of a_exprs */
7971 if (IsA($4, SubLink))
7973 /* generate NOT (foo = ANY (subquery)) */
7974 /* Make an = ANY node */
7975 SubLink *n = (SubLink *) $4;
7976 n->subLinkType = ANY_SUBLINK;
7978 n->operName = list_make1(makeString("="));
7980 /* Stick a NOT on top */
7981 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
7985 /* generate scalar NOT IN expression */
7986 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
7989 | a_expr subquery_Op sub_type select_with_parens %prec Op
7991 SubLink *n = makeNode(SubLink);
7992 n->subLinkType = $3;
7999 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
8001 if ($3 == ANY_SUBLINK)
8002 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
8004 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
8006 | UNIQUE select_with_parens
8008 /* Not sure how to get rid of the parentheses
8009 * but there are lots of shift/reduce errors without them.
8011 * Should be able to implement this by plopping the entire
8012 * select into a node, then transforming the target expressions
8013 * from whatever they are into count(*), and testing the
8014 * entire result equal to one.
8015 * But, will probably implement a separate node in the executor.
8018 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8019 errmsg("UNIQUE predicate is not yet implemented"),
8020 scanner_errposition(@1)));
8022 | a_expr IS DOCUMENT_P %prec IS
8024 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8025 list_make1($1), @2);
8027 | a_expr IS NOT DOCUMENT_P %prec IS
8029 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8030 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8031 list_make1($1), @2),
8037 * Restricted expressions
8039 * b_expr is a subset of the complete expression syntax defined by a_expr.
8041 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
8042 * cause trouble in the places where b_expr is used. For simplicity, we
8043 * just eliminate all the boolean-keyword-operator productions from b_expr.
8047 | b_expr TYPECAST Typename
8048 { $$ = makeTypeCast($1, $3, @2); }
8049 | '+' b_expr %prec UMINUS
8050 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
8051 | '-' b_expr %prec UMINUS
8052 { $$ = doNegate($2, @1); }
8054 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
8056 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
8058 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
8060 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
8062 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
8064 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
8066 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
8068 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
8070 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
8071 | b_expr qual_Op b_expr %prec Op
8072 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
8073 | qual_Op b_expr %prec Op
8074 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
8075 | b_expr qual_Op %prec POSTFIXOP
8076 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
8077 | b_expr IS DISTINCT FROM b_expr %prec IS
8079 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
8081 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
8083 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
8084 NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
8086 | b_expr IS OF '(' type_list ')' %prec IS
8088 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
8090 | b_expr IS NOT OF '(' type_list ')' %prec IS
8092 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
8094 | b_expr IS DOCUMENT_P %prec IS
8096 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8097 list_make1($1), @2);
8099 | b_expr IS NOT DOCUMENT_P %prec IS
8101 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8102 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8103 list_make1($1), @2),
8109 * Productions that can be used in both a_expr and b_expr.
8111 * Note: productions that refer recursively to a_expr or b_expr mostly
8112 * cannot appear here. However, it's OK to refer to a_exprs that occur
8113 * inside parentheses, such as function arguments; that cannot introduce
8114 * ambiguity to the b_expr syntax.
8116 c_expr: columnref { $$ = $1; }
8117 | AexprConst { $$ = $1; }
8118 | PARAM opt_indirection
8120 ParamRef *p = makeNode(ParamRef);
8125 A_Indirection *n = makeNode(A_Indirection);
8126 n->arg = (Node *) p;
8127 n->indirection = check_indirection($2);
8133 | '(' a_expr ')' opt_indirection
8137 A_Indirection *n = makeNode(A_Indirection);
8139 n->indirection = check_indirection($4);
8149 | select_with_parens %prec UMINUS
8151 SubLink *n = makeNode(SubLink);
8152 n->subLinkType = EXPR_SUBLINK;
8159 | EXISTS select_with_parens
8161 SubLink *n = makeNode(SubLink);
8162 n->subLinkType = EXISTS_SUBLINK;
8169 | ARRAY select_with_parens
8171 SubLink *n = makeNode(SubLink);
8172 n->subLinkType = ARRAY_SUBLINK;
8181 A_ArrayExpr *n = (A_ArrayExpr *) $2;
8182 Assert(IsA(n, A_ArrayExpr));
8183 /* point outermost A_ArrayExpr to the ARRAY keyword */
8189 RowExpr *r = makeNode(RowExpr);
8191 r->row_typeid = InvalidOid; /* not analyzed yet */
8198 * func_expr is split out from c_expr just so that we have a classification
8199 * for "everything that is a function call or looks like one". This isn't
8200 * very important, but it saves us having to document which variants are
8201 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
8202 * (Note that many of the special SQL functions wouldn't actually make any
8203 * sense as functional index entries, but we ignore that consideration here.)
8205 func_expr: func_name '(' ')'
8207 FuncCall *n = makeNode(FuncCall);
8210 n->agg_star = FALSE;
8211 n->agg_distinct = FALSE;
8212 n->func_variadic = FALSE;
8216 | func_name '(' expr_list ')'
8218 FuncCall *n = makeNode(FuncCall);
8221 n->agg_star = FALSE;
8222 n->agg_distinct = FALSE;
8223 n->func_variadic = FALSE;
8227 | func_name '(' VARIADIC a_expr ')'
8229 FuncCall *n = makeNode(FuncCall);
8231 n->args = list_make1($4);
8232 n->agg_star = FALSE;
8233 n->agg_distinct = FALSE;
8234 n->func_variadic = TRUE;
8238 | func_name '(' expr_list ',' VARIADIC a_expr ')'
8240 FuncCall *n = makeNode(FuncCall);
8242 n->args = lappend($3, $6);
8243 n->agg_star = FALSE;
8244 n->agg_distinct = FALSE;
8245 n->func_variadic = TRUE;
8249 | func_name '(' ALL expr_list ')'
8251 FuncCall *n = makeNode(FuncCall);
8254 n->agg_star = FALSE;
8255 n->agg_distinct = FALSE;
8256 /* Ideally we'd mark the FuncCall node to indicate
8257 * "must be an aggregate", but there's no provision
8258 * for that in FuncCall at the moment.
8260 n->func_variadic = FALSE;
8264 | func_name '(' DISTINCT expr_list ')'
8266 FuncCall *n = makeNode(FuncCall);
8269 n->agg_star = FALSE;
8270 n->agg_distinct = TRUE;
8271 n->func_variadic = FALSE;
8275 | func_name '(' '*' ')'
8278 * We consider AGGREGATE(*) to invoke a parameterless
8279 * aggregate. This does the right thing for COUNT(*),
8280 * and there are no other aggregates in SQL92 that accept
8283 * The FuncCall node is also marked agg_star = true,
8284 * so that later processing can detect what the argument
8287 FuncCall *n = makeNode(FuncCall);
8291 n->agg_distinct = FALSE;
8292 n->func_variadic = FALSE;
8299 * Translate as "'now'::text::date".
8301 * We cannot use "'now'::date" because coerce_type() will
8302 * immediately reduce that to a constant representing
8303 * today's date. We need to delay the conversion until
8304 * runtime, else the wrong things will happen when
8305 * CURRENT_DATE is used in a column default value or rule.
8307 * This could be simplified if we had a way to generate
8308 * an expression tree representing runtime application
8309 * of type-input conversion functions. (As of PG 7.3
8310 * that is actually possible, but not clear that we want
8314 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8315 $$ = makeTypeCast(n, SystemTypeName("date"), -1);
8320 * Translate as "'now'::text::timetz".
8321 * See comments for CURRENT_DATE.
8324 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8325 $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
8327 | CURRENT_TIME '(' Iconst ')'
8330 * Translate as "'now'::text::timetz(n)".
8331 * See comments for CURRENT_DATE.
8335 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8336 d = SystemTypeName("timetz");
8337 d->typmods = list_make1(makeIntConst($3, @3));
8338 $$ = makeTypeCast(n, d, -1);
8343 * Translate as "now()", since we have a function that
8344 * does exactly what is needed.
8346 FuncCall *n = makeNode(FuncCall);
8347 n->funcname = SystemFuncName("now");
8349 n->agg_star = FALSE;
8350 n->agg_distinct = FALSE;
8351 n->func_variadic = FALSE;
8355 | CURRENT_TIMESTAMP '(' Iconst ')'
8358 * Translate as "'now'::text::timestamptz(n)".
8359 * See comments for CURRENT_DATE.
8363 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8364 d = SystemTypeName("timestamptz");
8365 d->typmods = list_make1(makeIntConst($3, @3));
8366 $$ = makeTypeCast(n, d, -1);
8371 * Translate as "'now'::text::time".
8372 * See comments for CURRENT_DATE.
8375 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8376 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
8378 | LOCALTIME '(' Iconst ')'
8381 * Translate as "'now'::text::time(n)".
8382 * See comments for CURRENT_DATE.
8386 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8387 d = SystemTypeName("time");
8388 d->typmods = list_make1(makeIntConst($3, @3));
8389 $$ = makeTypeCast((Node *)n, d, -1);
8394 * Translate as "'now'::text::timestamp".
8395 * See comments for CURRENT_DATE.
8398 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8399 $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
8401 | LOCALTIMESTAMP '(' Iconst ')'
8404 * Translate as "'now'::text::timestamp(n)".
8405 * See comments for CURRENT_DATE.
8409 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8410 d = SystemTypeName("timestamp");
8411 d->typmods = list_make1(makeIntConst($3, @3));
8412 $$ = makeTypeCast(n, d, -1);
8416 FuncCall *n = makeNode(FuncCall);
8417 n->funcname = SystemFuncName("current_user");
8419 n->agg_star = FALSE;
8420 n->agg_distinct = FALSE;
8421 n->func_variadic = FALSE;
8427 FuncCall *n = makeNode(FuncCall);
8428 n->funcname = SystemFuncName("current_user");
8430 n->agg_star = FALSE;
8431 n->agg_distinct = FALSE;
8432 n->func_variadic = FALSE;
8438 FuncCall *n = makeNode(FuncCall);
8439 n->funcname = SystemFuncName("session_user");
8441 n->agg_star = FALSE;
8442 n->agg_distinct = FALSE;
8443 n->func_variadic = FALSE;
8449 FuncCall *n = makeNode(FuncCall);
8450 n->funcname = SystemFuncName("current_user");
8452 n->agg_star = FALSE;
8453 n->agg_distinct = FALSE;
8454 n->func_variadic = FALSE;
8460 FuncCall *n = makeNode(FuncCall);
8461 n->funcname = SystemFuncName("current_database");
8463 n->agg_star = FALSE;
8464 n->agg_distinct = FALSE;
8465 n->func_variadic = FALSE;
8471 FuncCall *n = makeNode(FuncCall);
8472 n->funcname = SystemFuncName("current_schema");
8474 n->agg_star = FALSE;
8475 n->agg_distinct = FALSE;
8476 n->func_variadic = FALSE;
8480 | CAST '(' a_expr AS Typename ')'
8481 { $$ = makeTypeCast($3, $5, @1); }
8482 | EXTRACT '(' extract_list ')'
8484 FuncCall *n = makeNode(FuncCall);
8485 n->funcname = SystemFuncName("date_part");
8487 n->agg_star = FALSE;
8488 n->agg_distinct = FALSE;
8489 n->func_variadic = FALSE;
8493 | OVERLAY '(' overlay_list ')'
8495 /* overlay(A PLACING B FROM C FOR D) is converted to
8496 * substring(A, 1, C-1) || B || substring(A, C+1, C+D)
8497 * overlay(A PLACING B FROM C) is converted to
8498 * substring(A, 1, C-1) || B || substring(A, C+1, C+char_length(B))
8500 FuncCall *n = makeNode(FuncCall);
8501 n->funcname = SystemFuncName("overlay");
8503 n->agg_star = FALSE;
8504 n->agg_distinct = FALSE;
8505 n->func_variadic = FALSE;
8509 | POSITION '(' position_list ')'
8511 /* position(A in B) is converted to position(B, A) */
8512 FuncCall *n = makeNode(FuncCall);
8513 n->funcname = SystemFuncName("position");
8515 n->agg_star = FALSE;
8516 n->agg_distinct = FALSE;
8517 n->func_variadic = FALSE;
8521 | SUBSTRING '(' substr_list ')'
8523 /* substring(A from B for C) is converted to
8524 * substring(A, B, C) - thomas 2000-11-28
8526 FuncCall *n = makeNode(FuncCall);
8527 n->funcname = SystemFuncName("substring");
8529 n->agg_star = FALSE;
8530 n->agg_distinct = FALSE;
8531 n->func_variadic = FALSE;
8535 | TREAT '(' a_expr AS Typename ')'
8537 /* TREAT(expr AS target) converts expr of a particular type to target,
8538 * which is defined to be a subtype of the original expression.
8539 * In SQL99, this is intended for use with structured UDTs,
8540 * but let's make this a generally useful form allowing stronger
8541 * coercions than are handled by implicit casting.
8543 FuncCall *n = makeNode(FuncCall);
8544 /* Convert SystemTypeName() to SystemFuncName() even though
8545 * at the moment they result in the same thing.
8547 n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
8548 n->args = list_make1($3);
8549 n->agg_star = FALSE;
8550 n->agg_distinct = FALSE;
8551 n->func_variadic = FALSE;
8555 | TRIM '(' BOTH trim_list ')'
8557 /* various trim expressions are defined in SQL92
8558 * - thomas 1997-07-19
8560 FuncCall *n = makeNode(FuncCall);
8561 n->funcname = SystemFuncName("btrim");
8563 n->agg_star = FALSE;
8564 n->agg_distinct = FALSE;
8565 n->func_variadic = FALSE;
8569 | TRIM '(' LEADING trim_list ')'
8571 FuncCall *n = makeNode(FuncCall);
8572 n->funcname = SystemFuncName("ltrim");
8574 n->agg_star = FALSE;
8575 n->agg_distinct = FALSE;
8576 n->func_variadic = FALSE;
8580 | TRIM '(' TRAILING trim_list ')'
8582 FuncCall *n = makeNode(FuncCall);
8583 n->funcname = SystemFuncName("rtrim");
8585 n->agg_star = FALSE;
8586 n->agg_distinct = FALSE;
8587 n->func_variadic = FALSE;
8591 | TRIM '(' trim_list ')'
8593 FuncCall *n = makeNode(FuncCall);
8594 n->funcname = SystemFuncName("btrim");
8596 n->agg_star = FALSE;
8597 n->agg_distinct = FALSE;
8598 n->func_variadic = FALSE;
8602 | NULLIF '(' a_expr ',' a_expr ')'
8604 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
8606 | COALESCE '(' expr_list ')'
8608 CoalesceExpr *c = makeNode(CoalesceExpr);
8613 | GREATEST '(' expr_list ')'
8615 MinMaxExpr *v = makeNode(MinMaxExpr);
8617 v->op = IS_GREATEST;
8621 | LEAST '(' expr_list ')'
8623 MinMaxExpr *v = makeNode(MinMaxExpr);
8629 | XMLCONCAT '(' expr_list ')'
8631 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
8633 | XMLELEMENT '(' NAME_P ColLabel ')'
8635 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
8637 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
8639 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
8641 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
8643 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
8645 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
8647 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
8649 | XMLFOREST '(' xml_attribute_list ')'
8651 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
8653 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
8655 XmlExpr *x = (XmlExpr *)
8656 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
8657 list_make2($4, makeBoolAConst($5, -1)),
8662 | XMLPI '(' NAME_P ColLabel ')'
8664 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
8666 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
8668 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
8670 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
8672 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
8673 list_make3($3, $5, $6), @1);
8675 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
8677 XmlSerialize *n = makeNode(XmlSerialize);
8689 xml_root_version: VERSION_P a_expr
8691 | VERSION_P NO VALUE_P
8692 { $$ = makeNullAConst(-1); }
8695 opt_xml_root_standalone: ',' STANDALONE_P YES_P
8696 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
8697 | ',' STANDALONE_P NO
8698 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
8699 | ',' STANDALONE_P NO VALUE_P
8700 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
8702 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
8705 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
8708 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
8709 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
8712 xml_attribute_el: a_expr AS ColLabel
8714 $$ = makeNode(ResTarget);
8716 $$->indirection = NIL;
8717 $$->val = (Node *) $1;
8722 $$ = makeNode(ResTarget);
8724 $$->indirection = NIL;
8725 $$->val = (Node *) $1;
8730 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
8731 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
8734 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
8735 | STRIP_P WHITESPACE_P { $$ = FALSE; }
8736 | /*EMPTY*/ { $$ = FALSE; }
8740 * Supporting nonterminals for expressions.
8743 /* Explicit row production.
8745 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
8746 * without conflicting with the parenthesized a_expr production. Without the
8747 * ROW keyword, there must be more than one a_expr inside the parens.
8749 row: ROW '(' expr_list ')' { $$ = $3; }
8750 | ROW '(' ')' { $$ = NIL; }
8751 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
8754 sub_type: ANY { $$ = ANY_SUBLINK; }
8755 | SOME { $$ = ANY_SUBLINK; }
8756 | ALL { $$ = ALL_SUBLINK; }
8759 all_Op: Op { $$ = $1; }
8760 | MathOp { $$ = $1; }
8763 MathOp: '+' { $$ = "+"; }
8775 { $$ = list_make1(makeString($1)); }
8776 | OPERATOR '(' any_operator ')'
8782 { $$ = list_make1(makeString($1)); }
8783 | OPERATOR '(' any_operator ')'
8789 { $$ = list_make1(makeString($1)); }
8790 | OPERATOR '(' any_operator ')'
8793 { $$ = list_make1(makeString("~~")); }
8795 { $$ = list_make1(makeString("!~~")); }
8797 { $$ = list_make1(makeString("~~*")); }
8799 { $$ = list_make1(makeString("!~~*")); }
8800 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
8801 * the regular expression is preprocessed by a function (similar_escape),
8802 * and the ~ operator for posix regular expressions is used.
8803 * x SIMILAR TO y -> x ~ similar_escape(y)
8804 * this transformation is made on the fly by the parser upwards.
8805 * however the SubLink structure which handles any/some/all stuff
8806 * is not ready for such a thing.
8812 $$ = list_make1($1);
8814 | expr_list ',' a_expr
8816 $$ = lappend($1, $3);
8820 type_list: Typename { $$ = list_make1($1); }
8821 | type_list ',' Typename { $$ = lappend($1, $3); }
8824 array_expr: '[' expr_list ']'
8826 $$ = makeAArrayExpr($2, @1);
8828 | '[' array_expr_list ']'
8830 $$ = makeAArrayExpr($2, @1);
8834 $$ = makeAArrayExpr(NIL, @1);
8838 array_expr_list: array_expr { $$ = list_make1($1); }
8839 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
8844 extract_arg FROM a_expr
8846 $$ = list_make2(makeStringConst($1, @1), $3);
8848 | /*EMPTY*/ { $$ = NIL; }
8851 /* Allow delimited string Sconst in extract_arg as an SQL extension.
8852 * - thomas 2001-04-12
8856 | YEAR_P { $$ = "year"; }
8857 | MONTH_P { $$ = "month"; }
8858 | DAY_P { $$ = "day"; }
8859 | HOUR_P { $$ = "hour"; }
8860 | MINUTE_P { $$ = "minute"; }
8861 | SECOND_P { $$ = "second"; }
8862 | Sconst { $$ = $1; }
8865 /* OVERLAY() arguments
8866 * SQL99 defines the OVERLAY() function:
8867 * o overlay(text placing text from int for int)
8868 * o overlay(text placing text from int)
8871 a_expr overlay_placing substr_from substr_for
8873 $$ = list_make4($1, $2, $3, $4);
8875 | a_expr overlay_placing substr_from
8877 $$ = list_make3($1, $2, $3);
8886 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
8889 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
8890 | /*EMPTY*/ { $$ = NIL; }
8893 /* SUBSTRING() arguments
8894 * SQL9x defines a specific syntax for arguments to SUBSTRING():
8895 * o substring(text from int for int)
8896 * o substring(text from int) get entire string from starting point "int"
8897 * o substring(text for int) get first "int" characters of string
8898 * o substring(text from pattern) get entire string matching pattern
8899 * o substring(text from pattern for escape) same with specified escape char
8900 * We also want to support generic substring functions which accept
8901 * the usual generic list of arguments. So we will accept both styles
8902 * here, and convert the SQL9x style to the generic list for further
8903 * processing. - thomas 2000-11-28
8906 a_expr substr_from substr_for
8908 $$ = list_make3($1, $2, $3);
8910 | a_expr substr_for substr_from
8912 /* not legal per SQL99, but might as well allow it */
8913 $$ = list_make3($1, $3, $2);
8915 | a_expr substr_from
8917 $$ = list_make2($1, $2);
8922 * Since there are no cases where this syntax allows
8923 * a textual FOR value, we forcibly cast the argument
8924 * to int4. The possible matches in pg_proc are
8925 * substring(text,int4) and substring(text,text),
8926 * and we don't want the parser to choose the latter,
8927 * which it is likely to do if the second argument
8928 * is unknown or doesn't have an implicit cast to int4.
8930 $$ = list_make3($1, makeIntConst(1, -1),
8932 SystemTypeName("int4"), -1));
8943 FROM a_expr { $$ = $2; }
8946 substr_for: FOR a_expr { $$ = $2; }
8949 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
8950 | FROM expr_list { $$ = $2; }
8951 | expr_list { $$ = $1; }
8954 in_expr: select_with_parens
8956 SubLink *n = makeNode(SubLink);
8958 /* other fields will be filled later */
8961 | '(' expr_list ')' { $$ = (Node *)$2; }
8965 * Define SQL92-style case clause.
8966 * - Full specification
8967 * CASE WHEN a = b THEN c ... ELSE d END
8968 * - Implicit argument
8969 * CASE a WHEN b THEN c ... ELSE d END
8971 case_expr: CASE case_arg when_clause_list case_default END_P
8973 CaseExpr *c = makeNode(CaseExpr);
8974 c->casetype = InvalidOid; /* not analyzed yet */
8975 c->arg = (Expr *) $2;
8977 c->defresult = (Expr *) $4;
8984 /* There must be at least one */
8985 when_clause { $$ = list_make1($1); }
8986 | when_clause_list when_clause { $$ = lappend($1, $2); }
8990 WHEN a_expr THEN a_expr
8992 CaseWhen *w = makeNode(CaseWhen);
8993 w->expr = (Expr *) $2;
8994 w->result = (Expr *) $4;
9001 ELSE a_expr { $$ = $2; }
9002 | /*EMPTY*/ { $$ = NULL; }
9005 case_arg: a_expr { $$ = $1; }
9006 | /*EMPTY*/ { $$ = NULL; }
9010 * columnref starts with relation_name not ColId, so that OLD and NEW
9011 * references can be accepted. Note that when there are more than two
9012 * dotted names, the first name is not actually a relation name...
9014 columnref: relation_name
9016 $$ = makeColumnRef($1, NIL, @1);
9018 | relation_name indirection
9020 $$ = makeColumnRef($1, $2, @1);
9027 $$ = (Node *) makeString($2);
9031 $$ = (Node *) makeNode(A_Star);
9035 A_Indices *ai = makeNode(A_Indices);
9040 | '[' a_expr ':' a_expr ']'
9042 A_Indices *ai = makeNode(A_Indices);
9050 indirection_el { $$ = list_make1($1); }
9051 | indirection indirection_el { $$ = lappend($1, $2); }
9055 /*EMPTY*/ { $$ = NIL; }
9056 | opt_indirection indirection_el { $$ = lappend($1, $2); }
9059 opt_asymmetric: ASYMMETRIC
9064 * The SQL spec defines "contextually typed value expressions" and
9065 * "contextually typed row value constructors", which for our purposes
9066 * are the same as "a_expr" and "row" except that DEFAULT can appear at
9071 a_expr { $$ = (Node *) $1; }
9074 SetToDefault *n = makeNode(SetToDefault);
9081 ctext_expr { $$ = list_make1($1); }
9082 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
9086 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
9087 * making VALUES a fully reserved word, which will probably break more apps
9088 * than allowing the noise-word is worth.
9090 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
9094 /*****************************************************************************
9096 * target list for SELECT
9098 *****************************************************************************/
9101 target_el { $$ = list_make1($1); }
9102 | target_list ',' target_el { $$ = lappend($1, $3); }
9105 target_el: a_expr AS ColLabel
9107 $$ = makeNode(ResTarget);
9109 $$->indirection = NIL;
9110 $$->val = (Node *)$1;
9114 * We support omitting AS only for column labels that aren't
9115 * any known keyword. There is an ambiguity against postfix
9116 * operators: is "a ! b" an infix expression, or a postfix
9117 * expression and a column label? We prefer to resolve this
9118 * as an infix expression, which we accomplish by assigning
9119 * IDENT a precedence higher than POSTFIXOP.
9123 $$ = makeNode(ResTarget);
9125 $$->indirection = NIL;
9126 $$->val = (Node *)$1;
9131 $$ = makeNode(ResTarget);
9133 $$->indirection = NIL;
9134 $$->val = (Node *)$1;
9139 ColumnRef *n = makeNode(ColumnRef);
9140 n->fields = list_make1(makeNode(A_Star));
9143 $$ = makeNode(ResTarget);
9145 $$->indirection = NIL;
9146 $$->val = (Node *)n;
9152 /*****************************************************************************
9154 * Names and constants
9156 *****************************************************************************/
9159 SpecialRuleRelation { $$ = $1; }
9160 | ColId { $$ = $1; }
9163 qualified_name_list:
9164 qualified_name { $$ = list_make1($1); }
9165 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
9169 * The production for a qualified relation name has to exactly match the
9170 * production for a qualified func_name, because in a FROM clause we cannot
9171 * tell which we are parsing until we see what comes after it ('(' for a
9172 * func_name, something else for a relation). Therefore we allow 'indirection'
9173 * which may contain subscripts, and reject that case in the C code.
9178 $$ = makeNode(RangeVar);
9179 $$->catalogname = NULL;
9180 $$->schemaname = NULL;
9184 | relation_name indirection
9186 check_qualified_name($2);
9187 $$ = makeNode(RangeVar);
9188 switch (list_length($2))
9191 $$->catalogname = NULL;
9192 $$->schemaname = $1;
9193 $$->relname = strVal(linitial($2));
9196 $$->catalogname = $1;
9197 $$->schemaname = strVal(linitial($2));
9198 $$->relname = strVal(lsecond($2));
9202 (errcode(ERRCODE_SYNTAX_ERROR),
9203 errmsg("improper qualified name (too many dotted names): %s",
9204 NameListToString(lcons(makeString($1), $2))),
9205 scanner_errposition(@1)));
9213 { $$ = list_make1(makeString($1)); }
9214 | name_list ',' name
9215 { $$ = lappend($1, makeString($3)); }
9219 name: ColId { $$ = $1; };
9227 attr_name: ColLabel { $$ = $1; };
9229 index_name: ColId { $$ = $1; };
9231 file_name: Sconst { $$ = $1; };
9234 * The production for a qualified func_name has to exactly match the
9235 * production for a qualified columnref, because we cannot tell which we
9236 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
9237 * anything else for a columnref). Therefore we allow 'indirection' which
9238 * may contain subscripts, and reject that case in the C code. (If we
9239 * ever implement SQL99-like methods, such syntax may actually become legal!)
9241 func_name: type_function_name
9242 { $$ = list_make1(makeString($1)); }
9243 | relation_name indirection
9244 { $$ = check_func_name(lcons(makeString($1), $2)); }
9253 $$ = makeIntConst($1, @1);
9257 $$ = makeFloatConst($1, @1);
9261 $$ = makeStringConst($1, @1);
9265 $$ = makeBitStringConst($1, @1);
9269 /* This is a bit constant per SQL99:
9270 * Without Feature F511, "BIT data type",
9271 * a <general literal> shall not be a
9272 * <bit string literal> or a <hex string literal>.
9274 $$ = makeBitStringConst($1, @1);
9278 /* generic type 'literal' syntax */
9279 TypeName *t = makeTypeNameFromNameList($1);
9281 $$ = makeStringConstCast($2, @2, t);
9283 | func_name '(' expr_list ')' Sconst
9285 /* generic syntax with a type modifier */
9286 TypeName *t = makeTypeNameFromNameList($1);
9289 $$ = makeStringConstCast($5, @5, t);
9291 | ConstTypename Sconst
9293 $$ = makeStringConstCast($2, @2, $1);
9295 | ConstInterval Sconst opt_interval
9299 $$ = makeStringConstCast($2, @2, t);
9301 | ConstInterval '(' Iconst ')' Sconst opt_interval
9306 if (list_length($6) != 1)
9308 (errcode(ERRCODE_SYNTAX_ERROR),
9309 errmsg("interval precision specified twice"),
9310 scanner_errposition(@1)));
9311 t->typmods = lappend($6, makeIntConst($3, @3));
9314 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
9315 makeIntConst($3, @3));
9316 $$ = makeStringConstCast($5, @5, t);
9320 $$ = makeBoolAConst(TRUE, @1);
9324 $$ = makeBoolAConst(FALSE, @1);
9328 $$ = makeNullAConst(@1);
9332 Iconst: ICONST { $$ = $1; };
9333 Sconst: SCONST { $$ = $1; };
9334 RoleId: ColId { $$ = $1; };
9336 SignedIconst: Iconst { $$ = $1; }
9337 | '+' Iconst { $$ = + $2; }
9338 | '-' Iconst { $$ = - $2; }
9342 * Name classification hierarchy.
9344 * IDENT is the lexeme returned by the lexer for identifiers that match
9345 * no known keyword. In most cases, we can accept certain keywords as
9346 * names, not only IDENTs. We prefer to accept as many such keywords
9347 * as possible to minimize the impact of "reserved words" on programmers.
9348 * So, we divide names into several possible classes. The classification
9349 * is chosen in part to make keywords acceptable as names wherever possible.
9352 /* Column identifier --- names that can be column, table, etc names.
9354 ColId: IDENT { $$ = $1; }
9355 | unreserved_keyword { $$ = pstrdup($1); }
9356 | col_name_keyword { $$ = pstrdup($1); }
9359 /* Type/function identifier --- names that can be type or function names.
9361 type_function_name: IDENT { $$ = $1; }
9362 | unreserved_keyword { $$ = pstrdup($1); }
9363 | type_func_name_keyword { $$ = pstrdup($1); }
9366 /* Column label --- allowed labels in "AS" clauses.
9367 * This presently includes *all* Postgres keywords.
9369 ColLabel: IDENT { $$ = $1; }
9370 | unreserved_keyword { $$ = pstrdup($1); }
9371 | col_name_keyword { $$ = pstrdup($1); }
9372 | type_func_name_keyword { $$ = pstrdup($1); }
9373 | reserved_keyword { $$ = pstrdup($1); }
9378 * Keyword category lists. Generally, every keyword present in
9379 * the Postgres grammar should appear in exactly one of these lists.
9381 * Put a new keyword into the first list that it can go into without causing
9382 * shift or reduce conflicts. The earlier lists define "less reserved"
9383 * categories of keywords.
9385 * Make sure that each keyword's category in keywords.c matches where
9386 * it is listed here. (Someday we may be able to generate these lists and
9387 * keywords.c's table from a common master list.)
9390 /* "Unreserved" keywords --- available for use as any kind of name.
9632 /* Column identifier --- keywords that can be column, table, etc names.
9634 * Many of these keywords will in fact be recognized as type or function
9635 * names too; but they have special productions for the purpose, and so
9636 * can't be treated as "generic" type or function names.
9638 * The type names appearing here are not usable as function names
9639 * because they can be followed by '(' in typename productions, which
9640 * looks too much like a function call for an LR(1) parser.
9690 /* Type/function identifier --- keywords that can be type or function names.
9692 * Most of these are keywords that are used as operators in expressions;
9693 * in general such keywords can't be column names because they would be
9694 * ambiguous with variables, but they are unambiguous as function identifiers.
9696 * Do not include POSITION, SUBSTRING, etc here since they have explicit
9697 * productions in a_expr to support the goofy SQL9x argument syntax.
9698 * - thomas 2000-11-28
9700 type_func_name_keyword:
9724 /* Reserved keyword --- these keywords are usable only as a ColLabel.
9726 * Keywords appear here if they could not be distinguished from variable,
9727 * type, or function names in some contexts. Don't put things here unless
9812 SpecialRuleRelation:
9819 (errcode(ERRCODE_SYNTAX_ERROR),
9820 errmsg("OLD used in query that is not in a rule"),
9821 scanner_errposition(@1)));
9829 (errcode(ERRCODE_SYNTAX_ERROR),
9830 errmsg("NEW used in query that is not in a rule"),
9831 scanner_errposition(@1)));
9838 makeColumnRef(char *colname, List *indirection, int location)
9841 * Generate a ColumnRef node, with an A_Indirection node added if there
9842 * is any subscripting in the specified indirection list. However,
9843 * any field selection at the start of the indirection list must be
9844 * transposed into the "fields" part of the ColumnRef node.
9846 ColumnRef *c = makeNode(ColumnRef);
9850 c->location = location;
9851 foreach(l, indirection)
9853 if (IsA(lfirst(l), A_Indices))
9855 A_Indirection *i = makeNode(A_Indirection);
9859 /* easy case - all indirection goes to A_Indirection */
9860 c->fields = list_make1(makeString(colname));
9861 i->indirection = check_indirection(indirection);
9865 /* got to split the list in two */
9866 i->indirection = check_indirection(list_copy_tail(indirection,
9868 indirection = list_truncate(indirection, nfields);
9869 c->fields = lcons(makeString(colname), indirection);
9871 i->arg = (Node *) c;
9874 else if (IsA(lfirst(l), A_Star))
9876 /* We only allow '*' at the end of a ColumnRef */
9877 if (lnext(l) != NULL)
9878 yyerror("improper use of \"*\"");
9882 /* No subscripting, so all indirection gets added to field list */
9883 c->fields = lcons(makeString(colname), indirection);
9888 makeTypeCast(Node *arg, TypeName *typename, int location)
9890 TypeCast *n = makeNode(TypeCast);
9892 n->typename = typename;
9893 n->location = location;
9898 makeStringConst(char *str, int location)
9900 A_Const *n = makeNode(A_Const);
9902 n->val.type = T_String;
9903 n->val.val.str = str;
9904 n->location = location;
9910 makeStringConstCast(char *str, int location, TypeName *typename)
9912 Node *s = makeStringConst(str, location);
9914 return makeTypeCast(s, typename, -1);
9918 makeIntConst(int val, int location)
9920 A_Const *n = makeNode(A_Const);
9922 n->val.type = T_Integer;
9923 n->val.val.ival = val;
9924 n->location = location;
9930 makeFloatConst(char *str, int location)
9932 A_Const *n = makeNode(A_Const);
9934 n->val.type = T_Float;
9935 n->val.val.str = str;
9936 n->location = location;
9942 makeBitStringConst(char *str, int location)
9944 A_Const *n = makeNode(A_Const);
9946 n->val.type = T_BitString;
9947 n->val.val.str = str;
9948 n->location = location;
9954 makeNullAConst(int location)
9956 A_Const *n = makeNode(A_Const);
9958 n->val.type = T_Null;
9959 n->location = location;
9965 makeAConst(Value *v, int location)
9972 n = makeFloatConst(v->val.str, location);
9976 n = makeIntConst(v->val.ival, location);
9981 n = makeStringConst(v->val.str, location);
9989 * Create an A_Const string node and put it inside a boolean cast.
9992 makeBoolAConst(bool state, int location)
9994 A_Const *n = makeNode(A_Const);
9996 n->val.type = T_String;
9997 n->val.val.str = (state ? "t" : "f");
9998 n->location = location;
10000 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
10004 * Create and populate a FuncCall node to support the OVERLAPS operator.
10007 makeOverlaps(List *largs, List *rargs, int location)
10009 FuncCall *n = makeNode(FuncCall);
10011 n->funcname = SystemFuncName("overlaps");
10012 if (list_length(largs) == 1)
10013 largs = lappend(largs, largs);
10014 else if (list_length(largs) != 2)
10016 (errcode(ERRCODE_SYNTAX_ERROR),
10017 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
10018 scanner_errposition(location)));
10019 if (list_length(rargs) == 1)
10020 rargs = lappend(rargs, rargs);
10021 else if (list_length(rargs) != 2)
10023 (errcode(ERRCODE_SYNTAX_ERROR),
10024 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
10025 scanner_errposition(location)));
10026 n->args = list_concat(largs, rargs);
10027 n->agg_star = FALSE;
10028 n->agg_distinct = FALSE;
10029 n->func_variadic = FALSE;
10030 n->location = location;
10034 /* check_qualified_name --- check the result of qualified_name production
10036 * It's easiest to let the grammar production for qualified_name allow
10037 * subscripts and '*', which we then must reject here.
10040 check_qualified_name(List *names)
10046 if (!IsA(lfirst(i), String))
10047 yyerror("syntax error");
10051 /* check_func_name --- check the result of func_name production
10053 * It's easiest to let the grammar production for func_name allow subscripts
10054 * and '*', which we then must reject here.
10057 check_func_name(List *names)
10063 if (!IsA(lfirst(i), String))
10064 yyerror("syntax error");
10069 /* check_indirection --- check the result of indirection production
10071 * We only allow '*' at the end of the list, but it's hard to enforce that
10072 * in the grammar, so do it here.
10075 check_indirection(List *indirection)
10079 foreach(l, indirection)
10081 if (IsA(lfirst(l), A_Star))
10083 if (lnext(l) != NULL)
10084 yyerror("improper use of \"*\"");
10087 return indirection;
10090 /* extractArgTypes()
10091 * Given a list of FunctionParameter nodes, extract a list of just the
10092 * argument types (TypeNames) for input parameters only. This is what
10093 * is needed to look up an existing function, which is what is wanted by
10094 * the productions that use this call.
10097 extractArgTypes(List *parameters)
10099 List *result = NIL;
10102 foreach(i, parameters)
10104 FunctionParameter *p = (FunctionParameter *) lfirst(i);
10106 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
10107 result = lappend(result, p->argType);
10112 /* findLeftmostSelect()
10113 * Find the leftmost component SelectStmt in a set-operation parsetree.
10115 static SelectStmt *
10116 findLeftmostSelect(SelectStmt *node)
10118 while (node && node->op != SETOP_NONE)
10120 Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
10124 /* insertSelectOptions()
10125 * Insert ORDER BY, etc into an already-constructed SelectStmt.
10127 * This routine is just to avoid duplicating code in SelectStmt productions.
10130 insertSelectOptions(SelectStmt *stmt,
10131 List *sortClause, List *lockingClause,
10132 Node *limitOffset, Node *limitCount,
10133 WithClause *withClause)
10135 Assert(IsA(stmt, SelectStmt));
10138 * Tests here are to reject constructs like
10139 * (SELECT foo ORDER BY bar) ORDER BY baz
10143 if (stmt->sortClause)
10145 (errcode(ERRCODE_SYNTAX_ERROR),
10146 errmsg("multiple ORDER BY clauses not allowed"),
10147 scanner_errposition(exprLocation((Node *) sortClause))));
10148 stmt->sortClause = sortClause;
10150 /* We can handle multiple locking clauses, though */
10151 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
10154 if (stmt->limitOffset)
10156 (errcode(ERRCODE_SYNTAX_ERROR),
10157 errmsg("multiple OFFSET clauses not allowed"),
10158 scanner_errposition(exprLocation(limitOffset))));
10159 stmt->limitOffset = limitOffset;
10163 if (stmt->limitCount)
10165 (errcode(ERRCODE_SYNTAX_ERROR),
10166 errmsg("multiple LIMIT clauses not allowed"),
10167 scanner_errposition(exprLocation(limitCount))));
10168 stmt->limitCount = limitCount;
10172 if (stmt->withClause)
10174 (errcode(ERRCODE_SYNTAX_ERROR),
10175 errmsg("multiple WITH clauses not allowed"),
10176 scanner_errposition(exprLocation((Node *) withClause))));
10177 stmt->withClause = withClause;
10182 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
10184 SelectStmt *n = makeNode(SelectStmt);
10188 n->larg = (SelectStmt *) larg;
10189 n->rarg = (SelectStmt *) rarg;
10193 /* SystemFuncName()
10194 * Build a properly-qualified reference to a built-in function.
10197 SystemFuncName(char *name)
10199 return list_make2(makeString("pg_catalog"), makeString(name));
10202 /* SystemTypeName()
10203 * Build a properly-qualified reference to a built-in type.
10205 * typmod is defaulted, but may be changed afterwards by caller.
10206 * Likewise for the location.
10209 SystemTypeName(char *name)
10211 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
10212 makeString(name)));
10216 * Handle negation of a numeric constant.
10218 * Formerly, we did this here because the optimizer couldn't cope with
10219 * indexquals that looked like "var = -4" --- it wants "var = const"
10220 * and a unary minus operator applied to a constant didn't qualify.
10221 * As of Postgres 7.0, that problem doesn't exist anymore because there
10222 * is a constant-subexpression simplifier in the optimizer. However,
10223 * there's still a good reason for doing this here, which is that we can
10224 * postpone committing to a particular internal representation for simple
10225 * negative constants. It's better to leave "-123.456" in string form
10226 * until we know what the desired type is.
10229 doNegate(Node *n, int location)
10231 if (IsA(n, A_Const))
10233 A_Const *con = (A_Const *)n;
10235 /* report the constant's location as that of the '-' sign */
10236 con->location = location;
10238 if (con->val.type == T_Integer)
10240 con->val.val.ival = -con->val.val.ival;
10243 if (con->val.type == T_Float)
10245 doNegateFloat(&con->val);
10250 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
10254 doNegateFloat(Value *v)
10256 char *oldval = v->val.str;
10258 Assert(IsA(v, Float));
10259 if (*oldval == '+')
10261 if (*oldval == '-')
10262 v->val.str = oldval+1; /* just strip the '-' */
10265 char *newval = (char *) palloc(strlen(oldval) + 2);
10268 strcpy(newval+1, oldval);
10269 v->val.str = newval;
10274 makeAArrayExpr(List *elements, int location)
10276 A_ArrayExpr *n = makeNode(A_ArrayExpr);
10278 n->elements = elements;
10279 n->location = location;
10284 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
10287 XmlExpr *x = makeNode(XmlExpr);
10292 * named_args is a list of ResTarget; it'll be split apart into separate
10293 * expression and name lists in transformXmlExpr().
10295 x->named_args = named_args;
10296 x->arg_names = NIL;
10298 /* xmloption, if relevant, must be filled in by caller */
10299 /* type and typmod will be filled in during parse analysis */
10300 x->location = location;
10305 * Initialize to parse one query string
10310 QueryIsRule = FALSE;
10314 * Merge the input and output parameters of a table function.
10317 mergeTableFuncParameters(List *func_args, List *columns)
10321 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
10322 foreach(lc, func_args)
10324 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
10326 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
10328 (errcode(ERRCODE_SYNTAX_ERROR),
10329 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
10332 return list_concat(func_args, columns);
10336 * Determine return type of a TABLE function. A single result column
10337 * returns setof that column's type; otherwise return setof record.
10340 TableFuncTypeName(List *columns)
10344 if (list_length(columns) == 1)
10346 FunctionParameter *p = (FunctionParameter *) linitial(columns);
10348 result = (TypeName *) copyObject(p->argType);
10351 result = SystemTypeName("record");
10353 result->setof = true;
10359 * Must undefine base_yylex before including scan.c, since we want it
10360 * to create the function base_yylex not filtered_base_yylex.