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.640 2008/11/24 08:46:03 petere Exp $
17 * AUTHOR DATE MAJOR EVENT
18 * Andrew Yu Sept, 1994 POSTQUEL to SQL conversion
19 * Andrew Yu Oct, 1994 lispy code conversion
22 * CAPITALS are used to represent terminal symbols.
23 * non-capitals are used to represent non-terminals.
24 * SQL92-specific syntax is separated from plain SQL/Postgres syntax
25 * to help isolate the non-extensible portions of the parser.
27 * In general, nothing in this file should initiate database accesses
28 * nor depend on changeable state (such as SET variables). If you do
29 * database accesses, your code will fail when we have aborted the
30 * current transaction and are just parsing commands to find the next
31 * ROLLBACK or COMMIT. If you make use of SET variables, then you
32 * will do the wrong thing in multi-query strings like this:
33 * SET SQL_inheritance TO off; SELECT * FROM foo;
34 * because the entire string is parsed by gram.y before the SET gets
35 * executed. Anything that depends on the database or changeable state
36 * should be handled during parse analysis so that it happens at the
37 * right time not the wrong time. The handling of SQL_inheritance is
41 * If you use a list, make sure the datum is a node so that the printing
44 * Sometimes we assign constants to makeStrings. Make sure we don't free
47 *-------------------------------------------------------------------------
54 #include "catalog/index.h"
55 #include "catalog/namespace.h"
56 #include "commands/defrem.h"
57 #include "nodes/makefuncs.h"
58 #include "nodes/nodeFuncs.h"
59 #include "parser/gramparse.h"
60 #include "storage/lmgr.h"
61 #include "utils/date.h"
62 #include "utils/datetime.h"
63 #include "utils/numeric.h"
64 #include "utils/xml.h"
67 /* Location tracking support --- simpler than bison's default */
68 #define YYLLOC_DEFAULT(Current, Rhs, N) \
71 (Current) = (Rhs)[1]; \
73 (Current) = (Rhs)[0]; \
77 * The %name-prefix option below will make bison call base_yylex, but we
78 * really want it to call filtered_base_yylex (see parser.c).
80 #define base_yylex filtered_base_yylex
83 * Bison doesn't allocate anything that needs to live across parser calls,
84 * so we can easily have it use palloc instead of malloc. This prevents
85 * memory leaks if we error out during parsing. Note this only works with
86 * bison >= 2.0. However, in bison 1.875 the default is to use alloca()
87 * if possible, so there's not really much problem anyhow, at least if
88 * you're building with gcc.
90 #define YYMALLOC palloc
93 extern List *parsetree; /* final parse result is delivered here */
95 static bool QueryIsRule = FALSE;
98 * If you need access to certain yacc-generated variables and find that
99 * they're static by default, uncomment the next line. (this is not a
102 /*#define __YYSCLASS*/
104 static Node *makeColumnRef(char *colname, List *indirection, int location);
105 static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
106 static Node *makeStringConst(char *str, int location);
107 static Node *makeStringConstCast(char *str, int location, TypeName *typename);
108 static Node *makeIntConst(int val, int location);
109 static Node *makeFloatConst(char *str, int location);
110 static Node *makeBitStringConst(char *str, int location);
111 static Node *makeNullAConst(int location);
112 static Node *makeAConst(Value *v, int location);
113 static Node *makeBoolAConst(bool state, int location);
114 static FuncCall *makeOverlaps(List *largs, List *rargs, int location);
115 static void check_qualified_name(List *names);
116 static List *check_func_name(List *names);
117 static List *check_indirection(List *indirection);
118 static List *extractArgTypes(List *parameters);
119 static SelectStmt *findLeftmostSelect(SelectStmt *node);
120 static void insertSelectOptions(SelectStmt *stmt,
121 List *sortClause, List *lockingClause,
122 Node *limitOffset, Node *limitCount,
123 WithClause *withClause);
124 static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
125 static Node *doNegate(Node *n, int location);
126 static void doNegateFloat(Value *v);
127 static Node *makeAArrayExpr(List *elements, int location);
128 static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
129 List *args, int location);
130 static List *mergeTableFuncParameters(List *func_args, List *columns);
131 static TypeName *TableFuncTypeName(List *columns);
135 %name-prefix="base_yy"
146 DropBehavior dbehavior;
147 OnCommitAction oncommit;
154 FunctionParameter *fun_param;
155 FunctionParameterMode fun_param_mode;
156 FuncWithArgs *funwithargs;
167 PrivTarget *privtarget;
170 VariableSetStmt *vsetstmt;
173 %type <node> stmt schema_stmt
174 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterGroupStmt
175 AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterTableStmt
176 AlterUserStmt AlterUserSetStmt AlterRoleStmt AlterRoleSetStmt
177 AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
178 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
179 CreateDomainStmt CreateGroupStmt CreateOpClassStmt
180 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
181 CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
182 CreateAssertStmt CreateTrigStmt CreateUserStmt CreateRoleStmt
183 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt
184 DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
185 DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
186 DropUserStmt DropdbStmt DropTableSpaceStmt ExplainStmt FetchStmt
187 GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
188 LockStmt NotifyStmt ExplainableStmt PreparableStmt
189 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
190 RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
191 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
192 SelectStmt TransactionStmt TruncateStmt
193 UnlistenStmt UpdateStmt VacuumStmt
194 VariableResetStmt VariableSetStmt VariableShowStmt
195 ViewStmt CheckPointStmt CreateConversionStmt
196 DeallocateStmt PrepareStmt ExecuteStmt
197 DropOwnedStmt ReassignOwnedStmt
198 AlterTSConfigurationStmt AlterTSDictionaryStmt
200 %type <node> select_no_parens select_with_parens select_clause
201 simple_select values_clause
203 %type <node> alter_column_default opclass_item opclass_drop alter_using
204 %type <ival> add_drop opt_asc_desc opt_nulls_order
206 %type <node> alter_table_cmd
207 %type <list> alter_table_cmds
209 %type <dbehavior> opt_drop_behavior
211 %type <list> createdb_opt_list alterdb_opt_list copy_opt_list
212 transaction_mode_list
213 %type <defelt> createdb_opt_item alterdb_opt_item copy_opt_item
214 transaction_mode_item
216 %type <ival> opt_lock lock_type cast_context
217 %type <boolean> opt_force opt_or_replace
218 opt_grant_grant_option opt_grant_admin_option
219 opt_nowait opt_if_exists 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 [VERBOSE] <qualified_name> [ USING <index_name> ]
5786 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
5788 *****************************************************************************/
5791 CLUSTER opt_verbose qualified_name cluster_index_specification
5793 ClusterStmt *n = makeNode(ClusterStmt);
5799 | CLUSTER opt_verbose
5801 ClusterStmt *n = makeNode(ClusterStmt);
5803 n->indexname = NULL;
5807 /* kept for pre-8.3 compatibility */
5808 | CLUSTER opt_verbose index_name ON qualified_name
5810 ClusterStmt *n = makeNode(ClusterStmt);
5818 cluster_index_specification:
5819 USING index_name { $$ = $2; }
5820 | /*EMPTY*/ { $$ = NULL; }
5824 /*****************************************************************************
5830 *****************************************************************************/
5832 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
5834 VacuumStmt *n = makeNode(VacuumStmt);
5838 n->freeze_min_age = $3 ? 0 : -1;
5844 | VACUUM opt_full opt_freeze opt_verbose qualified_name
5846 VacuumStmt *n = makeNode(VacuumStmt);
5850 n->freeze_min_age = $3 ? 0 : -1;
5856 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
5858 VacuumStmt *n = (VacuumStmt *) $5;
5861 n->freeze_min_age = $3 ? 0 : -1;
5868 analyze_keyword opt_verbose
5870 VacuumStmt *n = makeNode(VacuumStmt);
5874 n->freeze_min_age = -1;
5880 | analyze_keyword opt_verbose qualified_name opt_name_list
5882 VacuumStmt *n = makeNode(VacuumStmt);
5886 n->freeze_min_age = -1;
5896 | ANALYSE /* British */ {}
5900 VERBOSE { $$ = TRUE; }
5901 | /*EMPTY*/ { $$ = FALSE; }
5904 opt_full: FULL { $$ = TRUE; }
5905 | /*EMPTY*/ { $$ = FALSE; }
5908 opt_freeze: FREEZE { $$ = TRUE; }
5909 | /*EMPTY*/ { $$ = FALSE; }
5913 '(' name_list ')' { $$ = $2; }
5914 | /*EMPTY*/ { $$ = NIL; }
5918 /*****************************************************************************
5921 * EXPLAIN [ANALYZE] [VERBOSE] query
5923 *****************************************************************************/
5925 ExplainStmt: EXPLAIN opt_analyze opt_verbose ExplainableStmt
5927 ExplainStmt *n = makeNode(ExplainStmt);
5942 | ExecuteStmt /* by default all are $$=$1 */
5946 analyze_keyword { $$ = TRUE; }
5947 | /* EMPTY */ { $$ = FALSE; }
5950 /*****************************************************************************
5953 * PREPARE <plan_name> [(args, ...)] AS <query>
5955 *****************************************************************************/
5957 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
5959 PrepareStmt *n = makeNode(PrepareStmt);
5967 prep_type_clause: '(' type_list ')' { $$ = $2; }
5968 | /* EMPTY */ { $$ = NIL; }
5975 | DeleteStmt /* by default all are $$=$1 */
5978 /*****************************************************************************
5980 * EXECUTE <plan_name> [(params, ...)]
5981 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
5983 *****************************************************************************/
5985 ExecuteStmt: EXECUTE name execute_param_clause
5987 ExecuteStmt *n = makeNode(ExecuteStmt);
5993 | CREATE OptTemp TABLE create_as_target AS
5994 EXECUTE name execute_param_clause
5996 ExecuteStmt *n = makeNode(ExecuteStmt);
5999 $4->rel->istemp = $2;
6003 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6004 errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
6005 /* ... because it's not implemented, but it could be */
6010 execute_param_clause: '(' expr_list ')' { $$ = $2; }
6011 | /* EMPTY */ { $$ = NIL; }
6014 /*****************************************************************************
6017 * DEALLOCATE [PREPARE] <plan_name>
6019 *****************************************************************************/
6021 DeallocateStmt: DEALLOCATE name
6023 DeallocateStmt *n = makeNode(DeallocateStmt);
6027 | DEALLOCATE PREPARE name
6029 DeallocateStmt *n = makeNode(DeallocateStmt);
6035 DeallocateStmt *n = makeNode(DeallocateStmt);
6039 | DEALLOCATE PREPARE ALL
6041 DeallocateStmt *n = makeNode(DeallocateStmt);
6047 /*****************************************************************************
6052 *****************************************************************************/
6055 INSERT INTO qualified_name insert_rest returning_clause
6058 $4->returningList = $5;
6066 $$ = makeNode(InsertStmt);
6068 $$->selectStmt = $1;
6070 | '(' insert_column_list ')' SelectStmt
6072 $$ = makeNode(InsertStmt);
6074 $$->selectStmt = $4;
6078 $$ = makeNode(InsertStmt);
6080 $$->selectStmt = NULL;
6086 { $$ = list_make1($1); }
6087 | insert_column_list ',' insert_column_item
6088 { $$ = lappend($1, $3); }
6092 ColId opt_indirection
6094 $$ = makeNode(ResTarget);
6096 $$->indirection = check_indirection($2);
6103 RETURNING target_list { $$ = $2; }
6104 | /* EMPTY */ { $$ = NIL; }
6108 /*****************************************************************************
6113 *****************************************************************************/
6115 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
6116 using_clause where_or_current_clause returning_clause
6118 DeleteStmt *n = makeNode(DeleteStmt);
6120 n->usingClause = $4;
6121 n->whereClause = $5;
6122 n->returningList = $6;
6128 USING from_list { $$ = $2; }
6129 | /*EMPTY*/ { $$ = NIL; }
6132 LockStmt: LOCK_P opt_table qualified_name_list opt_lock opt_nowait
6134 LockStmt *n = makeNode(LockStmt);
6143 opt_lock: IN_P lock_type MODE { $$ = $2; }
6144 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
6147 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
6148 | ROW SHARE { $$ = RowShareLock; }
6149 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
6150 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
6151 | SHARE { $$ = ShareLock; }
6152 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
6153 | EXCLUSIVE { $$ = ExclusiveLock; }
6154 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
6157 opt_nowait: NOWAIT { $$ = TRUE; }
6158 | /*EMPTY*/ { $$ = FALSE; }
6162 /*****************************************************************************
6165 * UpdateStmt (UPDATE)
6167 *****************************************************************************/
6169 UpdateStmt: UPDATE relation_expr_opt_alias
6172 where_or_current_clause
6175 UpdateStmt *n = makeNode(UpdateStmt);
6179 n->whereClause = $6;
6180 n->returningList = $7;
6186 set_clause { $$ = $1; }
6187 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
6191 single_set_clause { $$ = list_make1($1); }
6192 | multiple_set_clause { $$ = $1; }
6196 set_target '=' ctext_expr
6199 $$->val = (Node *) $3;
6203 multiple_set_clause:
6204 '(' set_target_list ')' '=' ctext_row
6210 * Break the ctext_row apart, merge individual expressions
6211 * into the destination ResTargets. XXX this approach
6212 * cannot work for general row expressions as sources.
6214 if (list_length($2) != list_length($5))
6216 (errcode(ERRCODE_SYNTAX_ERROR),
6217 errmsg("number of columns does not match number of values"),
6218 scanner_errposition(@1)));
6219 forboth(col_cell, $2, val_cell, $5)
6221 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
6222 Node *res_val = (Node *) lfirst(val_cell);
6224 res_col->val = res_val;
6232 ColId opt_indirection
6234 $$ = makeNode(ResTarget);
6236 $$->indirection = check_indirection($2);
6237 $$->val = NULL; /* upper production sets this */
6243 set_target { $$ = list_make1($1); }
6244 | set_target_list ',' set_target { $$ = lappend($1,$3); }
6248 /*****************************************************************************
6253 *****************************************************************************/
6254 DeclareCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR SelectStmt
6256 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
6258 /* currently we always set FAST_PLAN option */
6259 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
6265 cursor_options: /*EMPTY*/ { $$ = 0; }
6266 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
6267 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
6268 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
6269 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
6272 opt_hold: /* EMPTY */ { $$ = 0; }
6273 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
6274 | WITHOUT HOLD { $$ = 0; }
6277 /*****************************************************************************
6282 *****************************************************************************/
6284 /* A complete SELECT statement looks like this.
6286 * The rule returns either a single SelectStmt node or a tree of them,
6287 * representing a set-operation tree.
6289 * There is an ambiguity when a sub-SELECT is within an a_expr and there
6290 * are excess parentheses: do the parentheses belong to the sub-SELECT or
6291 * to the surrounding a_expr? We don't really care, but yacc wants to know.
6292 * To resolve the ambiguity, we are careful to define the grammar so that
6293 * the decision is staved off as long as possible: as long as we can keep
6294 * absorbing parentheses into the sub-SELECT, we will do so, and only when
6295 * it's no longer possible to do that will we decide that parens belong to
6296 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
6297 * parentheses are treated as part of the sub-select. The necessity of doing
6298 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
6299 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
6300 * SELECT viewpoint when we see the UNION.
6302 * This approach is implemented by defining a nonterminal select_with_parens,
6303 * which represents a SELECT with at least one outer layer of parentheses,
6304 * and being careful to use select_with_parens, never '(' SelectStmt ')',
6305 * in the expression grammar. We will then have shift-reduce conflicts
6306 * which we can resolve in favor of always treating '(' <select> ')' as
6307 * a select_with_parens. To resolve the conflicts, the productions that
6308 * conflict with the select_with_parens productions are manually given
6309 * precedences lower than the precedence of ')', thereby ensuring that we
6310 * shift ')' (and then reduce to select_with_parens) rather than trying to
6311 * reduce the inner <select> nonterminal to something else. We use UMINUS
6312 * precedence for this, which is a fairly arbitrary choice.
6314 * To be able to define select_with_parens itself without ambiguity, we need
6315 * a nonterminal select_no_parens that represents a SELECT structure with no
6316 * outermost parentheses. This is a little bit tedious, but it works.
6318 * In non-expression contexts, we use SelectStmt which can represent a SELECT
6319 * with or without outer parentheses.
6322 SelectStmt: select_no_parens %prec UMINUS
6323 | select_with_parens %prec UMINUS
6327 '(' select_no_parens ')' { $$ = $2; }
6328 | '(' select_with_parens ')' { $$ = $2; }
6332 * This rule parses the equivalent of the standard's <query expression>.
6333 * The duplicative productions are annoying, but hard to get rid of without
6334 * creating shift/reduce conflicts.
6336 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
6337 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
6338 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
6342 simple_select { $$ = $1; }
6343 | select_clause sort_clause
6345 insertSelectOptions((SelectStmt *) $1, $2, NIL,
6349 | select_clause opt_sort_clause for_locking_clause opt_select_limit
6351 insertSelectOptions((SelectStmt *) $1, $2, $3,
6352 list_nth($4, 0), list_nth($4, 1),
6356 | select_clause opt_sort_clause select_limit opt_for_locking_clause
6358 insertSelectOptions((SelectStmt *) $1, $2, $4,
6359 list_nth($3, 0), list_nth($3, 1),
6363 | with_clause simple_select
6365 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
6370 | with_clause select_clause sort_clause
6372 insertSelectOptions((SelectStmt *) $2, $3, NIL,
6377 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
6379 insertSelectOptions((SelectStmt *) $2, $3, $4,
6380 list_nth($5, 0), list_nth($5, 1),
6384 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
6386 insertSelectOptions((SelectStmt *) $2, $3, $5,
6387 list_nth($4, 0), list_nth($4, 1),
6394 simple_select { $$ = $1; }
6395 | select_with_parens { $$ = $1; }
6399 * This rule parses SELECT statements that can appear within set operations,
6400 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
6401 * the ordering of the set operations. Without '(' and ')' we want the
6402 * operations to be ordered per the precedence specs at the head of this file.
6404 * As with select_no_parens, simple_select cannot have outer parentheses,
6405 * but can have parenthesized subclauses.
6407 * Note that sort clauses cannot be included at this level --- SQL92 requires
6408 * SELECT foo UNION SELECT bar ORDER BY baz
6410 * (SELECT foo UNION SELECT bar) ORDER BY baz
6412 * SELECT foo UNION (SELECT bar ORDER BY baz)
6413 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
6414 * described as part of the select_no_parens production, not simple_select.
6415 * This does not limit functionality, because you can reintroduce these
6416 * clauses inside parentheses.
6418 * NOTE: only the leftmost component SelectStmt should have INTO.
6419 * However, this is not checked by the grammar; parse analysis must check it.
6422 SELECT opt_distinct target_list
6423 into_clause from_clause where_clause
6424 group_clause having_clause
6426 SelectStmt *n = makeNode(SelectStmt);
6427 n->distinctClause = $2;
6431 n->whereClause = $6;
6432 n->groupClause = $7;
6433 n->havingClause = $8;
6436 | values_clause { $$ = $1; }
6437 | TABLE relation_expr
6439 /* same as SELECT * FROM relation_expr */
6440 ColumnRef *cr = makeNode(ColumnRef);
6441 ResTarget *rt = makeNode(ResTarget);
6442 SelectStmt *n = makeNode(SelectStmt);
6444 cr->fields = list_make1(makeNode(A_Star));
6448 rt->indirection = NIL;
6449 rt->val = (Node *)cr;
6452 n->targetList = list_make1(rt);
6453 n->fromClause = list_make1($2);
6456 | select_clause UNION opt_all select_clause
6458 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
6460 | select_clause INTERSECT opt_all select_clause
6462 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
6464 | select_clause EXCEPT opt_all select_clause
6466 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
6471 * SQL standard WITH clause looks like:
6473 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
6474 * AS (query) [ SEARCH or CYCLE clause ]
6476 * We don't currently support the SEARCH or CYCLE clause.
6481 $$ = makeNode(WithClause);
6483 $$->recursive = false;
6486 | WITH RECURSIVE cte_list
6488 $$ = makeNode(WithClause);
6490 $$->recursive = true;
6496 common_table_expr { $$ = list_make1($1); }
6497 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
6500 common_table_expr: name opt_name_list AS select_with_parens
6502 CommonTableExpr *n = makeNode(CommonTableExpr);
6504 n->aliascolnames = $2;
6512 INTO OptTempTableName
6514 $$ = makeNode(IntoClause);
6518 $$->onCommit = ONCOMMIT_NOOP;
6519 $$->tableSpaceName = NULL;
6526 * Redundancy here is needed to avoid shift/reduce conflicts,
6527 * since TEMP is not a reserved word. See also OptTemp.
6530 TEMPORARY opt_table qualified_name
6535 | TEMP opt_table qualified_name
6540 | LOCAL TEMPORARY opt_table qualified_name
6545 | LOCAL TEMP opt_table qualified_name
6550 | GLOBAL TEMPORARY opt_table qualified_name
6555 | GLOBAL TEMP opt_table qualified_name
6560 | TABLE qualified_name
6576 opt_all: ALL { $$ = TRUE; }
6577 | DISTINCT { $$ = FALSE; }
6578 | /*EMPTY*/ { $$ = FALSE; }
6581 /* We use (NIL) as a placeholder to indicate that all target expressions
6582 * should be placed in the DISTINCT list during parsetree analysis.
6585 DISTINCT { $$ = list_make1(NIL); }
6586 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
6588 | /*EMPTY*/ { $$ = NIL; }
6592 sort_clause { $$ = $1;}
6593 | /*EMPTY*/ { $$ = NIL; }
6597 ORDER BY sortby_list { $$ = $3; }
6601 sortby { $$ = list_make1($1); }
6602 | sortby_list ',' sortby { $$ = lappend($1, $3); }
6605 sortby: a_expr USING qual_all_Op opt_nulls_order
6607 $$ = makeNode(SortBy);
6609 $$->sortby_dir = SORTBY_USING;
6610 $$->sortby_nulls = $4;
6614 | a_expr opt_asc_desc opt_nulls_order
6616 $$ = makeNode(SortBy);
6618 $$->sortby_dir = $2;
6619 $$->sortby_nulls = $3;
6621 $$->location = -1; /* no operator */
6627 LIMIT select_limit_value OFFSET select_offset_value
6628 { $$ = list_make2($4, $2); }
6629 | OFFSET select_offset_value LIMIT select_limit_value
6630 { $$ = list_make2($2, $4); }
6631 | LIMIT select_limit_value
6632 { $$ = list_make2(NULL, $2); }
6633 | OFFSET select_offset_value
6634 { $$ = list_make2($2, NULL); }
6635 | LIMIT select_limit_value ',' select_offset_value
6637 /* Disabled because it was too confusing, bjm 2002-02-18 */
6639 (errcode(ERRCODE_SYNTAX_ERROR),
6640 errmsg("LIMIT #,# syntax is not supported"),
6641 errhint("Use separate LIMIT and OFFSET clauses."),
6642 scanner_errposition(@1)));
6644 /* SQL:2008 syntax variants */
6645 | OFFSET select_offset_value2 row_or_rows
6646 { $$ = list_make2($2, NULL); }
6647 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
6648 { $$ = list_make2(NULL, $3); }
6649 | OFFSET select_offset_value2 row_or_rows FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
6650 { $$ = list_make2($2, $6); }
6654 select_limit { $$ = $1; }
6656 { $$ = list_make2(NULL,NULL); }
6663 /* LIMIT ALL is represented as a NULL constant */
6664 $$ = makeNullAConst(@1);
6669 * Allowing full expressions without parentheses causes various parsing
6670 * problems with the trailing ROW/ROWS key words. SQL only calls for
6671 * constants, so we allow the rest only with parentheses.
6673 opt_select_fetch_first_value:
6674 SignedIconst { $$ = makeIntConst($1, @1); }
6675 | '(' a_expr ')' { $$ = $2; }
6676 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
6679 select_offset_value:
6684 * Again, the trailing ROW/ROWS in this case prevent the full expression
6685 * syntax. c_expr is the best we can do.
6687 select_offset_value2:
6704 GROUP_P BY expr_list { $$ = $3; }
6705 | /*EMPTY*/ { $$ = NIL; }
6709 HAVING a_expr { $$ = $2; }
6710 | /*EMPTY*/ { $$ = NULL; }
6714 for_locking_items { $$ = $1; }
6715 | FOR READ ONLY { $$ = NIL; }
6718 opt_for_locking_clause:
6719 for_locking_clause { $$ = $1; }
6720 | /* EMPTY */ { $$ = NIL; }
6724 for_locking_item { $$ = list_make1($1); }
6725 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
6729 FOR UPDATE locked_rels_list opt_nowait
6731 LockingClause *n = makeNode(LockingClause);
6733 n->forUpdate = TRUE;
6737 | FOR SHARE locked_rels_list opt_nowait
6739 LockingClause *n = makeNode(LockingClause);
6741 n->forUpdate = FALSE;
6748 OF qualified_name_list { $$ = $2; }
6749 | /* EMPTY */ { $$ = NIL; }
6756 SelectStmt *n = makeNode(SelectStmt);
6757 n->valuesLists = list_make1($2);
6760 | values_clause ',' ctext_row
6762 SelectStmt *n = (SelectStmt *) $1;
6763 n->valuesLists = lappend(n->valuesLists, $3);
6769 /*****************************************************************************
6771 * clauses common to all Optimizable Stmts:
6772 * from_clause - allow list of both JOIN expressions and table names
6773 * where_clause - qualifications for joins or restrictions
6775 *****************************************************************************/
6778 FROM from_list { $$ = $2; }
6779 | /*EMPTY*/ { $$ = NIL; }
6783 table_ref { $$ = list_make1($1); }
6784 | from_list ',' table_ref { $$ = lappend($1, $3); }
6788 * table_ref is where an alias clause can be attached. Note we cannot make
6789 * alias_clause have an empty production because that causes parse conflicts
6790 * between table_ref := '(' joined_table ')' alias_clause
6791 * and joined_table := '(' joined_table ')'. So, we must have the
6792 * redundant-looking productions here instead.
6794 table_ref: relation_expr
6798 | relation_expr alias_clause
6805 RangeFunction *n = makeNode(RangeFunction);
6806 n->funccallnode = $1;
6807 n->coldeflist = NIL;
6810 | func_table alias_clause
6812 RangeFunction *n = makeNode(RangeFunction);
6813 n->funccallnode = $1;
6815 n->coldeflist = NIL;
6818 | func_table AS '(' TableFuncElementList ')'
6820 RangeFunction *n = makeNode(RangeFunction);
6821 n->funccallnode = $1;
6825 | func_table AS ColId '(' TableFuncElementList ')'
6827 RangeFunction *n = makeNode(RangeFunction);
6828 Alias *a = makeNode(Alias);
6829 n->funccallnode = $1;
6835 | func_table ColId '(' TableFuncElementList ')'
6837 RangeFunction *n = makeNode(RangeFunction);
6838 Alias *a = makeNode(Alias);
6839 n->funccallnode = $1;
6845 | select_with_parens
6848 * The SQL spec does not permit a subselect
6849 * (<derived_table>) without an alias clause,
6850 * so we don't either. This avoids the problem
6851 * of needing to invent a unique refname for it.
6852 * That could be surmounted if there's sufficient
6853 * popular demand, but for now let's just implement
6854 * the spec and see if anyone complains.
6855 * However, it does seem like a good idea to emit
6856 * an error message that's better than "syntax error".
6858 if (IsA($1, SelectStmt) &&
6859 ((SelectStmt *) $1)->valuesLists)
6861 (errcode(ERRCODE_SYNTAX_ERROR),
6862 errmsg("VALUES in FROM must have an alias"),
6863 errhint("For example, FROM (VALUES ...) [AS] foo."),
6864 scanner_errposition(@1)));
6867 (errcode(ERRCODE_SYNTAX_ERROR),
6868 errmsg("subquery in FROM must have an alias"),
6869 errhint("For example, FROM (SELECT ...) [AS] foo."),
6870 scanner_errposition(@1)));
6873 | select_with_parens alias_clause
6875 RangeSubselect *n = makeNode(RangeSubselect);
6884 | '(' joined_table ')' alias_clause
6893 * It may seem silly to separate joined_table from table_ref, but there is
6894 * method in SQL92's madness: if you don't do it this way you get reduce-
6895 * reduce conflicts, because it's not clear to the parser generator whether
6896 * to expect alias_clause after ')' or not. For the same reason we must
6897 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
6898 * join_type to expand to empty; if we try it, the parser generator can't
6899 * figure out when to reduce an empty join_type right after table_ref.
6901 * Note that a CROSS JOIN is the same as an unqualified
6902 * INNER JOIN, and an INNER JOIN/ON has the same shape
6903 * but a qualification expression to limit membership.
6904 * A NATURAL JOIN implicitly matches column names between
6905 * tables and the shape is determined by which columns are
6906 * in common. We'll collect columns during the later transformations.
6910 '(' joined_table ')'
6914 | table_ref CROSS JOIN table_ref
6916 /* CROSS JOIN is same as unqualified inner join */
6917 JoinExpr *n = makeNode(JoinExpr);
6918 n->jointype = JOIN_INNER;
6919 n->isNatural = FALSE;
6926 | table_ref join_type JOIN table_ref join_qual
6928 JoinExpr *n = makeNode(JoinExpr);
6930 n->isNatural = FALSE;
6933 if ($5 != NULL && IsA($5, List))
6934 n->using = (List *) $5; /* USING clause */
6936 n->quals = $5; /* ON clause */
6939 | table_ref JOIN table_ref join_qual
6941 /* letting join_type reduce to empty doesn't work */
6942 JoinExpr *n = makeNode(JoinExpr);
6943 n->jointype = JOIN_INNER;
6944 n->isNatural = FALSE;
6947 if ($4 != NULL && IsA($4, List))
6948 n->using = (List *) $4; /* USING clause */
6950 n->quals = $4; /* ON clause */
6953 | table_ref NATURAL join_type JOIN table_ref
6955 JoinExpr *n = makeNode(JoinExpr);
6957 n->isNatural = TRUE;
6960 n->using = NIL; /* figure out which columns later... */
6961 n->quals = NULL; /* fill later */
6964 | table_ref NATURAL JOIN table_ref
6966 /* letting join_type reduce to empty doesn't work */
6967 JoinExpr *n = makeNode(JoinExpr);
6968 n->jointype = JOIN_INNER;
6969 n->isNatural = TRUE;
6972 n->using = NIL; /* figure out which columns later... */
6973 n->quals = NULL; /* fill later */
6979 AS ColId '(' name_list ')'
6981 $$ = makeNode(Alias);
6987 $$ = makeNode(Alias);
6990 | ColId '(' name_list ')'
6992 $$ = makeNode(Alias);
6998 $$ = makeNode(Alias);
7003 join_type: FULL join_outer { $$ = JOIN_FULL; }
7004 | LEFT join_outer { $$ = JOIN_LEFT; }
7005 | RIGHT join_outer { $$ = JOIN_RIGHT; }
7006 | INNER_P { $$ = JOIN_INNER; }
7009 /* OUTER is just noise... */
7010 join_outer: OUTER_P { $$ = NULL; }
7011 | /*EMPTY*/ { $$ = NULL; }
7014 /* JOIN qualification clauses
7015 * Possibilities are:
7016 * USING ( column list ) allows only unqualified column names,
7017 * which must match between tables.
7018 * ON expr allows more general qualifications.
7020 * We return USING as a List node, while an ON-expr will not be a List.
7023 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
7024 | ON a_expr { $$ = $2; }
7031 /* default inheritance */
7033 $$->inhOpt = INH_DEFAULT;
7036 | qualified_name '*'
7038 /* inheritance query */
7040 $$->inhOpt = INH_YES;
7043 | ONLY qualified_name
7045 /* no inheritance */
7047 $$->inhOpt = INH_NO;
7050 | ONLY '(' qualified_name ')'
7052 /* no inheritance, SQL99-style syntax */
7054 $$->inhOpt = INH_NO;
7061 * Given "UPDATE foo set set ...", we have to decide without looking any
7062 * further ahead whether the first "set" is an alias or the UPDATE's SET
7063 * keyword. Since "set" is allowed as a column name both interpretations
7064 * are feasible. We resolve the shift/reduce conflict by giving the first
7065 * relation_expr_opt_alias production a higher precedence than the SET token
7066 * has, causing the parser to prefer to reduce, in effect assuming that the
7067 * SET is not an alias.
7069 relation_expr_opt_alias: relation_expr %prec UMINUS
7073 | relation_expr ColId
7075 Alias *alias = makeNode(Alias);
7076 alias->aliasname = $2;
7080 | relation_expr AS ColId
7082 Alias *alias = makeNode(Alias);
7083 alias->aliasname = $3;
7090 func_table: func_expr { $$ = $1; }
7095 WHERE a_expr { $$ = $2; }
7096 | /*EMPTY*/ { $$ = NULL; }
7099 /* variant for UPDATE and DELETE */
7100 where_or_current_clause:
7101 WHERE a_expr { $$ = $2; }
7102 | WHERE CURRENT_P OF name
7104 CurrentOfExpr *n = makeNode(CurrentOfExpr);
7105 /* cvarno is filled in by parse analysis */
7106 n->cursor_name = $4;
7107 n->cursor_param = 0;
7110 | WHERE CURRENT_P OF PARAM
7112 CurrentOfExpr *n = makeNode(CurrentOfExpr);
7113 /* cvarno is filled in by parse analysis */
7114 n->cursor_name = NULL;
7115 n->cursor_param = $4;
7118 | /*EMPTY*/ { $$ = NULL; }
7122 TableFuncElementList:
7125 $$ = list_make1($1);
7127 | TableFuncElementList ',' TableFuncElement
7129 $$ = lappend($1, $3);
7133 TableFuncElement: ColId Typename
7135 ColumnDef *n = makeNode(ColumnDef);
7138 n->constraints = NIL;
7144 /*****************************************************************************
7147 * SQL92 introduces a large amount of type-specific syntax.
7148 * Define individual clauses to handle these cases, and use
7149 * the generic case to handle regular type-extensible Postgres syntax.
7150 * - thomas 1997-10-10
7152 *****************************************************************************/
7154 Typename: SimpleTypename opt_array_bounds
7157 $$->arrayBounds = $2;
7159 | SETOF SimpleTypename opt_array_bounds
7162 $$->arrayBounds = $3;
7165 /* SQL standard syntax, currently only one-dimensional */
7166 | SimpleTypename ARRAY '[' Iconst ']'
7169 $$->arrayBounds = list_make1(makeInteger($4));
7171 | SETOF SimpleTypename ARRAY '[' Iconst ']'
7174 $$->arrayBounds = list_make1(makeInteger($5));
7177 | SimpleTypename ARRAY
7180 $$->arrayBounds = list_make1(makeInteger(-1));
7182 | SETOF SimpleTypename ARRAY
7185 $$->arrayBounds = list_make1(makeInteger(-1));
7191 opt_array_bounds '[' ']'
7192 { $$ = lappend($1, makeInteger(-1)); }
7193 | opt_array_bounds '[' Iconst ']'
7194 { $$ = lappend($1, makeInteger($3)); }
7200 GenericType { $$ = $1; }
7201 | Numeric { $$ = $1; }
7203 | Character { $$ = $1; }
7204 | ConstDatetime { $$ = $1; }
7205 | ConstInterval opt_interval
7210 | ConstInterval '(' Iconst ')' opt_interval
7215 if (list_length($5) != 1)
7217 (errcode(ERRCODE_SYNTAX_ERROR),
7218 errmsg("interval precision specified twice"),
7219 scanner_errposition(@1)));
7220 $$->typmods = lappend($5, makeIntConst($3, @3));
7223 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
7224 makeIntConst($3, @3));
7228 /* We have a separate ConstTypename to allow defaulting fixed-length
7229 * types such as CHAR() and BIT() to an unspecified length.
7230 * SQL9x requires that these default to a length of one, but this
7231 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
7232 * where there is an obvious better choice to make.
7233 * Note that ConstInterval is not included here since it must
7234 * be pushed up higher in the rules to accomodate the postfix
7235 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
7236 * the generic-type-name case in AExprConst to avoid premature
7237 * reduce/reduce conflicts against function names.
7240 Numeric { $$ = $1; }
7241 | ConstBit { $$ = $1; }
7242 | ConstCharacter { $$ = $1; }
7243 | ConstDatetime { $$ = $1; }
7247 * GenericType covers all type names that don't have special syntax mandated
7248 * by the standard, including qualified names. We also allow type modifiers.
7249 * To avoid parsing conflicts against function invocations, the modifiers
7250 * have to be shown as expr_list here, but parse analysis will only accept
7251 * constants for them.
7254 type_function_name opt_type_modifiers
7256 $$ = makeTypeName($1);
7260 | type_function_name attrs opt_type_modifiers
7262 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
7268 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
7269 | /* EMPTY */ { $$ = NIL; }
7273 * SQL92 numeric data types
7277 $$ = SystemTypeName("int4");
7282 $$ = SystemTypeName("int4");
7287 $$ = SystemTypeName("int2");
7292 $$ = SystemTypeName("int8");
7297 $$ = SystemTypeName("float4");
7305 | DOUBLE_P PRECISION
7307 $$ = SystemTypeName("float8");
7310 | DECIMAL_P opt_type_modifiers
7312 $$ = SystemTypeName("numeric");
7316 | DEC opt_type_modifiers
7318 $$ = SystemTypeName("numeric");
7322 | NUMERIC opt_type_modifiers
7324 $$ = SystemTypeName("numeric");
7330 $$ = SystemTypeName("bool");
7335 opt_float: '(' Iconst ')'
7338 * Check FLOAT() precision limits assuming IEEE floating
7339 * types - thomas 1997-09-18
7343 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7344 errmsg("precision for type float must be at least 1 bit"),
7345 scanner_errposition(@2)));
7347 $$ = SystemTypeName("float4");
7349 $$ = SystemTypeName("float8");
7352 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7353 errmsg("precision for type float must be less than 54 bits"),
7354 scanner_errposition(@2)));
7358 $$ = SystemTypeName("float8");
7363 * SQL92 bit-field data types
7364 * The following implements BIT() and BIT VARYING().
7376 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
7377 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
7378 ConstBit: BitWithLength
7390 BIT opt_varying '(' expr_list ')'
7394 typname = $2 ? "varbit" : "bit";
7395 $$ = SystemTypeName(typname);
7404 /* bit defaults to bit(1), varbit to no limit */
7407 $$ = SystemTypeName("varbit");
7411 $$ = SystemTypeName("bit");
7412 $$->typmods = list_make1(makeIntConst(1, -1));
7420 * SQL92 character data types
7421 * The following implements CHAR() and VARCHAR().
7423 Character: CharacterWithLength
7427 | CharacterWithoutLength
7433 ConstCharacter: CharacterWithLength
7437 | CharacterWithoutLength
7439 /* Length was not specified so allow to be unrestricted.
7440 * This handles problems with fixed-length (bpchar) strings
7441 * which in column definitions must default to a length
7442 * of one, but should not be constrained if the length
7443 * was not specified.
7450 CharacterWithLength: character '(' Iconst ')' opt_charset
7452 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
7456 type = palloc(strlen($1) + 1 + strlen($5) + 1);
7463 $$ = SystemTypeName($1);
7464 $$->typmods = list_make1(makeIntConst($3, @3));
7469 CharacterWithoutLength: character opt_charset
7471 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
7475 type = palloc(strlen($1) + 1 + strlen($2) + 1);
7482 $$ = SystemTypeName($1);
7484 /* char defaults to char(1), varchar to no limit */
7485 if (strcmp($1, "bpchar") == 0)
7486 $$->typmods = list_make1(makeIntConst(1, -1));
7492 character: CHARACTER opt_varying
7493 { $$ = $2 ? "varchar": "bpchar"; }
7494 | CHAR_P opt_varying
7495 { $$ = $2 ? "varchar": "bpchar"; }
7498 | NATIONAL CHARACTER opt_varying
7499 { $$ = $3 ? "varchar": "bpchar"; }
7500 | NATIONAL CHAR_P opt_varying
7501 { $$ = $3 ? "varchar": "bpchar"; }
7503 { $$ = $2 ? "varchar": "bpchar"; }
7507 VARYING { $$ = TRUE; }
7508 | /*EMPTY*/ { $$ = FALSE; }
7512 CHARACTER SET ColId { $$ = $3; }
7513 | /*EMPTY*/ { $$ = NULL; }
7517 * SQL92 date/time types
7520 TIMESTAMP '(' Iconst ')' opt_timezone
7523 $$ = SystemTypeName("timestamptz");
7525 $$ = SystemTypeName("timestamp");
7526 $$->typmods = list_make1(makeIntConst($3, @3));
7529 | TIMESTAMP opt_timezone
7532 $$ = SystemTypeName("timestamptz");
7534 $$ = SystemTypeName("timestamp");
7537 | TIME '(' Iconst ')' opt_timezone
7540 $$ = SystemTypeName("timetz");
7542 $$ = SystemTypeName("time");
7543 $$->typmods = list_make1(makeIntConst($3, @3));
7549 $$ = SystemTypeName("timetz");
7551 $$ = SystemTypeName("time");
7559 $$ = SystemTypeName("interval");
7565 WITH_TIME ZONE { $$ = TRUE; }
7566 | WITHOUT TIME ZONE { $$ = FALSE; }
7567 | /*EMPTY*/ { $$ = FALSE; }
7572 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
7574 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
7576 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
7578 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
7580 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
7585 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
7586 INTERVAL_MASK(MONTH), @1));
7590 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
7591 INTERVAL_MASK(HOUR), @1));
7595 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
7596 INTERVAL_MASK(HOUR) |
7597 INTERVAL_MASK(MINUTE), @1));
7599 | DAY_P TO interval_second
7602 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
7603 INTERVAL_MASK(HOUR) |
7604 INTERVAL_MASK(MINUTE) |
7605 INTERVAL_MASK(SECOND), @1);
7607 | HOUR_P TO MINUTE_P
7609 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
7610 INTERVAL_MASK(MINUTE), @1));
7612 | HOUR_P TO interval_second
7615 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
7616 INTERVAL_MASK(MINUTE) |
7617 INTERVAL_MASK(SECOND), @1);
7619 | MINUTE_P TO interval_second
7622 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
7623 INTERVAL_MASK(SECOND), @1);
7632 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
7634 | SECOND_P '(' Iconst ')'
7636 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
7637 makeIntConst($3, @3));
7642 /*****************************************************************************
7644 * expression grammar
7646 *****************************************************************************/
7649 * General expressions
7650 * This is the heart of the expression syntax.
7652 * We have two expression types: a_expr is the unrestricted kind, and
7653 * b_expr is a subset that must be used in some places to avoid shift/reduce
7654 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
7655 * because that use of AND conflicts with AND as a boolean operator. So,
7656 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
7658 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
7659 * always be used by surrounding it with parens.
7661 * c_expr is all the productions that are common to a_expr and b_expr;
7662 * it's factored out just to eliminate redundant coding.
7664 a_expr: c_expr { $$ = $1; }
7665 | a_expr TYPECAST Typename
7666 { $$ = makeTypeCast($1, $3, @2); }
7667 | a_expr AT TIME ZONE a_expr
7669 FuncCall *n = makeNode(FuncCall);
7670 n->funcname = SystemFuncName("timezone");
7671 n->args = list_make2($5, $1);
7672 n->agg_star = FALSE;
7673 n->agg_distinct = FALSE;
7674 n->func_variadic = FALSE;
7679 * These operators must be called out explicitly in order to make use
7680 * of yacc/bison's automatic operator-precedence handling. All other
7681 * operator names are handled by the generic productions using "Op",
7682 * below; and all those operators will have the same precedence.
7684 * If you add more explicitly-known operators, be sure to add them
7685 * also to b_expr and to the MathOp list above.
7687 | '+' a_expr %prec UMINUS
7688 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
7689 | '-' a_expr %prec UMINUS
7690 { $$ = doNegate($2, @1); }
7692 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
7694 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
7696 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
7698 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
7700 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
7702 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
7704 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
7706 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
7708 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
7710 | a_expr qual_Op a_expr %prec Op
7711 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
7712 | qual_Op a_expr %prec Op
7713 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
7714 | a_expr qual_Op %prec POSTFIXOP
7715 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
7718 { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
7720 { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
7722 { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
7724 | a_expr LIKE a_expr
7725 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
7726 | a_expr LIKE a_expr ESCAPE a_expr
7728 FuncCall *n = makeNode(FuncCall);
7729 n->funcname = SystemFuncName("like_escape");
7730 n->args = list_make2($3, $5);
7731 n->agg_star = FALSE;
7732 n->agg_distinct = FALSE;
7733 n->func_variadic = FALSE;
7735 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
7737 | a_expr NOT LIKE a_expr
7738 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
7739 | a_expr NOT LIKE a_expr ESCAPE a_expr
7741 FuncCall *n = makeNode(FuncCall);
7742 n->funcname = SystemFuncName("like_escape");
7743 n->args = list_make2($4, $6);
7744 n->agg_star = FALSE;
7745 n->agg_distinct = FALSE;
7746 n->func_variadic = FALSE;
7748 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
7750 | a_expr ILIKE a_expr
7751 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
7752 | a_expr ILIKE a_expr ESCAPE a_expr
7754 FuncCall *n = makeNode(FuncCall);
7755 n->funcname = SystemFuncName("like_escape");
7756 n->args = list_make2($3, $5);
7757 n->agg_star = FALSE;
7758 n->agg_distinct = FALSE;
7759 n->func_variadic = FALSE;
7761 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n, @2);
7763 | a_expr NOT ILIKE a_expr
7764 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
7765 | a_expr NOT ILIKE a_expr ESCAPE a_expr
7767 FuncCall *n = makeNode(FuncCall);
7768 n->funcname = SystemFuncName("like_escape");
7769 n->args = list_make2($4, $6);
7770 n->agg_star = FALSE;
7771 n->agg_distinct = FALSE;
7772 n->func_variadic = FALSE;
7774 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n, @2);
7777 | a_expr SIMILAR TO a_expr %prec SIMILAR
7779 FuncCall *n = makeNode(FuncCall);
7780 n->funcname = SystemFuncName("similar_escape");
7781 n->args = list_make2($4, 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 SIMILAR TO a_expr ESCAPE a_expr
7790 FuncCall *n = makeNode(FuncCall);
7791 n->funcname = SystemFuncName("similar_escape");
7792 n->args = list_make2($4, $6);
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);
7799 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
7801 FuncCall *n = makeNode(FuncCall);
7802 n->funcname = SystemFuncName("similar_escape");
7803 n->args = list_make2($5, makeNullAConst(-1));
7804 n->agg_star = FALSE;
7805 n->agg_distinct = FALSE;
7806 n->func_variadic = FALSE;
7808 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
7810 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
7812 FuncCall *n = makeNode(FuncCall);
7813 n->funcname = SystemFuncName("similar_escape");
7814 n->args = list_make2($5, $7);
7815 n->agg_star = FALSE;
7816 n->agg_distinct = FALSE;
7817 n->func_variadic = FALSE;
7819 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
7823 * Define SQL92-style Null test clause.
7824 * Allow two forms described in the standard:
7827 * Allow two SQL extensions
7833 NullTest *n = makeNode(NullTest);
7834 n->arg = (Expr *) $1;
7835 n->nulltesttype = IS_NULL;
7840 NullTest *n = makeNode(NullTest);
7841 n->arg = (Expr *) $1;
7842 n->nulltesttype = IS_NULL;
7845 | a_expr IS NOT NULL_P
7847 NullTest *n = makeNode(NullTest);
7848 n->arg = (Expr *) $1;
7849 n->nulltesttype = IS_NOT_NULL;
7854 NullTest *n = makeNode(NullTest);
7855 n->arg = (Expr *) $1;
7856 n->nulltesttype = IS_NOT_NULL;
7861 $$ = (Node *)makeOverlaps($1, $3, @2);
7865 BooleanTest *b = makeNode(BooleanTest);
7866 b->arg = (Expr *) $1;
7867 b->booltesttype = IS_TRUE;
7870 | a_expr IS NOT TRUE_P
7872 BooleanTest *b = makeNode(BooleanTest);
7873 b->arg = (Expr *) $1;
7874 b->booltesttype = IS_NOT_TRUE;
7879 BooleanTest *b = makeNode(BooleanTest);
7880 b->arg = (Expr *) $1;
7881 b->booltesttype = IS_FALSE;
7884 | a_expr IS NOT FALSE_P
7886 BooleanTest *b = makeNode(BooleanTest);
7887 b->arg = (Expr *) $1;
7888 b->booltesttype = IS_NOT_FALSE;
7893 BooleanTest *b = makeNode(BooleanTest);
7894 b->arg = (Expr *) $1;
7895 b->booltesttype = IS_UNKNOWN;
7898 | a_expr IS NOT UNKNOWN
7900 BooleanTest *b = makeNode(BooleanTest);
7901 b->arg = (Expr *) $1;
7902 b->booltesttype = IS_NOT_UNKNOWN;
7905 | a_expr IS DISTINCT FROM a_expr %prec IS
7907 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
7909 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
7911 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
7912 (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
7917 | a_expr IS OF '(' type_list ')' %prec IS
7919 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
7921 | a_expr IS NOT OF '(' type_list ')' %prec IS
7923 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
7925 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
7927 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
7928 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
7929 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
7932 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
7934 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
7935 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
7936 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
7939 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
7941 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
7942 (Node *) makeA_Expr(AEXPR_AND, NIL,
7943 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
7944 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
7946 (Node *) makeA_Expr(AEXPR_AND, NIL,
7947 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
7948 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
7952 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
7954 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
7955 (Node *) makeA_Expr(AEXPR_OR, NIL,
7956 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
7957 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
7959 (Node *) makeA_Expr(AEXPR_OR, NIL,
7960 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
7961 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
7965 | a_expr IN_P in_expr
7967 /* in_expr returns a SubLink or a list of a_exprs */
7968 if (IsA($3, SubLink))
7970 /* generate foo = ANY (subquery) */
7971 SubLink *n = (SubLink *) $3;
7972 n->subLinkType = ANY_SUBLINK;
7974 n->operName = list_make1(makeString("="));
7980 /* generate scalar IN expression */
7981 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
7984 | a_expr NOT IN_P in_expr
7986 /* in_expr returns a SubLink or a list of a_exprs */
7987 if (IsA($4, SubLink))
7989 /* generate NOT (foo = ANY (subquery)) */
7990 /* Make an = ANY node */
7991 SubLink *n = (SubLink *) $4;
7992 n->subLinkType = ANY_SUBLINK;
7994 n->operName = list_make1(makeString("="));
7996 /* Stick a NOT on top */
7997 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
8001 /* generate scalar NOT IN expression */
8002 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
8005 | a_expr subquery_Op sub_type select_with_parens %prec Op
8007 SubLink *n = makeNode(SubLink);
8008 n->subLinkType = $3;
8015 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
8017 if ($3 == ANY_SUBLINK)
8018 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
8020 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
8022 | UNIQUE select_with_parens
8024 /* Not sure how to get rid of the parentheses
8025 * but there are lots of shift/reduce errors without them.
8027 * Should be able to implement this by plopping the entire
8028 * select into a node, then transforming the target expressions
8029 * from whatever they are into count(*), and testing the
8030 * entire result equal to one.
8031 * But, will probably implement a separate node in the executor.
8034 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8035 errmsg("UNIQUE predicate is not yet implemented"),
8036 scanner_errposition(@1)));
8038 | a_expr IS DOCUMENT_P %prec IS
8040 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8041 list_make1($1), @2);
8043 | a_expr IS NOT DOCUMENT_P %prec IS
8045 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8046 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8047 list_make1($1), @2),
8053 * Restricted expressions
8055 * b_expr is a subset of the complete expression syntax defined by a_expr.
8057 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
8058 * cause trouble in the places where b_expr is used. For simplicity, we
8059 * just eliminate all the boolean-keyword-operator productions from b_expr.
8063 | b_expr TYPECAST Typename
8064 { $$ = makeTypeCast($1, $3, @2); }
8065 | '+' b_expr %prec UMINUS
8066 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
8067 | '-' b_expr %prec UMINUS
8068 { $$ = doNegate($2, @1); }
8070 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
8072 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
8074 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
8076 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
8078 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
8080 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
8082 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
8084 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
8086 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
8087 | b_expr qual_Op b_expr %prec Op
8088 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
8089 | qual_Op b_expr %prec Op
8090 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
8091 | b_expr qual_Op %prec POSTFIXOP
8092 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
8093 | b_expr IS DISTINCT FROM b_expr %prec IS
8095 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
8097 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
8099 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
8100 NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
8102 | b_expr IS OF '(' type_list ')' %prec IS
8104 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
8106 | b_expr IS NOT OF '(' type_list ')' %prec IS
8108 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
8110 | b_expr IS DOCUMENT_P %prec IS
8112 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8113 list_make1($1), @2);
8115 | b_expr IS NOT DOCUMENT_P %prec IS
8117 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8118 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8119 list_make1($1), @2),
8125 * Productions that can be used in both a_expr and b_expr.
8127 * Note: productions that refer recursively to a_expr or b_expr mostly
8128 * cannot appear here. However, it's OK to refer to a_exprs that occur
8129 * inside parentheses, such as function arguments; that cannot introduce
8130 * ambiguity to the b_expr syntax.
8132 c_expr: columnref { $$ = $1; }
8133 | AexprConst { $$ = $1; }
8134 | PARAM opt_indirection
8136 ParamRef *p = makeNode(ParamRef);
8141 A_Indirection *n = makeNode(A_Indirection);
8142 n->arg = (Node *) p;
8143 n->indirection = check_indirection($2);
8149 | '(' a_expr ')' opt_indirection
8153 A_Indirection *n = makeNode(A_Indirection);
8155 n->indirection = check_indirection($4);
8165 | select_with_parens %prec UMINUS
8167 SubLink *n = makeNode(SubLink);
8168 n->subLinkType = EXPR_SUBLINK;
8175 | EXISTS select_with_parens
8177 SubLink *n = makeNode(SubLink);
8178 n->subLinkType = EXISTS_SUBLINK;
8185 | ARRAY select_with_parens
8187 SubLink *n = makeNode(SubLink);
8188 n->subLinkType = ARRAY_SUBLINK;
8197 A_ArrayExpr *n = (A_ArrayExpr *) $2;
8198 Assert(IsA(n, A_ArrayExpr));
8199 /* point outermost A_ArrayExpr to the ARRAY keyword */
8205 RowExpr *r = makeNode(RowExpr);
8207 r->row_typeid = InvalidOid; /* not analyzed yet */
8214 * func_expr is split out from c_expr just so that we have a classification
8215 * for "everything that is a function call or looks like one". This isn't
8216 * very important, but it saves us having to document which variants are
8217 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
8218 * (Note that many of the special SQL functions wouldn't actually make any
8219 * sense as functional index entries, but we ignore that consideration here.)
8221 func_expr: func_name '(' ')'
8223 FuncCall *n = makeNode(FuncCall);
8226 n->agg_star = FALSE;
8227 n->agg_distinct = FALSE;
8228 n->func_variadic = FALSE;
8232 | func_name '(' expr_list ')'
8234 FuncCall *n = makeNode(FuncCall);
8237 n->agg_star = FALSE;
8238 n->agg_distinct = FALSE;
8239 n->func_variadic = FALSE;
8243 | func_name '(' VARIADIC a_expr ')'
8245 FuncCall *n = makeNode(FuncCall);
8247 n->args = list_make1($4);
8248 n->agg_star = FALSE;
8249 n->agg_distinct = FALSE;
8250 n->func_variadic = TRUE;
8254 | func_name '(' expr_list ',' VARIADIC a_expr ')'
8256 FuncCall *n = makeNode(FuncCall);
8258 n->args = lappend($3, $6);
8259 n->agg_star = FALSE;
8260 n->agg_distinct = FALSE;
8261 n->func_variadic = TRUE;
8265 | func_name '(' ALL expr_list ')'
8267 FuncCall *n = makeNode(FuncCall);
8270 n->agg_star = FALSE;
8271 n->agg_distinct = FALSE;
8272 /* Ideally we'd mark the FuncCall node to indicate
8273 * "must be an aggregate", but there's no provision
8274 * for that in FuncCall at the moment.
8276 n->func_variadic = FALSE;
8280 | func_name '(' DISTINCT expr_list ')'
8282 FuncCall *n = makeNode(FuncCall);
8285 n->agg_star = FALSE;
8286 n->agg_distinct = TRUE;
8287 n->func_variadic = FALSE;
8291 | func_name '(' '*' ')'
8294 * We consider AGGREGATE(*) to invoke a parameterless
8295 * aggregate. This does the right thing for COUNT(*),
8296 * and there are no other aggregates in SQL92 that accept
8299 * The FuncCall node is also marked agg_star = true,
8300 * so that later processing can detect what the argument
8303 FuncCall *n = makeNode(FuncCall);
8307 n->agg_distinct = FALSE;
8308 n->func_variadic = FALSE;
8315 * Translate as "'now'::text::date".
8317 * We cannot use "'now'::date" because coerce_type() will
8318 * immediately reduce that to a constant representing
8319 * today's date. We need to delay the conversion until
8320 * runtime, else the wrong things will happen when
8321 * CURRENT_DATE is used in a column default value or rule.
8323 * This could be simplified if we had a way to generate
8324 * an expression tree representing runtime application
8325 * of type-input conversion functions. (As of PG 7.3
8326 * that is actually possible, but not clear that we want
8330 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8331 $$ = makeTypeCast(n, SystemTypeName("date"), -1);
8336 * Translate as "'now'::text::timetz".
8337 * See comments for CURRENT_DATE.
8340 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8341 $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
8343 | CURRENT_TIME '(' Iconst ')'
8346 * Translate as "'now'::text::timetz(n)".
8347 * See comments for CURRENT_DATE.
8351 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8352 d = SystemTypeName("timetz");
8353 d->typmods = list_make1(makeIntConst($3, @3));
8354 $$ = makeTypeCast(n, d, -1);
8359 * Translate as "now()", since we have a function that
8360 * does exactly what is needed.
8362 FuncCall *n = makeNode(FuncCall);
8363 n->funcname = SystemFuncName("now");
8365 n->agg_star = FALSE;
8366 n->agg_distinct = FALSE;
8367 n->func_variadic = FALSE;
8371 | CURRENT_TIMESTAMP '(' Iconst ')'
8374 * Translate as "'now'::text::timestamptz(n)".
8375 * See comments for CURRENT_DATE.
8379 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8380 d = SystemTypeName("timestamptz");
8381 d->typmods = list_make1(makeIntConst($3, @3));
8382 $$ = makeTypeCast(n, d, -1);
8387 * Translate as "'now'::text::time".
8388 * See comments for CURRENT_DATE.
8391 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8392 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
8394 | LOCALTIME '(' Iconst ')'
8397 * Translate as "'now'::text::time(n)".
8398 * See comments for CURRENT_DATE.
8402 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8403 d = SystemTypeName("time");
8404 d->typmods = list_make1(makeIntConst($3, @3));
8405 $$ = makeTypeCast((Node *)n, d, -1);
8410 * Translate as "'now'::text::timestamp".
8411 * See comments for CURRENT_DATE.
8414 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8415 $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
8417 | LOCALTIMESTAMP '(' Iconst ')'
8420 * Translate as "'now'::text::timestamp(n)".
8421 * See comments for CURRENT_DATE.
8425 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8426 d = SystemTypeName("timestamp");
8427 d->typmods = list_make1(makeIntConst($3, @3));
8428 $$ = makeTypeCast(n, d, -1);
8432 FuncCall *n = makeNode(FuncCall);
8433 n->funcname = SystemFuncName("current_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("session_user");
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_user");
8468 n->agg_star = FALSE;
8469 n->agg_distinct = FALSE;
8470 n->func_variadic = FALSE;
8476 FuncCall *n = makeNode(FuncCall);
8477 n->funcname = SystemFuncName("current_database");
8479 n->agg_star = FALSE;
8480 n->agg_distinct = FALSE;
8481 n->func_variadic = FALSE;
8487 FuncCall *n = makeNode(FuncCall);
8488 n->funcname = SystemFuncName("current_schema");
8490 n->agg_star = FALSE;
8491 n->agg_distinct = FALSE;
8492 n->func_variadic = FALSE;
8496 | CAST '(' a_expr AS Typename ')'
8497 { $$ = makeTypeCast($3, $5, @1); }
8498 | EXTRACT '(' extract_list ')'
8500 FuncCall *n = makeNode(FuncCall);
8501 n->funcname = SystemFuncName("date_part");
8503 n->agg_star = FALSE;
8504 n->agg_distinct = FALSE;
8505 n->func_variadic = FALSE;
8509 | OVERLAY '(' overlay_list ')'
8511 /* overlay(A PLACING B FROM C FOR D) is converted to
8512 * substring(A, 1, C-1) || B || substring(A, C+1, C+D)
8513 * overlay(A PLACING B FROM C) is converted to
8514 * substring(A, 1, C-1) || B || substring(A, C+1, C+char_length(B))
8516 FuncCall *n = makeNode(FuncCall);
8517 n->funcname = SystemFuncName("overlay");
8519 n->agg_star = FALSE;
8520 n->agg_distinct = FALSE;
8521 n->func_variadic = FALSE;
8525 | POSITION '(' position_list ')'
8527 /* position(A in B) is converted to position(B, A) */
8528 FuncCall *n = makeNode(FuncCall);
8529 n->funcname = SystemFuncName("position");
8531 n->agg_star = FALSE;
8532 n->agg_distinct = FALSE;
8533 n->func_variadic = FALSE;
8537 | SUBSTRING '(' substr_list ')'
8539 /* substring(A from B for C) is converted to
8540 * substring(A, B, C) - thomas 2000-11-28
8542 FuncCall *n = makeNode(FuncCall);
8543 n->funcname = SystemFuncName("substring");
8545 n->agg_star = FALSE;
8546 n->agg_distinct = FALSE;
8547 n->func_variadic = FALSE;
8551 | TREAT '(' a_expr AS Typename ')'
8553 /* TREAT(expr AS target) converts expr of a particular type to target,
8554 * which is defined to be a subtype of the original expression.
8555 * In SQL99, this is intended for use with structured UDTs,
8556 * but let's make this a generally useful form allowing stronger
8557 * coercions than are handled by implicit casting.
8559 FuncCall *n = makeNode(FuncCall);
8560 /* Convert SystemTypeName() to SystemFuncName() even though
8561 * at the moment they result in the same thing.
8563 n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
8564 n->args = list_make1($3);
8565 n->agg_star = FALSE;
8566 n->agg_distinct = FALSE;
8567 n->func_variadic = FALSE;
8571 | TRIM '(' BOTH trim_list ')'
8573 /* various trim expressions are defined in SQL92
8574 * - thomas 1997-07-19
8576 FuncCall *n = makeNode(FuncCall);
8577 n->funcname = SystemFuncName("btrim");
8579 n->agg_star = FALSE;
8580 n->agg_distinct = FALSE;
8581 n->func_variadic = FALSE;
8585 | TRIM '(' LEADING trim_list ')'
8587 FuncCall *n = makeNode(FuncCall);
8588 n->funcname = SystemFuncName("ltrim");
8590 n->agg_star = FALSE;
8591 n->agg_distinct = FALSE;
8592 n->func_variadic = FALSE;
8596 | TRIM '(' TRAILING trim_list ')'
8598 FuncCall *n = makeNode(FuncCall);
8599 n->funcname = SystemFuncName("rtrim");
8601 n->agg_star = FALSE;
8602 n->agg_distinct = FALSE;
8603 n->func_variadic = FALSE;
8607 | TRIM '(' trim_list ')'
8609 FuncCall *n = makeNode(FuncCall);
8610 n->funcname = SystemFuncName("btrim");
8612 n->agg_star = FALSE;
8613 n->agg_distinct = FALSE;
8614 n->func_variadic = FALSE;
8618 | NULLIF '(' a_expr ',' a_expr ')'
8620 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
8622 | COALESCE '(' expr_list ')'
8624 CoalesceExpr *c = makeNode(CoalesceExpr);
8629 | GREATEST '(' expr_list ')'
8631 MinMaxExpr *v = makeNode(MinMaxExpr);
8633 v->op = IS_GREATEST;
8637 | LEAST '(' expr_list ')'
8639 MinMaxExpr *v = makeNode(MinMaxExpr);
8645 | XMLCONCAT '(' expr_list ')'
8647 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
8649 | XMLELEMENT '(' NAME_P ColLabel ')'
8651 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
8653 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
8655 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
8657 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
8659 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
8661 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
8663 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
8665 | XMLFOREST '(' xml_attribute_list ')'
8667 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
8669 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
8671 XmlExpr *x = (XmlExpr *)
8672 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
8673 list_make2($4, makeBoolAConst($5, -1)),
8678 | XMLPI '(' NAME_P ColLabel ')'
8680 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
8682 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
8684 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
8686 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
8688 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
8689 list_make3($3, $5, $6), @1);
8691 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
8693 XmlSerialize *n = makeNode(XmlSerialize);
8705 xml_root_version: VERSION_P a_expr
8707 | VERSION_P NO VALUE_P
8708 { $$ = makeNullAConst(-1); }
8711 opt_xml_root_standalone: ',' STANDALONE_P YES_P
8712 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
8713 | ',' STANDALONE_P NO
8714 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
8715 | ',' STANDALONE_P NO VALUE_P
8716 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
8718 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
8721 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
8724 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
8725 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
8728 xml_attribute_el: a_expr AS ColLabel
8730 $$ = makeNode(ResTarget);
8732 $$->indirection = NIL;
8733 $$->val = (Node *) $1;
8738 $$ = makeNode(ResTarget);
8740 $$->indirection = NIL;
8741 $$->val = (Node *) $1;
8746 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
8747 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
8750 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
8751 | STRIP_P WHITESPACE_P { $$ = FALSE; }
8752 | /*EMPTY*/ { $$ = FALSE; }
8756 * Supporting nonterminals for expressions.
8759 /* Explicit row production.
8761 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
8762 * without conflicting with the parenthesized a_expr production. Without the
8763 * ROW keyword, there must be more than one a_expr inside the parens.
8765 row: ROW '(' expr_list ')' { $$ = $3; }
8766 | ROW '(' ')' { $$ = NIL; }
8767 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
8770 sub_type: ANY { $$ = ANY_SUBLINK; }
8771 | SOME { $$ = ANY_SUBLINK; }
8772 | ALL { $$ = ALL_SUBLINK; }
8775 all_Op: Op { $$ = $1; }
8776 | MathOp { $$ = $1; }
8779 MathOp: '+' { $$ = "+"; }
8791 { $$ = list_make1(makeString($1)); }
8792 | OPERATOR '(' any_operator ')'
8798 { $$ = list_make1(makeString($1)); }
8799 | OPERATOR '(' any_operator ')'
8805 { $$ = list_make1(makeString($1)); }
8806 | OPERATOR '(' any_operator ')'
8809 { $$ = list_make1(makeString("~~")); }
8811 { $$ = list_make1(makeString("!~~")); }
8813 { $$ = list_make1(makeString("~~*")); }
8815 { $$ = list_make1(makeString("!~~*")); }
8816 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
8817 * the regular expression is preprocessed by a function (similar_escape),
8818 * and the ~ operator for posix regular expressions is used.
8819 * x SIMILAR TO y -> x ~ similar_escape(y)
8820 * this transformation is made on the fly by the parser upwards.
8821 * however the SubLink structure which handles any/some/all stuff
8822 * is not ready for such a thing.
8828 $$ = list_make1($1);
8830 | expr_list ',' a_expr
8832 $$ = lappend($1, $3);
8836 type_list: Typename { $$ = list_make1($1); }
8837 | type_list ',' Typename { $$ = lappend($1, $3); }
8840 array_expr: '[' expr_list ']'
8842 $$ = makeAArrayExpr($2, @1);
8844 | '[' array_expr_list ']'
8846 $$ = makeAArrayExpr($2, @1);
8850 $$ = makeAArrayExpr(NIL, @1);
8854 array_expr_list: array_expr { $$ = list_make1($1); }
8855 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
8860 extract_arg FROM a_expr
8862 $$ = list_make2(makeStringConst($1, @1), $3);
8864 | /*EMPTY*/ { $$ = NIL; }
8867 /* Allow delimited string Sconst in extract_arg as an SQL extension.
8868 * - thomas 2001-04-12
8872 | YEAR_P { $$ = "year"; }
8873 | MONTH_P { $$ = "month"; }
8874 | DAY_P { $$ = "day"; }
8875 | HOUR_P { $$ = "hour"; }
8876 | MINUTE_P { $$ = "minute"; }
8877 | SECOND_P { $$ = "second"; }
8878 | Sconst { $$ = $1; }
8881 /* OVERLAY() arguments
8882 * SQL99 defines the OVERLAY() function:
8883 * o overlay(text placing text from int for int)
8884 * o overlay(text placing text from int)
8887 a_expr overlay_placing substr_from substr_for
8889 $$ = list_make4($1, $2, $3, $4);
8891 | a_expr overlay_placing substr_from
8893 $$ = list_make3($1, $2, $3);
8902 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
8905 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
8906 | /*EMPTY*/ { $$ = NIL; }
8909 /* SUBSTRING() arguments
8910 * SQL9x defines a specific syntax for arguments to SUBSTRING():
8911 * o substring(text from int for int)
8912 * o substring(text from int) get entire string from starting point "int"
8913 * o substring(text for int) get first "int" characters of string
8914 * o substring(text from pattern) get entire string matching pattern
8915 * o substring(text from pattern for escape) same with specified escape char
8916 * We also want to support generic substring functions which accept
8917 * the usual generic list of arguments. So we will accept both styles
8918 * here, and convert the SQL9x style to the generic list for further
8919 * processing. - thomas 2000-11-28
8922 a_expr substr_from substr_for
8924 $$ = list_make3($1, $2, $3);
8926 | a_expr substr_for substr_from
8928 /* not legal per SQL99, but might as well allow it */
8929 $$ = list_make3($1, $3, $2);
8931 | a_expr substr_from
8933 $$ = list_make2($1, $2);
8938 * Since there are no cases where this syntax allows
8939 * a textual FOR value, we forcibly cast the argument
8940 * to int4. The possible matches in pg_proc are
8941 * substring(text,int4) and substring(text,text),
8942 * and we don't want the parser to choose the latter,
8943 * which it is likely to do if the second argument
8944 * is unknown or doesn't have an implicit cast to int4.
8946 $$ = list_make3($1, makeIntConst(1, -1),
8948 SystemTypeName("int4"), -1));
8959 FROM a_expr { $$ = $2; }
8962 substr_for: FOR a_expr { $$ = $2; }
8965 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
8966 | FROM expr_list { $$ = $2; }
8967 | expr_list { $$ = $1; }
8970 in_expr: select_with_parens
8972 SubLink *n = makeNode(SubLink);
8974 /* other fields will be filled later */
8977 | '(' expr_list ')' { $$ = (Node *)$2; }
8981 * Define SQL92-style case clause.
8982 * - Full specification
8983 * CASE WHEN a = b THEN c ... ELSE d END
8984 * - Implicit argument
8985 * CASE a WHEN b THEN c ... ELSE d END
8987 case_expr: CASE case_arg when_clause_list case_default END_P
8989 CaseExpr *c = makeNode(CaseExpr);
8990 c->casetype = InvalidOid; /* not analyzed yet */
8991 c->arg = (Expr *) $2;
8993 c->defresult = (Expr *) $4;
9000 /* There must be at least one */
9001 when_clause { $$ = list_make1($1); }
9002 | when_clause_list when_clause { $$ = lappend($1, $2); }
9006 WHEN a_expr THEN a_expr
9008 CaseWhen *w = makeNode(CaseWhen);
9009 w->expr = (Expr *) $2;
9010 w->result = (Expr *) $4;
9017 ELSE a_expr { $$ = $2; }
9018 | /*EMPTY*/ { $$ = NULL; }
9021 case_arg: a_expr { $$ = $1; }
9022 | /*EMPTY*/ { $$ = NULL; }
9026 * columnref starts with relation_name not ColId, so that OLD and NEW
9027 * references can be accepted. Note that when there are more than two
9028 * dotted names, the first name is not actually a relation name...
9030 columnref: relation_name
9032 $$ = makeColumnRef($1, NIL, @1);
9034 | relation_name indirection
9036 $$ = makeColumnRef($1, $2, @1);
9043 $$ = (Node *) makeString($2);
9047 $$ = (Node *) makeNode(A_Star);
9051 A_Indices *ai = makeNode(A_Indices);
9056 | '[' a_expr ':' a_expr ']'
9058 A_Indices *ai = makeNode(A_Indices);
9066 indirection_el { $$ = list_make1($1); }
9067 | indirection indirection_el { $$ = lappend($1, $2); }
9071 /*EMPTY*/ { $$ = NIL; }
9072 | opt_indirection indirection_el { $$ = lappend($1, $2); }
9075 opt_asymmetric: ASYMMETRIC
9080 * The SQL spec defines "contextually typed value expressions" and
9081 * "contextually typed row value constructors", which for our purposes
9082 * are the same as "a_expr" and "row" except that DEFAULT can appear at
9087 a_expr { $$ = (Node *) $1; }
9090 SetToDefault *n = makeNode(SetToDefault);
9097 ctext_expr { $$ = list_make1($1); }
9098 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
9102 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
9103 * making VALUES a fully reserved word, which will probably break more apps
9104 * than allowing the noise-word is worth.
9106 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
9110 /*****************************************************************************
9112 * target list for SELECT
9114 *****************************************************************************/
9117 target_el { $$ = list_make1($1); }
9118 | target_list ',' target_el { $$ = lappend($1, $3); }
9121 target_el: a_expr AS ColLabel
9123 $$ = makeNode(ResTarget);
9125 $$->indirection = NIL;
9126 $$->val = (Node *)$1;
9130 * We support omitting AS only for column labels that aren't
9131 * any known keyword. There is an ambiguity against postfix
9132 * operators: is "a ! b" an infix expression, or a postfix
9133 * expression and a column label? We prefer to resolve this
9134 * as an infix expression, which we accomplish by assigning
9135 * IDENT a precedence higher than POSTFIXOP.
9139 $$ = makeNode(ResTarget);
9141 $$->indirection = NIL;
9142 $$->val = (Node *)$1;
9147 $$ = makeNode(ResTarget);
9149 $$->indirection = NIL;
9150 $$->val = (Node *)$1;
9155 ColumnRef *n = makeNode(ColumnRef);
9156 n->fields = list_make1(makeNode(A_Star));
9159 $$ = makeNode(ResTarget);
9161 $$->indirection = NIL;
9162 $$->val = (Node *)n;
9168 /*****************************************************************************
9170 * Names and constants
9172 *****************************************************************************/
9175 SpecialRuleRelation { $$ = $1; }
9176 | ColId { $$ = $1; }
9179 qualified_name_list:
9180 qualified_name { $$ = list_make1($1); }
9181 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
9185 * The production for a qualified relation name has to exactly match the
9186 * production for a qualified func_name, because in a FROM clause we cannot
9187 * tell which we are parsing until we see what comes after it ('(' for a
9188 * func_name, something else for a relation). Therefore we allow 'indirection'
9189 * which may contain subscripts, and reject that case in the C code.
9194 $$ = makeNode(RangeVar);
9195 $$->catalogname = NULL;
9196 $$->schemaname = NULL;
9200 | relation_name indirection
9202 check_qualified_name($2);
9203 $$ = makeNode(RangeVar);
9204 switch (list_length($2))
9207 $$->catalogname = NULL;
9208 $$->schemaname = $1;
9209 $$->relname = strVal(linitial($2));
9212 $$->catalogname = $1;
9213 $$->schemaname = strVal(linitial($2));
9214 $$->relname = strVal(lsecond($2));
9218 (errcode(ERRCODE_SYNTAX_ERROR),
9219 errmsg("improper qualified name (too many dotted names): %s",
9220 NameListToString(lcons(makeString($1), $2))),
9221 scanner_errposition(@1)));
9229 { $$ = list_make1(makeString($1)); }
9230 | name_list ',' name
9231 { $$ = lappend($1, makeString($3)); }
9235 name: ColId { $$ = $1; };
9243 attr_name: ColLabel { $$ = $1; };
9245 index_name: ColId { $$ = $1; };
9247 file_name: Sconst { $$ = $1; };
9250 * The production for a qualified func_name has to exactly match the
9251 * production for a qualified columnref, because we cannot tell which we
9252 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
9253 * anything else for a columnref). Therefore we allow 'indirection' which
9254 * may contain subscripts, and reject that case in the C code. (If we
9255 * ever implement SQL99-like methods, such syntax may actually become legal!)
9257 func_name: type_function_name
9258 { $$ = list_make1(makeString($1)); }
9259 | relation_name indirection
9260 { $$ = check_func_name(lcons(makeString($1), $2)); }
9269 $$ = makeIntConst($1, @1);
9273 $$ = makeFloatConst($1, @1);
9277 $$ = makeStringConst($1, @1);
9281 $$ = makeBitStringConst($1, @1);
9285 /* This is a bit constant per SQL99:
9286 * Without Feature F511, "BIT data type",
9287 * a <general literal> shall not be a
9288 * <bit string literal> or a <hex string literal>.
9290 $$ = makeBitStringConst($1, @1);
9294 /* generic type 'literal' syntax */
9295 TypeName *t = makeTypeNameFromNameList($1);
9297 $$ = makeStringConstCast($2, @2, t);
9299 | func_name '(' expr_list ')' Sconst
9301 /* generic syntax with a type modifier */
9302 TypeName *t = makeTypeNameFromNameList($1);
9305 $$ = makeStringConstCast($5, @5, t);
9307 | ConstTypename Sconst
9309 $$ = makeStringConstCast($2, @2, $1);
9311 | ConstInterval Sconst opt_interval
9315 $$ = makeStringConstCast($2, @2, t);
9317 | ConstInterval '(' Iconst ')' Sconst opt_interval
9322 if (list_length($6) != 1)
9324 (errcode(ERRCODE_SYNTAX_ERROR),
9325 errmsg("interval precision specified twice"),
9326 scanner_errposition(@1)));
9327 t->typmods = lappend($6, makeIntConst($3, @3));
9330 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
9331 makeIntConst($3, @3));
9332 $$ = makeStringConstCast($5, @5, t);
9336 $$ = makeBoolAConst(TRUE, @1);
9340 $$ = makeBoolAConst(FALSE, @1);
9344 $$ = makeNullAConst(@1);
9348 Iconst: ICONST { $$ = $1; };
9349 Sconst: SCONST { $$ = $1; };
9350 RoleId: ColId { $$ = $1; };
9352 SignedIconst: Iconst { $$ = $1; }
9353 | '+' Iconst { $$ = + $2; }
9354 | '-' Iconst { $$ = - $2; }
9358 * Name classification hierarchy.
9360 * IDENT is the lexeme returned by the lexer for identifiers that match
9361 * no known keyword. In most cases, we can accept certain keywords as
9362 * names, not only IDENTs. We prefer to accept as many such keywords
9363 * as possible to minimize the impact of "reserved words" on programmers.
9364 * So, we divide names into several possible classes. The classification
9365 * is chosen in part to make keywords acceptable as names wherever possible.
9368 /* Column identifier --- names that can be column, table, etc names.
9370 ColId: IDENT { $$ = $1; }
9371 | unreserved_keyword { $$ = pstrdup($1); }
9372 | col_name_keyword { $$ = pstrdup($1); }
9375 /* Type/function identifier --- names that can be type or function names.
9377 type_function_name: IDENT { $$ = $1; }
9378 | unreserved_keyword { $$ = pstrdup($1); }
9379 | type_func_name_keyword { $$ = pstrdup($1); }
9382 /* Column label --- allowed labels in "AS" clauses.
9383 * This presently includes *all* Postgres keywords.
9385 ColLabel: IDENT { $$ = $1; }
9386 | unreserved_keyword { $$ = pstrdup($1); }
9387 | col_name_keyword { $$ = pstrdup($1); }
9388 | type_func_name_keyword { $$ = pstrdup($1); }
9389 | reserved_keyword { $$ = pstrdup($1); }
9394 * Keyword category lists. Generally, every keyword present in
9395 * the Postgres grammar should appear in exactly one of these lists.
9397 * Put a new keyword into the first list that it can go into without causing
9398 * shift or reduce conflicts. The earlier lists define "less reserved"
9399 * categories of keywords.
9401 * Make sure that each keyword's category in keywords.c matches where
9402 * it is listed here. (Someday we may be able to generate these lists and
9403 * keywords.c's table from a common master list.)
9406 /* "Unreserved" keywords --- available for use as any kind of name.
9648 /* Column identifier --- keywords that can be column, table, etc names.
9650 * Many of these keywords will in fact be recognized as type or function
9651 * names too; but they have special productions for the purpose, and so
9652 * can't be treated as "generic" type or function names.
9654 * The type names appearing here are not usable as function names
9655 * because they can be followed by '(' in typename productions, which
9656 * looks too much like a function call for an LR(1) parser.
9706 /* Type/function identifier --- keywords that can be type or function names.
9708 * Most of these are keywords that are used as operators in expressions;
9709 * in general such keywords can't be column names because they would be
9710 * ambiguous with variables, but they are unambiguous as function identifiers.
9712 * Do not include POSITION, SUBSTRING, etc here since they have explicit
9713 * productions in a_expr to support the goofy SQL9x argument syntax.
9714 * - thomas 2000-11-28
9716 type_func_name_keyword:
9740 /* Reserved keyword --- these keywords are usable only as a ColLabel.
9742 * Keywords appear here if they could not be distinguished from variable,
9743 * type, or function names in some contexts. Don't put things here unless
9828 SpecialRuleRelation:
9835 (errcode(ERRCODE_SYNTAX_ERROR),
9836 errmsg("OLD used in query that is not in a rule"),
9837 scanner_errposition(@1)));
9845 (errcode(ERRCODE_SYNTAX_ERROR),
9846 errmsg("NEW used in query that is not in a rule"),
9847 scanner_errposition(@1)));
9854 makeColumnRef(char *colname, List *indirection, int location)
9857 * Generate a ColumnRef node, with an A_Indirection node added if there
9858 * is any subscripting in the specified indirection list. However,
9859 * any field selection at the start of the indirection list must be
9860 * transposed into the "fields" part of the ColumnRef node.
9862 ColumnRef *c = makeNode(ColumnRef);
9866 c->location = location;
9867 foreach(l, indirection)
9869 if (IsA(lfirst(l), A_Indices))
9871 A_Indirection *i = makeNode(A_Indirection);
9875 /* easy case - all indirection goes to A_Indirection */
9876 c->fields = list_make1(makeString(colname));
9877 i->indirection = check_indirection(indirection);
9881 /* got to split the list in two */
9882 i->indirection = check_indirection(list_copy_tail(indirection,
9884 indirection = list_truncate(indirection, nfields);
9885 c->fields = lcons(makeString(colname), indirection);
9887 i->arg = (Node *) c;
9890 else if (IsA(lfirst(l), A_Star))
9892 /* We only allow '*' at the end of a ColumnRef */
9893 if (lnext(l) != NULL)
9894 yyerror("improper use of \"*\"");
9898 /* No subscripting, so all indirection gets added to field list */
9899 c->fields = lcons(makeString(colname), indirection);
9904 makeTypeCast(Node *arg, TypeName *typename, int location)
9906 TypeCast *n = makeNode(TypeCast);
9908 n->typename = typename;
9909 n->location = location;
9914 makeStringConst(char *str, int location)
9916 A_Const *n = makeNode(A_Const);
9918 n->val.type = T_String;
9919 n->val.val.str = str;
9920 n->location = location;
9926 makeStringConstCast(char *str, int location, TypeName *typename)
9928 Node *s = makeStringConst(str, location);
9930 return makeTypeCast(s, typename, -1);
9934 makeIntConst(int val, int location)
9936 A_Const *n = makeNode(A_Const);
9938 n->val.type = T_Integer;
9939 n->val.val.ival = val;
9940 n->location = location;
9946 makeFloatConst(char *str, int location)
9948 A_Const *n = makeNode(A_Const);
9950 n->val.type = T_Float;
9951 n->val.val.str = str;
9952 n->location = location;
9958 makeBitStringConst(char *str, int location)
9960 A_Const *n = makeNode(A_Const);
9962 n->val.type = T_BitString;
9963 n->val.val.str = str;
9964 n->location = location;
9970 makeNullAConst(int location)
9972 A_Const *n = makeNode(A_Const);
9974 n->val.type = T_Null;
9975 n->location = location;
9981 makeAConst(Value *v, int location)
9988 n = makeFloatConst(v->val.str, location);
9992 n = makeIntConst(v->val.ival, location);
9997 n = makeStringConst(v->val.str, location);
10004 /* makeBoolAConst()
10005 * Create an A_Const string node and put it inside a boolean cast.
10008 makeBoolAConst(bool state, int location)
10010 A_Const *n = makeNode(A_Const);
10012 n->val.type = T_String;
10013 n->val.val.str = (state ? "t" : "f");
10014 n->location = location;
10016 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
10020 * Create and populate a FuncCall node to support the OVERLAPS operator.
10023 makeOverlaps(List *largs, List *rargs, int location)
10025 FuncCall *n = makeNode(FuncCall);
10027 n->funcname = SystemFuncName("overlaps");
10028 if (list_length(largs) == 1)
10029 largs = lappend(largs, largs);
10030 else if (list_length(largs) != 2)
10032 (errcode(ERRCODE_SYNTAX_ERROR),
10033 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
10034 scanner_errposition(location)));
10035 if (list_length(rargs) == 1)
10036 rargs = lappend(rargs, rargs);
10037 else if (list_length(rargs) != 2)
10039 (errcode(ERRCODE_SYNTAX_ERROR),
10040 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
10041 scanner_errposition(location)));
10042 n->args = list_concat(largs, rargs);
10043 n->agg_star = FALSE;
10044 n->agg_distinct = FALSE;
10045 n->func_variadic = FALSE;
10046 n->location = location;
10050 /* check_qualified_name --- check the result of qualified_name production
10052 * It's easiest to let the grammar production for qualified_name allow
10053 * subscripts and '*', which we then must reject here.
10056 check_qualified_name(List *names)
10062 if (!IsA(lfirst(i), String))
10063 yyerror("syntax error");
10067 /* check_func_name --- check the result of func_name production
10069 * It's easiest to let the grammar production for func_name allow subscripts
10070 * and '*', which we then must reject here.
10073 check_func_name(List *names)
10079 if (!IsA(lfirst(i), String))
10080 yyerror("syntax error");
10085 /* check_indirection --- check the result of indirection production
10087 * We only allow '*' at the end of the list, but it's hard to enforce that
10088 * in the grammar, so do it here.
10091 check_indirection(List *indirection)
10095 foreach(l, indirection)
10097 if (IsA(lfirst(l), A_Star))
10099 if (lnext(l) != NULL)
10100 yyerror("improper use of \"*\"");
10103 return indirection;
10106 /* extractArgTypes()
10107 * Given a list of FunctionParameter nodes, extract a list of just the
10108 * argument types (TypeNames) for input parameters only. This is what
10109 * is needed to look up an existing function, which is what is wanted by
10110 * the productions that use this call.
10113 extractArgTypes(List *parameters)
10115 List *result = NIL;
10118 foreach(i, parameters)
10120 FunctionParameter *p = (FunctionParameter *) lfirst(i);
10122 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
10123 result = lappend(result, p->argType);
10128 /* findLeftmostSelect()
10129 * Find the leftmost component SelectStmt in a set-operation parsetree.
10131 static SelectStmt *
10132 findLeftmostSelect(SelectStmt *node)
10134 while (node && node->op != SETOP_NONE)
10136 Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
10140 /* insertSelectOptions()
10141 * Insert ORDER BY, etc into an already-constructed SelectStmt.
10143 * This routine is just to avoid duplicating code in SelectStmt productions.
10146 insertSelectOptions(SelectStmt *stmt,
10147 List *sortClause, List *lockingClause,
10148 Node *limitOffset, Node *limitCount,
10149 WithClause *withClause)
10151 Assert(IsA(stmt, SelectStmt));
10154 * Tests here are to reject constructs like
10155 * (SELECT foo ORDER BY bar) ORDER BY baz
10159 if (stmt->sortClause)
10161 (errcode(ERRCODE_SYNTAX_ERROR),
10162 errmsg("multiple ORDER BY clauses not allowed"),
10163 scanner_errposition(exprLocation((Node *) sortClause))));
10164 stmt->sortClause = sortClause;
10166 /* We can handle multiple locking clauses, though */
10167 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
10170 if (stmt->limitOffset)
10172 (errcode(ERRCODE_SYNTAX_ERROR),
10173 errmsg("multiple OFFSET clauses not allowed"),
10174 scanner_errposition(exprLocation(limitOffset))));
10175 stmt->limitOffset = limitOffset;
10179 if (stmt->limitCount)
10181 (errcode(ERRCODE_SYNTAX_ERROR),
10182 errmsg("multiple LIMIT clauses not allowed"),
10183 scanner_errposition(exprLocation(limitCount))));
10184 stmt->limitCount = limitCount;
10188 if (stmt->withClause)
10190 (errcode(ERRCODE_SYNTAX_ERROR),
10191 errmsg("multiple WITH clauses not allowed"),
10192 scanner_errposition(exprLocation((Node *) withClause))));
10193 stmt->withClause = withClause;
10198 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
10200 SelectStmt *n = makeNode(SelectStmt);
10204 n->larg = (SelectStmt *) larg;
10205 n->rarg = (SelectStmt *) rarg;
10209 /* SystemFuncName()
10210 * Build a properly-qualified reference to a built-in function.
10213 SystemFuncName(char *name)
10215 return list_make2(makeString("pg_catalog"), makeString(name));
10218 /* SystemTypeName()
10219 * Build a properly-qualified reference to a built-in type.
10221 * typmod is defaulted, but may be changed afterwards by caller.
10222 * Likewise for the location.
10225 SystemTypeName(char *name)
10227 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
10228 makeString(name)));
10232 * Handle negation of a numeric constant.
10234 * Formerly, we did this here because the optimizer couldn't cope with
10235 * indexquals that looked like "var = -4" --- it wants "var = const"
10236 * and a unary minus operator applied to a constant didn't qualify.
10237 * As of Postgres 7.0, that problem doesn't exist anymore because there
10238 * is a constant-subexpression simplifier in the optimizer. However,
10239 * there's still a good reason for doing this here, which is that we can
10240 * postpone committing to a particular internal representation for simple
10241 * negative constants. It's better to leave "-123.456" in string form
10242 * until we know what the desired type is.
10245 doNegate(Node *n, int location)
10247 if (IsA(n, A_Const))
10249 A_Const *con = (A_Const *)n;
10251 /* report the constant's location as that of the '-' sign */
10252 con->location = location;
10254 if (con->val.type == T_Integer)
10256 con->val.val.ival = -con->val.val.ival;
10259 if (con->val.type == T_Float)
10261 doNegateFloat(&con->val);
10266 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
10270 doNegateFloat(Value *v)
10272 char *oldval = v->val.str;
10274 Assert(IsA(v, Float));
10275 if (*oldval == '+')
10277 if (*oldval == '-')
10278 v->val.str = oldval+1; /* just strip the '-' */
10281 char *newval = (char *) palloc(strlen(oldval) + 2);
10284 strcpy(newval+1, oldval);
10285 v->val.str = newval;
10290 makeAArrayExpr(List *elements, int location)
10292 A_ArrayExpr *n = makeNode(A_ArrayExpr);
10294 n->elements = elements;
10295 n->location = location;
10300 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
10303 XmlExpr *x = makeNode(XmlExpr);
10308 * named_args is a list of ResTarget; it'll be split apart into separate
10309 * expression and name lists in transformXmlExpr().
10311 x->named_args = named_args;
10312 x->arg_names = NIL;
10314 /* xmloption, if relevant, must be filled in by caller */
10315 /* type and typmod will be filled in during parse analysis */
10316 x->location = location;
10321 * Initialize to parse one query string
10326 QueryIsRule = FALSE;
10330 * Merge the input and output parameters of a table function.
10333 mergeTableFuncParameters(List *func_args, List *columns)
10337 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
10338 foreach(lc, func_args)
10340 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
10342 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
10344 (errcode(ERRCODE_SYNTAX_ERROR),
10345 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
10348 return list_concat(func_args, columns);
10352 * Determine return type of a TABLE function. A single result column
10353 * returns setof that column's type; otherwise return setof record.
10356 TableFuncTypeName(List *columns)
10360 if (list_length(columns) == 1)
10362 FunctionParameter *p = (FunctionParameter *) linitial(columns);
10364 result = (TypeName *) copyObject(p->argType);
10367 result = SystemTypeName("record");
10369 result->setof = true;
10375 * Must undefine base_yylex before including scan.c, since we want it
10376 * to create the function base_yylex not filtered_base_yylex.