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.630 2008/10/27 09:37:47 petere 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
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_CASCADED WITH_LOCAL WITH_CHECK
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
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;
2441 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
2443 $$ = makeNode(IntoClause);
2448 $$->tableSpaceName = $5;
2453 '(' CreateAsList ')' { $$ = $2; }
2454 | /*EMPTY*/ { $$ = NIL; }
2458 CreateAsElement { $$ = list_make1($1); }
2459 | CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); }
2465 ColumnDef *n = makeNode(ColumnDef);
2470 n->is_not_null = false;
2471 n->raw_default = NULL;
2472 n->cooked_default = NULL;
2473 n->constraints = NIL;
2479 /*****************************************************************************
2482 * CREATE SEQUENCE seqname
2483 * ALTER SEQUENCE seqname
2485 *****************************************************************************/
2488 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
2490 CreateSeqStmt *n = makeNode(CreateSeqStmt);
2499 ALTER SEQUENCE relation_expr SeqOptList
2501 AlterSeqStmt *n = makeNode(AlterSeqStmt);
2508 OptSeqOptList: SeqOptList { $$ = $1; }
2509 | /*EMPTY*/ { $$ = NIL; }
2512 SeqOptList: SeqOptElem { $$ = list_make1($1); }
2513 | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
2516 SeqOptElem: CACHE NumericOnly
2518 $$ = makeDefElem("cache", (Node *)$2);
2522 $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE));
2526 $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE));
2528 | INCREMENT opt_by NumericOnly
2530 $$ = makeDefElem("increment", (Node *)$3);
2532 | MAXVALUE NumericOnly
2534 $$ = makeDefElem("maxvalue", (Node *)$2);
2536 | MINVALUE NumericOnly
2538 $$ = makeDefElem("minvalue", (Node *)$2);
2542 $$ = makeDefElem("maxvalue", NULL);
2546 $$ = makeDefElem("minvalue", NULL);
2550 $$ = makeDefElem("owned_by", (Node *)$3);
2552 | START opt_with NumericOnly
2554 $$ = makeDefElem("start", (Node *)$3);
2558 $$ = makeDefElem("restart", NULL);
2560 | RESTART opt_with NumericOnly
2562 $$ = makeDefElem("restart", (Node *)$3);
2571 FloatOnly { $$ = $1; }
2572 | IntegerOnly { $$ = $1; }
2575 FloatOnly: FCONST { $$ = makeFloat($1); }
2583 IntegerOnly: SignedIconst { $$ = makeInteger($1); };
2586 /*****************************************************************************
2589 * CREATE PROCEDURAL LANGUAGE ...
2590 * DROP PROCEDURAL LANGUAGE ...
2592 *****************************************************************************/
2595 CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2597 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2599 /* parameters are all to be supplied by system */
2601 n->plvalidator = NIL;
2602 n->pltrusted = false;
2605 | CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2606 HANDLER handler_name opt_validator opt_lancompiler
2608 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2611 n->plvalidator = $8;
2613 /* LANCOMPILER is now ignored entirely */
2619 TRUSTED { $$ = TRUE; }
2620 | /*EMPTY*/ { $$ = FALSE; }
2623 /* This ought to be just func_name, but that causes reduce/reduce conflicts
2624 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
2625 * Work around by using simple names, instead.
2628 name { $$ = list_make1(makeString($1)); }
2629 | name attrs { $$ = lcons(makeString($1), $2); }
2633 VALIDATOR handler_name { $$ = $2; }
2634 | /*EMPTY*/ { $$ = NIL; }
2638 LANCOMPILER Sconst { $$ = $2; }
2639 | /*EMPTY*/ { $$ = NULL; }
2643 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
2645 DropPLangStmt *n = makeNode(DropPLangStmt);
2648 n->missing_ok = false;
2651 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
2653 DropPLangStmt *n = makeNode(DropPLangStmt);
2656 n->missing_ok = true;
2666 /*****************************************************************************
2669 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
2671 *****************************************************************************/
2673 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
2675 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
2676 n->tablespacename = $3;
2683 OptTableSpaceOwner: OWNER name { $$ = $2; }
2684 | /*EMPTY */ { $$ = NULL; }
2687 /*****************************************************************************
2690 * DROP TABLESPACE <tablespace>
2692 * No need for drop behaviour as we cannot implement dependencies for
2693 * objects in other databases; we can only support RESTRICT.
2695 ****************************************************************************/
2697 DropTableSpaceStmt: DROP TABLESPACE name
2699 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2700 n->tablespacename = $3;
2701 n->missing_ok = false;
2704 | DROP TABLESPACE IF_P EXISTS name
2706 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2707 n->tablespacename = $5;
2708 n->missing_ok = true;
2713 /*****************************************************************************
2716 * CREATE TRIGGER ...
2719 *****************************************************************************/
2722 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
2723 qualified_name TriggerForSpec EXECUTE PROCEDURE
2724 func_name '(' TriggerFuncArgs ')'
2726 CreateTrigStmt *n = makeNode(CreateTrigStmt);
2733 memcpy(n->actions, $5, 4);
2734 n->isconstraint = FALSE;
2735 n->deferrable = FALSE;
2736 n->initdeferred = FALSE;
2737 n->constrrel = NULL;
2740 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
2741 qualified_name OptConstrFromTable
2742 ConstraintAttributeSpec
2743 FOR EACH ROW EXECUTE PROCEDURE
2744 func_name '(' TriggerFuncArgs ')'
2746 CreateTrigStmt *n = makeNode(CreateTrigStmt);
2753 memcpy(n->actions, $6, 4);
2754 n->isconstraint = TRUE;
2755 n->deferrable = ($10 & 1) != 0;
2756 n->initdeferred = ($10 & 2) != 0;
2764 BEFORE { $$ = TRUE; }
2765 | AFTER { $$ = FALSE; }
2771 char *e = palloc(4);
2772 e[0] = $1; e[1] = '\0';
2775 | TriggerOneEvent OR TriggerOneEvent
2777 char *e = palloc(4);
2778 e[0] = $1; e[1] = $3; e[2] = '\0';
2781 | TriggerOneEvent OR TriggerOneEvent OR TriggerOneEvent
2783 char *e = palloc(4);
2784 e[0] = $1; e[1] = $3; e[2] = $5; e[3] = '\0';
2790 INSERT { $$ = 'i'; }
2791 | DELETE_P { $$ = 'd'; }
2792 | UPDATE { $$ = 'u'; }
2793 | TRUNCATE { $$ = 't'; }
2797 FOR TriggerForOpt TriggerForType
2804 * If ROW/STATEMENT not specified, default to
2805 * STATEMENT, per SQL
2818 | STATEMENT { $$ = FALSE; }
2822 TriggerFuncArg { $$ = list_make1($1); }
2823 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
2824 | /*EMPTY*/ { $$ = NIL; }
2831 snprintf(buf, sizeof(buf), "%d", $1);
2832 $$ = makeString(pstrdup(buf));
2834 | FCONST { $$ = makeString($1); }
2835 | Sconst { $$ = makeString($1); }
2836 | BCONST { $$ = makeString($1); }
2837 | XCONST { $$ = makeString($1); }
2838 | ColId { $$ = makeString($1); }
2842 FROM qualified_name { $$ = $2; }
2843 | /*EMPTY*/ { $$ = NULL; }
2846 ConstraintAttributeSpec:
2847 ConstraintDeferrabilitySpec
2849 | ConstraintDeferrabilitySpec ConstraintTimeSpec
2851 if ($1 == 0 && $2 != 0)
2853 (errcode(ERRCODE_SYNTAX_ERROR),
2854 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
2855 scanner_errposition(@1)));
2858 | ConstraintTimeSpec
2865 | ConstraintTimeSpec ConstraintDeferrabilitySpec
2867 if ($2 == 0 && $1 != 0)
2869 (errcode(ERRCODE_SYNTAX_ERROR),
2870 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
2871 scanner_errposition(@1)));
2878 ConstraintDeferrabilitySpec:
2879 NOT DEFERRABLE { $$ = 0; }
2880 | DEFERRABLE { $$ = 1; }
2884 INITIALLY IMMEDIATE { $$ = 0; }
2885 | INITIALLY DEFERRED { $$ = 2; }
2890 DROP TRIGGER name ON qualified_name opt_drop_behavior
2892 DropPropertyStmt *n = makeNode(DropPropertyStmt);
2896 n->removeType = OBJECT_TRIGGER;
2897 n->missing_ok = false;
2900 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
2902 DropPropertyStmt *n = makeNode(DropPropertyStmt);
2906 n->removeType = OBJECT_TRIGGER;
2907 n->missing_ok = true;
2913 /*****************************************************************************
2916 * CREATE ASSERTION ...
2917 * DROP ASSERTION ...
2919 *****************************************************************************/
2922 CREATE ASSERTION name CHECK '(' a_expr ')'
2923 ConstraintAttributeSpec
2925 CreateTrigStmt *n = makeNode(CreateTrigStmt);
2927 n->args = list_make1($6);
2928 n->isconstraint = TRUE;
2929 n->deferrable = ($8 & 1) != 0;
2930 n->initdeferred = ($8 & 2) != 0;
2933 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2934 errmsg("CREATE ASSERTION is not yet implemented")));
2941 DROP ASSERTION name opt_drop_behavior
2943 DropPropertyStmt *n = makeNode(DropPropertyStmt);
2947 n->removeType = OBJECT_TRIGGER; /* XXX */
2949 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2950 errmsg("DROP ASSERTION is not yet implemented")));
2956 /*****************************************************************************
2959 * define (aggregate,operator,type)
2961 *****************************************************************************/
2964 CREATE AGGREGATE func_name aggr_args definition
2966 DefineStmt *n = makeNode(DefineStmt);
2967 n->kind = OBJECT_AGGREGATE;
2968 n->oldstyle = false;
2974 | CREATE AGGREGATE func_name old_aggr_definition
2976 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
2977 DefineStmt *n = makeNode(DefineStmt);
2978 n->kind = OBJECT_AGGREGATE;
2985 | CREATE OPERATOR any_operator definition
2987 DefineStmt *n = makeNode(DefineStmt);
2988 n->kind = OBJECT_OPERATOR;
2989 n->oldstyle = false;
2995 | CREATE TYPE_P any_name definition
2997 DefineStmt *n = makeNode(DefineStmt);
2998 n->kind = OBJECT_TYPE;
2999 n->oldstyle = false;
3005 | CREATE TYPE_P any_name
3007 /* Shell type (identified by lack of definition) */
3008 DefineStmt *n = makeNode(DefineStmt);
3009 n->kind = OBJECT_TYPE;
3010 n->oldstyle = false;
3013 n->definition = NIL;
3016 | CREATE TYPE_P any_name AS '(' TableFuncElementList ')'
3018 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
3019 RangeVar *r = makeNode(RangeVar);
3021 /* can't use qualified_name, sigh */
3022 switch (list_length($3))
3025 r->catalogname = NULL;
3026 r->schemaname = NULL;
3027 r->relname = strVal(linitial($3));
3030 r->catalogname = NULL;
3031 r->schemaname = strVal(linitial($3));
3032 r->relname = strVal(lsecond($3));
3035 r->catalogname = strVal(linitial($3));
3036 r->schemaname = strVal(lsecond($3));
3037 r->relname = strVal(lthird($3));
3041 (errcode(ERRCODE_SYNTAX_ERROR),
3042 errmsg("improper qualified name (too many dotted names): %s",
3043 NameListToString($3)),
3044 scanner_errposition(@3)));
3052 | CREATE TYPE_P any_name AS ENUM_P '(' enum_val_list ')'
3054 CreateEnumStmt *n = makeNode(CreateEnumStmt);
3059 | CREATE TEXT_P SEARCH PARSER any_name definition
3061 DefineStmt *n = makeNode(DefineStmt);
3062 n->kind = OBJECT_TSPARSER;
3068 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
3070 DefineStmt *n = makeNode(DefineStmt);
3071 n->kind = OBJECT_TSDICTIONARY;
3077 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
3079 DefineStmt *n = makeNode(DefineStmt);
3080 n->kind = OBJECT_TSTEMPLATE;
3086 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
3088 DefineStmt *n = makeNode(DefineStmt);
3089 n->kind = OBJECT_TSCONFIGURATION;
3097 definition: '(' def_list ')' { $$ = $2; }
3100 def_list: def_elem { $$ = list_make1($1); }
3101 | def_list ',' def_elem { $$ = lappend($1, $3); }
3104 def_elem: ColLabel '=' def_arg
3106 $$ = makeDefElem($1, (Node *)$3);
3110 $$ = makeDefElem($1, NULL);
3114 /* Note: any simple identifier will be returned as a type name! */
3115 def_arg: func_type { $$ = (Node *)$1; }
3116 | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
3117 | qual_all_Op { $$ = (Node *)$1; }
3118 | NumericOnly { $$ = (Node *)$1; }
3119 | Sconst { $$ = (Node *)makeString($1); }
3122 aggr_args: '(' type_list ')' { $$ = $2; }
3123 | '(' '*' ')' { $$ = NIL; }
3126 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
3129 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
3130 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
3133 old_aggr_elem: IDENT '=' def_arg
3135 $$ = makeDefElem($1, (Node *)$3);
3139 enum_val_list: Sconst
3140 { $$ = list_make1(makeString($1)); }
3141 | enum_val_list ',' Sconst
3142 { $$ = lappend($1, makeString($3)); }
3146 /*****************************************************************************
3149 * CREATE OPERATOR CLASS ...
3150 * CREATE OPERATOR FAMILY ...
3151 * ALTER OPERATOR FAMILY ...
3152 * DROP OPERATOR CLASS ...
3153 * DROP OPERATOR FAMILY ...
3155 *****************************************************************************/
3158 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
3159 USING access_method opt_opfamily AS opclass_item_list
3161 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
3162 n->opclassname = $4;
3166 n->opfamilyname = $11;
3173 opclass_item { $$ = list_make1($1); }
3174 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
3178 OPERATOR Iconst any_operator opt_recheck
3180 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3181 n->itemtype = OPCLASS_ITEM_OPERATOR;
3187 | OPERATOR Iconst any_operator oper_argtypes opt_recheck
3189 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3190 n->itemtype = OPCLASS_ITEM_OPERATOR;
3196 | FUNCTION Iconst func_name func_args
3198 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3199 n->itemtype = OPCLASS_ITEM_FUNCTION;
3201 n->args = extractArgTypes($4);
3205 | FUNCTION Iconst '(' type_list ')' func_name func_args
3207 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3208 n->itemtype = OPCLASS_ITEM_FUNCTION;
3210 n->args = extractArgTypes($7);
3217 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3218 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
3224 opt_default: DEFAULT { $$ = TRUE; }
3225 | /*EMPTY*/ { $$ = FALSE; }
3228 opt_opfamily: FAMILY any_name { $$ = $2; }
3229 | /*EMPTY*/ { $$ = NIL; }
3232 opt_recheck: RECHECK
3235 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3236 errmsg("RECHECK is no longer supported"),
3237 errhint("Update your data type."),
3238 scanner_errposition(@1)));
3241 | /*EMPTY*/ { $$ = FALSE; }
3246 CREATE OPERATOR FAMILY any_name USING access_method
3248 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
3249 n->opfamilyname = $4;
3256 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
3258 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3259 n->opfamilyname = $4;
3265 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
3267 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3268 n->opfamilyname = $4;
3277 opclass_drop { $$ = list_make1($1); }
3278 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
3282 OPERATOR Iconst '(' type_list ')'
3284 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3285 n->itemtype = OPCLASS_ITEM_OPERATOR;
3290 | FUNCTION Iconst '(' type_list ')'
3292 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3293 n->itemtype = OPCLASS_ITEM_FUNCTION;
3302 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
3304 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3305 n->opclassname = $4;
3308 n->missing_ok = false;
3311 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
3313 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3314 n->opclassname = $6;
3317 n->missing_ok = true;
3323 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
3325 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3326 n->opfamilyname = $4;
3329 n->missing_ok = false;
3332 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
3334 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3335 n->opfamilyname = $6;
3338 n->missing_ok = true;
3344 /*****************************************************************************
3348 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
3349 * REASSIGN OWNED BY username [, username ...] TO username
3351 *****************************************************************************/
3353 DROP OWNED BY name_list opt_drop_behavior
3355 DropOwnedStmt *n = makeNode(DropOwnedStmt);
3363 REASSIGN OWNED BY name_list TO name
3365 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
3372 /*****************************************************************************
3376 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
3377 * [ RESTRICT | CASCADE ]
3379 *****************************************************************************/
3381 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
3383 DropStmt *n = makeNode(DropStmt);
3385 n->missing_ok = TRUE;
3390 | DROP drop_type any_name_list opt_drop_behavior
3392 DropStmt *n = makeNode(DropStmt);
3394 n->missing_ok = FALSE;
3402 drop_type: TABLE { $$ = OBJECT_TABLE; }
3403 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
3404 | VIEW { $$ = OBJECT_VIEW; }
3405 | INDEX { $$ = OBJECT_INDEX; }
3406 | TYPE_P { $$ = OBJECT_TYPE; }
3407 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
3408 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
3409 | SCHEMA { $$ = OBJECT_SCHEMA; }
3410 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
3411 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
3412 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
3413 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
3417 any_name { $$ = list_make1($1); }
3418 | any_name_list ',' any_name { $$ = lappend($1, $3); }
3421 any_name: ColId { $$ = list_make1(makeString($1)); }
3422 | ColId attrs { $$ = lcons(makeString($1), $2); }
3425 attrs: '.' attr_name
3426 { $$ = list_make1(makeString($2)); }
3427 | attrs '.' attr_name
3428 { $$ = lappend($1, makeString($3)); }
3432 /*****************************************************************************
3435 * truncate table relname1, relname2, ...
3437 *****************************************************************************/
3440 TRUNCATE opt_table qualified_name_list opt_restart_seqs opt_drop_behavior
3442 TruncateStmt *n = makeNode(TruncateStmt);
3444 n->restart_seqs = $4;
3451 CONTINUE_P IDENTITY_P { $$ = false; }
3452 | RESTART IDENTITY_P { $$ = true; }
3453 | /* EMPTY */ { $$ = false; }
3456 /*****************************************************************************
3458 * The COMMENT ON statement can take different forms based upon the type of
3459 * the object associated with the comment. The form of the statement is:
3461 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
3462 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
3463 * CAST | COLUMN | SCHEMA | TABLESPACE | ROLE |
3464 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
3465 * TEXT SEARCH TEMPLATE |
3466 * TEXT SEARCH CONFIGURATION ] <objname> |
3467 * AGGREGATE <aggname> (arg1, ...) |
3468 * FUNCTION <funcname> (arg1, arg2, ...) |
3469 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
3470 * TRIGGER <triggername> ON <relname> |
3471 * CONSTRAINT <constraintname> ON <relname> |
3472 * RULE <rulename> ON <relname> ]
3475 *****************************************************************************/
3478 COMMENT ON comment_type any_name IS comment_text
3480 CommentStmt *n = makeNode(CommentStmt);
3487 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
3489 CommentStmt *n = makeNode(CommentStmt);
3490 n->objtype = OBJECT_AGGREGATE;
3496 | COMMENT ON FUNCTION func_name func_args IS comment_text
3498 CommentStmt *n = makeNode(CommentStmt);
3499 n->objtype = OBJECT_FUNCTION;
3501 n->objargs = extractArgTypes($5);
3505 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
3507 CommentStmt *n = makeNode(CommentStmt);
3508 n->objtype = OBJECT_OPERATOR;
3514 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
3516 CommentStmt *n = makeNode(CommentStmt);
3517 n->objtype = OBJECT_CONSTRAINT;
3518 n->objname = lappend($6, makeString($4));
3523 | COMMENT ON RULE name ON any_name IS comment_text
3525 CommentStmt *n = makeNode(CommentStmt);
3526 n->objtype = OBJECT_RULE;
3527 n->objname = lappend($6, makeString($4));
3532 | COMMENT ON RULE name IS comment_text
3534 /* Obsolete syntax supported for awhile for compatibility */
3535 CommentStmt *n = makeNode(CommentStmt);
3536 n->objtype = OBJECT_RULE;
3537 n->objname = list_make1(makeString($4));
3542 | COMMENT ON TRIGGER name ON any_name IS comment_text
3544 CommentStmt *n = makeNode(CommentStmt);
3545 n->objtype = OBJECT_TRIGGER;
3546 n->objname = lappend($6, makeString($4));
3551 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
3553 CommentStmt *n = makeNode(CommentStmt);
3554 n->objtype = OBJECT_OPCLASS;
3556 n->objargs = list_make1(makeString($7));
3560 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
3562 CommentStmt *n = makeNode(CommentStmt);
3563 n->objtype = OBJECT_OPFAMILY;
3565 n->objargs = list_make1(makeString($7));
3569 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
3571 CommentStmt *n = makeNode(CommentStmt);
3572 n->objtype = OBJECT_LARGEOBJECT;
3573 n->objname = list_make1($5);
3578 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
3580 CommentStmt *n = makeNode(CommentStmt);
3581 n->objtype = OBJECT_CAST;
3582 n->objname = list_make1($5);
3583 n->objargs = list_make1($7);
3587 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
3589 CommentStmt *n = makeNode(CommentStmt);
3590 n->objtype = OBJECT_LANGUAGE;
3596 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
3598 CommentStmt *n = makeNode(CommentStmt);
3599 n->objtype = OBJECT_TSPARSER;
3604 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
3606 CommentStmt *n = makeNode(CommentStmt);
3607 n->objtype = OBJECT_TSDICTIONARY;
3612 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
3614 CommentStmt *n = makeNode(CommentStmt);
3615 n->objtype = OBJECT_TSTEMPLATE;
3620 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
3622 CommentStmt *n = makeNode(CommentStmt);
3623 n->objtype = OBJECT_TSCONFIGURATION;
3631 COLUMN { $$ = OBJECT_COLUMN; }
3632 | DATABASE { $$ = OBJECT_DATABASE; }
3633 | SCHEMA { $$ = OBJECT_SCHEMA; }
3634 | INDEX { $$ = OBJECT_INDEX; }
3635 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
3636 | TABLE { $$ = OBJECT_TABLE; }
3637 | DOMAIN_P { $$ = OBJECT_TYPE; }
3638 | TYPE_P { $$ = OBJECT_TYPE; }
3639 | VIEW { $$ = OBJECT_VIEW; }
3640 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
3641 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
3642 | ROLE { $$ = OBJECT_ROLE; }
3647 | NULL_P { $$ = NULL; }
3650 /*****************************************************************************
3655 *****************************************************************************/
3657 FetchStmt: FETCH fetch_direction from_in name
3659 FetchStmt *n = (FetchStmt *) $2;
3666 FetchStmt *n = makeNode(FetchStmt);
3667 n->direction = FETCH_FORWARD;
3673 | MOVE fetch_direction from_in name
3675 FetchStmt *n = (FetchStmt *) $2;
3682 FetchStmt *n = makeNode(FetchStmt);
3683 n->direction = FETCH_FORWARD;
3694 FetchStmt *n = makeNode(FetchStmt);
3695 n->direction = FETCH_FORWARD;
3701 FetchStmt *n = makeNode(FetchStmt);
3702 n->direction = FETCH_FORWARD;
3708 FetchStmt *n = makeNode(FetchStmt);
3709 n->direction = FETCH_BACKWARD;
3715 FetchStmt *n = makeNode(FetchStmt);
3716 n->direction = FETCH_ABSOLUTE;
3722 FetchStmt *n = makeNode(FetchStmt);
3723 n->direction = FETCH_ABSOLUTE;
3727 | ABSOLUTE_P SignedIconst
3729 FetchStmt *n = makeNode(FetchStmt);
3730 n->direction = FETCH_ABSOLUTE;
3734 | RELATIVE_P SignedIconst
3736 FetchStmt *n = makeNode(FetchStmt);
3737 n->direction = FETCH_RELATIVE;
3743 FetchStmt *n = makeNode(FetchStmt);
3744 n->direction = FETCH_FORWARD;
3750 FetchStmt *n = makeNode(FetchStmt);
3751 n->direction = FETCH_FORWARD;
3752 n->howMany = FETCH_ALL;
3757 FetchStmt *n = makeNode(FetchStmt);
3758 n->direction = FETCH_FORWARD;
3762 | FORWARD SignedIconst
3764 FetchStmt *n = makeNode(FetchStmt);
3765 n->direction = FETCH_FORWARD;
3771 FetchStmt *n = makeNode(FetchStmt);
3772 n->direction = FETCH_FORWARD;
3773 n->howMany = FETCH_ALL;
3778 FetchStmt *n = makeNode(FetchStmt);
3779 n->direction = FETCH_BACKWARD;
3783 | BACKWARD SignedIconst
3785 FetchStmt *n = makeNode(FetchStmt);
3786 n->direction = FETCH_BACKWARD;
3792 FetchStmt *n = makeNode(FetchStmt);
3793 n->direction = FETCH_BACKWARD;
3794 n->howMany = FETCH_ALL;
3804 /*****************************************************************************
3806 * GRANT and REVOKE statements
3808 *****************************************************************************/
3810 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
3811 opt_grant_grant_option
3813 GrantStmt *n = makeNode(GrantStmt);
3816 n->objtype = ($4)->objtype;
3817 n->objects = ($4)->objs;
3819 n->grant_option = $7;
3825 REVOKE privileges ON privilege_target
3826 FROM grantee_list opt_drop_behavior
3828 GrantStmt *n = makeNode(GrantStmt);
3829 n->is_grant = false;
3830 n->grant_option = false;
3832 n->objtype = ($4)->objtype;
3833 n->objects = ($4)->objs;
3838 | REVOKE GRANT OPTION FOR privileges ON privilege_target
3839 FROM grantee_list opt_drop_behavior
3841 GrantStmt *n = makeNode(GrantStmt);
3842 n->is_grant = false;
3843 n->grant_option = true;
3845 n->objtype = ($7)->objtype;
3846 n->objects = ($7)->objs;
3855 * A privilege list is represented as a list of strings; the validity of
3856 * the privilege names gets checked at execution. This is a bit annoying
3857 * but we have little choice because of the syntactic conflict with lists
3858 * of role names in GRANT/REVOKE. What's more, we have to call out in
3859 * the "privilege" production any reserved keywords that need to be usable
3860 * as privilege names.
3863 /* either ALL [PRIVILEGES] or a list of individual privileges */
3864 privileges: privilege_list
3872 privilege_list: privilege
3873 { $$ = list_make1(makeString($1)); }
3874 | privilege_list ',' privilege
3875 { $$ = lappend($1, makeString($3)); }
3878 privilege: SELECT { $$ = pstrdup($1); }
3879 | REFERENCES { $$ = pstrdup($1); }
3880 | CREATE { $$ = pstrdup($1); }
3881 | ColId { $$ = $1; }
3885 /* Don't bother trying to fold the first two rules into one using
3886 * opt_table. You're going to get conflicts.
3891 PrivTarget *n = makeNode(PrivTarget);
3892 n->objtype = ACL_OBJECT_RELATION;
3896 | TABLE qualified_name_list
3898 PrivTarget *n = makeNode(PrivTarget);
3899 n->objtype = ACL_OBJECT_RELATION;
3903 | SEQUENCE qualified_name_list
3905 PrivTarget *n = makeNode(PrivTarget);
3906 n->objtype = ACL_OBJECT_SEQUENCE;
3910 | FUNCTION function_with_argtypes_list
3912 PrivTarget *n = makeNode(PrivTarget);
3913 n->objtype = ACL_OBJECT_FUNCTION;
3917 | DATABASE name_list
3919 PrivTarget *n = makeNode(PrivTarget);
3920 n->objtype = ACL_OBJECT_DATABASE;
3924 | LANGUAGE name_list
3926 PrivTarget *n = makeNode(PrivTarget);
3927 n->objtype = ACL_OBJECT_LANGUAGE;
3933 PrivTarget *n = makeNode(PrivTarget);
3934 n->objtype = ACL_OBJECT_NAMESPACE;
3938 | TABLESPACE name_list
3940 PrivTarget *n = makeNode(PrivTarget);
3941 n->objtype = ACL_OBJECT_TABLESPACE;
3949 grantee { $$ = list_make1($1); }
3950 | grantee_list ',' grantee { $$ = lappend($1, $3); }
3955 PrivGrantee *n = makeNode(PrivGrantee);
3956 /* This hack lets us avoid reserving PUBLIC as a keyword*/
3957 if (strcmp($1, "public") == 0)
3965 PrivGrantee *n = makeNode(PrivGrantee);
3966 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
3967 if (strcmp($2, "public") == 0)
3976 opt_grant_grant_option:
3977 WITH GRANT OPTION { $$ = TRUE; }
3978 | /*EMPTY*/ { $$ = FALSE; }
3981 function_with_argtypes_list:
3982 function_with_argtypes { $$ = list_make1($1); }
3983 | function_with_argtypes_list ',' function_with_argtypes
3984 { $$ = lappend($1, $3); }
3987 function_with_argtypes:
3990 FuncWithArgs *n = makeNode(FuncWithArgs);
3992 n->funcargs = extractArgTypes($2);
3997 /*****************************************************************************
3999 * GRANT and REVOKE ROLE statements
4001 *****************************************************************************/
4004 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4006 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4008 n->granted_roles = $2;
4009 n->grantee_roles = $4;
4017 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4019 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4020 n->is_grant = false;
4021 n->admin_opt = false;
4022 n->granted_roles = $2;
4023 n->grantee_roles = $4;
4027 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4029 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4030 n->is_grant = false;
4031 n->admin_opt = true;
4032 n->granted_roles = $5;
4033 n->grantee_roles = $7;
4039 opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
4040 | /*EMPTY*/ { $$ = FALSE; }
4043 opt_granted_by: GRANTED BY RoleId { $$ = $3; }
4044 | /*EMPTY*/ { $$ = NULL; }
4048 /*****************************************************************************
4050 * QUERY: CREATE INDEX
4052 * Note: we can't factor CONCURRENTLY into a separate production without
4053 * making it a reserved word.
4055 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
4056 * willing to make TABLESPACE a fully reserved word.
4057 *****************************************************************************/
4059 IndexStmt: CREATE index_opt_unique INDEX index_name
4060 ON qualified_name access_method_clause '(' index_params ')'
4061 opt_definition OptTableSpace where_clause
4063 IndexStmt *n = makeNode(IndexStmt);
4065 n->concurrent = false;
4068 n->accessMethod = $7;
4069 n->indexParams = $9;
4071 n->tableSpace = $12;
4072 n->whereClause = $13;
4075 | CREATE index_opt_unique INDEX CONCURRENTLY index_name
4076 ON qualified_name access_method_clause '(' index_params ')'
4077 opt_definition OptTableSpace where_clause
4079 IndexStmt *n = makeNode(IndexStmt);
4081 n->concurrent = true;
4084 n->accessMethod = $8;
4085 n->indexParams = $10;
4087 n->tableSpace = $13;
4088 n->whereClause = $14;
4094 UNIQUE { $$ = TRUE; }
4095 | /*EMPTY*/ { $$ = FALSE; }
4098 access_method_clause:
4099 USING access_method { $$ = $2; }
4100 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
4103 index_params: index_elem { $$ = list_make1($1); }
4104 | index_params ',' index_elem { $$ = lappend($1, $3); }
4108 * Index attributes can be either simple column references, or arbitrary
4109 * expressions in parens. For backwards-compatibility reasons, we allow
4110 * an expression that's just a function call to be written without parens.
4112 index_elem: ColId opt_class opt_asc_desc opt_nulls_order
4114 $$ = makeNode(IndexElem);
4119 $$->nulls_ordering = $4;
4121 | func_expr opt_class opt_asc_desc opt_nulls_order
4123 $$ = makeNode(IndexElem);
4128 $$->nulls_ordering = $4;
4130 | '(' a_expr ')' opt_class opt_asc_desc opt_nulls_order
4132 $$ = makeNode(IndexElem);
4137 $$->nulls_ordering = $6;
4141 opt_class: any_name { $$ = $1; }
4142 | USING any_name { $$ = $2; }
4143 | /*EMPTY*/ { $$ = NIL; }
4146 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
4147 | DESC { $$ = SORTBY_DESC; }
4148 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
4151 opt_nulls_order: NULLS_FIRST { $$ = SORTBY_NULLS_FIRST; }
4152 | NULLS_LAST { $$ = SORTBY_NULLS_LAST; }
4153 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
4157 /*****************************************************************************
4160 * create [or replace] function <fname>
4161 * [(<type-1> { , <type-n>})]
4163 * as <filename or code in language as appropriate>
4164 * language <lang> [with parameters]
4166 *****************************************************************************/
4169 CREATE opt_or_replace FUNCTION func_name func_args
4170 RETURNS func_return createfunc_opt_list opt_definition
4172 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4181 | CREATE opt_or_replace FUNCTION func_name func_args
4182 RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
4184 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4187 n->parameters = mergeTableFuncParameters($5, $9);
4188 n->returnType = TableFuncTypeName($9);
4189 n->returnType->location = @7;
4191 n->withClause = $12;
4194 | CREATE opt_or_replace FUNCTION func_name func_args
4195 createfunc_opt_list opt_definition
4197 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4201 n->returnType = NULL;
4209 OR REPLACE { $$ = TRUE; }
4210 | /*EMPTY*/ { $$ = FALSE; }
4213 func_args: '(' func_args_list ')' { $$ = $2; }
4214 | '(' ')' { $$ = NIL; }
4218 func_arg { $$ = list_make1($1); }
4219 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
4223 * The style with arg_class first is SQL99 standard, but Oracle puts
4224 * param_name first; accept both since it's likely people will try both
4225 * anyway. Don't bother trying to save productions by letting arg_class
4226 * have an empty alternative ... you'll get shift/reduce conflicts.
4228 * We can catch over-specified arguments here if we want to,
4229 * but for now better to silently swallow typmod, etc.
4230 * - thomas 2000-03-22
4233 arg_class param_name func_type
4235 FunctionParameter *n = makeNode(FunctionParameter);
4241 | param_name arg_class func_type
4243 FunctionParameter *n = makeNode(FunctionParameter);
4249 | param_name func_type
4251 FunctionParameter *n = makeNode(FunctionParameter);
4254 n->mode = FUNC_PARAM_IN;
4257 | arg_class func_type
4259 FunctionParameter *n = makeNode(FunctionParameter);
4267 FunctionParameter *n = makeNode(FunctionParameter);
4270 n->mode = FUNC_PARAM_IN;
4275 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
4276 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
4277 | OUT_P { $$ = FUNC_PARAM_OUT; }
4278 | INOUT { $$ = FUNC_PARAM_INOUT; }
4279 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
4280 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
4284 * Ideally param_name should be ColId, but that causes too many conflicts.
4286 param_name: type_function_name
4292 /* We can catch over-specified results here if we want to,
4293 * but for now better to silently swallow typmod, etc.
4294 * - thomas 2000-03-22
4301 * We would like to make the %TYPE productions here be ColId attrs etc,
4302 * but that causes reduce/reduce conflicts. type_function_name
4303 * is next best choice.
4305 func_type: Typename { $$ = $1; }
4306 | type_function_name attrs '%' TYPE_P
4308 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
4309 $$->pct_type = true;
4312 | SETOF type_function_name attrs '%' TYPE_P
4314 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
4315 $$->pct_type = true;
4322 createfunc_opt_list:
4323 /* Must be at least one to prevent conflict */
4324 createfunc_opt_item { $$ = list_make1($1); }
4325 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
4329 * Options common to both CREATE FUNCTION and ALTER FUNCTION
4331 common_func_opt_item:
4332 CALLED ON NULL_P INPUT_P
4334 $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
4336 | RETURNS NULL_P ON NULL_P INPUT_P
4338 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
4342 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
4346 $$ = makeDefElem("volatility", (Node *)makeString("immutable"));
4350 $$ = makeDefElem("volatility", (Node *)makeString("stable"));
4354 $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
4356 | EXTERNAL SECURITY DEFINER
4358 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
4360 | EXTERNAL SECURITY INVOKER
4362 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
4366 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
4370 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
4374 $$ = makeDefElem("cost", (Node *)$2);
4378 $$ = makeDefElem("rows", (Node *)$2);
4382 /* we abuse the normal content of a DefElem here */
4383 $$ = makeDefElem("set", (Node *)$1);
4387 createfunc_opt_item:
4390 $$ = makeDefElem("as", (Node *)$2);
4392 | LANGUAGE ColId_or_Sconst
4394 $$ = makeDefElem("language", (Node *)makeString($2));
4396 | common_func_opt_item
4402 func_as: Sconst { $$ = list_make1(makeString($1)); }
4405 $$ = list_make2(makeString($1), makeString($3));
4410 WITH definition { $$ = $2; }
4411 | /*EMPTY*/ { $$ = NIL; }
4414 table_func_column: param_name func_type
4416 FunctionParameter *n = makeNode(FunctionParameter);
4419 n->mode = FUNC_PARAM_TABLE;
4424 table_func_column_list:
4427 $$ = list_make1($1);
4429 | table_func_column_list ',' table_func_column
4431 $$ = lappend($1, $3);
4435 /*****************************************************************************
4438 * RENAME and OWNER subcommands are already provided by the generic
4439 * ALTER infrastructure, here we just specify alterations that can
4440 * only be applied to functions.
4442 *****************************************************************************/
4444 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
4446 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
4454 /* At least one option must be specified */
4455 common_func_opt_item { $$ = list_make1($1); }
4456 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
4459 /* Ignored, merely for SQL compliance */
4466 /*****************************************************************************
4470 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
4471 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
4472 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
4474 *****************************************************************************/
4477 DROP FUNCTION func_name func_args opt_drop_behavior
4479 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4480 n->kind = OBJECT_FUNCTION;
4482 n->args = extractArgTypes($4);
4484 n->missing_ok = false;
4487 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
4489 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4490 n->kind = OBJECT_FUNCTION;
4492 n->args = extractArgTypes($6);
4494 n->missing_ok = true;
4500 DROP AGGREGATE func_name aggr_args opt_drop_behavior
4502 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4503 n->kind = OBJECT_AGGREGATE;
4507 n->missing_ok = false;
4510 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
4512 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4513 n->kind = OBJECT_AGGREGATE;
4517 n->missing_ok = true;
4523 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
4525 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4526 n->kind = OBJECT_OPERATOR;
4530 n->missing_ok = false;
4533 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
4535 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4536 n->kind = OBJECT_OPERATOR;
4540 n->missing_ok = true;
4549 (errcode(ERRCODE_SYNTAX_ERROR),
4550 errmsg("missing argument"),
4551 errhint("Use NONE to denote the missing argument of a unary operator."),
4552 scanner_errposition(@3)));
4554 | '(' Typename ',' Typename ')'
4555 { $$ = list_make2($2, $4); }
4556 | '(' NONE ',' Typename ')' /* left unary */
4557 { $$ = list_make2(NULL, $4); }
4558 | '(' Typename ',' NONE ')' /* right unary */
4559 { $$ = list_make2($2, NULL); }
4564 { $$ = list_make1(makeString($1)); }
4565 | ColId '.' any_operator
4566 { $$ = lcons(makeString($1), $3); }
4570 /*****************************************************************************
4572 * CREATE CAST / DROP CAST
4574 *****************************************************************************/
4576 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
4577 WITH FUNCTION function_with_argtypes cast_context
4579 CreateCastStmt *n = makeNode(CreateCastStmt);
4583 n->context = (CoercionContext) $11;
4586 | CREATE CAST '(' Typename AS Typename ')'
4587 WITHOUT FUNCTION cast_context
4589 CreateCastStmt *n = makeNode(CreateCastStmt);
4593 n->context = (CoercionContext) $10;
4598 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
4599 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
4600 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
4604 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
4606 DropCastStmt *n = makeNode(DropCastStmt);
4615 opt_if_exists: IF_P EXISTS { $$ = TRUE; }
4616 | /*EMPTY*/ { $$ = FALSE; }
4620 /*****************************************************************************
4624 * REINDEX type <name> [FORCE]
4626 * FORCE no longer does anything, but we accept it for backwards compatibility
4627 *****************************************************************************/
4630 REINDEX reindex_type qualified_name opt_force
4632 ReindexStmt *n = makeNode(ReindexStmt);
4638 | REINDEX SYSTEM_P name opt_force
4640 ReindexStmt *n = makeNode(ReindexStmt);
4641 n->kind = OBJECT_DATABASE;
4644 n->do_system = true;
4648 | REINDEX DATABASE name opt_force
4650 ReindexStmt *n = makeNode(ReindexStmt);
4651 n->kind = OBJECT_DATABASE;
4654 n->do_system = true;
4661 INDEX { $$ = OBJECT_INDEX; }
4662 | TABLE { $$ = OBJECT_TABLE; }
4665 opt_force: FORCE { $$ = TRUE; }
4666 | /* EMPTY */ { $$ = FALSE; }
4670 /*****************************************************************************
4672 * ALTER THING name RENAME TO newname
4674 *****************************************************************************/
4676 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
4678 RenameStmt *n = makeNode(RenameStmt);
4679 n->renameType = OBJECT_AGGREGATE;
4685 | ALTER CONVERSION_P any_name RENAME TO name
4687 RenameStmt *n = makeNode(RenameStmt);
4688 n->renameType = OBJECT_CONVERSION;
4693 | ALTER DATABASE database_name RENAME TO database_name
4695 RenameStmt *n = makeNode(RenameStmt);
4696 n->renameType = OBJECT_DATABASE;
4701 | ALTER FUNCTION function_with_argtypes RENAME TO name
4703 RenameStmt *n = makeNode(RenameStmt);
4704 n->renameType = OBJECT_FUNCTION;
4705 n->object = $3->funcname;
4706 n->objarg = $3->funcargs;
4710 | ALTER GROUP_P RoleId RENAME TO RoleId
4712 RenameStmt *n = makeNode(RenameStmt);
4713 n->renameType = OBJECT_ROLE;
4718 | ALTER opt_procedural LANGUAGE name RENAME TO name
4720 RenameStmt *n = makeNode(RenameStmt);
4721 n->renameType = OBJECT_LANGUAGE;
4726 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
4728 RenameStmt *n = makeNode(RenameStmt);
4729 n->renameType = OBJECT_OPCLASS;
4735 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
4737 RenameStmt *n = makeNode(RenameStmt);
4738 n->renameType = OBJECT_OPFAMILY;
4744 | ALTER SCHEMA name RENAME TO name
4746 RenameStmt *n = makeNode(RenameStmt);
4747 n->renameType = OBJECT_SCHEMA;
4752 | ALTER TABLE relation_expr RENAME TO name
4754 RenameStmt *n = makeNode(RenameStmt);
4755 n->renameType = OBJECT_TABLE;
4761 | ALTER SEQUENCE relation_expr RENAME TO name
4763 RenameStmt *n = makeNode(RenameStmt);
4764 n->renameType = OBJECT_SEQUENCE;
4770 | ALTER VIEW relation_expr RENAME TO name
4772 RenameStmt *n = makeNode(RenameStmt);
4773 n->renameType = OBJECT_VIEW;
4779 | ALTER INDEX relation_expr RENAME TO name
4781 RenameStmt *n = makeNode(RenameStmt);
4782 n->renameType = OBJECT_INDEX;
4788 | ALTER TABLE relation_expr RENAME opt_column name TO name
4790 RenameStmt *n = makeNode(RenameStmt);
4791 n->renameType = OBJECT_COLUMN;
4797 | ALTER TRIGGER name ON relation_expr RENAME TO name
4799 RenameStmt *n = makeNode(RenameStmt);
4800 n->renameType = OBJECT_TRIGGER;
4806 | ALTER ROLE RoleId RENAME TO RoleId
4808 RenameStmt *n = makeNode(RenameStmt);
4809 n->renameType = OBJECT_ROLE;
4814 | ALTER USER RoleId RENAME TO RoleId
4816 RenameStmt *n = makeNode(RenameStmt);
4817 n->renameType = OBJECT_ROLE;
4822 | ALTER TABLESPACE name RENAME TO name
4824 RenameStmt *n = makeNode(RenameStmt);
4825 n->renameType = OBJECT_TABLESPACE;
4830 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
4832 RenameStmt *n = makeNode(RenameStmt);
4833 n->renameType = OBJECT_TSPARSER;
4838 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
4840 RenameStmt *n = makeNode(RenameStmt);
4841 n->renameType = OBJECT_TSDICTIONARY;
4846 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
4848 RenameStmt *n = makeNode(RenameStmt);
4849 n->renameType = OBJECT_TSTEMPLATE;
4854 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
4856 RenameStmt *n = makeNode(RenameStmt);
4857 n->renameType = OBJECT_TSCONFIGURATION;
4862 | ALTER TYPE_P any_name RENAME TO name
4864 RenameStmt *n = makeNode(RenameStmt);
4865 n->renameType = OBJECT_TYPE;
4872 opt_column: COLUMN { $$ = COLUMN; }
4873 | /*EMPTY*/ { $$ = 0; }
4876 opt_set_data: SET DATA_P { $$ = 1; }
4877 | /*EMPTY*/ { $$ = 0; }
4880 /*****************************************************************************
4882 * ALTER THING name SET SCHEMA name
4884 *****************************************************************************/
4886 AlterObjectSchemaStmt:
4887 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
4889 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4890 n->objectType = OBJECT_AGGREGATE;
4896 | ALTER DOMAIN_P any_name SET SCHEMA name
4898 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4899 n->objectType = OBJECT_DOMAIN;
4904 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
4906 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4907 n->objectType = OBJECT_FUNCTION;
4908 n->object = $3->funcname;
4909 n->objarg = $3->funcargs;
4913 | ALTER TABLE relation_expr SET SCHEMA name
4915 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4916 n->objectType = OBJECT_TABLE;
4921 | ALTER SEQUENCE relation_expr SET SCHEMA name
4923 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4924 n->objectType = OBJECT_SEQUENCE;
4929 | ALTER VIEW relation_expr SET SCHEMA name
4931 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4932 n->objectType = OBJECT_VIEW;
4937 | ALTER TYPE_P any_name SET SCHEMA name
4939 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4940 n->objectType = OBJECT_TYPE;
4947 /*****************************************************************************
4949 * ALTER THING name OWNER TO newname
4951 *****************************************************************************/
4953 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
4955 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
4956 n->objectType = OBJECT_AGGREGATE;
4962 | ALTER CONVERSION_P any_name OWNER TO RoleId
4964 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
4965 n->objectType = OBJECT_CONVERSION;
4970 | ALTER DATABASE database_name OWNER TO RoleId
4972 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
4973 n->objectType = OBJECT_DATABASE;
4974 n->object = list_make1(makeString($3));
4978 | ALTER DOMAIN_P any_name OWNER TO RoleId
4980 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
4981 n->objectType = OBJECT_DOMAIN;
4986 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
4988 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
4989 n->objectType = OBJECT_FUNCTION;
4990 n->object = $3->funcname;
4991 n->objarg = $3->funcargs;
4995 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
4997 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
4998 n->objectType = OBJECT_LANGUAGE;
4999 n->object = list_make1(makeString($4));
5003 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
5005 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5006 n->objectType = OBJECT_OPERATOR;
5012 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
5014 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5015 n->objectType = OBJECT_OPCLASS;
5021 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
5023 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5024 n->objectType = OBJECT_OPFAMILY;
5030 | ALTER SCHEMA name OWNER TO RoleId
5032 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5033 n->objectType = OBJECT_SCHEMA;
5034 n->object = list_make1(makeString($3));
5038 | ALTER TYPE_P any_name OWNER TO RoleId
5040 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5041 n->objectType = OBJECT_TYPE;
5046 | ALTER TABLESPACE name OWNER TO RoleId
5048 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5049 n->objectType = OBJECT_TABLESPACE;
5050 n->object = list_make1(makeString($3));
5054 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
5056 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5057 n->objectType = OBJECT_TSDICTIONARY;
5062 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
5064 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5065 n->objectType = OBJECT_TSCONFIGURATION;
5073 /*****************************************************************************
5075 * QUERY: Define Rewrite Rule
5077 *****************************************************************************/
5079 RuleStmt: CREATE opt_or_replace RULE name AS
5080 { QueryIsRule=TRUE; }
5081 ON event TO qualified_name where_clause
5082 DO opt_instead RuleActionList
5084 RuleStmt *n = makeNode(RuleStmt);
5088 n->whereClause = $11;
5098 NOTHING { $$ = NIL; }
5099 | RuleActionStmt { $$ = list_make1($1); }
5100 | '(' RuleActionMulti ')' { $$ = $2; }
5103 /* the thrashing around here is to discard "empty" statements... */
5105 RuleActionMulti ';' RuleActionStmtOrEmpty
5107 $$ = lappend($1, $3);
5111 | RuleActionStmtOrEmpty
5113 $$ = list_make1($1);
5127 RuleActionStmtOrEmpty:
5128 RuleActionStmt { $$ = $1; }
5129 | /*EMPTY*/ { $$ = NULL; }
5132 event: SELECT { $$ = CMD_SELECT; }
5133 | UPDATE { $$ = CMD_UPDATE; }
5134 | DELETE_P { $$ = CMD_DELETE; }
5135 | INSERT { $$ = CMD_INSERT; }
5139 INSTEAD { $$ = TRUE; }
5140 | ALSO { $$ = FALSE; }
5141 | /*EMPTY*/ { $$ = FALSE; }
5146 DROP RULE name ON qualified_name opt_drop_behavior
5148 DropPropertyStmt *n = makeNode(DropPropertyStmt);
5152 n->removeType = OBJECT_RULE;
5153 n->missing_ok = false;
5156 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
5158 DropPropertyStmt *n = makeNode(DropPropertyStmt);
5162 n->removeType = OBJECT_RULE;
5163 n->missing_ok = true;
5169 /*****************************************************************************
5172 * NOTIFY <identifier> can appear both in rule bodies and
5173 * as a query-level command
5175 *****************************************************************************/
5177 NotifyStmt: NOTIFY ColId
5179 NotifyStmt *n = makeNode(NotifyStmt);
5180 n->conditionname = $2;
5185 ListenStmt: LISTEN ColId
5187 ListenStmt *n = makeNode(ListenStmt);
5188 n->conditionname = $2;
5196 UnlistenStmt *n = makeNode(UnlistenStmt);
5197 n->conditionname = $2;
5202 UnlistenStmt *n = makeNode(UnlistenStmt);
5203 n->conditionname = NULL;
5209 /*****************************************************************************
5213 * BEGIN / COMMIT / ROLLBACK
5214 * (also older versions END / ABORT)
5216 *****************************************************************************/
5219 ABORT_P opt_transaction
5221 TransactionStmt *n = makeNode(TransactionStmt);
5222 n->kind = TRANS_STMT_ROLLBACK;
5226 | BEGIN_P opt_transaction transaction_mode_list_or_empty
5228 TransactionStmt *n = makeNode(TransactionStmt);
5229 n->kind = TRANS_STMT_BEGIN;
5233 | START TRANSACTION transaction_mode_list_or_empty
5235 TransactionStmt *n = makeNode(TransactionStmt);
5236 n->kind = TRANS_STMT_START;
5240 | COMMIT opt_transaction
5242 TransactionStmt *n = makeNode(TransactionStmt);
5243 n->kind = TRANS_STMT_COMMIT;
5247 | END_P opt_transaction
5249 TransactionStmt *n = makeNode(TransactionStmt);
5250 n->kind = TRANS_STMT_COMMIT;
5254 | ROLLBACK opt_transaction
5256 TransactionStmt *n = makeNode(TransactionStmt);
5257 n->kind = TRANS_STMT_ROLLBACK;
5263 TransactionStmt *n = makeNode(TransactionStmt);
5264 n->kind = TRANS_STMT_SAVEPOINT;
5265 n->options = list_make1(makeDefElem("savepoint_name",
5266 (Node *)makeString($2)));
5269 | RELEASE SAVEPOINT ColId
5271 TransactionStmt *n = makeNode(TransactionStmt);
5272 n->kind = TRANS_STMT_RELEASE;
5273 n->options = list_make1(makeDefElem("savepoint_name",
5274 (Node *)makeString($3)));
5279 TransactionStmt *n = makeNode(TransactionStmt);
5280 n->kind = TRANS_STMT_RELEASE;
5281 n->options = list_make1(makeDefElem("savepoint_name",
5282 (Node *)makeString($2)));
5285 | ROLLBACK opt_transaction TO SAVEPOINT ColId
5287 TransactionStmt *n = makeNode(TransactionStmt);
5288 n->kind = TRANS_STMT_ROLLBACK_TO;
5289 n->options = list_make1(makeDefElem("savepoint_name",
5290 (Node *)makeString($5)));
5293 | ROLLBACK opt_transaction TO ColId
5295 TransactionStmt *n = makeNode(TransactionStmt);
5296 n->kind = TRANS_STMT_ROLLBACK_TO;
5297 n->options = list_make1(makeDefElem("savepoint_name",
5298 (Node *)makeString($4)));
5301 | PREPARE TRANSACTION Sconst
5303 TransactionStmt *n = makeNode(TransactionStmt);
5304 n->kind = TRANS_STMT_PREPARE;
5308 | COMMIT PREPARED Sconst
5310 TransactionStmt *n = makeNode(TransactionStmt);
5311 n->kind = TRANS_STMT_COMMIT_PREPARED;
5315 | ROLLBACK PREPARED Sconst
5317 TransactionStmt *n = makeNode(TransactionStmt);
5318 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
5324 opt_transaction: WORK {}
5329 transaction_mode_item:
5330 ISOLATION LEVEL iso_level
5331 { $$ = makeDefElem("transaction_isolation",
5332 makeStringConst($3, @3)); }
5334 { $$ = makeDefElem("transaction_read_only",
5335 makeIntConst(TRUE, @1)); }
5337 { $$ = makeDefElem("transaction_read_only",
5338 makeIntConst(FALSE, @1)); }
5341 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
5342 transaction_mode_list:
5343 transaction_mode_item
5344 { $$ = list_make1($1); }
5345 | transaction_mode_list ',' transaction_mode_item
5346 { $$ = lappend($1, $3); }
5347 | transaction_mode_list transaction_mode_item
5348 { $$ = lappend($1, $2); }
5351 transaction_mode_list_or_empty:
5352 transaction_mode_list
5358 /*****************************************************************************
5361 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
5362 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
5364 *****************************************************************************/
5366 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
5367 AS SelectStmt opt_check_option
5369 ViewStmt *n = makeNode(ViewStmt);
5371 n->view->istemp = $2;
5377 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
5378 AS SelectStmt opt_check_option
5380 ViewStmt *n = makeNode(ViewStmt);
5382 n->view->istemp = $4;
5391 * We use merged tokens here to avoid creating shift/reduce conflicts against
5392 * a whole lot of other uses of WITH.
5398 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5399 errmsg("WITH CHECK OPTION is not implemented")));
5401 | WITH_CASCADED CHECK OPTION
5404 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5405 errmsg("WITH CHECK OPTION is not implemented")));
5407 | WITH_LOCAL CHECK OPTION
5410 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5411 errmsg("WITH CHECK OPTION is not implemented")));
5413 | /* EMPTY */ { $$ = NIL; }
5416 /*****************************************************************************
5421 *****************************************************************************/
5423 LoadStmt: LOAD file_name
5425 LoadStmt *n = makeNode(LoadStmt);
5432 /*****************************************************************************
5436 *****************************************************************************/
5439 CREATE DATABASE database_name opt_with createdb_opt_list
5441 CreatedbStmt *n = makeNode(CreatedbStmt);
5449 createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
5450 | /* EMPTY */ { $$ = NIL; }
5454 TABLESPACE opt_equal name
5456 $$ = makeDefElem("tablespace", (Node *)makeString($3));
5458 | TABLESPACE opt_equal DEFAULT
5460 $$ = makeDefElem("tablespace", NULL);
5462 | LOCATION opt_equal Sconst
5464 $$ = makeDefElem("location", (Node *)makeString($3));
5466 | LOCATION opt_equal DEFAULT
5468 $$ = makeDefElem("location", NULL);
5470 | TEMPLATE opt_equal name
5472 $$ = makeDefElem("template", (Node *)makeString($3));
5474 | TEMPLATE opt_equal DEFAULT
5476 $$ = makeDefElem("template", NULL);
5478 | ENCODING opt_equal Sconst
5480 $$ = makeDefElem("encoding", (Node *)makeString($3));
5482 | ENCODING opt_equal Iconst
5484 $$ = makeDefElem("encoding", (Node *)makeInteger($3));
5486 | ENCODING opt_equal DEFAULT
5488 $$ = makeDefElem("encoding", NULL);
5490 | COLLATE opt_equal Sconst
5492 $$ = makeDefElem("collate", (Node *)makeString($3));
5494 | COLLATE opt_equal DEFAULT
5496 $$ = makeDefElem("collate", NULL);
5498 | CTYPE opt_equal Sconst
5500 $$ = makeDefElem("ctype", (Node *)makeString($3));
5502 | CTYPE opt_equal DEFAULT
5504 $$ = makeDefElem("ctype", NULL);
5506 | CONNECTION LIMIT opt_equal SignedIconst
5508 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
5510 | OWNER opt_equal name
5512 $$ = makeDefElem("owner", (Node *)makeString($3));
5514 | OWNER opt_equal DEFAULT
5516 $$ = makeDefElem("owner", NULL);
5521 * Though the equals sign doesn't match other WITH options, pg_dump uses
5522 * equals for backward compatibility, and it doesn't seem worth removing it.
5529 /*****************************************************************************
5533 *****************************************************************************/
5536 ALTER DATABASE database_name opt_with alterdb_opt_list
5538 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
5545 AlterDatabaseSetStmt:
5546 ALTER DATABASE database_name SetResetClause
5548 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
5557 alterdb_opt_list alterdb_opt_item { $$ = lappend($1, $2); }
5558 | /* EMPTY */ { $$ = NIL; }
5562 CONNECTION LIMIT opt_equal SignedIconst
5564 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
5569 /*****************************************************************************
5571 * DROP DATABASE [ IF EXISTS ]
5573 * This is implicitly CASCADE, no need for drop behavior
5574 *****************************************************************************/
5576 DropdbStmt: DROP DATABASE database_name
5578 DropdbStmt *n = makeNode(DropdbStmt);
5580 n->missing_ok = FALSE;
5583 | DROP DATABASE IF_P EXISTS database_name
5585 DropdbStmt *n = makeNode(DropdbStmt);
5587 n->missing_ok = TRUE;
5593 /*****************************************************************************
5595 * Manipulate a domain
5597 *****************************************************************************/
5600 CREATE DOMAIN_P any_name opt_as Typename ColQualList
5602 CreateDomainStmt *n = makeNode(CreateDomainStmt);
5605 n->constraints = $6;
5611 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
5612 ALTER DOMAIN_P any_name alter_column_default
5614 AlterDomainStmt *n = makeNode(AlterDomainStmt);
5620 /* ALTER DOMAIN <domain> DROP NOT NULL */
5621 | ALTER DOMAIN_P any_name DROP NOT NULL_P
5623 AlterDomainStmt *n = makeNode(AlterDomainStmt);
5628 /* ALTER DOMAIN <domain> SET NOT NULL */
5629 | ALTER DOMAIN_P any_name SET NOT NULL_P
5631 AlterDomainStmt *n = makeNode(AlterDomainStmt);
5636 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
5637 | ALTER DOMAIN_P any_name ADD_P TableConstraint
5639 AlterDomainStmt *n = makeNode(AlterDomainStmt);
5645 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
5646 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
5648 AlterDomainStmt *n = makeNode(AlterDomainStmt);
5662 /*****************************************************************************
5664 * Manipulate a text search dictionary or configuration
5666 *****************************************************************************/
5668 AlterTSDictionaryStmt:
5669 ALTER TEXT_P SEARCH DICTIONARY any_name definition
5671 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
5678 AlterTSConfigurationStmt:
5679 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
5681 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5685 n->override = false;
5689 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
5691 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5699 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
5701 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5704 n->dicts = list_make2($9,$11);
5705 n->override = false;
5709 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
5711 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5714 n->dicts = list_make2($11,$13);
5715 n->override = false;
5719 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
5721 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5724 n->missing_ok = false;
5727 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
5729 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5732 n->missing_ok = true;
5738 /*****************************************************************************
5740 * Manipulate a conversion
5742 * CREATE [DEFAULT] CONVERSION <conversion_name>
5743 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
5745 *****************************************************************************/
5747 CreateConversionStmt:
5748 CREATE opt_default CONVERSION_P any_name FOR Sconst
5749 TO Sconst FROM any_name
5751 CreateConversionStmt *n = makeNode(CreateConversionStmt);
5752 n->conversion_name = $4;
5753 n->for_encoding_name = $6;
5754 n->to_encoding_name = $8;
5761 /*****************************************************************************
5764 * CLUSTER <qualified_name> [ USING <index_name> ]
5766 * CLUSTER <index_name> ON <qualified_name> (for pre-8.3)
5768 *****************************************************************************/
5771 CLUSTER qualified_name cluster_index_specification
5773 ClusterStmt *n = makeNode(ClusterStmt);
5780 ClusterStmt *n = makeNode(ClusterStmt);
5782 n->indexname = NULL;
5785 /* kept for pre-8.3 compatibility */
5786 | CLUSTER index_name ON qualified_name
5788 ClusterStmt *n = makeNode(ClusterStmt);
5795 cluster_index_specification:
5796 USING index_name { $$ = $2; }
5797 | /*EMPTY*/ { $$ = NULL; }
5801 /*****************************************************************************
5807 *****************************************************************************/
5809 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
5811 VacuumStmt *n = makeNode(VacuumStmt);
5815 n->freeze_min_age = $3 ? 0 : -1;
5821 | VACUUM opt_full opt_freeze opt_verbose qualified_name
5823 VacuumStmt *n = makeNode(VacuumStmt);
5827 n->freeze_min_age = $3 ? 0 : -1;
5833 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
5835 VacuumStmt *n = (VacuumStmt *) $5;
5838 n->freeze_min_age = $3 ? 0 : -1;
5845 analyze_keyword opt_verbose
5847 VacuumStmt *n = makeNode(VacuumStmt);
5851 n->freeze_min_age = -1;
5857 | analyze_keyword opt_verbose qualified_name opt_name_list
5859 VacuumStmt *n = makeNode(VacuumStmt);
5863 n->freeze_min_age = -1;
5873 | ANALYSE /* British */ {}
5877 VERBOSE { $$ = TRUE; }
5878 | /*EMPTY*/ { $$ = FALSE; }
5881 opt_full: FULL { $$ = TRUE; }
5882 | /*EMPTY*/ { $$ = FALSE; }
5885 opt_freeze: FREEZE { $$ = TRUE; }
5886 | /*EMPTY*/ { $$ = FALSE; }
5890 '(' name_list ')' { $$ = $2; }
5891 | /*EMPTY*/ { $$ = NIL; }
5895 /*****************************************************************************
5898 * EXPLAIN [ANALYZE] [VERBOSE] query
5900 *****************************************************************************/
5902 ExplainStmt: EXPLAIN opt_analyze opt_verbose ExplainableStmt
5904 ExplainStmt *n = makeNode(ExplainStmt);
5919 | ExecuteStmt /* by default all are $$=$1 */
5923 analyze_keyword { $$ = TRUE; }
5924 | /* EMPTY */ { $$ = FALSE; }
5927 /*****************************************************************************
5930 * PREPARE <plan_name> [(args, ...)] AS <query>
5932 *****************************************************************************/
5934 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
5936 PrepareStmt *n = makeNode(PrepareStmt);
5944 prep_type_clause: '(' type_list ')' { $$ = $2; }
5945 | /* EMPTY */ { $$ = NIL; }
5952 | DeleteStmt /* by default all are $$=$1 */
5955 /*****************************************************************************
5957 * EXECUTE <plan_name> [(params, ...)]
5958 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
5960 *****************************************************************************/
5962 ExecuteStmt: EXECUTE name execute_param_clause
5964 ExecuteStmt *n = makeNode(ExecuteStmt);
5970 | CREATE OptTemp TABLE create_as_target AS
5971 EXECUTE name execute_param_clause
5973 ExecuteStmt *n = makeNode(ExecuteStmt);
5976 $4->rel->istemp = $2;
5980 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5981 errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
5982 /* ... because it's not implemented, but it could be */
5987 execute_param_clause: '(' expr_list ')' { $$ = $2; }
5988 | /* EMPTY */ { $$ = NIL; }
5991 /*****************************************************************************
5994 * DEALLOCATE [PREPARE] <plan_name>
5996 *****************************************************************************/
5998 DeallocateStmt: DEALLOCATE name
6000 DeallocateStmt *n = makeNode(DeallocateStmt);
6004 | DEALLOCATE PREPARE name
6006 DeallocateStmt *n = makeNode(DeallocateStmt);
6012 DeallocateStmt *n = makeNode(DeallocateStmt);
6016 | DEALLOCATE PREPARE ALL
6018 DeallocateStmt *n = makeNode(DeallocateStmt);
6024 /*****************************************************************************
6029 *****************************************************************************/
6032 INSERT INTO qualified_name insert_rest returning_clause
6035 $4->returningList = $5;
6043 $$ = makeNode(InsertStmt);
6045 $$->selectStmt = $1;
6047 | '(' insert_column_list ')' SelectStmt
6049 $$ = makeNode(InsertStmt);
6051 $$->selectStmt = $4;
6055 $$ = makeNode(InsertStmt);
6057 $$->selectStmt = NULL;
6063 { $$ = list_make1($1); }
6064 | insert_column_list ',' insert_column_item
6065 { $$ = lappend($1, $3); }
6069 ColId opt_indirection
6071 $$ = makeNode(ResTarget);
6073 $$->indirection = check_indirection($2);
6080 RETURNING target_list { $$ = $2; }
6081 | /* EMPTY */ { $$ = NIL; }
6085 /*****************************************************************************
6090 *****************************************************************************/
6092 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
6093 using_clause where_or_current_clause returning_clause
6095 DeleteStmt *n = makeNode(DeleteStmt);
6097 n->usingClause = $4;
6098 n->whereClause = $5;
6099 n->returningList = $6;
6105 USING from_list { $$ = $2; }
6106 | /*EMPTY*/ { $$ = NIL; }
6109 LockStmt: LOCK_P opt_table qualified_name_list opt_lock opt_nowait
6111 LockStmt *n = makeNode(LockStmt);
6120 opt_lock: IN_P lock_type MODE { $$ = $2; }
6121 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
6124 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
6125 | ROW SHARE { $$ = RowShareLock; }
6126 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
6127 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
6128 | SHARE { $$ = ShareLock; }
6129 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
6130 | EXCLUSIVE { $$ = ExclusiveLock; }
6131 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
6134 opt_nowait: NOWAIT { $$ = TRUE; }
6135 | /*EMPTY*/ { $$ = FALSE; }
6139 /*****************************************************************************
6142 * UpdateStmt (UPDATE)
6144 *****************************************************************************/
6146 UpdateStmt: UPDATE relation_expr_opt_alias
6149 where_or_current_clause
6152 UpdateStmt *n = makeNode(UpdateStmt);
6156 n->whereClause = $6;
6157 n->returningList = $7;
6163 set_clause { $$ = $1; }
6164 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
6168 single_set_clause { $$ = list_make1($1); }
6169 | multiple_set_clause { $$ = $1; }
6173 set_target '=' ctext_expr
6176 $$->val = (Node *) $3;
6180 multiple_set_clause:
6181 '(' set_target_list ')' '=' ctext_row
6187 * Break the ctext_row apart, merge individual expressions
6188 * into the destination ResTargets. XXX this approach
6189 * cannot work for general row expressions as sources.
6191 if (list_length($2) != list_length($5))
6193 (errcode(ERRCODE_SYNTAX_ERROR),
6194 errmsg("number of columns does not match number of values"),
6195 scanner_errposition(@1)));
6196 forboth(col_cell, $2, val_cell, $5)
6198 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
6199 Node *res_val = (Node *) lfirst(val_cell);
6201 res_col->val = res_val;
6209 ColId opt_indirection
6211 $$ = makeNode(ResTarget);
6213 $$->indirection = check_indirection($2);
6214 $$->val = NULL; /* upper production sets this */
6220 set_target { $$ = list_make1($1); }
6221 | set_target_list ',' set_target { $$ = lappend($1,$3); }
6225 /*****************************************************************************
6230 *****************************************************************************/
6231 DeclareCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR SelectStmt
6233 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
6235 /* currently we always set FAST_PLAN option */
6236 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
6242 cursor_options: /*EMPTY*/ { $$ = 0; }
6243 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
6244 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
6245 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
6246 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
6249 opt_hold: /* EMPTY */ { $$ = 0; }
6250 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
6251 | WITHOUT HOLD { $$ = 0; }
6254 /*****************************************************************************
6259 *****************************************************************************/
6261 /* A complete SELECT statement looks like this.
6263 * The rule returns either a single SelectStmt node or a tree of them,
6264 * representing a set-operation tree.
6266 * There is an ambiguity when a sub-SELECT is within an a_expr and there
6267 * are excess parentheses: do the parentheses belong to the sub-SELECT or
6268 * to the surrounding a_expr? We don't really care, but yacc wants to know.
6269 * To resolve the ambiguity, we are careful to define the grammar so that
6270 * the decision is staved off as long as possible: as long as we can keep
6271 * absorbing parentheses into the sub-SELECT, we will do so, and only when
6272 * it's no longer possible to do that will we decide that parens belong to
6273 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
6274 * parentheses are treated as part of the sub-select. The necessity of doing
6275 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
6276 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
6277 * SELECT viewpoint when we see the UNION.
6279 * This approach is implemented by defining a nonterminal select_with_parens,
6280 * which represents a SELECT with at least one outer layer of parentheses,
6281 * and being careful to use select_with_parens, never '(' SelectStmt ')',
6282 * in the expression grammar. We will then have shift-reduce conflicts
6283 * which we can resolve in favor of always treating '(' <select> ')' as
6284 * a select_with_parens. To resolve the conflicts, the productions that
6285 * conflict with the select_with_parens productions are manually given
6286 * precedences lower than the precedence of ')', thereby ensuring that we
6287 * shift ')' (and then reduce to select_with_parens) rather than trying to
6288 * reduce the inner <select> nonterminal to something else. We use UMINUS
6289 * precedence for this, which is a fairly arbitrary choice.
6291 * To be able to define select_with_parens itself without ambiguity, we need
6292 * a nonterminal select_no_parens that represents a SELECT structure with no
6293 * outermost parentheses. This is a little bit tedious, but it works.
6295 * In non-expression contexts, we use SelectStmt which can represent a SELECT
6296 * with or without outer parentheses.
6299 SelectStmt: select_no_parens %prec UMINUS
6300 | select_with_parens %prec UMINUS
6304 '(' select_no_parens ')' { $$ = $2; }
6305 | '(' select_with_parens ')' { $$ = $2; }
6309 * This rule parses the equivalent of the standard's <query expression>.
6310 * The duplicative productions are annoying, but hard to get rid of without
6311 * creating shift/reduce conflicts.
6313 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
6314 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
6315 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
6319 simple_select { $$ = $1; }
6320 | select_clause sort_clause
6322 insertSelectOptions((SelectStmt *) $1, $2, NIL,
6326 | select_clause opt_sort_clause for_locking_clause opt_select_limit
6328 insertSelectOptions((SelectStmt *) $1, $2, $3,
6329 list_nth($4, 0), list_nth($4, 1),
6333 | select_clause opt_sort_clause select_limit opt_for_locking_clause
6335 insertSelectOptions((SelectStmt *) $1, $2, $4,
6336 list_nth($3, 0), list_nth($3, 1),
6340 | with_clause simple_select
6342 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
6347 | with_clause select_clause sort_clause
6349 insertSelectOptions((SelectStmt *) $2, $3, NIL,
6354 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
6356 insertSelectOptions((SelectStmt *) $2, $3, $4,
6357 list_nth($5, 0), list_nth($5, 1),
6361 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
6363 insertSelectOptions((SelectStmt *) $2, $3, $5,
6364 list_nth($4, 0), list_nth($4, 1),
6371 simple_select { $$ = $1; }
6372 | select_with_parens { $$ = $1; }
6376 * This rule parses SELECT statements that can appear within set operations,
6377 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
6378 * the ordering of the set operations. Without '(' and ')' we want the
6379 * operations to be ordered per the precedence specs at the head of this file.
6381 * As with select_no_parens, simple_select cannot have outer parentheses,
6382 * but can have parenthesized subclauses.
6384 * Note that sort clauses cannot be included at this level --- SQL92 requires
6385 * SELECT foo UNION SELECT bar ORDER BY baz
6387 * (SELECT foo UNION SELECT bar) ORDER BY baz
6389 * SELECT foo UNION (SELECT bar ORDER BY baz)
6390 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
6391 * described as part of the select_no_parens production, not simple_select.
6392 * This does not limit functionality, because you can reintroduce these
6393 * clauses inside parentheses.
6395 * NOTE: only the leftmost component SelectStmt should have INTO.
6396 * However, this is not checked by the grammar; parse analysis must check it.
6399 SELECT opt_distinct target_list
6400 into_clause from_clause where_clause
6401 group_clause having_clause
6403 SelectStmt *n = makeNode(SelectStmt);
6404 n->distinctClause = $2;
6408 n->whereClause = $6;
6409 n->groupClause = $7;
6410 n->havingClause = $8;
6413 | values_clause { $$ = $1; }
6414 | select_clause UNION opt_all select_clause
6416 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
6418 | select_clause INTERSECT opt_all select_clause
6420 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
6422 | select_clause EXCEPT opt_all select_clause
6424 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
6429 * SQL standard WITH clause looks like:
6431 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
6432 * AS (query) [ SEARCH or CYCLE clause ]
6434 * We don't currently support the SEARCH or CYCLE clause.
6439 $$ = makeNode(WithClause);
6441 $$->recursive = false;
6444 | WITH RECURSIVE cte_list
6446 $$ = makeNode(WithClause);
6448 $$->recursive = true;
6454 common_table_expr { $$ = list_make1($1); }
6455 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
6458 common_table_expr: name opt_name_list AS select_with_parens
6460 CommonTableExpr *n = makeNode(CommonTableExpr);
6462 n->aliascolnames = $2;
6470 INTO OptTempTableName
6472 $$ = makeNode(IntoClause);
6476 $$->onCommit = ONCOMMIT_NOOP;
6477 $$->tableSpaceName = NULL;
6484 * Redundancy here is needed to avoid shift/reduce conflicts,
6485 * since TEMP is not a reserved word. See also OptTemp.
6488 TEMPORARY opt_table qualified_name
6493 | TEMP opt_table qualified_name
6498 | LOCAL TEMPORARY opt_table qualified_name
6503 | LOCAL TEMP opt_table qualified_name
6508 | GLOBAL TEMPORARY opt_table qualified_name
6513 | GLOBAL TEMP opt_table qualified_name
6518 | TABLE qualified_name
6534 opt_all: ALL { $$ = TRUE; }
6535 | DISTINCT { $$ = FALSE; }
6536 | /*EMPTY*/ { $$ = FALSE; }
6539 /* We use (NIL) as a placeholder to indicate that all target expressions
6540 * should be placed in the DISTINCT list during parsetree analysis.
6543 DISTINCT { $$ = list_make1(NIL); }
6544 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
6546 | /*EMPTY*/ { $$ = NIL; }
6550 sort_clause { $$ = $1;}
6551 | /*EMPTY*/ { $$ = NIL; }
6555 ORDER BY sortby_list { $$ = $3; }
6559 sortby { $$ = list_make1($1); }
6560 | sortby_list ',' sortby { $$ = lappend($1, $3); }
6563 sortby: a_expr USING qual_all_Op opt_nulls_order
6565 $$ = makeNode(SortBy);
6567 $$->sortby_dir = SORTBY_USING;
6568 $$->sortby_nulls = $4;
6572 | a_expr opt_asc_desc opt_nulls_order
6574 $$ = makeNode(SortBy);
6576 $$->sortby_dir = $2;
6577 $$->sortby_nulls = $3;
6579 $$->location = -1; /* no operator */
6585 LIMIT select_limit_value OFFSET select_offset_value
6586 { $$ = list_make2($4, $2); }
6587 | OFFSET select_offset_value LIMIT select_limit_value
6588 { $$ = list_make2($2, $4); }
6589 | LIMIT select_limit_value
6590 { $$ = list_make2(NULL, $2); }
6591 | OFFSET select_offset_value
6592 { $$ = list_make2($2, NULL); }
6593 | LIMIT select_limit_value ',' select_offset_value
6595 /* Disabled because it was too confusing, bjm 2002-02-18 */
6597 (errcode(ERRCODE_SYNTAX_ERROR),
6598 errmsg("LIMIT #,# syntax is not supported"),
6599 errhint("Use separate LIMIT and OFFSET clauses."),
6600 scanner_errposition(@1)));
6602 /* SQL:2008 syntax variants */
6603 | OFFSET select_offset_value2 row_or_rows
6604 { $$ = list_make2($2, NULL); }
6605 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
6606 { $$ = list_make2(NULL, $3); }
6607 | OFFSET select_offset_value2 row_or_rows FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
6608 { $$ = list_make2($2, $6); }
6612 select_limit { $$ = $1; }
6614 { $$ = list_make2(NULL,NULL); }
6621 /* LIMIT ALL is represented as a NULL constant */
6622 $$ = makeNullAConst(@1);
6627 * Allowing full expressions without parentheses causes various parsing
6628 * problems with the trailing ROW/ROWS key words. SQL only calls for
6629 * constants, so we allow the rest only with parentheses.
6631 opt_select_fetch_first_value:
6632 SignedIconst { $$ = makeIntConst($1, @1); }
6633 | '(' a_expr ')' { $$ = $2; }
6634 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
6637 select_offset_value:
6642 * Again, the trailing ROW/ROWS in this case prevent the full expression
6643 * syntax. c_expr is the best we can do.
6645 select_offset_value2:
6661 GROUP_P BY expr_list { $$ = $3; }
6662 | /*EMPTY*/ { $$ = NIL; }
6666 HAVING a_expr { $$ = $2; }
6667 | /*EMPTY*/ { $$ = NULL; }
6671 for_locking_items { $$ = $1; }
6672 | FOR READ ONLY { $$ = NIL; }
6675 opt_for_locking_clause:
6676 for_locking_clause { $$ = $1; }
6677 | /* EMPTY */ { $$ = NIL; }
6681 for_locking_item { $$ = list_make1($1); }
6682 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
6686 FOR UPDATE locked_rels_list opt_nowait
6688 LockingClause *n = makeNode(LockingClause);
6690 n->forUpdate = TRUE;
6694 | FOR SHARE locked_rels_list opt_nowait
6696 LockingClause *n = makeNode(LockingClause);
6698 n->forUpdate = FALSE;
6705 OF qualified_name_list { $$ = $2; }
6706 | /* EMPTY */ { $$ = NIL; }
6713 SelectStmt *n = makeNode(SelectStmt);
6714 n->valuesLists = list_make1($2);
6717 | values_clause ',' ctext_row
6719 SelectStmt *n = (SelectStmt *) $1;
6720 n->valuesLists = lappend(n->valuesLists, $3);
6726 /*****************************************************************************
6728 * clauses common to all Optimizable Stmts:
6729 * from_clause - allow list of both JOIN expressions and table names
6730 * where_clause - qualifications for joins or restrictions
6732 *****************************************************************************/
6735 FROM from_list { $$ = $2; }
6736 | /*EMPTY*/ { $$ = NIL; }
6740 table_ref { $$ = list_make1($1); }
6741 | from_list ',' table_ref { $$ = lappend($1, $3); }
6745 * table_ref is where an alias clause can be attached. Note we cannot make
6746 * alias_clause have an empty production because that causes parse conflicts
6747 * between table_ref := '(' joined_table ')' alias_clause
6748 * and joined_table := '(' joined_table ')'. So, we must have the
6749 * redundant-looking productions here instead.
6751 table_ref: relation_expr
6755 | relation_expr alias_clause
6762 RangeFunction *n = makeNode(RangeFunction);
6763 n->funccallnode = $1;
6764 n->coldeflist = NIL;
6767 | func_table alias_clause
6769 RangeFunction *n = makeNode(RangeFunction);
6770 n->funccallnode = $1;
6772 n->coldeflist = NIL;
6775 | func_table AS '(' TableFuncElementList ')'
6777 RangeFunction *n = makeNode(RangeFunction);
6778 n->funccallnode = $1;
6782 | func_table AS ColId '(' TableFuncElementList ')'
6784 RangeFunction *n = makeNode(RangeFunction);
6785 Alias *a = makeNode(Alias);
6786 n->funccallnode = $1;
6792 | func_table ColId '(' TableFuncElementList ')'
6794 RangeFunction *n = makeNode(RangeFunction);
6795 Alias *a = makeNode(Alias);
6796 n->funccallnode = $1;
6802 | select_with_parens
6805 * The SQL spec does not permit a subselect
6806 * (<derived_table>) without an alias clause,
6807 * so we don't either. This avoids the problem
6808 * of needing to invent a unique refname for it.
6809 * That could be surmounted if there's sufficient
6810 * popular demand, but for now let's just implement
6811 * the spec and see if anyone complains.
6812 * However, it does seem like a good idea to emit
6813 * an error message that's better than "syntax error".
6815 if (IsA($1, SelectStmt) &&
6816 ((SelectStmt *) $1)->valuesLists)
6818 (errcode(ERRCODE_SYNTAX_ERROR),
6819 errmsg("VALUES in FROM must have an alias"),
6820 errhint("For example, FROM (VALUES ...) [AS] foo."),
6821 scanner_errposition(@1)));
6824 (errcode(ERRCODE_SYNTAX_ERROR),
6825 errmsg("subquery in FROM must have an alias"),
6826 errhint("For example, FROM (SELECT ...) [AS] foo."),
6827 scanner_errposition(@1)));
6830 | select_with_parens alias_clause
6832 RangeSubselect *n = makeNode(RangeSubselect);
6841 | '(' joined_table ')' alias_clause
6850 * It may seem silly to separate joined_table from table_ref, but there is
6851 * method in SQL92's madness: if you don't do it this way you get reduce-
6852 * reduce conflicts, because it's not clear to the parser generator whether
6853 * to expect alias_clause after ')' or not. For the same reason we must
6854 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
6855 * join_type to expand to empty; if we try it, the parser generator can't
6856 * figure out when to reduce an empty join_type right after table_ref.
6858 * Note that a CROSS JOIN is the same as an unqualified
6859 * INNER JOIN, and an INNER JOIN/ON has the same shape
6860 * but a qualification expression to limit membership.
6861 * A NATURAL JOIN implicitly matches column names between
6862 * tables and the shape is determined by which columns are
6863 * in common. We'll collect columns during the later transformations.
6867 '(' joined_table ')'
6871 | table_ref CROSS JOIN table_ref
6873 /* CROSS JOIN is same as unqualified inner join */
6874 JoinExpr *n = makeNode(JoinExpr);
6875 n->jointype = JOIN_INNER;
6876 n->isNatural = FALSE;
6883 | table_ref join_type JOIN table_ref join_qual
6885 JoinExpr *n = makeNode(JoinExpr);
6887 n->isNatural = FALSE;
6890 if ($5 != NULL && IsA($5, List))
6891 n->using = (List *) $5; /* USING clause */
6893 n->quals = $5; /* ON clause */
6896 | table_ref JOIN table_ref join_qual
6898 /* letting join_type reduce to empty doesn't work */
6899 JoinExpr *n = makeNode(JoinExpr);
6900 n->jointype = JOIN_INNER;
6901 n->isNatural = FALSE;
6904 if ($4 != NULL && IsA($4, List))
6905 n->using = (List *) $4; /* USING clause */
6907 n->quals = $4; /* ON clause */
6910 | table_ref NATURAL join_type JOIN table_ref
6912 JoinExpr *n = makeNode(JoinExpr);
6914 n->isNatural = TRUE;
6917 n->using = NIL; /* figure out which columns later... */
6918 n->quals = NULL; /* fill later */
6921 | table_ref NATURAL JOIN table_ref
6923 /* letting join_type reduce to empty doesn't work */
6924 JoinExpr *n = makeNode(JoinExpr);
6925 n->jointype = JOIN_INNER;
6926 n->isNatural = TRUE;
6929 n->using = NIL; /* figure out which columns later... */
6930 n->quals = NULL; /* fill later */
6936 AS ColId '(' name_list ')'
6938 $$ = makeNode(Alias);
6944 $$ = makeNode(Alias);
6947 | ColId '(' name_list ')'
6949 $$ = makeNode(Alias);
6955 $$ = makeNode(Alias);
6960 join_type: FULL join_outer { $$ = JOIN_FULL; }
6961 | LEFT join_outer { $$ = JOIN_LEFT; }
6962 | RIGHT join_outer { $$ = JOIN_RIGHT; }
6963 | INNER_P { $$ = JOIN_INNER; }
6966 /* OUTER is just noise... */
6967 join_outer: OUTER_P { $$ = NULL; }
6968 | /*EMPTY*/ { $$ = NULL; }
6971 /* JOIN qualification clauses
6972 * Possibilities are:
6973 * USING ( column list ) allows only unqualified column names,
6974 * which must match between tables.
6975 * ON expr allows more general qualifications.
6977 * We return USING as a List node, while an ON-expr will not be a List.
6980 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
6981 | ON a_expr { $$ = $2; }
6988 /* default inheritance */
6990 $$->inhOpt = INH_DEFAULT;
6993 | qualified_name '*'
6995 /* inheritance query */
6997 $$->inhOpt = INH_YES;
7000 | ONLY qualified_name
7002 /* no inheritance */
7004 $$->inhOpt = INH_NO;
7007 | ONLY '(' qualified_name ')'
7009 /* no inheritance, SQL99-style syntax */
7011 $$->inhOpt = INH_NO;
7018 * Given "UPDATE foo set set ...", we have to decide without looking any
7019 * further ahead whether the first "set" is an alias or the UPDATE's SET
7020 * keyword. Since "set" is allowed as a column name both interpretations
7021 * are feasible. We resolve the shift/reduce conflict by giving the first
7022 * relation_expr_opt_alias production a higher precedence than the SET token
7023 * has, causing the parser to prefer to reduce, in effect assuming that the
7024 * SET is not an alias.
7026 relation_expr_opt_alias: relation_expr %prec UMINUS
7030 | relation_expr ColId
7032 Alias *alias = makeNode(Alias);
7033 alias->aliasname = $2;
7037 | relation_expr AS ColId
7039 Alias *alias = makeNode(Alias);
7040 alias->aliasname = $3;
7047 func_table: func_expr { $$ = $1; }
7052 WHERE a_expr { $$ = $2; }
7053 | /*EMPTY*/ { $$ = NULL; }
7056 /* variant for UPDATE and DELETE */
7057 where_or_current_clause:
7058 WHERE a_expr { $$ = $2; }
7059 | WHERE CURRENT_P OF name
7061 CurrentOfExpr *n = makeNode(CurrentOfExpr);
7062 /* cvarno is filled in by parse analysis */
7063 n->cursor_name = $4;
7064 n->cursor_param = 0;
7067 | WHERE CURRENT_P OF PARAM
7069 CurrentOfExpr *n = makeNode(CurrentOfExpr);
7070 /* cvarno is filled in by parse analysis */
7071 n->cursor_name = NULL;
7072 n->cursor_param = $4;
7075 | /*EMPTY*/ { $$ = NULL; }
7079 TableFuncElementList:
7082 $$ = list_make1($1);
7084 | TableFuncElementList ',' TableFuncElement
7086 $$ = lappend($1, $3);
7090 TableFuncElement: ColId Typename
7092 ColumnDef *n = makeNode(ColumnDef);
7095 n->constraints = NIL;
7101 /*****************************************************************************
7104 * SQL92 introduces a large amount of type-specific syntax.
7105 * Define individual clauses to handle these cases, and use
7106 * the generic case to handle regular type-extensible Postgres syntax.
7107 * - thomas 1997-10-10
7109 *****************************************************************************/
7111 Typename: SimpleTypename opt_array_bounds
7114 $$->arrayBounds = $2;
7116 | SETOF SimpleTypename opt_array_bounds
7119 $$->arrayBounds = $3;
7122 | SimpleTypename ARRAY '[' Iconst ']'
7124 /* SQL99's redundant syntax */
7126 $$->arrayBounds = list_make1(makeInteger($4));
7128 | SETOF SimpleTypename ARRAY '[' Iconst ']'
7130 /* SQL99's redundant syntax */
7132 $$->arrayBounds = list_make1(makeInteger($5));
7138 opt_array_bounds '[' ']'
7139 { $$ = lappend($1, makeInteger(-1)); }
7140 | opt_array_bounds '[' Iconst ']'
7141 { $$ = lappend($1, makeInteger($3)); }
7147 GenericType { $$ = $1; }
7148 | Numeric { $$ = $1; }
7150 | Character { $$ = $1; }
7151 | ConstDatetime { $$ = $1; }
7152 | ConstInterval opt_interval
7157 | ConstInterval '(' Iconst ')' opt_interval
7162 if (list_length($5) != 1)
7164 (errcode(ERRCODE_SYNTAX_ERROR),
7165 errmsg("interval precision specified twice"),
7166 scanner_errposition(@1)));
7167 $$->typmods = lappend($5, makeIntConst($3, @3));
7170 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
7171 makeIntConst($3, @3));
7175 /* We have a separate ConstTypename to allow defaulting fixed-length
7176 * types such as CHAR() and BIT() to an unspecified length.
7177 * SQL9x requires that these default to a length of one, but this
7178 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
7179 * where there is an obvious better choice to make.
7180 * Note that ConstInterval is not included here since it must
7181 * be pushed up higher in the rules to accomodate the postfix
7182 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
7183 * the generic-type-name case in AExprConst to avoid premature
7184 * reduce/reduce conflicts against function names.
7187 Numeric { $$ = $1; }
7188 | ConstBit { $$ = $1; }
7189 | ConstCharacter { $$ = $1; }
7190 | ConstDatetime { $$ = $1; }
7194 * GenericType covers all type names that don't have special syntax mandated
7195 * by the standard, including qualified names. We also allow type modifiers.
7196 * To avoid parsing conflicts against function invocations, the modifiers
7197 * have to be shown as expr_list here, but parse analysis will only accept
7198 * constants for them.
7201 type_function_name opt_type_modifiers
7203 $$ = makeTypeName($1);
7207 | type_function_name attrs opt_type_modifiers
7209 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
7215 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
7216 | /* EMPTY */ { $$ = NIL; }
7220 * SQL92 numeric data types
7224 $$ = SystemTypeName("int4");
7229 $$ = SystemTypeName("int4");
7234 $$ = SystemTypeName("int2");
7239 $$ = SystemTypeName("int8");
7244 $$ = SystemTypeName("float4");
7252 | DOUBLE_P PRECISION
7254 $$ = SystemTypeName("float8");
7257 | DECIMAL_P opt_type_modifiers
7259 $$ = SystemTypeName("numeric");
7263 | DEC opt_type_modifiers
7265 $$ = SystemTypeName("numeric");
7269 | NUMERIC opt_type_modifiers
7271 $$ = SystemTypeName("numeric");
7277 $$ = SystemTypeName("bool");
7282 opt_float: '(' Iconst ')'
7285 * Check FLOAT() precision limits assuming IEEE floating
7286 * types - thomas 1997-09-18
7290 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7291 errmsg("precision for type float must be at least 1 bit"),
7292 scanner_errposition(@2)));
7294 $$ = SystemTypeName("float4");
7296 $$ = SystemTypeName("float8");
7299 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7300 errmsg("precision for type float must be less than 54 bits"),
7301 scanner_errposition(@2)));
7305 $$ = SystemTypeName("float8");
7310 * SQL92 bit-field data types
7311 * The following implements BIT() and BIT VARYING().
7323 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
7324 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
7325 ConstBit: BitWithLength
7337 BIT opt_varying '(' expr_list ')'
7341 typname = $2 ? "varbit" : "bit";
7342 $$ = SystemTypeName(typname);
7351 /* bit defaults to bit(1), varbit to no limit */
7354 $$ = SystemTypeName("varbit");
7358 $$ = SystemTypeName("bit");
7359 $$->typmods = list_make1(makeIntConst(1, -1));
7367 * SQL92 character data types
7368 * The following implements CHAR() and VARCHAR().
7370 Character: CharacterWithLength
7374 | CharacterWithoutLength
7380 ConstCharacter: CharacterWithLength
7384 | CharacterWithoutLength
7386 /* Length was not specified so allow to be unrestricted.
7387 * This handles problems with fixed-length (bpchar) strings
7388 * which in column definitions must default to a length
7389 * of one, but should not be constrained if the length
7390 * was not specified.
7397 CharacterWithLength: character '(' Iconst ')' opt_charset
7399 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
7403 type = palloc(strlen($1) + 1 + strlen($5) + 1);
7410 $$ = SystemTypeName($1);
7411 $$->typmods = list_make1(makeIntConst($3, @3));
7416 CharacterWithoutLength: character opt_charset
7418 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
7422 type = palloc(strlen($1) + 1 + strlen($2) + 1);
7429 $$ = SystemTypeName($1);
7431 /* char defaults to char(1), varchar to no limit */
7432 if (strcmp($1, "bpchar") == 0)
7433 $$->typmods = list_make1(makeIntConst(1, -1));
7439 character: CHARACTER opt_varying
7440 { $$ = $2 ? "varchar": "bpchar"; }
7441 | CHAR_P opt_varying
7442 { $$ = $2 ? "varchar": "bpchar"; }
7445 | NATIONAL CHARACTER opt_varying
7446 { $$ = $3 ? "varchar": "bpchar"; }
7447 | NATIONAL CHAR_P opt_varying
7448 { $$ = $3 ? "varchar": "bpchar"; }
7450 { $$ = $2 ? "varchar": "bpchar"; }
7454 VARYING { $$ = TRUE; }
7455 | /*EMPTY*/ { $$ = FALSE; }
7459 CHARACTER SET ColId { $$ = $3; }
7460 | /*EMPTY*/ { $$ = NULL; }
7464 * SQL92 date/time types
7467 TIMESTAMP '(' Iconst ')' opt_timezone
7470 $$ = SystemTypeName("timestamptz");
7472 $$ = SystemTypeName("timestamp");
7473 $$->typmods = list_make1(makeIntConst($3, @3));
7476 | TIMESTAMP opt_timezone
7479 $$ = SystemTypeName("timestamptz");
7481 $$ = SystemTypeName("timestamp");
7484 | TIME '(' Iconst ')' opt_timezone
7487 $$ = SystemTypeName("timetz");
7489 $$ = SystemTypeName("time");
7490 $$->typmods = list_make1(makeIntConst($3, @3));
7496 $$ = SystemTypeName("timetz");
7498 $$ = SystemTypeName("time");
7506 $$ = SystemTypeName("interval");
7512 WITH TIME ZONE { $$ = TRUE; }
7513 | WITHOUT TIME ZONE { $$ = FALSE; }
7514 | /*EMPTY*/ { $$ = FALSE; }
7519 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
7521 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
7523 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
7525 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
7527 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
7532 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
7533 INTERVAL_MASK(MONTH), @1));
7537 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
7538 INTERVAL_MASK(HOUR), @1));
7542 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
7543 INTERVAL_MASK(HOUR) |
7544 INTERVAL_MASK(MINUTE), @1));
7546 | DAY_P TO interval_second
7549 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
7550 INTERVAL_MASK(HOUR) |
7551 INTERVAL_MASK(MINUTE) |
7552 INTERVAL_MASK(SECOND), @1);
7554 | HOUR_P TO MINUTE_P
7556 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
7557 INTERVAL_MASK(MINUTE), @1));
7559 | HOUR_P TO interval_second
7562 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
7563 INTERVAL_MASK(MINUTE) |
7564 INTERVAL_MASK(SECOND), @1);
7566 | MINUTE_P TO interval_second
7569 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
7570 INTERVAL_MASK(SECOND), @1);
7579 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
7581 | SECOND_P '(' Iconst ')'
7583 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
7584 makeIntConst($3, @3));
7589 /*****************************************************************************
7591 * expression grammar
7593 *****************************************************************************/
7596 * General expressions
7597 * This is the heart of the expression syntax.
7599 * We have two expression types: a_expr is the unrestricted kind, and
7600 * b_expr is a subset that must be used in some places to avoid shift/reduce
7601 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
7602 * because that use of AND conflicts with AND as a boolean operator. So,
7603 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
7605 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
7606 * always be used by surrounding it with parens.
7608 * c_expr is all the productions that are common to a_expr and b_expr;
7609 * it's factored out just to eliminate redundant coding.
7611 a_expr: c_expr { $$ = $1; }
7612 | a_expr TYPECAST Typename
7613 { $$ = makeTypeCast($1, $3, @2); }
7614 | a_expr AT TIME ZONE a_expr
7616 FuncCall *n = makeNode(FuncCall);
7617 n->funcname = SystemFuncName("timezone");
7618 n->args = list_make2($5, $1);
7619 n->agg_star = FALSE;
7620 n->agg_distinct = FALSE;
7621 n->func_variadic = FALSE;
7626 * These operators must be called out explicitly in order to make use
7627 * of yacc/bison's automatic operator-precedence handling. All other
7628 * operator names are handled by the generic productions using "Op",
7629 * below; and all those operators will have the same precedence.
7631 * If you add more explicitly-known operators, be sure to add them
7632 * also to b_expr and to the MathOp list above.
7634 | '+' a_expr %prec UMINUS
7635 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
7636 | '-' a_expr %prec UMINUS
7637 { $$ = doNegate($2, @1); }
7639 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
7641 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
7643 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
7645 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
7647 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
7649 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
7651 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
7653 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
7655 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
7657 | a_expr qual_Op a_expr %prec Op
7658 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
7659 | qual_Op a_expr %prec Op
7660 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
7661 | a_expr qual_Op %prec POSTFIXOP
7662 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
7665 { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
7667 { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
7669 { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
7671 | a_expr LIKE a_expr
7672 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
7673 | a_expr LIKE a_expr ESCAPE a_expr
7675 FuncCall *n = makeNode(FuncCall);
7676 n->funcname = SystemFuncName("like_escape");
7677 n->args = list_make2($3, $5);
7678 n->agg_star = FALSE;
7679 n->agg_distinct = FALSE;
7680 n->func_variadic = FALSE;
7682 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
7684 | a_expr NOT LIKE a_expr
7685 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
7686 | a_expr NOT LIKE a_expr ESCAPE a_expr
7688 FuncCall *n = makeNode(FuncCall);
7689 n->funcname = SystemFuncName("like_escape");
7690 n->args = list_make2($4, $6);
7691 n->agg_star = FALSE;
7692 n->agg_distinct = FALSE;
7693 n->func_variadic = FALSE;
7695 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
7697 | a_expr ILIKE a_expr
7698 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
7699 | a_expr ILIKE a_expr ESCAPE a_expr
7701 FuncCall *n = makeNode(FuncCall);
7702 n->funcname = SystemFuncName("like_escape");
7703 n->args = list_make2($3, $5);
7704 n->agg_star = FALSE;
7705 n->agg_distinct = FALSE;
7706 n->func_variadic = FALSE;
7708 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n, @2);
7710 | a_expr NOT ILIKE a_expr
7711 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
7712 | a_expr NOT ILIKE a_expr ESCAPE a_expr
7714 FuncCall *n = makeNode(FuncCall);
7715 n->funcname = SystemFuncName("like_escape");
7716 n->args = list_make2($4, $6);
7717 n->agg_star = FALSE;
7718 n->agg_distinct = FALSE;
7719 n->func_variadic = FALSE;
7721 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n, @2);
7724 | a_expr SIMILAR TO a_expr %prec SIMILAR
7726 FuncCall *n = makeNode(FuncCall);
7727 n->funcname = SystemFuncName("similar_escape");
7728 n->args = list_make2($4, makeNullAConst(-1));
7729 n->agg_star = FALSE;
7730 n->agg_distinct = FALSE;
7731 n->func_variadic = FALSE;
7733 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
7735 | a_expr SIMILAR TO a_expr ESCAPE a_expr
7737 FuncCall *n = makeNode(FuncCall);
7738 n->funcname = SystemFuncName("similar_escape");
7739 n->args = list_make2($4, $6);
7740 n->agg_star = FALSE;
7741 n->agg_distinct = FALSE;
7742 n->func_variadic = FALSE;
7744 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
7746 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
7748 FuncCall *n = makeNode(FuncCall);
7749 n->funcname = SystemFuncName("similar_escape");
7750 n->args = list_make2($5, makeNullAConst(-1));
7751 n->agg_star = FALSE;
7752 n->agg_distinct = FALSE;
7753 n->func_variadic = FALSE;
7755 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
7757 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
7759 FuncCall *n = makeNode(FuncCall);
7760 n->funcname = SystemFuncName("similar_escape");
7761 n->args = list_make2($5, $7);
7762 n->agg_star = FALSE;
7763 n->agg_distinct = FALSE;
7764 n->func_variadic = FALSE;
7766 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
7770 * Define SQL92-style Null test clause.
7771 * Allow two forms described in the standard:
7774 * Allow two SQL extensions
7780 NullTest *n = makeNode(NullTest);
7781 n->arg = (Expr *) $1;
7782 n->nulltesttype = IS_NULL;
7787 NullTest *n = makeNode(NullTest);
7788 n->arg = (Expr *) $1;
7789 n->nulltesttype = IS_NULL;
7792 | a_expr IS NOT NULL_P
7794 NullTest *n = makeNode(NullTest);
7795 n->arg = (Expr *) $1;
7796 n->nulltesttype = IS_NOT_NULL;
7801 NullTest *n = makeNode(NullTest);
7802 n->arg = (Expr *) $1;
7803 n->nulltesttype = IS_NOT_NULL;
7808 $$ = (Node *)makeOverlaps($1, $3, @2);
7812 BooleanTest *b = makeNode(BooleanTest);
7813 b->arg = (Expr *) $1;
7814 b->booltesttype = IS_TRUE;
7817 | a_expr IS NOT TRUE_P
7819 BooleanTest *b = makeNode(BooleanTest);
7820 b->arg = (Expr *) $1;
7821 b->booltesttype = IS_NOT_TRUE;
7826 BooleanTest *b = makeNode(BooleanTest);
7827 b->arg = (Expr *) $1;
7828 b->booltesttype = IS_FALSE;
7831 | a_expr IS NOT FALSE_P
7833 BooleanTest *b = makeNode(BooleanTest);
7834 b->arg = (Expr *) $1;
7835 b->booltesttype = IS_NOT_FALSE;
7840 BooleanTest *b = makeNode(BooleanTest);
7841 b->arg = (Expr *) $1;
7842 b->booltesttype = IS_UNKNOWN;
7845 | a_expr IS NOT UNKNOWN
7847 BooleanTest *b = makeNode(BooleanTest);
7848 b->arg = (Expr *) $1;
7849 b->booltesttype = IS_NOT_UNKNOWN;
7852 | a_expr IS DISTINCT FROM a_expr %prec IS
7854 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
7856 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
7858 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
7859 (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
7864 | a_expr IS OF '(' type_list ')' %prec IS
7866 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
7868 | a_expr IS NOT OF '(' type_list ')' %prec IS
7870 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
7872 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
7874 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
7875 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
7876 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
7879 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
7881 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
7882 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
7883 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
7886 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
7888 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
7889 (Node *) makeA_Expr(AEXPR_AND, NIL,
7890 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
7891 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
7893 (Node *) makeA_Expr(AEXPR_AND, NIL,
7894 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
7895 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
7899 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
7901 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
7902 (Node *) makeA_Expr(AEXPR_OR, NIL,
7903 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
7904 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
7906 (Node *) makeA_Expr(AEXPR_OR, NIL,
7907 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
7908 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
7912 | a_expr IN_P in_expr
7914 /* in_expr returns a SubLink or a list of a_exprs */
7915 if (IsA($3, SubLink))
7917 /* generate foo = ANY (subquery) */
7918 SubLink *n = (SubLink *) $3;
7919 n->subLinkType = ANY_SUBLINK;
7921 n->operName = list_make1(makeString("="));
7927 /* generate scalar IN expression */
7928 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
7931 | a_expr NOT IN_P in_expr
7933 /* in_expr returns a SubLink or a list of a_exprs */
7934 if (IsA($4, SubLink))
7936 /* generate NOT (foo = ANY (subquery)) */
7937 /* Make an = ANY node */
7938 SubLink *n = (SubLink *) $4;
7939 n->subLinkType = ANY_SUBLINK;
7941 n->operName = list_make1(makeString("="));
7943 /* Stick a NOT on top */
7944 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
7948 /* generate scalar NOT IN expression */
7949 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
7952 | a_expr subquery_Op sub_type select_with_parens %prec Op
7954 SubLink *n = makeNode(SubLink);
7955 n->subLinkType = $3;
7962 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
7964 if ($3 == ANY_SUBLINK)
7965 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
7967 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
7969 | UNIQUE select_with_parens
7971 /* Not sure how to get rid of the parentheses
7972 * but there are lots of shift/reduce errors without them.
7974 * Should be able to implement this by plopping the entire
7975 * select into a node, then transforming the target expressions
7976 * from whatever they are into count(*), and testing the
7977 * entire result equal to one.
7978 * But, will probably implement a separate node in the executor.
7981 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7982 errmsg("UNIQUE predicate is not yet implemented"),
7983 scanner_errposition(@1)));
7985 | a_expr IS DOCUMENT_P %prec IS
7987 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
7988 list_make1($1), @2);
7990 | a_expr IS NOT DOCUMENT_P %prec IS
7992 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
7993 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
7994 list_make1($1), @2),
8000 * Restricted expressions
8002 * b_expr is a subset of the complete expression syntax defined by a_expr.
8004 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
8005 * cause trouble in the places where b_expr is used. For simplicity, we
8006 * just eliminate all the boolean-keyword-operator productions from b_expr.
8010 | b_expr TYPECAST Typename
8011 { $$ = makeTypeCast($1, $3, @2); }
8012 | '+' b_expr %prec UMINUS
8013 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
8014 | '-' b_expr %prec UMINUS
8015 { $$ = doNegate($2, @1); }
8017 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
8019 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
8021 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
8023 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
8025 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
8027 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
8029 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
8031 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
8033 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
8034 | b_expr qual_Op b_expr %prec Op
8035 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
8036 | qual_Op b_expr %prec Op
8037 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
8038 | b_expr qual_Op %prec POSTFIXOP
8039 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
8040 | b_expr IS DISTINCT FROM b_expr %prec IS
8042 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
8044 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
8046 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
8047 NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
8049 | b_expr IS OF '(' type_list ')' %prec IS
8051 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
8053 | b_expr IS NOT OF '(' type_list ')' %prec IS
8055 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
8057 | b_expr IS DOCUMENT_P %prec IS
8059 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8060 list_make1($1), @2);
8062 | b_expr IS NOT DOCUMENT_P %prec IS
8064 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8065 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8066 list_make1($1), @2),
8072 * Productions that can be used in both a_expr and b_expr.
8074 * Note: productions that refer recursively to a_expr or b_expr mostly
8075 * cannot appear here. However, it's OK to refer to a_exprs that occur
8076 * inside parentheses, such as function arguments; that cannot introduce
8077 * ambiguity to the b_expr syntax.
8079 c_expr: columnref { $$ = $1; }
8080 | AexprConst { $$ = $1; }
8081 | PARAM opt_indirection
8083 ParamRef *p = makeNode(ParamRef);
8088 A_Indirection *n = makeNode(A_Indirection);
8089 n->arg = (Node *) p;
8090 n->indirection = check_indirection($2);
8096 | '(' a_expr ')' opt_indirection
8100 A_Indirection *n = makeNode(A_Indirection);
8102 n->indirection = check_indirection($4);
8112 | select_with_parens %prec UMINUS
8114 SubLink *n = makeNode(SubLink);
8115 n->subLinkType = EXPR_SUBLINK;
8122 | EXISTS select_with_parens
8124 SubLink *n = makeNode(SubLink);
8125 n->subLinkType = EXISTS_SUBLINK;
8132 | ARRAY select_with_parens
8134 SubLink *n = makeNode(SubLink);
8135 n->subLinkType = ARRAY_SUBLINK;
8144 A_ArrayExpr *n = (A_ArrayExpr *) $2;
8145 Assert(IsA(n, A_ArrayExpr));
8146 /* point outermost A_ArrayExpr to the ARRAY keyword */
8152 RowExpr *r = makeNode(RowExpr);
8154 r->row_typeid = InvalidOid; /* not analyzed yet */
8161 * func_expr is split out from c_expr just so that we have a classification
8162 * for "everything that is a function call or looks like one". This isn't
8163 * very important, but it saves us having to document which variants are
8164 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
8165 * (Note that many of the special SQL functions wouldn't actually make any
8166 * sense as functional index entries, but we ignore that consideration here.)
8168 func_expr: func_name '(' ')'
8170 FuncCall *n = makeNode(FuncCall);
8173 n->agg_star = FALSE;
8174 n->agg_distinct = FALSE;
8175 n->func_variadic = FALSE;
8179 | func_name '(' expr_list ')'
8181 FuncCall *n = makeNode(FuncCall);
8184 n->agg_star = FALSE;
8185 n->agg_distinct = FALSE;
8186 n->func_variadic = FALSE;
8190 | func_name '(' VARIADIC a_expr ')'
8192 FuncCall *n = makeNode(FuncCall);
8194 n->args = list_make1($4);
8195 n->agg_star = FALSE;
8196 n->agg_distinct = FALSE;
8197 n->func_variadic = TRUE;
8201 | func_name '(' expr_list ',' VARIADIC a_expr ')'
8203 FuncCall *n = makeNode(FuncCall);
8205 n->args = lappend($3, $6);
8206 n->agg_star = FALSE;
8207 n->agg_distinct = FALSE;
8208 n->func_variadic = TRUE;
8212 | func_name '(' ALL expr_list ')'
8214 FuncCall *n = makeNode(FuncCall);
8217 n->agg_star = FALSE;
8218 n->agg_distinct = FALSE;
8219 /* Ideally we'd mark the FuncCall node to indicate
8220 * "must be an aggregate", but there's no provision
8221 * for that in FuncCall at the moment.
8223 n->func_variadic = FALSE;
8227 | func_name '(' DISTINCT expr_list ')'
8229 FuncCall *n = makeNode(FuncCall);
8232 n->agg_star = FALSE;
8233 n->agg_distinct = TRUE;
8234 n->func_variadic = FALSE;
8238 | func_name '(' '*' ')'
8241 * We consider AGGREGATE(*) to invoke a parameterless
8242 * aggregate. This does the right thing for COUNT(*),
8243 * and there are no other aggregates in SQL92 that accept
8246 * The FuncCall node is also marked agg_star = true,
8247 * so that later processing can detect what the argument
8250 FuncCall *n = makeNode(FuncCall);
8254 n->agg_distinct = FALSE;
8255 n->func_variadic = FALSE;
8262 * Translate as "'now'::text::date".
8264 * We cannot use "'now'::date" because coerce_type() will
8265 * immediately reduce that to a constant representing
8266 * today's date. We need to delay the conversion until
8267 * runtime, else the wrong things will happen when
8268 * CURRENT_DATE is used in a column default value or rule.
8270 * This could be simplified if we had a way to generate
8271 * an expression tree representing runtime application
8272 * of type-input conversion functions. (As of PG 7.3
8273 * that is actually possible, but not clear that we want
8277 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8278 $$ = makeTypeCast(n, SystemTypeName("date"), -1);
8283 * Translate as "'now'::text::timetz".
8284 * See comments for CURRENT_DATE.
8287 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8288 $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
8290 | CURRENT_TIME '(' Iconst ')'
8293 * Translate as "'now'::text::timetz(n)".
8294 * See comments for CURRENT_DATE.
8298 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8299 d = SystemTypeName("timetz");
8300 d->typmods = list_make1(makeIntConst($3, @3));
8301 $$ = makeTypeCast(n, d, -1);
8306 * Translate as "now()", since we have a function that
8307 * does exactly what is needed.
8309 FuncCall *n = makeNode(FuncCall);
8310 n->funcname = SystemFuncName("now");
8312 n->agg_star = FALSE;
8313 n->agg_distinct = FALSE;
8314 n->func_variadic = FALSE;
8318 | CURRENT_TIMESTAMP '(' Iconst ')'
8321 * Translate as "'now'::text::timestamptz(n)".
8322 * See comments for CURRENT_DATE.
8326 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8327 d = SystemTypeName("timestamptz");
8328 d->typmods = list_make1(makeIntConst($3, @3));
8329 $$ = makeTypeCast(n, d, -1);
8334 * Translate as "'now'::text::time".
8335 * See comments for CURRENT_DATE.
8338 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8339 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
8341 | LOCALTIME '(' Iconst ')'
8344 * Translate as "'now'::text::time(n)".
8345 * See comments for CURRENT_DATE.
8349 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8350 d = SystemTypeName("time");
8351 d->typmods = list_make1(makeIntConst($3, @3));
8352 $$ = makeTypeCast((Node *)n, d, -1);
8357 * Translate as "'now'::text::timestamp".
8358 * See comments for CURRENT_DATE.
8361 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8362 $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
8364 | LOCALTIMESTAMP '(' Iconst ')'
8367 * Translate as "'now'::text::timestamp(n)".
8368 * See comments for CURRENT_DATE.
8372 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8373 d = SystemTypeName("timestamp");
8374 d->typmods = list_make1(makeIntConst($3, @3));
8375 $$ = makeTypeCast(n, d, -1);
8379 FuncCall *n = makeNode(FuncCall);
8380 n->funcname = SystemFuncName("current_user");
8382 n->agg_star = FALSE;
8383 n->agg_distinct = FALSE;
8384 n->func_variadic = FALSE;
8390 FuncCall *n = makeNode(FuncCall);
8391 n->funcname = SystemFuncName("current_user");
8393 n->agg_star = FALSE;
8394 n->agg_distinct = FALSE;
8395 n->func_variadic = FALSE;
8401 FuncCall *n = makeNode(FuncCall);
8402 n->funcname = SystemFuncName("session_user");
8404 n->agg_star = FALSE;
8405 n->agg_distinct = FALSE;
8406 n->func_variadic = FALSE;
8412 FuncCall *n = makeNode(FuncCall);
8413 n->funcname = SystemFuncName("current_user");
8415 n->agg_star = FALSE;
8416 n->agg_distinct = FALSE;
8417 n->func_variadic = FALSE;
8423 FuncCall *n = makeNode(FuncCall);
8424 n->funcname = SystemFuncName("current_database");
8426 n->agg_star = FALSE;
8427 n->agg_distinct = FALSE;
8428 n->func_variadic = FALSE;
8434 FuncCall *n = makeNode(FuncCall);
8435 n->funcname = SystemFuncName("current_schema");
8437 n->agg_star = FALSE;
8438 n->agg_distinct = FALSE;
8439 n->func_variadic = FALSE;
8443 | CAST '(' a_expr AS Typename ')'
8444 { $$ = makeTypeCast($3, $5, @1); }
8445 | EXTRACT '(' extract_list ')'
8447 FuncCall *n = makeNode(FuncCall);
8448 n->funcname = SystemFuncName("date_part");
8450 n->agg_star = FALSE;
8451 n->agg_distinct = FALSE;
8452 n->func_variadic = FALSE;
8456 | OVERLAY '(' overlay_list ')'
8458 /* overlay(A PLACING B FROM C FOR D) is converted to
8459 * substring(A, 1, C-1) || B || substring(A, C+1, C+D)
8460 * overlay(A PLACING B FROM C) is converted to
8461 * substring(A, 1, C-1) || B || substring(A, C+1, C+char_length(B))
8463 FuncCall *n = makeNode(FuncCall);
8464 n->funcname = SystemFuncName("overlay");
8466 n->agg_star = FALSE;
8467 n->agg_distinct = FALSE;
8468 n->func_variadic = FALSE;
8472 | POSITION '(' position_list ')'
8474 /* position(A in B) is converted to position(B, A) */
8475 FuncCall *n = makeNode(FuncCall);
8476 n->funcname = SystemFuncName("position");
8478 n->agg_star = FALSE;
8479 n->agg_distinct = FALSE;
8480 n->func_variadic = FALSE;
8484 | SUBSTRING '(' substr_list ')'
8486 /* substring(A from B for C) is converted to
8487 * substring(A, B, C) - thomas 2000-11-28
8489 FuncCall *n = makeNode(FuncCall);
8490 n->funcname = SystemFuncName("substring");
8492 n->agg_star = FALSE;
8493 n->agg_distinct = FALSE;
8494 n->func_variadic = FALSE;
8498 | TREAT '(' a_expr AS Typename ')'
8500 /* TREAT(expr AS target) converts expr of a particular type to target,
8501 * which is defined to be a subtype of the original expression.
8502 * In SQL99, this is intended for use with structured UDTs,
8503 * but let's make this a generally useful form allowing stronger
8504 * coercions than are handled by implicit casting.
8506 FuncCall *n = makeNode(FuncCall);
8507 /* Convert SystemTypeName() to SystemFuncName() even though
8508 * at the moment they result in the same thing.
8510 n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
8511 n->args = list_make1($3);
8512 n->agg_star = FALSE;
8513 n->agg_distinct = FALSE;
8514 n->func_variadic = FALSE;
8518 | TRIM '(' BOTH trim_list ')'
8520 /* various trim expressions are defined in SQL92
8521 * - thomas 1997-07-19
8523 FuncCall *n = makeNode(FuncCall);
8524 n->funcname = SystemFuncName("btrim");
8526 n->agg_star = FALSE;
8527 n->agg_distinct = FALSE;
8528 n->func_variadic = FALSE;
8532 | TRIM '(' LEADING trim_list ')'
8534 FuncCall *n = makeNode(FuncCall);
8535 n->funcname = SystemFuncName("ltrim");
8537 n->agg_star = FALSE;
8538 n->agg_distinct = FALSE;
8539 n->func_variadic = FALSE;
8543 | TRIM '(' TRAILING trim_list ')'
8545 FuncCall *n = makeNode(FuncCall);
8546 n->funcname = SystemFuncName("rtrim");
8548 n->agg_star = FALSE;
8549 n->agg_distinct = FALSE;
8550 n->func_variadic = FALSE;
8554 | TRIM '(' trim_list ')'
8556 FuncCall *n = makeNode(FuncCall);
8557 n->funcname = SystemFuncName("btrim");
8559 n->agg_star = FALSE;
8560 n->agg_distinct = FALSE;
8561 n->func_variadic = FALSE;
8565 | NULLIF '(' a_expr ',' a_expr ')'
8567 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
8569 | COALESCE '(' expr_list ')'
8571 CoalesceExpr *c = makeNode(CoalesceExpr);
8576 | GREATEST '(' expr_list ')'
8578 MinMaxExpr *v = makeNode(MinMaxExpr);
8580 v->op = IS_GREATEST;
8584 | LEAST '(' expr_list ')'
8586 MinMaxExpr *v = makeNode(MinMaxExpr);
8592 | XMLCONCAT '(' expr_list ')'
8594 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
8596 | XMLELEMENT '(' NAME_P ColLabel ')'
8598 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
8600 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
8602 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
8604 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
8606 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
8608 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
8610 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
8612 | XMLFOREST '(' xml_attribute_list ')'
8614 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
8616 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
8618 XmlExpr *x = (XmlExpr *)
8619 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
8620 list_make2($4, makeBoolAConst($5, -1)),
8625 | XMLPI '(' NAME_P ColLabel ')'
8627 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
8629 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
8631 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
8633 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
8635 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
8636 list_make3($3, $5, $6), @1);
8638 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
8640 XmlSerialize *n = makeNode(XmlSerialize);
8652 xml_root_version: VERSION_P a_expr
8654 | VERSION_P NO VALUE_P
8655 { $$ = makeNullAConst(-1); }
8658 opt_xml_root_standalone: ',' STANDALONE_P YES_P
8659 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
8660 | ',' STANDALONE_P NO
8661 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
8662 | ',' STANDALONE_P NO VALUE_P
8663 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
8665 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
8668 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
8671 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
8672 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
8675 xml_attribute_el: a_expr AS ColLabel
8677 $$ = makeNode(ResTarget);
8679 $$->indirection = NIL;
8680 $$->val = (Node *) $1;
8685 $$ = makeNode(ResTarget);
8687 $$->indirection = NIL;
8688 $$->val = (Node *) $1;
8693 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
8694 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
8697 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
8698 | STRIP_P WHITESPACE_P { $$ = FALSE; }
8699 | /*EMPTY*/ { $$ = FALSE; }
8703 * Supporting nonterminals for expressions.
8706 /* Explicit row production.
8708 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
8709 * without conflicting with the parenthesized a_expr production. Without the
8710 * ROW keyword, there must be more than one a_expr inside the parens.
8712 row: ROW '(' expr_list ')' { $$ = $3; }
8713 | ROW '(' ')' { $$ = NIL; }
8714 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
8717 sub_type: ANY { $$ = ANY_SUBLINK; }
8718 | SOME { $$ = ANY_SUBLINK; }
8719 | ALL { $$ = ALL_SUBLINK; }
8722 all_Op: Op { $$ = $1; }
8723 | MathOp { $$ = $1; }
8726 MathOp: '+' { $$ = "+"; }
8738 { $$ = list_make1(makeString($1)); }
8739 | OPERATOR '(' any_operator ')'
8745 { $$ = list_make1(makeString($1)); }
8746 | OPERATOR '(' any_operator ')'
8752 { $$ = list_make1(makeString($1)); }
8753 | OPERATOR '(' any_operator ')'
8756 { $$ = list_make1(makeString("~~")); }
8758 { $$ = list_make1(makeString("!~~")); }
8760 { $$ = list_make1(makeString("~~*")); }
8762 { $$ = list_make1(makeString("!~~*")); }
8763 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
8764 * the regular expression is preprocessed by a function (similar_escape),
8765 * and the ~ operator for posix regular expressions is used.
8766 * x SIMILAR TO y -> x ~ similar_escape(y)
8767 * this transformation is made on the fly by the parser upwards.
8768 * however the SubLink structure which handles any/some/all stuff
8769 * is not ready for such a thing.
8775 $$ = list_make1($1);
8777 | expr_list ',' a_expr
8779 $$ = lappend($1, $3);
8783 type_list: Typename { $$ = list_make1($1); }
8784 | type_list ',' Typename { $$ = lappend($1, $3); }
8787 array_expr: '[' expr_list ']'
8789 $$ = makeAArrayExpr($2, @1);
8791 | '[' array_expr_list ']'
8793 $$ = makeAArrayExpr($2, @1);
8797 $$ = makeAArrayExpr(NIL, @1);
8801 array_expr_list: array_expr { $$ = list_make1($1); }
8802 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
8807 extract_arg FROM a_expr
8809 $$ = list_make2(makeStringConst($1, @1), $3);
8811 | /*EMPTY*/ { $$ = NIL; }
8814 /* Allow delimited string SCONST in extract_arg as an SQL extension.
8815 * - thomas 2001-04-12
8819 | YEAR_P { $$ = "year"; }
8820 | MONTH_P { $$ = "month"; }
8821 | DAY_P { $$ = "day"; }
8822 | HOUR_P { $$ = "hour"; }
8823 | MINUTE_P { $$ = "minute"; }
8824 | SECOND_P { $$ = "second"; }
8825 | SCONST { $$ = $1; }
8828 /* OVERLAY() arguments
8829 * SQL99 defines the OVERLAY() function:
8830 * o overlay(text placing text from int for int)
8831 * o overlay(text placing text from int)
8834 a_expr overlay_placing substr_from substr_for
8836 $$ = list_make4($1, $2, $3, $4);
8838 | a_expr overlay_placing substr_from
8840 $$ = list_make3($1, $2, $3);
8849 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
8852 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
8853 | /*EMPTY*/ { $$ = NIL; }
8856 /* SUBSTRING() arguments
8857 * SQL9x defines a specific syntax for arguments to SUBSTRING():
8858 * o substring(text from int for int)
8859 * o substring(text from int) get entire string from starting point "int"
8860 * o substring(text for int) get first "int" characters of string
8861 * o substring(text from pattern) get entire string matching pattern
8862 * o substring(text from pattern for escape) same with specified escape char
8863 * We also want to support generic substring functions which accept
8864 * the usual generic list of arguments. So we will accept both styles
8865 * here, and convert the SQL9x style to the generic list for further
8866 * processing. - thomas 2000-11-28
8869 a_expr substr_from substr_for
8871 $$ = list_make3($1, $2, $3);
8873 | a_expr substr_for substr_from
8875 /* not legal per SQL99, but might as well allow it */
8876 $$ = list_make3($1, $3, $2);
8878 | a_expr substr_from
8880 $$ = list_make2($1, $2);
8885 * Since there are no cases where this syntax allows
8886 * a textual FOR value, we forcibly cast the argument
8887 * to int4. The possible matches in pg_proc are
8888 * substring(text,int4) and substring(text,text),
8889 * and we don't want the parser to choose the latter,
8890 * which it is likely to do if the second argument
8891 * is unknown or doesn't have an implicit cast to int4.
8893 $$ = list_make3($1, makeIntConst(1, -1),
8895 SystemTypeName("int4"), -1));
8906 FROM a_expr { $$ = $2; }
8909 substr_for: FOR a_expr { $$ = $2; }
8912 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
8913 | FROM expr_list { $$ = $2; }
8914 | expr_list { $$ = $1; }
8917 in_expr: select_with_parens
8919 SubLink *n = makeNode(SubLink);
8921 /* other fields will be filled later */
8924 | '(' expr_list ')' { $$ = (Node *)$2; }
8928 * Define SQL92-style case clause.
8929 * - Full specification
8930 * CASE WHEN a = b THEN c ... ELSE d END
8931 * - Implicit argument
8932 * CASE a WHEN b THEN c ... ELSE d END
8934 case_expr: CASE case_arg when_clause_list case_default END_P
8936 CaseExpr *c = makeNode(CaseExpr);
8937 c->casetype = InvalidOid; /* not analyzed yet */
8938 c->arg = (Expr *) $2;
8940 c->defresult = (Expr *) $4;
8947 /* There must be at least one */
8948 when_clause { $$ = list_make1($1); }
8949 | when_clause_list when_clause { $$ = lappend($1, $2); }
8953 WHEN a_expr THEN a_expr
8955 CaseWhen *w = makeNode(CaseWhen);
8956 w->expr = (Expr *) $2;
8957 w->result = (Expr *) $4;
8964 ELSE a_expr { $$ = $2; }
8965 | /*EMPTY*/ { $$ = NULL; }
8968 case_arg: a_expr { $$ = $1; }
8969 | /*EMPTY*/ { $$ = NULL; }
8973 * columnref starts with relation_name not ColId, so that OLD and NEW
8974 * references can be accepted. Note that when there are more than two
8975 * dotted names, the first name is not actually a relation name...
8977 columnref: relation_name
8979 $$ = makeColumnRef($1, NIL, @1);
8981 | relation_name indirection
8983 $$ = makeColumnRef($1, $2, @1);
8990 $$ = (Node *) makeString($2);
8994 $$ = (Node *) makeNode(A_Star);
8998 A_Indices *ai = makeNode(A_Indices);
9003 | '[' a_expr ':' a_expr ']'
9005 A_Indices *ai = makeNode(A_Indices);
9013 indirection_el { $$ = list_make1($1); }
9014 | indirection indirection_el { $$ = lappend($1, $2); }
9018 /*EMPTY*/ { $$ = NIL; }
9019 | opt_indirection indirection_el { $$ = lappend($1, $2); }
9022 opt_asymmetric: ASYMMETRIC
9027 * The SQL spec defines "contextually typed value expressions" and
9028 * "contextually typed row value constructors", which for our purposes
9029 * are the same as "a_expr" and "row" except that DEFAULT can appear at
9034 a_expr { $$ = (Node *) $1; }
9037 SetToDefault *n = makeNode(SetToDefault);
9044 ctext_expr { $$ = list_make1($1); }
9045 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
9049 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
9050 * making VALUES a fully reserved word, which will probably break more apps
9051 * than allowing the noise-word is worth.
9053 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
9057 /*****************************************************************************
9059 * target list for SELECT
9061 *****************************************************************************/
9064 target_el { $$ = list_make1($1); }
9065 | target_list ',' target_el { $$ = lappend($1, $3); }
9068 target_el: a_expr AS ColLabel
9070 $$ = makeNode(ResTarget);
9072 $$->indirection = NIL;
9073 $$->val = (Node *)$1;
9077 * We support omitting AS only for column labels that aren't
9078 * any known keyword. There is an ambiguity against postfix
9079 * operators: is "a ! b" an infix expression, or a postfix
9080 * expression and a column label? We prefer to resolve this
9081 * as an infix expression, which we accomplish by assigning
9082 * IDENT a precedence higher than POSTFIXOP.
9086 $$ = makeNode(ResTarget);
9088 $$->indirection = NIL;
9089 $$->val = (Node *)$1;
9094 $$ = makeNode(ResTarget);
9096 $$->indirection = NIL;
9097 $$->val = (Node *)$1;
9102 ColumnRef *n = makeNode(ColumnRef);
9103 n->fields = list_make1(makeNode(A_Star));
9106 $$ = makeNode(ResTarget);
9108 $$->indirection = NIL;
9109 $$->val = (Node *)n;
9115 /*****************************************************************************
9117 * Names and constants
9119 *****************************************************************************/
9122 SpecialRuleRelation { $$ = $1; }
9123 | ColId { $$ = $1; }
9126 qualified_name_list:
9127 qualified_name { $$ = list_make1($1); }
9128 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
9132 * The production for a qualified relation name has to exactly match the
9133 * production for a qualified func_name, because in a FROM clause we cannot
9134 * tell which we are parsing until we see what comes after it ('(' for a
9135 * func_name, something else for a relation). Therefore we allow 'indirection'
9136 * which may contain subscripts, and reject that case in the C code.
9141 $$ = makeNode(RangeVar);
9142 $$->catalogname = NULL;
9143 $$->schemaname = NULL;
9147 | relation_name indirection
9149 check_qualified_name($2);
9150 $$ = makeNode(RangeVar);
9151 switch (list_length($2))
9154 $$->catalogname = NULL;
9155 $$->schemaname = $1;
9156 $$->relname = strVal(linitial($2));
9159 $$->catalogname = $1;
9160 $$->schemaname = strVal(linitial($2));
9161 $$->relname = strVal(lsecond($2));
9165 (errcode(ERRCODE_SYNTAX_ERROR),
9166 errmsg("improper qualified name (too many dotted names): %s",
9167 NameListToString(lcons(makeString($1), $2))),
9168 scanner_errposition(@1)));
9176 { $$ = list_make1(makeString($1)); }
9177 | name_list ',' name
9178 { $$ = lappend($1, makeString($3)); }
9182 name: ColId { $$ = $1; };
9190 attr_name: ColLabel { $$ = $1; };
9192 index_name: ColId { $$ = $1; };
9194 file_name: Sconst { $$ = $1; };
9197 * The production for a qualified func_name has to exactly match the
9198 * production for a qualified columnref, because we cannot tell which we
9199 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
9200 * anything else for a columnref). Therefore we allow 'indirection' which
9201 * may contain subscripts, and reject that case in the C code. (If we
9202 * ever implement SQL99-like methods, such syntax may actually become legal!)
9204 func_name: type_function_name
9205 { $$ = list_make1(makeString($1)); }
9206 | relation_name indirection
9207 { $$ = check_func_name(lcons(makeString($1), $2)); }
9216 $$ = makeIntConst($1, @1);
9220 $$ = makeFloatConst($1, @1);
9224 $$ = makeStringConst($1, @1);
9228 $$ = makeBitStringConst($1, @1);
9232 /* This is a bit constant per SQL99:
9233 * Without Feature F511, "BIT data type",
9234 * a <general literal> shall not be a
9235 * <bit string literal> or a <hex string literal>.
9237 $$ = makeBitStringConst($1, @1);
9241 /* generic type 'literal' syntax */
9242 TypeName *t = makeTypeNameFromNameList($1);
9244 $$ = makeStringConstCast($2, @2, t);
9246 | func_name '(' expr_list ')' Sconst
9248 /* generic syntax with a type modifier */
9249 TypeName *t = makeTypeNameFromNameList($1);
9252 $$ = makeStringConstCast($5, @5, t);
9254 | ConstTypename Sconst
9256 $$ = makeStringConstCast($2, @2, $1);
9258 | ConstInterval Sconst opt_interval
9262 $$ = makeStringConstCast($2, @2, t);
9264 | ConstInterval '(' Iconst ')' Sconst opt_interval
9269 if (list_length($6) != 1)
9271 (errcode(ERRCODE_SYNTAX_ERROR),
9272 errmsg("interval precision specified twice"),
9273 scanner_errposition(@1)));
9274 t->typmods = lappend($6, makeIntConst($3, @3));
9277 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
9278 makeIntConst($3, @3));
9279 $$ = makeStringConstCast($5, @5, t);
9283 $$ = makeBoolAConst(TRUE, @1);
9287 $$ = makeBoolAConst(FALSE, @1);
9291 $$ = makeNullAConst(@1);
9295 Iconst: ICONST { $$ = $1; };
9296 Sconst: SCONST { $$ = $1; };
9297 RoleId: ColId { $$ = $1; };
9299 SignedIconst: ICONST { $$ = $1; }
9300 | '+' ICONST { $$ = + $2; }
9301 | '-' ICONST { $$ = - $2; }
9305 * Name classification hierarchy.
9307 * IDENT is the lexeme returned by the lexer for identifiers that match
9308 * no known keyword. In most cases, we can accept certain keywords as
9309 * names, not only IDENTs. We prefer to accept as many such keywords
9310 * as possible to minimize the impact of "reserved words" on programmers.
9311 * So, we divide names into several possible classes. The classification
9312 * is chosen in part to make keywords acceptable as names wherever possible.
9315 /* Column identifier --- names that can be column, table, etc names.
9317 ColId: IDENT { $$ = $1; }
9318 | unreserved_keyword { $$ = pstrdup($1); }
9319 | col_name_keyword { $$ = pstrdup($1); }
9322 /* Type/function identifier --- names that can be type or function names.
9324 type_function_name: IDENT { $$ = $1; }
9325 | unreserved_keyword { $$ = pstrdup($1); }
9326 | type_func_name_keyword { $$ = pstrdup($1); }
9329 /* Column label --- allowed labels in "AS" clauses.
9330 * This presently includes *all* Postgres keywords.
9332 ColLabel: IDENT { $$ = $1; }
9333 | unreserved_keyword { $$ = pstrdup($1); }
9334 | col_name_keyword { $$ = pstrdup($1); }
9335 | type_func_name_keyword { $$ = pstrdup($1); }
9336 | reserved_keyword { $$ = pstrdup($1); }
9341 * Keyword category lists. Generally, every keyword present in
9342 * the Postgres grammar should appear in exactly one of these lists.
9344 * Put a new keyword into the first list that it can go into without causing
9345 * shift or reduce conflicts. The earlier lists define "less reserved"
9346 * categories of keywords.
9348 * Make sure that each keyword's category in keywords.c matches where
9349 * it is listed here. (Someday we may be able to generate these lists and
9350 * keywords.c's table from a common master list.)
9353 /* "Unreserved" keywords --- available for use as any kind of name.
9595 /* Column identifier --- keywords that can be column, table, etc names.
9597 * Many of these keywords will in fact be recognized as type or function
9598 * names too; but they have special productions for the purpose, and so
9599 * can't be treated as "generic" type or function names.
9601 * The type names appearing here are not usable as function names
9602 * because they can be followed by '(' in typename productions, which
9603 * looks too much like a function call for an LR(1) parser.
9653 /* Type/function identifier --- keywords that can be type or function names.
9655 * Most of these are keywords that are used as operators in expressions;
9656 * in general such keywords can't be column names because they would be
9657 * ambiguous with variables, but they are unambiguous as function identifiers.
9659 * Do not include POSITION, SUBSTRING, etc here since they have explicit
9660 * productions in a_expr to support the goofy SQL9x argument syntax.
9661 * - thomas 2000-11-28
9663 type_func_name_keyword:
9687 /* Reserved keyword --- these keywords are usable only as a ColLabel.
9689 * Keywords appear here if they could not be distinguished from variable,
9690 * type, or function names in some contexts. Don't put things here unless
9775 SpecialRuleRelation:
9782 (errcode(ERRCODE_SYNTAX_ERROR),
9783 errmsg("OLD used in query that is not in a rule"),
9784 scanner_errposition(@1)));
9792 (errcode(ERRCODE_SYNTAX_ERROR),
9793 errmsg("NEW used in query that is not in a rule"),
9794 scanner_errposition(@1)));
9801 makeColumnRef(char *colname, List *indirection, int location)
9804 * Generate a ColumnRef node, with an A_Indirection node added if there
9805 * is any subscripting in the specified indirection list. However,
9806 * any field selection at the start of the indirection list must be
9807 * transposed into the "fields" part of the ColumnRef node.
9809 ColumnRef *c = makeNode(ColumnRef);
9813 c->location = location;
9814 foreach(l, indirection)
9816 if (IsA(lfirst(l), A_Indices))
9818 A_Indirection *i = makeNode(A_Indirection);
9822 /* easy case - all indirection goes to A_Indirection */
9823 c->fields = list_make1(makeString(colname));
9824 i->indirection = check_indirection(indirection);
9828 /* got to split the list in two */
9829 i->indirection = check_indirection(list_copy_tail(indirection,
9831 indirection = list_truncate(indirection, nfields);
9832 c->fields = lcons(makeString(colname), indirection);
9834 i->arg = (Node *) c;
9837 else if (IsA(lfirst(l), A_Star))
9839 /* We only allow '*' at the end of a ColumnRef */
9840 if (lnext(l) != NULL)
9841 yyerror("improper use of \"*\"");
9845 /* No subscripting, so all indirection gets added to field list */
9846 c->fields = lcons(makeString(colname), indirection);
9851 makeTypeCast(Node *arg, TypeName *typename, int location)
9853 TypeCast *n = makeNode(TypeCast);
9855 n->typename = typename;
9856 n->location = location;
9861 makeStringConst(char *str, int location)
9863 A_Const *n = makeNode(A_Const);
9865 n->val.type = T_String;
9866 n->val.val.str = str;
9867 n->location = location;
9873 makeStringConstCast(char *str, int location, TypeName *typename)
9875 Node *s = makeStringConst(str, location);
9877 return makeTypeCast(s, typename, -1);
9881 makeIntConst(int val, int location)
9883 A_Const *n = makeNode(A_Const);
9885 n->val.type = T_Integer;
9886 n->val.val.ival = val;
9887 n->location = location;
9893 makeFloatConst(char *str, int location)
9895 A_Const *n = makeNode(A_Const);
9897 n->val.type = T_Float;
9898 n->val.val.str = str;
9899 n->location = location;
9905 makeBitStringConst(char *str, int location)
9907 A_Const *n = makeNode(A_Const);
9909 n->val.type = T_BitString;
9910 n->val.val.str = str;
9911 n->location = location;
9917 makeNullAConst(int location)
9919 A_Const *n = makeNode(A_Const);
9921 n->val.type = T_Null;
9922 n->location = location;
9928 makeAConst(Value *v, int location)
9935 n = makeFloatConst(v->val.str, location);
9939 n = makeIntConst(v->val.ival, location);
9944 n = makeStringConst(v->val.str, location);
9952 * Create an A_Const string node and put it inside a boolean cast.
9955 makeBoolAConst(bool state, int location)
9957 A_Const *n = makeNode(A_Const);
9959 n->val.type = T_String;
9960 n->val.val.str = (state ? "t" : "f");
9961 n->location = location;
9963 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
9967 * Create and populate a FuncCall node to support the OVERLAPS operator.
9970 makeOverlaps(List *largs, List *rargs, int location)
9972 FuncCall *n = makeNode(FuncCall);
9974 n->funcname = SystemFuncName("overlaps");
9975 if (list_length(largs) == 1)
9976 largs = lappend(largs, largs);
9977 else if (list_length(largs) != 2)
9979 (errcode(ERRCODE_SYNTAX_ERROR),
9980 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
9981 scanner_errposition(location)));
9982 if (list_length(rargs) == 1)
9983 rargs = lappend(rargs, rargs);
9984 else if (list_length(rargs) != 2)
9986 (errcode(ERRCODE_SYNTAX_ERROR),
9987 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
9988 scanner_errposition(location)));
9989 n->args = list_concat(largs, rargs);
9990 n->agg_star = FALSE;
9991 n->agg_distinct = FALSE;
9992 n->func_variadic = FALSE;
9993 n->location = location;
9997 /* check_qualified_name --- check the result of qualified_name production
9999 * It's easiest to let the grammar production for qualified_name allow
10000 * subscripts and '*', which we then must reject here.
10003 check_qualified_name(List *names)
10009 if (!IsA(lfirst(i), String))
10010 yyerror("syntax error");
10014 /* check_func_name --- check the result of func_name production
10016 * It's easiest to let the grammar production for func_name allow subscripts
10017 * and '*', which we then must reject here.
10020 check_func_name(List *names)
10026 if (!IsA(lfirst(i), String))
10027 yyerror("syntax error");
10032 /* check_indirection --- check the result of indirection production
10034 * We only allow '*' at the end of the list, but it's hard to enforce that
10035 * in the grammar, so do it here.
10038 check_indirection(List *indirection)
10042 foreach(l, indirection)
10044 if (IsA(lfirst(l), A_Star))
10046 if (lnext(l) != NULL)
10047 yyerror("improper use of \"*\"");
10050 return indirection;
10053 /* extractArgTypes()
10054 * Given a list of FunctionParameter nodes, extract a list of just the
10055 * argument types (TypeNames) for input parameters only. This is what
10056 * is needed to look up an existing function, which is what is wanted by
10057 * the productions that use this call.
10060 extractArgTypes(List *parameters)
10062 List *result = NIL;
10065 foreach(i, parameters)
10067 FunctionParameter *p = (FunctionParameter *) lfirst(i);
10069 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
10070 result = lappend(result, p->argType);
10075 /* findLeftmostSelect()
10076 * Find the leftmost component SelectStmt in a set-operation parsetree.
10078 static SelectStmt *
10079 findLeftmostSelect(SelectStmt *node)
10081 while (node && node->op != SETOP_NONE)
10083 Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
10087 /* insertSelectOptions()
10088 * Insert ORDER BY, etc into an already-constructed SelectStmt.
10090 * This routine is just to avoid duplicating code in SelectStmt productions.
10093 insertSelectOptions(SelectStmt *stmt,
10094 List *sortClause, List *lockingClause,
10095 Node *limitOffset, Node *limitCount,
10096 WithClause *withClause)
10098 Assert(IsA(stmt, SelectStmt));
10101 * Tests here are to reject constructs like
10102 * (SELECT foo ORDER BY bar) ORDER BY baz
10106 if (stmt->sortClause)
10108 (errcode(ERRCODE_SYNTAX_ERROR),
10109 errmsg("multiple ORDER BY clauses not allowed"),
10110 scanner_errposition(exprLocation((Node *) sortClause))));
10111 stmt->sortClause = sortClause;
10113 /* We can handle multiple locking clauses, though */
10114 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
10117 if (stmt->limitOffset)
10119 (errcode(ERRCODE_SYNTAX_ERROR),
10120 errmsg("multiple OFFSET clauses not allowed"),
10121 scanner_errposition(exprLocation(limitOffset))));
10122 stmt->limitOffset = limitOffset;
10126 if (stmt->limitCount)
10128 (errcode(ERRCODE_SYNTAX_ERROR),
10129 errmsg("multiple LIMIT clauses not allowed"),
10130 scanner_errposition(exprLocation(limitCount))));
10131 stmt->limitCount = limitCount;
10135 if (stmt->withClause)
10137 (errcode(ERRCODE_SYNTAX_ERROR),
10138 errmsg("multiple WITH clauses not allowed"),
10139 scanner_errposition(exprLocation((Node *) withClause))));
10140 stmt->withClause = withClause;
10145 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
10147 SelectStmt *n = makeNode(SelectStmt);
10151 n->larg = (SelectStmt *) larg;
10152 n->rarg = (SelectStmt *) rarg;
10156 /* SystemFuncName()
10157 * Build a properly-qualified reference to a built-in function.
10160 SystemFuncName(char *name)
10162 return list_make2(makeString("pg_catalog"), makeString(name));
10165 /* SystemTypeName()
10166 * Build a properly-qualified reference to a built-in type.
10168 * typmod is defaulted, but may be changed afterwards by caller.
10169 * Likewise for the location.
10172 SystemTypeName(char *name)
10174 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
10175 makeString(name)));
10179 * Handle negation of a numeric constant.
10181 * Formerly, we did this here because the optimizer couldn't cope with
10182 * indexquals that looked like "var = -4" --- it wants "var = const"
10183 * and a unary minus operator applied to a constant didn't qualify.
10184 * As of Postgres 7.0, that problem doesn't exist anymore because there
10185 * is a constant-subexpression simplifier in the optimizer. However,
10186 * there's still a good reason for doing this here, which is that we can
10187 * postpone committing to a particular internal representation for simple
10188 * negative constants. It's better to leave "-123.456" in string form
10189 * until we know what the desired type is.
10192 doNegate(Node *n, int location)
10194 if (IsA(n, A_Const))
10196 A_Const *con = (A_Const *)n;
10198 /* report the constant's location as that of the '-' sign */
10199 con->location = location;
10201 if (con->val.type == T_Integer)
10203 con->val.val.ival = -con->val.val.ival;
10206 if (con->val.type == T_Float)
10208 doNegateFloat(&con->val);
10213 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
10217 doNegateFloat(Value *v)
10219 char *oldval = v->val.str;
10221 Assert(IsA(v, Float));
10222 if (*oldval == '+')
10224 if (*oldval == '-')
10225 v->val.str = oldval+1; /* just strip the '-' */
10228 char *newval = (char *) palloc(strlen(oldval) + 2);
10231 strcpy(newval+1, oldval);
10232 v->val.str = newval;
10237 makeAArrayExpr(List *elements, int location)
10239 A_ArrayExpr *n = makeNode(A_ArrayExpr);
10241 n->elements = elements;
10242 n->location = location;
10247 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
10250 XmlExpr *x = makeNode(XmlExpr);
10255 * named_args is a list of ResTarget; it'll be split apart into separate
10256 * expression and name lists in transformXmlExpr().
10258 x->named_args = named_args;
10259 x->arg_names = NIL;
10261 /* xmloption, if relevant, must be filled in by caller */
10262 /* type and typmod will be filled in during parse analysis */
10263 x->location = location;
10268 * Initialize to parse one query string
10273 QueryIsRule = FALSE;
10277 * Merge the input and output parameters of a table function.
10280 mergeTableFuncParameters(List *func_args, List *columns)
10284 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
10285 foreach(lc, func_args)
10287 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
10289 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
10291 (errcode(ERRCODE_SYNTAX_ERROR),
10292 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
10295 return list_concat(func_args, columns);
10299 * Determine return type of a TABLE function. A single result column
10300 * returns setof that column's type; otherwise return setof record.
10303 TableFuncTypeName(List *columns)
10307 if (list_length(columns) == 1)
10309 FunctionParameter *p = (FunctionParameter *) linitial(columns);
10311 result = (TypeName *) copyObject(p->argType);
10314 result = SystemTypeName("record");
10316 result->setof = true;
10322 * Must undefine base_yylex before including scan.c, since we want it
10323 * to create the function base_yylex not filtered_base_yylex.