4 /*-------------------------------------------------------------------------
7 * POSTGRES SQL YACC rules/actions
9 * Portions Copyright (c) 1996-2009, 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.652 2009/01/07 22:54:45 momjian 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);
136 %name-prefix="base_yy"
147 DropBehavior dbehavior;
148 OnCommitAction oncommit;
155 FunctionParameter *fun_param;
156 FunctionParameterMode fun_param_mode;
157 FuncWithArgs *funwithargs;
159 OptionDefElem *optdef;
170 PrivTarget *privtarget;
173 VariableSetStmt *vsetstmt;
176 %type <node> stmt schema_stmt
177 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterFdwStmt
178 AlterForeignServerStmt AlterGroupStmt
179 AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterTableStmt
180 AlterUserStmt AlterUserMappingStmt AlterUserSetStmt AlterRoleStmt AlterRoleSetStmt
181 AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
182 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
183 CreateDomainStmt CreateGroupStmt CreateOpClassStmt
184 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
185 CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
186 CreateFdwStmt CreateForeignServerStmt CreateAssertStmt CreateTrigStmt
187 CreateUserStmt CreateUserMappingStmt CreateRoleStmt
188 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt
189 DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
190 DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
191 DropUserStmt DropdbStmt DropTableSpaceStmt DropFdwStmt
192 DropForeignServerStmt DropUserMappingStmt ExplainStmt FetchStmt
193 GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
194 LockStmt NotifyStmt ExplainableStmt PreparableStmt
195 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
196 RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
197 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
198 SelectStmt TransactionStmt TruncateStmt
199 UnlistenStmt UpdateStmt VacuumStmt
200 VariableResetStmt VariableSetStmt VariableShowStmt
201 ViewStmt CheckPointStmt CreateConversionStmt
202 DeallocateStmt PrepareStmt ExecuteStmt
203 DropOwnedStmt ReassignOwnedStmt
204 AlterTSConfigurationStmt AlterTSDictionaryStmt
206 %type <node> select_no_parens select_with_parens select_clause
207 simple_select values_clause
209 %type <node> alter_column_default opclass_item opclass_drop alter_using
210 %type <ival> add_drop opt_asc_desc opt_nulls_order
212 %type <node> alter_table_cmd
213 %type <list> alter_table_cmds
215 %type <dbehavior> opt_drop_behavior
217 %type <list> createdb_opt_list alterdb_opt_list copy_opt_list
218 transaction_mode_list
219 %type <defelt> createdb_opt_item alterdb_opt_item copy_opt_item
220 transaction_mode_item
222 %type <ival> opt_lock lock_type cast_context
223 %type <boolean> opt_force opt_or_replace
224 opt_grant_grant_option opt_grant_admin_option
225 opt_nowait opt_if_exists opt_with_data
227 %type <list> OptRoleList
228 %type <defelt> OptRoleElem
231 %type <str> foreign_server_version opt_foreign_server_version
232 %type <str> auth_ident
234 %type <str> OptSchemaName
235 %type <list> OptSchemaEltList
237 %type <boolean> TriggerActionTime TriggerForSpec opt_trusted opt_restart_seqs
238 %type <str> opt_lancompiler
240 %type <str> TriggerEvents
241 %type <value> TriggerFuncArg
243 %type <str> relation_name copy_file_name
244 database_name access_method_clause access_method attr_name
245 index_name name file_name cluster_index_specification
247 %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
248 opt_class opt_validator
250 %type <range> qualified_name OptConstrFromTable
252 %type <str> all_Op MathOp SpecialRuleRelation
254 %type <str> iso_level opt_encoding
256 %type <list> grantee_list
257 %type <str> privilege
258 %type <list> privileges privilege_list
259 %type <privtarget> privilege_target
260 %type <funwithargs> function_with_argtypes
261 %type <list> function_with_argtypes_list
262 %type <chr> TriggerOneEvent
264 %type <list> stmtblock stmtmulti
265 OptTableElementList TableElementList OptInherit definition
266 OptWith opt_distinct opt_definition func_args func_args_list
267 func_args_with_defaults func_args_with_defaults_list
268 func_as createfunc_opt_list alterfunc_opt_list
269 aggr_args old_aggr_definition old_aggr_list
270 oper_argtypes RuleActionList RuleActionMulti
271 opt_column_list columnList opt_name_list
272 sort_clause opt_sort_clause sortby_list index_params
273 name_list from_clause from_list opt_array_bounds
274 qualified_name_list any_name any_name_list
275 any_operator expr_list attrs
276 target_list insert_column_list set_target_list
277 set_clause_list set_clause multiple_set_clause
278 ctext_expr_list ctext_row def_list indirection opt_indirection
279 group_clause TriggerFuncArgs select_limit
280 opt_select_limit opclass_item_list opclass_drop_list
281 opt_opfamily transaction_mode_list_or_empty
282 TableFuncElementList opt_type_modifiers
284 execute_param_clause using_clause returning_clause
285 enum_val_list table_func_column_list
286 create_generic_options alter_generic_options
288 %type <range> OptTempTableName
289 %type <into> into_clause create_as_target
291 %type <defelt> createfunc_opt_item common_func_opt_item
292 %type <fun_param> func_arg func_arg_with_default table_func_column
293 %type <fun_param_mode> arg_class
294 %type <typnam> func_return func_type
296 %type <boolean> TriggerForType OptTemp
297 %type <oncommit> OnCommitOption
299 %type <node> for_locking_item
300 %type <list> for_locking_clause opt_for_locking_clause for_locking_items
301 %type <list> locked_rels_list
302 %type <boolean> opt_all
304 %type <node> join_outer join_qual
305 %type <jtype> join_type
307 %type <list> extract_list overlay_list position_list
308 %type <list> substr_list trim_list
309 %type <list> opt_interval interval_second
310 %type <node> overlay_placing substr_from substr_for
312 %type <boolean> opt_instead opt_analyze
313 %type <boolean> index_opt_unique opt_verbose opt_full
314 %type <boolean> opt_freeze opt_default opt_recheck
315 %type <defelt> opt_binary opt_oids copy_delimiter
317 %type <boolean> copy_from
319 %type <ival> opt_column event cursor_options opt_hold opt_set_data
320 %type <objtype> reindex_type drop_type comment_type
322 %type <node> fetch_direction select_limit_value select_offset_value
323 select_offset_value2 opt_select_fetch_first_value
324 %type <ival> row_or_rows first_or_next
326 %type <list> OptSeqOptList SeqOptList
327 %type <defelt> SeqOptElem
329 %type <istmt> insert_rest
331 %type <vsetstmt> set_rest SetResetClause
333 %type <node> TableElement ConstraintElem TableFuncElement
334 %type <node> columnDef
335 %type <defelt> def_elem old_aggr_elem
336 %type <node> def_arg columnElem where_clause where_or_current_clause
337 a_expr b_expr c_expr func_expr AexprConst indirection_el
338 columnref in_expr having_clause func_table array_expr
339 %type <list> row type_list array_expr_list
340 %type <node> case_expr case_arg when_clause case_default
341 %type <list> when_clause_list
342 %type <ival> sub_type
343 %type <list> OptCreateAs CreateAsList
344 %type <node> CreateAsElement ctext_expr
345 %type <value> NumericOnly
346 %type <alias> alias_clause
347 %type <sortby> sortby
348 %type <ielem> index_elem
349 %type <node> table_ref
350 %type <jexpr> joined_table
351 %type <range> relation_expr
352 %type <range> relation_expr_opt_alias
353 %type <target> target_el single_set_clause set_target insert_column_item
355 %type <str> generic_option_name
356 %type <node> generic_option_arg
357 %type <defelt> generic_option_elem
358 %type <optdef> alter_generic_option_elem
359 %type <list> generic_option_list alter_generic_option_list
361 %type <typnam> Typename SimpleTypename ConstTypename
362 GenericType Numeric opt_float
363 Character ConstCharacter
364 CharacterWithLength CharacterWithoutLength
365 ConstDatetime ConstInterval
366 Bit ConstBit BitWithLength BitWithoutLength
367 %type <str> character
368 %type <str> extract_arg
369 %type <str> opt_charset
370 %type <boolean> opt_varying opt_timezone
372 %type <ival> Iconst SignedIconst
373 %type <str> Sconst comment_text
374 %type <str> RoleId opt_granted_by opt_boolean ColId_or_Sconst
375 %type <list> var_list
376 %type <str> ColId ColLabel var_name type_function_name param_name
377 %type <node> var_value zone_value
379 %type <keyword> unreserved_keyword type_func_name_keyword
380 %type <keyword> col_name_keyword reserved_keyword
382 %type <node> TableConstraint TableLikeClause
383 %type <list> TableLikeOptionList
384 %type <ival> TableLikeOption
385 %type <list> ColQualList
386 %type <node> ColConstraint ColConstraintElem ConstraintAttr
387 %type <ival> key_actions key_delete key_match key_update key_action
388 %type <ival> ConstraintAttributeSpec ConstraintDeferrabilitySpec
391 %type <list> constraints_set_list
392 %type <boolean> constraints_set_mode
393 %type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
394 %type <list> opt_check_option
396 %type <target> xml_attribute_el
397 %type <list> xml_attribute_list xml_attributes
398 %type <node> xml_root_version opt_xml_root_standalone
399 %type <ival> document_or_content
400 %type <boolean> xml_whitespace_option
402 %type <node> common_table_expr
403 %type <with> with_clause
404 %type <list> cte_list
406 %type <list> window_clause window_definition_list opt_partition_clause
407 %type <windef> window_definition over_clause window_specification
408 %type <str> opt_existing_window_name
409 %type <ival> opt_frame_clause frame_extent frame_bound
413 * If you make any token changes, update the keyword table in
414 * parser/keywords.c and add new keywords to the appropriate one of
415 * the reserved-or-not-so-reserved keyword lists, below; search
416 * this file for "Name classification hierarchy".
419 /* ordinary key words in alphabetical order */
420 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
421 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
422 ASSERTION ASSIGNMENT ASYMMETRIC AT AUTHORIZATION
424 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
427 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
428 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
429 CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT
430 COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
431 CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
432 CREATEROLE CREATEUSER CROSS CSV CTYPE CURRENT_P
433 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
434 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
436 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
437 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
438 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
440 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT
441 EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
443 FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOLLOWING FOR FORCE FOREIGN FORWARD
444 FREEZE FROM FULL FUNCTION
446 GLOBAL GRANT GRANTED GREATEST GROUP_P
448 HANDLER HAVING HEADER_P HOLD HOUR_P
450 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
451 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY
452 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
453 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
459 LANCOMPILER LANGUAGE LARGE_P LAST_P LEADING LEAST LEFT LEVEL
460 LIBRARY LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP LOCATION
463 MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
465 NAME_P NAMES NATIONAL NATURAL NCHAR NEW NEXT NO NOCREATEDB
466 NOCREATEROLE NOCREATEUSER NOINHERIT NOLOGIN_P NONE NOSUPERUSER
467 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NULLS_P NUMERIC
469 OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OPTIONS OR
470 ORDER OUT_P OUTER_P OVER OVERLAPS OVERLAY OWNED OWNER
472 PARSER PARTIAL PARTITION PASSWORD PLACING PLANS POSITION
473 PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
474 PRIOR PRIVILEGES PROCEDURAL PROCEDURE
478 RANGE READ REAL REASSIGN RECHECK RECURSIVE REFERENCES REINDEX
479 RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA RESET RESTART
480 RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROW ROWS RULE
482 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE
483 SERIALIZABLE SERVER SESSION SESSION_USER SET SETOF SHARE
484 SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT
485 STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING SUPERUSER_P
486 SYMMETRIC SYSID SYSTEM_P
488 TABLE TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
489 TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
490 TRUNCATE TRUSTED TYPE_P
492 UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
495 VACUUM VALID VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
496 VERBOSE VERSION_P VIEW VOLATILE
498 WHEN WHERE WHITESPACE_P WINDOW WITH WITHOUT WORK WRAPPER WRITE
500 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLFOREST XMLPARSE
501 XMLPI XMLROOT XMLSERIALIZE
507 /* The grammar thinks these are keywords, but they are not in the keywords.c
508 * list and so can never be entered directly. The filter in parser.c
509 * creates these tokens when required.
511 %token NULLS_FIRST NULLS_LAST WITH_TIME
513 /* Special token types, not actually keywords - see the "lex" file */
514 %token <str> IDENT FCONST SCONST BCONST XCONST Op
515 %token <ival> ICONST PARAM
517 /* precedence: lowest to highest */
518 %nonassoc SET /* see relation_expr_opt_alias */
526 %nonassoc LIKE ILIKE SIMILAR
531 %left POSTFIXOP /* dummy for postfix Op rules */
533 * To support target_el without AS, we must give IDENT an explicit priority
534 * between POSTFIXOP and Op. We can safely assign the same priority to
535 * various unreserved keywords as needed to resolve ambiguities (this can't
536 * have any bad effects since obviously the keywords will still behave the
537 * same as if they weren't keywords). We need to do this for PARTITION,
538 * RANGE, ROWS to support opt_existing_window_name; and for RANGE, ROWS
539 * so that they can follow a_expr without creating
540 * postfix-operator problems.
542 %nonassoc IDENT PARTITION RANGE ROWS
543 %left Op OPERATOR /* multi-character ops and user-defined operators */
546 %nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN /* sets precedence for IS NULL, etc */
550 /* Unary Operators */
551 %left AT ZONE /* sets precedence for AT TIME ZONE */
558 * These might seem to be low-precedence, but actually they are not part
559 * of the arithmetic hierarchy at all in their use as JOIN operators.
560 * We make them high-precedence to support their use as function names.
561 * They wouldn't be given a precedence at all, were it not that we need
562 * left-associativity among the JOIN rules themselves.
564 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
565 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
566 %right PRESERVE STRIP_P
570 * Handle comment-only lines, and ;; SELECT * FROM pg_class ;;;
571 * psql already handles such cases, but other interfaces don't.
574 stmtblock: stmtmulti { parsetree = $1; }
577 /* the thrashing around here is to discard "empty" statements... */
578 stmtmulti: stmtmulti ';' stmt
580 $$ = lappend($1, $3);
594 | AlterDatabaseSetStmt
597 | AlterForeignServerStmt
600 | AlterObjectSchemaStmt
606 | AlterTSConfigurationStmt
607 | AlterTSDictionaryStmt
608 | AlterUserMappingStmt
621 | CreateConversionStmt
624 | CreateForeignServerStmt
634 | CreateTableSpaceStmt
638 | CreateUserMappingStmt
648 | DropForeignServerStmt
660 | DropUserMappingStmt
697 /*****************************************************************************
699 * Create a new Postgres DBMS role
701 *****************************************************************************/
704 CREATE ROLE RoleId opt_with OptRoleList
706 CreateRoleStmt *n = makeNode(CreateRoleStmt);
707 n->stmt_type = ROLESTMT_ROLE;
720 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
721 * for backwards compatibility). Note: the only option required by SQL99
722 * is "WITH ADMIN name".
725 OptRoleList OptRoleElem { $$ = lappend($1, $2); }
726 | /* EMPTY */ { $$ = NIL; }
732 $$ = makeDefElem("password",
733 (Node *)makeString($2));
737 $$ = makeDefElem("password", NULL);
739 | ENCRYPTED PASSWORD Sconst
741 $$ = makeDefElem("encryptedPassword",
742 (Node *)makeString($3));
744 | UNENCRYPTED PASSWORD Sconst
746 $$ = makeDefElem("unencryptedPassword",
747 (Node *)makeString($3));
751 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
755 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
759 $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE));
763 $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE));
767 $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
771 $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
775 $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE));
779 $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE));
783 /* For backwards compatibility, synonym for SUPERUSER */
784 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
788 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
792 $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE));
796 $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE));
798 | CONNECTION LIMIT SignedIconst
800 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3));
804 $$ = makeDefElem("validUntil", (Node *)makeString($3));
806 /* Supported but not documented for roles, for use by ALTER GROUP. */
809 $$ = makeDefElem("rolemembers", (Node *)$2);
811 /* The following are not supported by ALTER ROLE/USER/GROUP */
814 $$ = makeDefElem("sysid", (Node *)makeInteger($2));
818 $$ = makeDefElem("adminmembers", (Node *)$2);
822 $$ = makeDefElem("rolemembers", (Node *)$2);
824 | IN_P ROLE name_list
826 $$ = makeDefElem("addroleto", (Node *)$3);
828 | IN_P GROUP_P name_list
830 $$ = makeDefElem("addroleto", (Node *)$3);
835 /*****************************************************************************
837 * Create a new Postgres DBMS user (role with implied login ability)
839 *****************************************************************************/
842 CREATE USER RoleId opt_with OptRoleList
844 CreateRoleStmt *n = makeNode(CreateRoleStmt);
845 n->stmt_type = ROLESTMT_USER;
853 /*****************************************************************************
855 * Alter a postgresql DBMS role
857 *****************************************************************************/
860 ALTER ROLE RoleId opt_with OptRoleList
862 AlterRoleStmt *n = makeNode(AlterRoleStmt);
864 n->action = +1; /* add, if there are members */
871 ALTER ROLE RoleId SetResetClause
873 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
881 /*****************************************************************************
883 * Alter a postgresql DBMS user
885 *****************************************************************************/
888 ALTER USER RoleId opt_with OptRoleList
890 AlterRoleStmt *n = makeNode(AlterRoleStmt);
892 n->action = +1; /* add, if there are members */
900 ALTER USER RoleId SetResetClause
902 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
910 /*****************************************************************************
912 * Drop a postgresql DBMS role
914 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
915 * might own objects in multiple databases, there is presently no way to
916 * implement either cascading or restricting. Caveat DBA.
917 *****************************************************************************/
922 DropRoleStmt *n = makeNode(DropRoleStmt);
923 n->missing_ok = FALSE;
927 | DROP ROLE IF_P EXISTS name_list
929 DropRoleStmt *n = makeNode(DropRoleStmt);
930 n->missing_ok = TRUE;
936 /*****************************************************************************
938 * Drop a postgresql DBMS user
940 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
941 * might own objects in multiple databases, there is presently no way to
942 * implement either cascading or restricting. Caveat DBA.
943 *****************************************************************************/
948 DropRoleStmt *n = makeNode(DropRoleStmt);
949 n->missing_ok = FALSE;
953 | DROP USER IF_P EXISTS name_list
955 DropRoleStmt *n = makeNode(DropRoleStmt);
957 n->missing_ok = TRUE;
963 /*****************************************************************************
965 * Create a postgresql group (role without login ability)
967 *****************************************************************************/
970 CREATE GROUP_P RoleId opt_with OptRoleList
972 CreateRoleStmt *n = makeNode(CreateRoleStmt);
973 n->stmt_type = ROLESTMT_GROUP;
981 /*****************************************************************************
983 * Alter a postgresql group
985 *****************************************************************************/
988 ALTER GROUP_P RoleId add_drop USER name_list
990 AlterRoleStmt *n = makeNode(AlterRoleStmt);
993 n->options = list_make1(makeDefElem("rolemembers",
999 add_drop: ADD_P { $$ = +1; }
1004 /*****************************************************************************
1006 * Drop a postgresql group
1008 * XXX see above notes about cascading DROP USER; groups have same problem.
1009 *****************************************************************************/
1012 DROP GROUP_P name_list
1014 DropRoleStmt *n = makeNode(DropRoleStmt);
1015 n->missing_ok = FALSE;
1019 | DROP GROUP_P IF_P EXISTS name_list
1021 DropRoleStmt *n = makeNode(DropRoleStmt);
1022 n->missing_ok = TRUE;
1029 /*****************************************************************************
1031 * Manipulate a schema
1033 *****************************************************************************/
1036 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
1038 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1039 /* One can omit the schema name or the authorization id. */
1048 | CREATE SCHEMA ColId OptSchemaEltList
1050 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1051 /* ...but not both */
1061 | /* EMPTY */ { $$ = NULL; }
1065 OptSchemaEltList schema_stmt { $$ = lappend($1, $2); }
1066 | /* EMPTY */ { $$ = NIL; }
1070 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1071 * statement (in addition to by themselves).
1083 /*****************************************************************************
1085 * Set PG internal variable
1086 * SET name TO 'var_value'
1087 * Include SQL92 syntax (thomas 1997-10-22):
1088 * SET TIME ZONE 'var_value'
1090 *****************************************************************************/
1095 VariableSetStmt *n = $2;
1096 n->is_local = false;
1099 | SET LOCAL set_rest
1101 VariableSetStmt *n = $3;
1105 | SET SESSION set_rest
1107 VariableSetStmt *n = $3;
1108 n->is_local = false;
1113 set_rest: /* Generic SET syntaxes: */
1114 var_name TO var_list
1116 VariableSetStmt *n = makeNode(VariableSetStmt);
1117 n->kind = VAR_SET_VALUE;
1122 | var_name '=' var_list
1124 VariableSetStmt *n = makeNode(VariableSetStmt);
1125 n->kind = VAR_SET_VALUE;
1130 | var_name TO DEFAULT
1132 VariableSetStmt *n = makeNode(VariableSetStmt);
1133 n->kind = VAR_SET_DEFAULT;
1137 | var_name '=' DEFAULT
1139 VariableSetStmt *n = makeNode(VariableSetStmt);
1140 n->kind = VAR_SET_DEFAULT;
1144 | var_name FROM CURRENT_P
1146 VariableSetStmt *n = makeNode(VariableSetStmt);
1147 n->kind = VAR_SET_CURRENT;
1151 /* Special syntaxes mandated by SQL standard: */
1152 | TIME ZONE zone_value
1154 VariableSetStmt *n = makeNode(VariableSetStmt);
1155 n->kind = VAR_SET_VALUE;
1156 n->name = "timezone";
1158 n->args = list_make1($3);
1160 n->kind = VAR_SET_DEFAULT;
1163 | TRANSACTION transaction_mode_list
1165 VariableSetStmt *n = makeNode(VariableSetStmt);
1166 n->kind = VAR_SET_MULTI;
1167 n->name = "TRANSACTION";
1171 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1173 VariableSetStmt *n = makeNode(VariableSetStmt);
1174 n->kind = VAR_SET_MULTI;
1175 n->name = "SESSION CHARACTERISTICS";
1182 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1183 errmsg("current database cannot be changed"),
1184 scanner_errposition(@2)));
1185 $$ = NULL; /*not reached*/
1189 VariableSetStmt *n = makeNode(VariableSetStmt);
1190 n->kind = VAR_SET_VALUE;
1191 n->name = "search_path";
1192 n->args = list_make1(makeStringConst($2, @2));
1195 | NAMES opt_encoding
1197 VariableSetStmt *n = makeNode(VariableSetStmt);
1198 n->kind = VAR_SET_VALUE;
1199 n->name = "client_encoding";
1201 n->args = list_make1(makeStringConst($2, @2));
1203 n->kind = VAR_SET_DEFAULT;
1206 | ROLE ColId_or_Sconst
1208 VariableSetStmt *n = makeNode(VariableSetStmt);
1209 n->kind = VAR_SET_VALUE;
1211 n->args = list_make1(makeStringConst($2, @2));
1214 | SESSION AUTHORIZATION ColId_or_Sconst
1216 VariableSetStmt *n = makeNode(VariableSetStmt);
1217 n->kind = VAR_SET_VALUE;
1218 n->name = "session_authorization";
1219 n->args = list_make1(makeStringConst($3, @3));
1222 | SESSION AUTHORIZATION DEFAULT
1224 VariableSetStmt *n = makeNode(VariableSetStmt);
1225 n->kind = VAR_SET_DEFAULT;
1226 n->name = "session_authorization";
1229 | XML_P OPTION document_or_content
1231 VariableSetStmt *n = makeNode(VariableSetStmt);
1232 n->kind = VAR_SET_VALUE;
1233 n->name = "xmloption";
1234 n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1239 var_name: ColId { $$ = $1; }
1240 | var_name '.' ColId
1242 $$ = palloc(strlen($1) + strlen($3) + 2);
1243 sprintf($$, "%s.%s", $1, $3);
1247 var_list: var_value { $$ = list_make1($1); }
1248 | var_list ',' var_value { $$ = lappend($1, $3); }
1251 var_value: opt_boolean
1252 { $$ = makeStringConst($1, @1); }
1254 { $$ = makeStringConst($1, @1); }
1256 { $$ = makeAConst($1, @1); }
1259 iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1260 | READ COMMITTED { $$ = "read committed"; }
1261 | REPEATABLE READ { $$ = "repeatable read"; }
1262 | SERIALIZABLE { $$ = "serializable"; }
1266 TRUE_P { $$ = "true"; }
1267 | FALSE_P { $$ = "false"; }
1269 | OFF { $$ = "off"; }
1272 /* Timezone values can be:
1273 * - a string such as 'pst8pdt'
1274 * - an identifier such as "pst8pdt"
1275 * - an integer or floating point number
1276 * - a time interval per SQL99
1277 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1278 * so use IDENT (meaning we reject anything that is a key word).
1283 $$ = makeStringConst($1, @1);
1287 $$ = makeStringConst($1, @1);
1289 | ConstInterval Sconst opt_interval
1294 A_Const *n = (A_Const *) linitial($3);
1295 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1297 (errcode(ERRCODE_SYNTAX_ERROR),
1298 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1299 scanner_errposition(@3)));
1302 $$ = makeStringConstCast($2, @2, t);
1304 | ConstInterval '(' Iconst ')' Sconst opt_interval
1309 A_Const *n = (A_Const *) linitial($6);
1310 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1312 (errcode(ERRCODE_SYNTAX_ERROR),
1313 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1314 scanner_errposition(@6)));
1315 if (list_length($6) != 1)
1317 (errcode(ERRCODE_SYNTAX_ERROR),
1318 errmsg("interval precision specified twice"),
1319 scanner_errposition(@1)));
1320 t->typmods = lappend($6, makeIntConst($3, @3));
1323 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1324 makeIntConst($3, @3));
1325 $$ = makeStringConstCast($5, @5, t);
1327 | NumericOnly { $$ = makeAConst($1, @1); }
1328 | DEFAULT { $$ = NULL; }
1329 | LOCAL { $$ = NULL; }
1334 | DEFAULT { $$ = NULL; }
1335 | /*EMPTY*/ { $$ = NULL; }
1340 | Sconst { $$ = $1; }
1346 VariableSetStmt *n = makeNode(VariableSetStmt);
1347 n->kind = VAR_RESET;
1353 VariableSetStmt *n = makeNode(VariableSetStmt);
1354 n->kind = VAR_RESET;
1355 n->name = "timezone";
1358 | RESET TRANSACTION ISOLATION LEVEL
1360 VariableSetStmt *n = makeNode(VariableSetStmt);
1361 n->kind = VAR_RESET;
1362 n->name = "transaction_isolation";
1365 | RESET SESSION AUTHORIZATION
1367 VariableSetStmt *n = makeNode(VariableSetStmt);
1368 n->kind = VAR_RESET;
1369 n->name = "session_authorization";
1374 VariableSetStmt *n = makeNode(VariableSetStmt);
1375 n->kind = VAR_RESET_ALL;
1380 /* SetResetClause allows SET or RESET without LOCAL */
1382 SET set_rest { $$ = $2; }
1383 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1390 VariableShowStmt *n = makeNode(VariableShowStmt);
1396 VariableShowStmt *n = makeNode(VariableShowStmt);
1397 n->name = "timezone";
1400 | SHOW TRANSACTION ISOLATION LEVEL
1402 VariableShowStmt *n = makeNode(VariableShowStmt);
1403 n->name = "transaction_isolation";
1406 | SHOW SESSION AUTHORIZATION
1408 VariableShowStmt *n = makeNode(VariableShowStmt);
1409 n->name = "session_authorization";
1414 VariableShowStmt *n = makeNode(VariableShowStmt);
1422 SET CONSTRAINTS constraints_set_list constraints_set_mode
1424 ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
1425 n->constraints = $3;
1431 constraints_set_list:
1433 | qualified_name_list { $$ = $1; }
1436 constraints_set_mode:
1437 DEFERRED { $$ = TRUE; }
1438 | IMMEDIATE { $$ = FALSE; }
1443 * Checkpoint statement
1448 CheckPointStmt *n = makeNode(CheckPointStmt);
1454 /*****************************************************************************
1456 * DISCARD { ALL | TEMP | PLANS }
1458 *****************************************************************************/
1463 DiscardStmt *n = makeNode(DiscardStmt);
1464 n->target = DISCARD_ALL;
1469 DiscardStmt *n = makeNode(DiscardStmt);
1470 n->target = DISCARD_TEMP;
1475 DiscardStmt *n = makeNode(DiscardStmt);
1476 n->target = DISCARD_TEMP;
1481 DiscardStmt *n = makeNode(DiscardStmt);
1482 n->target = DISCARD_PLANS;
1488 /*****************************************************************************
1490 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations
1492 * Note: we accept all subcommands for each of the four variants, and sort
1493 * out what's really legal at execution time.
1494 *****************************************************************************/
1497 ALTER TABLE relation_expr alter_table_cmds
1499 AlterTableStmt *n = makeNode(AlterTableStmt);
1502 n->relkind = OBJECT_TABLE;
1505 | ALTER INDEX relation_expr alter_table_cmds
1507 AlterTableStmt *n = makeNode(AlterTableStmt);
1510 n->relkind = OBJECT_INDEX;
1513 | ALTER SEQUENCE relation_expr alter_table_cmds
1515 AlterTableStmt *n = makeNode(AlterTableStmt);
1518 n->relkind = OBJECT_SEQUENCE;
1521 | ALTER VIEW relation_expr alter_table_cmds
1523 AlterTableStmt *n = makeNode(AlterTableStmt);
1526 n->relkind = OBJECT_VIEW;
1532 alter_table_cmd { $$ = list_make1($1); }
1533 | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
1537 /* ALTER TABLE <name> ADD [COLUMN] <coldef> */
1538 ADD_P opt_column columnDef
1540 AlterTableCmd *n = makeNode(AlterTableCmd);
1541 n->subtype = AT_AddColumn;
1545 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1546 | ALTER opt_column ColId alter_column_default
1548 AlterTableCmd *n = makeNode(AlterTableCmd);
1549 n->subtype = AT_ColumnDefault;
1554 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1555 | ALTER opt_column ColId DROP NOT NULL_P
1557 AlterTableCmd *n = makeNode(AlterTableCmd);
1558 n->subtype = AT_DropNotNull;
1562 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1563 | ALTER opt_column ColId SET NOT NULL_P
1565 AlterTableCmd *n = makeNode(AlterTableCmd);
1566 n->subtype = AT_SetNotNull;
1570 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
1571 | ALTER opt_column ColId SET STATISTICS SignedIconst
1573 AlterTableCmd *n = makeNode(AlterTableCmd);
1574 n->subtype = AT_SetStatistics;
1576 n->def = (Node *) makeInteger($6);
1579 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1580 | ALTER opt_column ColId SET STORAGE ColId
1582 AlterTableCmd *n = makeNode(AlterTableCmd);
1583 n->subtype = AT_SetStorage;
1585 n->def = (Node *) makeString($6);
1588 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1589 | DROP opt_column ColId opt_drop_behavior
1591 AlterTableCmd *n = makeNode(AlterTableCmd);
1592 n->subtype = AT_DropColumn;
1598 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
1599 * [ USING <expression> ]
1601 | ALTER opt_column ColId opt_set_data TYPE_P Typename alter_using
1603 AlterTableCmd *n = makeNode(AlterTableCmd);
1604 n->subtype = AT_AlterColumnType;
1606 n->def = (Node *) $6;
1610 /* ALTER TABLE <name> ADD CONSTRAINT ... */
1611 | ADD_P TableConstraint
1613 AlterTableCmd *n = makeNode(AlterTableCmd);
1614 n->subtype = AT_AddConstraint;
1618 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1619 | DROP CONSTRAINT name opt_drop_behavior
1621 AlterTableCmd *n = makeNode(AlterTableCmd);
1622 n->subtype = AT_DropConstraint;
1627 /* ALTER TABLE <name> SET WITHOUT OIDS */
1630 AlterTableCmd *n = makeNode(AlterTableCmd);
1631 n->subtype = AT_DropOids;
1634 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1637 AlterTableCmd *n = makeNode(AlterTableCmd);
1638 n->subtype = AT_ClusterOn;
1642 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1643 | SET WITHOUT CLUSTER
1645 AlterTableCmd *n = makeNode(AlterTableCmd);
1646 n->subtype = AT_DropCluster;
1650 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
1651 | ENABLE_P TRIGGER name
1653 AlterTableCmd *n = makeNode(AlterTableCmd);
1654 n->subtype = AT_EnableTrig;
1658 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
1659 | ENABLE_P ALWAYS TRIGGER name
1661 AlterTableCmd *n = makeNode(AlterTableCmd);
1662 n->subtype = AT_EnableAlwaysTrig;
1666 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
1667 | ENABLE_P REPLICA TRIGGER name
1669 AlterTableCmd *n = makeNode(AlterTableCmd);
1670 n->subtype = AT_EnableReplicaTrig;
1674 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
1675 | ENABLE_P TRIGGER ALL
1677 AlterTableCmd *n = makeNode(AlterTableCmd);
1678 n->subtype = AT_EnableTrigAll;
1681 /* ALTER TABLE <name> ENABLE TRIGGER USER */
1682 | ENABLE_P TRIGGER USER
1684 AlterTableCmd *n = makeNode(AlterTableCmd);
1685 n->subtype = AT_EnableTrigUser;
1688 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
1689 | DISABLE_P TRIGGER name
1691 AlterTableCmd *n = makeNode(AlterTableCmd);
1692 n->subtype = AT_DisableTrig;
1696 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
1697 | DISABLE_P TRIGGER ALL
1699 AlterTableCmd *n = makeNode(AlterTableCmd);
1700 n->subtype = AT_DisableTrigAll;
1703 /* ALTER TABLE <name> DISABLE TRIGGER USER */
1704 | DISABLE_P TRIGGER USER
1706 AlterTableCmd *n = makeNode(AlterTableCmd);
1707 n->subtype = AT_DisableTrigUser;
1710 /* ALTER TABLE <name> ENABLE RULE <rule> */
1711 | ENABLE_P RULE name
1713 AlterTableCmd *n = makeNode(AlterTableCmd);
1714 n->subtype = AT_EnableRule;
1718 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
1719 | ENABLE_P ALWAYS RULE name
1721 AlterTableCmd *n = makeNode(AlterTableCmd);
1722 n->subtype = AT_EnableAlwaysRule;
1726 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
1727 | ENABLE_P REPLICA RULE name
1729 AlterTableCmd *n = makeNode(AlterTableCmd);
1730 n->subtype = AT_EnableReplicaRule;
1734 /* ALTER TABLE <name> DISABLE RULE <rule> */
1735 | DISABLE_P RULE name
1737 AlterTableCmd *n = makeNode(AlterTableCmd);
1738 n->subtype = AT_DisableRule;
1742 /* ALTER TABLE <name> INHERIT <parent> */
1743 | INHERIT qualified_name
1745 AlterTableCmd *n = makeNode(AlterTableCmd);
1746 n->subtype = AT_AddInherit;
1747 n->def = (Node *) $2;
1750 /* ALTER TABLE <name> NO INHERIT <parent> */
1751 | NO INHERIT qualified_name
1753 AlterTableCmd *n = makeNode(AlterTableCmd);
1754 n->subtype = AT_DropInherit;
1755 n->def = (Node *) $3;
1758 /* ALTER TABLE <name> OWNER TO RoleId */
1761 AlterTableCmd *n = makeNode(AlterTableCmd);
1762 n->subtype = AT_ChangeOwner;
1766 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1767 | SET TABLESPACE name
1769 AlterTableCmd *n = makeNode(AlterTableCmd);
1770 n->subtype = AT_SetTableSpace;
1774 /* ALTER TABLE <name> SET (...) */
1777 AlterTableCmd *n = makeNode(AlterTableCmd);
1778 n->subtype = AT_SetRelOptions;
1779 n->def = (Node *)$2;
1782 /* ALTER TABLE <name> RESET (...) */
1785 AlterTableCmd *n = makeNode(AlterTableCmd);
1786 n->subtype = AT_ResetRelOptions;
1787 n->def = (Node *)$2;
1792 alter_column_default:
1793 SET DEFAULT a_expr { $$ = $3; }
1794 | DROP DEFAULT { $$ = NULL; }
1798 CASCADE { $$ = DROP_CASCADE; }
1799 | RESTRICT { $$ = DROP_RESTRICT; }
1800 | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1804 USING a_expr { $$ = $2; }
1805 | /* EMPTY */ { $$ = NULL; }
1810 /*****************************************************************************
1813 * close <portalname>
1815 *****************************************************************************/
1820 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1826 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1827 n->portalname = NULL;
1833 /*****************************************************************************
1836 * COPY relname ['(' columnList ')'] FROM/TO file [WITH options]
1838 * BINARY, OIDS, and DELIMITERS kept in old locations
1839 * for backward compatibility. 2002-06-18
1841 * COPY ( SELECT ... ) TO file [WITH options]
1842 * This form doesn't have the backwards-compatible option
1845 *****************************************************************************/
1847 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
1848 copy_from copy_file_name copy_delimiter opt_with copy_opt_list
1850 CopyStmt *n = makeNode(CopyStmt);
1858 /* Concatenate user-supplied flags */
1860 n->options = lappend(n->options, $2);
1862 n->options = lappend(n->options, $5);
1864 n->options = lappend(n->options, $8);
1866 n->options = list_concat(n->options, $10);
1869 | COPY select_with_parens TO copy_file_name opt_with
1872 CopyStmt *n = makeNode(CopyStmt);
1885 | TO { $$ = FALSE; }
1889 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
1890 * used depends on the direction. (It really doesn't make sense to copy from
1891 * stdout. We silently correct the "typo".) - AY 9/94
1895 | STDIN { $$ = NULL; }
1896 | STDOUT { $$ = NULL; }
1902 copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
1903 | /* EMPTY */ { $$ = NIL; }
1910 $$ = makeDefElem("binary", (Node *)makeInteger(TRUE));
1914 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
1916 | DELIMITER opt_as Sconst
1918 $$ = makeDefElem("delimiter", (Node *)makeString($3));
1920 | NULL_P opt_as Sconst
1922 $$ = makeDefElem("null", (Node *)makeString($3));
1926 $$ = makeDefElem("csv", (Node *)makeInteger(TRUE));
1930 $$ = makeDefElem("header", (Node *)makeInteger(TRUE));
1932 | QUOTE opt_as Sconst
1934 $$ = makeDefElem("quote", (Node *)makeString($3));
1936 | ESCAPE opt_as Sconst
1938 $$ = makeDefElem("escape", (Node *)makeString($3));
1940 | FORCE QUOTE columnList
1942 $$ = makeDefElem("force_quote", (Node *)$3);
1944 | FORCE NOT NULL_P columnList
1946 $$ = makeDefElem("force_notnull", (Node *)$4);
1950 /* The following exist for backward compatibility */
1955 $$ = makeDefElem("binary", (Node *)makeInteger(TRUE));
1957 | /*EMPTY*/ { $$ = NULL; }
1963 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
1965 | /*EMPTY*/ { $$ = NULL; }
1969 /* USING DELIMITERS kept for backward compatibility. 2002-06-15 */
1970 opt_using DELIMITERS Sconst
1972 $$ = makeDefElem("delimiter", (Node *)makeString($3));
1974 | /*EMPTY*/ { $$ = NULL; }
1983 /*****************************************************************************
1986 * CREATE TABLE relname
1988 *****************************************************************************/
1990 CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
1991 OptInherit OptWith OnCommitOption OptTableSpace
1993 CreateStmt *n = makeNode(CreateStmt);
1997 n->inhRelations = $8;
1998 n->constraints = NIL;
2001 n->tablespacename = $11;
2004 | CREATE OptTemp TABLE qualified_name OF qualified_name
2005 '(' OptTableElementList ')' OptWith OnCommitOption OptTableSpace
2007 /* SQL99 CREATE TABLE OF <UDT> (cols) seems to be satisfied
2008 * by our inheritance capabilities. Let's try it...
2010 CreateStmt *n = makeNode(CreateStmt);
2014 n->inhRelations = list_make1($6);
2015 n->constraints = NIL;
2018 n->tablespacename = $12;
2024 * Redundancy here is needed to avoid shift/reduce conflicts,
2025 * since TEMP is not a reserved word. See also OptTempTableName.
2027 * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
2028 * the LOCAL keyword is really meaningless.
2030 OptTemp: TEMPORARY { $$ = TRUE; }
2031 | TEMP { $$ = TRUE; }
2032 | LOCAL TEMPORARY { $$ = TRUE; }
2033 | LOCAL TEMP { $$ = TRUE; }
2034 | GLOBAL TEMPORARY { $$ = TRUE; }
2035 | GLOBAL TEMP { $$ = TRUE; }
2036 | /*EMPTY*/ { $$ = FALSE; }
2039 OptTableElementList:
2040 TableElementList { $$ = $1; }
2041 | /*EMPTY*/ { $$ = NIL; }
2047 $$ = list_make1($1);
2049 | TableElementList ',' TableElement
2051 $$ = lappend($1, $3);
2056 columnDef { $$ = $1; }
2057 | TableLikeClause { $$ = $1; }
2058 | TableConstraint { $$ = $1; }
2061 columnDef: ColId Typename ColQualList
2063 ColumnDef *n = makeNode(ColumnDef);
2066 n->constraints = $3;
2073 ColQualList ColConstraint { $$ = lappend($1, $2); }
2074 | /*EMPTY*/ { $$ = NIL; }
2078 CONSTRAINT name ColConstraintElem
2080 switch (nodeTag($3))
2084 Constraint *n = (Constraint *)$3;
2088 case T_FkConstraint:
2090 FkConstraint *n = (FkConstraint *)$3;
2091 n->constr_name = $2;
2099 | ColConstraintElem { $$ = $1; }
2100 | ConstraintAttr { $$ = $1; }
2103 /* DEFAULT NULL is already the default for Postgres.
2104 * But define it here and carry it forward into the system
2105 * to make it explicit.
2106 * - thomas 1998-09-13
2108 * WITH NULL and NULL are not SQL92-standard syntax elements,
2109 * so leave them out. Use DEFAULT NULL to explicitly indicate
2110 * that a column may have that value. WITH NULL leads to
2111 * shift/reduce conflicts with WITH TIME ZONE anyway.
2112 * - thomas 1999-01-08
2114 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
2115 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
2116 * or be part of a_expr NOT LIKE or similar constructs).
2121 Constraint *n = makeNode(Constraint);
2122 n->contype = CONSTR_NOTNULL;
2125 n->cooked_expr = NULL;
2127 n->indexspace = NULL;
2132 Constraint *n = makeNode(Constraint);
2133 n->contype = CONSTR_NULL;
2136 n->cooked_expr = NULL;
2138 n->indexspace = NULL;
2141 | UNIQUE opt_definition OptConsTableSpace
2143 Constraint *n = makeNode(Constraint);
2144 n->contype = CONSTR_UNIQUE;
2147 n->cooked_expr = NULL;
2153 | PRIMARY KEY opt_definition OptConsTableSpace
2155 Constraint *n = makeNode(Constraint);
2156 n->contype = CONSTR_PRIMARY;
2159 n->cooked_expr = NULL;
2165 | CHECK '(' a_expr ')'
2167 Constraint *n = makeNode(Constraint);
2168 n->contype = CONSTR_CHECK;
2171 n->cooked_expr = NULL;
2173 n->indexspace = NULL;
2178 Constraint *n = makeNode(Constraint);
2179 n->contype = CONSTR_DEFAULT;
2182 n->cooked_expr = NULL;
2184 n->indexspace = NULL;
2187 | REFERENCES qualified_name opt_column_list key_match key_actions
2189 FkConstraint *n = makeNode(FkConstraint);
2190 n->constr_name = NULL;
2194 n->fk_matchtype = $4;
2195 n->fk_upd_action = (char) ($5 >> 8);
2196 n->fk_del_action = (char) ($5 & 0xFF);
2197 n->deferrable = FALSE;
2198 n->initdeferred = FALSE;
2204 * ConstraintAttr represents constraint attributes, which we parse as if
2205 * they were independent constraint clauses, in order to avoid shift/reduce
2206 * conflicts (since NOT might start either an independent NOT NULL clause
2207 * or an attribute). parse_utilcmd.c is responsible for attaching the
2208 * attribute information to the preceding "real" constraint node, and for
2209 * complaining if attribute clauses appear in the wrong place or wrong
2212 * See also ConstraintAttributeSpec, which can be used in places where
2213 * there is no parsing conflict.
2218 Constraint *n = makeNode(Constraint);
2219 n->contype = CONSTR_ATTR_DEFERRABLE;
2224 Constraint *n = makeNode(Constraint);
2225 n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
2228 | INITIALLY DEFERRED
2230 Constraint *n = makeNode(Constraint);
2231 n->contype = CONSTR_ATTR_DEFERRED;
2234 | INITIALLY IMMEDIATE
2236 Constraint *n = makeNode(Constraint);
2237 n->contype = CONSTR_ATTR_IMMEDIATE;
2244 * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2245 * This seems to be a poor man's inheritance capability, with the resulting
2246 * tables completely decoupled except for the original commonality in definitions.
2248 * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2249 * which is a part of SQL:2003.
2252 LIKE qualified_name TableLikeOptionList
2254 InhRelation *n = makeNode(InhRelation);
2261 TableLikeOptionList:
2262 TableLikeOptionList TableLikeOption { $$ = lappend_int($1, $2); }
2263 | /* EMPTY */ { $$ = NIL; }
2267 INCLUDING DEFAULTS { $$ = CREATE_TABLE_LIKE_INCLUDING_DEFAULTS; }
2268 | EXCLUDING DEFAULTS { $$ = CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS; }
2269 | INCLUDING CONSTRAINTS { $$ = CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS; }
2270 | EXCLUDING CONSTRAINTS { $$ = CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS; }
2271 | INCLUDING INDEXES { $$ = CREATE_TABLE_LIKE_INCLUDING_INDEXES; }
2272 | EXCLUDING INDEXES { $$ = CREATE_TABLE_LIKE_EXCLUDING_INDEXES; }
2276 /* ConstraintElem specifies constraint syntax which is not embedded into
2277 * a column definition. ColConstraintElem specifies the embedded form.
2278 * - thomas 1997-12-03
2281 CONSTRAINT name ConstraintElem
2283 switch (nodeTag($3))
2287 Constraint *n = (Constraint *)$3;
2291 case T_FkConstraint:
2293 FkConstraint *n = (FkConstraint *)$3;
2294 n->constr_name = $2;
2302 | ConstraintElem { $$ = $1; }
2306 CHECK '(' a_expr ')'
2308 Constraint *n = makeNode(Constraint);
2309 n->contype = CONSTR_CHECK;
2312 n->cooked_expr = NULL;
2313 n->indexspace = NULL;
2316 | UNIQUE '(' columnList ')' opt_definition OptConsTableSpace
2318 Constraint *n = makeNode(Constraint);
2319 n->contype = CONSTR_UNIQUE;
2322 n->cooked_expr = NULL;
2328 | PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace
2330 Constraint *n = makeNode(Constraint);
2331 n->contype = CONSTR_PRIMARY;
2334 n->cooked_expr = NULL;
2340 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
2341 opt_column_list key_match key_actions ConstraintAttributeSpec
2343 FkConstraint *n = makeNode(FkConstraint);
2344 n->constr_name = NULL;
2348 n->fk_matchtype = $9;
2349 n->fk_upd_action = (char) ($10 >> 8);
2350 n->fk_del_action = (char) ($10 & 0xFF);
2351 n->deferrable = ($11 & 1) != 0;
2352 n->initdeferred = ($11 & 2) != 0;
2358 '(' columnList ')' { $$ = $2; }
2359 | /*EMPTY*/ { $$ = NIL; }
2363 columnElem { $$ = list_make1($1); }
2364 | columnList ',' columnElem { $$ = lappend($1, $3); }
2369 $$ = (Node *) makeString($1);
2373 key_match: MATCH FULL
2375 $$ = FKCONSTR_MATCH_FULL;
2380 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2381 errmsg("MATCH PARTIAL not yet implemented"),
2382 scanner_errposition(@1)));
2383 $$ = FKCONSTR_MATCH_PARTIAL;
2387 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2391 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2396 * We combine the update and delete actions into one value temporarily
2397 * for simplicity of parsing, and then break them down again in the
2398 * calling production. update is in the left 8 bits, delete in the right.
2399 * Note that NOACTION is the default.
2403 { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2405 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
2406 | key_update key_delete
2407 { $$ = ($1 << 8) | ($2 & 0xFF); }
2408 | key_delete key_update
2409 { $$ = ($2 << 8) | ($1 & 0xFF); }
2411 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2414 key_update: ON UPDATE key_action { $$ = $3; }
2417 key_delete: ON DELETE_P key_action { $$ = $3; }
2421 NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; }
2422 | RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; }
2423 | CASCADE { $$ = FKCONSTR_ACTION_CASCADE; }
2424 | SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; }
2425 | SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; }
2428 OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
2429 | /*EMPTY*/ { $$ = NIL; }
2432 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
2434 WITH definition { $$ = $2; }
2435 | WITH OIDS { $$ = list_make1(defWithOids(true)); }
2436 | WITHOUT OIDS { $$ = list_make1(defWithOids(false)); }
2437 | /*EMPTY*/ { $$ = NIL; }
2440 OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
2441 | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
2442 | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
2443 | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
2446 OptTableSpace: TABLESPACE name { $$ = $2; }
2447 | /*EMPTY*/ { $$ = NULL; }
2450 OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
2451 | /*EMPTY*/ { $$ = NULL; }
2456 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
2461 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
2464 * When the SelectStmt is a set-operation tree, we must
2465 * stuff the INTO information into the leftmost component
2466 * Select, because that's where analyze.c will expect
2467 * to find it. Similarly, the output column names must
2468 * be attached to that Select's target list.
2470 SelectStmt *n = findLeftmostSelect((SelectStmt *) $6);
2471 if (n->intoClause != NULL)
2473 (errcode(ERRCODE_SYNTAX_ERROR),
2474 errmsg("CREATE TABLE AS cannot specify INTO"),
2475 scanner_errposition(exprLocation((Node *) n->intoClause))));
2476 $4->rel->istemp = $2;
2478 /* Implement WITH NO DATA by forcing top-level LIMIT 0 */
2480 ((SelectStmt *) $6)->limitCount = makeIntConst(0, -1);
2486 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
2488 $$ = makeNode(IntoClause);
2493 $$->tableSpaceName = $5;
2498 '(' CreateAsList ')' { $$ = $2; }
2499 | /*EMPTY*/ { $$ = NIL; }
2503 CreateAsElement { $$ = list_make1($1); }
2504 | CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); }
2510 ColumnDef *n = makeNode(ColumnDef);
2515 n->is_not_null = false;
2516 n->raw_default = NULL;
2517 n->cooked_default = NULL;
2518 n->constraints = NIL;
2524 WITH DATA_P { $$ = TRUE; }
2525 | WITH NO DATA_P { $$ = FALSE; }
2526 | /*EMPTY*/ { $$ = TRUE; }
2530 /*****************************************************************************
2533 * CREATE SEQUENCE seqname
2534 * ALTER SEQUENCE seqname
2536 *****************************************************************************/
2539 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
2541 CreateSeqStmt *n = makeNode(CreateSeqStmt);
2550 ALTER SEQUENCE relation_expr SeqOptList
2552 AlterSeqStmt *n = makeNode(AlterSeqStmt);
2559 OptSeqOptList: SeqOptList { $$ = $1; }
2560 | /*EMPTY*/ { $$ = NIL; }
2563 SeqOptList: SeqOptElem { $$ = list_make1($1); }
2564 | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
2567 SeqOptElem: CACHE NumericOnly
2569 $$ = makeDefElem("cache", (Node *)$2);
2573 $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE));
2577 $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE));
2579 | INCREMENT opt_by NumericOnly
2581 $$ = makeDefElem("increment", (Node *)$3);
2583 | MAXVALUE NumericOnly
2585 $$ = makeDefElem("maxvalue", (Node *)$2);
2587 | MINVALUE NumericOnly
2589 $$ = makeDefElem("minvalue", (Node *)$2);
2593 $$ = makeDefElem("maxvalue", NULL);
2597 $$ = makeDefElem("minvalue", NULL);
2601 $$ = makeDefElem("owned_by", (Node *)$3);
2603 | START opt_with NumericOnly
2605 $$ = makeDefElem("start", (Node *)$3);
2609 $$ = makeDefElem("restart", NULL);
2611 | RESTART opt_with NumericOnly
2613 $$ = makeDefElem("restart", (Node *)$3);
2622 FCONST { $$ = makeFloat($1); }
2628 | SignedIconst { $$ = makeInteger($1); };
2631 /*****************************************************************************
2634 * CREATE PROCEDURAL LANGUAGE ...
2635 * DROP PROCEDURAL LANGUAGE ...
2637 *****************************************************************************/
2640 CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2642 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2644 /* parameters are all to be supplied by system */
2646 n->plvalidator = NIL;
2647 n->pltrusted = false;
2650 | CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2651 HANDLER handler_name opt_validator opt_lancompiler
2653 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2656 n->plvalidator = $8;
2658 /* LANCOMPILER is now ignored entirely */
2664 TRUSTED { $$ = TRUE; }
2665 | /*EMPTY*/ { $$ = FALSE; }
2668 /* This ought to be just func_name, but that causes reduce/reduce conflicts
2669 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
2670 * Work around by using simple names, instead.
2673 name { $$ = list_make1(makeString($1)); }
2674 | name attrs { $$ = lcons(makeString($1), $2); }
2678 VALIDATOR handler_name { $$ = $2; }
2679 | /*EMPTY*/ { $$ = NIL; }
2683 LANCOMPILER Sconst { $$ = $2; }
2684 | /*EMPTY*/ { $$ = NULL; }
2688 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
2690 DropPLangStmt *n = makeNode(DropPLangStmt);
2693 n->missing_ok = false;
2696 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
2698 DropPLangStmt *n = makeNode(DropPLangStmt);
2701 n->missing_ok = true;
2711 /*****************************************************************************
2714 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
2716 *****************************************************************************/
2718 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
2720 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
2721 n->tablespacename = $3;
2728 OptTableSpaceOwner: OWNER name { $$ = $2; }
2729 | /*EMPTY */ { $$ = NULL; }
2732 /*****************************************************************************
2735 * DROP TABLESPACE <tablespace>
2737 * No need for drop behaviour as we cannot implement dependencies for
2738 * objects in other databases; we can only support RESTRICT.
2740 ****************************************************************************/
2742 DropTableSpaceStmt: DROP TABLESPACE name
2744 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2745 n->tablespacename = $3;
2746 n->missing_ok = false;
2749 | DROP TABLESPACE IF_P EXISTS name
2751 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2752 n->tablespacename = $5;
2753 n->missing_ok = true;
2758 /*****************************************************************************
2761 * CREATE FOREIGN DATA WRAPPER name LIBRARY 'library_name' LANGUAGE C
2763 *****************************************************************************/
2765 CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name LIBRARY Sconst LANGUAGE ColId create_generic_options
2767 CreateFdwStmt *n = makeNode(CreateFdwStmt);
2773 if (pg_strcasecmp($9, "C") != 0)
2775 (errcode(ERRCODE_SYNTAX_ERROR),
2776 errmsg("language for foreign-data wrapper must be C"),
2777 scanner_errposition(@9)));
2781 /*****************************************************************************
2784 * DROP FOREIGN DATA WRAPPER name
2786 ****************************************************************************/
2788 DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
2790 DropFdwStmt *n = makeNode(DropFdwStmt);
2792 n->missing_ok = false;
2796 | DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior
2798 DropFdwStmt *n = makeNode(DropFdwStmt);
2800 n->missing_ok = true;
2806 /*****************************************************************************
2809 * ALTER FOREIGN DATA WRAPPER name
2811 ****************************************************************************/
2813 AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name LIBRARY Sconst alter_generic_options
2815 AlterFdwStmt *n = makeNode(AlterFdwStmt);
2821 | ALTER FOREIGN DATA_P WRAPPER name LIBRARY Sconst
2823 AlterFdwStmt *n = makeNode(AlterFdwStmt);
2828 | ALTER FOREIGN DATA_P WRAPPER name alter_generic_options
2830 AlterFdwStmt *n = makeNode(AlterFdwStmt);
2837 /* Options definition for CREATE FDW, SERVER and USER MAPPING */
2838 create_generic_options:
2839 OPTIONS '(' generic_option_list ')' { $$ = $3; }
2840 | /*EMPTY*/ { $$ = NIL; }
2843 generic_option_list: generic_option_elem
2845 $$ = list_make1(makeOptionDefElem(ALTER_OPT_ADD, $1));
2847 | generic_option_list ',' generic_option_elem
2849 $$ = lappend($1, makeOptionDefElem(ALTER_OPT_ADD, $3));
2853 /* Options definition for ALTER FDW, SERVER and USER MAPPING */
2854 alter_generic_options:
2855 OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
2858 alter_generic_option_list:
2859 alter_generic_option_elem
2861 $$ = list_make1($1);
2863 | generic_option_elem
2865 $$ = list_make1(makeOptionDefElem(ALTER_OPT_ADD, $1));
2867 | alter_generic_option_list ',' alter_generic_option_elem
2869 $$ = lappend($1, $3);
2871 | alter_generic_option_list ',' generic_option_elem
2873 $$ = lappend($1, makeOptionDefElem(ALTER_OPT_ADD, $3));
2877 alter_generic_option_elem:
2878 ADD_P generic_option_elem
2880 $$ = makeOptionDefElem(ALTER_OPT_ADD, $2);
2882 | SET generic_option_elem
2884 $$ = makeOptionDefElem(ALTER_OPT_SET, $2);
2886 | DROP generic_option_name
2888 $$ = makeOptionDefElem(ALTER_OPT_DROP,
2889 makeDefElem($2, NULL));
2893 generic_option_elem:
2894 generic_option_name generic_option_arg { $$ = makeDefElem($1, $2); }
2897 generic_option_name:
2898 attr_name { $$ = $1; }
2902 Sconst { $$ = (Node *)makeString($1); }
2905 /*****************************************************************************
2908 * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
2910 *****************************************************************************/
2912 CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
2913 FOREIGN DATA_P WRAPPER name create_generic_options
2915 CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
2926 TYPE_P Sconst { $$ = $2; }
2927 | /*EMPTY*/ { $$ = NULL; }
2931 foreign_server_version:
2932 VERSION_P Sconst { $$ = $2; }
2933 | VERSION_P NULL_P { $$ = NULL; }
2936 opt_foreign_server_version:
2937 foreign_server_version { $$ = $1; }
2938 | /*EMPTY*/ { $$ = NULL; }
2941 /*****************************************************************************
2946 ****************************************************************************/
2948 DropForeignServerStmt: DROP SERVER name opt_drop_behavior
2950 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
2952 n->missing_ok = false;
2956 | DROP SERVER IF_P EXISTS name opt_drop_behavior
2958 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
2960 n->missing_ok = true;
2966 /*****************************************************************************
2969 * ALTER SERVER name [VERSION] [OPTIONS]
2971 ****************************************************************************/
2973 AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
2975 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
2979 n->has_version = true;
2982 | ALTER SERVER name foreign_server_version
2984 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
2987 n->has_version = true;
2990 | ALTER SERVER name alter_generic_options
2992 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
2999 /*****************************************************************************
3002 * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
3004 *****************************************************************************/
3006 CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
3008 CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
3016 /* User mapping authorization identifier */
3018 CURRENT_USER { $$ = "current_user"; }
3019 | USER { $$ = "current_user"; }
3020 | RoleId { $$ = (strcmp($1, "public") == 0) ? NULL : $1; }
3023 /*****************************************************************************
3026 * DROP USER MAPPING FOR auth_ident SERVER name
3028 ****************************************************************************/
3030 DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
3032 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3035 n->missing_ok = false;
3038 | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
3040 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3043 n->missing_ok = true;
3048 /*****************************************************************************
3051 * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
3053 ****************************************************************************/
3055 AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
3057 AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
3065 /*****************************************************************************
3068 * CREATE TRIGGER ...
3071 *****************************************************************************/
3074 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
3075 qualified_name TriggerForSpec EXECUTE PROCEDURE
3076 func_name '(' TriggerFuncArgs ')'
3078 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3085 memcpy(n->actions, $5, 4);
3086 n->isconstraint = FALSE;
3087 n->deferrable = FALSE;
3088 n->initdeferred = FALSE;
3089 n->constrrel = NULL;
3092 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
3093 qualified_name OptConstrFromTable
3094 ConstraintAttributeSpec
3095 FOR EACH ROW EXECUTE PROCEDURE
3096 func_name '(' TriggerFuncArgs ')'
3098 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3105 memcpy(n->actions, $6, 4);
3106 n->isconstraint = TRUE;
3107 n->deferrable = ($10 & 1) != 0;
3108 n->initdeferred = ($10 & 2) != 0;
3116 BEFORE { $$ = TRUE; }
3117 | AFTER { $$ = FALSE; }
3123 char *e = palloc(4);
3124 e[0] = $1; e[1] = '\0';
3127 | TriggerOneEvent OR TriggerOneEvent
3129 char *e = palloc(4);
3130 e[0] = $1; e[1] = $3; e[2] = '\0';
3133 | TriggerOneEvent OR TriggerOneEvent OR TriggerOneEvent
3135 char *e = palloc(4);
3136 e[0] = $1; e[1] = $3; e[2] = $5; e[3] = '\0';
3142 INSERT { $$ = 'i'; }
3143 | DELETE_P { $$ = 'd'; }
3144 | UPDATE { $$ = 'u'; }
3145 | TRUNCATE { $$ = 't'; }
3149 FOR TriggerForOpt TriggerForType
3156 * If ROW/STATEMENT not specified, default to
3157 * STATEMENT, per SQL
3170 | STATEMENT { $$ = FALSE; }
3174 TriggerFuncArg { $$ = list_make1($1); }
3175 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
3176 | /*EMPTY*/ { $$ = NIL; }
3183 snprintf(buf, sizeof(buf), "%d", $1);
3184 $$ = makeString(pstrdup(buf));
3186 | FCONST { $$ = makeString($1); }
3187 | Sconst { $$ = makeString($1); }
3188 | BCONST { $$ = makeString($1); }
3189 | XCONST { $$ = makeString($1); }
3190 | ColId { $$ = makeString($1); }
3194 FROM qualified_name { $$ = $2; }
3195 | /*EMPTY*/ { $$ = NULL; }
3198 ConstraintAttributeSpec:
3199 ConstraintDeferrabilitySpec
3201 | ConstraintDeferrabilitySpec ConstraintTimeSpec
3203 if ($1 == 0 && $2 != 0)
3205 (errcode(ERRCODE_SYNTAX_ERROR),
3206 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3207 scanner_errposition(@1)));
3210 | ConstraintTimeSpec
3217 | ConstraintTimeSpec ConstraintDeferrabilitySpec
3219 if ($2 == 0 && $1 != 0)
3221 (errcode(ERRCODE_SYNTAX_ERROR),
3222 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3223 scanner_errposition(@1)));
3230 ConstraintDeferrabilitySpec:
3231 NOT DEFERRABLE { $$ = 0; }
3232 | DEFERRABLE { $$ = 1; }
3236 INITIALLY IMMEDIATE { $$ = 0; }
3237 | INITIALLY DEFERRED { $$ = 2; }
3242 DROP TRIGGER name ON qualified_name opt_drop_behavior
3244 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3248 n->removeType = OBJECT_TRIGGER;
3249 n->missing_ok = false;
3252 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
3254 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3258 n->removeType = OBJECT_TRIGGER;
3259 n->missing_ok = true;
3265 /*****************************************************************************
3268 * CREATE ASSERTION ...
3269 * DROP ASSERTION ...
3271 *****************************************************************************/
3274 CREATE ASSERTION name CHECK '(' a_expr ')'
3275 ConstraintAttributeSpec
3277 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3279 n->args = list_make1($6);
3280 n->isconstraint = TRUE;
3281 n->deferrable = ($8 & 1) != 0;
3282 n->initdeferred = ($8 & 2) != 0;
3285 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3286 errmsg("CREATE ASSERTION is not yet implemented")));
3293 DROP ASSERTION name opt_drop_behavior
3295 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3299 n->removeType = OBJECT_TRIGGER; /* XXX */
3301 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3302 errmsg("DROP ASSERTION is not yet implemented")));
3308 /*****************************************************************************
3311 * define (aggregate,operator,type)
3313 *****************************************************************************/
3316 CREATE AGGREGATE func_name aggr_args definition
3318 DefineStmt *n = makeNode(DefineStmt);
3319 n->kind = OBJECT_AGGREGATE;
3320 n->oldstyle = false;
3326 | CREATE AGGREGATE func_name old_aggr_definition
3328 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
3329 DefineStmt *n = makeNode(DefineStmt);
3330 n->kind = OBJECT_AGGREGATE;
3337 | CREATE OPERATOR any_operator definition
3339 DefineStmt *n = makeNode(DefineStmt);
3340 n->kind = OBJECT_OPERATOR;
3341 n->oldstyle = false;
3347 | CREATE TYPE_P any_name definition
3349 DefineStmt *n = makeNode(DefineStmt);
3350 n->kind = OBJECT_TYPE;
3351 n->oldstyle = false;
3357 | CREATE TYPE_P any_name
3359 /* Shell type (identified by lack of definition) */
3360 DefineStmt *n = makeNode(DefineStmt);
3361 n->kind = OBJECT_TYPE;
3362 n->oldstyle = false;
3365 n->definition = NIL;
3368 | CREATE TYPE_P any_name AS '(' TableFuncElementList ')'
3370 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
3371 RangeVar *r = makeNode(RangeVar);
3373 /* can't use qualified_name, sigh */
3374 switch (list_length($3))
3377 r->catalogname = NULL;
3378 r->schemaname = NULL;
3379 r->relname = strVal(linitial($3));
3382 r->catalogname = NULL;
3383 r->schemaname = strVal(linitial($3));
3384 r->relname = strVal(lsecond($3));
3387 r->catalogname = strVal(linitial($3));
3388 r->schemaname = strVal(lsecond($3));
3389 r->relname = strVal(lthird($3));
3393 (errcode(ERRCODE_SYNTAX_ERROR),
3394 errmsg("improper qualified name (too many dotted names): %s",
3395 NameListToString($3)),
3396 scanner_errposition(@3)));
3404 | CREATE TYPE_P any_name AS ENUM_P '(' enum_val_list ')'
3406 CreateEnumStmt *n = makeNode(CreateEnumStmt);
3411 | CREATE TEXT_P SEARCH PARSER any_name definition
3413 DefineStmt *n = makeNode(DefineStmt);
3414 n->kind = OBJECT_TSPARSER;
3420 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
3422 DefineStmt *n = makeNode(DefineStmt);
3423 n->kind = OBJECT_TSDICTIONARY;
3429 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
3431 DefineStmt *n = makeNode(DefineStmt);
3432 n->kind = OBJECT_TSTEMPLATE;
3438 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
3440 DefineStmt *n = makeNode(DefineStmt);
3441 n->kind = OBJECT_TSCONFIGURATION;
3449 definition: '(' def_list ')' { $$ = $2; }
3452 def_list: def_elem { $$ = list_make1($1); }
3453 | def_list ',' def_elem { $$ = lappend($1, $3); }
3456 def_elem: ColLabel '=' def_arg
3458 $$ = makeDefElem($1, (Node *)$3);
3462 $$ = makeDefElem($1, NULL);
3466 /* Note: any simple identifier will be returned as a type name! */
3467 def_arg: func_type { $$ = (Node *)$1; }
3468 | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
3469 | qual_all_Op { $$ = (Node *)$1; }
3470 | NumericOnly { $$ = (Node *)$1; }
3471 | Sconst { $$ = (Node *)makeString($1); }
3474 aggr_args: '(' type_list ')' { $$ = $2; }
3475 | '(' '*' ')' { $$ = NIL; }
3478 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
3481 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
3482 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
3486 * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
3487 * the item names needed in old aggregate definitions are likely to become
3490 old_aggr_elem: IDENT '=' def_arg
3492 $$ = makeDefElem($1, (Node *)$3);
3496 enum_val_list: Sconst
3497 { $$ = list_make1(makeString($1)); }
3498 | enum_val_list ',' Sconst
3499 { $$ = lappend($1, makeString($3)); }
3503 /*****************************************************************************
3506 * CREATE OPERATOR CLASS ...
3507 * CREATE OPERATOR FAMILY ...
3508 * ALTER OPERATOR FAMILY ...
3509 * DROP OPERATOR CLASS ...
3510 * DROP OPERATOR FAMILY ...
3512 *****************************************************************************/
3515 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
3516 USING access_method opt_opfamily AS opclass_item_list
3518 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
3519 n->opclassname = $4;
3523 n->opfamilyname = $11;
3530 opclass_item { $$ = list_make1($1); }
3531 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
3535 OPERATOR Iconst any_operator opt_recheck
3537 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3538 n->itemtype = OPCLASS_ITEM_OPERATOR;
3544 | OPERATOR Iconst any_operator oper_argtypes opt_recheck
3546 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3547 n->itemtype = OPCLASS_ITEM_OPERATOR;
3553 | FUNCTION Iconst func_name func_args
3555 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3556 n->itemtype = OPCLASS_ITEM_FUNCTION;
3558 n->args = extractArgTypes($4);
3562 | FUNCTION Iconst '(' type_list ')' func_name func_args
3564 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3565 n->itemtype = OPCLASS_ITEM_FUNCTION;
3567 n->args = extractArgTypes($7);
3574 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3575 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
3581 opt_default: DEFAULT { $$ = TRUE; }
3582 | /*EMPTY*/ { $$ = FALSE; }
3585 opt_opfamily: FAMILY any_name { $$ = $2; }
3586 | /*EMPTY*/ { $$ = NIL; }
3589 opt_recheck: RECHECK
3592 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3593 errmsg("RECHECK is no longer supported"),
3594 errhint("Update your data type."),
3595 scanner_errposition(@1)));
3598 | /*EMPTY*/ { $$ = FALSE; }
3603 CREATE OPERATOR FAMILY any_name USING access_method
3605 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
3606 n->opfamilyname = $4;
3613 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
3615 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3616 n->opfamilyname = $4;
3622 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
3624 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3625 n->opfamilyname = $4;
3634 opclass_drop { $$ = list_make1($1); }
3635 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
3639 OPERATOR Iconst '(' type_list ')'
3641 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3642 n->itemtype = OPCLASS_ITEM_OPERATOR;
3647 | FUNCTION Iconst '(' type_list ')'
3649 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3650 n->itemtype = OPCLASS_ITEM_FUNCTION;
3659 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
3661 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3662 n->opclassname = $4;
3665 n->missing_ok = false;
3668 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
3670 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3671 n->opclassname = $6;
3674 n->missing_ok = true;
3680 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
3682 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3683 n->opfamilyname = $4;
3686 n->missing_ok = false;
3689 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
3691 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3692 n->opfamilyname = $6;
3695 n->missing_ok = true;
3701 /*****************************************************************************
3705 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
3706 * REASSIGN OWNED BY username [, username ...] TO username
3708 *****************************************************************************/
3710 DROP OWNED BY name_list opt_drop_behavior
3712 DropOwnedStmt *n = makeNode(DropOwnedStmt);
3720 REASSIGN OWNED BY name_list TO name
3722 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
3729 /*****************************************************************************
3733 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
3734 * [ RESTRICT | CASCADE ]
3736 *****************************************************************************/
3738 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
3740 DropStmt *n = makeNode(DropStmt);
3742 n->missing_ok = TRUE;
3747 | DROP drop_type any_name_list opt_drop_behavior
3749 DropStmt *n = makeNode(DropStmt);
3751 n->missing_ok = FALSE;
3759 drop_type: TABLE { $$ = OBJECT_TABLE; }
3760 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
3761 | VIEW { $$ = OBJECT_VIEW; }
3762 | INDEX { $$ = OBJECT_INDEX; }
3763 | TYPE_P { $$ = OBJECT_TYPE; }
3764 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
3765 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
3766 | SCHEMA { $$ = OBJECT_SCHEMA; }
3767 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
3768 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
3769 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
3770 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
3774 any_name { $$ = list_make1($1); }
3775 | any_name_list ',' any_name { $$ = lappend($1, $3); }
3778 any_name: ColId { $$ = list_make1(makeString($1)); }
3779 | ColId attrs { $$ = lcons(makeString($1), $2); }
3782 attrs: '.' attr_name
3783 { $$ = list_make1(makeString($2)); }
3784 | attrs '.' attr_name
3785 { $$ = lappend($1, makeString($3)); }
3789 /*****************************************************************************
3792 * truncate table relname1, relname2, ...
3794 *****************************************************************************/
3797 TRUNCATE opt_table qualified_name_list opt_restart_seqs opt_drop_behavior
3799 TruncateStmt *n = makeNode(TruncateStmt);
3801 n->restart_seqs = $4;
3808 CONTINUE_P IDENTITY_P { $$ = false; }
3809 | RESTART IDENTITY_P { $$ = true; }
3810 | /* EMPTY */ { $$ = false; }
3813 /*****************************************************************************
3815 * The COMMENT ON statement can take different forms based upon the type of
3816 * the object associated with the comment. The form of the statement is:
3818 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
3819 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
3820 * CAST | COLUMN | SCHEMA | TABLESPACE | ROLE |
3821 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
3822 * TEXT SEARCH TEMPLATE |
3823 * TEXT SEARCH CONFIGURATION ] <objname> |
3824 * AGGREGATE <aggname> (arg1, ...) |
3825 * FUNCTION <funcname> (arg1, arg2, ...) |
3826 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
3827 * TRIGGER <triggername> ON <relname> |
3828 * CONSTRAINT <constraintname> ON <relname> |
3829 * RULE <rulename> ON <relname> ]
3832 *****************************************************************************/
3835 COMMENT ON comment_type any_name IS comment_text
3837 CommentStmt *n = makeNode(CommentStmt);
3844 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
3846 CommentStmt *n = makeNode(CommentStmt);
3847 n->objtype = OBJECT_AGGREGATE;
3853 | COMMENT ON FUNCTION func_name func_args IS comment_text
3855 CommentStmt *n = makeNode(CommentStmt);
3856 n->objtype = OBJECT_FUNCTION;
3858 n->objargs = extractArgTypes($5);
3862 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
3864 CommentStmt *n = makeNode(CommentStmt);
3865 n->objtype = OBJECT_OPERATOR;
3871 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
3873 CommentStmt *n = makeNode(CommentStmt);
3874 n->objtype = OBJECT_CONSTRAINT;
3875 n->objname = lappend($6, makeString($4));
3880 | COMMENT ON RULE name ON any_name IS comment_text
3882 CommentStmt *n = makeNode(CommentStmt);
3883 n->objtype = OBJECT_RULE;
3884 n->objname = lappend($6, makeString($4));
3889 | COMMENT ON RULE name IS comment_text
3891 /* Obsolete syntax supported for awhile for compatibility */
3892 CommentStmt *n = makeNode(CommentStmt);
3893 n->objtype = OBJECT_RULE;
3894 n->objname = list_make1(makeString($4));
3899 | COMMENT ON TRIGGER name ON any_name IS comment_text
3901 CommentStmt *n = makeNode(CommentStmt);
3902 n->objtype = OBJECT_TRIGGER;
3903 n->objname = lappend($6, makeString($4));
3908 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
3910 CommentStmt *n = makeNode(CommentStmt);
3911 n->objtype = OBJECT_OPCLASS;
3913 n->objargs = list_make1(makeString($7));
3917 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
3919 CommentStmt *n = makeNode(CommentStmt);
3920 n->objtype = OBJECT_OPFAMILY;
3922 n->objargs = list_make1(makeString($7));
3926 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
3928 CommentStmt *n = makeNode(CommentStmt);
3929 n->objtype = OBJECT_LARGEOBJECT;
3930 n->objname = list_make1($5);
3935 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
3937 CommentStmt *n = makeNode(CommentStmt);
3938 n->objtype = OBJECT_CAST;
3939 n->objname = list_make1($5);
3940 n->objargs = list_make1($7);
3944 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
3946 CommentStmt *n = makeNode(CommentStmt);
3947 n->objtype = OBJECT_LANGUAGE;
3953 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
3955 CommentStmt *n = makeNode(CommentStmt);
3956 n->objtype = OBJECT_TSPARSER;
3961 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
3963 CommentStmt *n = makeNode(CommentStmt);
3964 n->objtype = OBJECT_TSDICTIONARY;
3969 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
3971 CommentStmt *n = makeNode(CommentStmt);
3972 n->objtype = OBJECT_TSTEMPLATE;
3977 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
3979 CommentStmt *n = makeNode(CommentStmt);
3980 n->objtype = OBJECT_TSCONFIGURATION;
3988 COLUMN { $$ = OBJECT_COLUMN; }
3989 | DATABASE { $$ = OBJECT_DATABASE; }
3990 | SCHEMA { $$ = OBJECT_SCHEMA; }
3991 | INDEX { $$ = OBJECT_INDEX; }
3992 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
3993 | TABLE { $$ = OBJECT_TABLE; }
3994 | DOMAIN_P { $$ = OBJECT_TYPE; }
3995 | TYPE_P { $$ = OBJECT_TYPE; }
3996 | VIEW { $$ = OBJECT_VIEW; }
3997 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
3998 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
3999 | ROLE { $$ = OBJECT_ROLE; }
4004 | NULL_P { $$ = NULL; }
4007 /*****************************************************************************
4012 *****************************************************************************/
4014 FetchStmt: FETCH fetch_direction from_in name
4016 FetchStmt *n = (FetchStmt *) $2;
4023 FetchStmt *n = makeNode(FetchStmt);
4024 n->direction = FETCH_FORWARD;
4030 | MOVE fetch_direction from_in name
4032 FetchStmt *n = (FetchStmt *) $2;
4039 FetchStmt *n = makeNode(FetchStmt);
4040 n->direction = FETCH_FORWARD;
4051 FetchStmt *n = makeNode(FetchStmt);
4052 n->direction = FETCH_FORWARD;
4058 FetchStmt *n = makeNode(FetchStmt);
4059 n->direction = FETCH_FORWARD;
4065 FetchStmt *n = makeNode(FetchStmt);
4066 n->direction = FETCH_BACKWARD;
4072 FetchStmt *n = makeNode(FetchStmt);
4073 n->direction = FETCH_ABSOLUTE;
4079 FetchStmt *n = makeNode(FetchStmt);
4080 n->direction = FETCH_ABSOLUTE;
4084 | ABSOLUTE_P SignedIconst
4086 FetchStmt *n = makeNode(FetchStmt);
4087 n->direction = FETCH_ABSOLUTE;
4091 | RELATIVE_P SignedIconst
4093 FetchStmt *n = makeNode(FetchStmt);
4094 n->direction = FETCH_RELATIVE;
4100 FetchStmt *n = makeNode(FetchStmt);
4101 n->direction = FETCH_FORWARD;
4107 FetchStmt *n = makeNode(FetchStmt);
4108 n->direction = FETCH_FORWARD;
4109 n->howMany = FETCH_ALL;
4114 FetchStmt *n = makeNode(FetchStmt);
4115 n->direction = FETCH_FORWARD;
4119 | FORWARD SignedIconst
4121 FetchStmt *n = makeNode(FetchStmt);
4122 n->direction = FETCH_FORWARD;
4128 FetchStmt *n = makeNode(FetchStmt);
4129 n->direction = FETCH_FORWARD;
4130 n->howMany = FETCH_ALL;
4135 FetchStmt *n = makeNode(FetchStmt);
4136 n->direction = FETCH_BACKWARD;
4140 | BACKWARD SignedIconst
4142 FetchStmt *n = makeNode(FetchStmt);
4143 n->direction = FETCH_BACKWARD;
4149 FetchStmt *n = makeNode(FetchStmt);
4150 n->direction = FETCH_BACKWARD;
4151 n->howMany = FETCH_ALL;
4161 /*****************************************************************************
4163 * GRANT and REVOKE statements
4165 *****************************************************************************/
4167 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
4168 opt_grant_grant_option
4170 GrantStmt *n = makeNode(GrantStmt);
4173 n->objtype = ($4)->objtype;
4174 n->objects = ($4)->objs;
4176 n->grant_option = $7;
4182 REVOKE privileges ON privilege_target
4183 FROM grantee_list opt_drop_behavior
4185 GrantStmt *n = makeNode(GrantStmt);
4186 n->is_grant = false;
4187 n->grant_option = false;
4189 n->objtype = ($4)->objtype;
4190 n->objects = ($4)->objs;
4195 | REVOKE GRANT OPTION FOR privileges ON privilege_target
4196 FROM grantee_list opt_drop_behavior
4198 GrantStmt *n = makeNode(GrantStmt);
4199 n->is_grant = false;
4200 n->grant_option = true;
4202 n->objtype = ($7)->objtype;
4203 n->objects = ($7)->objs;
4212 * A privilege list is represented as a list of strings; the validity of
4213 * the privilege names gets checked at execution. This is a bit annoying
4214 * but we have little choice because of the syntactic conflict with lists
4215 * of role names in GRANT/REVOKE. What's more, we have to call out in
4216 * the "privilege" production any reserved keywords that need to be usable
4217 * as privilege names.
4220 /* either ALL [PRIVILEGES] or a list of individual privileges */
4221 privileges: privilege_list
4229 privilege_list: privilege
4230 { $$ = list_make1(makeString($1)); }
4231 | privilege_list ',' privilege
4232 { $$ = lappend($1, makeString($3)); }
4235 privilege: SELECT { $$ = pstrdup($1); }
4236 | REFERENCES { $$ = pstrdup($1); }
4237 | CREATE { $$ = pstrdup($1); }
4238 | ColId { $$ = $1; }
4242 /* Don't bother trying to fold the first two rules into one using
4243 * opt_table. You're going to get conflicts.
4248 PrivTarget *n = makeNode(PrivTarget);
4249 n->objtype = ACL_OBJECT_RELATION;
4253 | TABLE qualified_name_list
4255 PrivTarget *n = makeNode(PrivTarget);
4256 n->objtype = ACL_OBJECT_RELATION;
4260 | SEQUENCE qualified_name_list
4262 PrivTarget *n = makeNode(PrivTarget);
4263 n->objtype = ACL_OBJECT_SEQUENCE;
4267 | FOREIGN DATA_P WRAPPER name_list
4269 PrivTarget *n = makeNode(PrivTarget);
4270 n->objtype = ACL_OBJECT_FDW;
4274 | FOREIGN SERVER name_list
4276 PrivTarget *n = makeNode(PrivTarget);
4277 n->objtype = ACL_OBJECT_FOREIGN_SERVER;
4281 | FUNCTION function_with_argtypes_list
4283 PrivTarget *n = makeNode(PrivTarget);
4284 n->objtype = ACL_OBJECT_FUNCTION;
4288 | DATABASE name_list
4290 PrivTarget *n = makeNode(PrivTarget);
4291 n->objtype = ACL_OBJECT_DATABASE;
4295 | LANGUAGE name_list
4297 PrivTarget *n = makeNode(PrivTarget);
4298 n->objtype = ACL_OBJECT_LANGUAGE;
4304 PrivTarget *n = makeNode(PrivTarget);
4305 n->objtype = ACL_OBJECT_NAMESPACE;
4309 | TABLESPACE name_list
4311 PrivTarget *n = makeNode(PrivTarget);
4312 n->objtype = ACL_OBJECT_TABLESPACE;
4320 grantee { $$ = list_make1($1); }
4321 | grantee_list ',' grantee { $$ = lappend($1, $3); }
4326 PrivGrantee *n = makeNode(PrivGrantee);
4327 /* This hack lets us avoid reserving PUBLIC as a keyword*/
4328 if (strcmp($1, "public") == 0)
4336 PrivGrantee *n = makeNode(PrivGrantee);
4337 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
4338 if (strcmp($2, "public") == 0)
4347 opt_grant_grant_option:
4348 WITH GRANT OPTION { $$ = TRUE; }
4349 | /*EMPTY*/ { $$ = FALSE; }
4352 function_with_argtypes_list:
4353 function_with_argtypes { $$ = list_make1($1); }
4354 | function_with_argtypes_list ',' function_with_argtypes
4355 { $$ = lappend($1, $3); }
4358 function_with_argtypes:
4361 FuncWithArgs *n = makeNode(FuncWithArgs);
4363 n->funcargs = extractArgTypes($2);
4368 /*****************************************************************************
4370 * GRANT and REVOKE ROLE statements
4372 *****************************************************************************/
4375 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4377 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4379 n->granted_roles = $2;
4380 n->grantee_roles = $4;
4388 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4390 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4391 n->is_grant = false;
4392 n->admin_opt = false;
4393 n->granted_roles = $2;
4394 n->grantee_roles = $4;
4398 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4400 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4401 n->is_grant = false;
4402 n->admin_opt = true;
4403 n->granted_roles = $5;
4404 n->grantee_roles = $7;
4410 opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
4411 | /*EMPTY*/ { $$ = FALSE; }
4414 opt_granted_by: GRANTED BY RoleId { $$ = $3; }
4415 | /*EMPTY*/ { $$ = NULL; }
4419 /*****************************************************************************
4421 * QUERY: CREATE INDEX
4423 * Note: we can't factor CONCURRENTLY into a separate production without
4424 * making it a reserved word.
4426 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
4427 * willing to make TABLESPACE a fully reserved word.
4428 *****************************************************************************/
4430 IndexStmt: CREATE index_opt_unique INDEX index_name
4431 ON qualified_name access_method_clause '(' index_params ')'
4432 opt_definition OptTableSpace where_clause
4434 IndexStmt *n = makeNode(IndexStmt);
4436 n->concurrent = false;
4439 n->accessMethod = $7;
4440 n->indexParams = $9;
4442 n->tableSpace = $12;
4443 n->whereClause = $13;
4446 | CREATE index_opt_unique INDEX CONCURRENTLY index_name
4447 ON qualified_name access_method_clause '(' index_params ')'
4448 opt_definition OptTableSpace where_clause
4450 IndexStmt *n = makeNode(IndexStmt);
4452 n->concurrent = true;
4455 n->accessMethod = $8;
4456 n->indexParams = $10;
4458 n->tableSpace = $13;
4459 n->whereClause = $14;
4465 UNIQUE { $$ = TRUE; }
4466 | /*EMPTY*/ { $$ = FALSE; }
4469 access_method_clause:
4470 USING access_method { $$ = $2; }
4471 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
4474 index_params: index_elem { $$ = list_make1($1); }
4475 | index_params ',' index_elem { $$ = lappend($1, $3); }
4479 * Index attributes can be either simple column references, or arbitrary
4480 * expressions in parens. For backwards-compatibility reasons, we allow
4481 * an expression that's just a function call to be written without parens.
4483 index_elem: ColId opt_class opt_asc_desc opt_nulls_order
4485 $$ = makeNode(IndexElem);
4490 $$->nulls_ordering = $4;
4492 | func_expr opt_class opt_asc_desc opt_nulls_order
4494 $$ = makeNode(IndexElem);
4499 $$->nulls_ordering = $4;
4501 | '(' a_expr ')' opt_class opt_asc_desc opt_nulls_order
4503 $$ = makeNode(IndexElem);
4508 $$->nulls_ordering = $6;
4512 opt_class: any_name { $$ = $1; }
4513 | USING any_name { $$ = $2; }
4514 | /*EMPTY*/ { $$ = NIL; }
4517 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
4518 | DESC { $$ = SORTBY_DESC; }
4519 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
4522 opt_nulls_order: NULLS_FIRST { $$ = SORTBY_NULLS_FIRST; }
4523 | NULLS_LAST { $$ = SORTBY_NULLS_LAST; }
4524 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
4528 /*****************************************************************************
4531 * create [or replace] function <fname>
4532 * [(<type-1> { , <type-n>})]
4534 * as <filename or code in language as appropriate>
4535 * language <lang> [with parameters]
4537 *****************************************************************************/
4540 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4541 RETURNS func_return createfunc_opt_list opt_definition
4543 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4552 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4553 RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
4555 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4558 n->parameters = mergeTableFuncParameters($5, $9);
4559 n->returnType = TableFuncTypeName($9);
4560 n->returnType->location = @7;
4562 n->withClause = $12;
4565 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4566 createfunc_opt_list opt_definition
4568 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4572 n->returnType = NULL;
4580 OR REPLACE { $$ = TRUE; }
4581 | /*EMPTY*/ { $$ = FALSE; }
4584 func_args: '(' func_args_list ')' { $$ = $2; }
4585 | '(' ')' { $$ = NIL; }
4589 func_arg { $$ = list_make1($1); }
4590 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
4594 * func_args_with_defaults is separate because we only want to accept
4595 * defaults in CREATE FUNCTION, not in ALTER etc.
4597 func_args_with_defaults:
4598 '(' func_args_with_defaults_list ')' { $$ = $2; }
4599 | '(' ')' { $$ = NIL; }
4602 func_args_with_defaults_list:
4603 func_arg_with_default { $$ = list_make1($1); }
4604 | func_args_with_defaults_list ',' func_arg_with_default
4605 { $$ = lappend($1, $3); }
4609 * The style with arg_class first is SQL99 standard, but Oracle puts
4610 * param_name first; accept both since it's likely people will try both
4611 * anyway. Don't bother trying to save productions by letting arg_class
4612 * have an empty alternative ... you'll get shift/reduce conflicts.
4614 * We can catch over-specified arguments here if we want to,
4615 * but for now better to silently swallow typmod, etc.
4616 * - thomas 2000-03-22
4619 arg_class param_name func_type
4621 FunctionParameter *n = makeNode(FunctionParameter);
4628 | param_name arg_class func_type
4630 FunctionParameter *n = makeNode(FunctionParameter);
4637 | param_name func_type
4639 FunctionParameter *n = makeNode(FunctionParameter);
4642 n->mode = FUNC_PARAM_IN;
4646 | arg_class func_type
4648 FunctionParameter *n = makeNode(FunctionParameter);
4657 FunctionParameter *n = makeNode(FunctionParameter);
4660 n->mode = FUNC_PARAM_IN;
4666 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
4667 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
4668 | OUT_P { $$ = FUNC_PARAM_OUT; }
4669 | INOUT { $$ = FUNC_PARAM_INOUT; }
4670 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
4671 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
4675 * Ideally param_name should be ColId, but that causes too many conflicts.
4677 param_name: type_function_name
4683 /* We can catch over-specified results here if we want to,
4684 * but for now better to silently swallow typmod, etc.
4685 * - thomas 2000-03-22
4692 * We would like to make the %TYPE productions here be ColId attrs etc,
4693 * but that causes reduce/reduce conflicts. type_function_name
4694 * is next best choice.
4696 func_type: Typename { $$ = $1; }
4697 | type_function_name attrs '%' TYPE_P
4699 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
4700 $$->pct_type = true;
4703 | SETOF type_function_name attrs '%' TYPE_P
4705 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
4706 $$->pct_type = true;
4712 func_arg_with_default:
4717 | func_arg DEFAULT a_expr
4722 | func_arg '=' a_expr
4730 createfunc_opt_list:
4731 /* Must be at least one to prevent conflict */
4732 createfunc_opt_item { $$ = list_make1($1); }
4733 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
4737 * Options common to both CREATE FUNCTION and ALTER FUNCTION
4739 common_func_opt_item:
4740 CALLED ON NULL_P INPUT_P
4742 $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
4744 | RETURNS NULL_P ON NULL_P INPUT_P
4746 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
4750 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
4754 $$ = makeDefElem("volatility", (Node *)makeString("immutable"));
4758 $$ = makeDefElem("volatility", (Node *)makeString("stable"));
4762 $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
4764 | EXTERNAL SECURITY DEFINER
4766 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
4768 | EXTERNAL SECURITY INVOKER
4770 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
4774 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
4778 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
4782 $$ = makeDefElem("cost", (Node *)$2);
4786 $$ = makeDefElem("rows", (Node *)$2);
4790 /* we abuse the normal content of a DefElem here */
4791 $$ = makeDefElem("set", (Node *)$1);
4795 createfunc_opt_item:
4798 $$ = makeDefElem("as", (Node *)$2);
4800 | LANGUAGE ColId_or_Sconst
4802 $$ = makeDefElem("language", (Node *)makeString($2));
4806 $$ = makeDefElem("window", (Node *)makeInteger(TRUE));
4808 | common_func_opt_item
4814 func_as: Sconst { $$ = list_make1(makeString($1)); }
4817 $$ = list_make2(makeString($1), makeString($3));
4822 WITH definition { $$ = $2; }
4823 | /*EMPTY*/ { $$ = NIL; }
4826 table_func_column: param_name func_type
4828 FunctionParameter *n = makeNode(FunctionParameter);
4831 n->mode = FUNC_PARAM_TABLE;
4837 table_func_column_list:
4840 $$ = list_make1($1);
4842 | table_func_column_list ',' table_func_column
4844 $$ = lappend($1, $3);
4848 /*****************************************************************************
4851 * RENAME and OWNER subcommands are already provided by the generic
4852 * ALTER infrastructure, here we just specify alterations that can
4853 * only be applied to functions.
4855 *****************************************************************************/
4857 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
4859 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
4867 /* At least one option must be specified */
4868 common_func_opt_item { $$ = list_make1($1); }
4869 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
4872 /* Ignored, merely for SQL compliance */
4879 /*****************************************************************************
4883 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
4884 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
4885 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
4887 *****************************************************************************/
4890 DROP FUNCTION func_name func_args opt_drop_behavior
4892 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4893 n->kind = OBJECT_FUNCTION;
4895 n->args = extractArgTypes($4);
4897 n->missing_ok = false;
4900 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
4902 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4903 n->kind = OBJECT_FUNCTION;
4905 n->args = extractArgTypes($6);
4907 n->missing_ok = true;
4913 DROP AGGREGATE func_name aggr_args opt_drop_behavior
4915 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4916 n->kind = OBJECT_AGGREGATE;
4920 n->missing_ok = false;
4923 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
4925 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4926 n->kind = OBJECT_AGGREGATE;
4930 n->missing_ok = true;
4936 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
4938 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4939 n->kind = OBJECT_OPERATOR;
4943 n->missing_ok = false;
4946 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
4948 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
4949 n->kind = OBJECT_OPERATOR;
4953 n->missing_ok = true;
4962 (errcode(ERRCODE_SYNTAX_ERROR),
4963 errmsg("missing argument"),
4964 errhint("Use NONE to denote the missing argument of a unary operator."),
4965 scanner_errposition(@3)));
4967 | '(' Typename ',' Typename ')'
4968 { $$ = list_make2($2, $4); }
4969 | '(' NONE ',' Typename ')' /* left unary */
4970 { $$ = list_make2(NULL, $4); }
4971 | '(' Typename ',' NONE ')' /* right unary */
4972 { $$ = list_make2($2, NULL); }
4977 { $$ = list_make1(makeString($1)); }
4978 | ColId '.' any_operator
4979 { $$ = lcons(makeString($1), $3); }
4983 /*****************************************************************************
4985 * CREATE CAST / DROP CAST
4987 *****************************************************************************/
4989 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
4990 WITH FUNCTION function_with_argtypes cast_context
4992 CreateCastStmt *n = makeNode(CreateCastStmt);
4996 n->context = (CoercionContext) $11;
5000 | CREATE CAST '(' Typename AS Typename ')'
5001 WITHOUT FUNCTION cast_context
5003 CreateCastStmt *n = makeNode(CreateCastStmt);
5007 n->context = (CoercionContext) $10;
5011 | CREATE CAST '(' Typename AS Typename ')'
5012 WITH INOUT cast_context
5014 CreateCastStmt *n = makeNode(CreateCastStmt);
5018 n->context = (CoercionContext) $10;
5024 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
5025 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
5026 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
5030 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
5032 DropCastStmt *n = makeNode(DropCastStmt);
5041 opt_if_exists: IF_P EXISTS { $$ = TRUE; }
5042 | /*EMPTY*/ { $$ = FALSE; }
5046 /*****************************************************************************
5050 * REINDEX type <name> [FORCE]
5052 * FORCE no longer does anything, but we accept it for backwards compatibility
5053 *****************************************************************************/
5056 REINDEX reindex_type qualified_name opt_force
5058 ReindexStmt *n = makeNode(ReindexStmt);
5064 | REINDEX SYSTEM_P name opt_force
5066 ReindexStmt *n = makeNode(ReindexStmt);
5067 n->kind = OBJECT_DATABASE;
5070 n->do_system = true;
5074 | REINDEX DATABASE name opt_force
5076 ReindexStmt *n = makeNode(ReindexStmt);
5077 n->kind = OBJECT_DATABASE;
5080 n->do_system = true;
5087 INDEX { $$ = OBJECT_INDEX; }
5088 | TABLE { $$ = OBJECT_TABLE; }
5091 opt_force: FORCE { $$ = TRUE; }
5092 | /* EMPTY */ { $$ = FALSE; }
5096 /*****************************************************************************
5098 * ALTER THING name RENAME TO newname
5100 *****************************************************************************/
5102 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
5104 RenameStmt *n = makeNode(RenameStmt);
5105 n->renameType = OBJECT_AGGREGATE;
5111 | ALTER CONVERSION_P any_name RENAME TO name
5113 RenameStmt *n = makeNode(RenameStmt);
5114 n->renameType = OBJECT_CONVERSION;
5119 | ALTER DATABASE database_name RENAME TO database_name
5121 RenameStmt *n = makeNode(RenameStmt);
5122 n->renameType = OBJECT_DATABASE;
5127 | ALTER FUNCTION function_with_argtypes RENAME TO name
5129 RenameStmt *n = makeNode(RenameStmt);
5130 n->renameType = OBJECT_FUNCTION;
5131 n->object = $3->funcname;
5132 n->objarg = $3->funcargs;
5136 | ALTER GROUP_P RoleId RENAME TO RoleId
5138 RenameStmt *n = makeNode(RenameStmt);
5139 n->renameType = OBJECT_ROLE;
5144 | ALTER opt_procedural LANGUAGE name RENAME TO name
5146 RenameStmt *n = makeNode(RenameStmt);
5147 n->renameType = OBJECT_LANGUAGE;
5152 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
5154 RenameStmt *n = makeNode(RenameStmt);
5155 n->renameType = OBJECT_OPCLASS;
5161 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
5163 RenameStmt *n = makeNode(RenameStmt);
5164 n->renameType = OBJECT_OPFAMILY;
5170 | ALTER SCHEMA name RENAME TO name
5172 RenameStmt *n = makeNode(RenameStmt);
5173 n->renameType = OBJECT_SCHEMA;
5178 | ALTER TABLE relation_expr RENAME TO name
5180 RenameStmt *n = makeNode(RenameStmt);
5181 n->renameType = OBJECT_TABLE;
5187 | ALTER SEQUENCE relation_expr RENAME TO name
5189 RenameStmt *n = makeNode(RenameStmt);
5190 n->renameType = OBJECT_SEQUENCE;
5196 | ALTER VIEW relation_expr RENAME TO name
5198 RenameStmt *n = makeNode(RenameStmt);
5199 n->renameType = OBJECT_VIEW;
5205 | ALTER INDEX relation_expr RENAME TO name
5207 RenameStmt *n = makeNode(RenameStmt);
5208 n->renameType = OBJECT_INDEX;
5214 | ALTER TABLE relation_expr RENAME opt_column name TO name
5216 RenameStmt *n = makeNode(RenameStmt);
5217 n->renameType = OBJECT_COLUMN;
5223 | ALTER TRIGGER name ON relation_expr RENAME TO name
5225 RenameStmt *n = makeNode(RenameStmt);
5226 n->renameType = OBJECT_TRIGGER;
5232 | ALTER ROLE RoleId RENAME TO RoleId
5234 RenameStmt *n = makeNode(RenameStmt);
5235 n->renameType = OBJECT_ROLE;
5240 | ALTER USER RoleId RENAME TO RoleId
5242 RenameStmt *n = makeNode(RenameStmt);
5243 n->renameType = OBJECT_ROLE;
5248 | ALTER TABLESPACE name RENAME TO name
5250 RenameStmt *n = makeNode(RenameStmt);
5251 n->renameType = OBJECT_TABLESPACE;
5256 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
5258 RenameStmt *n = makeNode(RenameStmt);
5259 n->renameType = OBJECT_TSPARSER;
5264 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
5266 RenameStmt *n = makeNode(RenameStmt);
5267 n->renameType = OBJECT_TSDICTIONARY;
5272 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
5274 RenameStmt *n = makeNode(RenameStmt);
5275 n->renameType = OBJECT_TSTEMPLATE;
5280 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
5282 RenameStmt *n = makeNode(RenameStmt);
5283 n->renameType = OBJECT_TSCONFIGURATION;
5288 | ALTER TYPE_P any_name RENAME TO name
5290 RenameStmt *n = makeNode(RenameStmt);
5291 n->renameType = OBJECT_TYPE;
5298 opt_column: COLUMN { $$ = COLUMN; }
5299 | /*EMPTY*/ { $$ = 0; }
5302 opt_set_data: SET DATA_P { $$ = 1; }
5303 | /*EMPTY*/ { $$ = 0; }
5306 /*****************************************************************************
5308 * ALTER THING name SET SCHEMA name
5310 *****************************************************************************/
5312 AlterObjectSchemaStmt:
5313 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
5315 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5316 n->objectType = OBJECT_AGGREGATE;
5322 | ALTER DOMAIN_P any_name SET SCHEMA name
5324 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5325 n->objectType = OBJECT_DOMAIN;
5330 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
5332 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5333 n->objectType = OBJECT_FUNCTION;
5334 n->object = $3->funcname;
5335 n->objarg = $3->funcargs;
5339 | ALTER TABLE relation_expr SET SCHEMA name
5341 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5342 n->objectType = OBJECT_TABLE;
5347 | ALTER SEQUENCE relation_expr SET SCHEMA name
5349 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5350 n->objectType = OBJECT_SEQUENCE;
5355 | ALTER VIEW relation_expr SET SCHEMA name
5357 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5358 n->objectType = OBJECT_VIEW;
5363 | ALTER TYPE_P any_name SET SCHEMA name
5365 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5366 n->objectType = OBJECT_TYPE;
5373 /*****************************************************************************
5375 * ALTER THING name OWNER TO newname
5377 *****************************************************************************/
5379 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
5381 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5382 n->objectType = OBJECT_AGGREGATE;
5388 | ALTER CONVERSION_P any_name OWNER TO RoleId
5390 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5391 n->objectType = OBJECT_CONVERSION;
5396 | ALTER DATABASE database_name OWNER TO RoleId
5398 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5399 n->objectType = OBJECT_DATABASE;
5400 n->object = list_make1(makeString($3));
5404 | ALTER DOMAIN_P any_name OWNER TO RoleId
5406 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5407 n->objectType = OBJECT_DOMAIN;
5412 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
5414 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5415 n->objectType = OBJECT_FUNCTION;
5416 n->object = $3->funcname;
5417 n->objarg = $3->funcargs;
5421 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
5423 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5424 n->objectType = OBJECT_LANGUAGE;
5425 n->object = list_make1(makeString($4));
5429 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
5431 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5432 n->objectType = OBJECT_OPERATOR;
5438 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
5440 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5441 n->objectType = OBJECT_OPCLASS;
5447 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
5449 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5450 n->objectType = OBJECT_OPFAMILY;
5456 | ALTER SCHEMA name OWNER TO RoleId
5458 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5459 n->objectType = OBJECT_SCHEMA;
5460 n->object = list_make1(makeString($3));
5464 | ALTER TYPE_P any_name OWNER TO RoleId
5466 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5467 n->objectType = OBJECT_TYPE;
5472 | ALTER TABLESPACE name OWNER TO RoleId
5474 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5475 n->objectType = OBJECT_TABLESPACE;
5476 n->object = list_make1(makeString($3));
5480 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
5482 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5483 n->objectType = OBJECT_TSDICTIONARY;
5488 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
5490 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5491 n->objectType = OBJECT_TSCONFIGURATION;
5496 | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleId
5498 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5499 n->objectType = OBJECT_FDW;
5500 n->object = list_make1(makeString($5));
5504 | ALTER SERVER name OWNER TO RoleId
5506 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5507 n->objectType = OBJECT_FOREIGN_SERVER;
5508 n->object = list_make1(makeString($3));
5515 /*****************************************************************************
5517 * QUERY: Define Rewrite Rule
5519 *****************************************************************************/
5521 RuleStmt: CREATE opt_or_replace RULE name AS
5522 { QueryIsRule=TRUE; }
5523 ON event TO qualified_name where_clause
5524 DO opt_instead RuleActionList
5526 RuleStmt *n = makeNode(RuleStmt);
5530 n->whereClause = $11;
5540 NOTHING { $$ = NIL; }
5541 | RuleActionStmt { $$ = list_make1($1); }
5542 | '(' RuleActionMulti ')' { $$ = $2; }
5545 /* the thrashing around here is to discard "empty" statements... */
5547 RuleActionMulti ';' RuleActionStmtOrEmpty
5549 $$ = lappend($1, $3);
5553 | RuleActionStmtOrEmpty
5555 $$ = list_make1($1);
5569 RuleActionStmtOrEmpty:
5570 RuleActionStmt { $$ = $1; }
5571 | /*EMPTY*/ { $$ = NULL; }
5574 event: SELECT { $$ = CMD_SELECT; }
5575 | UPDATE { $$ = CMD_UPDATE; }
5576 | DELETE_P { $$ = CMD_DELETE; }
5577 | INSERT { $$ = CMD_INSERT; }
5581 INSTEAD { $$ = TRUE; }
5582 | ALSO { $$ = FALSE; }
5583 | /*EMPTY*/ { $$ = FALSE; }
5588 DROP RULE name ON qualified_name opt_drop_behavior
5590 DropPropertyStmt *n = makeNode(DropPropertyStmt);
5594 n->removeType = OBJECT_RULE;
5595 n->missing_ok = false;
5598 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
5600 DropPropertyStmt *n = makeNode(DropPropertyStmt);
5604 n->removeType = OBJECT_RULE;
5605 n->missing_ok = true;
5611 /*****************************************************************************
5614 * NOTIFY <identifier> can appear both in rule bodies and
5615 * as a query-level command
5617 *****************************************************************************/
5619 NotifyStmt: NOTIFY ColId
5621 NotifyStmt *n = makeNode(NotifyStmt);
5622 n->conditionname = $2;
5627 ListenStmt: LISTEN ColId
5629 ListenStmt *n = makeNode(ListenStmt);
5630 n->conditionname = $2;
5638 UnlistenStmt *n = makeNode(UnlistenStmt);
5639 n->conditionname = $2;
5644 UnlistenStmt *n = makeNode(UnlistenStmt);
5645 n->conditionname = NULL;
5651 /*****************************************************************************
5655 * BEGIN / COMMIT / ROLLBACK
5656 * (also older versions END / ABORT)
5658 *****************************************************************************/
5661 ABORT_P opt_transaction
5663 TransactionStmt *n = makeNode(TransactionStmt);
5664 n->kind = TRANS_STMT_ROLLBACK;
5668 | BEGIN_P opt_transaction transaction_mode_list_or_empty
5670 TransactionStmt *n = makeNode(TransactionStmt);
5671 n->kind = TRANS_STMT_BEGIN;
5675 | START TRANSACTION transaction_mode_list_or_empty
5677 TransactionStmt *n = makeNode(TransactionStmt);
5678 n->kind = TRANS_STMT_START;
5682 | COMMIT opt_transaction
5684 TransactionStmt *n = makeNode(TransactionStmt);
5685 n->kind = TRANS_STMT_COMMIT;
5689 | END_P opt_transaction
5691 TransactionStmt *n = makeNode(TransactionStmt);
5692 n->kind = TRANS_STMT_COMMIT;
5696 | ROLLBACK opt_transaction
5698 TransactionStmt *n = makeNode(TransactionStmt);
5699 n->kind = TRANS_STMT_ROLLBACK;
5705 TransactionStmt *n = makeNode(TransactionStmt);
5706 n->kind = TRANS_STMT_SAVEPOINT;
5707 n->options = list_make1(makeDefElem("savepoint_name",
5708 (Node *)makeString($2)));
5711 | RELEASE SAVEPOINT ColId
5713 TransactionStmt *n = makeNode(TransactionStmt);
5714 n->kind = TRANS_STMT_RELEASE;
5715 n->options = list_make1(makeDefElem("savepoint_name",
5716 (Node *)makeString($3)));
5721 TransactionStmt *n = makeNode(TransactionStmt);
5722 n->kind = TRANS_STMT_RELEASE;
5723 n->options = list_make1(makeDefElem("savepoint_name",
5724 (Node *)makeString($2)));
5727 | ROLLBACK opt_transaction TO SAVEPOINT ColId
5729 TransactionStmt *n = makeNode(TransactionStmt);
5730 n->kind = TRANS_STMT_ROLLBACK_TO;
5731 n->options = list_make1(makeDefElem("savepoint_name",
5732 (Node *)makeString($5)));
5735 | ROLLBACK opt_transaction TO ColId
5737 TransactionStmt *n = makeNode(TransactionStmt);
5738 n->kind = TRANS_STMT_ROLLBACK_TO;
5739 n->options = list_make1(makeDefElem("savepoint_name",
5740 (Node *)makeString($4)));
5743 | PREPARE TRANSACTION Sconst
5745 TransactionStmt *n = makeNode(TransactionStmt);
5746 n->kind = TRANS_STMT_PREPARE;
5750 | COMMIT PREPARED Sconst
5752 TransactionStmt *n = makeNode(TransactionStmt);
5753 n->kind = TRANS_STMT_COMMIT_PREPARED;
5757 | ROLLBACK PREPARED Sconst
5759 TransactionStmt *n = makeNode(TransactionStmt);
5760 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
5766 opt_transaction: WORK {}
5771 transaction_mode_item:
5772 ISOLATION LEVEL iso_level
5773 { $$ = makeDefElem("transaction_isolation",
5774 makeStringConst($3, @3)); }
5776 { $$ = makeDefElem("transaction_read_only",
5777 makeIntConst(TRUE, @1)); }
5779 { $$ = makeDefElem("transaction_read_only",
5780 makeIntConst(FALSE, @1)); }
5783 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
5784 transaction_mode_list:
5785 transaction_mode_item
5786 { $$ = list_make1($1); }
5787 | transaction_mode_list ',' transaction_mode_item
5788 { $$ = lappend($1, $3); }
5789 | transaction_mode_list transaction_mode_item
5790 { $$ = lappend($1, $2); }
5793 transaction_mode_list_or_empty:
5794 transaction_mode_list
5800 /*****************************************************************************
5803 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
5804 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
5806 *****************************************************************************/
5808 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
5809 AS SelectStmt opt_check_option
5811 ViewStmt *n = makeNode(ViewStmt);
5813 n->view->istemp = $2;
5819 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
5820 AS SelectStmt opt_check_option
5822 ViewStmt *n = makeNode(ViewStmt);
5824 n->view->istemp = $4;
5836 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5837 errmsg("WITH CHECK OPTION is not implemented")));
5839 | WITH CASCADED CHECK OPTION
5842 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5843 errmsg("WITH CHECK OPTION is not implemented")));
5845 | WITH LOCAL CHECK OPTION
5848 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5849 errmsg("WITH CHECK OPTION is not implemented")));
5851 | /* EMPTY */ { $$ = NIL; }
5854 /*****************************************************************************
5859 *****************************************************************************/
5861 LoadStmt: LOAD file_name
5863 LoadStmt *n = makeNode(LoadStmt);
5870 /*****************************************************************************
5874 *****************************************************************************/
5877 CREATE DATABASE database_name opt_with createdb_opt_list
5879 CreatedbStmt *n = makeNode(CreatedbStmt);
5887 createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
5888 | /* EMPTY */ { $$ = NIL; }
5892 TABLESPACE opt_equal name
5894 $$ = makeDefElem("tablespace", (Node *)makeString($3));
5896 | TABLESPACE opt_equal DEFAULT
5898 $$ = makeDefElem("tablespace", NULL);
5900 | LOCATION opt_equal Sconst
5902 $$ = makeDefElem("location", (Node *)makeString($3));
5904 | LOCATION opt_equal DEFAULT
5906 $$ = makeDefElem("location", NULL);
5908 | TEMPLATE opt_equal name
5910 $$ = makeDefElem("template", (Node *)makeString($3));
5912 | TEMPLATE opt_equal DEFAULT
5914 $$ = makeDefElem("template", NULL);
5916 | ENCODING opt_equal Sconst
5918 $$ = makeDefElem("encoding", (Node *)makeString($3));
5920 | ENCODING opt_equal Iconst
5922 $$ = makeDefElem("encoding", (Node *)makeInteger($3));
5924 | ENCODING opt_equal DEFAULT
5926 $$ = makeDefElem("encoding", NULL);
5928 | COLLATE opt_equal Sconst
5930 $$ = makeDefElem("collate", (Node *)makeString($3));
5932 | COLLATE opt_equal DEFAULT
5934 $$ = makeDefElem("collate", NULL);
5936 | CTYPE opt_equal Sconst
5938 $$ = makeDefElem("ctype", (Node *)makeString($3));
5940 | CTYPE opt_equal DEFAULT
5942 $$ = makeDefElem("ctype", NULL);
5944 | CONNECTION LIMIT opt_equal SignedIconst
5946 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
5948 | OWNER opt_equal name
5950 $$ = makeDefElem("owner", (Node *)makeString($3));
5952 | OWNER opt_equal DEFAULT
5954 $$ = makeDefElem("owner", NULL);
5959 * Though the equals sign doesn't match other WITH options, pg_dump uses
5960 * equals for backward compatibility, and it doesn't seem worth removing it.
5967 /*****************************************************************************
5971 *****************************************************************************/
5974 ALTER DATABASE database_name opt_with alterdb_opt_list
5976 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
5981 | ALTER DATABASE database_name SET TABLESPACE name
5983 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
5985 n->options = list_make1(makeDefElem("tablespace",
5986 (Node *)makeString($6)));
5991 AlterDatabaseSetStmt:
5992 ALTER DATABASE database_name SetResetClause
5994 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
6003 alterdb_opt_list alterdb_opt_item { $$ = lappend($1, $2); }
6004 | /* EMPTY */ { $$ = NIL; }
6008 CONNECTION LIMIT opt_equal SignedIconst
6010 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6015 /*****************************************************************************
6017 * DROP DATABASE [ IF EXISTS ]
6019 * This is implicitly CASCADE, no need for drop behavior
6020 *****************************************************************************/
6022 DropdbStmt: DROP DATABASE database_name
6024 DropdbStmt *n = makeNode(DropdbStmt);
6026 n->missing_ok = FALSE;
6029 | DROP DATABASE IF_P EXISTS database_name
6031 DropdbStmt *n = makeNode(DropdbStmt);
6033 n->missing_ok = TRUE;
6039 /*****************************************************************************
6041 * Manipulate a domain
6043 *****************************************************************************/
6046 CREATE DOMAIN_P any_name opt_as Typename ColQualList
6048 CreateDomainStmt *n = makeNode(CreateDomainStmt);
6051 n->constraints = $6;
6057 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
6058 ALTER DOMAIN_P any_name alter_column_default
6060 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6066 /* ALTER DOMAIN <domain> DROP NOT NULL */
6067 | ALTER DOMAIN_P any_name DROP NOT NULL_P
6069 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6074 /* ALTER DOMAIN <domain> SET NOT NULL */
6075 | ALTER DOMAIN_P any_name SET NOT NULL_P
6077 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6082 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
6083 | ALTER DOMAIN_P any_name ADD_P TableConstraint
6085 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6091 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
6092 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
6094 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6108 /*****************************************************************************
6110 * Manipulate a text search dictionary or configuration
6112 *****************************************************************************/
6114 AlterTSDictionaryStmt:
6115 ALTER TEXT_P SEARCH DICTIONARY any_name definition
6117 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
6124 AlterTSConfigurationStmt:
6125 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
6127 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6131 n->override = false;
6135 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
6137 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6145 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
6147 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6150 n->dicts = list_make2($9,$11);
6151 n->override = false;
6155 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
6157 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6160 n->dicts = list_make2($11,$13);
6161 n->override = false;
6165 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
6167 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6170 n->missing_ok = false;
6173 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
6175 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6178 n->missing_ok = true;
6184 /*****************************************************************************
6186 * Manipulate a conversion
6188 * CREATE [DEFAULT] CONVERSION <conversion_name>
6189 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
6191 *****************************************************************************/
6193 CreateConversionStmt:
6194 CREATE opt_default CONVERSION_P any_name FOR Sconst
6195 TO Sconst FROM any_name
6197 CreateConversionStmt *n = makeNode(CreateConversionStmt);
6198 n->conversion_name = $4;
6199 n->for_encoding_name = $6;
6200 n->to_encoding_name = $8;
6207 /*****************************************************************************
6210 * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
6212 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
6214 *****************************************************************************/
6217 CLUSTER opt_verbose qualified_name cluster_index_specification
6219 ClusterStmt *n = makeNode(ClusterStmt);
6225 | CLUSTER opt_verbose
6227 ClusterStmt *n = makeNode(ClusterStmt);
6229 n->indexname = NULL;
6233 /* kept for pre-8.3 compatibility */
6234 | CLUSTER opt_verbose index_name ON qualified_name
6236 ClusterStmt *n = makeNode(ClusterStmt);
6244 cluster_index_specification:
6245 USING index_name { $$ = $2; }
6246 | /*EMPTY*/ { $$ = NULL; }
6250 /*****************************************************************************
6256 *****************************************************************************/
6258 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
6260 VacuumStmt *n = makeNode(VacuumStmt);
6264 n->freeze_min_age = $3 ? 0 : -1;
6265 n->scan_all = $2 || $3;
6271 | VACUUM opt_full opt_freeze opt_verbose qualified_name
6273 VacuumStmt *n = makeNode(VacuumStmt);
6277 n->freeze_min_age = $3 ? 0 : -1;
6278 n->scan_all = $2 || $3;
6284 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
6286 VacuumStmt *n = (VacuumStmt *) $5;
6289 n->freeze_min_age = $3 ? 0 : -1;
6290 n->scan_all = $2 || $3;
6297 analyze_keyword opt_verbose
6299 VacuumStmt *n = makeNode(VacuumStmt);
6303 n->freeze_min_age = -1;
6309 | analyze_keyword opt_verbose qualified_name opt_name_list
6311 VacuumStmt *n = makeNode(VacuumStmt);
6315 n->freeze_min_age = -1;
6325 | ANALYSE /* British */ {}
6329 VERBOSE { $$ = TRUE; }
6330 | /*EMPTY*/ { $$ = FALSE; }
6333 opt_full: FULL { $$ = TRUE; }
6334 | /*EMPTY*/ { $$ = FALSE; }
6337 opt_freeze: FREEZE { $$ = TRUE; }
6338 | /*EMPTY*/ { $$ = FALSE; }
6342 '(' name_list ')' { $$ = $2; }
6343 | /*EMPTY*/ { $$ = NIL; }
6347 /*****************************************************************************
6350 * EXPLAIN [ANALYZE] [VERBOSE] query
6352 *****************************************************************************/
6354 ExplainStmt: EXPLAIN opt_analyze opt_verbose ExplainableStmt
6356 ExplainStmt *n = makeNode(ExplainStmt);
6371 | ExecuteStmt /* by default all are $$=$1 */
6375 analyze_keyword { $$ = TRUE; }
6376 | /* EMPTY */ { $$ = FALSE; }
6379 /*****************************************************************************
6382 * PREPARE <plan_name> [(args, ...)] AS <query>
6384 *****************************************************************************/
6386 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
6388 PrepareStmt *n = makeNode(PrepareStmt);
6396 prep_type_clause: '(' type_list ')' { $$ = $2; }
6397 | /* EMPTY */ { $$ = NIL; }
6404 | DeleteStmt /* by default all are $$=$1 */
6407 /*****************************************************************************
6409 * EXECUTE <plan_name> [(params, ...)]
6410 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
6412 *****************************************************************************/
6414 ExecuteStmt: EXECUTE name execute_param_clause
6416 ExecuteStmt *n = makeNode(ExecuteStmt);
6422 | CREATE OptTemp TABLE create_as_target AS
6423 EXECUTE name execute_param_clause
6425 ExecuteStmt *n = makeNode(ExecuteStmt);
6428 $4->rel->istemp = $2;
6432 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6433 errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
6434 /* ... because it's not implemented, but it could be */
6439 execute_param_clause: '(' expr_list ')' { $$ = $2; }
6440 | /* EMPTY */ { $$ = NIL; }
6443 /*****************************************************************************
6446 * DEALLOCATE [PREPARE] <plan_name>
6448 *****************************************************************************/
6450 DeallocateStmt: DEALLOCATE name
6452 DeallocateStmt *n = makeNode(DeallocateStmt);
6456 | DEALLOCATE PREPARE name
6458 DeallocateStmt *n = makeNode(DeallocateStmt);
6464 DeallocateStmt *n = makeNode(DeallocateStmt);
6468 | DEALLOCATE PREPARE ALL
6470 DeallocateStmt *n = makeNode(DeallocateStmt);
6476 /*****************************************************************************
6481 *****************************************************************************/
6484 INSERT INTO qualified_name insert_rest returning_clause
6487 $4->returningList = $5;
6495 $$ = makeNode(InsertStmt);
6497 $$->selectStmt = $1;
6499 | '(' insert_column_list ')' SelectStmt
6501 $$ = makeNode(InsertStmt);
6503 $$->selectStmt = $4;
6507 $$ = makeNode(InsertStmt);
6509 $$->selectStmt = NULL;
6515 { $$ = list_make1($1); }
6516 | insert_column_list ',' insert_column_item
6517 { $$ = lappend($1, $3); }
6521 ColId opt_indirection
6523 $$ = makeNode(ResTarget);
6525 $$->indirection = check_indirection($2);
6532 RETURNING target_list { $$ = $2; }
6533 | /* EMPTY */ { $$ = NIL; }
6537 /*****************************************************************************
6542 *****************************************************************************/
6544 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
6545 using_clause where_or_current_clause returning_clause
6547 DeleteStmt *n = makeNode(DeleteStmt);
6549 n->usingClause = $4;
6550 n->whereClause = $5;
6551 n->returningList = $6;
6557 USING from_list { $$ = $2; }
6558 | /*EMPTY*/ { $$ = NIL; }
6561 LockStmt: LOCK_P opt_table qualified_name_list opt_lock opt_nowait
6563 LockStmt *n = makeNode(LockStmt);
6572 opt_lock: IN_P lock_type MODE { $$ = $2; }
6573 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
6576 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
6577 | ROW SHARE { $$ = RowShareLock; }
6578 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
6579 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
6580 | SHARE { $$ = ShareLock; }
6581 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
6582 | EXCLUSIVE { $$ = ExclusiveLock; }
6583 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
6586 opt_nowait: NOWAIT { $$ = TRUE; }
6587 | /*EMPTY*/ { $$ = FALSE; }
6591 /*****************************************************************************
6594 * UpdateStmt (UPDATE)
6596 *****************************************************************************/
6598 UpdateStmt: UPDATE relation_expr_opt_alias
6601 where_or_current_clause
6604 UpdateStmt *n = makeNode(UpdateStmt);
6608 n->whereClause = $6;
6609 n->returningList = $7;
6615 set_clause { $$ = $1; }
6616 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
6620 single_set_clause { $$ = list_make1($1); }
6621 | multiple_set_clause { $$ = $1; }
6625 set_target '=' ctext_expr
6628 $$->val = (Node *) $3;
6632 multiple_set_clause:
6633 '(' set_target_list ')' '=' ctext_row
6639 * Break the ctext_row apart, merge individual expressions
6640 * into the destination ResTargets. XXX this approach
6641 * cannot work for general row expressions as sources.
6643 if (list_length($2) != list_length($5))
6645 (errcode(ERRCODE_SYNTAX_ERROR),
6646 errmsg("number of columns does not match number of values"),
6647 scanner_errposition(@1)));
6648 forboth(col_cell, $2, val_cell, $5)
6650 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
6651 Node *res_val = (Node *) lfirst(val_cell);
6653 res_col->val = res_val;
6661 ColId opt_indirection
6663 $$ = makeNode(ResTarget);
6665 $$->indirection = check_indirection($2);
6666 $$->val = NULL; /* upper production sets this */
6672 set_target { $$ = list_make1($1); }
6673 | set_target_list ',' set_target { $$ = lappend($1,$3); }
6677 /*****************************************************************************
6682 *****************************************************************************/
6683 DeclareCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR SelectStmt
6685 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
6687 /* currently we always set FAST_PLAN option */
6688 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
6694 cursor_options: /*EMPTY*/ { $$ = 0; }
6695 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
6696 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
6697 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
6698 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
6701 opt_hold: /* EMPTY */ { $$ = 0; }
6702 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
6703 | WITHOUT HOLD { $$ = 0; }
6706 /*****************************************************************************
6711 *****************************************************************************/
6713 /* A complete SELECT statement looks like this.
6715 * The rule returns either a single SelectStmt node or a tree of them,
6716 * representing a set-operation tree.
6718 * There is an ambiguity when a sub-SELECT is within an a_expr and there
6719 * are excess parentheses: do the parentheses belong to the sub-SELECT or
6720 * to the surrounding a_expr? We don't really care, but yacc wants to know.
6721 * To resolve the ambiguity, we are careful to define the grammar so that
6722 * the decision is staved off as long as possible: as long as we can keep
6723 * absorbing parentheses into the sub-SELECT, we will do so, and only when
6724 * it's no longer possible to do that will we decide that parens belong to
6725 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
6726 * parentheses are treated as part of the sub-select. The necessity of doing
6727 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
6728 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
6729 * SELECT viewpoint when we see the UNION.
6731 * This approach is implemented by defining a nonterminal select_with_parens,
6732 * which represents a SELECT with at least one outer layer of parentheses,
6733 * and being careful to use select_with_parens, never '(' SelectStmt ')',
6734 * in the expression grammar. We will then have shift-reduce conflicts
6735 * which we can resolve in favor of always treating '(' <select> ')' as
6736 * a select_with_parens. To resolve the conflicts, the productions that
6737 * conflict with the select_with_parens productions are manually given
6738 * precedences lower than the precedence of ')', thereby ensuring that we
6739 * shift ')' (and then reduce to select_with_parens) rather than trying to
6740 * reduce the inner <select> nonterminal to something else. We use UMINUS
6741 * precedence for this, which is a fairly arbitrary choice.
6743 * To be able to define select_with_parens itself without ambiguity, we need
6744 * a nonterminal select_no_parens that represents a SELECT structure with no
6745 * outermost parentheses. This is a little bit tedious, but it works.
6747 * In non-expression contexts, we use SelectStmt which can represent a SELECT
6748 * with or without outer parentheses.
6751 SelectStmt: select_no_parens %prec UMINUS
6752 | select_with_parens %prec UMINUS
6756 '(' select_no_parens ')' { $$ = $2; }
6757 | '(' select_with_parens ')' { $$ = $2; }
6761 * This rule parses the equivalent of the standard's <query expression>.
6762 * The duplicative productions are annoying, but hard to get rid of without
6763 * creating shift/reduce conflicts.
6765 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
6766 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
6767 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
6771 simple_select { $$ = $1; }
6772 | select_clause sort_clause
6774 insertSelectOptions((SelectStmt *) $1, $2, NIL,
6778 | select_clause opt_sort_clause for_locking_clause opt_select_limit
6780 insertSelectOptions((SelectStmt *) $1, $2, $3,
6781 list_nth($4, 0), list_nth($4, 1),
6785 | select_clause opt_sort_clause select_limit opt_for_locking_clause
6787 insertSelectOptions((SelectStmt *) $1, $2, $4,
6788 list_nth($3, 0), list_nth($3, 1),
6792 | with_clause simple_select
6794 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
6799 | with_clause select_clause sort_clause
6801 insertSelectOptions((SelectStmt *) $2, $3, NIL,
6806 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
6808 insertSelectOptions((SelectStmt *) $2, $3, $4,
6809 list_nth($5, 0), list_nth($5, 1),
6813 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
6815 insertSelectOptions((SelectStmt *) $2, $3, $5,
6816 list_nth($4, 0), list_nth($4, 1),
6823 simple_select { $$ = $1; }
6824 | select_with_parens { $$ = $1; }
6828 * This rule parses SELECT statements that can appear within set operations,
6829 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
6830 * the ordering of the set operations. Without '(' and ')' we want the
6831 * operations to be ordered per the precedence specs at the head of this file.
6833 * As with select_no_parens, simple_select cannot have outer parentheses,
6834 * but can have parenthesized subclauses.
6836 * Note that sort clauses cannot be included at this level --- SQL92 requires
6837 * SELECT foo UNION SELECT bar ORDER BY baz
6839 * (SELECT foo UNION SELECT bar) ORDER BY baz
6841 * SELECT foo UNION (SELECT bar ORDER BY baz)
6842 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
6843 * described as part of the select_no_parens production, not simple_select.
6844 * This does not limit functionality, because you can reintroduce these
6845 * clauses inside parentheses.
6847 * NOTE: only the leftmost component SelectStmt should have INTO.
6848 * However, this is not checked by the grammar; parse analysis must check it.
6851 SELECT opt_distinct target_list
6852 into_clause from_clause where_clause
6853 group_clause having_clause window_clause
6855 SelectStmt *n = makeNode(SelectStmt);
6856 n->distinctClause = $2;
6860 n->whereClause = $6;
6861 n->groupClause = $7;
6862 n->havingClause = $8;
6863 n->windowClause = $9;
6866 | values_clause { $$ = $1; }
6867 | TABLE relation_expr
6869 /* same as SELECT * FROM relation_expr */
6870 ColumnRef *cr = makeNode(ColumnRef);
6871 ResTarget *rt = makeNode(ResTarget);
6872 SelectStmt *n = makeNode(SelectStmt);
6874 cr->fields = list_make1(makeNode(A_Star));
6878 rt->indirection = NIL;
6879 rt->val = (Node *)cr;
6882 n->targetList = list_make1(rt);
6883 n->fromClause = list_make1($2);
6886 | select_clause UNION opt_all select_clause
6888 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
6890 | select_clause INTERSECT opt_all select_clause
6892 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
6894 | select_clause EXCEPT opt_all select_clause
6896 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
6901 * SQL standard WITH clause looks like:
6903 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
6904 * AS (query) [ SEARCH or CYCLE clause ]
6906 * We don't currently support the SEARCH or CYCLE clause.
6911 $$ = makeNode(WithClause);
6913 $$->recursive = false;
6916 | WITH RECURSIVE cte_list
6918 $$ = makeNode(WithClause);
6920 $$->recursive = true;
6926 common_table_expr { $$ = list_make1($1); }
6927 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
6930 common_table_expr: name opt_name_list AS select_with_parens
6932 CommonTableExpr *n = makeNode(CommonTableExpr);
6934 n->aliascolnames = $2;
6942 INTO OptTempTableName
6944 $$ = makeNode(IntoClause);
6948 $$->onCommit = ONCOMMIT_NOOP;
6949 $$->tableSpaceName = NULL;
6956 * Redundancy here is needed to avoid shift/reduce conflicts,
6957 * since TEMP is not a reserved word. See also OptTemp.
6960 TEMPORARY opt_table qualified_name
6965 | TEMP opt_table qualified_name
6970 | LOCAL TEMPORARY opt_table qualified_name
6975 | LOCAL TEMP opt_table qualified_name
6980 | GLOBAL TEMPORARY opt_table qualified_name
6985 | GLOBAL TEMP opt_table qualified_name
6990 | TABLE qualified_name
7006 opt_all: ALL { $$ = TRUE; }
7007 | DISTINCT { $$ = FALSE; }
7008 | /*EMPTY*/ { $$ = FALSE; }
7011 /* We use (NIL) as a placeholder to indicate that all target expressions
7012 * should be placed in the DISTINCT list during parsetree analysis.
7015 DISTINCT { $$ = list_make1(NIL); }
7016 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
7018 | /*EMPTY*/ { $$ = NIL; }
7022 sort_clause { $$ = $1;}
7023 | /*EMPTY*/ { $$ = NIL; }
7027 ORDER BY sortby_list { $$ = $3; }
7031 sortby { $$ = list_make1($1); }
7032 | sortby_list ',' sortby { $$ = lappend($1, $3); }
7035 sortby: a_expr USING qual_all_Op opt_nulls_order
7037 $$ = makeNode(SortBy);
7039 $$->sortby_dir = SORTBY_USING;
7040 $$->sortby_nulls = $4;
7044 | a_expr opt_asc_desc opt_nulls_order
7046 $$ = makeNode(SortBy);
7048 $$->sortby_dir = $2;
7049 $$->sortby_nulls = $3;
7051 $$->location = -1; /* no operator */
7057 LIMIT select_limit_value OFFSET select_offset_value
7058 { $$ = list_make2($4, $2); }
7059 | OFFSET select_offset_value LIMIT select_limit_value
7060 { $$ = list_make2($2, $4); }
7061 | LIMIT select_limit_value
7062 { $$ = list_make2(NULL, $2); }
7063 | OFFSET select_offset_value
7064 { $$ = list_make2($2, NULL); }
7065 | LIMIT select_limit_value ',' select_offset_value
7067 /* Disabled because it was too confusing, bjm 2002-02-18 */
7069 (errcode(ERRCODE_SYNTAX_ERROR),
7070 errmsg("LIMIT #,# syntax is not supported"),
7071 errhint("Use separate LIMIT and OFFSET clauses."),
7072 scanner_errposition(@1)));
7074 /* SQL:2008 syntax variants */
7075 | OFFSET select_offset_value2 row_or_rows
7076 { $$ = list_make2($2, NULL); }
7077 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
7078 { $$ = list_make2(NULL, $3); }
7079 | OFFSET select_offset_value2 row_or_rows FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
7080 { $$ = list_make2($2, $6); }
7084 select_limit { $$ = $1; }
7086 { $$ = list_make2(NULL,NULL); }
7093 /* LIMIT ALL is represented as a NULL constant */
7094 $$ = makeNullAConst(@1);
7099 * Allowing full expressions without parentheses causes various parsing
7100 * problems with the trailing ROW/ROWS key words. SQL only calls for
7101 * constants, so we allow the rest only with parentheses.
7103 opt_select_fetch_first_value:
7104 SignedIconst { $$ = makeIntConst($1, @1); }
7105 | '(' a_expr ')' { $$ = $2; }
7106 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
7109 select_offset_value:
7114 * Again, the trailing ROW/ROWS in this case prevent the full expression
7115 * syntax. c_expr is the best we can do.
7117 select_offset_value2:
7134 GROUP_P BY expr_list { $$ = $3; }
7135 | /*EMPTY*/ { $$ = NIL; }
7139 HAVING a_expr { $$ = $2; }
7140 | /*EMPTY*/ { $$ = NULL; }
7144 for_locking_items { $$ = $1; }
7145 | FOR READ ONLY { $$ = NIL; }
7148 opt_for_locking_clause:
7149 for_locking_clause { $$ = $1; }
7150 | /* EMPTY */ { $$ = NIL; }
7154 for_locking_item { $$ = list_make1($1); }
7155 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
7159 FOR UPDATE locked_rels_list opt_nowait
7161 LockingClause *n = makeNode(LockingClause);
7163 n->forUpdate = TRUE;
7167 | FOR SHARE locked_rels_list opt_nowait
7169 LockingClause *n = makeNode(LockingClause);
7171 n->forUpdate = FALSE;
7178 OF qualified_name_list { $$ = $2; }
7179 | /* EMPTY */ { $$ = NIL; }
7186 SelectStmt *n = makeNode(SelectStmt);
7187 n->valuesLists = list_make1($2);
7190 | values_clause ',' ctext_row
7192 SelectStmt *n = (SelectStmt *) $1;
7193 n->valuesLists = lappend(n->valuesLists, $3);
7199 /*****************************************************************************
7201 * clauses common to all Optimizable Stmts:
7202 * from_clause - allow list of both JOIN expressions and table names
7203 * where_clause - qualifications for joins or restrictions
7205 *****************************************************************************/
7208 FROM from_list { $$ = $2; }
7209 | /*EMPTY*/ { $$ = NIL; }
7213 table_ref { $$ = list_make1($1); }
7214 | from_list ',' table_ref { $$ = lappend($1, $3); }
7218 * table_ref is where an alias clause can be attached. Note we cannot make
7219 * alias_clause have an empty production because that causes parse conflicts
7220 * between table_ref := '(' joined_table ')' alias_clause
7221 * and joined_table := '(' joined_table ')'. So, we must have the
7222 * redundant-looking productions here instead.
7224 table_ref: relation_expr
7228 | relation_expr alias_clause
7235 RangeFunction *n = makeNode(RangeFunction);
7236 n->funccallnode = $1;
7237 n->coldeflist = NIL;
7240 | func_table alias_clause
7242 RangeFunction *n = makeNode(RangeFunction);
7243 n->funccallnode = $1;
7245 n->coldeflist = NIL;
7248 | func_table AS '(' TableFuncElementList ')'
7250 RangeFunction *n = makeNode(RangeFunction);
7251 n->funccallnode = $1;
7255 | func_table AS ColId '(' TableFuncElementList ')'
7257 RangeFunction *n = makeNode(RangeFunction);
7258 Alias *a = makeNode(Alias);
7259 n->funccallnode = $1;
7265 | func_table ColId '(' TableFuncElementList ')'
7267 RangeFunction *n = makeNode(RangeFunction);
7268 Alias *a = makeNode(Alias);
7269 n->funccallnode = $1;
7275 | select_with_parens
7278 * The SQL spec does not permit a subselect
7279 * (<derived_table>) without an alias clause,
7280 * so we don't either. This avoids the problem
7281 * of needing to invent a unique refname for it.
7282 * That could be surmounted if there's sufficient
7283 * popular demand, but for now let's just implement
7284 * the spec and see if anyone complains.
7285 * However, it does seem like a good idea to emit
7286 * an error message that's better than "syntax error".
7288 if (IsA($1, SelectStmt) &&
7289 ((SelectStmt *) $1)->valuesLists)
7291 (errcode(ERRCODE_SYNTAX_ERROR),
7292 errmsg("VALUES in FROM must have an alias"),
7293 errhint("For example, FROM (VALUES ...) [AS] foo."),
7294 scanner_errposition(@1)));
7297 (errcode(ERRCODE_SYNTAX_ERROR),
7298 errmsg("subquery in FROM must have an alias"),
7299 errhint("For example, FROM (SELECT ...) [AS] foo."),
7300 scanner_errposition(@1)));
7303 | select_with_parens alias_clause
7305 RangeSubselect *n = makeNode(RangeSubselect);
7314 | '(' joined_table ')' alias_clause
7323 * It may seem silly to separate joined_table from table_ref, but there is
7324 * method in SQL92's madness: if you don't do it this way you get reduce-
7325 * reduce conflicts, because it's not clear to the parser generator whether
7326 * to expect alias_clause after ')' or not. For the same reason we must
7327 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
7328 * join_type to expand to empty; if we try it, the parser generator can't
7329 * figure out when to reduce an empty join_type right after table_ref.
7331 * Note that a CROSS JOIN is the same as an unqualified
7332 * INNER JOIN, and an INNER JOIN/ON has the same shape
7333 * but a qualification expression to limit membership.
7334 * A NATURAL JOIN implicitly matches column names between
7335 * tables and the shape is determined by which columns are
7336 * in common. We'll collect columns during the later transformations.
7340 '(' joined_table ')'
7344 | table_ref CROSS JOIN table_ref
7346 /* CROSS JOIN is same as unqualified inner join */
7347 JoinExpr *n = makeNode(JoinExpr);
7348 n->jointype = JOIN_INNER;
7349 n->isNatural = FALSE;
7356 | table_ref join_type JOIN table_ref join_qual
7358 JoinExpr *n = makeNode(JoinExpr);
7360 n->isNatural = FALSE;
7363 if ($5 != NULL && IsA($5, List))
7364 n->using = (List *) $5; /* USING clause */
7366 n->quals = $5; /* ON clause */
7369 | table_ref JOIN table_ref join_qual
7371 /* letting join_type reduce to empty doesn't work */
7372 JoinExpr *n = makeNode(JoinExpr);
7373 n->jointype = JOIN_INNER;
7374 n->isNatural = FALSE;
7377 if ($4 != NULL && IsA($4, List))
7378 n->using = (List *) $4; /* USING clause */
7380 n->quals = $4; /* ON clause */
7383 | table_ref NATURAL join_type JOIN table_ref
7385 JoinExpr *n = makeNode(JoinExpr);
7387 n->isNatural = TRUE;
7390 n->using = NIL; /* figure out which columns later... */
7391 n->quals = NULL; /* fill later */
7394 | table_ref NATURAL JOIN table_ref
7396 /* letting join_type reduce to empty doesn't work */
7397 JoinExpr *n = makeNode(JoinExpr);
7398 n->jointype = JOIN_INNER;
7399 n->isNatural = TRUE;
7402 n->using = NIL; /* figure out which columns later... */
7403 n->quals = NULL; /* fill later */
7409 AS ColId '(' name_list ')'
7411 $$ = makeNode(Alias);
7417 $$ = makeNode(Alias);
7420 | ColId '(' name_list ')'
7422 $$ = makeNode(Alias);
7428 $$ = makeNode(Alias);
7433 join_type: FULL join_outer { $$ = JOIN_FULL; }
7434 | LEFT join_outer { $$ = JOIN_LEFT; }
7435 | RIGHT join_outer { $$ = JOIN_RIGHT; }
7436 | INNER_P { $$ = JOIN_INNER; }
7439 /* OUTER is just noise... */
7440 join_outer: OUTER_P { $$ = NULL; }
7441 | /*EMPTY*/ { $$ = NULL; }
7444 /* JOIN qualification clauses
7445 * Possibilities are:
7446 * USING ( column list ) allows only unqualified column names,
7447 * which must match between tables.
7448 * ON expr allows more general qualifications.
7450 * We return USING as a List node, while an ON-expr will not be a List.
7453 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
7454 | ON a_expr { $$ = $2; }
7461 /* default inheritance */
7463 $$->inhOpt = INH_DEFAULT;
7466 | qualified_name '*'
7468 /* inheritance query */
7470 $$->inhOpt = INH_YES;
7473 | ONLY qualified_name
7475 /* no inheritance */
7477 $$->inhOpt = INH_NO;
7480 | ONLY '(' qualified_name ')'
7482 /* no inheritance, SQL99-style syntax */
7484 $$->inhOpt = INH_NO;
7491 * Given "UPDATE foo set set ...", we have to decide without looking any
7492 * further ahead whether the first "set" is an alias or the UPDATE's SET
7493 * keyword. Since "set" is allowed as a column name both interpretations
7494 * are feasible. We resolve the shift/reduce conflict by giving the first
7495 * relation_expr_opt_alias production a higher precedence than the SET token
7496 * has, causing the parser to prefer to reduce, in effect assuming that the
7497 * SET is not an alias.
7499 relation_expr_opt_alias: relation_expr %prec UMINUS
7503 | relation_expr ColId
7505 Alias *alias = makeNode(Alias);
7506 alias->aliasname = $2;
7510 | relation_expr AS ColId
7512 Alias *alias = makeNode(Alias);
7513 alias->aliasname = $3;
7520 func_table: func_expr { $$ = $1; }
7525 WHERE a_expr { $$ = $2; }
7526 | /*EMPTY*/ { $$ = NULL; }
7529 /* variant for UPDATE and DELETE */
7530 where_or_current_clause:
7531 WHERE a_expr { $$ = $2; }
7532 | WHERE CURRENT_P OF name
7534 CurrentOfExpr *n = makeNode(CurrentOfExpr);
7535 /* cvarno is filled in by parse analysis */
7536 n->cursor_name = $4;
7537 n->cursor_param = 0;
7540 | WHERE CURRENT_P OF PARAM
7542 CurrentOfExpr *n = makeNode(CurrentOfExpr);
7543 /* cvarno is filled in by parse analysis */
7544 n->cursor_name = NULL;
7545 n->cursor_param = $4;
7548 | /*EMPTY*/ { $$ = NULL; }
7552 TableFuncElementList:
7555 $$ = list_make1($1);
7557 | TableFuncElementList ',' TableFuncElement
7559 $$ = lappend($1, $3);
7563 TableFuncElement: ColId Typename
7565 ColumnDef *n = makeNode(ColumnDef);
7568 n->constraints = NIL;
7574 /*****************************************************************************
7577 * SQL92 introduces a large amount of type-specific syntax.
7578 * Define individual clauses to handle these cases, and use
7579 * the generic case to handle regular type-extensible Postgres syntax.
7580 * - thomas 1997-10-10
7582 *****************************************************************************/
7584 Typename: SimpleTypename opt_array_bounds
7587 $$->arrayBounds = $2;
7589 | SETOF SimpleTypename opt_array_bounds
7592 $$->arrayBounds = $3;
7595 /* SQL standard syntax, currently only one-dimensional */
7596 | SimpleTypename ARRAY '[' Iconst ']'
7599 $$->arrayBounds = list_make1(makeInteger($4));
7601 | SETOF SimpleTypename ARRAY '[' Iconst ']'
7604 $$->arrayBounds = list_make1(makeInteger($5));
7607 | SimpleTypename ARRAY
7610 $$->arrayBounds = list_make1(makeInteger(-1));
7612 | SETOF SimpleTypename ARRAY
7615 $$->arrayBounds = list_make1(makeInteger(-1));
7621 opt_array_bounds '[' ']'
7622 { $$ = lappend($1, makeInteger(-1)); }
7623 | opt_array_bounds '[' Iconst ']'
7624 { $$ = lappend($1, makeInteger($3)); }
7630 GenericType { $$ = $1; }
7631 | Numeric { $$ = $1; }
7633 | Character { $$ = $1; }
7634 | ConstDatetime { $$ = $1; }
7635 | ConstInterval opt_interval
7640 | ConstInterval '(' Iconst ')' opt_interval
7645 if (list_length($5) != 1)
7647 (errcode(ERRCODE_SYNTAX_ERROR),
7648 errmsg("interval precision specified twice"),
7649 scanner_errposition(@1)));
7650 $$->typmods = lappend($5, makeIntConst($3, @3));
7653 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
7654 makeIntConst($3, @3));
7658 /* We have a separate ConstTypename to allow defaulting fixed-length
7659 * types such as CHAR() and BIT() to an unspecified length.
7660 * SQL9x requires that these default to a length of one, but this
7661 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
7662 * where there is an obvious better choice to make.
7663 * Note that ConstInterval is not included here since it must
7664 * be pushed up higher in the rules to accomodate the postfix
7665 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
7666 * the generic-type-name case in AExprConst to avoid premature
7667 * reduce/reduce conflicts against function names.
7670 Numeric { $$ = $1; }
7671 | ConstBit { $$ = $1; }
7672 | ConstCharacter { $$ = $1; }
7673 | ConstDatetime { $$ = $1; }
7677 * GenericType covers all type names that don't have special syntax mandated
7678 * by the standard, including qualified names. We also allow type modifiers.
7679 * To avoid parsing conflicts against function invocations, the modifiers
7680 * have to be shown as expr_list here, but parse analysis will only accept
7681 * constants for them.
7684 type_function_name opt_type_modifiers
7686 $$ = makeTypeName($1);
7690 | type_function_name attrs opt_type_modifiers
7692 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
7698 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
7699 | /* EMPTY */ { $$ = NIL; }
7703 * SQL92 numeric data types
7707 $$ = SystemTypeName("int4");
7712 $$ = SystemTypeName("int4");
7717 $$ = SystemTypeName("int2");
7722 $$ = SystemTypeName("int8");
7727 $$ = SystemTypeName("float4");
7735 | DOUBLE_P PRECISION
7737 $$ = SystemTypeName("float8");
7740 | DECIMAL_P opt_type_modifiers
7742 $$ = SystemTypeName("numeric");
7746 | DEC opt_type_modifiers
7748 $$ = SystemTypeName("numeric");
7752 | NUMERIC opt_type_modifiers
7754 $$ = SystemTypeName("numeric");
7760 $$ = SystemTypeName("bool");
7765 opt_float: '(' Iconst ')'
7768 * Check FLOAT() precision limits assuming IEEE floating
7769 * types - thomas 1997-09-18
7773 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7774 errmsg("precision for type float must be at least 1 bit"),
7775 scanner_errposition(@2)));
7777 $$ = SystemTypeName("float4");
7779 $$ = SystemTypeName("float8");
7782 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7783 errmsg("precision for type float must be less than 54 bits"),
7784 scanner_errposition(@2)));
7788 $$ = SystemTypeName("float8");
7793 * SQL92 bit-field data types
7794 * The following implements BIT() and BIT VARYING().
7806 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
7807 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
7808 ConstBit: BitWithLength
7820 BIT opt_varying '(' expr_list ')'
7824 typname = $2 ? "varbit" : "bit";
7825 $$ = SystemTypeName(typname);
7834 /* bit defaults to bit(1), varbit to no limit */
7837 $$ = SystemTypeName("varbit");
7841 $$ = SystemTypeName("bit");
7842 $$->typmods = list_make1(makeIntConst(1, -1));
7850 * SQL92 character data types
7851 * The following implements CHAR() and VARCHAR().
7853 Character: CharacterWithLength
7857 | CharacterWithoutLength
7863 ConstCharacter: CharacterWithLength
7867 | CharacterWithoutLength
7869 /* Length was not specified so allow to be unrestricted.
7870 * This handles problems with fixed-length (bpchar) strings
7871 * which in column definitions must default to a length
7872 * of one, but should not be constrained if the length
7873 * was not specified.
7880 CharacterWithLength: character '(' Iconst ')' opt_charset
7882 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
7886 type = palloc(strlen($1) + 1 + strlen($5) + 1);
7893 $$ = SystemTypeName($1);
7894 $$->typmods = list_make1(makeIntConst($3, @3));
7899 CharacterWithoutLength: character opt_charset
7901 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
7905 type = palloc(strlen($1) + 1 + strlen($2) + 1);
7912 $$ = SystemTypeName($1);
7914 /* char defaults to char(1), varchar to no limit */
7915 if (strcmp($1, "bpchar") == 0)
7916 $$->typmods = list_make1(makeIntConst(1, -1));
7922 character: CHARACTER opt_varying
7923 { $$ = $2 ? "varchar": "bpchar"; }
7924 | CHAR_P opt_varying
7925 { $$ = $2 ? "varchar": "bpchar"; }
7928 | NATIONAL CHARACTER opt_varying
7929 { $$ = $3 ? "varchar": "bpchar"; }
7930 | NATIONAL CHAR_P opt_varying
7931 { $$ = $3 ? "varchar": "bpchar"; }
7933 { $$ = $2 ? "varchar": "bpchar"; }
7937 VARYING { $$ = TRUE; }
7938 | /*EMPTY*/ { $$ = FALSE; }
7942 CHARACTER SET ColId { $$ = $3; }
7943 | /*EMPTY*/ { $$ = NULL; }
7947 * SQL92 date/time types
7950 TIMESTAMP '(' Iconst ')' opt_timezone
7953 $$ = SystemTypeName("timestamptz");
7955 $$ = SystemTypeName("timestamp");
7956 $$->typmods = list_make1(makeIntConst($3, @3));
7959 | TIMESTAMP opt_timezone
7962 $$ = SystemTypeName("timestamptz");
7964 $$ = SystemTypeName("timestamp");
7967 | TIME '(' Iconst ')' opt_timezone
7970 $$ = SystemTypeName("timetz");
7972 $$ = SystemTypeName("time");
7973 $$->typmods = list_make1(makeIntConst($3, @3));
7979 $$ = SystemTypeName("timetz");
7981 $$ = SystemTypeName("time");
7989 $$ = SystemTypeName("interval");
7995 WITH_TIME ZONE { $$ = TRUE; }
7996 | WITHOUT TIME ZONE { $$ = FALSE; }
7997 | /*EMPTY*/ { $$ = FALSE; }
8002 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
8004 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
8006 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
8008 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
8010 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
8015 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
8016 INTERVAL_MASK(MONTH), @1));
8020 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8021 INTERVAL_MASK(HOUR), @1));
8025 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8026 INTERVAL_MASK(HOUR) |
8027 INTERVAL_MASK(MINUTE), @1));
8029 | DAY_P TO interval_second
8032 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
8033 INTERVAL_MASK(HOUR) |
8034 INTERVAL_MASK(MINUTE) |
8035 INTERVAL_MASK(SECOND), @1);
8037 | HOUR_P TO MINUTE_P
8039 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
8040 INTERVAL_MASK(MINUTE), @1));
8042 | HOUR_P TO interval_second
8045 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
8046 INTERVAL_MASK(MINUTE) |
8047 INTERVAL_MASK(SECOND), @1);
8049 | MINUTE_P TO interval_second
8052 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
8053 INTERVAL_MASK(SECOND), @1);
8062 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
8064 | SECOND_P '(' Iconst ')'
8066 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
8067 makeIntConst($3, @3));
8072 /*****************************************************************************
8074 * expression grammar
8076 *****************************************************************************/
8079 * General expressions
8080 * This is the heart of the expression syntax.
8082 * We have two expression types: a_expr is the unrestricted kind, and
8083 * b_expr is a subset that must be used in some places to avoid shift/reduce
8084 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
8085 * because that use of AND conflicts with AND as a boolean operator. So,
8086 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
8088 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
8089 * always be used by surrounding it with parens.
8091 * c_expr is all the productions that are common to a_expr and b_expr;
8092 * it's factored out just to eliminate redundant coding.
8094 a_expr: c_expr { $$ = $1; }
8095 | a_expr TYPECAST Typename
8096 { $$ = makeTypeCast($1, $3, @2); }
8097 | a_expr AT TIME ZONE a_expr
8099 FuncCall *n = makeNode(FuncCall);
8100 n->funcname = SystemFuncName("timezone");
8101 n->args = list_make2($5, $1);
8102 n->agg_star = FALSE;
8103 n->agg_distinct = FALSE;
8104 n->func_variadic = FALSE;
8110 * These operators must be called out explicitly in order to make use
8111 * of yacc/bison's automatic operator-precedence handling. All other
8112 * operator names are handled by the generic productions using "Op",
8113 * below; and all those operators will have the same precedence.
8115 * If you add more explicitly-known operators, be sure to add them
8116 * also to b_expr and to the MathOp list above.
8118 | '+' a_expr %prec UMINUS
8119 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
8120 | '-' a_expr %prec UMINUS
8121 { $$ = doNegate($2, @1); }
8123 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
8125 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
8127 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
8129 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
8131 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
8133 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
8135 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
8137 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
8139 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
8141 | a_expr qual_Op a_expr %prec Op
8142 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
8143 | qual_Op a_expr %prec Op
8144 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
8145 | a_expr qual_Op %prec POSTFIXOP
8146 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
8149 { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
8151 { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
8153 { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
8155 | a_expr LIKE a_expr
8156 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
8157 | a_expr LIKE a_expr ESCAPE a_expr
8159 FuncCall *n = makeNode(FuncCall);
8160 n->funcname = SystemFuncName("like_escape");
8161 n->args = list_make2($3, $5);
8162 n->agg_star = FALSE;
8163 n->agg_distinct = FALSE;
8164 n->func_variadic = FALSE;
8167 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
8169 | a_expr NOT LIKE a_expr
8170 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
8171 | a_expr NOT LIKE a_expr ESCAPE a_expr
8173 FuncCall *n = makeNode(FuncCall);
8174 n->funcname = SystemFuncName("like_escape");
8175 n->args = list_make2($4, $6);
8176 n->agg_star = FALSE;
8177 n->agg_distinct = FALSE;
8178 n->func_variadic = FALSE;
8181 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
8183 | a_expr ILIKE a_expr
8184 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
8185 | a_expr ILIKE a_expr ESCAPE a_expr
8187 FuncCall *n = makeNode(FuncCall);
8188 n->funcname = SystemFuncName("like_escape");
8189 n->args = list_make2($3, $5);
8190 n->agg_star = FALSE;
8191 n->agg_distinct = FALSE;
8192 n->func_variadic = FALSE;
8195 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n, @2);
8197 | a_expr NOT ILIKE a_expr
8198 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
8199 | a_expr NOT ILIKE a_expr ESCAPE a_expr
8201 FuncCall *n = makeNode(FuncCall);
8202 n->funcname = SystemFuncName("like_escape");
8203 n->args = list_make2($4, $6);
8204 n->agg_star = FALSE;
8205 n->agg_distinct = FALSE;
8206 n->func_variadic = FALSE;
8209 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n, @2);
8212 | a_expr SIMILAR TO a_expr %prec SIMILAR
8214 FuncCall *n = makeNode(FuncCall);
8215 n->funcname = SystemFuncName("similar_escape");
8216 n->args = list_make2($4, makeNullAConst(-1));
8217 n->agg_star = FALSE;
8218 n->agg_distinct = FALSE;
8219 n->func_variadic = FALSE;
8222 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8224 | a_expr SIMILAR TO a_expr ESCAPE a_expr
8226 FuncCall *n = makeNode(FuncCall);
8227 n->funcname = SystemFuncName("similar_escape");
8228 n->args = list_make2($4, $6);
8229 n->agg_star = FALSE;
8230 n->agg_distinct = FALSE;
8231 n->func_variadic = FALSE;
8234 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8236 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
8238 FuncCall *n = makeNode(FuncCall);
8239 n->funcname = SystemFuncName("similar_escape");
8240 n->args = list_make2($5, makeNullAConst(-1));
8241 n->agg_star = FALSE;
8242 n->agg_distinct = FALSE;
8243 n->func_variadic = FALSE;
8246 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8248 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
8250 FuncCall *n = makeNode(FuncCall);
8251 n->funcname = SystemFuncName("similar_escape");
8252 n->args = list_make2($5, $7);
8253 n->agg_star = FALSE;
8254 n->agg_distinct = FALSE;
8255 n->func_variadic = FALSE;
8258 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8262 * Define SQL92-style Null test clause.
8263 * Allow two forms described in the standard:
8266 * Allow two SQL extensions
8272 NullTest *n = makeNode(NullTest);
8273 n->arg = (Expr *) $1;
8274 n->nulltesttype = IS_NULL;
8279 NullTest *n = makeNode(NullTest);
8280 n->arg = (Expr *) $1;
8281 n->nulltesttype = IS_NULL;
8284 | a_expr IS NOT NULL_P
8286 NullTest *n = makeNode(NullTest);
8287 n->arg = (Expr *) $1;
8288 n->nulltesttype = IS_NOT_NULL;
8293 NullTest *n = makeNode(NullTest);
8294 n->arg = (Expr *) $1;
8295 n->nulltesttype = IS_NOT_NULL;
8300 $$ = (Node *)makeOverlaps($1, $3, @2);
8304 BooleanTest *b = makeNode(BooleanTest);
8305 b->arg = (Expr *) $1;
8306 b->booltesttype = IS_TRUE;
8309 | a_expr IS NOT TRUE_P
8311 BooleanTest *b = makeNode(BooleanTest);
8312 b->arg = (Expr *) $1;
8313 b->booltesttype = IS_NOT_TRUE;
8318 BooleanTest *b = makeNode(BooleanTest);
8319 b->arg = (Expr *) $1;
8320 b->booltesttype = IS_FALSE;
8323 | a_expr IS NOT FALSE_P
8325 BooleanTest *b = makeNode(BooleanTest);
8326 b->arg = (Expr *) $1;
8327 b->booltesttype = IS_NOT_FALSE;
8332 BooleanTest *b = makeNode(BooleanTest);
8333 b->arg = (Expr *) $1;
8334 b->booltesttype = IS_UNKNOWN;
8337 | a_expr IS NOT UNKNOWN
8339 BooleanTest *b = makeNode(BooleanTest);
8340 b->arg = (Expr *) $1;
8341 b->booltesttype = IS_NOT_UNKNOWN;
8344 | a_expr IS DISTINCT FROM a_expr %prec IS
8346 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
8348 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
8350 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8351 (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
8356 | a_expr IS OF '(' type_list ')' %prec IS
8358 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
8360 | a_expr IS NOT OF '(' type_list ')' %prec IS
8362 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
8365 * Ideally we would not use hard-wired operators below but instead use
8366 * opclasses. However, mixed data types and other issues make this
8367 * difficult: http://archives.postgresql.org/pgsql-hackers/2008-08/msg01142.php
8369 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
8371 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
8372 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
8373 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
8376 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
8378 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
8379 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
8380 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
8383 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
8385 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
8386 (Node *) makeA_Expr(AEXPR_AND, NIL,
8387 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
8388 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
8390 (Node *) makeA_Expr(AEXPR_AND, NIL,
8391 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
8392 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
8396 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
8398 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
8399 (Node *) makeA_Expr(AEXPR_OR, NIL,
8400 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
8401 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
8403 (Node *) makeA_Expr(AEXPR_OR, NIL,
8404 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
8405 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
8409 | a_expr IN_P in_expr
8411 /* in_expr returns a SubLink or a list of a_exprs */
8412 if (IsA($3, SubLink))
8414 /* generate foo = ANY (subquery) */
8415 SubLink *n = (SubLink *) $3;
8416 n->subLinkType = ANY_SUBLINK;
8418 n->operName = list_make1(makeString("="));
8424 /* generate scalar IN expression */
8425 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
8428 | a_expr NOT IN_P in_expr
8430 /* in_expr returns a SubLink or a list of a_exprs */
8431 if (IsA($4, SubLink))
8433 /* generate NOT (foo = ANY (subquery)) */
8434 /* Make an = ANY node */
8435 SubLink *n = (SubLink *) $4;
8436 n->subLinkType = ANY_SUBLINK;
8438 n->operName = list_make1(makeString("="));
8440 /* Stick a NOT on top */
8441 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
8445 /* generate scalar NOT IN expression */
8446 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
8449 | a_expr subquery_Op sub_type select_with_parens %prec Op
8451 SubLink *n = makeNode(SubLink);
8452 n->subLinkType = $3;
8459 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
8461 if ($3 == ANY_SUBLINK)
8462 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
8464 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
8466 | UNIQUE select_with_parens
8468 /* Not sure how to get rid of the parentheses
8469 * but there are lots of shift/reduce errors without them.
8471 * Should be able to implement this by plopping the entire
8472 * select into a node, then transforming the target expressions
8473 * from whatever they are into count(*), and testing the
8474 * entire result equal to one.
8475 * But, will probably implement a separate node in the executor.
8478 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8479 errmsg("UNIQUE predicate is not yet implemented"),
8480 scanner_errposition(@1)));
8482 | a_expr IS DOCUMENT_P %prec IS
8484 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8485 list_make1($1), @2);
8487 | a_expr IS NOT DOCUMENT_P %prec IS
8489 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8490 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8491 list_make1($1), @2),
8497 * Restricted expressions
8499 * b_expr is a subset of the complete expression syntax defined by a_expr.
8501 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
8502 * cause trouble in the places where b_expr is used. For simplicity, we
8503 * just eliminate all the boolean-keyword-operator productions from b_expr.
8507 | b_expr TYPECAST Typename
8508 { $$ = makeTypeCast($1, $3, @2); }
8509 | '+' b_expr %prec UMINUS
8510 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
8511 | '-' b_expr %prec UMINUS
8512 { $$ = doNegate($2, @1); }
8514 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
8516 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
8518 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
8520 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
8522 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
8524 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
8526 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
8528 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
8530 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
8531 | b_expr qual_Op b_expr %prec Op
8532 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
8533 | qual_Op b_expr %prec Op
8534 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
8535 | b_expr qual_Op %prec POSTFIXOP
8536 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
8537 | b_expr IS DISTINCT FROM b_expr %prec IS
8539 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
8541 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
8543 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
8544 NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
8546 | b_expr IS OF '(' type_list ')' %prec IS
8548 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
8550 | b_expr IS NOT OF '(' type_list ')' %prec IS
8552 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
8554 | b_expr IS DOCUMENT_P %prec IS
8556 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8557 list_make1($1), @2);
8559 | b_expr IS NOT DOCUMENT_P %prec IS
8561 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8562 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8563 list_make1($1), @2),
8569 * Productions that can be used in both a_expr and b_expr.
8571 * Note: productions that refer recursively to a_expr or b_expr mostly
8572 * cannot appear here. However, it's OK to refer to a_exprs that occur
8573 * inside parentheses, such as function arguments; that cannot introduce
8574 * ambiguity to the b_expr syntax.
8576 c_expr: columnref { $$ = $1; }
8577 | AexprConst { $$ = $1; }
8578 | PARAM opt_indirection
8580 ParamRef *p = makeNode(ParamRef);
8585 A_Indirection *n = makeNode(A_Indirection);
8586 n->arg = (Node *) p;
8587 n->indirection = check_indirection($2);
8593 | '(' a_expr ')' opt_indirection
8597 A_Indirection *n = makeNode(A_Indirection);
8599 n->indirection = check_indirection($4);
8609 | select_with_parens %prec UMINUS
8611 SubLink *n = makeNode(SubLink);
8612 n->subLinkType = EXPR_SUBLINK;
8619 | EXISTS select_with_parens
8621 SubLink *n = makeNode(SubLink);
8622 n->subLinkType = EXISTS_SUBLINK;
8629 | ARRAY select_with_parens
8631 SubLink *n = makeNode(SubLink);
8632 n->subLinkType = ARRAY_SUBLINK;
8641 A_ArrayExpr *n = (A_ArrayExpr *) $2;
8642 Assert(IsA(n, A_ArrayExpr));
8643 /* point outermost A_ArrayExpr to the ARRAY keyword */
8649 RowExpr *r = makeNode(RowExpr);
8651 r->row_typeid = InvalidOid; /* not analyzed yet */
8658 * func_expr is split out from c_expr just so that we have a classification
8659 * for "everything that is a function call or looks like one". This isn't
8660 * very important, but it saves us having to document which variants are
8661 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
8662 * (Note that many of the special SQL functions wouldn't actually make any
8663 * sense as functional index entries, but we ignore that consideration here.)
8665 func_expr: func_name '(' ')' over_clause
8667 FuncCall *n = makeNode(FuncCall);
8670 n->agg_star = FALSE;
8671 n->agg_distinct = FALSE;
8672 n->func_variadic = FALSE;
8677 | func_name '(' expr_list ')' over_clause
8679 FuncCall *n = makeNode(FuncCall);
8682 n->agg_star = FALSE;
8683 n->agg_distinct = FALSE;
8684 n->func_variadic = FALSE;
8689 | func_name '(' VARIADIC a_expr ')' over_clause
8691 FuncCall *n = makeNode(FuncCall);
8693 n->args = list_make1($4);
8694 n->agg_star = FALSE;
8695 n->agg_distinct = FALSE;
8696 n->func_variadic = TRUE;
8701 | func_name '(' expr_list ',' VARIADIC a_expr ')' over_clause
8703 FuncCall *n = makeNode(FuncCall);
8705 n->args = lappend($3, $6);
8706 n->agg_star = FALSE;
8707 n->agg_distinct = FALSE;
8708 n->func_variadic = TRUE;
8713 | func_name '(' ALL expr_list ')' over_clause
8715 FuncCall *n = makeNode(FuncCall);
8718 n->agg_star = FALSE;
8719 n->agg_distinct = FALSE;
8720 /* Ideally we'd mark the FuncCall node to indicate
8721 * "must be an aggregate", but there's no provision
8722 * for that in FuncCall at the moment.
8724 n->func_variadic = FALSE;
8729 | func_name '(' DISTINCT expr_list ')' over_clause
8731 FuncCall *n = makeNode(FuncCall);
8734 n->agg_star = FALSE;
8735 n->agg_distinct = TRUE;
8736 n->func_variadic = FALSE;
8741 | func_name '(' '*' ')' over_clause
8744 * We consider AGGREGATE(*) to invoke a parameterless
8745 * aggregate. This does the right thing for COUNT(*),
8746 * and there are no other aggregates in SQL92 that accept
8749 * The FuncCall node is also marked agg_star = true,
8750 * so that later processing can detect what the argument
8753 FuncCall *n = makeNode(FuncCall);
8757 n->agg_distinct = FALSE;
8758 n->func_variadic = FALSE;
8766 * Translate as "'now'::text::date".
8768 * We cannot use "'now'::date" because coerce_type() will
8769 * immediately reduce that to a constant representing
8770 * today's date. We need to delay the conversion until
8771 * runtime, else the wrong things will happen when
8772 * CURRENT_DATE is used in a column default value or rule.
8774 * This could be simplified if we had a way to generate
8775 * an expression tree representing runtime application
8776 * of type-input conversion functions. (As of PG 7.3
8777 * that is actually possible, but not clear that we want
8781 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8782 $$ = makeTypeCast(n, SystemTypeName("date"), -1);
8787 * Translate as "'now'::text::timetz".
8788 * See comments for CURRENT_DATE.
8791 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8792 $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
8794 | CURRENT_TIME '(' Iconst ')'
8797 * Translate as "'now'::text::timetz(n)".
8798 * See comments for CURRENT_DATE.
8802 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8803 d = SystemTypeName("timetz");
8804 d->typmods = list_make1(makeIntConst($3, @3));
8805 $$ = makeTypeCast(n, d, -1);
8810 * Translate as "now()", since we have a function that
8811 * does exactly what is needed.
8813 FuncCall *n = makeNode(FuncCall);
8814 n->funcname = SystemFuncName("now");
8816 n->agg_star = FALSE;
8817 n->agg_distinct = FALSE;
8818 n->func_variadic = FALSE;
8823 | CURRENT_TIMESTAMP '(' Iconst ')'
8826 * Translate as "'now'::text::timestamptz(n)".
8827 * See comments for CURRENT_DATE.
8831 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8832 d = SystemTypeName("timestamptz");
8833 d->typmods = list_make1(makeIntConst($3, @3));
8834 $$ = makeTypeCast(n, d, -1);
8839 * Translate as "'now'::text::time".
8840 * See comments for CURRENT_DATE.
8843 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8844 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
8846 | LOCALTIME '(' Iconst ')'
8849 * Translate as "'now'::text::time(n)".
8850 * See comments for CURRENT_DATE.
8854 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8855 d = SystemTypeName("time");
8856 d->typmods = list_make1(makeIntConst($3, @3));
8857 $$ = makeTypeCast((Node *)n, d, -1);
8862 * Translate as "'now'::text::timestamp".
8863 * See comments for CURRENT_DATE.
8866 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8867 $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
8869 | LOCALTIMESTAMP '(' Iconst ')'
8872 * Translate as "'now'::text::timestamp(n)".
8873 * See comments for CURRENT_DATE.
8877 n = makeStringConstCast("now", @1, SystemTypeName("text"));
8878 d = SystemTypeName("timestamp");
8879 d->typmods = list_make1(makeIntConst($3, @3));
8880 $$ = makeTypeCast(n, d, -1);
8884 FuncCall *n = makeNode(FuncCall);
8885 n->funcname = SystemFuncName("current_user");
8887 n->agg_star = FALSE;
8888 n->agg_distinct = FALSE;
8889 n->func_variadic = FALSE;
8896 FuncCall *n = makeNode(FuncCall);
8897 n->funcname = SystemFuncName("current_user");
8899 n->agg_star = FALSE;
8900 n->agg_distinct = FALSE;
8901 n->func_variadic = FALSE;
8908 FuncCall *n = makeNode(FuncCall);
8909 n->funcname = SystemFuncName("session_user");
8911 n->agg_star = FALSE;
8912 n->agg_distinct = FALSE;
8913 n->func_variadic = FALSE;
8920 FuncCall *n = makeNode(FuncCall);
8921 n->funcname = SystemFuncName("current_user");
8923 n->agg_star = FALSE;
8924 n->agg_distinct = FALSE;
8925 n->func_variadic = FALSE;
8932 FuncCall *n = makeNode(FuncCall);
8933 n->funcname = SystemFuncName("current_database");
8935 n->agg_star = FALSE;
8936 n->agg_distinct = FALSE;
8937 n->func_variadic = FALSE;
8944 FuncCall *n = makeNode(FuncCall);
8945 n->funcname = SystemFuncName("current_schema");
8947 n->agg_star = FALSE;
8948 n->agg_distinct = FALSE;
8949 n->func_variadic = FALSE;
8954 | CAST '(' a_expr AS Typename ')'
8955 { $$ = makeTypeCast($3, $5, @1); }
8956 | EXTRACT '(' extract_list ')'
8958 FuncCall *n = makeNode(FuncCall);
8959 n->funcname = SystemFuncName("date_part");
8961 n->agg_star = FALSE;
8962 n->agg_distinct = FALSE;
8963 n->func_variadic = FALSE;
8968 | OVERLAY '(' overlay_list ')'
8970 /* overlay(A PLACING B FROM C FOR D) is converted to
8971 * substring(A, 1, C-1) || B || substring(A, C+1, C+D)
8972 * overlay(A PLACING B FROM C) is converted to
8973 * substring(A, 1, C-1) || B || substring(A, C+1, C+char_length(B))
8975 FuncCall *n = makeNode(FuncCall);
8976 n->funcname = SystemFuncName("overlay");
8978 n->agg_star = FALSE;
8979 n->agg_distinct = FALSE;
8980 n->func_variadic = FALSE;
8985 | POSITION '(' position_list ')'
8987 /* position(A in B) is converted to position(B, A) */
8988 FuncCall *n = makeNode(FuncCall);
8989 n->funcname = SystemFuncName("position");
8991 n->agg_star = FALSE;
8992 n->agg_distinct = FALSE;
8993 n->func_variadic = FALSE;
8998 | SUBSTRING '(' substr_list ')'
9000 /* substring(A from B for C) is converted to
9001 * substring(A, B, C) - thomas 2000-11-28
9003 FuncCall *n = makeNode(FuncCall);
9004 n->funcname = SystemFuncName("substring");
9006 n->agg_star = FALSE;
9007 n->agg_distinct = FALSE;
9008 n->func_variadic = FALSE;
9013 | TREAT '(' a_expr AS Typename ')'
9015 /* TREAT(expr AS target) converts expr of a particular type to target,
9016 * which is defined to be a subtype of the original expression.
9017 * In SQL99, this is intended for use with structured UDTs,
9018 * but let's make this a generally useful form allowing stronger
9019 * coercions than are handled by implicit casting.
9021 FuncCall *n = makeNode(FuncCall);
9022 /* Convert SystemTypeName() to SystemFuncName() even though
9023 * at the moment they result in the same thing.
9025 n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
9026 n->args = list_make1($3);
9027 n->agg_star = FALSE;
9028 n->agg_distinct = FALSE;
9029 n->func_variadic = FALSE;
9034 | TRIM '(' BOTH trim_list ')'
9036 /* various trim expressions are defined in SQL92
9037 * - thomas 1997-07-19
9039 FuncCall *n = makeNode(FuncCall);
9040 n->funcname = SystemFuncName("btrim");
9042 n->agg_star = FALSE;
9043 n->agg_distinct = FALSE;
9044 n->func_variadic = FALSE;
9049 | TRIM '(' LEADING trim_list ')'
9051 FuncCall *n = makeNode(FuncCall);
9052 n->funcname = SystemFuncName("ltrim");
9054 n->agg_star = FALSE;
9055 n->agg_distinct = FALSE;
9056 n->func_variadic = FALSE;
9061 | TRIM '(' TRAILING trim_list ')'
9063 FuncCall *n = makeNode(FuncCall);
9064 n->funcname = SystemFuncName("rtrim");
9066 n->agg_star = FALSE;
9067 n->agg_distinct = FALSE;
9068 n->func_variadic = FALSE;
9073 | TRIM '(' trim_list ')'
9075 FuncCall *n = makeNode(FuncCall);
9076 n->funcname = SystemFuncName("btrim");
9078 n->agg_star = FALSE;
9079 n->agg_distinct = FALSE;
9080 n->func_variadic = FALSE;
9085 | NULLIF '(' a_expr ',' a_expr ')'
9087 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
9089 | COALESCE '(' expr_list ')'
9091 CoalesceExpr *c = makeNode(CoalesceExpr);
9096 | GREATEST '(' expr_list ')'
9098 MinMaxExpr *v = makeNode(MinMaxExpr);
9100 v->op = IS_GREATEST;
9104 | LEAST '(' expr_list ')'
9106 MinMaxExpr *v = makeNode(MinMaxExpr);
9112 | XMLCONCAT '(' expr_list ')'
9114 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
9116 | XMLELEMENT '(' NAME_P ColLabel ')'
9118 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
9120 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
9122 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
9124 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
9126 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
9128 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
9130 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
9132 | XMLFOREST '(' xml_attribute_list ')'
9134 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
9136 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
9138 XmlExpr *x = (XmlExpr *)
9139 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
9140 list_make2($4, makeBoolAConst($5, -1)),
9145 | XMLPI '(' NAME_P ColLabel ')'
9147 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
9149 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
9151 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
9153 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
9155 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
9156 list_make3($3, $5, $6), @1);
9158 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
9160 XmlSerialize *n = makeNode(XmlSerialize);
9172 xml_root_version: VERSION_P a_expr
9174 | VERSION_P NO VALUE_P
9175 { $$ = makeNullAConst(-1); }
9178 opt_xml_root_standalone: ',' STANDALONE_P YES_P
9179 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
9180 | ',' STANDALONE_P NO
9181 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
9182 | ',' STANDALONE_P NO VALUE_P
9183 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
9185 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
9188 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
9191 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
9192 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
9195 xml_attribute_el: a_expr AS ColLabel
9197 $$ = makeNode(ResTarget);
9199 $$->indirection = NIL;
9200 $$->val = (Node *) $1;
9205 $$ = makeNode(ResTarget);
9207 $$->indirection = NIL;
9208 $$->val = (Node *) $1;
9213 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
9214 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
9217 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
9218 | STRIP_P WHITESPACE_P { $$ = FALSE; }
9219 | /*EMPTY*/ { $$ = FALSE; }
9223 * Window Definitions
9226 WINDOW window_definition_list { $$ = $2; }
9227 | /*EMPTY*/ { $$ = NIL; }
9230 window_definition_list:
9231 window_definition { $$ = list_make1($1); }
9232 | window_definition_list ',' window_definition
9233 { $$ = lappend($1, $3); }
9237 ColId AS window_specification
9245 over_clause: OVER window_specification
9249 WindowDef *n = makeNode(WindowDef);
9252 n->partitionClause = NIL;
9253 n->orderClause = NIL;
9254 n->frameOptions = FRAMEOPTION_DEFAULTS;
9262 window_specification: '(' opt_existing_window_name opt_partition_clause
9263 opt_sort_clause opt_frame_clause ')'
9265 WindowDef *n = makeNode(WindowDef);
9268 n->partitionClause = $3;
9269 n->orderClause = $4;
9270 n->frameOptions = $5;
9277 * If we see PARTITION, RANGE, or ROWS as the first token after the '('
9278 * of a window_specification, we want the assumption to be that there is
9279 * no existing_window_name; but those keywords are unreserved and so could
9280 * be ColIds. We fix this by making them have the same precedence as IDENT
9281 * and giving the empty production here a slightly higher precedence, so
9282 * that the shift/reduce conflict is resolved in favor of reducing the rule.
9283 * These keywords are thus precluded from being an existing_window_name but
9284 * are not reserved for any other purpose.
9286 opt_existing_window_name: ColId { $$ = $1; }
9287 | /*EMPTY*/ %prec Op { $$ = NULL; }
9290 opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
9291 | /*EMPTY*/ { $$ = NIL; }
9295 * This is only a subset of the full SQL:2008 frame_clause grammar.
9296 * We don't support <expression> PRECEDING, <expression> FOLLOWING,
9297 * nor <window frame exclusion> yet.
9302 $$ = FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE | $2;
9306 $$ = FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS | $2;
9309 { $$ = FRAMEOPTION_DEFAULTS; }
9312 frame_extent: frame_bound
9314 /* reject invalid cases */
9315 if ($1 & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
9317 (errcode(ERRCODE_WINDOWING_ERROR),
9318 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
9319 scanner_errposition(@1)));
9320 if ($1 & FRAMEOPTION_START_CURRENT_ROW)
9322 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9323 errmsg("frame start at CURRENT ROW is not implemented"),
9324 scanner_errposition(@1)));
9325 $$ = $1 | FRAMEOPTION_END_CURRENT_ROW;
9327 | BETWEEN frame_bound AND frame_bound
9329 /* reject invalid cases */
9330 if ($2 & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
9332 (errcode(ERRCODE_WINDOWING_ERROR),
9333 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
9334 scanner_errposition(@2)));
9335 if ($2 & FRAMEOPTION_START_CURRENT_ROW)
9337 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9338 errmsg("frame start at CURRENT ROW is not implemented"),
9339 scanner_errposition(@2)));
9340 if ($4 & FRAMEOPTION_START_UNBOUNDED_PRECEDING)
9342 (errcode(ERRCODE_WINDOWING_ERROR),
9343 errmsg("frame end cannot be UNBOUNDED PRECEDING"),
9344 scanner_errposition(@4)));
9345 /* shift converts START_ options to END_ options */
9346 $$ = FRAMEOPTION_BETWEEN | $2 | ($4 << 1);
9351 * This is used for both frame start and frame end, with output set up on
9352 * the assumption it's frame start; the frame_extent productions must reject
9358 $$ = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
9360 | UNBOUNDED FOLLOWING
9362 $$ = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
9366 $$ = FRAMEOPTION_START_CURRENT_ROW;
9372 * Supporting nonterminals for expressions.
9375 /* Explicit row production.
9377 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
9378 * without conflicting with the parenthesized a_expr production. Without the
9379 * ROW keyword, there must be more than one a_expr inside the parens.
9381 row: ROW '(' expr_list ')' { $$ = $3; }
9382 | ROW '(' ')' { $$ = NIL; }
9383 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
9386 sub_type: ANY { $$ = ANY_SUBLINK; }
9387 | SOME { $$ = ANY_SUBLINK; }
9388 | ALL { $$ = ALL_SUBLINK; }
9391 all_Op: Op { $$ = $1; }
9392 | MathOp { $$ = $1; }
9395 MathOp: '+' { $$ = "+"; }
9407 { $$ = list_make1(makeString($1)); }
9408 | OPERATOR '(' any_operator ')'
9414 { $$ = list_make1(makeString($1)); }
9415 | OPERATOR '(' any_operator ')'
9421 { $$ = list_make1(makeString($1)); }
9422 | OPERATOR '(' any_operator ')'
9425 { $$ = list_make1(makeString("~~")); }
9427 { $$ = list_make1(makeString("!~~")); }
9429 { $$ = list_make1(makeString("~~*")); }
9431 { $$ = list_make1(makeString("!~~*")); }
9432 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
9433 * the regular expression is preprocessed by a function (similar_escape),
9434 * and the ~ operator for posix regular expressions is used.
9435 * x SIMILAR TO y -> x ~ similar_escape(y)
9436 * this transformation is made on the fly by the parser upwards.
9437 * however the SubLink structure which handles any/some/all stuff
9438 * is not ready for such a thing.
9444 $$ = list_make1($1);
9446 | expr_list ',' a_expr
9448 $$ = lappend($1, $3);
9452 type_list: Typename { $$ = list_make1($1); }
9453 | type_list ',' Typename { $$ = lappend($1, $3); }
9456 array_expr: '[' expr_list ']'
9458 $$ = makeAArrayExpr($2, @1);
9460 | '[' array_expr_list ']'
9462 $$ = makeAArrayExpr($2, @1);
9466 $$ = makeAArrayExpr(NIL, @1);
9470 array_expr_list: array_expr { $$ = list_make1($1); }
9471 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
9476 extract_arg FROM a_expr
9478 $$ = list_make2(makeStringConst($1, @1), $3);
9480 | /*EMPTY*/ { $$ = NIL; }
9483 /* Allow delimited string Sconst in extract_arg as an SQL extension.
9484 * - thomas 2001-04-12
9488 | YEAR_P { $$ = "year"; }
9489 | MONTH_P { $$ = "month"; }
9490 | DAY_P { $$ = "day"; }
9491 | HOUR_P { $$ = "hour"; }
9492 | MINUTE_P { $$ = "minute"; }
9493 | SECOND_P { $$ = "second"; }
9494 | Sconst { $$ = $1; }
9497 /* OVERLAY() arguments
9498 * SQL99 defines the OVERLAY() function:
9499 * o overlay(text placing text from int for int)
9500 * o overlay(text placing text from int)
9503 a_expr overlay_placing substr_from substr_for
9505 $$ = list_make4($1, $2, $3, $4);
9507 | a_expr overlay_placing substr_from
9509 $$ = list_make3($1, $2, $3);
9518 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
9521 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
9522 | /*EMPTY*/ { $$ = NIL; }
9525 /* SUBSTRING() arguments
9526 * SQL9x defines a specific syntax for arguments to SUBSTRING():
9527 * o substring(text from int for int)
9528 * o substring(text from int) get entire string from starting point "int"
9529 * o substring(text for int) get first "int" characters of string
9530 * o substring(text from pattern) get entire string matching pattern
9531 * o substring(text from pattern for escape) same with specified escape char
9532 * We also want to support generic substring functions which accept
9533 * the usual generic list of arguments. So we will accept both styles
9534 * here, and convert the SQL9x style to the generic list for further
9535 * processing. - thomas 2000-11-28
9538 a_expr substr_from substr_for
9540 $$ = list_make3($1, $2, $3);
9542 | a_expr substr_for substr_from
9544 /* not legal per SQL99, but might as well allow it */
9545 $$ = list_make3($1, $3, $2);
9547 | a_expr substr_from
9549 $$ = list_make2($1, $2);
9554 * Since there are no cases where this syntax allows
9555 * a textual FOR value, we forcibly cast the argument
9556 * to int4. The possible matches in pg_proc are
9557 * substring(text,int4) and substring(text,text),
9558 * and we don't want the parser to choose the latter,
9559 * which it is likely to do if the second argument
9560 * is unknown or doesn't have an implicit cast to int4.
9562 $$ = list_make3($1, makeIntConst(1, -1),
9564 SystemTypeName("int4"), -1));
9575 FROM a_expr { $$ = $2; }
9578 substr_for: FOR a_expr { $$ = $2; }
9581 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
9582 | FROM expr_list { $$ = $2; }
9583 | expr_list { $$ = $1; }
9586 in_expr: select_with_parens
9588 SubLink *n = makeNode(SubLink);
9590 /* other fields will be filled later */
9593 | '(' expr_list ')' { $$ = (Node *)$2; }
9597 * Define SQL92-style case clause.
9598 * - Full specification
9599 * CASE WHEN a = b THEN c ... ELSE d END
9600 * - Implicit argument
9601 * CASE a WHEN b THEN c ... ELSE d END
9603 case_expr: CASE case_arg when_clause_list case_default END_P
9605 CaseExpr *c = makeNode(CaseExpr);
9606 c->casetype = InvalidOid; /* not analyzed yet */
9607 c->arg = (Expr *) $2;
9609 c->defresult = (Expr *) $4;
9616 /* There must be at least one */
9617 when_clause { $$ = list_make1($1); }
9618 | when_clause_list when_clause { $$ = lappend($1, $2); }
9622 WHEN a_expr THEN a_expr
9624 CaseWhen *w = makeNode(CaseWhen);
9625 w->expr = (Expr *) $2;
9626 w->result = (Expr *) $4;
9633 ELSE a_expr { $$ = $2; }
9634 | /*EMPTY*/ { $$ = NULL; }
9637 case_arg: a_expr { $$ = $1; }
9638 | /*EMPTY*/ { $$ = NULL; }
9642 * columnref starts with relation_name not ColId, so that OLD and NEW
9643 * references can be accepted. Note that when there are more than two
9644 * dotted names, the first name is not actually a relation name...
9646 columnref: relation_name
9648 $$ = makeColumnRef($1, NIL, @1);
9650 | relation_name indirection
9652 $$ = makeColumnRef($1, $2, @1);
9659 $$ = (Node *) makeString($2);
9663 $$ = (Node *) makeNode(A_Star);
9667 A_Indices *ai = makeNode(A_Indices);
9672 | '[' a_expr ':' a_expr ']'
9674 A_Indices *ai = makeNode(A_Indices);
9682 indirection_el { $$ = list_make1($1); }
9683 | indirection indirection_el { $$ = lappend($1, $2); }
9687 /*EMPTY*/ { $$ = NIL; }
9688 | opt_indirection indirection_el { $$ = lappend($1, $2); }
9691 opt_asymmetric: ASYMMETRIC
9696 * The SQL spec defines "contextually typed value expressions" and
9697 * "contextually typed row value constructors", which for our purposes
9698 * are the same as "a_expr" and "row" except that DEFAULT can appear at
9703 a_expr { $$ = (Node *) $1; }
9706 SetToDefault *n = makeNode(SetToDefault);
9713 ctext_expr { $$ = list_make1($1); }
9714 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
9718 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
9719 * making VALUES a fully reserved word, which will probably break more apps
9720 * than allowing the noise-word is worth.
9722 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
9726 /*****************************************************************************
9728 * target list for SELECT
9730 *****************************************************************************/
9733 target_el { $$ = list_make1($1); }
9734 | target_list ',' target_el { $$ = lappend($1, $3); }
9737 target_el: a_expr AS ColLabel
9739 $$ = makeNode(ResTarget);
9741 $$->indirection = NIL;
9742 $$->val = (Node *)$1;
9746 * We support omitting AS only for column labels that aren't
9747 * any known keyword. There is an ambiguity against postfix
9748 * operators: is "a ! b" an infix expression, or a postfix
9749 * expression and a column label? We prefer to resolve this
9750 * as an infix expression, which we accomplish by assigning
9751 * IDENT a precedence higher than POSTFIXOP.
9755 $$ = makeNode(ResTarget);
9757 $$->indirection = NIL;
9758 $$->val = (Node *)$1;
9763 $$ = makeNode(ResTarget);
9765 $$->indirection = NIL;
9766 $$->val = (Node *)$1;
9771 ColumnRef *n = makeNode(ColumnRef);
9772 n->fields = list_make1(makeNode(A_Star));
9775 $$ = makeNode(ResTarget);
9777 $$->indirection = NIL;
9778 $$->val = (Node *)n;
9784 /*****************************************************************************
9786 * Names and constants
9788 *****************************************************************************/
9791 SpecialRuleRelation { $$ = $1; }
9792 | ColId { $$ = $1; }
9795 qualified_name_list:
9796 qualified_name { $$ = list_make1($1); }
9797 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
9801 * The production for a qualified relation name has to exactly match the
9802 * production for a qualified func_name, because in a FROM clause we cannot
9803 * tell which we are parsing until we see what comes after it ('(' for a
9804 * func_name, something else for a relation). Therefore we allow 'indirection'
9805 * which may contain subscripts, and reject that case in the C code.
9810 $$ = makeNode(RangeVar);
9811 $$->catalogname = NULL;
9812 $$->schemaname = NULL;
9816 | relation_name indirection
9818 check_qualified_name($2);
9819 $$ = makeNode(RangeVar);
9820 switch (list_length($2))
9823 $$->catalogname = NULL;
9824 $$->schemaname = $1;
9825 $$->relname = strVal(linitial($2));
9828 $$->catalogname = $1;
9829 $$->schemaname = strVal(linitial($2));
9830 $$->relname = strVal(lsecond($2));
9834 (errcode(ERRCODE_SYNTAX_ERROR),
9835 errmsg("improper qualified name (too many dotted names): %s",
9836 NameListToString(lcons(makeString($1), $2))),
9837 scanner_errposition(@1)));
9845 { $$ = list_make1(makeString($1)); }
9846 | name_list ',' name
9847 { $$ = lappend($1, makeString($3)); }
9851 name: ColId { $$ = $1; };
9859 attr_name: ColLabel { $$ = $1; };
9861 index_name: ColId { $$ = $1; };
9863 file_name: Sconst { $$ = $1; };
9866 * The production for a qualified func_name has to exactly match the
9867 * production for a qualified columnref, because we cannot tell which we
9868 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
9869 * anything else for a columnref). Therefore we allow 'indirection' which
9870 * may contain subscripts, and reject that case in the C code. (If we
9871 * ever implement SQL99-like methods, such syntax may actually become legal!)
9873 func_name: type_function_name
9874 { $$ = list_make1(makeString($1)); }
9875 | relation_name indirection
9876 { $$ = check_func_name(lcons(makeString($1), $2)); }
9885 $$ = makeIntConst($1, @1);
9889 $$ = makeFloatConst($1, @1);
9893 $$ = makeStringConst($1, @1);
9897 $$ = makeBitStringConst($1, @1);
9901 /* This is a bit constant per SQL99:
9902 * Without Feature F511, "BIT data type",
9903 * a <general literal> shall not be a
9904 * <bit string literal> or a <hex string literal>.
9906 $$ = makeBitStringConst($1, @1);
9910 /* generic type 'literal' syntax */
9911 TypeName *t = makeTypeNameFromNameList($1);
9913 $$ = makeStringConstCast($2, @2, t);
9915 | func_name '(' expr_list ')' Sconst
9917 /* generic syntax with a type modifier */
9918 TypeName *t = makeTypeNameFromNameList($1);
9921 $$ = makeStringConstCast($5, @5, t);
9923 | ConstTypename Sconst
9925 $$ = makeStringConstCast($2, @2, $1);
9927 | ConstInterval Sconst opt_interval
9931 $$ = makeStringConstCast($2, @2, t);
9933 | ConstInterval '(' Iconst ')' Sconst opt_interval
9938 if (list_length($6) != 1)
9940 (errcode(ERRCODE_SYNTAX_ERROR),
9941 errmsg("interval precision specified twice"),
9942 scanner_errposition(@1)));
9943 t->typmods = lappend($6, makeIntConst($3, @3));
9946 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
9947 makeIntConst($3, @3));
9948 $$ = makeStringConstCast($5, @5, t);
9952 $$ = makeBoolAConst(TRUE, @1);
9956 $$ = makeBoolAConst(FALSE, @1);
9960 $$ = makeNullAConst(@1);
9964 Iconst: ICONST { $$ = $1; };
9965 Sconst: SCONST { $$ = $1; };
9966 RoleId: ColId { $$ = $1; };
9968 SignedIconst: Iconst { $$ = $1; }
9969 | '+' Iconst { $$ = + $2; }
9970 | '-' Iconst { $$ = - $2; }
9974 * Name classification hierarchy.
9976 * IDENT is the lexeme returned by the lexer for identifiers that match
9977 * no known keyword. In most cases, we can accept certain keywords as
9978 * names, not only IDENTs. We prefer to accept as many such keywords
9979 * as possible to minimize the impact of "reserved words" on programmers.
9980 * So, we divide names into several possible classes. The classification
9981 * is chosen in part to make keywords acceptable as names wherever possible.
9984 /* Column identifier --- names that can be column, table, etc names.
9986 ColId: IDENT { $$ = $1; }
9987 | unreserved_keyword { $$ = pstrdup($1); }
9988 | col_name_keyword { $$ = pstrdup($1); }
9991 /* Type/function identifier --- names that can be type or function names.
9993 type_function_name: IDENT { $$ = $1; }
9994 | unreserved_keyword { $$ = pstrdup($1); }
9995 | type_func_name_keyword { $$ = pstrdup($1); }
9998 /* Column label --- allowed labels in "AS" clauses.
9999 * This presently includes *all* Postgres keywords.
10001 ColLabel: IDENT { $$ = $1; }
10002 | unreserved_keyword { $$ = pstrdup($1); }
10003 | col_name_keyword { $$ = pstrdup($1); }
10004 | type_func_name_keyword { $$ = pstrdup($1); }
10005 | reserved_keyword { $$ = pstrdup($1); }
10010 * Keyword category lists. Generally, every keyword present in
10011 * the Postgres grammar should appear in exactly one of these lists.
10013 * Put a new keyword into the first list that it can go into without causing
10014 * shift or reduce conflicts. The earlier lists define "less reserved"
10015 * categories of keywords.
10017 * Make sure that each keyword's category in keywords.c matches where
10018 * it is listed here. (Someday we may be able to generate these lists and
10019 * keywords.c's table from a common master list.)
10022 /* "Unreserved" keywords --- available for use as any kind of name.
10024 unreserved_keyword:
10273 /* Column identifier --- keywords that can be column, table, etc names.
10275 * Many of these keywords will in fact be recognized as type or function
10276 * names too; but they have special productions for the purpose, and so
10277 * can't be treated as "generic" type or function names.
10279 * The type names appearing here are not usable as function names
10280 * because they can be followed by '(' in typename productions, which
10281 * looks too much like a function call for an LR(1) parser.
10331 /* Type/function identifier --- keywords that can be type or function names.
10333 * Most of these are keywords that are used as operators in expressions;
10334 * in general such keywords can't be column names because they would be
10335 * ambiguous with variables, but they are unambiguous as function identifiers.
10337 * Do not include POSITION, SUBSTRING, etc here since they have explicit
10338 * productions in a_expr to support the goofy SQL9x argument syntax.
10339 * - thomas 2000-11-28
10341 type_func_name_keyword:
10366 /* Reserved keyword --- these keywords are usable only as a ColLabel.
10368 * Keywords appear here if they could not be distinguished from variable,
10369 * type, or function names in some contexts. Don't put things here unless
10394 | CURRENT_TIMESTAMP
10455 SpecialRuleRelation:
10462 (errcode(ERRCODE_SYNTAX_ERROR),
10463 errmsg("OLD used in query that is not in a rule"),
10464 scanner_errposition(@1)));
10472 (errcode(ERRCODE_SYNTAX_ERROR),
10473 errmsg("NEW used in query that is not in a rule"),
10474 scanner_errposition(@1)));
10481 makeColumnRef(char *colname, List *indirection, int location)
10484 * Generate a ColumnRef node, with an A_Indirection node added if there
10485 * is any subscripting in the specified indirection list. However,
10486 * any field selection at the start of the indirection list must be
10487 * transposed into the "fields" part of the ColumnRef node.
10489 ColumnRef *c = makeNode(ColumnRef);
10493 c->location = location;
10494 foreach(l, indirection)
10496 if (IsA(lfirst(l), A_Indices))
10498 A_Indirection *i = makeNode(A_Indirection);
10502 /* easy case - all indirection goes to A_Indirection */
10503 c->fields = list_make1(makeString(colname));
10504 i->indirection = check_indirection(indirection);
10508 /* got to split the list in two */
10509 i->indirection = check_indirection(list_copy_tail(indirection,
10511 indirection = list_truncate(indirection, nfields);
10512 c->fields = lcons(makeString(colname), indirection);
10514 i->arg = (Node *) c;
10517 else if (IsA(lfirst(l), A_Star))
10519 /* We only allow '*' at the end of a ColumnRef */
10520 if (lnext(l) != NULL)
10521 yyerror("improper use of \"*\"");
10525 /* No subscripting, so all indirection gets added to field list */
10526 c->fields = lcons(makeString(colname), indirection);
10531 makeTypeCast(Node *arg, TypeName *typename, int location)
10533 TypeCast *n = makeNode(TypeCast);
10535 n->typename = typename;
10536 n->location = location;
10541 makeStringConst(char *str, int location)
10543 A_Const *n = makeNode(A_Const);
10545 n->val.type = T_String;
10546 n->val.val.str = str;
10547 n->location = location;
10553 makeStringConstCast(char *str, int location, TypeName *typename)
10555 Node *s = makeStringConst(str, location);
10557 return makeTypeCast(s, typename, -1);
10561 makeIntConst(int val, int location)
10563 A_Const *n = makeNode(A_Const);
10565 n->val.type = T_Integer;
10566 n->val.val.ival = val;
10567 n->location = location;
10573 makeFloatConst(char *str, int location)
10575 A_Const *n = makeNode(A_Const);
10577 n->val.type = T_Float;
10578 n->val.val.str = str;
10579 n->location = location;
10585 makeBitStringConst(char *str, int location)
10587 A_Const *n = makeNode(A_Const);
10589 n->val.type = T_BitString;
10590 n->val.val.str = str;
10591 n->location = location;
10597 makeNullAConst(int location)
10599 A_Const *n = makeNode(A_Const);
10601 n->val.type = T_Null;
10602 n->location = location;
10608 makeAConst(Value *v, int location)
10615 n = makeFloatConst(v->val.str, location);
10619 n = makeIntConst(v->val.ival, location);
10624 n = makeStringConst(v->val.str, location);
10631 /* makeBoolAConst()
10632 * Create an A_Const string node and put it inside a boolean cast.
10635 makeBoolAConst(bool state, int location)
10637 A_Const *n = makeNode(A_Const);
10639 n->val.type = T_String;
10640 n->val.val.str = (state ? "t" : "f");
10641 n->location = location;
10643 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
10647 * Create and populate a FuncCall node to support the OVERLAPS operator.
10650 makeOverlaps(List *largs, List *rargs, int location)
10652 FuncCall *n = makeNode(FuncCall);
10654 n->funcname = SystemFuncName("overlaps");
10655 if (list_length(largs) == 1)
10656 largs = lappend(largs, largs);
10657 else if (list_length(largs) != 2)
10659 (errcode(ERRCODE_SYNTAX_ERROR),
10660 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
10661 scanner_errposition(location)));
10662 if (list_length(rargs) == 1)
10663 rargs = lappend(rargs, rargs);
10664 else if (list_length(rargs) != 2)
10666 (errcode(ERRCODE_SYNTAX_ERROR),
10667 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
10668 scanner_errposition(location)));
10669 n->args = list_concat(largs, rargs);
10670 n->agg_star = FALSE;
10671 n->agg_distinct = FALSE;
10672 n->func_variadic = FALSE;
10674 n->location = location;
10678 /* check_qualified_name --- check the result of qualified_name production
10680 * It's easiest to let the grammar production for qualified_name allow
10681 * subscripts and '*', which we then must reject here.
10684 check_qualified_name(List *names)
10690 if (!IsA(lfirst(i), String))
10691 yyerror("syntax error");
10695 /* check_func_name --- check the result of func_name production
10697 * It's easiest to let the grammar production for func_name allow subscripts
10698 * and '*', which we then must reject here.
10701 check_func_name(List *names)
10707 if (!IsA(lfirst(i), String))
10708 yyerror("syntax error");
10713 /* check_indirection --- check the result of indirection production
10715 * We only allow '*' at the end of the list, but it's hard to enforce that
10716 * in the grammar, so do it here.
10719 check_indirection(List *indirection)
10723 foreach(l, indirection)
10725 if (IsA(lfirst(l), A_Star))
10727 if (lnext(l) != NULL)
10728 yyerror("improper use of \"*\"");
10731 return indirection;
10734 /* extractArgTypes()
10735 * Given a list of FunctionParameter nodes, extract a list of just the
10736 * argument types (TypeNames) for input parameters only. This is what
10737 * is needed to look up an existing function, which is what is wanted by
10738 * the productions that use this call.
10741 extractArgTypes(List *parameters)
10743 List *result = NIL;
10746 foreach(i, parameters)
10748 FunctionParameter *p = (FunctionParameter *) lfirst(i);
10750 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
10751 result = lappend(result, p->argType);
10756 /* findLeftmostSelect()
10757 * Find the leftmost component SelectStmt in a set-operation parsetree.
10759 static SelectStmt *
10760 findLeftmostSelect(SelectStmt *node)
10762 while (node && node->op != SETOP_NONE)
10764 Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
10768 /* insertSelectOptions()
10769 * Insert ORDER BY, etc into an already-constructed SelectStmt.
10771 * This routine is just to avoid duplicating code in SelectStmt productions.
10774 insertSelectOptions(SelectStmt *stmt,
10775 List *sortClause, List *lockingClause,
10776 Node *limitOffset, Node *limitCount,
10777 WithClause *withClause)
10779 Assert(IsA(stmt, SelectStmt));
10782 * Tests here are to reject constructs like
10783 * (SELECT foo ORDER BY bar) ORDER BY baz
10787 if (stmt->sortClause)
10789 (errcode(ERRCODE_SYNTAX_ERROR),
10790 errmsg("multiple ORDER BY clauses not allowed"),
10791 scanner_errposition(exprLocation((Node *) sortClause))));
10792 stmt->sortClause = sortClause;
10794 /* We can handle multiple locking clauses, though */
10795 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
10798 if (stmt->limitOffset)
10800 (errcode(ERRCODE_SYNTAX_ERROR),
10801 errmsg("multiple OFFSET clauses not allowed"),
10802 scanner_errposition(exprLocation(limitOffset))));
10803 stmt->limitOffset = limitOffset;
10807 if (stmt->limitCount)
10809 (errcode(ERRCODE_SYNTAX_ERROR),
10810 errmsg("multiple LIMIT clauses not allowed"),
10811 scanner_errposition(exprLocation(limitCount))));
10812 stmt->limitCount = limitCount;
10816 if (stmt->withClause)
10818 (errcode(ERRCODE_SYNTAX_ERROR),
10819 errmsg("multiple WITH clauses not allowed"),
10820 scanner_errposition(exprLocation((Node *) withClause))));
10821 stmt->withClause = withClause;
10826 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
10828 SelectStmt *n = makeNode(SelectStmt);
10832 n->larg = (SelectStmt *) larg;
10833 n->rarg = (SelectStmt *) rarg;
10837 /* SystemFuncName()
10838 * Build a properly-qualified reference to a built-in function.
10841 SystemFuncName(char *name)
10843 return list_make2(makeString("pg_catalog"), makeString(name));
10846 /* SystemTypeName()
10847 * Build a properly-qualified reference to a built-in type.
10849 * typmod is defaulted, but may be changed afterwards by caller.
10850 * Likewise for the location.
10853 SystemTypeName(char *name)
10855 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
10856 makeString(name)));
10860 * Handle negation of a numeric constant.
10862 * Formerly, we did this here because the optimizer couldn't cope with
10863 * indexquals that looked like "var = -4" --- it wants "var = const"
10864 * and a unary minus operator applied to a constant didn't qualify.
10865 * As of Postgres 7.0, that problem doesn't exist anymore because there
10866 * is a constant-subexpression simplifier in the optimizer. However,
10867 * there's still a good reason for doing this here, which is that we can
10868 * postpone committing to a particular internal representation for simple
10869 * negative constants. It's better to leave "-123.456" in string form
10870 * until we know what the desired type is.
10873 doNegate(Node *n, int location)
10875 if (IsA(n, A_Const))
10877 A_Const *con = (A_Const *)n;
10879 /* report the constant's location as that of the '-' sign */
10880 con->location = location;
10882 if (con->val.type == T_Integer)
10884 con->val.val.ival = -con->val.val.ival;
10887 if (con->val.type == T_Float)
10889 doNegateFloat(&con->val);
10894 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
10898 doNegateFloat(Value *v)
10900 char *oldval = v->val.str;
10902 Assert(IsA(v, Float));
10903 if (*oldval == '+')
10905 if (*oldval == '-')
10906 v->val.str = oldval+1; /* just strip the '-' */
10909 char *newval = (char *) palloc(strlen(oldval) + 2);
10912 strcpy(newval+1, oldval);
10913 v->val.str = newval;
10918 makeAArrayExpr(List *elements, int location)
10920 A_ArrayExpr *n = makeNode(A_ArrayExpr);
10922 n->elements = elements;
10923 n->location = location;
10928 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
10931 XmlExpr *x = makeNode(XmlExpr);
10936 * named_args is a list of ResTarget; it'll be split apart into separate
10937 * expression and name lists in transformXmlExpr().
10939 x->named_args = named_args;
10940 x->arg_names = NIL;
10942 /* xmloption, if relevant, must be filled in by caller */
10943 /* type and typmod will be filled in during parse analysis */
10944 x->location = location;
10949 * Initialize to parse one query string
10954 QueryIsRule = FALSE;
10958 * Merge the input and output parameters of a table function.
10961 mergeTableFuncParameters(List *func_args, List *columns)
10965 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
10966 foreach(lc, func_args)
10968 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
10970 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
10972 (errcode(ERRCODE_SYNTAX_ERROR),
10973 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
10976 return list_concat(func_args, columns);
10980 * Determine return type of a TABLE function. A single result column
10981 * returns setof that column's type; otherwise return setof record.
10984 TableFuncTypeName(List *columns)
10988 if (list_length(columns) == 1)
10990 FunctionParameter *p = (FunctionParameter *) linitial(columns);
10992 result = (TypeName *) copyObject(p->argType);
10995 result = SystemTypeName("record");
10997 result->setof = true;
11003 * Must undefine base_yylex before including scan.c, since we want it
11004 * to create the function base_yylex not filtered_base_yylex.