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.637 2008/11/13 11:10:06 meskes Exp $
17 * AUTHOR DATE MAJOR EVENT
18 * Andrew Yu Sept, 1994 POSTQUEL to SQL conversion
19 * Andrew Yu Oct, 1994 lispy code conversion
22 * CAPITALS are used to represent terminal symbols.
23 * non-capitals are used to represent non-terminals.
24 * SQL92-specific syntax is separated from plain SQL/Postgres syntax
25 * to help isolate the non-extensible portions of the parser.
27 * In general, nothing in this file should initiate database accesses
28 * nor depend on changeable state (such as SET variables). If you do
29 * database accesses, your code will fail when we have aborted the
30 * current transaction and are just parsing commands to find the next
31 * ROLLBACK or COMMIT. If you make use of SET variables, then you
32 * will do the wrong thing in multi-query strings like this:
33 * SET SQL_inheritance TO off; SELECT * FROM foo;
34 * because the entire string is parsed by gram.y before the SET gets
35 * executed. Anything that depends on the database or changeable state
36 * should be handled during parse analysis so that it happens at the
37 * right time not the wrong time. The handling of SQL_inheritance is
41 * If you use a list, make sure the datum is a node so that the printing
44 * Sometimes we assign constants to makeStrings. Make sure we don't free
47 *-------------------------------------------------------------------------
54 #include "catalog/index.h"
55 #include "catalog/namespace.h"
56 #include "commands/defrem.h"
57 #include "nodes/makefuncs.h"
58 #include "nodes/nodeFuncs.h"
59 #include "parser/gramparse.h"
60 #include "storage/lmgr.h"
61 #include "utils/date.h"
62 #include "utils/datetime.h"
63 #include "utils/numeric.h"
64 #include "utils/xml.h"
67 /* Location tracking support --- simpler than bison's default */
68 #define YYLLOC_DEFAULT(Current, Rhs, N) \
71 (Current) = (Rhs)[1]; \
73 (Current) = (Rhs)[0]; \
77 * The %name-prefix option below will make bison call base_yylex, but we
78 * really want it to call filtered_base_yylex (see parser.c).
80 #define base_yylex filtered_base_yylex
83 * Bison doesn't allocate anything that needs to live across parser calls,
84 * so we can easily have it use palloc instead of malloc. This prevents
85 * memory leaks if we error out during parsing. Note this only works with
86 * bison >= 2.0. However, in bison 1.875 the default is to use alloca()
87 * if possible, so there's not really much problem anyhow, at least if
88 * you're building with gcc.
90 #define YYMALLOC palloc
93 extern List *parsetree; /* final parse result is delivered here */
95 static bool QueryIsRule = FALSE;
98 * If you need access to certain yacc-generated variables and find that
99 * they're static by default, uncomment the next line. (this is not a
102 /*#define __YYSCLASS*/
104 static Node *makeColumnRef(char *colname, List *indirection, int location);
105 static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
106 static Node *makeStringConst(char *str, int location);
107 static Node *makeStringConstCast(char *str, int location, TypeName *typename);
108 static Node *makeIntConst(int val, int location);
109 static Node *makeFloatConst(char *str, int location);
110 static Node *makeBitStringConst(char *str, int location);
111 static Node *makeNullAConst(int location);
112 static Node *makeAConst(Value *v, int location);
113 static Node *makeBoolAConst(bool state, int location);
114 static FuncCall *makeOverlaps(List *largs, List *rargs, int location);
115 static void check_qualified_name(List *names);
116 static List *check_func_name(List *names);
117 static List *check_indirection(List *indirection);
118 static List *extractArgTypes(List *parameters);
119 static SelectStmt *findLeftmostSelect(SelectStmt *node);
120 static void insertSelectOptions(SelectStmt *stmt,
121 List *sortClause, List *lockingClause,
122 Node *limitOffset, Node *limitCount,
123 WithClause *withClause);
124 static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
125 static Node *doNegate(Node *n, int location);
126 static void doNegateFloat(Value *v);
127 static Node *makeAArrayExpr(List *elements, int location);
128 static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
129 List *args, int location);
130 static List *mergeTableFuncParameters(List *func_args, List *columns);
131 static TypeName *TableFuncTypeName(List *columns);
135 %name-prefix="base_yy"
146 DropBehavior dbehavior;
147 OnCommitAction oncommit;
154 FunctionParameter *fun_param;
155 FunctionParameterMode fun_param_mode;
156 FuncWithArgs *funwithargs;
167 PrivTarget *privtarget;
170 VariableSetStmt *vsetstmt;
173 %type <node> stmt schema_stmt
174 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterGroupStmt
175 AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterTableStmt
176 AlterUserStmt AlterUserSetStmt AlterRoleStmt AlterRoleSetStmt
177 AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
178 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
179 CreateDomainStmt CreateGroupStmt CreateOpClassStmt
180 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
181 CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
182 CreateAssertStmt CreateTrigStmt CreateUserStmt CreateRoleStmt
183 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt
184 DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
185 DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
186 DropUserStmt DropdbStmt DropTableSpaceStmt ExplainStmt FetchStmt
187 GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
188 LockStmt NotifyStmt ExplainableStmt PreparableStmt
189 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
190 RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
191 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
192 SelectStmt TransactionStmt TruncateStmt
193 UnlistenStmt UpdateStmt VacuumStmt
194 VariableResetStmt VariableSetStmt VariableShowStmt
195 ViewStmt CheckPointStmt CreateConversionStmt
196 DeallocateStmt PrepareStmt ExecuteStmt
197 DropOwnedStmt ReassignOwnedStmt
198 AlterTSConfigurationStmt AlterTSDictionaryStmt
200 %type <node> select_no_parens select_with_parens select_clause
201 simple_select values_clause
203 %type <node> alter_column_default opclass_item opclass_drop alter_using
204 %type <ival> add_drop opt_asc_desc opt_nulls_order
206 %type <node> alter_table_cmd
207 %type <list> alter_table_cmds
209 %type <dbehavior> opt_drop_behavior
211 %type <list> createdb_opt_list alterdb_opt_list copy_opt_list
212 transaction_mode_list
213 %type <defelt> createdb_opt_item alterdb_opt_item copy_opt_item
214 transaction_mode_item
216 %type <ival> opt_lock lock_type cast_context
217 %type <boolean> opt_force opt_or_replace
218 opt_grant_grant_option opt_grant_admin_option
219 opt_nowait opt_if_exists opt_with_data
221 %type <list> OptRoleList
222 %type <defelt> OptRoleElem
224 %type <str> OptSchemaName
225 %type <list> OptSchemaEltList
227 %type <boolean> TriggerActionTime TriggerForSpec opt_trusted opt_restart_seqs
228 %type <str> opt_lancompiler
230 %type <str> TriggerEvents
231 %type <value> TriggerFuncArg
233 %type <str> relation_name copy_file_name
234 database_name access_method_clause access_method attr_name
235 index_name name file_name cluster_index_specification
237 %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
238 opt_class opt_validator
240 %type <range> qualified_name OptConstrFromTable
242 %type <str> all_Op MathOp SpecialRuleRelation
244 %type <str> iso_level opt_encoding
246 %type <list> grantee_list
247 %type <str> privilege
248 %type <list> privileges privilege_list
249 %type <privtarget> privilege_target
250 %type <funwithargs> function_with_argtypes
251 %type <list> function_with_argtypes_list
252 %type <chr> TriggerOneEvent
254 %type <list> stmtblock stmtmulti
255 OptTableElementList TableElementList OptInherit definition
256 OptWith opt_distinct opt_definition func_args func_args_list
257 func_as createfunc_opt_list alterfunc_opt_list
258 aggr_args old_aggr_definition old_aggr_list
259 oper_argtypes RuleActionList RuleActionMulti
260 opt_column_list columnList opt_name_list
261 sort_clause opt_sort_clause sortby_list index_params
262 name_list from_clause from_list opt_array_bounds
263 qualified_name_list any_name any_name_list
264 any_operator expr_list attrs
265 target_list insert_column_list set_target_list
266 set_clause_list set_clause multiple_set_clause
267 ctext_expr_list ctext_row def_list indirection opt_indirection
268 group_clause TriggerFuncArgs select_limit
269 opt_select_limit opclass_item_list opclass_drop_list
270 opt_opfamily transaction_mode_list_or_empty
271 TableFuncElementList opt_type_modifiers
273 execute_param_clause using_clause returning_clause
274 enum_val_list table_func_column_list
276 %type <range> OptTempTableName
277 %type <into> into_clause create_as_target
279 %type <defelt> createfunc_opt_item common_func_opt_item
280 %type <fun_param> func_arg table_func_column
281 %type <fun_param_mode> arg_class
282 %type <typnam> func_return func_type
284 %type <boolean> TriggerForType OptTemp
285 %type <oncommit> OnCommitOption
287 %type <node> for_locking_item
288 %type <list> for_locking_clause opt_for_locking_clause for_locking_items
289 %type <list> locked_rels_list
290 %type <boolean> opt_all
292 %type <node> join_outer join_qual
293 %type <jtype> join_type
295 %type <list> extract_list overlay_list position_list
296 %type <list> substr_list trim_list
297 %type <list> opt_interval interval_second
298 %type <node> overlay_placing substr_from substr_for
300 %type <boolean> opt_instead opt_analyze
301 %type <boolean> index_opt_unique opt_verbose opt_full
302 %type <boolean> opt_freeze opt_default opt_recheck
303 %type <defelt> opt_binary opt_oids copy_delimiter
305 %type <boolean> copy_from
307 %type <ival> opt_column event cursor_options opt_hold opt_set_data
308 %type <objtype> reindex_type drop_type comment_type
310 %type <node> fetch_direction select_limit_value select_offset_value
311 select_offset_value2 opt_select_fetch_first_value
312 %type <ival> row_or_rows first_or_next
314 %type <list> OptSeqOptList SeqOptList
315 %type <defelt> SeqOptElem
317 %type <istmt> insert_rest
319 %type <vsetstmt> set_rest SetResetClause
321 %type <node> TableElement ConstraintElem TableFuncElement
322 %type <node> columnDef
323 %type <defelt> def_elem old_aggr_elem
324 %type <node> def_arg columnElem where_clause where_or_current_clause
325 a_expr b_expr c_expr func_expr AexprConst indirection_el
326 columnref in_expr having_clause func_table array_expr
327 %type <list> row type_list array_expr_list
328 %type <node> case_expr case_arg when_clause case_default
329 %type <list> when_clause_list
330 %type <ival> sub_type
331 %type <list> OptCreateAs CreateAsList
332 %type <node> CreateAsElement ctext_expr
333 %type <value> NumericOnly
334 %type <alias> alias_clause
335 %type <sortby> sortby
336 %type <ielem> index_elem
337 %type <node> table_ref
338 %type <jexpr> joined_table
339 %type <range> relation_expr
340 %type <range> relation_expr_opt_alias
341 %type <target> target_el single_set_clause set_target insert_column_item
343 %type <typnam> Typename SimpleTypename ConstTypename
344 GenericType Numeric opt_float
345 Character ConstCharacter
346 CharacterWithLength CharacterWithoutLength
347 ConstDatetime ConstInterval
348 Bit ConstBit BitWithLength BitWithoutLength
349 %type <str> character
350 %type <str> extract_arg
351 %type <str> opt_charset
352 %type <boolean> opt_varying opt_timezone
354 %type <ival> Iconst SignedIconst
355 %type <str> Sconst comment_text
356 %type <str> RoleId opt_granted_by opt_boolean ColId_or_Sconst
357 %type <list> var_list
358 %type <str> ColId ColLabel var_name type_function_name param_name
359 %type <node> var_value zone_value
361 %type <keyword> unreserved_keyword type_func_name_keyword
362 %type <keyword> col_name_keyword reserved_keyword
364 %type <node> TableConstraint TableLikeClause
365 %type <list> TableLikeOptionList
366 %type <ival> TableLikeOption
367 %type <list> ColQualList
368 %type <node> ColConstraint ColConstraintElem ConstraintAttr
369 %type <ival> key_actions key_delete key_match key_update key_action
370 %type <ival> ConstraintAttributeSpec ConstraintDeferrabilitySpec
373 %type <list> constraints_set_list
374 %type <boolean> constraints_set_mode
375 %type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
376 %type <list> opt_check_option
378 %type <target> xml_attribute_el
379 %type <list> xml_attribute_list xml_attributes
380 %type <node> xml_root_version opt_xml_root_standalone
381 %type <ival> document_or_content
382 %type <boolean> xml_whitespace_option
384 %type <node> common_table_expr
385 %type <with> with_clause
386 %type <list> cte_list
390 * If you make any token changes, update the keyword table in
391 * parser/keywords.c and add new keywords to the appropriate one of
392 * the reserved-or-not-so-reserved keyword lists, below; search
393 * this file for "Name classification hierarchy".
396 /* ordinary key words in alphabetical order */
397 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
398 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
399 ASSERTION ASSIGNMENT ASYMMETRIC AT AUTHORIZATION
401 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
404 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
405 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
406 CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT
407 COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
408 CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
409 CREATEROLE CREATEUSER CROSS CSV CTYPE CURRENT_P
410 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
411 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
413 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
414 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
415 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
417 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT EXCLUDING
418 EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
420 FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOR FORCE FOREIGN FORWARD
421 FREEZE FROM FULL FUNCTION
423 GLOBAL GRANT GRANTED GREATEST GROUP_P
425 HANDLER HAVING HEADER_P HOLD HOUR_P
427 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
428 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY
429 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
430 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
436 LANCOMPILER LANGUAGE LARGE_P LAST_P LEADING LEAST LEFT LEVEL
437 LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP LOCATION
440 MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
442 NAME_P NAMES NATIONAL NATURAL NCHAR NEW NEXT NO NOCREATEDB
443 NOCREATEROLE NOCREATEUSER NOINHERIT NOLOGIN_P NONE NOSUPERUSER
444 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NULLS_P NUMERIC
446 OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OR
447 ORDER OUT_P OUTER_P OVERLAPS OVERLAY OWNED OWNER
449 PARSER PARTIAL PASSWORD PLACING PLANS POSITION
450 PRECISION PRESERVE PREPARE PREPARED PRIMARY
451 PRIOR PRIVILEGES PROCEDURAL PROCEDURE
455 READ REAL REASSIGN RECHECK RECURSIVE REFERENCES REINDEX RELATIVE_P RELEASE
456 RENAME REPEATABLE REPLACE REPLICA RESET RESTART RESTRICT RETURNING RETURNS
457 REVOKE RIGHT ROLE ROLLBACK ROW ROWS RULE
459 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE
460 SERIALIZABLE SESSION SESSION_USER SET SETOF SHARE
461 SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT
462 STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING SUPERUSER_P
463 SYMMETRIC SYSID SYSTEM_P
465 TABLE TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
466 TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
467 TRUNCATE TRUSTED TYPE_P
469 UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
472 VACUUM VALID VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
473 VERBOSE VERSION_P VIEW VOLATILE
475 WHEN WHERE WHITESPACE_P WITH WITHOUT WORK WRITE
477 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLFOREST XMLPARSE
478 XMLPI XMLROOT XMLSERIALIZE
484 /* The grammar thinks these are keywords, but they are not in the keywords.c
485 * list and so can never be entered directly. The filter in parser.c
486 * creates these tokens when required.
488 %token NULLS_FIRST NULLS_LAST WITH_TIME
490 /* Special token types, not actually keywords - see the "lex" file */
491 %token <str> IDENT FCONST SCONST BCONST XCONST Op
492 %token <ival> ICONST PARAM
494 /* precedence: lowest to highest */
495 %nonassoc SET /* see relation_expr_opt_alias */
503 %nonassoc LIKE ILIKE SIMILAR
508 %left POSTFIXOP /* dummy for postfix Op rules */
509 %nonassoc IDENT /* to support target_el without AS */
510 %left Op OPERATOR /* multi-character ops and user-defined operators */
513 %nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN /* sets precedence for IS NULL, etc */
517 /* Unary Operators */
518 %left AT ZONE /* sets precedence for AT TIME ZONE */
525 * These might seem to be low-precedence, but actually they are not part
526 * of the arithmetic hierarchy at all in their use as JOIN operators.
527 * We make them high-precedence to support their use as function names.
528 * They wouldn't be given a precedence at all, were it not that we need
529 * left-associativity among the JOIN rules themselves.
531 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
532 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
533 %right PRESERVE STRIP_P
537 * Handle comment-only lines, and ;; SELECT * FROM pg_class ;;;
538 * psql already handles such cases, but other interfaces don't.
541 stmtblock: stmtmulti { parsetree = $1; }
544 /* the thrashing around here is to discard "empty" statements... */
545 stmtmulti: stmtmulti ';' stmt
547 $$ = lappend($1, $3);
561 | AlterDatabaseSetStmt
565 | AlterObjectSchemaStmt
571 | AlterTSConfigurationStmt
572 | AlterTSDictionaryStmt
585 | CreateConversionStmt
596 | CreateTableSpaceStmt
655 /*****************************************************************************
657 * Create a new Postgres DBMS role
659 *****************************************************************************/
662 CREATE ROLE RoleId opt_with OptRoleList
664 CreateRoleStmt *n = makeNode(CreateRoleStmt);
665 n->stmt_type = ROLESTMT_ROLE;
678 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
679 * for backwards compatibility). Note: the only option required by SQL99
680 * is "WITH ADMIN name".
683 OptRoleList OptRoleElem { $$ = lappend($1, $2); }
684 | /* EMPTY */ { $$ = NIL; }
690 $$ = makeDefElem("password",
691 (Node *)makeString($2));
695 $$ = makeDefElem("password", NULL);
697 | ENCRYPTED PASSWORD Sconst
699 $$ = makeDefElem("encryptedPassword",
700 (Node *)makeString($3));
702 | UNENCRYPTED PASSWORD Sconst
704 $$ = makeDefElem("unencryptedPassword",
705 (Node *)makeString($3));
709 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
713 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
717 $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE));
721 $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE));
725 $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
729 $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
733 $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE));
737 $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE));
741 /* For backwards compatibility, synonym for SUPERUSER */
742 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
746 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
750 $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE));
754 $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE));
756 | CONNECTION LIMIT SignedIconst
758 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3));
762 $$ = makeDefElem("validUntil", (Node *)makeString($3));
764 /* Supported but not documented for roles, for use by ALTER GROUP. */
767 $$ = makeDefElem("rolemembers", (Node *)$2);
769 /* The following are not supported by ALTER ROLE/USER/GROUP */
772 $$ = makeDefElem("sysid", (Node *)makeInteger($2));
776 $$ = makeDefElem("adminmembers", (Node *)$2);
780 $$ = makeDefElem("rolemembers", (Node *)$2);
782 | IN_P ROLE name_list
784 $$ = makeDefElem("addroleto", (Node *)$3);
786 | IN_P GROUP_P name_list
788 $$ = makeDefElem("addroleto", (Node *)$3);
793 /*****************************************************************************
795 * Create a new Postgres DBMS user (role with implied login ability)
797 *****************************************************************************/
800 CREATE USER RoleId opt_with OptRoleList
802 CreateRoleStmt *n = makeNode(CreateRoleStmt);
803 n->stmt_type = ROLESTMT_USER;
811 /*****************************************************************************
813 * Alter a postgresql DBMS role
815 *****************************************************************************/
818 ALTER ROLE RoleId opt_with OptRoleList
820 AlterRoleStmt *n = makeNode(AlterRoleStmt);
822 n->action = +1; /* add, if there are members */
829 ALTER ROLE RoleId SetResetClause
831 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
839 /*****************************************************************************
841 * Alter a postgresql DBMS user
843 *****************************************************************************/
846 ALTER USER RoleId opt_with OptRoleList
848 AlterRoleStmt *n = makeNode(AlterRoleStmt);
850 n->action = +1; /* add, if there are members */
858 ALTER USER RoleId SetResetClause
860 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
868 /*****************************************************************************
870 * Drop a postgresql DBMS role
872 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
873 * might own objects in multiple databases, there is presently no way to
874 * implement either cascading or restricting. Caveat DBA.
875 *****************************************************************************/
880 DropRoleStmt *n = makeNode(DropRoleStmt);
881 n->missing_ok = FALSE;
885 | DROP ROLE IF_P EXISTS name_list
887 DropRoleStmt *n = makeNode(DropRoleStmt);
888 n->missing_ok = TRUE;
894 /*****************************************************************************
896 * Drop a postgresql DBMS user
898 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
899 * might own objects in multiple databases, there is presently no way to
900 * implement either cascading or restricting. Caveat DBA.
901 *****************************************************************************/
906 DropRoleStmt *n = makeNode(DropRoleStmt);
907 n->missing_ok = FALSE;
911 | DROP USER IF_P EXISTS name_list
913 DropRoleStmt *n = makeNode(DropRoleStmt);
915 n->missing_ok = TRUE;
921 /*****************************************************************************
923 * Create a postgresql group (role without login ability)
925 *****************************************************************************/
928 CREATE GROUP_P RoleId opt_with OptRoleList
930 CreateRoleStmt *n = makeNode(CreateRoleStmt);
931 n->stmt_type = ROLESTMT_GROUP;
939 /*****************************************************************************
941 * Alter a postgresql group
943 *****************************************************************************/
946 ALTER GROUP_P RoleId add_drop USER name_list
948 AlterRoleStmt *n = makeNode(AlterRoleStmt);
951 n->options = list_make1(makeDefElem("rolemembers",
957 add_drop: ADD_P { $$ = +1; }
962 /*****************************************************************************
964 * Drop a postgresql group
966 * XXX see above notes about cascading DROP USER; groups have same problem.
967 *****************************************************************************/
970 DROP GROUP_P name_list
972 DropRoleStmt *n = makeNode(DropRoleStmt);
973 n->missing_ok = FALSE;
977 | DROP GROUP_P IF_P EXISTS name_list
979 DropRoleStmt *n = makeNode(DropRoleStmt);
980 n->missing_ok = TRUE;
987 /*****************************************************************************
989 * Manipulate a schema
991 *****************************************************************************/
994 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
996 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
997 /* One can omit the schema name or the authorization id. */
1006 | CREATE SCHEMA ColId OptSchemaEltList
1008 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1009 /* ...but not both */
1019 | /* EMPTY */ { $$ = NULL; }
1023 OptSchemaEltList schema_stmt { $$ = lappend($1, $2); }
1024 | /* EMPTY */ { $$ = NIL; }
1028 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1029 * statement (in addition to by themselves).
1041 /*****************************************************************************
1043 * Set PG internal variable
1044 * SET name TO 'var_value'
1045 * Include SQL92 syntax (thomas 1997-10-22):
1046 * SET TIME ZONE 'var_value'
1048 *****************************************************************************/
1053 VariableSetStmt *n = $2;
1054 n->is_local = false;
1057 | SET LOCAL set_rest
1059 VariableSetStmt *n = $3;
1063 | SET SESSION set_rest
1065 VariableSetStmt *n = $3;
1066 n->is_local = false;
1071 set_rest: /* Generic SET syntaxes: */
1072 var_name TO var_list
1074 VariableSetStmt *n = makeNode(VariableSetStmt);
1075 n->kind = VAR_SET_VALUE;
1080 | var_name '=' var_list
1082 VariableSetStmt *n = makeNode(VariableSetStmt);
1083 n->kind = VAR_SET_VALUE;
1088 | var_name TO DEFAULT
1090 VariableSetStmt *n = makeNode(VariableSetStmt);
1091 n->kind = VAR_SET_DEFAULT;
1095 | var_name '=' DEFAULT
1097 VariableSetStmt *n = makeNode(VariableSetStmt);
1098 n->kind = VAR_SET_DEFAULT;
1102 | var_name FROM CURRENT_P
1104 VariableSetStmt *n = makeNode(VariableSetStmt);
1105 n->kind = VAR_SET_CURRENT;
1109 /* Special syntaxes mandated by SQL standard: */
1110 | TIME ZONE zone_value
1112 VariableSetStmt *n = makeNode(VariableSetStmt);
1113 n->kind = VAR_SET_VALUE;
1114 n->name = "timezone";
1116 n->args = list_make1($3);
1118 n->kind = VAR_SET_DEFAULT;
1121 | TRANSACTION transaction_mode_list
1123 VariableSetStmt *n = makeNode(VariableSetStmt);
1124 n->kind = VAR_SET_MULTI;
1125 n->name = "TRANSACTION";
1129 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1131 VariableSetStmt *n = makeNode(VariableSetStmt);
1132 n->kind = VAR_SET_MULTI;
1133 n->name = "SESSION CHARACTERISTICS";
1140 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1141 errmsg("current database cannot be changed"),
1142 scanner_errposition(@2)));
1143 $$ = NULL; /*not reached*/
1147 VariableSetStmt *n = makeNode(VariableSetStmt);
1148 n->kind = VAR_SET_VALUE;
1149 n->name = "search_path";
1150 n->args = list_make1(makeStringConst($2, @2));
1153 | NAMES opt_encoding
1155 VariableSetStmt *n = makeNode(VariableSetStmt);
1156 n->kind = VAR_SET_VALUE;
1157 n->name = "client_encoding";
1159 n->args = list_make1(makeStringConst($2, @2));
1161 n->kind = VAR_SET_DEFAULT;
1164 | ROLE ColId_or_Sconst
1166 VariableSetStmt *n = makeNode(VariableSetStmt);
1167 n->kind = VAR_SET_VALUE;
1169 n->args = list_make1(makeStringConst($2, @2));
1172 | SESSION AUTHORIZATION ColId_or_Sconst
1174 VariableSetStmt *n = makeNode(VariableSetStmt);
1175 n->kind = VAR_SET_VALUE;
1176 n->name = "session_authorization";
1177 n->args = list_make1(makeStringConst($3, @3));
1180 | SESSION AUTHORIZATION DEFAULT
1182 VariableSetStmt *n = makeNode(VariableSetStmt);
1183 n->kind = VAR_SET_DEFAULT;
1184 n->name = "session_authorization";
1187 | XML_P OPTION document_or_content
1189 VariableSetStmt *n = makeNode(VariableSetStmt);
1190 n->kind = VAR_SET_VALUE;
1191 n->name = "xmloption";
1192 n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1197 var_name: ColId { $$ = $1; }
1198 | var_name '.' ColId
1200 $$ = palloc(strlen($1) + strlen($3) + 2);
1201 sprintf($$, "%s.%s", $1, $3);
1205 var_list: var_value { $$ = list_make1($1); }
1206 | var_list ',' var_value { $$ = lappend($1, $3); }
1209 var_value: opt_boolean
1210 { $$ = makeStringConst($1, @1); }
1212 { $$ = makeStringConst($1, @1); }
1214 { $$ = makeAConst($1, @1); }
1217 iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1218 | READ COMMITTED { $$ = "read committed"; }
1219 | REPEATABLE READ { $$ = "repeatable read"; }
1220 | SERIALIZABLE { $$ = "serializable"; }
1224 TRUE_P { $$ = "true"; }
1225 | FALSE_P { $$ = "false"; }
1227 | OFF { $$ = "off"; }
1230 /* Timezone values can be:
1231 * - a string such as 'pst8pdt'
1232 * - an identifier such as "pst8pdt"
1233 * - an integer or floating point number
1234 * - a time interval per SQL99
1235 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1236 * so use IDENT and reject anything which is a reserved word.
1241 $$ = makeStringConst($1, @1);
1245 $$ = makeStringConst($1, @1);
1247 | ConstInterval Sconst opt_interval
1252 A_Const *n = (A_Const *) linitial($3);
1253 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1255 (errcode(ERRCODE_SYNTAX_ERROR),
1256 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1257 scanner_errposition(@3)));
1260 $$ = makeStringConstCast($2, @2, t);
1262 | ConstInterval '(' Iconst ')' Sconst opt_interval
1267 A_Const *n = (A_Const *) linitial($6);
1268 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1270 (errcode(ERRCODE_SYNTAX_ERROR),
1271 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1272 scanner_errposition(@6)));
1273 if (list_length($6) != 1)
1275 (errcode(ERRCODE_SYNTAX_ERROR),
1276 errmsg("interval precision specified twice"),
1277 scanner_errposition(@1)));
1278 t->typmods = lappend($6, makeIntConst($3, @3));
1281 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1282 makeIntConst($3, @3));
1283 $$ = makeStringConstCast($5, @5, t);
1285 | NumericOnly { $$ = makeAConst($1, @1); }
1286 | DEFAULT { $$ = NULL; }
1287 | LOCAL { $$ = NULL; }
1292 | DEFAULT { $$ = NULL; }
1293 | /*EMPTY*/ { $$ = NULL; }
1298 | Sconst { $$ = $1; }
1304 VariableSetStmt *n = makeNode(VariableSetStmt);
1305 n->kind = VAR_RESET;
1311 VariableSetStmt *n = makeNode(VariableSetStmt);
1312 n->kind = VAR_RESET;
1313 n->name = "timezone";
1316 | RESET TRANSACTION ISOLATION LEVEL
1318 VariableSetStmt *n = makeNode(VariableSetStmt);
1319 n->kind = VAR_RESET;
1320 n->name = "transaction_isolation";
1323 | RESET SESSION AUTHORIZATION
1325 VariableSetStmt *n = makeNode(VariableSetStmt);
1326 n->kind = VAR_RESET;
1327 n->name = "session_authorization";
1332 VariableSetStmt *n = makeNode(VariableSetStmt);
1333 n->kind = VAR_RESET_ALL;
1338 /* SetResetClause allows SET or RESET without LOCAL */
1340 SET set_rest { $$ = $2; }
1341 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1348 VariableShowStmt *n = makeNode(VariableShowStmt);
1354 VariableShowStmt *n = makeNode(VariableShowStmt);
1355 n->name = "timezone";
1358 | SHOW TRANSACTION ISOLATION LEVEL
1360 VariableShowStmt *n = makeNode(VariableShowStmt);
1361 n->name = "transaction_isolation";
1364 | SHOW SESSION AUTHORIZATION
1366 VariableShowStmt *n = makeNode(VariableShowStmt);
1367 n->name = "session_authorization";
1372 VariableShowStmt *n = makeNode(VariableShowStmt);
1380 SET CONSTRAINTS constraints_set_list constraints_set_mode
1382 ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
1383 n->constraints = $3;
1389 constraints_set_list:
1391 | qualified_name_list { $$ = $1; }
1394 constraints_set_mode:
1395 DEFERRED { $$ = TRUE; }
1396 | IMMEDIATE { $$ = FALSE; }
1401 * Checkpoint statement
1406 CheckPointStmt *n = makeNode(CheckPointStmt);
1412 /*****************************************************************************
1414 * DISCARD { ALL | TEMP | PLANS }
1416 *****************************************************************************/
1421 DiscardStmt *n = makeNode(DiscardStmt);
1422 n->target = DISCARD_ALL;
1427 DiscardStmt *n = makeNode(DiscardStmt);
1428 n->target = DISCARD_TEMP;
1433 DiscardStmt *n = makeNode(DiscardStmt);
1434 n->target = DISCARD_TEMP;
1439 DiscardStmt *n = makeNode(DiscardStmt);
1440 n->target = DISCARD_PLANS;
1446 /*****************************************************************************
1448 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations
1450 * Note: we accept all subcommands for each of the four variants, and sort
1451 * out what's really legal at execution time.
1452 *****************************************************************************/
1455 ALTER TABLE relation_expr alter_table_cmds
1457 AlterTableStmt *n = makeNode(AlterTableStmt);
1460 n->relkind = OBJECT_TABLE;
1463 | ALTER INDEX relation_expr alter_table_cmds
1465 AlterTableStmt *n = makeNode(AlterTableStmt);
1468 n->relkind = OBJECT_INDEX;
1471 | ALTER SEQUENCE relation_expr alter_table_cmds
1473 AlterTableStmt *n = makeNode(AlterTableStmt);
1476 n->relkind = OBJECT_SEQUENCE;
1479 | ALTER VIEW relation_expr alter_table_cmds
1481 AlterTableStmt *n = makeNode(AlterTableStmt);
1484 n->relkind = OBJECT_VIEW;
1490 alter_table_cmd { $$ = list_make1($1); }
1491 | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
1495 /* ALTER TABLE <name> ADD [COLUMN] <coldef> */
1496 ADD_P opt_column columnDef
1498 AlterTableCmd *n = makeNode(AlterTableCmd);
1499 n->subtype = AT_AddColumn;
1503 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1504 | ALTER opt_column ColId alter_column_default
1506 AlterTableCmd *n = makeNode(AlterTableCmd);
1507 n->subtype = AT_ColumnDefault;
1512 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1513 | ALTER opt_column ColId DROP NOT NULL_P
1515 AlterTableCmd *n = makeNode(AlterTableCmd);
1516 n->subtype = AT_DropNotNull;
1520 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1521 | ALTER opt_column ColId SET NOT NULL_P
1523 AlterTableCmd *n = makeNode(AlterTableCmd);
1524 n->subtype = AT_SetNotNull;
1528 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
1529 | ALTER opt_column ColId SET STATISTICS SignedIconst
1531 AlterTableCmd *n = makeNode(AlterTableCmd);
1532 n->subtype = AT_SetStatistics;
1534 n->def = (Node *) makeInteger($6);
1537 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1538 | ALTER opt_column ColId SET STORAGE ColId
1540 AlterTableCmd *n = makeNode(AlterTableCmd);
1541 n->subtype = AT_SetStorage;
1543 n->def = (Node *) makeString($6);
1546 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1547 | DROP opt_column ColId opt_drop_behavior
1549 AlterTableCmd *n = makeNode(AlterTableCmd);
1550 n->subtype = AT_DropColumn;
1556 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
1557 * [ USING <expression> ]
1559 | ALTER opt_column ColId opt_set_data TYPE_P Typename alter_using
1561 AlterTableCmd *n = makeNode(AlterTableCmd);
1562 n->subtype = AT_AlterColumnType;
1564 n->def = (Node *) $6;
1568 /* ALTER TABLE <name> ADD CONSTRAINT ... */
1569 | ADD_P TableConstraint
1571 AlterTableCmd *n = makeNode(AlterTableCmd);
1572 n->subtype = AT_AddConstraint;
1576 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1577 | DROP CONSTRAINT name opt_drop_behavior
1579 AlterTableCmd *n = makeNode(AlterTableCmd);
1580 n->subtype = AT_DropConstraint;
1585 /* ALTER TABLE <name> SET WITHOUT OIDS */
1588 AlterTableCmd *n = makeNode(AlterTableCmd);
1589 n->subtype = AT_DropOids;
1592 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1595 AlterTableCmd *n = makeNode(AlterTableCmd);
1596 n->subtype = AT_ClusterOn;
1600 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1601 | SET WITHOUT CLUSTER
1603 AlterTableCmd *n = makeNode(AlterTableCmd);
1604 n->subtype = AT_DropCluster;
1608 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
1609 | ENABLE_P TRIGGER name
1611 AlterTableCmd *n = makeNode(AlterTableCmd);
1612 n->subtype = AT_EnableTrig;
1616 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
1617 | ENABLE_P ALWAYS TRIGGER name
1619 AlterTableCmd *n = makeNode(AlterTableCmd);
1620 n->subtype = AT_EnableAlwaysTrig;
1624 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
1625 | ENABLE_P REPLICA TRIGGER name
1627 AlterTableCmd *n = makeNode(AlterTableCmd);
1628 n->subtype = AT_EnableReplicaTrig;
1632 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
1633 | ENABLE_P TRIGGER ALL
1635 AlterTableCmd *n = makeNode(AlterTableCmd);
1636 n->subtype = AT_EnableTrigAll;
1639 /* ALTER TABLE <name> ENABLE TRIGGER USER */
1640 | ENABLE_P TRIGGER USER
1642 AlterTableCmd *n = makeNode(AlterTableCmd);
1643 n->subtype = AT_EnableTrigUser;
1646 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
1647 | DISABLE_P TRIGGER name
1649 AlterTableCmd *n = makeNode(AlterTableCmd);
1650 n->subtype = AT_DisableTrig;
1654 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
1655 | DISABLE_P TRIGGER ALL
1657 AlterTableCmd *n = makeNode(AlterTableCmd);
1658 n->subtype = AT_DisableTrigAll;
1661 /* ALTER TABLE <name> DISABLE TRIGGER USER */
1662 | DISABLE_P TRIGGER USER
1664 AlterTableCmd *n = makeNode(AlterTableCmd);
1665 n->subtype = AT_DisableTrigUser;
1668 /* ALTER TABLE <name> ENABLE RULE <rule> */
1669 | ENABLE_P RULE name
1671 AlterTableCmd *n = makeNode(AlterTableCmd);
1672 n->subtype = AT_EnableRule;
1676 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
1677 | ENABLE_P ALWAYS RULE name
1679 AlterTableCmd *n = makeNode(AlterTableCmd);
1680 n->subtype = AT_EnableAlwaysRule;
1684 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
1685 | ENABLE_P REPLICA RULE name
1687 AlterTableCmd *n = makeNode(AlterTableCmd);
1688 n->subtype = AT_EnableReplicaRule;
1692 /* ALTER TABLE <name> DISABLE RULE <rule> */
1693 | DISABLE_P RULE name
1695 AlterTableCmd *n = makeNode(AlterTableCmd);
1696 n->subtype = AT_DisableRule;
1700 /* ALTER TABLE <name> INHERIT <parent> */
1701 | INHERIT qualified_name
1703 AlterTableCmd *n = makeNode(AlterTableCmd);
1704 n->subtype = AT_AddInherit;
1705 n->def = (Node *) $2;
1708 /* ALTER TABLE <name> NO INHERIT <parent> */
1709 | NO INHERIT qualified_name
1711 AlterTableCmd *n = makeNode(AlterTableCmd);
1712 n->subtype = AT_DropInherit;
1713 n->def = (Node *) $3;
1716 /* ALTER TABLE <name> OWNER TO RoleId */
1719 AlterTableCmd *n = makeNode(AlterTableCmd);
1720 n->subtype = AT_ChangeOwner;
1724 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1725 | SET TABLESPACE name
1727 AlterTableCmd *n = makeNode(AlterTableCmd);
1728 n->subtype = AT_SetTableSpace;
1732 /* ALTER TABLE <name> SET (...) */
1735 AlterTableCmd *n = makeNode(AlterTableCmd);
1736 n->subtype = AT_SetRelOptions;
1737 n->def = (Node *)$2;
1740 /* ALTER TABLE <name> RESET (...) */
1743 AlterTableCmd *n = makeNode(AlterTableCmd);
1744 n->subtype = AT_ResetRelOptions;
1745 n->def = (Node *)$2;
1750 alter_column_default:
1751 SET DEFAULT a_expr { $$ = $3; }
1752 | DROP DEFAULT { $$ = NULL; }
1756 CASCADE { $$ = DROP_CASCADE; }
1757 | RESTRICT { $$ = DROP_RESTRICT; }
1758 | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1762 USING a_expr { $$ = $2; }
1763 | /* EMPTY */ { $$ = NULL; }
1768 /*****************************************************************************
1771 * close <portalname>
1773 *****************************************************************************/
1778 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1784 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1785 n->portalname = NULL;
1791 /*****************************************************************************
1794 * COPY relname ['(' columnList ')'] FROM/TO file [WITH options]
1796 * BINARY, OIDS, and DELIMITERS kept in old locations
1797 * for backward compatibility. 2002-06-18
1799 * COPY ( SELECT ... ) TO file [WITH options]
1800 * This form doesn't have the backwards-compatible option
1803 *****************************************************************************/
1805 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
1806 copy_from copy_file_name copy_delimiter opt_with copy_opt_list
1808 CopyStmt *n = makeNode(CopyStmt);
1816 /* Concatenate user-supplied flags */
1818 n->options = lappend(n->options, $2);
1820 n->options = lappend(n->options, $5);
1822 n->options = lappend(n->options, $8);
1824 n->options = list_concat(n->options, $10);
1827 | COPY select_with_parens TO copy_file_name opt_with
1830 CopyStmt *n = makeNode(CopyStmt);
1843 | TO { $$ = FALSE; }
1847 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
1848 * used depends on the direction. (It really doesn't make sense to copy from
1849 * stdout. We silently correct the "typo".) - AY 9/94
1853 | STDIN { $$ = NULL; }
1854 | STDOUT { $$ = NULL; }
1860 copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
1861 | /* EMPTY */ { $$ = NIL; }
1868 $$ = makeDefElem("binary", (Node *)makeInteger(TRUE));
1872 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
1874 | DELIMITER opt_as Sconst
1876 $$ = makeDefElem("delimiter", (Node *)makeString($3));
1878 | NULL_P opt_as Sconst
1880 $$ = makeDefElem("null", (Node *)makeString($3));
1884 $$ = makeDefElem("csv", (Node *)makeInteger(TRUE));
1888 $$ = makeDefElem("header", (Node *)makeInteger(TRUE));
1890 | QUOTE opt_as Sconst
1892 $$ = makeDefElem("quote", (Node *)makeString($3));
1894 | ESCAPE opt_as Sconst
1896 $$ = makeDefElem("escape", (Node *)makeString($3));
1898 | FORCE QUOTE columnList
1900 $$ = makeDefElem("force_quote", (Node *)$3);
1902 | FORCE NOT NULL_P columnList
1904 $$ = makeDefElem("force_notnull", (Node *)$4);
1908 /* The following exist for backward compatibility */
1913 $$ = makeDefElem("binary", (Node *)makeInteger(TRUE));
1915 | /*EMPTY*/ { $$ = NULL; }
1921 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
1923 | /*EMPTY*/ { $$ = NULL; }
1927 /* USING DELIMITERS kept for backward compatibility. 2002-06-15 */
1928 opt_using DELIMITERS Sconst
1930 $$ = makeDefElem("delimiter", (Node *)makeString($3));
1932 | /*EMPTY*/ { $$ = NULL; }
1941 /*****************************************************************************
1944 * CREATE TABLE relname
1946 *****************************************************************************/
1948 CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
1949 OptInherit OptWith OnCommitOption OptTableSpace
1951 CreateStmt *n = makeNode(CreateStmt);
1955 n->inhRelations = $8;
1956 n->constraints = NIL;
1959 n->tablespacename = $11;
1962 | CREATE OptTemp TABLE qualified_name OF qualified_name
1963 '(' OptTableElementList ')' OptWith OnCommitOption OptTableSpace
1965 /* SQL99 CREATE TABLE OF <UDT> (cols) seems to be satisfied
1966 * by our inheritance capabilities. Let's try it...
1968 CreateStmt *n = makeNode(CreateStmt);
1972 n->inhRelations = list_make1($6);
1973 n->constraints = NIL;
1976 n->tablespacename = $12;
1982 * Redundancy here is needed to avoid shift/reduce conflicts,
1983 * since TEMP is not a reserved word. See also OptTempTableName.
1985 * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
1986 * the LOCAL keyword is really meaningless.
1988 OptTemp: TEMPORARY { $$ = TRUE; }
1989 | TEMP { $$ = TRUE; }
1990 | LOCAL TEMPORARY { $$ = TRUE; }
1991 | LOCAL TEMP { $$ = TRUE; }
1992 | GLOBAL TEMPORARY { $$ = TRUE; }
1993 | GLOBAL TEMP { $$ = TRUE; }
1994 | /*EMPTY*/ { $$ = FALSE; }
1997 OptTableElementList:
1998 TableElementList { $$ = $1; }
1999 | /*EMPTY*/ { $$ = NIL; }
2005 $$ = list_make1($1);
2007 | TableElementList ',' TableElement
2009 $$ = lappend($1, $3);
2014 columnDef { $$ = $1; }
2015 | TableLikeClause { $$ = $1; }
2016 | TableConstraint { $$ = $1; }
2019 columnDef: ColId Typename ColQualList
2021 ColumnDef *n = makeNode(ColumnDef);
2024 n->constraints = $3;
2031 ColQualList ColConstraint { $$ = lappend($1, $2); }
2032 | /*EMPTY*/ { $$ = NIL; }
2036 CONSTRAINT name ColConstraintElem
2038 switch (nodeTag($3))
2042 Constraint *n = (Constraint *)$3;
2046 case T_FkConstraint:
2048 FkConstraint *n = (FkConstraint *)$3;
2049 n->constr_name = $2;
2057 | ColConstraintElem { $$ = $1; }
2058 | ConstraintAttr { $$ = $1; }
2061 /* DEFAULT NULL is already the default for Postgres.
2062 * But define it here and carry it forward into the system
2063 * to make it explicit.
2064 * - thomas 1998-09-13
2066 * WITH NULL and NULL are not SQL92-standard syntax elements,
2067 * so leave them out. Use DEFAULT NULL to explicitly indicate
2068 * that a column may have that value. WITH NULL leads to
2069 * shift/reduce conflicts with WITH TIME ZONE anyway.
2070 * - thomas 1999-01-08
2072 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
2073 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
2074 * or be part of a_expr NOT LIKE or similar constructs).
2079 Constraint *n = makeNode(Constraint);
2080 n->contype = CONSTR_NOTNULL;
2083 n->cooked_expr = NULL;
2085 n->indexspace = NULL;
2090 Constraint *n = makeNode(Constraint);
2091 n->contype = CONSTR_NULL;
2094 n->cooked_expr = NULL;
2096 n->indexspace = NULL;
2099 | UNIQUE opt_definition OptConsTableSpace
2101 Constraint *n = makeNode(Constraint);
2102 n->contype = CONSTR_UNIQUE;
2105 n->cooked_expr = NULL;
2111 | PRIMARY KEY opt_definition OptConsTableSpace
2113 Constraint *n = makeNode(Constraint);
2114 n->contype = CONSTR_PRIMARY;
2117 n->cooked_expr = NULL;
2123 | CHECK '(' a_expr ')'
2125 Constraint *n = makeNode(Constraint);
2126 n->contype = CONSTR_CHECK;
2129 n->cooked_expr = NULL;
2131 n->indexspace = NULL;
2136 Constraint *n = makeNode(Constraint);
2137 n->contype = CONSTR_DEFAULT;
2140 n->cooked_expr = NULL;
2142 n->indexspace = NULL;
2145 | REFERENCES qualified_name opt_column_list key_match key_actions
2147 FkConstraint *n = makeNode(FkConstraint);
2148 n->constr_name = NULL;
2152 n->fk_matchtype = $4;
2153 n->fk_upd_action = (char) ($5 >> 8);
2154 n->fk_del_action = (char) ($5 & 0xFF);
2155 n->deferrable = FALSE;
2156 n->initdeferred = FALSE;
2162 * ConstraintAttr represents constraint attributes, which we parse as if
2163 * they were independent constraint clauses, in order to avoid shift/reduce
2164 * conflicts (since NOT might start either an independent NOT NULL clause
2165 * or an attribute). parse_utilcmd.c is responsible for attaching the
2166 * attribute information to the preceding "real" constraint node, and for
2167 * complaining if attribute clauses appear in the wrong place or wrong
2170 * See also ConstraintAttributeSpec, which can be used in places where
2171 * there is no parsing conflict.
2176 Constraint *n = makeNode(Constraint);
2177 n->contype = CONSTR_ATTR_DEFERRABLE;
2182 Constraint *n = makeNode(Constraint);
2183 n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
2186 | INITIALLY DEFERRED
2188 Constraint *n = makeNode(Constraint);
2189 n->contype = CONSTR_ATTR_DEFERRED;
2192 | INITIALLY IMMEDIATE
2194 Constraint *n = makeNode(Constraint);
2195 n->contype = CONSTR_ATTR_IMMEDIATE;
2202 * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2203 * This seems to be a poor man's inheritance capability, with the resulting
2204 * tables completely decoupled except for the original commonality in definitions.
2206 * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2207 * which is a part of SQL:2003.
2210 LIKE qualified_name TableLikeOptionList
2212 InhRelation *n = makeNode(InhRelation);
2219 TableLikeOptionList:
2220 TableLikeOptionList TableLikeOption { $$ = lappend_int($1, $2); }
2221 | /* EMPTY */ { $$ = NIL; }
2225 INCLUDING DEFAULTS { $$ = CREATE_TABLE_LIKE_INCLUDING_DEFAULTS; }
2226 | EXCLUDING DEFAULTS { $$ = CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS; }
2227 | INCLUDING CONSTRAINTS { $$ = CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS; }
2228 | EXCLUDING CONSTRAINTS { $$ = CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS; }
2229 | INCLUDING INDEXES { $$ = CREATE_TABLE_LIKE_INCLUDING_INDEXES; }
2230 | EXCLUDING INDEXES { $$ = CREATE_TABLE_LIKE_EXCLUDING_INDEXES; }
2234 /* ConstraintElem specifies constraint syntax which is not embedded into
2235 * a column definition. ColConstraintElem specifies the embedded form.
2236 * - thomas 1997-12-03
2239 CONSTRAINT name ConstraintElem
2241 switch (nodeTag($3))
2245 Constraint *n = (Constraint *)$3;
2249 case T_FkConstraint:
2251 FkConstraint *n = (FkConstraint *)$3;
2252 n->constr_name = $2;
2260 | ConstraintElem { $$ = $1; }
2264 CHECK '(' a_expr ')'
2266 Constraint *n = makeNode(Constraint);
2267 n->contype = CONSTR_CHECK;
2270 n->cooked_expr = NULL;
2271 n->indexspace = NULL;
2274 | UNIQUE '(' columnList ')' opt_definition OptConsTableSpace
2276 Constraint *n = makeNode(Constraint);
2277 n->contype = CONSTR_UNIQUE;
2280 n->cooked_expr = NULL;
2286 | PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace
2288 Constraint *n = makeNode(Constraint);
2289 n->contype = CONSTR_PRIMARY;
2292 n->cooked_expr = NULL;
2298 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
2299 opt_column_list key_match key_actions ConstraintAttributeSpec
2301 FkConstraint *n = makeNode(FkConstraint);
2302 n->constr_name = NULL;
2306 n->fk_matchtype = $9;
2307 n->fk_upd_action = (char) ($10 >> 8);
2308 n->fk_del_action = (char) ($10 & 0xFF);
2309 n->deferrable = ($11 & 1) != 0;
2310 n->initdeferred = ($11 & 2) != 0;
2316 '(' columnList ')' { $$ = $2; }
2317 | /*EMPTY*/ { $$ = NIL; }
2321 columnElem { $$ = list_make1($1); }
2322 | columnList ',' columnElem { $$ = lappend($1, $3); }
2327 $$ = (Node *) makeString($1);
2331 key_match: MATCH FULL
2333 $$ = FKCONSTR_MATCH_FULL;
2338 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2339 errmsg("MATCH PARTIAL not yet implemented"),
2340 scanner_errposition(@1)));
2341 $$ = FKCONSTR_MATCH_PARTIAL;
2345 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2349 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2354 * We combine the update and delete actions into one value temporarily
2355 * for simplicity of parsing, and then break them down again in the
2356 * calling production. update is in the left 8 bits, delete in the right.
2357 * Note that NOACTION is the default.
2361 { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2363 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
2364 | key_update key_delete
2365 { $$ = ($1 << 8) | ($2 & 0xFF); }
2366 | key_delete key_update
2367 { $$ = ($2 << 8) | ($1 & 0xFF); }
2369 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2372 key_update: ON UPDATE key_action { $$ = $3; }
2375 key_delete: ON DELETE_P key_action { $$ = $3; }
2379 NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; }
2380 | RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; }
2381 | CASCADE { $$ = FKCONSTR_ACTION_CASCADE; }
2382 | SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; }
2383 | SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; }
2386 OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
2387 | /*EMPTY*/ { $$ = NIL; }
2390 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
2392 WITH definition { $$ = $2; }
2393 | WITH OIDS { $$ = list_make1(defWithOids(true)); }
2394 | WITHOUT OIDS { $$ = list_make1(defWithOids(false)); }
2395 | /*EMPTY*/ { $$ = NIL; }
2398 OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
2399 | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
2400 | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
2401 | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
2404 OptTableSpace: TABLESPACE name { $$ = $2; }
2405 | /*EMPTY*/ { $$ = NULL; }
2408 OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
2409 | /*EMPTY*/ { $$ = NULL; }
2414 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
2419 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
2422 * When the SelectStmt is a set-operation tree, we must
2423 * stuff the INTO information into the leftmost component
2424 * Select, because that's where analyze.c will expect
2425 * to find it. Similarly, the output column names must
2426 * be attached to that Select's target list.
2428 SelectStmt *n = findLeftmostSelect((SelectStmt *) $6);
2429 if (n->intoClause != NULL)
2431 (errcode(ERRCODE_SYNTAX_ERROR),
2432 errmsg("CREATE TABLE AS cannot specify INTO"),
2433 scanner_errposition(exprLocation((Node *) n->intoClause))));
2434 $4->rel->istemp = $2;
2436 /* Implement WITH NO DATA by forcing top-level LIMIT 0 */
2438 ((SelectStmt *) $6)->limitCount = makeIntConst(0, -1);
2444 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
2446 $$ = makeNode(IntoClause);
2451 $$->tableSpaceName = $5;
2456 '(' CreateAsList ')' { $$ = $2; }
2457 | /*EMPTY*/ { $$ = NIL; }
2461 CreateAsElement { $$ = list_make1($1); }
2462 | CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); }
2468 ColumnDef *n = makeNode(ColumnDef);
2473 n->is_not_null = false;
2474 n->raw_default = NULL;
2475 n->cooked_default = NULL;
2476 n->constraints = NIL;
2482 WITH DATA_P { $$ = TRUE; }
2483 | WITH NO DATA_P { $$ = FALSE; }
2484 | /*EMPTY*/ { $$ = TRUE; }
2488 /*****************************************************************************
2491 * CREATE SEQUENCE seqname
2492 * ALTER SEQUENCE seqname
2494 *****************************************************************************/
2497 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
2499 CreateSeqStmt *n = makeNode(CreateSeqStmt);
2508 ALTER SEQUENCE relation_expr SeqOptList
2510 AlterSeqStmt *n = makeNode(AlterSeqStmt);
2517 OptSeqOptList: SeqOptList { $$ = $1; }
2518 | /*EMPTY*/ { $$ = NIL; }
2521 SeqOptList: SeqOptElem { $$ = list_make1($1); }
2522 | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
2525 SeqOptElem: CACHE NumericOnly
2527 $$ = makeDefElem("cache", (Node *)$2);
2531 $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE));
2535 $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE));
2537 | INCREMENT opt_by NumericOnly
2539 $$ = makeDefElem("increment", (Node *)$3);
2541 | MAXVALUE NumericOnly
2543 $$ = makeDefElem("maxvalue", (Node *)$2);
2545 | MINVALUE NumericOnly
2547 $$ = makeDefElem("minvalue", (Node *)$2);
2551 $$ = makeDefElem("maxvalue", NULL);
2555 $$ = makeDefElem("minvalue", NULL);
2559 $$ = makeDefElem("owned_by", (Node *)$3);
2561 | START opt_with NumericOnly
2563 $$ = makeDefElem("start", (Node *)$3);
2567 $$ = makeDefElem("restart", NULL);
2569 | RESTART opt_with NumericOnly
2571 $$ = makeDefElem("restart", (Node *)$3);
2580 FCONST { $$ = makeFloat($1); }
2586 | SignedIconst { $$ = makeInteger($1); };
2589 /*****************************************************************************
2592 * CREATE PROCEDURAL LANGUAGE ...
2593 * DROP PROCEDURAL LANGUAGE ...
2595 *****************************************************************************/
2598 CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2600 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2602 /* parameters are all to be supplied by system */
2604 n->plvalidator = NIL;
2605 n->pltrusted = false;
2608 | CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2609 HANDLER handler_name opt_validator opt_lancompiler
2611 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2614 n->plvalidator = $8;
2616 /* LANCOMPILER is now ignored entirely */
2622 TRUSTED { $$ = TRUE; }
2623 | /*EMPTY*/ { $$ = FALSE; }
2626 /* This ought to be just func_name, but that causes reduce/reduce conflicts
2627 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
2628 * Work around by using simple names, instead.
2631 name { $$ = list_make1(makeString($1)); }
2632 | name attrs { $$ = lcons(makeString($1), $2); }
2636 VALIDATOR handler_name { $$ = $2; }
2637 | /*EMPTY*/ { $$ = NIL; }
2641 LANCOMPILER Sconst { $$ = $2; }
2642 | /*EMPTY*/ { $$ = NULL; }
2646 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
2648 DropPLangStmt *n = makeNode(DropPLangStmt);
2651 n->missing_ok = false;
2654 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
2656 DropPLangStmt *n = makeNode(DropPLangStmt);
2659 n->missing_ok = true;
2669 /*****************************************************************************
2672 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
2674 *****************************************************************************/
2676 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
2678 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
2679 n->tablespacename = $3;
2686 OptTableSpaceOwner: OWNER name { $$ = $2; }
2687 | /*EMPTY */ { $$ = NULL; }
2690 /*****************************************************************************
2693 * DROP TABLESPACE <tablespace>
2695 * No need for drop behaviour as we cannot implement dependencies for
2696 * objects in other databases; we can only support RESTRICT.
2698 ****************************************************************************/
2700 DropTableSpaceStmt: DROP TABLESPACE name
2702 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2703 n->tablespacename = $3;
2704 n->missing_ok = false;
2707 | DROP TABLESPACE IF_P EXISTS name
2709 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2710 n->tablespacename = $5;
2711 n->missing_ok = true;
2716 /*****************************************************************************
2719 * CREATE TRIGGER ...
2722 *****************************************************************************/
2725 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
2726 qualified_name TriggerForSpec EXECUTE PROCEDURE
2727 func_name '(' TriggerFuncArgs ')'
2729 CreateTrigStmt *n = makeNode(CreateTrigStmt);
2736 memcpy(n->actions, $5, 4);
2737 n->isconstraint = FALSE;
2738 n->deferrable = FALSE;
2739 n->initdeferred = FALSE;
2740 n->constrrel = NULL;
2743 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
2744 qualified_name OptConstrFromTable
2745 ConstraintAttributeSpec
2746 FOR EACH ROW EXECUTE PROCEDURE
2747 func_name '(' TriggerFuncArgs ')'
2749 CreateTrigStmt *n = makeNode(CreateTrigStmt);
2756 memcpy(n->actions, $6, 4);
2757 n->isconstraint = TRUE;
2758 n->deferrable = ($10 & 1) != 0;
2759 n->initdeferred = ($10 & 2) != 0;
2767 BEFORE { $$ = TRUE; }
2768 | AFTER { $$ = FALSE; }
2774 char *e = palloc(4);
2775 e[0] = $1; e[1] = '\0';
2778 | TriggerOneEvent OR TriggerOneEvent
2780 char *e = palloc(4);
2781 e[0] = $1; e[1] = $3; e[2] = '\0';
2784 | TriggerOneEvent OR TriggerOneEvent OR TriggerOneEvent
2786 char *e = palloc(4);
2787 e[0] = $1; e[1] = $3; e[2] = $5; e[3] = '\0';
2793 INSERT { $$ = 'i'; }
2794 | DELETE_P { $$ = 'd'; }
2795 | UPDATE { $$ = 'u'; }
2796 | TRUNCATE { $$ = 't'; }
2800 FOR TriggerForOpt TriggerForType
2807 * If ROW/STATEMENT not specified, default to
2808 * STATEMENT, per SQL
2821 | STATEMENT { $$ = FALSE; }
2825 TriggerFuncArg { $$ = list_make1($1); }
2826 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
2827 | /*EMPTY*/ { $$ = NIL; }
2834 snprintf(buf, sizeof(buf), "%d", $1);
2835 $$ = makeString(pstrdup(buf));
2837 | FCONST { $$ = makeString($1); }
2838 | Sconst { $$ = makeString($1); }
2839 | BCONST { $$ = makeString($1); }
2840 | XCONST { $$ = makeString($1); }
2841 | ColId { $$ = makeString($1); }
2845 FROM qualified_name { $$ = $2; }
2846 | /*EMPTY*/ { $$ = NULL; }
2849 ConstraintAttributeSpec:
2850 ConstraintDeferrabilitySpec
2852 | ConstraintDeferrabilitySpec ConstraintTimeSpec
2854 if ($1 == 0 && $2 != 0)
2856 (errcode(ERRCODE_SYNTAX_ERROR),
2857 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
2858 scanner_errposition(@1)));
2861 | ConstraintTimeSpec
2868 | ConstraintTimeSpec ConstraintDeferrabilitySpec
2870 if ($2 == 0 && $1 != 0)
2872 (errcode(ERRCODE_SYNTAX_ERROR),
2873 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
2874 scanner_errposition(@1)));
2881 ConstraintDeferrabilitySpec:
2882 NOT DEFERRABLE { $$ = 0; }
2883 | DEFERRABLE { $$ = 1; }
2887 INITIALLY IMMEDIATE { $$ = 0; }
2888 | INITIALLY DEFERRED { $$ = 2; }
2893 DROP TRIGGER name ON qualified_name opt_drop_behavior
2895 DropPropertyStmt *n = makeNode(DropPropertyStmt);
2899 n->removeType = OBJECT_TRIGGER;
2900 n->missing_ok = false;
2903 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
2905 DropPropertyStmt *n = makeNode(DropPropertyStmt);
2909 n->removeType = OBJECT_TRIGGER;
2910 n->missing_ok = true;
2916 /*****************************************************************************
2919 * CREATE ASSERTION ...
2920 * DROP ASSERTION ...
2922 *****************************************************************************/
2925 CREATE ASSERTION name CHECK '(' a_expr ')'
2926 ConstraintAttributeSpec
2928 CreateTrigStmt *n = makeNode(CreateTrigStmt);
2930 n->args = list_make1($6);
2931 n->isconstraint = TRUE;
2932 n->deferrable = ($8 & 1) != 0;
2933 n->initdeferred = ($8 & 2) != 0;
2936 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2937 errmsg("CREATE ASSERTION is not yet implemented")));
2944 DROP ASSERTION name opt_drop_behavior
2946 DropPropertyStmt *n = makeNode(DropPropertyStmt);
2950 n->removeType = OBJECT_TRIGGER; /* XXX */
2952 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2953 errmsg("DROP ASSERTION is not yet implemented")));
2959 /*****************************************************************************
2962 * define (aggregate,operator,type)
2964 *****************************************************************************/
2967 CREATE AGGREGATE func_name aggr_args definition
2969 DefineStmt *n = makeNode(DefineStmt);
2970 n->kind = OBJECT_AGGREGATE;
2971 n->oldstyle = false;
2977 | CREATE AGGREGATE func_name old_aggr_definition
2979 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
2980 DefineStmt *n = makeNode(DefineStmt);
2981 n->kind = OBJECT_AGGREGATE;
2988 | CREATE OPERATOR any_operator definition
2990 DefineStmt *n = makeNode(DefineStmt);
2991 n->kind = OBJECT_OPERATOR;
2992 n->oldstyle = false;
2998 | CREATE TYPE_P any_name definition
3000 DefineStmt *n = makeNode(DefineStmt);
3001 n->kind = OBJECT_TYPE;
3002 n->oldstyle = false;
3008 | CREATE TYPE_P any_name
3010 /* Shell type (identified by lack of definition) */
3011 DefineStmt *n = makeNode(DefineStmt);
3012 n->kind = OBJECT_TYPE;
3013 n->oldstyle = false;
3016 n->definition = NIL;
3019 | CREATE TYPE_P any_name AS '(' TableFuncElementList ')'
3021 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
3022 RangeVar *r = makeNode(RangeVar);
3024 /* can't use qualified_name, sigh */
3025 switch (list_length($3))
3028 r->catalogname = NULL;
3029 r->schemaname = NULL;
3030 r->relname = strVal(linitial($3));
3033 r->catalogname = NULL;
3034 r->schemaname = strVal(linitial($3));
3035 r->relname = strVal(lsecond($3));
3038 r->catalogname = strVal(linitial($3));
3039 r->schemaname = strVal(lsecond($3));
3040 r->relname = strVal(lthird($3));
3044 (errcode(ERRCODE_SYNTAX_ERROR),
3045 errmsg("improper qualified name (too many dotted names): %s",
3046 NameListToString($3)),
3047 scanner_errposition(@3)));
3055 | CREATE TYPE_P any_name AS ENUM_P '(' enum_val_list ')'
3057 CreateEnumStmt *n = makeNode(CreateEnumStmt);
3062 | CREATE TEXT_P SEARCH PARSER any_name definition
3064 DefineStmt *n = makeNode(DefineStmt);
3065 n->kind = OBJECT_TSPARSER;
3071 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
3073 DefineStmt *n = makeNode(DefineStmt);
3074 n->kind = OBJECT_TSDICTIONARY;
3080 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
3082 DefineStmt *n = makeNode(DefineStmt);
3083 n->kind = OBJECT_TSTEMPLATE;
3089 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
3091 DefineStmt *n = makeNode(DefineStmt);
3092 n->kind = OBJECT_TSCONFIGURATION;
3100 definition: '(' def_list ')' { $$ = $2; }
3103 def_list: def_elem { $$ = list_make1($1); }
3104 | def_list ',' def_elem { $$ = lappend($1, $3); }
3107 def_elem: ColLabel '=' def_arg
3109 $$ = makeDefElem($1, (Node *)$3);
3113 $$ = makeDefElem($1, NULL);
3117 /* Note: any simple identifier will be returned as a type name! */
3118 def_arg: func_type { $$ = (Node *)$1; }
3119 | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
3120 | qual_all_Op { $$ = (Node *)$1; }
3121 | NumericOnly { $$ = (Node *)$1; }
3122 | Sconst { $$ = (Node *)makeString($1); }
3125 aggr_args: '(' type_list ')' { $$ = $2; }
3126 | '(' '*' ')' { $$ = NIL; }
3129 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
3132 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
3133 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
3136 old_aggr_elem: IDENT '=' def_arg
3138 $$ = makeDefElem($1, (Node *)$3);
3142 enum_val_list: Sconst
3143 { $$ = list_make1(makeString($1)); }
3144 | enum_val_list ',' Sconst
3145 { $$ = lappend($1, makeString($3)); }
3149 /*****************************************************************************
3152 * CREATE OPERATOR CLASS ...
3153 * CREATE OPERATOR FAMILY ...
3154 * ALTER OPERATOR FAMILY ...
3155 * DROP OPERATOR CLASS ...
3156 * DROP OPERATOR FAMILY ...
3158 *****************************************************************************/
3161 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
3162 USING access_method opt_opfamily AS opclass_item_list
3164 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
3165 n->opclassname = $4;
3169 n->opfamilyname = $11;
3176 opclass_item { $$ = list_make1($1); }
3177 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
3181 OPERATOR Iconst any_operator opt_recheck
3183 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3184 n->itemtype = OPCLASS_ITEM_OPERATOR;
3190 | OPERATOR Iconst any_operator oper_argtypes opt_recheck
3192 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3193 n->itemtype = OPCLASS_ITEM_OPERATOR;
3199 | FUNCTION Iconst func_name func_args
3201 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3202 n->itemtype = OPCLASS_ITEM_FUNCTION;
3204 n->args = extractArgTypes($4);
3208 | FUNCTION Iconst '(' type_list ')' func_name func_args
3210 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3211 n->itemtype = OPCLASS_ITEM_FUNCTION;
3213 n->args = extractArgTypes($7);
3220 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3221 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
3227 opt_default: DEFAULT { $$ = TRUE; }
3228 | /*EMPTY*/ { $$ = FALSE; }
3231 opt_opfamily: FAMILY any_name { $$ = $2; }
3232 | /*EMPTY*/ { $$ = NIL; }
3235 opt_recheck: RECHECK
3238 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3239 errmsg("RECHECK is no longer supported"),
3240 errhint("Update your data type."),
3241 scanner_errposition(@1)));
3244 | /*EMPTY*/ { $$ = FALSE; }
3249 CREATE OPERATOR FAMILY any_name USING access_method
3251 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
3252 n->opfamilyname = $4;
3259 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
3261 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3262 n->opfamilyname = $4;
3268 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
3270 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3271 n->opfamilyname = $4;
3280 opclass_drop { $$ = list_make1($1); }
3281 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
3285 OPERATOR Iconst '(' type_list ')'
3287 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3288 n->itemtype = OPCLASS_ITEM_OPERATOR;
3293 | FUNCTION Iconst '(' type_list ')'
3295 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3296 n->itemtype = OPCLASS_ITEM_FUNCTION;
3305 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
3307 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3308 n->opclassname = $4;
3311 n->missing_ok = false;
3314 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
3316 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3317 n->opclassname = $6;
3320 n->missing_ok = true;
3326 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
3328 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3329 n->opfamilyname = $4;
3332 n->missing_ok = false;
3335 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
3337 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3338 n->opfamilyname = $6;
3341 n->missing_ok = true;
3347 /*****************************************************************************
3351 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
3352 * REASSIGN OWNED BY username [, username ...] TO username
3354 *****************************************************************************/
3356 DROP OWNED BY name_list opt_drop_behavior
3358 DropOwnedStmt *n = makeNode(DropOwnedStmt);
3366 REASSIGN OWNED BY name_list TO name
3368 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
3375 /*****************************************************************************
3379 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
3380 * [ RESTRICT | CASCADE ]
3382 *****************************************************************************/
3384 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
3386 DropStmt *n = makeNode(DropStmt);
3388 n->missing_ok = TRUE;
3393 | DROP drop_type any_name_list opt_drop_behavior
3395 DropStmt *n = makeNode(DropStmt);
3397 n->missing_ok = FALSE;
3405 drop_type: TABLE { $$ = OBJECT_TABLE; }
3406 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
3407 | VIEW { $$ = OBJECT_VIEW; }
3408 | INDEX { $$ = OBJECT_INDEX; }
3409 | TYPE_P { $$ = OBJECT_TYPE; }
3410 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
3411 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
3412 | SCHEMA { $$ = OBJECT_SCHEMA; }
3413 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
3414 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
3415 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
3416 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
3420 any_name { $$ = list_make1($1); }
3421 | any_name_list ',' any_name { $$ = lappend($1, $3); }
3424 any_name: ColId { $$ = list_make1(makeString($1)); }
3425 | ColId attrs { $$ = lcons(makeString($1), $2); }
3428 attrs: '.' attr_name
3429 { $$ = list_make1(makeString($2)); }
3430 | attrs '.' attr_name
3431 { $$ = lappend($1, makeString($3)); }
3435 /*****************************************************************************
3438 * truncate table relname1, relname2, ...
3440 *****************************************************************************/
3443 TRUNCATE opt_table qualified_name_list opt_restart_seqs opt_drop_behavior
3445 TruncateStmt *n = makeNode(TruncateStmt);
3447 n->restart_seqs = $4;
3454 CONTINUE_P IDENTITY_P { $$ = false; }
3455 | RESTART IDENTITY_P { $$ = true; }
3456 | /* EMPTY */ { $$ = false; }
3459 /*****************************************************************************
3461 * The COMMENT ON statement can take different forms based upon the type of
3462 * the object associated with the comment. The form of the statement is:
3464 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
3465 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
3466 * CAST | COLUMN | SCHEMA | TABLESPACE | ROLE |
3467 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
3468 * TEXT SEARCH TEMPLATE |
3469 * TEXT SEARCH CONFIGURATION ] <objname> |
3470 * AGGREGATE <aggname> (arg1, ...) |
3471 * FUNCTION <funcname> (arg1, arg2, ...) |
3472 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
3473 * TRIGGER <triggername> ON <relname> |
3474 * CONSTRAINT <constraintname> ON <relname> |
3475 * RULE <rulename> ON <relname> ]
3478 *****************************************************************************/
3481 COMMENT ON comment_type any_name IS comment_text
3483 CommentStmt *n = makeNode(CommentStmt);
3490 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
3492 CommentStmt *n = makeNode(CommentStmt);
3493 n->objtype = OBJECT_AGGREGATE;
3499 | COMMENT ON FUNCTION func_name func_args IS comment_text
3501 CommentStmt *n = makeNode(CommentStmt);
3502 n->objtype = OBJECT_FUNCTION;
3504 n->objargs = extractArgTypes($5);
3508 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
3510 CommentStmt *n = makeNode(CommentStmt);
3511 n->objtype = OBJECT_OPERATOR;
3517 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
3519 CommentStmt *n = makeNode(CommentStmt);
3520 n->objtype = OBJECT_CONSTRAINT;
3521 n->objname = lappend($6, makeString($4));
3526 | COMMENT ON RULE name ON any_name IS comment_text
3528 CommentStmt *n = makeNode(CommentStmt);
3529 n->objtype = OBJECT_RULE;
3530 n->objname = lappend($6, makeString($4));
3535 | COMMENT ON RULE name IS comment_text
3537 /* Obsolete syntax supported for awhile for compatibility */
3538 CommentStmt *n = makeNode(CommentStmt);
3539 n->objtype = OBJECT_RULE;
3540 n->objname = list_make1(makeString($4));
3545 | COMMENT ON TRIGGER name ON any_name IS comment_text
3547 CommentStmt *n = makeNode(CommentStmt);
3548 n->objtype = OBJECT_TRIGGER;
3549 n->objname = lappend($6, makeString($4));
3554 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
3556 CommentStmt *n = makeNode(CommentStmt);
3557 n->objtype = OBJECT_OPCLASS;
3559 n->objargs = list_make1(makeString($7));
3563 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
3565 CommentStmt *n = makeNode(CommentStmt);
3566 n->objtype = OBJECT_OPFAMILY;
3568 n->objargs = list_make1(makeString($7));
3572 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
3574 CommentStmt *n = makeNode(CommentStmt);
3575 n->objtype = OBJECT_LARGEOBJECT;
3576 n->objname = list_make1($5);
3581 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
3583 CommentStmt *n = makeNode(CommentStmt);
3584 n->objtype = OBJECT_CAST;
3585 n->objname = list_make1($5);
3586 n->objargs = list_make1($7);
3590 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
3592 CommentStmt *n = makeNode(CommentStmt);
3593 n->objtype = OBJECT_LANGUAGE;
3599 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
3601 CommentStmt *n = makeNode(CommentStmt);
3602 n->objtype = OBJECT_TSPARSER;
3607 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
3609 CommentStmt *n = makeNode(CommentStmt);
3610 n->objtype = OBJECT_TSDICTIONARY;
3615 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
3617 CommentStmt *n = makeNode(CommentStmt);
3618 n->objtype = OBJECT_TSTEMPLATE;
3623 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
3625 CommentStmt *n = makeNode(CommentStmt);
3626 n->objtype = OBJECT_TSCONFIGURATION;
3634 COLUMN { $$ = OBJECT_COLUMN; }
3635 | DATABASE { $$ = OBJECT_DATABASE; }
3636 | SCHEMA { $$ = OBJECT_SCHEMA; }
3637 | INDEX { $$ = OBJECT_INDEX; }
3638 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
3639 | TABLE { $$ = OBJECT_TABLE; }
3640 | DOMAIN_P { $$ = OBJECT_TYPE; }
3641 | TYPE_P { $$ = OBJECT_TYPE; }
3642 | VIEW { $$ = OBJECT_VIEW; }
3643 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
3644 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
3645 | ROLE { $$ = OBJECT_ROLE; }
3650 | NULL_P { $$ = NULL; }
3653 /*****************************************************************************
3658 *****************************************************************************/
3660 FetchStmt: FETCH fetch_direction from_in name
3662 FetchStmt *n = (FetchStmt *) $2;
3669 FetchStmt *n = makeNode(FetchStmt);
3670 n->direction = FETCH_FORWARD;
3676 | MOVE fetch_direction from_in name
3678 FetchStmt *n = (FetchStmt *) $2;
3685 FetchStmt *n = makeNode(FetchStmt);
3686 n->direction = FETCH_FORWARD;
3697 FetchStmt *n = makeNode(FetchStmt);
3698 n->direction = FETCH_FORWARD;
3704 FetchStmt *n = makeNode(FetchStmt);
3705 n->direction = FETCH_FORWARD;
3711 FetchStmt *n = makeNode(FetchStmt);
3712 n->direction = FETCH_BACKWARD;
3718 FetchStmt *n = makeNode(FetchStmt);
3719 n->direction = FETCH_ABSOLUTE;
3725 FetchStmt *n = makeNode(FetchStmt);
3726 n->direction = FETCH_ABSOLUTE;
3730 | ABSOLUTE_P SignedIconst
3732 FetchStmt *n = makeNode(FetchStmt);
3733 n->direction = FETCH_ABSOLUTE;
3737 | RELATIVE_P SignedIconst
3739 FetchStmt *n = makeNode(FetchStmt);
3740 n->direction = FETCH_RELATIVE;
3746 FetchStmt *n = makeNode(FetchStmt);
3747 n->direction = FETCH_FORWARD;
3753 FetchStmt *n = makeNode(FetchStmt);
3754 n->direction = FETCH_FORWARD;
3755 n->howMany = FETCH_ALL;
3760 FetchStmt *n = makeNode(FetchStmt);
3761 n->direction = FETCH_FORWARD;
3765 | FORWARD SignedIconst
3767 FetchStmt *n = makeNode(FetchStmt);
3768 n->direction = FETCH_FORWARD;
3774 FetchStmt *n = makeNode(FetchStmt);
3775 n->direction = FETCH_FORWARD;
3776 n->howMany = FETCH_ALL;
3781 FetchStmt *n = makeNode(FetchStmt);
3782 n->direction = FETCH_BACKWARD;
3786 | BACKWARD SignedIconst
3788 FetchStmt *n = makeNode(FetchStmt);
3789 n->direction = FETCH_BACKWARD;
3795 FetchStmt *n = makeNode(FetchStmt);
3796 n->direction = FETCH_BACKWARD;
3797 n->howMany = FETCH_ALL;
3807 /*****************************************************************************
3809 * GRANT and REVOKE statements
3811 *****************************************************************************/
3813 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
3814 opt_grant_grant_option
3816 GrantStmt *n = makeNode(GrantStmt);
3819 n->objtype = ($4)->objtype;
3820 n->objects = ($4)->objs;
3822 n->grant_option = $7;
3828 REVOKE privileges ON privilege_target
3829 FROM grantee_list opt_drop_behavior
3831 GrantStmt *n = makeNode(GrantStmt);
3832 n->is_grant = false;
3833 n->grant_option = false;
3835 n->objtype = ($4)->objtype;
3836 n->objects = ($4)->objs;
3841 | REVOKE GRANT OPTION FOR privileges ON privilege_target
3842 FROM grantee_list opt_drop_behavior
3844 GrantStmt *n = makeNode(GrantStmt);
3845 n->is_grant = false;
3846 n->grant_option = true;
3848 n->objtype = ($7)->objtype;
3849 n->objects = ($7)->objs;
3858 * A privilege list is represented as a list of strings; the validity of
3859 * the privilege names gets checked at execution. This is a bit annoying
3860 * but we have little choice because of the syntactic conflict with lists
3861 * of role names in GRANT/REVOKE. What's more, we have to call out in
3862 * the "privilege" production any reserved keywords that need to be usable
3863 * as privilege names.
3866 /* either ALL [PRIVILEGES] or a list of individual privileges */
3867 privileges: privilege_list
3875 privilege_list: privilege
3876 { $$ = list_make1(makeString($1)); }
3877 | privilege_list ',' privilege
3878 { $$ = lappend($1, makeString($3)); }
3881 privilege: SELECT { $$ = pstrdup($1); }
3882 | REFERENCES { $$ = pstrdup($1); }
3883 | CREATE { $$ = pstrdup($1); }
3884 | ColId { $$ = $1; }
3888 /* Don't bother trying to fold the first two rules into one using
3889 * opt_table. You're going to get conflicts.
3894 PrivTarget *n = makeNode(PrivTarget);
3895 n->objtype = ACL_OBJECT_RELATION;
3899 | TABLE qualified_name_list
3901 PrivTarget *n = makeNode(PrivTarget);
3902 n->objtype = ACL_OBJECT_RELATION;
3906 | SEQUENCE qualified_name_list
3908 PrivTarget *n = makeNode(PrivTarget);
3909 n->objtype = ACL_OBJECT_SEQUENCE;
3913 | FUNCTION function_with_argtypes_list
3915 PrivTarget *n = makeNode(PrivTarget);
3916 n->objtype = ACL_OBJECT_FUNCTION;
3920 | DATABASE name_list
3922 PrivTarget *n = makeNode(PrivTarget);
3923 n->objtype = ACL_OBJECT_DATABASE;
3927 | LANGUAGE name_list
3929 PrivTarget *n = makeNode(PrivTarget);
3930 n->objtype = ACL_OBJECT_LANGUAGE;
3936 PrivTarget *n = makeNode(PrivTarget);
3937 n->objtype = ACL_OBJECT_NAMESPACE;
3941 | TABLESPACE name_list
3943 PrivTarget *n = makeNode(PrivTarget);
3944 n->objtype = ACL_OBJECT_TABLESPACE;
3952 grantee { $$ = list_make1($1); }
3953 | grantee_list ',' grantee { $$ = lappend($1, $3); }
3958 PrivGrantee *n = makeNode(PrivGrantee);
3959 /* This hack lets us avoid reserving PUBLIC as a keyword*/
3960 if (strcmp($1, "public") == 0)
3968 PrivGrantee *n = makeNode(PrivGrantee);
3969 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
3970 if (strcmp($2, "public") == 0)
3979 opt_grant_grant_option:
3980 WITH GRANT OPTION { $$ = TRUE; }
3981 | /*EMPTY*/ { $$ = FALSE; }
3984 function_with_argtypes_list:
3985 function_with_argtypes { $$ = list_make1($1); }
3986 | function_with_argtypes_list ',' function_with_argtypes
3987 { $$ = lappend($1, $3); }
3990 function_with_argtypes:
3993 FuncWithArgs *n = makeNode(FuncWithArgs);
3995 n->funcargs = extractArgTypes($2);
4000 /*****************************************************************************
4002 * GRANT and REVOKE ROLE statements
4004 *****************************************************************************/
4007 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4009 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4011 n->granted_roles = $2;
4012 n->grantee_roles = $4;
4020 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4022 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4023 n->is_grant = false;
4024 n->admin_opt = false;
4025 n->granted_roles = $2;
4026 n->grantee_roles = $4;
4030 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4032 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4033 n->is_grant = false;
4034 n->admin_opt = true;
4035 n->granted_roles = $5;
4036 n->grantee_roles = $7;
4042 opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
4043 | /*EMPTY*/ { $$ = FALSE; }
4046 opt_granted_by: GRANTED BY RoleId { $$ = $3; }
4047 | /*EMPTY*/ { $$ = NULL; }
4051 /*****************************************************************************
4053 * QUERY: CREATE INDEX
4055 * Note: we can't factor CONCURRENTLY into a separate production without
4056 * making it a reserved word.
4058 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
4059 * willing to make TABLESPACE a fully reserved word.
4060 *****************************************************************************/
4062 IndexStmt: CREATE index_opt_unique INDEX index_name
4063 ON qualified_name access_method_clause '(' index_params ')'
4064 opt_definition OptTableSpace where_clause
4066 IndexStmt *n = makeNode(IndexStmt);
4068 n->concurrent = false;
4071 n->accessMethod = $7;
4072 n->indexParams = $9;
4074 n->tableSpace = $12;
4075 n->whereClause = $13;
4078 | CREATE index_opt_unique INDEX CONCURRENTLY index_name
4079 ON qualified_name access_method_clause '(' index_params ')'
4080 opt_definition OptTableSpace where_clause
4082 IndexStmt *n = makeNode(IndexStmt);
4084 n->concurrent = true;
4087 n->accessMethod = $8;
4088 n->indexParams = $10;
4090 n->tableSpace = $13;
4091 n->whereClause = $14;
4097 UNIQUE { $$ = TRUE; }
4098 | /*EMPTY*/ { $$ = FALSE; }
4101 access_method_clause:
4102 USING access_method { $$ = $2; }
4103 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
4106 index_params: index_elem { $$ = list_make1($1); }
4107 | index_params ',' index_elem { $$ = lappend($1, $3); }
4111 * Index attributes can be either simple column references, or arbitrary
4112 * expressions in parens. For backwards-compatibility reasons, we allow
4113 * an expression that's just a function call to be written without parens.
4115 index_elem: ColId opt_class opt_asc_desc opt_nulls_order
4117 $$ = makeNode(IndexElem);
4122 $$->nulls_ordering = $4;
4124 | func_expr opt_class opt_asc_desc opt_nulls_order
4126 $$ = makeNode(IndexElem);
4131 $$->nulls_ordering = $4;
4133 | '(' a_expr ')' opt_class opt_asc_desc opt_nulls_order
4135 $$ = makeNode(IndexElem);
4140 $$->nulls_ordering = $6;
4144 opt_class: any_name { $$ = $1; }
4145 | USING any_name { $$ = $2; }
4146 | /*EMPTY*/ { $$ = NIL; }
4149 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
4150 | DESC { $$ = SORTBY_DESC; }
4151 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
4154 opt_nulls_order: NULLS_FIRST { $$ = SORTBY_NULLS_FIRST; }
4155 | NULLS_LAST { $$ = SORTBY_NULLS_LAST; }
4156 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
4160 /*****************************************************************************
4163 * create [or replace] function <fname>
4164 * [(<type-1> { , <type-n>})]
4166 * as <filename or code in language as appropriate>
4167 * language <lang> [with parameters]
4169 *****************************************************************************/
4172 CREATE opt_or_replace FUNCTION func_name func_args
4173 RETURNS func_return createfunc_opt_list opt_definition
4175 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4184 | CREATE opt_or_replace FUNCTION func_name func_args
4185 RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
4187 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4190 n->parameters = mergeTableFuncParameters($5, $9);
4191 n->returnType = TableFuncTypeName($9);
4192 n->returnType->location = @7;
4194 n->withClause = $12;
4197 | CREATE opt_or_replace FUNCTION func_name func_args
4198 createfunc_opt_list opt_definition
4200 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4204 n->returnType = NULL;
4212 OR REPLACE { $$ = TRUE; }
4213 | /*EMPTY*/ { $$ = FALSE; }
4216 func_args: '(' func_args_list ')' { $$ = $2; }
4217 | '(' ')' { $$ = NIL; }
4221 func_arg { $$ = list_make1($1); }
4222 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
4226 * The style with arg_class first is SQL99 standard, but Oracle puts
4227 * param_name first; accept both since it's likely people will try both
4228 * anyway. Don't bother trying to save productions by letting arg_class
4229 * have an empty alternative ... you'll get shift/reduce conflicts.
4231 * We can catch over-specified arguments here if we want to,
4232 * but for now better to silently swallow typmod, etc.
4233 * - thomas 2000-03-22
4236 arg_class param_name func_type
4238 FunctionParameter *n = makeNode(FunctionParameter);
4244 | param_name arg_class func_type
4246 FunctionParameter *n = makeNode(FunctionParameter);
4252 | param_name func_type
4254 FunctionParameter *n = makeNode(FunctionParameter);
4257 n->mode = FUNC_PARAM_IN;
4260 | arg_class func_type
4262 FunctionParameter *n = makeNode(FunctionParameter);
4270 FunctionParameter *n = makeNode(FunctionParameter);
4273 n->mode = FUNC_PARAM_IN;
4278 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
4279 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
4280 | OUT_P { $$ = FUNC_PARAM_OUT; }
4281 | INOUT { $$ = FUNC_PARAM_INOUT; }
4282 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
4283 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
4287 * Ideally param_name should be ColId, but that causes too many conflicts.
4289 param_name: type_function_name
4295 /* We can catch over-specified results here if we want to,
4296 * but for now better to silently swallow typmod, etc.
4297 * - thomas 2000-03-22
4304 * We would like to make the %TYPE productions here be ColId attrs etc,
4305 * but that causes reduce/reduce conflicts. type_function_name
4306 * is next best choice.
4308 func_type: Typename { $$ = $1; }
4309 | type_function_name attrs '%' TYPE_P
4311 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
4312 $$->pct_type = true;
4315 | SETOF type_function_name attrs '%' TYPE_P
4317 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
4318 $$->pct_type = true;
4325 createfunc_opt_list:
4326 /* Must be at least one to prevent conflict */
4327 createfunc_opt_item { $$ = list_make1($1); }
4328 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
4332 * Options common to both CREATE FUNCTION and ALTER FUNCTION
4334 common_func_opt_item:
4335 CALLED ON NULL_P INPUT_P
4337 $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
4339 | RETURNS NULL_P ON NULL_P INPUT_P
4341 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
4345 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
4349 $$ = makeDefElem("volatility", (Node *)makeString("immutable"));
4353 $$ = makeDefElem("volatility", (Node *)makeString("stable"));
4357 $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
4359 | EXTERNAL SECURITY DEFINER
4361 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
4363 | EXTERNAL SECURITY INVOKER
4365 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
4369 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
4373 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
4377 $$ = makeDefElem("cost", (Node *)$2);
4381 $$ = makeDefElem("rows", (Node *)$2);
4385 /* we abuse the normal content of a DefElem here */
4386 $$ = makeDefElem("set", (Node *)$1);
4390 createfunc_opt_item:
4393 $$ = makeDefElem("as", (Node *)$2);
4395 | LANGUAGE ColId_or_Sconst
4397 $$ = makeDefElem("language", (Node *)makeString($2));
4399 | common_func_opt_item
4405 func_as: Sconst { $$ = list_make1(makeString($1)); }
4408 $$ = list_make2(makeString($1), makeString($3));
4413 WITH definition { $$ = $2; }
4414 | /*EMPTY*/ { $$ = NIL; }
4417 table_func_column: param_name func_type
4419 FunctionParameter *n = makeNode(FunctionParameter);
4422 n->mode = FUNC_PARAM_TABLE;
4427 table_func_column_list:
4430 $$ = list_make1($1);
4432 | table_func_column_list ',' table_func_column
4434 $$ = lappend($1, $3);
4438 /*****************************************************************************
4441 * RENAME and OWNER subcommands are already provided by the generic
4442 * ALTER infrastructure, here we just specify alterations that can
4443 * only be applied to functions.
4445 *****************************************************************************/
4447 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
4449 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
4457 /* At least one option must be specified */
4458 common_func_opt_item { $$ = list_make1($1); }
4459 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
4462 /* Ignored, merely for SQL compliance */
4469 /*****************************************************************************
4473 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
4474 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
4475 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
4477 *****************************************************************************/
4480 DROP FUNCTION func_name func_args opt_drop_behavior
4482 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4483 n->kind = OBJECT_FUNCTION;
4485 n->args = extractArgTypes($4);
4487 n->missing_ok = false;
4490 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
4492 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4493 n->kind = OBJECT_FUNCTION;
4495 n->args = extractArgTypes($6);
4497 n->missing_ok = true;
4503 DROP AGGREGATE func_name aggr_args opt_drop_behavior
4505 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4506 n->kind = OBJECT_AGGREGATE;
4510 n->missing_ok = false;
4513 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
4515 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4516 n->kind = OBJECT_AGGREGATE;
4520 n->missing_ok = true;
4526 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
4528 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4529 n->kind = OBJECT_OPERATOR;
4533 n->missing_ok = false;
4536 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
4538 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4539 n->kind = OBJECT_OPERATOR;
4543 n->missing_ok = true;
4552 (errcode(ERRCODE_SYNTAX_ERROR),
4553 errmsg("missing argument"),
4554 errhint("Use NONE to denote the missing argument of a unary operator."),
4555 scanner_errposition(@3)));
4557 | '(' Typename ',' Typename ')'
4558 { $$ = list_make2($2, $4); }
4559 | '(' NONE ',' Typename ')' /* left unary */
4560 { $$ = list_make2(NULL, $4); }
4561 | '(' Typename ',' NONE ')' /* right unary */
4562 { $$ = list_make2($2, NULL); }
4567 { $$ = list_make1(makeString($1)); }
4568 | ColId '.' any_operator
4569 { $$ = lcons(makeString($1), $3); }
4573 /*****************************************************************************
4575 * CREATE CAST / DROP CAST
4577 *****************************************************************************/
4579 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
4580 WITH FUNCTION function_with_argtypes cast_context
4582 CreateCastStmt *n = makeNode(CreateCastStmt);
4586 n->context = (CoercionContext) $11;
4590 | CREATE CAST '(' Typename AS Typename ')'
4591 WITHOUT FUNCTION cast_context
4593 CreateCastStmt *n = makeNode(CreateCastStmt);
4597 n->context = (CoercionContext) $10;
4601 | CREATE CAST '(' Typename AS Typename ')'
4602 WITH INOUT cast_context
4604 CreateCastStmt *n = makeNode(CreateCastStmt);
4608 n->context = (CoercionContext) $10;
4614 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
4615 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
4616 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
4620 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
4622 DropCastStmt *n = makeNode(DropCastStmt);
4631 opt_if_exists: IF_P EXISTS { $$ = TRUE; }
4632 | /*EMPTY*/ { $$ = FALSE; }
4636 /*****************************************************************************
4640 * REINDEX type <name> [FORCE]
4642 * FORCE no longer does anything, but we accept it for backwards compatibility
4643 *****************************************************************************/
4646 REINDEX reindex_type qualified_name opt_force
4648 ReindexStmt *n = makeNode(ReindexStmt);
4654 | REINDEX SYSTEM_P name opt_force
4656 ReindexStmt *n = makeNode(ReindexStmt);
4657 n->kind = OBJECT_DATABASE;
4660 n->do_system = true;
4664 | REINDEX DATABASE name opt_force
4666 ReindexStmt *n = makeNode(ReindexStmt);
4667 n->kind = OBJECT_DATABASE;
4670 n->do_system = true;
4677 INDEX { $$ = OBJECT_INDEX; }
4678 | TABLE { $$ = OBJECT_TABLE; }
4681 opt_force: FORCE { $$ = TRUE; }
4682 | /* EMPTY */ { $$ = FALSE; }
4686 /*****************************************************************************
4688 * ALTER THING name RENAME TO newname
4690 *****************************************************************************/
4692 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
4694 RenameStmt *n = makeNode(RenameStmt);
4695 n->renameType = OBJECT_AGGREGATE;
4701 | ALTER CONVERSION_P any_name RENAME TO name
4703 RenameStmt *n = makeNode(RenameStmt);
4704 n->renameType = OBJECT_CONVERSION;
4709 | ALTER DATABASE database_name RENAME TO database_name
4711 RenameStmt *n = makeNode(RenameStmt);
4712 n->renameType = OBJECT_DATABASE;
4717 | ALTER FUNCTION function_with_argtypes RENAME TO name
4719 RenameStmt *n = makeNode(RenameStmt);
4720 n->renameType = OBJECT_FUNCTION;
4721 n->object = $3->funcname;
4722 n->objarg = $3->funcargs;
4726 | ALTER GROUP_P RoleId RENAME TO RoleId
4728 RenameStmt *n = makeNode(RenameStmt);
4729 n->renameType = OBJECT_ROLE;
4734 | ALTER opt_procedural LANGUAGE name RENAME TO name
4736 RenameStmt *n = makeNode(RenameStmt);
4737 n->renameType = OBJECT_LANGUAGE;
4742 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
4744 RenameStmt *n = makeNode(RenameStmt);
4745 n->renameType = OBJECT_OPCLASS;
4751 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
4753 RenameStmt *n = makeNode(RenameStmt);
4754 n->renameType = OBJECT_OPFAMILY;
4760 | ALTER SCHEMA name RENAME TO name
4762 RenameStmt *n = makeNode(RenameStmt);
4763 n->renameType = OBJECT_SCHEMA;
4768 | ALTER TABLE relation_expr RENAME TO name
4770 RenameStmt *n = makeNode(RenameStmt);
4771 n->renameType = OBJECT_TABLE;
4777 | ALTER SEQUENCE relation_expr RENAME TO name
4779 RenameStmt *n = makeNode(RenameStmt);
4780 n->renameType = OBJECT_SEQUENCE;
4786 | ALTER VIEW relation_expr RENAME TO name
4788 RenameStmt *n = makeNode(RenameStmt);
4789 n->renameType = OBJECT_VIEW;
4795 | ALTER INDEX relation_expr RENAME TO name
4797 RenameStmt *n = makeNode(RenameStmt);
4798 n->renameType = OBJECT_INDEX;
4804 | ALTER TABLE relation_expr RENAME opt_column name TO name
4806 RenameStmt *n = makeNode(RenameStmt);
4807 n->renameType = OBJECT_COLUMN;
4813 | ALTER TRIGGER name ON relation_expr RENAME TO name
4815 RenameStmt *n = makeNode(RenameStmt);
4816 n->renameType = OBJECT_TRIGGER;
4822 | ALTER ROLE RoleId RENAME TO RoleId
4824 RenameStmt *n = makeNode(RenameStmt);
4825 n->renameType = OBJECT_ROLE;
4830 | ALTER USER RoleId RENAME TO RoleId
4832 RenameStmt *n = makeNode(RenameStmt);
4833 n->renameType = OBJECT_ROLE;
4838 | ALTER TABLESPACE name RENAME TO name
4840 RenameStmt *n = makeNode(RenameStmt);
4841 n->renameType = OBJECT_TABLESPACE;
4846 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
4848 RenameStmt *n = makeNode(RenameStmt);
4849 n->renameType = OBJECT_TSPARSER;
4854 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
4856 RenameStmt *n = makeNode(RenameStmt);
4857 n->renameType = OBJECT_TSDICTIONARY;
4862 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
4864 RenameStmt *n = makeNode(RenameStmt);
4865 n->renameType = OBJECT_TSTEMPLATE;
4870 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
4872 RenameStmt *n = makeNode(RenameStmt);
4873 n->renameType = OBJECT_TSCONFIGURATION;
4878 | ALTER TYPE_P any_name RENAME TO name
4880 RenameStmt *n = makeNode(RenameStmt);
4881 n->renameType = OBJECT_TYPE;
4888 opt_column: COLUMN { $$ = COLUMN; }
4889 | /*EMPTY*/ { $$ = 0; }
4892 opt_set_data: SET DATA_P { $$ = 1; }
4893 | /*EMPTY*/ { $$ = 0; }
4896 /*****************************************************************************
4898 * ALTER THING name SET SCHEMA name
4900 *****************************************************************************/
4902 AlterObjectSchemaStmt:
4903 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
4905 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4906 n->objectType = OBJECT_AGGREGATE;
4912 | ALTER DOMAIN_P any_name SET SCHEMA name
4914 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4915 n->objectType = OBJECT_DOMAIN;
4920 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
4922 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4923 n->objectType = OBJECT_FUNCTION;
4924 n->object = $3->funcname;
4925 n->objarg = $3->funcargs;
4929 | ALTER TABLE relation_expr SET SCHEMA name
4931 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4932 n->objectType = OBJECT_TABLE;
4937 | ALTER SEQUENCE relation_expr SET SCHEMA name
4939 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4940 n->objectType = OBJECT_SEQUENCE;
4945 | ALTER VIEW relation_expr SET SCHEMA name
4947 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4948 n->objectType = OBJECT_VIEW;
4953 | ALTER TYPE_P any_name SET SCHEMA name
4955 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
4956 n->objectType = OBJECT_TYPE;
4963 /*****************************************************************************
4965 * ALTER THING name OWNER TO newname
4967 *****************************************************************************/
4969 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
4971 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
4972 n->objectType = OBJECT_AGGREGATE;
4978 | ALTER CONVERSION_P any_name OWNER TO RoleId
4980 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
4981 n->objectType = OBJECT_CONVERSION;
4986 | ALTER DATABASE database_name OWNER TO RoleId
4988 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
4989 n->objectType = OBJECT_DATABASE;
4990 n->object = list_make1(makeString($3));
4994 | ALTER DOMAIN_P any_name OWNER TO RoleId
4996 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
4997 n->objectType = OBJECT_DOMAIN;
5002 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
5004 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5005 n->objectType = OBJECT_FUNCTION;
5006 n->object = $3->funcname;
5007 n->objarg = $3->funcargs;
5011 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
5013 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5014 n->objectType = OBJECT_LANGUAGE;
5015 n->object = list_make1(makeString($4));
5019 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
5021 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5022 n->objectType = OBJECT_OPERATOR;
5028 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
5030 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5031 n->objectType = OBJECT_OPCLASS;
5037 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
5039 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5040 n->objectType = OBJECT_OPFAMILY;
5046 | ALTER SCHEMA name OWNER TO RoleId
5048 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5049 n->objectType = OBJECT_SCHEMA;
5050 n->object = list_make1(makeString($3));
5054 | ALTER TYPE_P any_name OWNER TO RoleId
5056 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5057 n->objectType = OBJECT_TYPE;
5062 | ALTER TABLESPACE name OWNER TO RoleId
5064 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5065 n->objectType = OBJECT_TABLESPACE;
5066 n->object = list_make1(makeString($3));
5070 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
5072 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5073 n->objectType = OBJECT_TSDICTIONARY;
5078 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
5080 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5081 n->objectType = OBJECT_TSCONFIGURATION;
5089 /*****************************************************************************
5091 * QUERY: Define Rewrite Rule
5093 *****************************************************************************/
5095 RuleStmt: CREATE opt_or_replace RULE name AS
5096 { QueryIsRule=TRUE; }
5097 ON event TO qualified_name where_clause
5098 DO opt_instead RuleActionList
5100 RuleStmt *n = makeNode(RuleStmt);
5104 n->whereClause = $11;
5114 NOTHING { $$ = NIL; }
5115 | RuleActionStmt { $$ = list_make1($1); }
5116 | '(' RuleActionMulti ')' { $$ = $2; }
5119 /* the thrashing around here is to discard "empty" statements... */
5121 RuleActionMulti ';' RuleActionStmtOrEmpty
5123 $$ = lappend($1, $3);
5127 | RuleActionStmtOrEmpty
5129 $$ = list_make1($1);
5143 RuleActionStmtOrEmpty:
5144 RuleActionStmt { $$ = $1; }
5145 | /*EMPTY*/ { $$ = NULL; }
5148 event: SELECT { $$ = CMD_SELECT; }
5149 | UPDATE { $$ = CMD_UPDATE; }
5150 | DELETE_P { $$ = CMD_DELETE; }
5151 | INSERT { $$ = CMD_INSERT; }
5155 INSTEAD { $$ = TRUE; }
5156 | ALSO { $$ = FALSE; }
5157 | /*EMPTY*/ { $$ = FALSE; }
5162 DROP RULE name ON qualified_name opt_drop_behavior
5164 DropPropertyStmt *n = makeNode(DropPropertyStmt);
5168 n->removeType = OBJECT_RULE;
5169 n->missing_ok = false;
5172 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
5174 DropPropertyStmt *n = makeNode(DropPropertyStmt);
5178 n->removeType = OBJECT_RULE;
5179 n->missing_ok = true;
5185 /*****************************************************************************
5188 * NOTIFY <identifier> can appear both in rule bodies and
5189 * as a query-level command
5191 *****************************************************************************/
5193 NotifyStmt: NOTIFY ColId
5195 NotifyStmt *n = makeNode(NotifyStmt);
5196 n->conditionname = $2;
5201 ListenStmt: LISTEN ColId
5203 ListenStmt *n = makeNode(ListenStmt);
5204 n->conditionname = $2;
5212 UnlistenStmt *n = makeNode(UnlistenStmt);
5213 n->conditionname = $2;
5218 UnlistenStmt *n = makeNode(UnlistenStmt);
5219 n->conditionname = NULL;
5225 /*****************************************************************************
5229 * BEGIN / COMMIT / ROLLBACK
5230 * (also older versions END / ABORT)
5232 *****************************************************************************/
5235 ABORT_P opt_transaction
5237 TransactionStmt *n = makeNode(TransactionStmt);
5238 n->kind = TRANS_STMT_ROLLBACK;
5242 | BEGIN_P opt_transaction transaction_mode_list_or_empty
5244 TransactionStmt *n = makeNode(TransactionStmt);
5245 n->kind = TRANS_STMT_BEGIN;
5249 | START TRANSACTION transaction_mode_list_or_empty
5251 TransactionStmt *n = makeNode(TransactionStmt);
5252 n->kind = TRANS_STMT_START;
5256 | COMMIT opt_transaction
5258 TransactionStmt *n = makeNode(TransactionStmt);
5259 n->kind = TRANS_STMT_COMMIT;
5263 | END_P opt_transaction
5265 TransactionStmt *n = makeNode(TransactionStmt);
5266 n->kind = TRANS_STMT_COMMIT;
5270 | ROLLBACK opt_transaction
5272 TransactionStmt *n = makeNode(TransactionStmt);
5273 n->kind = TRANS_STMT_ROLLBACK;
5279 TransactionStmt *n = makeNode(TransactionStmt);
5280 n->kind = TRANS_STMT_SAVEPOINT;
5281 n->options = list_make1(makeDefElem("savepoint_name",
5282 (Node *)makeString($2)));
5285 | RELEASE SAVEPOINT ColId
5287 TransactionStmt *n = makeNode(TransactionStmt);
5288 n->kind = TRANS_STMT_RELEASE;
5289 n->options = list_make1(makeDefElem("savepoint_name",
5290 (Node *)makeString($3)));
5295 TransactionStmt *n = makeNode(TransactionStmt);
5296 n->kind = TRANS_STMT_RELEASE;
5297 n->options = list_make1(makeDefElem("savepoint_name",
5298 (Node *)makeString($2)));
5301 | ROLLBACK opt_transaction TO SAVEPOINT ColId
5303 TransactionStmt *n = makeNode(TransactionStmt);
5304 n->kind = TRANS_STMT_ROLLBACK_TO;
5305 n->options = list_make1(makeDefElem("savepoint_name",
5306 (Node *)makeString($5)));
5309 | ROLLBACK opt_transaction TO ColId
5311 TransactionStmt *n = makeNode(TransactionStmt);
5312 n->kind = TRANS_STMT_ROLLBACK_TO;
5313 n->options = list_make1(makeDefElem("savepoint_name",
5314 (Node *)makeString($4)));
5317 | PREPARE TRANSACTION Sconst
5319 TransactionStmt *n = makeNode(TransactionStmt);
5320 n->kind = TRANS_STMT_PREPARE;
5324 | COMMIT PREPARED Sconst
5326 TransactionStmt *n = makeNode(TransactionStmt);
5327 n->kind = TRANS_STMT_COMMIT_PREPARED;
5331 | ROLLBACK PREPARED Sconst
5333 TransactionStmt *n = makeNode(TransactionStmt);
5334 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
5340 opt_transaction: WORK {}
5345 transaction_mode_item:
5346 ISOLATION LEVEL iso_level
5347 { $$ = makeDefElem("transaction_isolation",
5348 makeStringConst($3, @3)); }
5350 { $$ = makeDefElem("transaction_read_only",
5351 makeIntConst(TRUE, @1)); }
5353 { $$ = makeDefElem("transaction_read_only",
5354 makeIntConst(FALSE, @1)); }
5357 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
5358 transaction_mode_list:
5359 transaction_mode_item
5360 { $$ = list_make1($1); }
5361 | transaction_mode_list ',' transaction_mode_item
5362 { $$ = lappend($1, $3); }
5363 | transaction_mode_list transaction_mode_item
5364 { $$ = lappend($1, $2); }
5367 transaction_mode_list_or_empty:
5368 transaction_mode_list
5374 /*****************************************************************************
5377 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
5378 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
5380 *****************************************************************************/
5382 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
5383 AS SelectStmt opt_check_option
5385 ViewStmt *n = makeNode(ViewStmt);
5387 n->view->istemp = $2;
5393 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
5394 AS SelectStmt opt_check_option
5396 ViewStmt *n = makeNode(ViewStmt);
5398 n->view->istemp = $4;
5410 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5411 errmsg("WITH CHECK OPTION is not implemented")));
5413 | WITH CASCADED CHECK OPTION
5416 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5417 errmsg("WITH CHECK OPTION is not implemented")));
5419 | WITH LOCAL CHECK OPTION
5422 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5423 errmsg("WITH CHECK OPTION is not implemented")));
5425 | /* EMPTY */ { $$ = NIL; }
5428 /*****************************************************************************
5433 *****************************************************************************/
5435 LoadStmt: LOAD file_name
5437 LoadStmt *n = makeNode(LoadStmt);
5444 /*****************************************************************************
5448 *****************************************************************************/
5451 CREATE DATABASE database_name opt_with createdb_opt_list
5453 CreatedbStmt *n = makeNode(CreatedbStmt);
5461 createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
5462 | /* EMPTY */ { $$ = NIL; }
5466 TABLESPACE opt_equal name
5468 $$ = makeDefElem("tablespace", (Node *)makeString($3));
5470 | TABLESPACE opt_equal DEFAULT
5472 $$ = makeDefElem("tablespace", NULL);
5474 | LOCATION opt_equal Sconst
5476 $$ = makeDefElem("location", (Node *)makeString($3));
5478 | LOCATION opt_equal DEFAULT
5480 $$ = makeDefElem("location", NULL);
5482 | TEMPLATE opt_equal name
5484 $$ = makeDefElem("template", (Node *)makeString($3));
5486 | TEMPLATE opt_equal DEFAULT
5488 $$ = makeDefElem("template", NULL);
5490 | ENCODING opt_equal Sconst
5492 $$ = makeDefElem("encoding", (Node *)makeString($3));
5494 | ENCODING opt_equal Iconst
5496 $$ = makeDefElem("encoding", (Node *)makeInteger($3));
5498 | ENCODING opt_equal DEFAULT
5500 $$ = makeDefElem("encoding", NULL);
5502 | COLLATE opt_equal Sconst
5504 $$ = makeDefElem("collate", (Node *)makeString($3));
5506 | COLLATE opt_equal DEFAULT
5508 $$ = makeDefElem("collate", NULL);
5510 | CTYPE opt_equal Sconst
5512 $$ = makeDefElem("ctype", (Node *)makeString($3));
5514 | CTYPE opt_equal DEFAULT
5516 $$ = makeDefElem("ctype", NULL);
5518 | CONNECTION LIMIT opt_equal SignedIconst
5520 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
5522 | OWNER opt_equal name
5524 $$ = makeDefElem("owner", (Node *)makeString($3));
5526 | OWNER opt_equal DEFAULT
5528 $$ = makeDefElem("owner", NULL);
5533 * Though the equals sign doesn't match other WITH options, pg_dump uses
5534 * equals for backward compatibility, and it doesn't seem worth removing it.
5541 /*****************************************************************************
5545 *****************************************************************************/
5548 ALTER DATABASE database_name opt_with alterdb_opt_list
5550 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
5555 | ALTER DATABASE database_name SET TABLESPACE name
5557 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
5559 n->options = list_make1(makeDefElem("tablespace",
5560 (Node *)makeString($6)));
5565 AlterDatabaseSetStmt:
5566 ALTER DATABASE database_name SetResetClause
5568 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
5577 alterdb_opt_list alterdb_opt_item { $$ = lappend($1, $2); }
5578 | /* EMPTY */ { $$ = NIL; }
5582 CONNECTION LIMIT opt_equal SignedIconst
5584 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
5589 /*****************************************************************************
5591 * DROP DATABASE [ IF EXISTS ]
5593 * This is implicitly CASCADE, no need for drop behavior
5594 *****************************************************************************/
5596 DropdbStmt: DROP DATABASE database_name
5598 DropdbStmt *n = makeNode(DropdbStmt);
5600 n->missing_ok = FALSE;
5603 | DROP DATABASE IF_P EXISTS database_name
5605 DropdbStmt *n = makeNode(DropdbStmt);
5607 n->missing_ok = TRUE;
5613 /*****************************************************************************
5615 * Manipulate a domain
5617 *****************************************************************************/
5620 CREATE DOMAIN_P any_name opt_as Typename ColQualList
5622 CreateDomainStmt *n = makeNode(CreateDomainStmt);
5625 n->constraints = $6;
5631 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
5632 ALTER DOMAIN_P any_name alter_column_default
5634 AlterDomainStmt *n = makeNode(AlterDomainStmt);
5640 /* ALTER DOMAIN <domain> DROP NOT NULL */
5641 | ALTER DOMAIN_P any_name DROP NOT NULL_P
5643 AlterDomainStmt *n = makeNode(AlterDomainStmt);
5648 /* ALTER DOMAIN <domain> SET NOT NULL */
5649 | ALTER DOMAIN_P any_name SET NOT NULL_P
5651 AlterDomainStmt *n = makeNode(AlterDomainStmt);
5656 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
5657 | ALTER DOMAIN_P any_name ADD_P TableConstraint
5659 AlterDomainStmt *n = makeNode(AlterDomainStmt);
5665 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
5666 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
5668 AlterDomainStmt *n = makeNode(AlterDomainStmt);
5682 /*****************************************************************************
5684 * Manipulate a text search dictionary or configuration
5686 *****************************************************************************/
5688 AlterTSDictionaryStmt:
5689 ALTER TEXT_P SEARCH DICTIONARY any_name definition
5691 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
5698 AlterTSConfigurationStmt:
5699 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
5701 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5705 n->override = false;
5709 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
5711 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5719 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
5721 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5724 n->dicts = list_make2($9,$11);
5725 n->override = false;
5729 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
5731 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5734 n->dicts = list_make2($11,$13);
5735 n->override = false;
5739 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
5741 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5744 n->missing_ok = false;
5747 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
5749 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5752 n->missing_ok = true;
5758 /*****************************************************************************
5760 * Manipulate a conversion
5762 * CREATE [DEFAULT] CONVERSION <conversion_name>
5763 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
5765 *****************************************************************************/
5767 CreateConversionStmt:
5768 CREATE opt_default CONVERSION_P any_name FOR Sconst
5769 TO Sconst FROM any_name
5771 CreateConversionStmt *n = makeNode(CreateConversionStmt);
5772 n->conversion_name = $4;
5773 n->for_encoding_name = $6;
5774 n->to_encoding_name = $8;
5781 /*****************************************************************************
5784 * CLUSTER <qualified_name> [ USING <index_name> ]
5786 * CLUSTER <index_name> ON <qualified_name> (for pre-8.3)
5788 *****************************************************************************/
5791 CLUSTER qualified_name cluster_index_specification
5793 ClusterStmt *n = makeNode(ClusterStmt);
5800 ClusterStmt *n = makeNode(ClusterStmt);
5802 n->indexname = NULL;
5805 /* kept for pre-8.3 compatibility */
5806 | CLUSTER index_name ON qualified_name
5808 ClusterStmt *n = makeNode(ClusterStmt);
5815 cluster_index_specification:
5816 USING index_name { $$ = $2; }
5817 | /*EMPTY*/ { $$ = NULL; }
5821 /*****************************************************************************
5827 *****************************************************************************/
5829 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
5831 VacuumStmt *n = makeNode(VacuumStmt);
5835 n->freeze_min_age = $3 ? 0 : -1;
5841 | VACUUM opt_full opt_freeze opt_verbose qualified_name
5843 VacuumStmt *n = makeNode(VacuumStmt);
5847 n->freeze_min_age = $3 ? 0 : -1;
5853 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
5855 VacuumStmt *n = (VacuumStmt *) $5;
5858 n->freeze_min_age = $3 ? 0 : -1;
5865 analyze_keyword opt_verbose
5867 VacuumStmt *n = makeNode(VacuumStmt);
5871 n->freeze_min_age = -1;
5877 | analyze_keyword opt_verbose qualified_name opt_name_list
5879 VacuumStmt *n = makeNode(VacuumStmt);
5883 n->freeze_min_age = -1;
5893 | ANALYSE /* British */ {}
5897 VERBOSE { $$ = TRUE; }
5898 | /*EMPTY*/ { $$ = FALSE; }
5901 opt_full: FULL { $$ = TRUE; }
5902 | /*EMPTY*/ { $$ = FALSE; }
5905 opt_freeze: FREEZE { $$ = TRUE; }
5906 | /*EMPTY*/ { $$ = FALSE; }
5910 '(' name_list ')' { $$ = $2; }
5911 | /*EMPTY*/ { $$ = NIL; }
5915 /*****************************************************************************
5918 * EXPLAIN [ANALYZE] [VERBOSE] query
5920 *****************************************************************************/
5922 ExplainStmt: EXPLAIN opt_analyze opt_verbose ExplainableStmt
5924 ExplainStmt *n = makeNode(ExplainStmt);
5939 | ExecuteStmt /* by default all are $$=$1 */
5943 analyze_keyword { $$ = TRUE; }
5944 | /* EMPTY */ { $$ = FALSE; }
5947 /*****************************************************************************
5950 * PREPARE <plan_name> [(args, ...)] AS <query>
5952 *****************************************************************************/
5954 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
5956 PrepareStmt *n = makeNode(PrepareStmt);
5964 prep_type_clause: '(' type_list ')' { $$ = $2; }
5965 | /* EMPTY */ { $$ = NIL; }
5972 | DeleteStmt /* by default all are $$=$1 */
5975 /*****************************************************************************
5977 * EXECUTE <plan_name> [(params, ...)]
5978 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
5980 *****************************************************************************/
5982 ExecuteStmt: EXECUTE name execute_param_clause
5984 ExecuteStmt *n = makeNode(ExecuteStmt);
5990 | CREATE OptTemp TABLE create_as_target AS
5991 EXECUTE name execute_param_clause
5993 ExecuteStmt *n = makeNode(ExecuteStmt);
5996 $4->rel->istemp = $2;
6000 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6001 errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
6002 /* ... because it's not implemented, but it could be */
6007 execute_param_clause: '(' expr_list ')' { $$ = $2; }
6008 | /* EMPTY */ { $$ = NIL; }
6011 /*****************************************************************************
6014 * DEALLOCATE [PREPARE] <plan_name>
6016 *****************************************************************************/
6018 DeallocateStmt: DEALLOCATE name
6020 DeallocateStmt *n = makeNode(DeallocateStmt);
6024 | DEALLOCATE PREPARE name
6026 DeallocateStmt *n = makeNode(DeallocateStmt);
6032 DeallocateStmt *n = makeNode(DeallocateStmt);
6036 | DEALLOCATE PREPARE ALL
6038 DeallocateStmt *n = makeNode(DeallocateStmt);
6044 /*****************************************************************************
6049 *****************************************************************************/
6052 INSERT INTO qualified_name insert_rest returning_clause
6055 $4->returningList = $5;
6063 $$ = makeNode(InsertStmt);
6065 $$->selectStmt = $1;
6067 | '(' insert_column_list ')' SelectStmt
6069 $$ = makeNode(InsertStmt);
6071 $$->selectStmt = $4;
6075 $$ = makeNode(InsertStmt);
6077 $$->selectStmt = NULL;
6083 { $$ = list_make1($1); }
6084 | insert_column_list ',' insert_column_item
6085 { $$ = lappend($1, $3); }
6089 ColId opt_indirection
6091 $$ = makeNode(ResTarget);
6093 $$->indirection = check_indirection($2);
6100 RETURNING target_list { $$ = $2; }
6101 | /* EMPTY */ { $$ = NIL; }
6105 /*****************************************************************************
6110 *****************************************************************************/
6112 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
6113 using_clause where_or_current_clause returning_clause
6115 DeleteStmt *n = makeNode(DeleteStmt);
6117 n->usingClause = $4;
6118 n->whereClause = $5;
6119 n->returningList = $6;
6125 USING from_list { $$ = $2; }
6126 | /*EMPTY*/ { $$ = NIL; }
6129 LockStmt: LOCK_P opt_table qualified_name_list opt_lock opt_nowait
6131 LockStmt *n = makeNode(LockStmt);
6140 opt_lock: IN_P lock_type MODE { $$ = $2; }
6141 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
6144 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
6145 | ROW SHARE { $$ = RowShareLock; }
6146 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
6147 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
6148 | SHARE { $$ = ShareLock; }
6149 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
6150 | EXCLUSIVE { $$ = ExclusiveLock; }
6151 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
6154 opt_nowait: NOWAIT { $$ = TRUE; }
6155 | /*EMPTY*/ { $$ = FALSE; }
6159 /*****************************************************************************
6162 * UpdateStmt (UPDATE)
6164 *****************************************************************************/
6166 UpdateStmt: UPDATE relation_expr_opt_alias
6169 where_or_current_clause
6172 UpdateStmt *n = makeNode(UpdateStmt);
6176 n->whereClause = $6;
6177 n->returningList = $7;
6183 set_clause { $$ = $1; }
6184 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
6188 single_set_clause { $$ = list_make1($1); }
6189 | multiple_set_clause { $$ = $1; }
6193 set_target '=' ctext_expr
6196 $$->val = (Node *) $3;
6200 multiple_set_clause:
6201 '(' set_target_list ')' '=' ctext_row
6207 * Break the ctext_row apart, merge individual expressions
6208 * into the destination ResTargets. XXX this approach
6209 * cannot work for general row expressions as sources.
6211 if (list_length($2) != list_length($5))
6213 (errcode(ERRCODE_SYNTAX_ERROR),
6214 errmsg("number of columns does not match number of values"),
6215 scanner_errposition(@1)));
6216 forboth(col_cell, $2, val_cell, $5)
6218 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
6219 Node *res_val = (Node *) lfirst(val_cell);
6221 res_col->val = res_val;
6229 ColId opt_indirection
6231 $$ = makeNode(ResTarget);
6233 $$->indirection = check_indirection($2);
6234 $$->val = NULL; /* upper production sets this */
6240 set_target { $$ = list_make1($1); }
6241 | set_target_list ',' set_target { $$ = lappend($1,$3); }
6245 /*****************************************************************************
6250 *****************************************************************************/
6251 DeclareCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR SelectStmt
6253 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
6255 /* currently we always set FAST_PLAN option */
6256 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
6262 cursor_options: /*EMPTY*/ { $$ = 0; }
6263 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
6264 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
6265 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
6266 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
6269 opt_hold: /* EMPTY */ { $$ = 0; }
6270 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
6271 | WITHOUT HOLD { $$ = 0; }
6274 /*****************************************************************************
6279 *****************************************************************************/
6281 /* A complete SELECT statement looks like this.
6283 * The rule returns either a single SelectStmt node or a tree of them,
6284 * representing a set-operation tree.
6286 * There is an ambiguity when a sub-SELECT is within an a_expr and there
6287 * are excess parentheses: do the parentheses belong to the sub-SELECT or
6288 * to the surrounding a_expr? We don't really care, but yacc wants to know.
6289 * To resolve the ambiguity, we are careful to define the grammar so that
6290 * the decision is staved off as long as possible: as long as we can keep
6291 * absorbing parentheses into the sub-SELECT, we will do so, and only when
6292 * it's no longer possible to do that will we decide that parens belong to
6293 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
6294 * parentheses are treated as part of the sub-select. The necessity of doing
6295 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
6296 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
6297 * SELECT viewpoint when we see the UNION.
6299 * This approach is implemented by defining a nonterminal select_with_parens,
6300 * which represents a SELECT with at least one outer layer of parentheses,
6301 * and being careful to use select_with_parens, never '(' SelectStmt ')',
6302 * in the expression grammar. We will then have shift-reduce conflicts
6303 * which we can resolve in favor of always treating '(' <select> ')' as
6304 * a select_with_parens. To resolve the conflicts, the productions that
6305 * conflict with the select_with_parens productions are manually given
6306 * precedences lower than the precedence of ')', thereby ensuring that we
6307 * shift ')' (and then reduce to select_with_parens) rather than trying to
6308 * reduce the inner <select> nonterminal to something else. We use UMINUS
6309 * precedence for this, which is a fairly arbitrary choice.
6311 * To be able to define select_with_parens itself without ambiguity, we need
6312 * a nonterminal select_no_parens that represents a SELECT structure with no
6313 * outermost parentheses. This is a little bit tedious, but it works.
6315 * In non-expression contexts, we use SelectStmt which can represent a SELECT
6316 * with or without outer parentheses.
6319 SelectStmt: select_no_parens %prec UMINUS
6320 | select_with_parens %prec UMINUS
6324 '(' select_no_parens ')' { $$ = $2; }
6325 | '(' select_with_parens ')' { $$ = $2; }
6329 * This rule parses the equivalent of the standard's <query expression>.
6330 * The duplicative productions are annoying, but hard to get rid of without
6331 * creating shift/reduce conflicts.
6333 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
6334 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
6335 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
6339 simple_select { $$ = $1; }
6340 | select_clause sort_clause
6342 insertSelectOptions((SelectStmt *) $1, $2, NIL,
6346 | select_clause opt_sort_clause for_locking_clause opt_select_limit
6348 insertSelectOptions((SelectStmt *) $1, $2, $3,
6349 list_nth($4, 0), list_nth($4, 1),
6353 | select_clause opt_sort_clause select_limit opt_for_locking_clause
6355 insertSelectOptions((SelectStmt *) $1, $2, $4,
6356 list_nth($3, 0), list_nth($3, 1),
6360 | with_clause simple_select
6362 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
6367 | with_clause select_clause sort_clause
6369 insertSelectOptions((SelectStmt *) $2, $3, NIL,
6374 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
6376 insertSelectOptions((SelectStmt *) $2, $3, $4,
6377 list_nth($5, 0), list_nth($5, 1),
6381 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
6383 insertSelectOptions((SelectStmt *) $2, $3, $5,
6384 list_nth($4, 0), list_nth($4, 1),
6391 simple_select { $$ = $1; }
6392 | select_with_parens { $$ = $1; }
6396 * This rule parses SELECT statements that can appear within set operations,
6397 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
6398 * the ordering of the set operations. Without '(' and ')' we want the
6399 * operations to be ordered per the precedence specs at the head of this file.
6401 * As with select_no_parens, simple_select cannot have outer parentheses,
6402 * but can have parenthesized subclauses.
6404 * Note that sort clauses cannot be included at this level --- SQL92 requires
6405 * SELECT foo UNION SELECT bar ORDER BY baz
6407 * (SELECT foo UNION SELECT bar) ORDER BY baz
6409 * SELECT foo UNION (SELECT bar ORDER BY baz)
6410 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
6411 * described as part of the select_no_parens production, not simple_select.
6412 * This does not limit functionality, because you can reintroduce these
6413 * clauses inside parentheses.
6415 * NOTE: only the leftmost component SelectStmt should have INTO.
6416 * However, this is not checked by the grammar; parse analysis must check it.
6419 SELECT opt_distinct target_list
6420 into_clause from_clause where_clause
6421 group_clause having_clause
6423 SelectStmt *n = makeNode(SelectStmt);
6424 n->distinctClause = $2;
6428 n->whereClause = $6;
6429 n->groupClause = $7;
6430 n->havingClause = $8;
6433 | values_clause { $$ = $1; }
6434 | select_clause UNION opt_all select_clause
6436 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
6438 | select_clause INTERSECT opt_all select_clause
6440 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
6442 | select_clause EXCEPT opt_all select_clause
6444 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
6449 * SQL standard WITH clause looks like:
6451 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
6452 * AS (query) [ SEARCH or CYCLE clause ]
6454 * We don't currently support the SEARCH or CYCLE clause.
6459 $$ = makeNode(WithClause);
6461 $$->recursive = false;
6464 | WITH RECURSIVE cte_list
6466 $$ = makeNode(WithClause);
6468 $$->recursive = true;
6474 common_table_expr { $$ = list_make1($1); }
6475 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
6478 common_table_expr: name opt_name_list AS select_with_parens
6480 CommonTableExpr *n = makeNode(CommonTableExpr);
6482 n->aliascolnames = $2;
6490 INTO OptTempTableName
6492 $$ = makeNode(IntoClause);
6496 $$->onCommit = ONCOMMIT_NOOP;
6497 $$->tableSpaceName = NULL;
6504 * Redundancy here is needed to avoid shift/reduce conflicts,
6505 * since TEMP is not a reserved word. See also OptTemp.
6508 TEMPORARY opt_table qualified_name
6513 | TEMP opt_table qualified_name
6518 | LOCAL TEMPORARY opt_table qualified_name
6523 | LOCAL TEMP opt_table qualified_name
6528 | GLOBAL TEMPORARY opt_table qualified_name
6533 | GLOBAL TEMP opt_table qualified_name
6538 | TABLE qualified_name
6554 opt_all: ALL { $$ = TRUE; }
6555 | DISTINCT { $$ = FALSE; }
6556 | /*EMPTY*/ { $$ = FALSE; }
6559 /* We use (NIL) as a placeholder to indicate that all target expressions
6560 * should be placed in the DISTINCT list during parsetree analysis.
6563 DISTINCT { $$ = list_make1(NIL); }
6564 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
6566 | /*EMPTY*/ { $$ = NIL; }
6570 sort_clause { $$ = $1;}
6571 | /*EMPTY*/ { $$ = NIL; }
6575 ORDER BY sortby_list { $$ = $3; }
6579 sortby { $$ = list_make1($1); }
6580 | sortby_list ',' sortby { $$ = lappend($1, $3); }
6583 sortby: a_expr USING qual_all_Op opt_nulls_order
6585 $$ = makeNode(SortBy);
6587 $$->sortby_dir = SORTBY_USING;
6588 $$->sortby_nulls = $4;
6592 | a_expr opt_asc_desc opt_nulls_order
6594 $$ = makeNode(SortBy);
6596 $$->sortby_dir = $2;
6597 $$->sortby_nulls = $3;
6599 $$->location = -1; /* no operator */
6605 LIMIT select_limit_value OFFSET select_offset_value
6606 { $$ = list_make2($4, $2); }
6607 | OFFSET select_offset_value LIMIT select_limit_value
6608 { $$ = list_make2($2, $4); }
6609 | LIMIT select_limit_value
6610 { $$ = list_make2(NULL, $2); }
6611 | OFFSET select_offset_value
6612 { $$ = list_make2($2, NULL); }
6613 | LIMIT select_limit_value ',' select_offset_value
6615 /* Disabled because it was too confusing, bjm 2002-02-18 */
6617 (errcode(ERRCODE_SYNTAX_ERROR),
6618 errmsg("LIMIT #,# syntax is not supported"),
6619 errhint("Use separate LIMIT and OFFSET clauses."),
6620 scanner_errposition(@1)));
6622 /* SQL:2008 syntax variants */
6623 | OFFSET select_offset_value2 row_or_rows
6624 { $$ = list_make2($2, NULL); }
6625 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
6626 { $$ = list_make2(NULL, $3); }
6627 | OFFSET select_offset_value2 row_or_rows FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
6628 { $$ = list_make2($2, $6); }
6632 select_limit { $$ = $1; }
6634 { $$ = list_make2(NULL,NULL); }
6641 /* LIMIT ALL is represented as a NULL constant */
6642 $$ = makeNullAConst(@1);
6647 * Allowing full expressions without parentheses causes various parsing
6648 * problems with the trailing ROW/ROWS key words. SQL only calls for
6649 * constants, so we allow the rest only with parentheses.
6651 opt_select_fetch_first_value:
6652 SignedIconst { $$ = makeIntConst($1, @1); }
6653 | '(' a_expr ')' { $$ = $2; }
6654 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
6657 select_offset_value:
6662 * Again, the trailing ROW/ROWS in this case prevent the full expression
6663 * syntax. c_expr is the best we can do.
6665 select_offset_value2:
6682 GROUP_P BY expr_list { $$ = $3; }
6683 | /*EMPTY*/ { $$ = NIL; }
6687 HAVING a_expr { $$ = $2; }
6688 | /*EMPTY*/ { $$ = NULL; }
6692 for_locking_items { $$ = $1; }
6693 | FOR READ ONLY { $$ = NIL; }
6696 opt_for_locking_clause:
6697 for_locking_clause { $$ = $1; }
6698 | /* EMPTY */ { $$ = NIL; }
6702 for_locking_item { $$ = list_make1($1); }
6703 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
6707 FOR UPDATE locked_rels_list opt_nowait
6709 LockingClause *n = makeNode(LockingClause);
6711 n->forUpdate = TRUE;
6715 | FOR SHARE locked_rels_list opt_nowait
6717 LockingClause *n = makeNode(LockingClause);
6719 n->forUpdate = FALSE;
6726 OF qualified_name_list { $$ = $2; }
6727 | /* EMPTY */ { $$ = NIL; }
6734 SelectStmt *n = makeNode(SelectStmt);
6735 n->valuesLists = list_make1($2);
6738 | values_clause ',' ctext_row
6740 SelectStmt *n = (SelectStmt *) $1;
6741 n->valuesLists = lappend(n->valuesLists, $3);
6747 /*****************************************************************************
6749 * clauses common to all Optimizable Stmts:
6750 * from_clause - allow list of both JOIN expressions and table names
6751 * where_clause - qualifications for joins or restrictions
6753 *****************************************************************************/
6756 FROM from_list { $$ = $2; }
6757 | /*EMPTY*/ { $$ = NIL; }
6761 table_ref { $$ = list_make1($1); }
6762 | from_list ',' table_ref { $$ = lappend($1, $3); }
6766 * table_ref is where an alias clause can be attached. Note we cannot make
6767 * alias_clause have an empty production because that causes parse conflicts
6768 * between table_ref := '(' joined_table ')' alias_clause
6769 * and joined_table := '(' joined_table ')'. So, we must have the
6770 * redundant-looking productions here instead.
6772 table_ref: relation_expr
6776 | relation_expr alias_clause
6783 RangeFunction *n = makeNode(RangeFunction);
6784 n->funccallnode = $1;
6785 n->coldeflist = NIL;
6788 | func_table alias_clause
6790 RangeFunction *n = makeNode(RangeFunction);
6791 n->funccallnode = $1;
6793 n->coldeflist = NIL;
6796 | func_table AS '(' TableFuncElementList ')'
6798 RangeFunction *n = makeNode(RangeFunction);
6799 n->funccallnode = $1;
6803 | func_table AS ColId '(' TableFuncElementList ')'
6805 RangeFunction *n = makeNode(RangeFunction);
6806 Alias *a = makeNode(Alias);
6807 n->funccallnode = $1;
6813 | func_table ColId '(' TableFuncElementList ')'
6815 RangeFunction *n = makeNode(RangeFunction);
6816 Alias *a = makeNode(Alias);
6817 n->funccallnode = $1;
6823 | select_with_parens
6826 * The SQL spec does not permit a subselect
6827 * (<derived_table>) without an alias clause,
6828 * so we don't either. This avoids the problem
6829 * of needing to invent a unique refname for it.
6830 * That could be surmounted if there's sufficient
6831 * popular demand, but for now let's just implement
6832 * the spec and see if anyone complains.
6833 * However, it does seem like a good idea to emit
6834 * an error message that's better than "syntax error".
6836 if (IsA($1, SelectStmt) &&
6837 ((SelectStmt *) $1)->valuesLists)
6839 (errcode(ERRCODE_SYNTAX_ERROR),
6840 errmsg("VALUES in FROM must have an alias"),
6841 errhint("For example, FROM (VALUES ...) [AS] foo."),
6842 scanner_errposition(@1)));
6845 (errcode(ERRCODE_SYNTAX_ERROR),
6846 errmsg("subquery in FROM must have an alias"),
6847 errhint("For example, FROM (SELECT ...) [AS] foo."),
6848 scanner_errposition(@1)));
6851 | select_with_parens alias_clause
6853 RangeSubselect *n = makeNode(RangeSubselect);
6862 | '(' joined_table ')' alias_clause
6871 * It may seem silly to separate joined_table from table_ref, but there is
6872 * method in SQL92's madness: if you don't do it this way you get reduce-
6873 * reduce conflicts, because it's not clear to the parser generator whether
6874 * to expect alias_clause after ')' or not. For the same reason we must
6875 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
6876 * join_type to expand to empty; if we try it, the parser generator can't
6877 * figure out when to reduce an empty join_type right after table_ref.
6879 * Note that a CROSS JOIN is the same as an unqualified
6880 * INNER JOIN, and an INNER JOIN/ON has the same shape
6881 * but a qualification expression to limit membership.
6882 * A NATURAL JOIN implicitly matches column names between
6883 * tables and the shape is determined by which columns are
6884 * in common. We'll collect columns during the later transformations.
6888 '(' joined_table ')'
6892 | table_ref CROSS JOIN table_ref
6894 /* CROSS JOIN is same as unqualified inner join */
6895 JoinExpr *n = makeNode(JoinExpr);
6896 n->jointype = JOIN_INNER;
6897 n->isNatural = FALSE;
6904 | table_ref join_type JOIN table_ref join_qual
6906 JoinExpr *n = makeNode(JoinExpr);
6908 n->isNatural = FALSE;
6911 if ($5 != NULL && IsA($5, List))
6912 n->using = (List *) $5; /* USING clause */
6914 n->quals = $5; /* ON clause */
6917 | table_ref JOIN table_ref join_qual
6919 /* letting join_type reduce to empty doesn't work */
6920 JoinExpr *n = makeNode(JoinExpr);
6921 n->jointype = JOIN_INNER;
6922 n->isNatural = FALSE;
6925 if ($4 != NULL && IsA($4, List))
6926 n->using = (List *) $4; /* USING clause */
6928 n->quals = $4; /* ON clause */
6931 | table_ref NATURAL join_type JOIN table_ref
6933 JoinExpr *n = makeNode(JoinExpr);
6935 n->isNatural = TRUE;
6938 n->using = NIL; /* figure out which columns later... */
6939 n->quals = NULL; /* fill later */
6942 | table_ref NATURAL JOIN table_ref
6944 /* letting join_type reduce to empty doesn't work */
6945 JoinExpr *n = makeNode(JoinExpr);
6946 n->jointype = JOIN_INNER;
6947 n->isNatural = TRUE;
6950 n->using = NIL; /* figure out which columns later... */
6951 n->quals = NULL; /* fill later */
6957 AS ColId '(' name_list ')'
6959 $$ = makeNode(Alias);
6965 $$ = makeNode(Alias);
6968 | ColId '(' name_list ')'
6970 $$ = makeNode(Alias);
6976 $$ = makeNode(Alias);
6981 join_type: FULL join_outer { $$ = JOIN_FULL; }
6982 | LEFT join_outer { $$ = JOIN_LEFT; }
6983 | RIGHT join_outer { $$ = JOIN_RIGHT; }
6984 | INNER_P { $$ = JOIN_INNER; }
6987 /* OUTER is just noise... */
6988 join_outer: OUTER_P { $$ = NULL; }
6989 | /*EMPTY*/ { $$ = NULL; }
6992 /* JOIN qualification clauses
6993 * Possibilities are:
6994 * USING ( column list ) allows only unqualified column names,
6995 * which must match between tables.
6996 * ON expr allows more general qualifications.
6998 * We return USING as a List node, while an ON-expr will not be a List.
7001 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
7002 | ON a_expr { $$ = $2; }
7009 /* default inheritance */
7011 $$->inhOpt = INH_DEFAULT;
7014 | qualified_name '*'
7016 /* inheritance query */
7018 $$->inhOpt = INH_YES;
7021 | ONLY qualified_name
7023 /* no inheritance */
7025 $$->inhOpt = INH_NO;
7028 | ONLY '(' qualified_name ')'
7030 /* no inheritance, SQL99-style syntax */
7032 $$->inhOpt = INH_NO;
7039 * Given "UPDATE foo set set ...", we have to decide without looking any
7040 * further ahead whether the first "set" is an alias or the UPDATE's SET
7041 * keyword. Since "set" is allowed as a column name both interpretations
7042 * are feasible. We resolve the shift/reduce conflict by giving the first
7043 * relation_expr_opt_alias production a higher precedence than the SET token
7044 * has, causing the parser to prefer to reduce, in effect assuming that the
7045 * SET is not an alias.
7047 relation_expr_opt_alias: relation_expr %prec UMINUS
7051 | relation_expr ColId
7053 Alias *alias = makeNode(Alias);
7054 alias->aliasname = $2;
7058 | relation_expr AS ColId
7060 Alias *alias = makeNode(Alias);
7061 alias->aliasname = $3;
7068 func_table: func_expr { $$ = $1; }
7073 WHERE a_expr { $$ = $2; }
7074 | /*EMPTY*/ { $$ = NULL; }
7077 /* variant for UPDATE and DELETE */
7078 where_or_current_clause:
7079 WHERE a_expr { $$ = $2; }
7080 | WHERE CURRENT_P OF name
7082 CurrentOfExpr *n = makeNode(CurrentOfExpr);
7083 /* cvarno is filled in by parse analysis */
7084 n->cursor_name = $4;
7085 n->cursor_param = 0;
7088 | WHERE CURRENT_P OF PARAM
7090 CurrentOfExpr *n = makeNode(CurrentOfExpr);
7091 /* cvarno is filled in by parse analysis */
7092 n->cursor_name = NULL;
7093 n->cursor_param = $4;
7096 | /*EMPTY*/ { $$ = NULL; }
7100 TableFuncElementList:
7103 $$ = list_make1($1);
7105 | TableFuncElementList ',' TableFuncElement
7107 $$ = lappend($1, $3);
7111 TableFuncElement: ColId Typename
7113 ColumnDef *n = makeNode(ColumnDef);
7116 n->constraints = NIL;
7122 /*****************************************************************************
7125 * SQL92 introduces a large amount of type-specific syntax.
7126 * Define individual clauses to handle these cases, and use
7127 * the generic case to handle regular type-extensible Postgres syntax.
7128 * - thomas 1997-10-10
7130 *****************************************************************************/
7132 Typename: SimpleTypename opt_array_bounds
7135 $$->arrayBounds = $2;
7137 | SETOF SimpleTypename opt_array_bounds
7140 $$->arrayBounds = $3;
7143 /* SQL standard syntax, currently only one-dimensional */
7144 | SimpleTypename ARRAY '[' Iconst ']'
7147 $$->arrayBounds = list_make1(makeInteger($4));
7149 | SETOF SimpleTypename ARRAY '[' Iconst ']'
7152 $$->arrayBounds = list_make1(makeInteger($5));
7155 | SimpleTypename ARRAY
7158 $$->arrayBounds = list_make1(makeInteger(-1));
7160 | SETOF SimpleTypename ARRAY
7163 $$->arrayBounds = list_make1(makeInteger(-1));
7169 opt_array_bounds '[' ']'
7170 { $$ = lappend($1, makeInteger(-1)); }
7171 | opt_array_bounds '[' Iconst ']'
7172 { $$ = lappend($1, makeInteger($3)); }
7178 GenericType { $$ = $1; }
7179 | Numeric { $$ = $1; }
7181 | Character { $$ = $1; }
7182 | ConstDatetime { $$ = $1; }
7183 | ConstInterval opt_interval
7188 | ConstInterval '(' Iconst ')' opt_interval
7193 if (list_length($5) != 1)
7195 (errcode(ERRCODE_SYNTAX_ERROR),
7196 errmsg("interval precision specified twice"),
7197 scanner_errposition(@1)));
7198 $$->typmods = lappend($5, makeIntConst($3, @3));
7201 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
7202 makeIntConst($3, @3));
7206 /* We have a separate ConstTypename to allow defaulting fixed-length
7207 * types such as CHAR() and BIT() to an unspecified length.
7208 * SQL9x requires that these default to a length of one, but this
7209 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
7210 * where there is an obvious better choice to make.
7211 * Note that ConstInterval is not included here since it must
7212 * be pushed up higher in the rules to accomodate the postfix
7213 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
7214 * the generic-type-name case in AExprConst to avoid premature
7215 * reduce/reduce conflicts against function names.
7218 Numeric { $$ = $1; }
7219 | ConstBit { $$ = $1; }
7220 | ConstCharacter { $$ = $1; }
7221 | ConstDatetime { $$ = $1; }
7225 * GenericType covers all type names that don't have special syntax mandated
7226 * by the standard, including qualified names. We also allow type modifiers.
7227 * To avoid parsing conflicts against function invocations, the modifiers
7228 * have to be shown as expr_list here, but parse analysis will only accept
7229 * constants for them.
7232 type_function_name opt_type_modifiers
7234 $$ = makeTypeName($1);
7238 | type_function_name attrs opt_type_modifiers
7240 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
7246 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
7247 | /* EMPTY */ { $$ = NIL; }
7251 * SQL92 numeric data types
7255 $$ = SystemTypeName("int4");
7260 $$ = SystemTypeName("int4");
7265 $$ = SystemTypeName("int2");
7270 $$ = SystemTypeName("int8");
7275 $$ = SystemTypeName("float4");
7283 | DOUBLE_P PRECISION
7285 $$ = SystemTypeName("float8");
7288 | DECIMAL_P opt_type_modifiers
7290 $$ = SystemTypeName("numeric");
7294 | DEC opt_type_modifiers
7296 $$ = SystemTypeName("numeric");
7300 | NUMERIC opt_type_modifiers
7302 $$ = SystemTypeName("numeric");
7308 $$ = SystemTypeName("bool");
7313 opt_float: '(' Iconst ')'
7316 * Check FLOAT() precision limits assuming IEEE floating
7317 * types - thomas 1997-09-18
7321 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7322 errmsg("precision for type float must be at least 1 bit"),
7323 scanner_errposition(@2)));
7325 $$ = SystemTypeName("float4");
7327 $$ = SystemTypeName("float8");
7330 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7331 errmsg("precision for type float must be less than 54 bits"),
7332 scanner_errposition(@2)));
7336 $$ = SystemTypeName("float8");
7341 * SQL92 bit-field data types
7342 * The following implements BIT() and BIT VARYING().
7354 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
7355 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
7356 ConstBit: BitWithLength
7368 BIT opt_varying '(' expr_list ')'
7372 typname = $2 ? "varbit" : "bit";
7373 $$ = SystemTypeName(typname);
7382 /* bit defaults to bit(1), varbit to no limit */
7385 $$ = SystemTypeName("varbit");
7389 $$ = SystemTypeName("bit");
7390 $$->typmods = list_make1(makeIntConst(1, -1));
7398 * SQL92 character data types
7399 * The following implements CHAR() and VARCHAR().
7401 Character: CharacterWithLength
7405 | CharacterWithoutLength
7411 ConstCharacter: CharacterWithLength
7415 | CharacterWithoutLength
7417 /* Length was not specified so allow to be unrestricted.
7418 * This handles problems with fixed-length (bpchar) strings
7419 * which in column definitions must default to a length
7420 * of one, but should not be constrained if the length
7421 * was not specified.
7428 CharacterWithLength: character '(' Iconst ')' opt_charset
7430 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
7434 type = palloc(strlen($1) + 1 + strlen($5) + 1);
7441 $$ = SystemTypeName($1);
7442 $$->typmods = list_make1(makeIntConst($3, @3));
7447 CharacterWithoutLength: character opt_charset
7449 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
7453 type = palloc(strlen($1) + 1 + strlen($2) + 1);
7460 $$ = SystemTypeName($1);
7462 /* char defaults to char(1), varchar to no limit */
7463 if (strcmp($1, "bpchar") == 0)
7464 $$->typmods = list_make1(makeIntConst(1, -1));
7470 character: CHARACTER opt_varying
7471 { $$ = $2 ? "varchar": "bpchar"; }
7472 | CHAR_P opt_varying
7473 { $$ = $2 ? "varchar": "bpchar"; }
7476 | NATIONAL CHARACTER opt_varying
7477 { $$ = $3 ? "varchar": "bpchar"; }
7478 | NATIONAL CHAR_P opt_varying
7479 { $$ = $3 ? "varchar": "bpchar"; }
7481 { $$ = $2 ? "varchar": "bpchar"; }
7485 VARYING { $$ = TRUE; }
7486 | /*EMPTY*/ { $$ = FALSE; }
7490 CHARACTER SET ColId { $$ = $3; }
7491 | /*EMPTY*/ { $$ = NULL; }
7495 * SQL92 date/time types
7498 TIMESTAMP '(' Iconst ')' opt_timezone
7501 $$ = SystemTypeName("timestamptz");
7503 $$ = SystemTypeName("timestamp");
7504 $$->typmods = list_make1(makeIntConst($3, @3));
7507 | TIMESTAMP opt_timezone
7510 $$ = SystemTypeName("timestamptz");
7512 $$ = SystemTypeName("timestamp");
7515 | TIME '(' Iconst ')' opt_timezone
7518 $$ = SystemTypeName("timetz");
7520 $$ = SystemTypeName("time");
7521 $$->typmods = list_make1(makeIntConst($3, @3));
7527 $$ = SystemTypeName("timetz");
7529 $$ = SystemTypeName("time");
7537 $$ = SystemTypeName("interval");
7543 WITH_TIME ZONE { $$ = TRUE; }
7544 | WITHOUT TIME ZONE { $$ = FALSE; }
7545 | /*EMPTY*/ { $$ = FALSE; }
7550 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
7552 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
7554 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
7556 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
7558 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
7563 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
7564 INTERVAL_MASK(MONTH), @1));
7568 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
7569 INTERVAL_MASK(HOUR), @1));
7573 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
7574 INTERVAL_MASK(HOUR) |
7575 INTERVAL_MASK(MINUTE), @1));
7577 | DAY_P TO interval_second
7580 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
7581 INTERVAL_MASK(HOUR) |
7582 INTERVAL_MASK(MINUTE) |
7583 INTERVAL_MASK(SECOND), @1);
7585 | HOUR_P TO MINUTE_P
7587 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
7588 INTERVAL_MASK(MINUTE), @1));
7590 | HOUR_P TO interval_second
7593 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
7594 INTERVAL_MASK(MINUTE) |
7595 INTERVAL_MASK(SECOND), @1);
7597 | MINUTE_P TO interval_second
7600 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
7601 INTERVAL_MASK(SECOND), @1);
7610 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
7612 | SECOND_P '(' Iconst ')'
7614 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
7615 makeIntConst($3, @3));
7620 /*****************************************************************************
7622 * expression grammar
7624 *****************************************************************************/
7627 * General expressions
7628 * This is the heart of the expression syntax.
7630 * We have two expression types: a_expr is the unrestricted kind, and
7631 * b_expr is a subset that must be used in some places to avoid shift/reduce
7632 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
7633 * because that use of AND conflicts with AND as a boolean operator. So,
7634 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
7636 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
7637 * always be used by surrounding it with parens.
7639 * c_expr is all the productions that are common to a_expr and b_expr;
7640 * it's factored out just to eliminate redundant coding.
7642 a_expr: c_expr { $$ = $1; }
7643 | a_expr TYPECAST Typename
7644 { $$ = makeTypeCast($1, $3, @2); }
7645 | a_expr AT TIME ZONE a_expr
7647 FuncCall *n = makeNode(FuncCall);
7648 n->funcname = SystemFuncName("timezone");
7649 n->args = list_make2($5, $1);
7650 n->agg_star = FALSE;
7651 n->agg_distinct = FALSE;
7652 n->func_variadic = FALSE;
7657 * These operators must be called out explicitly in order to make use
7658 * of yacc/bison's automatic operator-precedence handling. All other
7659 * operator names are handled by the generic productions using "Op",
7660 * below; and all those operators will have the same precedence.
7662 * If you add more explicitly-known operators, be sure to add them
7663 * also to b_expr and to the MathOp list above.
7665 | '+' a_expr %prec UMINUS
7666 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
7667 | '-' a_expr %prec UMINUS
7668 { $$ = doNegate($2, @1); }
7670 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
7672 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
7674 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
7676 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
7678 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
7680 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
7682 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
7684 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
7686 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
7688 | a_expr qual_Op a_expr %prec Op
7689 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
7690 | qual_Op a_expr %prec Op
7691 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
7692 | a_expr qual_Op %prec POSTFIXOP
7693 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
7696 { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
7698 { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
7700 { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
7702 | a_expr LIKE a_expr
7703 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
7704 | a_expr LIKE a_expr ESCAPE a_expr
7706 FuncCall *n = makeNode(FuncCall);
7707 n->funcname = SystemFuncName("like_escape");
7708 n->args = list_make2($3, $5);
7709 n->agg_star = FALSE;
7710 n->agg_distinct = FALSE;
7711 n->func_variadic = FALSE;
7713 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
7715 | a_expr NOT LIKE a_expr
7716 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
7717 | a_expr NOT LIKE a_expr ESCAPE a_expr
7719 FuncCall *n = makeNode(FuncCall);
7720 n->funcname = SystemFuncName("like_escape");
7721 n->args = list_make2($4, $6);
7722 n->agg_star = FALSE;
7723 n->agg_distinct = FALSE;
7724 n->func_variadic = FALSE;
7726 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
7728 | a_expr ILIKE a_expr
7729 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
7730 | a_expr ILIKE a_expr ESCAPE a_expr
7732 FuncCall *n = makeNode(FuncCall);
7733 n->funcname = SystemFuncName("like_escape");
7734 n->args = list_make2($3, $5);
7735 n->agg_star = FALSE;
7736 n->agg_distinct = FALSE;
7737 n->func_variadic = FALSE;
7739 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n, @2);
7741 | a_expr NOT ILIKE a_expr
7742 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
7743 | a_expr NOT ILIKE a_expr ESCAPE a_expr
7745 FuncCall *n = makeNode(FuncCall);
7746 n->funcname = SystemFuncName("like_escape");
7747 n->args = list_make2($4, $6);
7748 n->agg_star = FALSE;
7749 n->agg_distinct = FALSE;
7750 n->func_variadic = FALSE;
7752 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n, @2);
7755 | a_expr SIMILAR TO a_expr %prec SIMILAR
7757 FuncCall *n = makeNode(FuncCall);
7758 n->funcname = SystemFuncName("similar_escape");
7759 n->args = list_make2($4, makeNullAConst(-1));
7760 n->agg_star = FALSE;
7761 n->agg_distinct = FALSE;
7762 n->func_variadic = FALSE;
7764 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
7766 | a_expr SIMILAR TO a_expr ESCAPE a_expr
7768 FuncCall *n = makeNode(FuncCall);
7769 n->funcname = SystemFuncName("similar_escape");
7770 n->args = list_make2($4, $6);
7771 n->agg_star = FALSE;
7772 n->agg_distinct = FALSE;
7773 n->func_variadic = FALSE;
7775 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
7777 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
7779 FuncCall *n = makeNode(FuncCall);
7780 n->funcname = SystemFuncName("similar_escape");
7781 n->args = list_make2($5, makeNullAConst(-1));
7782 n->agg_star = FALSE;
7783 n->agg_distinct = FALSE;
7784 n->func_variadic = FALSE;
7786 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
7788 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
7790 FuncCall *n = makeNode(FuncCall);
7791 n->funcname = SystemFuncName("similar_escape");
7792 n->args = list_make2($5, $7);
7793 n->agg_star = FALSE;
7794 n->agg_distinct = FALSE;
7795 n->func_variadic = FALSE;
7797 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
7801 * Define SQL92-style Null test clause.
7802 * Allow two forms described in the standard:
7805 * Allow two SQL extensions
7811 NullTest *n = makeNode(NullTest);
7812 n->arg = (Expr *) $1;
7813 n->nulltesttype = IS_NULL;
7818 NullTest *n = makeNode(NullTest);
7819 n->arg = (Expr *) $1;
7820 n->nulltesttype = IS_NULL;
7823 | a_expr IS NOT NULL_P
7825 NullTest *n = makeNode(NullTest);
7826 n->arg = (Expr *) $1;
7827 n->nulltesttype = IS_NOT_NULL;
7832 NullTest *n = makeNode(NullTest);
7833 n->arg = (Expr *) $1;
7834 n->nulltesttype = IS_NOT_NULL;
7839 $$ = (Node *)makeOverlaps($1, $3, @2);
7843 BooleanTest *b = makeNode(BooleanTest);
7844 b->arg = (Expr *) $1;
7845 b->booltesttype = IS_TRUE;
7848 | a_expr IS NOT TRUE_P
7850 BooleanTest *b = makeNode(BooleanTest);
7851 b->arg = (Expr *) $1;
7852 b->booltesttype = IS_NOT_TRUE;
7857 BooleanTest *b = makeNode(BooleanTest);
7858 b->arg = (Expr *) $1;
7859 b->booltesttype = IS_FALSE;
7862 | a_expr IS NOT FALSE_P
7864 BooleanTest *b = makeNode(BooleanTest);
7865 b->arg = (Expr *) $1;
7866 b->booltesttype = IS_NOT_FALSE;
7871 BooleanTest *b = makeNode(BooleanTest);
7872 b->arg = (Expr *) $1;
7873 b->booltesttype = IS_UNKNOWN;
7876 | a_expr IS NOT UNKNOWN
7878 BooleanTest *b = makeNode(BooleanTest);
7879 b->arg = (Expr *) $1;
7880 b->booltesttype = IS_NOT_UNKNOWN;
7883 | a_expr IS DISTINCT FROM a_expr %prec IS
7885 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
7887 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
7889 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
7890 (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
7895 | a_expr IS OF '(' type_list ')' %prec IS
7897 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
7899 | a_expr IS NOT OF '(' type_list ')' %prec IS
7901 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
7903 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
7905 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
7906 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
7907 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
7910 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
7912 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
7913 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
7914 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
7917 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
7919 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
7920 (Node *) makeA_Expr(AEXPR_AND, NIL,
7921 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
7922 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
7924 (Node *) makeA_Expr(AEXPR_AND, NIL,
7925 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
7926 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
7930 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
7932 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
7933 (Node *) makeA_Expr(AEXPR_OR, NIL,
7934 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
7935 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
7937 (Node *) makeA_Expr(AEXPR_OR, NIL,
7938 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
7939 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
7943 | a_expr IN_P in_expr
7945 /* in_expr returns a SubLink or a list of a_exprs */
7946 if (IsA($3, SubLink))
7948 /* generate foo = ANY (subquery) */
7949 SubLink *n = (SubLink *) $3;
7950 n->subLinkType = ANY_SUBLINK;
7952 n->operName = list_make1(makeString("="));
7958 /* generate scalar IN expression */
7959 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
7962 | a_expr NOT IN_P in_expr
7964 /* in_expr returns a SubLink or a list of a_exprs */
7965 if (IsA($4, SubLink))
7967 /* generate NOT (foo = ANY (subquery)) */
7968 /* Make an = ANY node */
7969 SubLink *n = (SubLink *) $4;
7970 n->subLinkType = ANY_SUBLINK;
7972 n->operName = list_make1(makeString("="));
7974 /* Stick a NOT on top */
7975 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
7979 /* generate scalar NOT IN expression */
7980 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
7983 | a_expr subquery_Op sub_type select_with_parens %prec Op
7985 SubLink *n = makeNode(SubLink);
7986 n->subLinkType = $3;
7993 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
7995 if ($3 == ANY_SUBLINK)
7996 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
7998 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
8000 | UNIQUE select_with_parens
8002 /* Not sure how to get rid of the parentheses
8003 * but there are lots of shift/reduce errors without them.
8005 * Should be able to implement this by plopping the entire
8006 * select into a node, then transforming the target expressions
8007 * from whatever they are into count(*), and testing the
8008 * entire result equal to one.
8009 * But, will probably implement a separate node in the executor.
8012 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8013 errmsg("UNIQUE predicate is not yet implemented"),
8014 scanner_errposition(@1)));
8016 | a_expr IS DOCUMENT_P %prec IS
8018 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8019 list_make1($1), @2);
8021 | a_expr IS NOT DOCUMENT_P %prec IS
8023 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8024 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8025 list_make1($1), @2),
8031 * Restricted expressions
8033 * b_expr is a subset of the complete expression syntax defined by a_expr.
8035 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
8036 * cause trouble in the places where b_expr is used. For simplicity, we
8037 * just eliminate all the boolean-keyword-operator productions from b_expr.
8041 | b_expr TYPECAST Typename
8042 { $$ = makeTypeCast($1, $3, @2); }
8043 | '+' b_expr %prec UMINUS
8044 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
8045 | '-' b_expr %prec UMINUS
8046 { $$ = doNegate($2, @1); }
8048 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
8050 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
8052 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
8054 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
8056 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
8058 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
8060 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
8062 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
8064 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
8065 | b_expr qual_Op b_expr %prec Op
8066 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
8067 | qual_Op b_expr %prec Op
8068 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
8069 | b_expr qual_Op %prec POSTFIXOP
8070 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
8071 | b_expr IS DISTINCT FROM b_expr %prec IS
8073 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
8075 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
8077 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
8078 NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
8080 | b_expr IS OF '(' type_list ')' %prec IS
8082 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
8084 | b_expr IS NOT OF '(' type_list ')' %prec IS
8086 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
8088 | b_expr IS DOCUMENT_P %prec IS
8090 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8091 list_make1($1), @2);
8093 | b_expr IS NOT DOCUMENT_P %prec IS
8095 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8096 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8097 list_make1($1), @2),
8103 * Productions that can be used in both a_expr and b_expr.
8105 * Note: productions that refer recursively to a_expr or b_expr mostly
8106 * cannot appear here. However, it's OK to refer to a_exprs that occur
8107 * inside parentheses, such as function arguments; that cannot introduce
8108 * ambiguity to the b_expr syntax.
8110 c_expr: columnref { $$ = $1; }
8111 | AexprConst { $$ = $1; }
8112 | PARAM opt_indirection
8114 ParamRef *p = makeNode(ParamRef);
8119 A_Indirection *n = makeNode(A_Indirection);
8120 n->arg = (Node *) p;
8121 n->indirection = check_indirection($2);
8127 | '(' a_expr ')' opt_indirection
8131 A_Indirection *n = makeNode(A_Indirection);
8133 n->indirection = check_indirection($4);
8143 | select_with_parens %prec UMINUS
8145 SubLink *n = makeNode(SubLink);
8146 n->subLinkType = EXPR_SUBLINK;
8153 | EXISTS select_with_parens
8155 SubLink *n = makeNode(SubLink);
8156 n->subLinkType = EXISTS_SUBLINK;
8163 | ARRAY select_with_parens
8165 SubLink *n = makeNode(SubLink);
8166 n->subLinkType = ARRAY_SUBLINK;
8175 A_ArrayExpr *n = (A_ArrayExpr *) $2;
8176 Assert(IsA(n, A_ArrayExpr));
8177 /* point outermost A_ArrayExpr to the ARRAY keyword */
8183 RowExpr *r = makeNode(RowExpr);
8185 r->row_typeid = InvalidOid; /* not analyzed yet */
8192 * func_expr is split out from c_expr just so that we have a classification
8193 * for "everything that is a function call or looks like one". This isn't
8194 * very important, but it saves us having to document which variants are
8195 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
8196 * (Note that many of the special SQL functions wouldn't actually make any
8197 * sense as functional index entries, but we ignore that consideration here.)
8199 func_expr: func_name '(' ')'
8201 FuncCall *n = makeNode(FuncCall);
8204 n->agg_star = FALSE;
8205 n->agg_distinct = FALSE;
8206 n->func_variadic = FALSE;
8210 | func_name '(' expr_list ')'
8212 FuncCall *n = makeNode(FuncCall);
8215 n->agg_star = FALSE;
8216 n->agg_distinct = FALSE;
8217 n->func_variadic = FALSE;
8221 | func_name '(' VARIADIC a_expr ')'
8223 FuncCall *n = makeNode(FuncCall);
8225 n->args = list_make1($4);
8226 n->agg_star = FALSE;
8227 n->agg_distinct = FALSE;
8228 n->func_variadic = TRUE;
8232 | func_name '(' expr_list ',' VARIADIC a_expr ')'
8234 FuncCall *n = makeNode(FuncCall);
8236 n->args = lappend($3, $6);
8237 n->agg_star = FALSE;
8238 n->agg_distinct = FALSE;
8239 n->func_variadic = TRUE;
8243 | func_name '(' ALL expr_list ')'
8245 FuncCall *n = makeNode(FuncCall);
8248 n->agg_star = FALSE;
8249 n->agg_distinct = FALSE;
8250 /* Ideally we'd mark the FuncCall node to indicate
8251 * "must be an aggregate", but there's no provision
8252 * for that in FuncCall at the moment.
8254 n->func_variadic = FALSE;
8258 | func_name '(' DISTINCT expr_list ')'
8260 FuncCall *n = makeNode(FuncCall);
8263 n->agg_star = FALSE;
8264 n->agg_distinct = TRUE;
8265 n->func_variadic = FALSE;
8269 | func_name '(' '*' ')'
8272 * We consider AGGREGATE(*) to invoke a parameterless
8273 * aggregate. This does the right thing for COUNT(*),
8274 * and there are no other aggregates in SQL92 that accept
8277 * The FuncCall node is also marked agg_star = true,
8278 * so that later processing can detect what the argument
8281 FuncCall *n = makeNode(FuncCall);
8285 n->agg_distinct = FALSE;
8286 n->func_variadic = FALSE;
8293 * Translate as "'now'::text::date".
8295 * We cannot use "'now'::date" because coerce_type() will
8296 * immediately reduce that to a constant representing
8297 * today's date. We need to delay the conversion until
8298 * runtime, else the wrong things will happen when
8299 * CURRENT_DATE is used in a column default value or rule.
8301 * This could be simplified if we had a way to generate
8302 * an expression tree representing runtime application
8303 * of type-input conversion functions. (As of PG 7.3
8304 * that is actually possible, but not clear that we want
8308 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8309 $$ = makeTypeCast(n, SystemTypeName("date"), -1);
8314 * Translate as "'now'::text::timetz".
8315 * See comments for CURRENT_DATE.
8318 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8319 $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
8321 | CURRENT_TIME '(' Iconst ')'
8324 * Translate as "'now'::text::timetz(n)".
8325 * See comments for CURRENT_DATE.
8329 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8330 d = SystemTypeName("timetz");
8331 d->typmods = list_make1(makeIntConst($3, @3));
8332 $$ = makeTypeCast(n, d, -1);
8337 * Translate as "now()", since we have a function that
8338 * does exactly what is needed.
8340 FuncCall *n = makeNode(FuncCall);
8341 n->funcname = SystemFuncName("now");
8343 n->agg_star = FALSE;
8344 n->agg_distinct = FALSE;
8345 n->func_variadic = FALSE;
8349 | CURRENT_TIMESTAMP '(' Iconst ')'
8352 * Translate as "'now'::text::timestamptz(n)".
8353 * See comments for CURRENT_DATE.
8357 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8358 d = SystemTypeName("timestamptz");
8359 d->typmods = list_make1(makeIntConst($3, @3));
8360 $$ = makeTypeCast(n, d, -1);
8365 * Translate as "'now'::text::time".
8366 * See comments for CURRENT_DATE.
8369 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8370 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
8372 | LOCALTIME '(' Iconst ')'
8375 * Translate as "'now'::text::time(n)".
8376 * See comments for CURRENT_DATE.
8380 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8381 d = SystemTypeName("time");
8382 d->typmods = list_make1(makeIntConst($3, @3));
8383 $$ = makeTypeCast((Node *)n, d, -1);
8388 * Translate as "'now'::text::timestamp".
8389 * See comments for CURRENT_DATE.
8392 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8393 $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
8395 | LOCALTIMESTAMP '(' Iconst ')'
8398 * Translate as "'now'::text::timestamp(n)".
8399 * See comments for CURRENT_DATE.
8403 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8404 d = SystemTypeName("timestamp");
8405 d->typmods = list_make1(makeIntConst($3, @3));
8406 $$ = makeTypeCast(n, d, -1);
8410 FuncCall *n = makeNode(FuncCall);
8411 n->funcname = SystemFuncName("current_user");
8413 n->agg_star = FALSE;
8414 n->agg_distinct = FALSE;
8415 n->func_variadic = FALSE;
8421 FuncCall *n = makeNode(FuncCall);
8422 n->funcname = SystemFuncName("current_user");
8424 n->agg_star = FALSE;
8425 n->agg_distinct = FALSE;
8426 n->func_variadic = FALSE;
8432 FuncCall *n = makeNode(FuncCall);
8433 n->funcname = SystemFuncName("session_user");
8435 n->agg_star = FALSE;
8436 n->agg_distinct = FALSE;
8437 n->func_variadic = FALSE;
8443 FuncCall *n = makeNode(FuncCall);
8444 n->funcname = SystemFuncName("current_user");
8446 n->agg_star = FALSE;
8447 n->agg_distinct = FALSE;
8448 n->func_variadic = FALSE;
8454 FuncCall *n = makeNode(FuncCall);
8455 n->funcname = SystemFuncName("current_database");
8457 n->agg_star = FALSE;
8458 n->agg_distinct = FALSE;
8459 n->func_variadic = FALSE;
8465 FuncCall *n = makeNode(FuncCall);
8466 n->funcname = SystemFuncName("current_schema");
8468 n->agg_star = FALSE;
8469 n->agg_distinct = FALSE;
8470 n->func_variadic = FALSE;
8474 | CAST '(' a_expr AS Typename ')'
8475 { $$ = makeTypeCast($3, $5, @1); }
8476 | EXTRACT '(' extract_list ')'
8478 FuncCall *n = makeNode(FuncCall);
8479 n->funcname = SystemFuncName("date_part");
8481 n->agg_star = FALSE;
8482 n->agg_distinct = FALSE;
8483 n->func_variadic = FALSE;
8487 | OVERLAY '(' overlay_list ')'
8489 /* overlay(A PLACING B FROM C FOR D) is converted to
8490 * substring(A, 1, C-1) || B || substring(A, C+1, C+D)
8491 * overlay(A PLACING B FROM C) is converted to
8492 * substring(A, 1, C-1) || B || substring(A, C+1, C+char_length(B))
8494 FuncCall *n = makeNode(FuncCall);
8495 n->funcname = SystemFuncName("overlay");
8497 n->agg_star = FALSE;
8498 n->agg_distinct = FALSE;
8499 n->func_variadic = FALSE;
8503 | POSITION '(' position_list ')'
8505 /* position(A in B) is converted to position(B, A) */
8506 FuncCall *n = makeNode(FuncCall);
8507 n->funcname = SystemFuncName("position");
8509 n->agg_star = FALSE;
8510 n->agg_distinct = FALSE;
8511 n->func_variadic = FALSE;
8515 | SUBSTRING '(' substr_list ')'
8517 /* substring(A from B for C) is converted to
8518 * substring(A, B, C) - thomas 2000-11-28
8520 FuncCall *n = makeNode(FuncCall);
8521 n->funcname = SystemFuncName("substring");
8523 n->agg_star = FALSE;
8524 n->agg_distinct = FALSE;
8525 n->func_variadic = FALSE;
8529 | TREAT '(' a_expr AS Typename ')'
8531 /* TREAT(expr AS target) converts expr of a particular type to target,
8532 * which is defined to be a subtype of the original expression.
8533 * In SQL99, this is intended for use with structured UDTs,
8534 * but let's make this a generally useful form allowing stronger
8535 * coercions than are handled by implicit casting.
8537 FuncCall *n = makeNode(FuncCall);
8538 /* Convert SystemTypeName() to SystemFuncName() even though
8539 * at the moment they result in the same thing.
8541 n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
8542 n->args = list_make1($3);
8543 n->agg_star = FALSE;
8544 n->agg_distinct = FALSE;
8545 n->func_variadic = FALSE;
8549 | TRIM '(' BOTH trim_list ')'
8551 /* various trim expressions are defined in SQL92
8552 * - thomas 1997-07-19
8554 FuncCall *n = makeNode(FuncCall);
8555 n->funcname = SystemFuncName("btrim");
8557 n->agg_star = FALSE;
8558 n->agg_distinct = FALSE;
8559 n->func_variadic = FALSE;
8563 | TRIM '(' LEADING trim_list ')'
8565 FuncCall *n = makeNode(FuncCall);
8566 n->funcname = SystemFuncName("ltrim");
8568 n->agg_star = FALSE;
8569 n->agg_distinct = FALSE;
8570 n->func_variadic = FALSE;
8574 | TRIM '(' TRAILING trim_list ')'
8576 FuncCall *n = makeNode(FuncCall);
8577 n->funcname = SystemFuncName("rtrim");
8579 n->agg_star = FALSE;
8580 n->agg_distinct = FALSE;
8581 n->func_variadic = FALSE;
8585 | TRIM '(' trim_list ')'
8587 FuncCall *n = makeNode(FuncCall);
8588 n->funcname = SystemFuncName("btrim");
8590 n->agg_star = FALSE;
8591 n->agg_distinct = FALSE;
8592 n->func_variadic = FALSE;
8596 | NULLIF '(' a_expr ',' a_expr ')'
8598 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
8600 | COALESCE '(' expr_list ')'
8602 CoalesceExpr *c = makeNode(CoalesceExpr);
8607 | GREATEST '(' expr_list ')'
8609 MinMaxExpr *v = makeNode(MinMaxExpr);
8611 v->op = IS_GREATEST;
8615 | LEAST '(' expr_list ')'
8617 MinMaxExpr *v = makeNode(MinMaxExpr);
8623 | XMLCONCAT '(' expr_list ')'
8625 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
8627 | XMLELEMENT '(' NAME_P ColLabel ')'
8629 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
8631 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
8633 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
8635 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
8637 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
8639 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
8641 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
8643 | XMLFOREST '(' xml_attribute_list ')'
8645 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
8647 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
8649 XmlExpr *x = (XmlExpr *)
8650 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
8651 list_make2($4, makeBoolAConst($5, -1)),
8656 | XMLPI '(' NAME_P ColLabel ')'
8658 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
8660 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
8662 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
8664 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
8666 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
8667 list_make3($3, $5, $6), @1);
8669 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
8671 XmlSerialize *n = makeNode(XmlSerialize);
8683 xml_root_version: VERSION_P a_expr
8685 | VERSION_P NO VALUE_P
8686 { $$ = makeNullAConst(-1); }
8689 opt_xml_root_standalone: ',' STANDALONE_P YES_P
8690 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
8691 | ',' STANDALONE_P NO
8692 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
8693 | ',' STANDALONE_P NO VALUE_P
8694 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
8696 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
8699 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
8702 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
8703 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
8706 xml_attribute_el: a_expr AS ColLabel
8708 $$ = makeNode(ResTarget);
8710 $$->indirection = NIL;
8711 $$->val = (Node *) $1;
8716 $$ = makeNode(ResTarget);
8718 $$->indirection = NIL;
8719 $$->val = (Node *) $1;
8724 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
8725 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
8728 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
8729 | STRIP_P WHITESPACE_P { $$ = FALSE; }
8730 | /*EMPTY*/ { $$ = FALSE; }
8734 * Supporting nonterminals for expressions.
8737 /* Explicit row production.
8739 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
8740 * without conflicting with the parenthesized a_expr production. Without the
8741 * ROW keyword, there must be more than one a_expr inside the parens.
8743 row: ROW '(' expr_list ')' { $$ = $3; }
8744 | ROW '(' ')' { $$ = NIL; }
8745 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
8748 sub_type: ANY { $$ = ANY_SUBLINK; }
8749 | SOME { $$ = ANY_SUBLINK; }
8750 | ALL { $$ = ALL_SUBLINK; }
8753 all_Op: Op { $$ = $1; }
8754 | MathOp { $$ = $1; }
8757 MathOp: '+' { $$ = "+"; }
8769 { $$ = list_make1(makeString($1)); }
8770 | OPERATOR '(' any_operator ')'
8776 { $$ = list_make1(makeString($1)); }
8777 | OPERATOR '(' any_operator ')'
8783 { $$ = list_make1(makeString($1)); }
8784 | OPERATOR '(' any_operator ')'
8787 { $$ = list_make1(makeString("~~")); }
8789 { $$ = list_make1(makeString("!~~")); }
8791 { $$ = list_make1(makeString("~~*")); }
8793 { $$ = list_make1(makeString("!~~*")); }
8794 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
8795 * the regular expression is preprocessed by a function (similar_escape),
8796 * and the ~ operator for posix regular expressions is used.
8797 * x SIMILAR TO y -> x ~ similar_escape(y)
8798 * this transformation is made on the fly by the parser upwards.
8799 * however the SubLink structure which handles any/some/all stuff
8800 * is not ready for such a thing.
8806 $$ = list_make1($1);
8808 | expr_list ',' a_expr
8810 $$ = lappend($1, $3);
8814 type_list: Typename { $$ = list_make1($1); }
8815 | type_list ',' Typename { $$ = lappend($1, $3); }
8818 array_expr: '[' expr_list ']'
8820 $$ = makeAArrayExpr($2, @1);
8822 | '[' array_expr_list ']'
8824 $$ = makeAArrayExpr($2, @1);
8828 $$ = makeAArrayExpr(NIL, @1);
8832 array_expr_list: array_expr { $$ = list_make1($1); }
8833 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
8838 extract_arg FROM a_expr
8840 $$ = list_make2(makeStringConst($1, @1), $3);
8842 | /*EMPTY*/ { $$ = NIL; }
8845 /* Allow delimited string Sconst in extract_arg as an SQL extension.
8846 * - thomas 2001-04-12
8850 | YEAR_P { $$ = "year"; }
8851 | MONTH_P { $$ = "month"; }
8852 | DAY_P { $$ = "day"; }
8853 | HOUR_P { $$ = "hour"; }
8854 | MINUTE_P { $$ = "minute"; }
8855 | SECOND_P { $$ = "second"; }
8856 | Sconst { $$ = $1; }
8859 /* OVERLAY() arguments
8860 * SQL99 defines the OVERLAY() function:
8861 * o overlay(text placing text from int for int)
8862 * o overlay(text placing text from int)
8865 a_expr overlay_placing substr_from substr_for
8867 $$ = list_make4($1, $2, $3, $4);
8869 | a_expr overlay_placing substr_from
8871 $$ = list_make3($1, $2, $3);
8880 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
8883 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
8884 | /*EMPTY*/ { $$ = NIL; }
8887 /* SUBSTRING() arguments
8888 * SQL9x defines a specific syntax for arguments to SUBSTRING():
8889 * o substring(text from int for int)
8890 * o substring(text from int) get entire string from starting point "int"
8891 * o substring(text for int) get first "int" characters of string
8892 * o substring(text from pattern) get entire string matching pattern
8893 * o substring(text from pattern for escape) same with specified escape char
8894 * We also want to support generic substring functions which accept
8895 * the usual generic list of arguments. So we will accept both styles
8896 * here, and convert the SQL9x style to the generic list for further
8897 * processing. - thomas 2000-11-28
8900 a_expr substr_from substr_for
8902 $$ = list_make3($1, $2, $3);
8904 | a_expr substr_for substr_from
8906 /* not legal per SQL99, but might as well allow it */
8907 $$ = list_make3($1, $3, $2);
8909 | a_expr substr_from
8911 $$ = list_make2($1, $2);
8916 * Since there are no cases where this syntax allows
8917 * a textual FOR value, we forcibly cast the argument
8918 * to int4. The possible matches in pg_proc are
8919 * substring(text,int4) and substring(text,text),
8920 * and we don't want the parser to choose the latter,
8921 * which it is likely to do if the second argument
8922 * is unknown or doesn't have an implicit cast to int4.
8924 $$ = list_make3($1, makeIntConst(1, -1),
8926 SystemTypeName("int4"), -1));
8937 FROM a_expr { $$ = $2; }
8940 substr_for: FOR a_expr { $$ = $2; }
8943 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
8944 | FROM expr_list { $$ = $2; }
8945 | expr_list { $$ = $1; }
8948 in_expr: select_with_parens
8950 SubLink *n = makeNode(SubLink);
8952 /* other fields will be filled later */
8955 | '(' expr_list ')' { $$ = (Node *)$2; }
8959 * Define SQL92-style case clause.
8960 * - Full specification
8961 * CASE WHEN a = b THEN c ... ELSE d END
8962 * - Implicit argument
8963 * CASE a WHEN b THEN c ... ELSE d END
8965 case_expr: CASE case_arg when_clause_list case_default END_P
8967 CaseExpr *c = makeNode(CaseExpr);
8968 c->casetype = InvalidOid; /* not analyzed yet */
8969 c->arg = (Expr *) $2;
8971 c->defresult = (Expr *) $4;
8978 /* There must be at least one */
8979 when_clause { $$ = list_make1($1); }
8980 | when_clause_list when_clause { $$ = lappend($1, $2); }
8984 WHEN a_expr THEN a_expr
8986 CaseWhen *w = makeNode(CaseWhen);
8987 w->expr = (Expr *) $2;
8988 w->result = (Expr *) $4;
8995 ELSE a_expr { $$ = $2; }
8996 | /*EMPTY*/ { $$ = NULL; }
8999 case_arg: a_expr { $$ = $1; }
9000 | /*EMPTY*/ { $$ = NULL; }
9004 * columnref starts with relation_name not ColId, so that OLD and NEW
9005 * references can be accepted. Note that when there are more than two
9006 * dotted names, the first name is not actually a relation name...
9008 columnref: relation_name
9010 $$ = makeColumnRef($1, NIL, @1);
9012 | relation_name indirection
9014 $$ = makeColumnRef($1, $2, @1);
9021 $$ = (Node *) makeString($2);
9025 $$ = (Node *) makeNode(A_Star);
9029 A_Indices *ai = makeNode(A_Indices);
9034 | '[' a_expr ':' a_expr ']'
9036 A_Indices *ai = makeNode(A_Indices);
9044 indirection_el { $$ = list_make1($1); }
9045 | indirection indirection_el { $$ = lappend($1, $2); }
9049 /*EMPTY*/ { $$ = NIL; }
9050 | opt_indirection indirection_el { $$ = lappend($1, $2); }
9053 opt_asymmetric: ASYMMETRIC
9058 * The SQL spec defines "contextually typed value expressions" and
9059 * "contextually typed row value constructors", which for our purposes
9060 * are the same as "a_expr" and "row" except that DEFAULT can appear at
9065 a_expr { $$ = (Node *) $1; }
9068 SetToDefault *n = makeNode(SetToDefault);
9075 ctext_expr { $$ = list_make1($1); }
9076 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
9080 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
9081 * making VALUES a fully reserved word, which will probably break more apps
9082 * than allowing the noise-word is worth.
9084 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
9088 /*****************************************************************************
9090 * target list for SELECT
9092 *****************************************************************************/
9095 target_el { $$ = list_make1($1); }
9096 | target_list ',' target_el { $$ = lappend($1, $3); }
9099 target_el: a_expr AS ColLabel
9101 $$ = makeNode(ResTarget);
9103 $$->indirection = NIL;
9104 $$->val = (Node *)$1;
9108 * We support omitting AS only for column labels that aren't
9109 * any known keyword. There is an ambiguity against postfix
9110 * operators: is "a ! b" an infix expression, or a postfix
9111 * expression and a column label? We prefer to resolve this
9112 * as an infix expression, which we accomplish by assigning
9113 * IDENT a precedence higher than POSTFIXOP.
9117 $$ = makeNode(ResTarget);
9119 $$->indirection = NIL;
9120 $$->val = (Node *)$1;
9125 $$ = makeNode(ResTarget);
9127 $$->indirection = NIL;
9128 $$->val = (Node *)$1;
9133 ColumnRef *n = makeNode(ColumnRef);
9134 n->fields = list_make1(makeNode(A_Star));
9137 $$ = makeNode(ResTarget);
9139 $$->indirection = NIL;
9140 $$->val = (Node *)n;
9146 /*****************************************************************************
9148 * Names and constants
9150 *****************************************************************************/
9153 SpecialRuleRelation { $$ = $1; }
9154 | ColId { $$ = $1; }
9157 qualified_name_list:
9158 qualified_name { $$ = list_make1($1); }
9159 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
9163 * The production for a qualified relation name has to exactly match the
9164 * production for a qualified func_name, because in a FROM clause we cannot
9165 * tell which we are parsing until we see what comes after it ('(' for a
9166 * func_name, something else for a relation). Therefore we allow 'indirection'
9167 * which may contain subscripts, and reject that case in the C code.
9172 $$ = makeNode(RangeVar);
9173 $$->catalogname = NULL;
9174 $$->schemaname = NULL;
9178 | relation_name indirection
9180 check_qualified_name($2);
9181 $$ = makeNode(RangeVar);
9182 switch (list_length($2))
9185 $$->catalogname = NULL;
9186 $$->schemaname = $1;
9187 $$->relname = strVal(linitial($2));
9190 $$->catalogname = $1;
9191 $$->schemaname = strVal(linitial($2));
9192 $$->relname = strVal(lsecond($2));
9196 (errcode(ERRCODE_SYNTAX_ERROR),
9197 errmsg("improper qualified name (too many dotted names): %s",
9198 NameListToString(lcons(makeString($1), $2))),
9199 scanner_errposition(@1)));
9207 { $$ = list_make1(makeString($1)); }
9208 | name_list ',' name
9209 { $$ = lappend($1, makeString($3)); }
9213 name: ColId { $$ = $1; };
9221 attr_name: ColLabel { $$ = $1; };
9223 index_name: ColId { $$ = $1; };
9225 file_name: Sconst { $$ = $1; };
9228 * The production for a qualified func_name has to exactly match the
9229 * production for a qualified columnref, because we cannot tell which we
9230 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
9231 * anything else for a columnref). Therefore we allow 'indirection' which
9232 * may contain subscripts, and reject that case in the C code. (If we
9233 * ever implement SQL99-like methods, such syntax may actually become legal!)
9235 func_name: type_function_name
9236 { $$ = list_make1(makeString($1)); }
9237 | relation_name indirection
9238 { $$ = check_func_name(lcons(makeString($1), $2)); }
9247 $$ = makeIntConst($1, @1);
9251 $$ = makeFloatConst($1, @1);
9255 $$ = makeStringConst($1, @1);
9259 $$ = makeBitStringConst($1, @1);
9263 /* This is a bit constant per SQL99:
9264 * Without Feature F511, "BIT data type",
9265 * a <general literal> shall not be a
9266 * <bit string literal> or a <hex string literal>.
9268 $$ = makeBitStringConst($1, @1);
9272 /* generic type 'literal' syntax */
9273 TypeName *t = makeTypeNameFromNameList($1);
9275 $$ = makeStringConstCast($2, @2, t);
9277 | func_name '(' expr_list ')' Sconst
9279 /* generic syntax with a type modifier */
9280 TypeName *t = makeTypeNameFromNameList($1);
9283 $$ = makeStringConstCast($5, @5, t);
9285 | ConstTypename Sconst
9287 $$ = makeStringConstCast($2, @2, $1);
9289 | ConstInterval Sconst opt_interval
9293 $$ = makeStringConstCast($2, @2, t);
9295 | ConstInterval '(' Iconst ')' Sconst opt_interval
9300 if (list_length($6) != 1)
9302 (errcode(ERRCODE_SYNTAX_ERROR),
9303 errmsg("interval precision specified twice"),
9304 scanner_errposition(@1)));
9305 t->typmods = lappend($6, makeIntConst($3, @3));
9308 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
9309 makeIntConst($3, @3));
9310 $$ = makeStringConstCast($5, @5, t);
9314 $$ = makeBoolAConst(TRUE, @1);
9318 $$ = makeBoolAConst(FALSE, @1);
9322 $$ = makeNullAConst(@1);
9326 Iconst: ICONST { $$ = $1; };
9327 Sconst: SCONST { $$ = $1; };
9328 RoleId: ColId { $$ = $1; };
9330 SignedIconst: Iconst { $$ = $1; }
9331 | '+' Iconst { $$ = + $2; }
9332 | '-' Iconst { $$ = - $2; }
9336 * Name classification hierarchy.
9338 * IDENT is the lexeme returned by the lexer for identifiers that match
9339 * no known keyword. In most cases, we can accept certain keywords as
9340 * names, not only IDENTs. We prefer to accept as many such keywords
9341 * as possible to minimize the impact of "reserved words" on programmers.
9342 * So, we divide names into several possible classes. The classification
9343 * is chosen in part to make keywords acceptable as names wherever possible.
9346 /* Column identifier --- names that can be column, table, etc names.
9348 ColId: IDENT { $$ = $1; }
9349 | unreserved_keyword { $$ = pstrdup($1); }
9350 | col_name_keyword { $$ = pstrdup($1); }
9353 /* Type/function identifier --- names that can be type or function names.
9355 type_function_name: IDENT { $$ = $1; }
9356 | unreserved_keyword { $$ = pstrdup($1); }
9357 | type_func_name_keyword { $$ = pstrdup($1); }
9360 /* Column label --- allowed labels in "AS" clauses.
9361 * This presently includes *all* Postgres keywords.
9363 ColLabel: IDENT { $$ = $1; }
9364 | unreserved_keyword { $$ = pstrdup($1); }
9365 | col_name_keyword { $$ = pstrdup($1); }
9366 | type_func_name_keyword { $$ = pstrdup($1); }
9367 | reserved_keyword { $$ = pstrdup($1); }
9372 * Keyword category lists. Generally, every keyword present in
9373 * the Postgres grammar should appear in exactly one of these lists.
9375 * Put a new keyword into the first list that it can go into without causing
9376 * shift or reduce conflicts. The earlier lists define "less reserved"
9377 * categories of keywords.
9379 * Make sure that each keyword's category in keywords.c matches where
9380 * it is listed here. (Someday we may be able to generate these lists and
9381 * keywords.c's table from a common master list.)
9384 /* "Unreserved" keywords --- available for use as any kind of name.
9626 /* Column identifier --- keywords that can be column, table, etc names.
9628 * Many of these keywords will in fact be recognized as type or function
9629 * names too; but they have special productions for the purpose, and so
9630 * can't be treated as "generic" type or function names.
9632 * The type names appearing here are not usable as function names
9633 * because they can be followed by '(' in typename productions, which
9634 * looks too much like a function call for an LR(1) parser.
9684 /* Type/function identifier --- keywords that can be type or function names.
9686 * Most of these are keywords that are used as operators in expressions;
9687 * in general such keywords can't be column names because they would be
9688 * ambiguous with variables, but they are unambiguous as function identifiers.
9690 * Do not include POSITION, SUBSTRING, etc here since they have explicit
9691 * productions in a_expr to support the goofy SQL9x argument syntax.
9692 * - thomas 2000-11-28
9694 type_func_name_keyword:
9718 /* Reserved keyword --- these keywords are usable only as a ColLabel.
9720 * Keywords appear here if they could not be distinguished from variable,
9721 * type, or function names in some contexts. Don't put things here unless
9806 SpecialRuleRelation:
9813 (errcode(ERRCODE_SYNTAX_ERROR),
9814 errmsg("OLD used in query that is not in a rule"),
9815 scanner_errposition(@1)));
9823 (errcode(ERRCODE_SYNTAX_ERROR),
9824 errmsg("NEW used in query that is not in a rule"),
9825 scanner_errposition(@1)));
9832 makeColumnRef(char *colname, List *indirection, int location)
9835 * Generate a ColumnRef node, with an A_Indirection node added if there
9836 * is any subscripting in the specified indirection list. However,
9837 * any field selection at the start of the indirection list must be
9838 * transposed into the "fields" part of the ColumnRef node.
9840 ColumnRef *c = makeNode(ColumnRef);
9844 c->location = location;
9845 foreach(l, indirection)
9847 if (IsA(lfirst(l), A_Indices))
9849 A_Indirection *i = makeNode(A_Indirection);
9853 /* easy case - all indirection goes to A_Indirection */
9854 c->fields = list_make1(makeString(colname));
9855 i->indirection = check_indirection(indirection);
9859 /* got to split the list in two */
9860 i->indirection = check_indirection(list_copy_tail(indirection,
9862 indirection = list_truncate(indirection, nfields);
9863 c->fields = lcons(makeString(colname), indirection);
9865 i->arg = (Node *) c;
9868 else if (IsA(lfirst(l), A_Star))
9870 /* We only allow '*' at the end of a ColumnRef */
9871 if (lnext(l) != NULL)
9872 yyerror("improper use of \"*\"");
9876 /* No subscripting, so all indirection gets added to field list */
9877 c->fields = lcons(makeString(colname), indirection);
9882 makeTypeCast(Node *arg, TypeName *typename, int location)
9884 TypeCast *n = makeNode(TypeCast);
9886 n->typename = typename;
9887 n->location = location;
9892 makeStringConst(char *str, int location)
9894 A_Const *n = makeNode(A_Const);
9896 n->val.type = T_String;
9897 n->val.val.str = str;
9898 n->location = location;
9904 makeStringConstCast(char *str, int location, TypeName *typename)
9906 Node *s = makeStringConst(str, location);
9908 return makeTypeCast(s, typename, -1);
9912 makeIntConst(int val, int location)
9914 A_Const *n = makeNode(A_Const);
9916 n->val.type = T_Integer;
9917 n->val.val.ival = val;
9918 n->location = location;
9924 makeFloatConst(char *str, int location)
9926 A_Const *n = makeNode(A_Const);
9928 n->val.type = T_Float;
9929 n->val.val.str = str;
9930 n->location = location;
9936 makeBitStringConst(char *str, int location)
9938 A_Const *n = makeNode(A_Const);
9940 n->val.type = T_BitString;
9941 n->val.val.str = str;
9942 n->location = location;
9948 makeNullAConst(int location)
9950 A_Const *n = makeNode(A_Const);
9952 n->val.type = T_Null;
9953 n->location = location;
9959 makeAConst(Value *v, int location)
9966 n = makeFloatConst(v->val.str, location);
9970 n = makeIntConst(v->val.ival, location);
9975 n = makeStringConst(v->val.str, location);
9983 * Create an A_Const string node and put it inside a boolean cast.
9986 makeBoolAConst(bool state, int location)
9988 A_Const *n = makeNode(A_Const);
9990 n->val.type = T_String;
9991 n->val.val.str = (state ? "t" : "f");
9992 n->location = location;
9994 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
9998 * Create and populate a FuncCall node to support the OVERLAPS operator.
10001 makeOverlaps(List *largs, List *rargs, int location)
10003 FuncCall *n = makeNode(FuncCall);
10005 n->funcname = SystemFuncName("overlaps");
10006 if (list_length(largs) == 1)
10007 largs = lappend(largs, largs);
10008 else if (list_length(largs) != 2)
10010 (errcode(ERRCODE_SYNTAX_ERROR),
10011 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
10012 scanner_errposition(location)));
10013 if (list_length(rargs) == 1)
10014 rargs = lappend(rargs, rargs);
10015 else if (list_length(rargs) != 2)
10017 (errcode(ERRCODE_SYNTAX_ERROR),
10018 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
10019 scanner_errposition(location)));
10020 n->args = list_concat(largs, rargs);
10021 n->agg_star = FALSE;
10022 n->agg_distinct = FALSE;
10023 n->func_variadic = FALSE;
10024 n->location = location;
10028 /* check_qualified_name --- check the result of qualified_name production
10030 * It's easiest to let the grammar production for qualified_name allow
10031 * subscripts and '*', which we then must reject here.
10034 check_qualified_name(List *names)
10040 if (!IsA(lfirst(i), String))
10041 yyerror("syntax error");
10045 /* check_func_name --- check the result of func_name production
10047 * It's easiest to let the grammar production for func_name allow subscripts
10048 * and '*', which we then must reject here.
10051 check_func_name(List *names)
10057 if (!IsA(lfirst(i), String))
10058 yyerror("syntax error");
10063 /* check_indirection --- check the result of indirection production
10065 * We only allow '*' at the end of the list, but it's hard to enforce that
10066 * in the grammar, so do it here.
10069 check_indirection(List *indirection)
10073 foreach(l, indirection)
10075 if (IsA(lfirst(l), A_Star))
10077 if (lnext(l) != NULL)
10078 yyerror("improper use of \"*\"");
10081 return indirection;
10084 /* extractArgTypes()
10085 * Given a list of FunctionParameter nodes, extract a list of just the
10086 * argument types (TypeNames) for input parameters only. This is what
10087 * is needed to look up an existing function, which is what is wanted by
10088 * the productions that use this call.
10091 extractArgTypes(List *parameters)
10093 List *result = NIL;
10096 foreach(i, parameters)
10098 FunctionParameter *p = (FunctionParameter *) lfirst(i);
10100 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
10101 result = lappend(result, p->argType);
10106 /* findLeftmostSelect()
10107 * Find the leftmost component SelectStmt in a set-operation parsetree.
10109 static SelectStmt *
10110 findLeftmostSelect(SelectStmt *node)
10112 while (node && node->op != SETOP_NONE)
10114 Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
10118 /* insertSelectOptions()
10119 * Insert ORDER BY, etc into an already-constructed SelectStmt.
10121 * This routine is just to avoid duplicating code in SelectStmt productions.
10124 insertSelectOptions(SelectStmt *stmt,
10125 List *sortClause, List *lockingClause,
10126 Node *limitOffset, Node *limitCount,
10127 WithClause *withClause)
10129 Assert(IsA(stmt, SelectStmt));
10132 * Tests here are to reject constructs like
10133 * (SELECT foo ORDER BY bar) ORDER BY baz
10137 if (stmt->sortClause)
10139 (errcode(ERRCODE_SYNTAX_ERROR),
10140 errmsg("multiple ORDER BY clauses not allowed"),
10141 scanner_errposition(exprLocation((Node *) sortClause))));
10142 stmt->sortClause = sortClause;
10144 /* We can handle multiple locking clauses, though */
10145 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
10148 if (stmt->limitOffset)
10150 (errcode(ERRCODE_SYNTAX_ERROR),
10151 errmsg("multiple OFFSET clauses not allowed"),
10152 scanner_errposition(exprLocation(limitOffset))));
10153 stmt->limitOffset = limitOffset;
10157 if (stmt->limitCount)
10159 (errcode(ERRCODE_SYNTAX_ERROR),
10160 errmsg("multiple LIMIT clauses not allowed"),
10161 scanner_errposition(exprLocation(limitCount))));
10162 stmt->limitCount = limitCount;
10166 if (stmt->withClause)
10168 (errcode(ERRCODE_SYNTAX_ERROR),
10169 errmsg("multiple WITH clauses not allowed"),
10170 scanner_errposition(exprLocation((Node *) withClause))));
10171 stmt->withClause = withClause;
10176 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
10178 SelectStmt *n = makeNode(SelectStmt);
10182 n->larg = (SelectStmt *) larg;
10183 n->rarg = (SelectStmt *) rarg;
10187 /* SystemFuncName()
10188 * Build a properly-qualified reference to a built-in function.
10191 SystemFuncName(char *name)
10193 return list_make2(makeString("pg_catalog"), makeString(name));
10196 /* SystemTypeName()
10197 * Build a properly-qualified reference to a built-in type.
10199 * typmod is defaulted, but may be changed afterwards by caller.
10200 * Likewise for the location.
10203 SystemTypeName(char *name)
10205 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
10206 makeString(name)));
10210 * Handle negation of a numeric constant.
10212 * Formerly, we did this here because the optimizer couldn't cope with
10213 * indexquals that looked like "var = -4" --- it wants "var = const"
10214 * and a unary minus operator applied to a constant didn't qualify.
10215 * As of Postgres 7.0, that problem doesn't exist anymore because there
10216 * is a constant-subexpression simplifier in the optimizer. However,
10217 * there's still a good reason for doing this here, which is that we can
10218 * postpone committing to a particular internal representation for simple
10219 * negative constants. It's better to leave "-123.456" in string form
10220 * until we know what the desired type is.
10223 doNegate(Node *n, int location)
10225 if (IsA(n, A_Const))
10227 A_Const *con = (A_Const *)n;
10229 /* report the constant's location as that of the '-' sign */
10230 con->location = location;
10232 if (con->val.type == T_Integer)
10234 con->val.val.ival = -con->val.val.ival;
10237 if (con->val.type == T_Float)
10239 doNegateFloat(&con->val);
10244 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
10248 doNegateFloat(Value *v)
10250 char *oldval = v->val.str;
10252 Assert(IsA(v, Float));
10253 if (*oldval == '+')
10255 if (*oldval == '-')
10256 v->val.str = oldval+1; /* just strip the '-' */
10259 char *newval = (char *) palloc(strlen(oldval) + 2);
10262 strcpy(newval+1, oldval);
10263 v->val.str = newval;
10268 makeAArrayExpr(List *elements, int location)
10270 A_ArrayExpr *n = makeNode(A_ArrayExpr);
10272 n->elements = elements;
10273 n->location = location;
10278 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
10281 XmlExpr *x = makeNode(XmlExpr);
10286 * named_args is a list of ResTarget; it'll be split apart into separate
10287 * expression and name lists in transformXmlExpr().
10289 x->named_args = named_args;
10290 x->arg_names = NIL;
10292 /* xmloption, if relevant, must be filled in by caller */
10293 /* type and typmod will be filled in during parse analysis */
10294 x->location = location;
10299 * Initialize to parse one query string
10304 QueryIsRule = FALSE;
10308 * Merge the input and output parameters of a table function.
10311 mergeTableFuncParameters(List *func_args, List *columns)
10315 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
10316 foreach(lc, func_args)
10318 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
10320 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
10322 (errcode(ERRCODE_SYNTAX_ERROR),
10323 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
10326 return list_concat(func_args, columns);
10330 * Determine return type of a TABLE function. A single result column
10331 * returns setof that column's type; otherwise return setof record.
10334 TableFuncTypeName(List *columns)
10338 if (list_length(columns) == 1)
10340 FunctionParameter *p = (FunctionParameter *) linitial(columns);
10342 result = (TypeName *) copyObject(p->argType);
10345 result = SystemTypeName("record");
10347 result->setof = true;
10353 * Must undefine base_yylex before including scan.c, since we want it
10354 * to create the function base_yylex not filtered_base_yylex.