4 /*-------------------------------------------------------------------------
7 * POSTGRESQL BISON 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.678 2009/09/21 20:10:21 tgl 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 "catalog/pg_trigger.h"
57 #include "commands/defrem.h"
58 #include "nodes/makefuncs.h"
59 #include "nodes/nodeFuncs.h"
60 #include "parser/gramparse.h"
61 #include "parser/parser.h"
62 #include "storage/lmgr.h"
63 #include "utils/date.h"
64 #include "utils/datetime.h"
65 #include "utils/numeric.h"
66 #include "utils/xml.h"
69 /* Location tracking support --- simpler than bison's default */
70 #define YYLLOC_DEFAULT(Current, Rhs, N) \
73 (Current) = (Rhs)[1]; \
75 (Current) = (Rhs)[0]; \
79 * The %name-prefix option below will make bison call base_yylex, but we
80 * really want it to call filtered_base_yylex (see parser.c).
82 #define base_yylex filtered_base_yylex
85 * Bison doesn't allocate anything that needs to live across parser calls,
86 * so we can easily have it use palloc instead of malloc. This prevents
87 * memory leaks if we error out during parsing. Note this only works with
88 * bison >= 2.0. However, in bison 1.875 the default is to use alloca()
89 * if possible, so there's not really much problem anyhow, at least if
90 * you're building with gcc.
92 #define YYMALLOC palloc
95 /* Private struct for the result of privilege_target production */
96 typedef struct PrivTarget
98 GrantObjectType objtype;
103 #define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
104 #define parser_errposition(pos) scanner_errposition(pos, yyscanner)
106 static void base_yyerror(YYLTYPE *yylloc, base_yyscan_t yyscanner,
108 static Node *makeColumnRef(char *colname, List *indirection,
109 int location, base_yyscan_t yyscanner);
110 static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
111 static Node *makeStringConst(char *str, int location);
112 static Node *makeStringConstCast(char *str, int location, TypeName *typename);
113 static Node *makeIntConst(int val, int location);
114 static Node *makeFloatConst(char *str, int location);
115 static Node *makeBitStringConst(char *str, int location);
116 static Node *makeNullAConst(int location);
117 static Node *makeAConst(Value *v, int location);
118 static Node *makeBoolAConst(bool state, int location);
119 static FuncCall *makeOverlaps(List *largs, List *rargs,
120 int location, base_yyscan_t yyscanner);
121 static void check_qualified_name(List *names, base_yyscan_t yyscanner);
122 static List *check_func_name(List *names, base_yyscan_t yyscanner);
123 static List *check_indirection(List *indirection, base_yyscan_t yyscanner);
124 static List *extractArgTypes(List *parameters);
125 static SelectStmt *findLeftmostSelect(SelectStmt *node);
126 static void insertSelectOptions(SelectStmt *stmt,
127 List *sortClause, List *lockingClause,
128 Node *limitOffset, Node *limitCount,
129 WithClause *withClause,
130 base_yyscan_t yyscanner);
131 static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
132 static Node *doNegate(Node *n, int location);
133 static void doNegateFloat(Value *v);
134 static Node *makeAArrayExpr(List *elements, int location);
135 static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
136 List *args, int location);
137 static List *mergeTableFuncParameters(List *func_args, List *columns);
138 static TypeName *TableFuncTypeName(List *columns);
144 %name-prefix="base_yy"
147 %parse-param {base_yyscan_t yyscanner}
148 %lex-param {base_yyscan_t yyscanner}
158 DropBehavior dbehavior;
159 OnCommitAction oncommit;
166 FunctionParameter *fun_param;
167 FunctionParameterMode fun_param_mode;
168 FuncWithArgs *funwithargs;
180 struct PrivTarget *privtarget;
181 AccessPriv *accesspriv;
184 VariableSetStmt *vsetstmt;
187 %type <node> stmt schema_stmt
188 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterFdwStmt
189 AlterForeignServerStmt AlterGroupStmt
190 AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterTableStmt
191 AlterUserStmt AlterUserMappingStmt AlterUserSetStmt AlterRoleStmt AlterRoleSetStmt
192 AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
193 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
194 CreateDomainStmt CreateGroupStmt CreateOpClassStmt
195 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
196 CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
197 CreateFdwStmt CreateForeignServerStmt CreateAssertStmt CreateTrigStmt
198 CreateUserStmt CreateUserMappingStmt CreateRoleStmt
199 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt
200 DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
201 DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
202 DropUserStmt DropdbStmt DropTableSpaceStmt DropFdwStmt
203 DropForeignServerStmt DropUserMappingStmt ExplainStmt FetchStmt
204 GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
205 LockStmt NotifyStmt ExplainableStmt PreparableStmt
206 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
207 RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
208 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
209 SelectStmt TransactionStmt TruncateStmt
210 UnlistenStmt UpdateStmt VacuumStmt
211 VariableResetStmt VariableSetStmt VariableShowStmt
212 ViewStmt CheckPointStmt CreateConversionStmt
213 DeallocateStmt PrepareStmt ExecuteStmt
214 DropOwnedStmt ReassignOwnedStmt
215 AlterTSConfigurationStmt AlterTSDictionaryStmt
217 %type <node> select_no_parens select_with_parens select_clause
218 simple_select values_clause
220 %type <node> alter_column_default opclass_item opclass_drop alter_using
221 %type <ival> add_drop opt_asc_desc opt_nulls_order
223 %type <node> alter_table_cmd
224 %type <list> alter_table_cmds
226 %type <dbehavior> opt_drop_behavior
228 %type <list> createdb_opt_list alterdb_opt_list copy_opt_list
229 transaction_mode_list
230 %type <defelt> createdb_opt_item alterdb_opt_item copy_opt_item
231 transaction_mode_item
233 %type <ival> opt_lock lock_type cast_context
234 %type <boolean> opt_force opt_or_replace
235 opt_grant_grant_option opt_grant_admin_option
236 opt_nowait opt_if_exists opt_with_data
238 %type <list> OptRoleList
239 %type <defelt> OptRoleElem
242 %type <str> foreign_server_version opt_foreign_server_version
243 %type <str> auth_ident
245 %type <str> OptSchemaName
246 %type <list> OptSchemaEltList
248 %type <boolean> TriggerActionTime TriggerForSpec opt_trusted opt_restart_seqs
249 %type <str> opt_lancompiler
251 %type <ival> TriggerEvents TriggerOneEvent
252 %type <value> TriggerFuncArg
254 %type <str> relation_name copy_file_name
255 database_name access_method_clause access_method attr_name
256 index_name name file_name cluster_index_specification
258 %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
259 opt_class opt_validator validator_clause
261 %type <range> qualified_name OptConstrFromTable
263 %type <str> all_Op MathOp SpecialRuleRelation
265 %type <str> iso_level opt_encoding
267 %type <list> grantee_list
268 %type <accesspriv> privilege
269 %type <list> privileges privilege_list
270 %type <privtarget> privilege_target
271 %type <funwithargs> function_with_argtypes
272 %type <list> function_with_argtypes_list
274 %type <list> stmtblock stmtmulti
275 OptTableElementList TableElementList OptInherit definition
276 reloptions opt_reloptions
277 OptWith opt_distinct opt_definition func_args func_args_list
278 func_args_with_defaults func_args_with_defaults_list
279 func_as createfunc_opt_list alterfunc_opt_list
280 aggr_args old_aggr_definition old_aggr_list
281 oper_argtypes RuleActionList RuleActionMulti
282 opt_column_list columnList opt_name_list
283 sort_clause opt_sort_clause sortby_list index_params
284 name_list from_clause from_list opt_array_bounds
285 qualified_name_list any_name any_name_list
286 any_operator expr_list attrs
287 target_list insert_column_list set_target_list
288 set_clause_list set_clause multiple_set_clause
289 ctext_expr_list ctext_row def_list indirection opt_indirection
290 reloption_list group_clause TriggerFuncArgs select_limit
291 opt_select_limit opclass_item_list opclass_drop_list
292 opt_opfamily transaction_mode_list_or_empty
293 TableFuncElementList opt_type_modifiers
295 execute_param_clause using_clause returning_clause
296 enum_val_list table_func_column_list
297 create_generic_options alter_generic_options
300 %type <range> OptTempTableName
301 %type <into> into_clause create_as_target
303 %type <defelt> createfunc_opt_item common_func_opt_item
304 %type <fun_param> func_arg func_arg_with_default table_func_column
305 %type <fun_param_mode> arg_class
306 %type <typnam> func_return func_type
308 %type <boolean> TriggerForType OptTemp
309 %type <oncommit> OnCommitOption
311 %type <node> for_locking_item
312 %type <list> for_locking_clause opt_for_locking_clause for_locking_items
313 %type <list> locked_rels_list
314 %type <boolean> opt_all
316 %type <node> join_outer join_qual
317 %type <jtype> join_type
319 %type <list> extract_list overlay_list position_list
320 %type <list> substr_list trim_list
321 %type <list> opt_interval interval_second
322 %type <node> overlay_placing substr_from substr_for
324 %type <boolean> opt_instead
325 %type <boolean> index_opt_unique opt_verbose opt_full
326 %type <boolean> opt_freeze opt_default opt_recheck
327 %type <defelt> opt_binary opt_oids copy_delimiter
329 %type <boolean> copy_from
331 %type <ival> opt_column event cursor_options opt_hold opt_set_data
332 %type <objtype> reindex_type drop_type comment_type
334 %type <node> fetch_direction limit_clause select_limit_value
335 offset_clause select_offset_value
336 select_offset_value2 opt_select_fetch_first_value
337 %type <ival> row_or_rows first_or_next
339 %type <list> OptSeqOptList SeqOptList
340 %type <defelt> SeqOptElem
342 %type <istmt> insert_rest
344 %type <vsetstmt> set_rest SetResetClause
346 %type <node> TableElement ConstraintElem TableFuncElement
347 %type <node> columnDef
348 %type <defelt> def_elem reloption_elem old_aggr_elem
349 %type <node> def_arg columnElem where_clause where_or_current_clause
350 a_expr b_expr c_expr func_expr AexprConst indirection_el
351 columnref in_expr having_clause func_table array_expr
352 %type <list> row type_list array_expr_list
353 %type <node> case_expr case_arg when_clause case_default
354 %type <list> when_clause_list
355 %type <ival> sub_type
356 %type <list> OptCreateAs CreateAsList
357 %type <node> CreateAsElement ctext_expr
358 %type <value> NumericOnly
359 %type <alias> alias_clause
360 %type <sortby> sortby
361 %type <ielem> index_elem
362 %type <node> table_ref
363 %type <jexpr> joined_table
364 %type <range> relation_expr
365 %type <range> relation_expr_opt_alias
366 %type <target> target_el single_set_clause set_target insert_column_item
368 %type <str> generic_option_name
369 %type <node> generic_option_arg
370 %type <defelt> generic_option_elem alter_generic_option_elem
371 %type <list> generic_option_list alter_generic_option_list
372 %type <str> explain_option_name
373 %type <node> explain_option_arg
374 %type <defelt> explain_option_elem
375 %type <list> explain_option_list
376 %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
377 %type <defelt> copy_generic_opt_elem
378 %type <list> copy_generic_opt_list copy_generic_opt_arg_list
379 %type <list> copy_options
381 %type <typnam> Typename SimpleTypename ConstTypename
382 GenericType Numeric opt_float
383 Character ConstCharacter
384 CharacterWithLength CharacterWithoutLength
385 ConstDatetime ConstInterval
386 Bit ConstBit BitWithLength BitWithoutLength
387 %type <str> character
388 %type <str> extract_arg
389 %type <str> opt_charset
390 %type <boolean> opt_varying opt_timezone
392 %type <ival> Iconst SignedIconst
393 %type <str> Sconst comment_text
394 %type <str> RoleId opt_granted_by opt_boolean ColId_or_Sconst
395 %type <list> var_list
396 %type <str> ColId ColLabel var_name type_function_name param_name
397 %type <node> var_value zone_value
399 %type <keyword> unreserved_keyword type_func_name_keyword
400 %type <keyword> col_name_keyword reserved_keyword
402 %type <node> TableConstraint TableLikeClause
403 %type <list> TableLikeOptionList
404 %type <ival> TableLikeOption
405 %type <list> ColQualList
406 %type <node> ColConstraint ColConstraintElem ConstraintAttr
407 %type <ival> key_actions key_delete key_match key_update key_action
408 %type <ival> ConstraintAttributeSpec ConstraintDeferrabilitySpec
411 %type <list> constraints_set_list
412 %type <boolean> constraints_set_mode
413 %type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
414 %type <list> opt_check_option
416 %type <target> xml_attribute_el
417 %type <list> xml_attribute_list xml_attributes
418 %type <node> xml_root_version opt_xml_root_standalone
419 %type <ival> document_or_content
420 %type <boolean> xml_whitespace_option
422 %type <node> common_table_expr
423 %type <with> with_clause
424 %type <list> cte_list
426 %type <list> window_clause window_definition_list opt_partition_clause
427 %type <windef> window_definition over_clause window_specification
428 %type <str> opt_existing_window_name
429 %type <ival> opt_frame_clause frame_extent frame_bound
433 * Non-keyword token types. These are hard-wired into the "flex" lexer.
434 * They must be listed first so that their numeric codes do not depend on
435 * the set of keywords. PL/pgsql depends on this so that it can share the
436 * same lexer. If you add/change tokens here, fix PL/pgsql to match!
438 * DOT_DOT and COLON_EQUALS are unused in the core SQL grammar, and so will
439 * always provoke parse errors. They are needed by PL/pgsql.
441 %token <str> IDENT FCONST SCONST BCONST XCONST Op
442 %token <ival> ICONST PARAM
443 %token TYPECAST DOT_DOT COLON_EQUALS
446 * If you want to make any keyword changes, update the keyword table in
447 * src/include/parser/kwlist.h and add new keywords to the appropriate one
448 * of the reserved-or-not-so-reserved keyword lists, below; search
449 * this file for "Keyword category lists".
452 /* ordinary key words in alphabetical order */
453 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
454 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
455 ASSERTION ASSIGNMENT ASYMMETRIC AT AUTHORIZATION
457 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
460 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
461 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
462 CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT
463 COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
464 CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
465 CREATEROLE CREATEUSER CROSS CSV CURRENT_P
466 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
467 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
469 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
470 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
471 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
473 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT
474 EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
476 FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOLLOWING FOR FORCE FOREIGN FORWARD
477 FREEZE FROM FULL FUNCTION
479 GLOBAL GRANT GRANTED GREATEST GROUP_P
481 HANDLER HAVING HEADER_P HOLD HOUR_P
483 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
484 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY
485 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
486 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
492 LANCOMPILER LANGUAGE LARGE_P LAST_P LC_COLLATE_P LC_CTYPE_P LEADING
493 LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP
494 LOCATION LOCK_P LOGIN_P
496 MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
498 NAME_P NAMES NATIONAL NATURAL NCHAR NEW NEXT NO NOCREATEDB
499 NOCREATEROLE NOCREATEUSER NOINHERIT NOLOGIN_P NONE NOSUPERUSER
500 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NULLS_P NUMERIC
502 OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OPTIONS OR
503 ORDER OUT_P OUTER_P OVER OVERLAPS OVERLAY OWNED OWNER
505 PARSER PARTIAL PARTITION PASSWORD PLACING PLANS POSITION
506 PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
507 PRIOR PRIVILEGES PROCEDURAL PROCEDURE
511 RANGE READ REAL REASSIGN RECHECK RECURSIVE REFERENCES REINDEX
512 RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA RESET RESTART
513 RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROW ROWS RULE
515 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE
516 SERIALIZABLE SERVER SESSION SESSION_USER SET SETOF SHARE
517 SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT
518 STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING SUPERUSER_P
519 SYMMETRIC SYSID SYSTEM_P
521 TABLE TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
522 TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
523 TRUNCATE TRUSTED TYPE_P
525 UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
528 VACUUM VALID VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
529 VERBOSE VERSION_P VIEW VOLATILE
531 WHEN WHERE WHITESPACE_P WINDOW WITH WITHOUT WORK WRAPPER WRITE
533 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLFOREST XMLPARSE
534 XMLPI XMLROOT XMLSERIALIZE
541 * The grammar thinks these are keywords, but they are not in the kwlist.h
542 * list and so can never be entered directly. The filter in parser.c
543 * creates these tokens when required.
545 %token NULLS_FIRST NULLS_LAST WITH_TIME
548 /* Precedence: lowest to highest */
549 %nonassoc SET /* see relation_expr_opt_alias */
557 %nonassoc LIKE ILIKE SIMILAR
562 %left POSTFIXOP /* dummy for postfix Op rules */
564 * To support target_el without AS, we must give IDENT an explicit priority
565 * between POSTFIXOP and Op. We can safely assign the same priority to
566 * various unreserved keywords as needed to resolve ambiguities (this can't
567 * have any bad effects since obviously the keywords will still behave the
568 * same as if they weren't keywords). We need to do this for PARTITION,
569 * RANGE, ROWS to support opt_existing_window_name; and for RANGE, ROWS
570 * so that they can follow a_expr without creating
571 * postfix-operator problems.
573 %nonassoc IDENT PARTITION RANGE ROWS
574 %left Op OPERATOR /* multi-character ops and user-defined operators */
577 %nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN /* sets precedence for IS NULL, etc */
581 /* Unary Operators */
582 %left AT ZONE /* sets precedence for AT TIME ZONE */
589 * These might seem to be low-precedence, but actually they are not part
590 * of the arithmetic hierarchy at all in their use as JOIN operators.
591 * We make them high-precedence to support their use as function names.
592 * They wouldn't be given a precedence at all, were it not that we need
593 * left-associativity among the JOIN rules themselves.
595 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
596 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
597 %right PRESERVE STRIP_P
601 * The target production for the whole parse.
605 pg_yyget_extra(yyscanner)->parsetree = $1;
609 /* the thrashing around here is to discard "empty" statements... */
610 stmtmulti: stmtmulti ';' stmt
613 $$ = lappend($1, $3);
628 | AlterDatabaseSetStmt
631 | AlterForeignServerStmt
634 | AlterObjectSchemaStmt
640 | AlterTSConfigurationStmt
641 | AlterTSDictionaryStmt
642 | AlterUserMappingStmt
655 | CreateConversionStmt
658 | CreateForeignServerStmt
668 | CreateTableSpaceStmt
672 | CreateUserMappingStmt
682 | DropForeignServerStmt
694 | DropUserMappingStmt
731 /*****************************************************************************
733 * Create a new Postgres DBMS role
735 *****************************************************************************/
738 CREATE ROLE RoleId opt_with OptRoleList
740 CreateRoleStmt *n = makeNode(CreateRoleStmt);
741 n->stmt_type = ROLESTMT_ROLE;
754 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
755 * for backwards compatibility). Note: the only option required by SQL99
756 * is "WITH ADMIN name".
759 OptRoleList OptRoleElem { $$ = lappend($1, $2); }
760 | /* EMPTY */ { $$ = NIL; }
766 $$ = makeDefElem("password",
767 (Node *)makeString($2));
771 $$ = makeDefElem("password", NULL);
773 | ENCRYPTED PASSWORD Sconst
775 $$ = makeDefElem("encryptedPassword",
776 (Node *)makeString($3));
778 | UNENCRYPTED PASSWORD Sconst
780 $$ = makeDefElem("unencryptedPassword",
781 (Node *)makeString($3));
785 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
789 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
793 $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE));
797 $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE));
801 $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
805 $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
809 $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE));
813 $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE));
817 /* For backwards compatibility, synonym for SUPERUSER */
818 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
822 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
826 $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE));
830 $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE));
832 | CONNECTION LIMIT SignedIconst
834 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3));
838 $$ = makeDefElem("validUntil", (Node *)makeString($3));
840 /* Supported but not documented for roles, for use by ALTER GROUP. */
843 $$ = makeDefElem("rolemembers", (Node *)$2);
845 /* The following are not supported by ALTER ROLE/USER/GROUP */
848 $$ = makeDefElem("sysid", (Node *)makeInteger($2));
852 $$ = makeDefElem("adminmembers", (Node *)$2);
856 $$ = makeDefElem("rolemembers", (Node *)$2);
858 | IN_P ROLE name_list
860 $$ = makeDefElem("addroleto", (Node *)$3);
862 | IN_P GROUP_P name_list
864 $$ = makeDefElem("addroleto", (Node *)$3);
869 /*****************************************************************************
871 * Create a new Postgres DBMS user (role with implied login ability)
873 *****************************************************************************/
876 CREATE USER RoleId opt_with OptRoleList
878 CreateRoleStmt *n = makeNode(CreateRoleStmt);
879 n->stmt_type = ROLESTMT_USER;
887 /*****************************************************************************
889 * Alter a postgresql DBMS role
891 *****************************************************************************/
894 ALTER ROLE RoleId opt_with OptRoleList
896 AlterRoleStmt *n = makeNode(AlterRoleStmt);
898 n->action = +1; /* add, if there are members */
905 ALTER ROLE RoleId SetResetClause
907 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
915 /*****************************************************************************
917 * Alter a postgresql DBMS user
919 *****************************************************************************/
922 ALTER USER RoleId opt_with OptRoleList
924 AlterRoleStmt *n = makeNode(AlterRoleStmt);
926 n->action = +1; /* add, if there are members */
934 ALTER USER RoleId SetResetClause
936 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
944 /*****************************************************************************
946 * Drop a postgresql DBMS role
948 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
949 * might own objects in multiple databases, there is presently no way to
950 * implement either cascading or restricting. Caveat DBA.
951 *****************************************************************************/
956 DropRoleStmt *n = makeNode(DropRoleStmt);
957 n->missing_ok = FALSE;
961 | DROP ROLE IF_P EXISTS name_list
963 DropRoleStmt *n = makeNode(DropRoleStmt);
964 n->missing_ok = TRUE;
970 /*****************************************************************************
972 * Drop a postgresql DBMS user
974 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
975 * might own objects in multiple databases, there is presently no way to
976 * implement either cascading or restricting. Caveat DBA.
977 *****************************************************************************/
982 DropRoleStmt *n = makeNode(DropRoleStmt);
983 n->missing_ok = FALSE;
987 | DROP USER IF_P EXISTS name_list
989 DropRoleStmt *n = makeNode(DropRoleStmt);
991 n->missing_ok = TRUE;
997 /*****************************************************************************
999 * Create a postgresql group (role without login ability)
1001 *****************************************************************************/
1004 CREATE GROUP_P RoleId opt_with OptRoleList
1006 CreateRoleStmt *n = makeNode(CreateRoleStmt);
1007 n->stmt_type = ROLESTMT_GROUP;
1015 /*****************************************************************************
1017 * Alter a postgresql group
1019 *****************************************************************************/
1022 ALTER GROUP_P RoleId add_drop USER name_list
1024 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1027 n->options = list_make1(makeDefElem("rolemembers",
1033 add_drop: ADD_P { $$ = +1; }
1038 /*****************************************************************************
1040 * Drop a postgresql group
1042 * XXX see above notes about cascading DROP USER; groups have same problem.
1043 *****************************************************************************/
1046 DROP GROUP_P name_list
1048 DropRoleStmt *n = makeNode(DropRoleStmt);
1049 n->missing_ok = FALSE;
1053 | DROP GROUP_P IF_P EXISTS name_list
1055 DropRoleStmt *n = makeNode(DropRoleStmt);
1056 n->missing_ok = TRUE;
1063 /*****************************************************************************
1065 * Manipulate a schema
1067 *****************************************************************************/
1070 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
1072 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1073 /* One can omit the schema name or the authorization id. */
1082 | CREATE SCHEMA ColId OptSchemaEltList
1084 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1085 /* ...but not both */
1095 | /* EMPTY */ { $$ = NULL; }
1099 OptSchemaEltList schema_stmt { $$ = lappend($1, $2); }
1100 | /* EMPTY */ { $$ = NIL; }
1104 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1105 * statement (in addition to by themselves).
1117 /*****************************************************************************
1119 * Set PG internal variable
1120 * SET name TO 'var_value'
1121 * Include SQL92 syntax (thomas 1997-10-22):
1122 * SET TIME ZONE 'var_value'
1124 *****************************************************************************/
1129 VariableSetStmt *n = $2;
1130 n->is_local = false;
1133 | SET LOCAL set_rest
1135 VariableSetStmt *n = $3;
1139 | SET SESSION set_rest
1141 VariableSetStmt *n = $3;
1142 n->is_local = false;
1147 set_rest: /* Generic SET syntaxes: */
1148 var_name TO var_list
1150 VariableSetStmt *n = makeNode(VariableSetStmt);
1151 n->kind = VAR_SET_VALUE;
1156 | var_name '=' var_list
1158 VariableSetStmt *n = makeNode(VariableSetStmt);
1159 n->kind = VAR_SET_VALUE;
1164 | var_name TO DEFAULT
1166 VariableSetStmt *n = makeNode(VariableSetStmt);
1167 n->kind = VAR_SET_DEFAULT;
1171 | var_name '=' DEFAULT
1173 VariableSetStmt *n = makeNode(VariableSetStmt);
1174 n->kind = VAR_SET_DEFAULT;
1178 | var_name FROM CURRENT_P
1180 VariableSetStmt *n = makeNode(VariableSetStmt);
1181 n->kind = VAR_SET_CURRENT;
1185 /* Special syntaxes mandated by SQL standard: */
1186 | TIME ZONE zone_value
1188 VariableSetStmt *n = makeNode(VariableSetStmt);
1189 n->kind = VAR_SET_VALUE;
1190 n->name = "timezone";
1192 n->args = list_make1($3);
1194 n->kind = VAR_SET_DEFAULT;
1197 | TRANSACTION transaction_mode_list
1199 VariableSetStmt *n = makeNode(VariableSetStmt);
1200 n->kind = VAR_SET_MULTI;
1201 n->name = "TRANSACTION";
1205 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1207 VariableSetStmt *n = makeNode(VariableSetStmt);
1208 n->kind = VAR_SET_MULTI;
1209 n->name = "SESSION CHARACTERISTICS";
1216 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1217 errmsg("current database cannot be changed"),
1218 parser_errposition(@2)));
1219 $$ = NULL; /*not reached*/
1223 VariableSetStmt *n = makeNode(VariableSetStmt);
1224 n->kind = VAR_SET_VALUE;
1225 n->name = "search_path";
1226 n->args = list_make1(makeStringConst($2, @2));
1229 | NAMES opt_encoding
1231 VariableSetStmt *n = makeNode(VariableSetStmt);
1232 n->kind = VAR_SET_VALUE;
1233 n->name = "client_encoding";
1235 n->args = list_make1(makeStringConst($2, @2));
1237 n->kind = VAR_SET_DEFAULT;
1240 | ROLE ColId_or_Sconst
1242 VariableSetStmt *n = makeNode(VariableSetStmt);
1243 n->kind = VAR_SET_VALUE;
1245 n->args = list_make1(makeStringConst($2, @2));
1248 | SESSION AUTHORIZATION ColId_or_Sconst
1250 VariableSetStmt *n = makeNode(VariableSetStmt);
1251 n->kind = VAR_SET_VALUE;
1252 n->name = "session_authorization";
1253 n->args = list_make1(makeStringConst($3, @3));
1256 | SESSION AUTHORIZATION DEFAULT
1258 VariableSetStmt *n = makeNode(VariableSetStmt);
1259 n->kind = VAR_SET_DEFAULT;
1260 n->name = "session_authorization";
1263 | XML_P OPTION document_or_content
1265 VariableSetStmt *n = makeNode(VariableSetStmt);
1266 n->kind = VAR_SET_VALUE;
1267 n->name = "xmloption";
1268 n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1273 var_name: ColId { $$ = $1; }
1274 | var_name '.' ColId
1276 $$ = palloc(strlen($1) + strlen($3) + 2);
1277 sprintf($$, "%s.%s", $1, $3);
1281 var_list: var_value { $$ = list_make1($1); }
1282 | var_list ',' var_value { $$ = lappend($1, $3); }
1285 var_value: opt_boolean
1286 { $$ = makeStringConst($1, @1); }
1288 { $$ = makeStringConst($1, @1); }
1290 { $$ = makeAConst($1, @1); }
1293 iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1294 | READ COMMITTED { $$ = "read committed"; }
1295 | REPEATABLE READ { $$ = "repeatable read"; }
1296 | SERIALIZABLE { $$ = "serializable"; }
1300 TRUE_P { $$ = "true"; }
1301 | FALSE_P { $$ = "false"; }
1303 | OFF { $$ = "off"; }
1306 /* Timezone values can be:
1307 * - a string such as 'pst8pdt'
1308 * - an identifier such as "pst8pdt"
1309 * - an integer or floating point number
1310 * - a time interval per SQL99
1311 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1312 * so use IDENT (meaning we reject anything that is a key word).
1317 $$ = makeStringConst($1, @1);
1321 $$ = makeStringConst($1, @1);
1323 | ConstInterval Sconst opt_interval
1328 A_Const *n = (A_Const *) linitial($3);
1329 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1331 (errcode(ERRCODE_SYNTAX_ERROR),
1332 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1333 parser_errposition(@3)));
1336 $$ = makeStringConstCast($2, @2, t);
1338 | ConstInterval '(' Iconst ')' Sconst opt_interval
1343 A_Const *n = (A_Const *) linitial($6);
1344 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1346 (errcode(ERRCODE_SYNTAX_ERROR),
1347 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1348 parser_errposition(@6)));
1349 if (list_length($6) != 1)
1351 (errcode(ERRCODE_SYNTAX_ERROR),
1352 errmsg("interval precision specified twice"),
1353 parser_errposition(@1)));
1354 t->typmods = lappend($6, makeIntConst($3, @3));
1357 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1358 makeIntConst($3, @3));
1359 $$ = makeStringConstCast($5, @5, t);
1361 | NumericOnly { $$ = makeAConst($1, @1); }
1362 | DEFAULT { $$ = NULL; }
1363 | LOCAL { $$ = NULL; }
1368 | DEFAULT { $$ = NULL; }
1369 | /*EMPTY*/ { $$ = NULL; }
1374 | Sconst { $$ = $1; }
1380 VariableSetStmt *n = makeNode(VariableSetStmt);
1381 n->kind = VAR_RESET;
1387 VariableSetStmt *n = makeNode(VariableSetStmt);
1388 n->kind = VAR_RESET;
1389 n->name = "timezone";
1392 | RESET TRANSACTION ISOLATION LEVEL
1394 VariableSetStmt *n = makeNode(VariableSetStmt);
1395 n->kind = VAR_RESET;
1396 n->name = "transaction_isolation";
1399 | RESET SESSION AUTHORIZATION
1401 VariableSetStmt *n = makeNode(VariableSetStmt);
1402 n->kind = VAR_RESET;
1403 n->name = "session_authorization";
1408 VariableSetStmt *n = makeNode(VariableSetStmt);
1409 n->kind = VAR_RESET_ALL;
1414 /* SetResetClause allows SET or RESET without LOCAL */
1416 SET set_rest { $$ = $2; }
1417 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1424 VariableShowStmt *n = makeNode(VariableShowStmt);
1430 VariableShowStmt *n = makeNode(VariableShowStmt);
1431 n->name = "timezone";
1434 | SHOW TRANSACTION ISOLATION LEVEL
1436 VariableShowStmt *n = makeNode(VariableShowStmt);
1437 n->name = "transaction_isolation";
1440 | SHOW SESSION AUTHORIZATION
1442 VariableShowStmt *n = makeNode(VariableShowStmt);
1443 n->name = "session_authorization";
1448 VariableShowStmt *n = makeNode(VariableShowStmt);
1456 SET CONSTRAINTS constraints_set_list constraints_set_mode
1458 ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
1459 n->constraints = $3;
1465 constraints_set_list:
1467 | qualified_name_list { $$ = $1; }
1470 constraints_set_mode:
1471 DEFERRED { $$ = TRUE; }
1472 | IMMEDIATE { $$ = FALSE; }
1477 * Checkpoint statement
1482 CheckPointStmt *n = makeNode(CheckPointStmt);
1488 /*****************************************************************************
1490 * DISCARD { ALL | TEMP | PLANS }
1492 *****************************************************************************/
1497 DiscardStmt *n = makeNode(DiscardStmt);
1498 n->target = DISCARD_ALL;
1503 DiscardStmt *n = makeNode(DiscardStmt);
1504 n->target = DISCARD_TEMP;
1509 DiscardStmt *n = makeNode(DiscardStmt);
1510 n->target = DISCARD_TEMP;
1515 DiscardStmt *n = makeNode(DiscardStmt);
1516 n->target = DISCARD_PLANS;
1522 /*****************************************************************************
1524 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations
1526 * Note: we accept all subcommands for each of the four variants, and sort
1527 * out what's really legal at execution time.
1528 *****************************************************************************/
1531 ALTER TABLE relation_expr alter_table_cmds
1533 AlterTableStmt *n = makeNode(AlterTableStmt);
1536 n->relkind = OBJECT_TABLE;
1539 | ALTER INDEX qualified_name alter_table_cmds
1541 AlterTableStmt *n = makeNode(AlterTableStmt);
1544 n->relkind = OBJECT_INDEX;
1547 | ALTER SEQUENCE qualified_name alter_table_cmds
1549 AlterTableStmt *n = makeNode(AlterTableStmt);
1552 n->relkind = OBJECT_SEQUENCE;
1555 | ALTER VIEW qualified_name alter_table_cmds
1557 AlterTableStmt *n = makeNode(AlterTableStmt);
1560 n->relkind = OBJECT_VIEW;
1566 alter_table_cmd { $$ = list_make1($1); }
1567 | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
1571 /* ALTER TABLE <name> ADD [COLUMN] <coldef> */
1572 ADD_P opt_column columnDef
1574 AlterTableCmd *n = makeNode(AlterTableCmd);
1575 n->subtype = AT_AddColumn;
1579 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1580 | ALTER opt_column ColId alter_column_default
1582 AlterTableCmd *n = makeNode(AlterTableCmd);
1583 n->subtype = AT_ColumnDefault;
1588 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1589 | ALTER opt_column ColId DROP NOT NULL_P
1591 AlterTableCmd *n = makeNode(AlterTableCmd);
1592 n->subtype = AT_DropNotNull;
1596 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1597 | ALTER opt_column ColId SET NOT NULL_P
1599 AlterTableCmd *n = makeNode(AlterTableCmd);
1600 n->subtype = AT_SetNotNull;
1604 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
1605 | ALTER opt_column ColId SET STATISTICS SignedIconst
1607 AlterTableCmd *n = makeNode(AlterTableCmd);
1608 n->subtype = AT_SetStatistics;
1610 n->def = (Node *) makeInteger($6);
1613 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS DISTINCT <NumericOnly> */
1614 | ALTER opt_column ColId SET STATISTICS DISTINCT NumericOnly
1616 AlterTableCmd *n = makeNode(AlterTableCmd);
1617 n->subtype = AT_SetDistinct;
1619 n->def = (Node *) $7;
1622 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1623 | ALTER opt_column ColId SET STORAGE ColId
1625 AlterTableCmd *n = makeNode(AlterTableCmd);
1626 n->subtype = AT_SetStorage;
1628 n->def = (Node *) makeString($6);
1631 /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
1632 | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
1634 AlterTableCmd *n = makeNode(AlterTableCmd);
1635 n->subtype = AT_DropColumn;
1638 n->missing_ok = TRUE;
1641 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1642 | DROP opt_column ColId opt_drop_behavior
1644 AlterTableCmd *n = makeNode(AlterTableCmd);
1645 n->subtype = AT_DropColumn;
1648 n->missing_ok = FALSE;
1652 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
1653 * [ USING <expression> ]
1655 | ALTER opt_column ColId opt_set_data TYPE_P Typename alter_using
1657 AlterTableCmd *n = makeNode(AlterTableCmd);
1658 n->subtype = AT_AlterColumnType;
1660 n->def = (Node *) $6;
1664 /* ALTER TABLE <name> ADD CONSTRAINT ... */
1665 | ADD_P TableConstraint
1667 AlterTableCmd *n = makeNode(AlterTableCmd);
1668 n->subtype = AT_AddConstraint;
1672 /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
1673 | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
1675 AlterTableCmd *n = makeNode(AlterTableCmd);
1676 n->subtype = AT_DropConstraint;
1679 n->missing_ok = TRUE;
1682 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1683 | DROP CONSTRAINT name opt_drop_behavior
1685 AlterTableCmd *n = makeNode(AlterTableCmd);
1686 n->subtype = AT_DropConstraint;
1689 n->missing_ok = FALSE;
1692 /* ALTER TABLE <name> SET WITH OIDS */
1695 AlterTableCmd *n = makeNode(AlterTableCmd);
1696 n->subtype = AT_AddOids;
1699 /* ALTER TABLE <name> SET WITHOUT OIDS */
1702 AlterTableCmd *n = makeNode(AlterTableCmd);
1703 n->subtype = AT_DropOids;
1706 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1709 AlterTableCmd *n = makeNode(AlterTableCmd);
1710 n->subtype = AT_ClusterOn;
1714 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1715 | SET WITHOUT CLUSTER
1717 AlterTableCmd *n = makeNode(AlterTableCmd);
1718 n->subtype = AT_DropCluster;
1722 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
1723 | ENABLE_P TRIGGER name
1725 AlterTableCmd *n = makeNode(AlterTableCmd);
1726 n->subtype = AT_EnableTrig;
1730 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
1731 | ENABLE_P ALWAYS TRIGGER name
1733 AlterTableCmd *n = makeNode(AlterTableCmd);
1734 n->subtype = AT_EnableAlwaysTrig;
1738 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
1739 | ENABLE_P REPLICA TRIGGER name
1741 AlterTableCmd *n = makeNode(AlterTableCmd);
1742 n->subtype = AT_EnableReplicaTrig;
1746 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
1747 | ENABLE_P TRIGGER ALL
1749 AlterTableCmd *n = makeNode(AlterTableCmd);
1750 n->subtype = AT_EnableTrigAll;
1753 /* ALTER TABLE <name> ENABLE TRIGGER USER */
1754 | ENABLE_P TRIGGER USER
1756 AlterTableCmd *n = makeNode(AlterTableCmd);
1757 n->subtype = AT_EnableTrigUser;
1760 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
1761 | DISABLE_P TRIGGER name
1763 AlterTableCmd *n = makeNode(AlterTableCmd);
1764 n->subtype = AT_DisableTrig;
1768 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
1769 | DISABLE_P TRIGGER ALL
1771 AlterTableCmd *n = makeNode(AlterTableCmd);
1772 n->subtype = AT_DisableTrigAll;
1775 /* ALTER TABLE <name> DISABLE TRIGGER USER */
1776 | DISABLE_P TRIGGER USER
1778 AlterTableCmd *n = makeNode(AlterTableCmd);
1779 n->subtype = AT_DisableTrigUser;
1782 /* ALTER TABLE <name> ENABLE RULE <rule> */
1783 | ENABLE_P RULE name
1785 AlterTableCmd *n = makeNode(AlterTableCmd);
1786 n->subtype = AT_EnableRule;
1790 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
1791 | ENABLE_P ALWAYS RULE name
1793 AlterTableCmd *n = makeNode(AlterTableCmd);
1794 n->subtype = AT_EnableAlwaysRule;
1798 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
1799 | ENABLE_P REPLICA RULE name
1801 AlterTableCmd *n = makeNode(AlterTableCmd);
1802 n->subtype = AT_EnableReplicaRule;
1806 /* ALTER TABLE <name> DISABLE RULE <rule> */
1807 | DISABLE_P RULE name
1809 AlterTableCmd *n = makeNode(AlterTableCmd);
1810 n->subtype = AT_DisableRule;
1814 /* ALTER TABLE <name> INHERIT <parent> */
1815 | INHERIT qualified_name
1817 AlterTableCmd *n = makeNode(AlterTableCmd);
1818 n->subtype = AT_AddInherit;
1819 n->def = (Node *) $2;
1822 /* ALTER TABLE <name> NO INHERIT <parent> */
1823 | NO INHERIT qualified_name
1825 AlterTableCmd *n = makeNode(AlterTableCmd);
1826 n->subtype = AT_DropInherit;
1827 n->def = (Node *) $3;
1830 /* ALTER TABLE <name> OWNER TO RoleId */
1833 AlterTableCmd *n = makeNode(AlterTableCmd);
1834 n->subtype = AT_ChangeOwner;
1838 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1839 | SET TABLESPACE name
1841 AlterTableCmd *n = makeNode(AlterTableCmd);
1842 n->subtype = AT_SetTableSpace;
1846 /* ALTER TABLE <name> SET (...) */
1849 AlterTableCmd *n = makeNode(AlterTableCmd);
1850 n->subtype = AT_SetRelOptions;
1851 n->def = (Node *)$2;
1854 /* ALTER TABLE <name> RESET (...) */
1857 AlterTableCmd *n = makeNode(AlterTableCmd);
1858 n->subtype = AT_ResetRelOptions;
1859 n->def = (Node *)$2;
1864 alter_column_default:
1865 SET DEFAULT a_expr { $$ = $3; }
1866 | DROP DEFAULT { $$ = NULL; }
1870 CASCADE { $$ = DROP_CASCADE; }
1871 | RESTRICT { $$ = DROP_RESTRICT; }
1872 | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1876 USING a_expr { $$ = $2; }
1877 | /* EMPTY */ { $$ = NULL; }
1881 '(' reloption_list ')' { $$ = $2; }
1884 opt_reloptions: WITH reloptions { $$ = $2; }
1885 | /* EMPTY */ { $$ = NIL; }
1889 reloption_elem { $$ = list_make1($1); }
1890 | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
1893 /* This should match def_elem and also allow qualified names */
1895 ColLabel '=' def_arg
1897 $$ = makeDefElem($1, (Node *) $3);
1901 $$ = makeDefElem($1, NULL);
1903 | ColLabel '.' ColLabel '=' def_arg
1905 $$ = makeDefElemExtended($1, $3, (Node *) $5,
1908 | ColLabel '.' ColLabel
1910 $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC);
1915 /*****************************************************************************
1918 * close <portalname>
1920 *****************************************************************************/
1925 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1931 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1932 n->portalname = NULL;
1938 /*****************************************************************************
1941 * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
1942 * COPY ( SELECT ... ) TO file [WITH] [(options)]
1944 * In the preferred syntax the options are comma-separated
1945 * and use generic identifiers instead of keywords. The pre-8.5
1946 * syntax had a hard-wired, space-separated set of options.
1948 * Really old syntax, from versions 7.2 and prior:
1949 * COPY [ BINARY ] table [ WITH OIDS ] FROM/TO file
1950 * [ [ USING ] DELIMITERS 'delimiter' ] ]
1951 * [ WITH NULL AS 'null string' ]
1952 * This option placement is not supported with COPY (SELECT...).
1954 *****************************************************************************/
1956 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
1957 copy_from copy_file_name copy_delimiter opt_with copy_options
1959 CopyStmt *n = makeNode(CopyStmt);
1967 /* Concatenate user-supplied flags */
1969 n->options = lappend(n->options, $2);
1971 n->options = lappend(n->options, $5);
1973 n->options = lappend(n->options, $8);
1975 n->options = list_concat(n->options, $10);
1978 | COPY select_with_parens TO copy_file_name opt_with copy_options
1980 CopyStmt *n = makeNode(CopyStmt);
1993 | TO { $$ = FALSE; }
1997 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
1998 * used depends on the direction. (It really doesn't make sense to copy from
1999 * stdout. We silently correct the "typo".) - AY 9/94
2003 | STDIN { $$ = NULL; }
2004 | STDOUT { $$ = NULL; }
2007 copy_options: copy_opt_list { $$ = $1; }
2008 | '(' copy_generic_opt_list ')' { $$ = $2; }
2011 /* old COPY option syntax */
2013 copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
2014 | /* EMPTY */ { $$ = NIL; }
2020 $$ = makeDefElem("format", (Node *)makeString("binary"));
2024 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2026 | DELIMITER opt_as Sconst
2028 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2030 | NULL_P opt_as Sconst
2032 $$ = makeDefElem("null", (Node *)makeString($3));
2036 $$ = makeDefElem("format", (Node *)makeString("csv"));
2040 $$ = makeDefElem("header", (Node *)makeInteger(TRUE));
2042 | QUOTE opt_as Sconst
2044 $$ = makeDefElem("quote", (Node *)makeString($3));
2046 | ESCAPE opt_as Sconst
2048 $$ = makeDefElem("escape", (Node *)makeString($3));
2050 | FORCE QUOTE columnList
2052 $$ = makeDefElem("force_quote", (Node *)$3);
2056 $$ = makeDefElem("force_quote", (Node *)makeNode(A_Star));
2058 | FORCE NOT NULL_P columnList
2060 $$ = makeDefElem("force_not_null", (Node *)$4);
2064 /* The following exist for backward compatibility with very old versions */
2069 $$ = makeDefElem("format", (Node *)makeString("binary"));
2071 | /*EMPTY*/ { $$ = NULL; }
2077 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2079 | /*EMPTY*/ { $$ = NULL; }
2083 opt_using DELIMITERS Sconst
2085 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2087 | /*EMPTY*/ { $$ = NULL; }
2095 /* new COPY option syntax */
2096 copy_generic_opt_list:
2097 copy_generic_opt_elem
2099 $$ = list_make1($1);
2101 | copy_generic_opt_list ',' copy_generic_opt_elem
2103 $$ = lappend($1, $3);
2107 copy_generic_opt_elem:
2108 ColLabel copy_generic_opt_arg
2110 $$ = makeDefElem($1, $2);
2114 copy_generic_opt_arg:
2115 opt_boolean { $$ = (Node *) makeString($1); }
2116 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
2117 | NumericOnly { $$ = (Node *) $1; }
2118 | '*' { $$ = (Node *) makeNode(A_Star); }
2119 | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
2120 | /* EMPTY */ { $$ = NULL; }
2123 copy_generic_opt_arg_list:
2124 copy_generic_opt_arg_list_item
2126 $$ = list_make1($1);
2128 | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
2130 $$ = lappend($1, $3);
2134 /* beware of emitting non-string list elements here; see commands/define.c */
2135 copy_generic_opt_arg_list_item:
2136 opt_boolean { $$ = (Node *) makeString($1); }
2137 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
2141 /*****************************************************************************
2144 * CREATE TABLE relname
2146 *****************************************************************************/
2148 CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
2149 OptInherit OptWith OnCommitOption OptTableSpace
2151 CreateStmt *n = makeNode(CreateStmt);
2155 n->inhRelations = $8;
2156 n->constraints = NIL;
2159 n->tablespacename = $11;
2162 | CREATE OptTemp TABLE qualified_name OF qualified_name
2163 '(' OptTableElementList ')' OptWith OnCommitOption OptTableSpace
2165 /* SQL99 CREATE TABLE OF <UDT> (cols) seems to be satisfied
2166 * by our inheritance capabilities. Let's try it...
2168 CreateStmt *n = makeNode(CreateStmt);
2172 n->inhRelations = list_make1($6);
2173 n->constraints = NIL;
2176 n->tablespacename = $12;
2182 * Redundancy here is needed to avoid shift/reduce conflicts,
2183 * since TEMP is not a reserved word. See also OptTempTableName.
2185 * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
2186 * the LOCAL keyword is really meaningless.
2188 OptTemp: TEMPORARY { $$ = TRUE; }
2189 | TEMP { $$ = TRUE; }
2190 | LOCAL TEMPORARY { $$ = TRUE; }
2191 | LOCAL TEMP { $$ = TRUE; }
2192 | GLOBAL TEMPORARY { $$ = TRUE; }
2193 | GLOBAL TEMP { $$ = TRUE; }
2194 | /*EMPTY*/ { $$ = FALSE; }
2197 OptTableElementList:
2198 TableElementList { $$ = $1; }
2199 | /*EMPTY*/ { $$ = NIL; }
2205 $$ = list_make1($1);
2207 | TableElementList ',' TableElement
2209 $$ = lappend($1, $3);
2214 columnDef { $$ = $1; }
2215 | TableLikeClause { $$ = $1; }
2216 | TableConstraint { $$ = $1; }
2219 columnDef: ColId Typename ColQualList
2221 ColumnDef *n = makeNode(ColumnDef);
2224 n->constraints = $3;
2231 ColQualList ColConstraint { $$ = lappend($1, $2); }
2232 | /*EMPTY*/ { $$ = NIL; }
2236 CONSTRAINT name ColConstraintElem
2238 Constraint *n = (Constraint *) $3;
2239 Assert(IsA(n, Constraint));
2244 | ColConstraintElem { $$ = $1; }
2245 | ConstraintAttr { $$ = $1; }
2248 /* DEFAULT NULL is already the default for Postgres.
2249 * But define it here and carry it forward into the system
2250 * to make it explicit.
2251 * - thomas 1998-09-13
2253 * WITH NULL and NULL are not SQL92-standard syntax elements,
2254 * so leave them out. Use DEFAULT NULL to explicitly indicate
2255 * that a column may have that value. WITH NULL leads to
2256 * shift/reduce conflicts with WITH TIME ZONE anyway.
2257 * - thomas 1999-01-08
2259 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
2260 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
2261 * or be part of a_expr NOT LIKE or similar constructs).
2266 Constraint *n = makeNode(Constraint);
2267 n->contype = CONSTR_NOTNULL;
2273 Constraint *n = makeNode(Constraint);
2274 n->contype = CONSTR_NULL;
2278 | UNIQUE opt_definition OptConsTableSpace
2280 Constraint *n = makeNode(Constraint);
2281 n->contype = CONSTR_UNIQUE;
2288 | PRIMARY KEY opt_definition OptConsTableSpace
2290 Constraint *n = makeNode(Constraint);
2291 n->contype = CONSTR_PRIMARY;
2298 | CHECK '(' a_expr ')'
2300 Constraint *n = makeNode(Constraint);
2301 n->contype = CONSTR_CHECK;
2304 n->cooked_expr = NULL;
2309 Constraint *n = makeNode(Constraint);
2310 n->contype = CONSTR_DEFAULT;
2313 n->cooked_expr = NULL;
2316 | REFERENCES qualified_name opt_column_list key_match key_actions
2318 Constraint *n = makeNode(Constraint);
2319 n->contype = CONSTR_FOREIGN;
2324 n->fk_matchtype = $4;
2325 n->fk_upd_action = (char) ($5 >> 8);
2326 n->fk_del_action = (char) ($5 & 0xFF);
2327 n->skip_validation = FALSE;
2333 * ConstraintAttr represents constraint attributes, which we parse as if
2334 * they were independent constraint clauses, in order to avoid shift/reduce
2335 * conflicts (since NOT might start either an independent NOT NULL clause
2336 * or an attribute). parse_utilcmd.c is responsible for attaching the
2337 * attribute information to the preceding "real" constraint node, and for
2338 * complaining if attribute clauses appear in the wrong place or wrong
2341 * See also ConstraintAttributeSpec, which can be used in places where
2342 * there is no parsing conflict.
2347 Constraint *n = makeNode(Constraint);
2348 n->contype = CONSTR_ATTR_DEFERRABLE;
2354 Constraint *n = makeNode(Constraint);
2355 n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
2359 | INITIALLY DEFERRED
2361 Constraint *n = makeNode(Constraint);
2362 n->contype = CONSTR_ATTR_DEFERRED;
2366 | INITIALLY IMMEDIATE
2368 Constraint *n = makeNode(Constraint);
2369 n->contype = CONSTR_ATTR_IMMEDIATE;
2377 * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2378 * This seems to be a poor man's inheritance capability, with the resulting
2379 * tables completely decoupled except for the original commonality in definitions.
2381 * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2382 * which is a part of SQL:2003.
2385 LIKE qualified_name TableLikeOptionList
2387 InhRelation *n = makeNode(InhRelation);
2394 TableLikeOptionList:
2395 TableLikeOptionList TableLikeOption { $$ = lappend_int($1, $2); }
2396 | /* EMPTY */ { $$ = NIL; }
2400 INCLUDING DEFAULTS { $$ = CREATE_TABLE_LIKE_INCLUDING_DEFAULTS; }
2401 | EXCLUDING DEFAULTS { $$ = CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS; }
2402 | INCLUDING CONSTRAINTS { $$ = CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS; }
2403 | EXCLUDING CONSTRAINTS { $$ = CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS; }
2404 | INCLUDING INDEXES { $$ = CREATE_TABLE_LIKE_INCLUDING_INDEXES; }
2405 | EXCLUDING INDEXES { $$ = CREATE_TABLE_LIKE_EXCLUDING_INDEXES; }
2409 /* ConstraintElem specifies constraint syntax which is not embedded into
2410 * a column definition. ColConstraintElem specifies the embedded form.
2411 * - thomas 1997-12-03
2414 CONSTRAINT name ConstraintElem
2416 Constraint *n = (Constraint *) $3;
2417 Assert(IsA(n, Constraint));
2422 | ConstraintElem { $$ = $1; }
2426 CHECK '(' a_expr ')' ConstraintAttributeSpec
2428 Constraint *n = makeNode(Constraint);
2429 n->contype = CONSTR_CHECK;
2432 n->cooked_expr = NULL;
2435 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2436 errmsg("CHECK constraints cannot be deferred"),
2437 parser_errposition(@5)));
2440 | UNIQUE '(' columnList ')' opt_definition OptConsTableSpace
2441 ConstraintAttributeSpec
2443 Constraint *n = makeNode(Constraint);
2444 n->contype = CONSTR_UNIQUE;
2449 n->deferrable = ($7 & 1) != 0;
2450 n->initdeferred = ($7 & 2) != 0;
2453 | PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace
2454 ConstraintAttributeSpec
2456 Constraint *n = makeNode(Constraint);
2457 n->contype = CONSTR_PRIMARY;
2462 n->deferrable = ($8 & 1) != 0;
2463 n->initdeferred = ($8 & 2) != 0;
2466 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
2467 opt_column_list key_match key_actions ConstraintAttributeSpec
2469 Constraint *n = makeNode(Constraint);
2470 n->contype = CONSTR_FOREIGN;
2475 n->fk_matchtype = $9;
2476 n->fk_upd_action = (char) ($10 >> 8);
2477 n->fk_del_action = (char) ($10 & 0xFF);
2478 n->skip_validation = FALSE;
2479 n->deferrable = ($11 & 1) != 0;
2480 n->initdeferred = ($11 & 2) != 0;
2486 '(' columnList ')' { $$ = $2; }
2487 | /*EMPTY*/ { $$ = NIL; }
2491 columnElem { $$ = list_make1($1); }
2492 | columnList ',' columnElem { $$ = lappend($1, $3); }
2497 $$ = (Node *) makeString($1);
2501 key_match: MATCH FULL
2503 $$ = FKCONSTR_MATCH_FULL;
2508 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2509 errmsg("MATCH PARTIAL not yet implemented"),
2510 parser_errposition(@1)));
2511 $$ = FKCONSTR_MATCH_PARTIAL;
2515 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2519 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2524 * We combine the update and delete actions into one value temporarily
2525 * for simplicity of parsing, and then break them down again in the
2526 * calling production. update is in the left 8 bits, delete in the right.
2527 * Note that NOACTION is the default.
2531 { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2533 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
2534 | key_update key_delete
2535 { $$ = ($1 << 8) | ($2 & 0xFF); }
2536 | key_delete key_update
2537 { $$ = ($2 << 8) | ($1 & 0xFF); }
2539 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2542 key_update: ON UPDATE key_action { $$ = $3; }
2545 key_delete: ON DELETE_P key_action { $$ = $3; }
2549 NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; }
2550 | RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; }
2551 | CASCADE { $$ = FKCONSTR_ACTION_CASCADE; }
2552 | SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; }
2553 | SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; }
2556 OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
2557 | /*EMPTY*/ { $$ = NIL; }
2560 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
2562 WITH reloptions { $$ = $2; }
2563 | WITH OIDS { $$ = list_make1(defWithOids(true)); }
2564 | WITHOUT OIDS { $$ = list_make1(defWithOids(false)); }
2565 | /*EMPTY*/ { $$ = NIL; }
2568 OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
2569 | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
2570 | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
2571 | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
2574 OptTableSpace: TABLESPACE name { $$ = $2; }
2575 | /*EMPTY*/ { $$ = NULL; }
2578 OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
2579 | /*EMPTY*/ { $$ = NULL; }
2584 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
2589 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
2592 * When the SelectStmt is a set-operation tree, we must
2593 * stuff the INTO information into the leftmost component
2594 * Select, because that's where analyze.c will expect
2595 * to find it. Similarly, the output column names must
2596 * be attached to that Select's target list.
2598 SelectStmt *n = findLeftmostSelect((SelectStmt *) $6);
2599 if (n->intoClause != NULL)
2601 (errcode(ERRCODE_SYNTAX_ERROR),
2602 errmsg("CREATE TABLE AS cannot specify INTO"),
2603 parser_errposition(exprLocation((Node *) n->intoClause))));
2604 $4->rel->istemp = $2;
2606 /* Implement WITH NO DATA by forcing top-level LIMIT 0 */
2608 ((SelectStmt *) $6)->limitCount = makeIntConst(0, -1);
2614 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
2616 $$ = makeNode(IntoClause);
2621 $$->tableSpaceName = $5;
2626 '(' CreateAsList ')' { $$ = $2; }
2627 | /*EMPTY*/ { $$ = NIL; }
2631 CreateAsElement { $$ = list_make1($1); }
2632 | CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); }
2638 ColumnDef *n = makeNode(ColumnDef);
2643 n->is_not_null = false;
2644 n->raw_default = NULL;
2645 n->cooked_default = NULL;
2646 n->constraints = NIL;
2652 WITH DATA_P { $$ = TRUE; }
2653 | WITH NO DATA_P { $$ = FALSE; }
2654 | /*EMPTY*/ { $$ = TRUE; }
2658 /*****************************************************************************
2661 * CREATE SEQUENCE seqname
2662 * ALTER SEQUENCE seqname
2664 *****************************************************************************/
2667 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
2669 CreateSeqStmt *n = makeNode(CreateSeqStmt);
2678 ALTER SEQUENCE qualified_name SeqOptList
2680 AlterSeqStmt *n = makeNode(AlterSeqStmt);
2687 OptSeqOptList: SeqOptList { $$ = $1; }
2688 | /*EMPTY*/ { $$ = NIL; }
2691 SeqOptList: SeqOptElem { $$ = list_make1($1); }
2692 | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
2695 SeqOptElem: CACHE NumericOnly
2697 $$ = makeDefElem("cache", (Node *)$2);
2701 $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE));
2705 $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE));
2707 | INCREMENT opt_by NumericOnly
2709 $$ = makeDefElem("increment", (Node *)$3);
2711 | MAXVALUE NumericOnly
2713 $$ = makeDefElem("maxvalue", (Node *)$2);
2715 | MINVALUE NumericOnly
2717 $$ = makeDefElem("minvalue", (Node *)$2);
2721 $$ = makeDefElem("maxvalue", NULL);
2725 $$ = makeDefElem("minvalue", NULL);
2729 $$ = makeDefElem("owned_by", (Node *)$3);
2731 | START opt_with NumericOnly
2733 $$ = makeDefElem("start", (Node *)$3);
2737 $$ = makeDefElem("restart", NULL);
2739 | RESTART opt_with NumericOnly
2741 $$ = makeDefElem("restart", (Node *)$3);
2750 FCONST { $$ = makeFloat($1); }
2756 | SignedIconst { $$ = makeInteger($1); }
2759 /*****************************************************************************
2762 * CREATE PROCEDURAL LANGUAGE ...
2763 * DROP PROCEDURAL LANGUAGE ...
2765 *****************************************************************************/
2768 CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2770 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2772 /* parameters are all to be supplied by system */
2774 n->plvalidator = NIL;
2775 n->pltrusted = false;
2778 | CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2779 HANDLER handler_name opt_validator opt_lancompiler
2781 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2784 n->plvalidator = $8;
2786 /* LANCOMPILER is now ignored entirely */
2792 TRUSTED { $$ = TRUE; }
2793 | /*EMPTY*/ { $$ = FALSE; }
2796 /* This ought to be just func_name, but that causes reduce/reduce conflicts
2797 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
2798 * Work around by using simple names, instead.
2801 name { $$ = list_make1(makeString($1)); }
2802 | name attrs { $$ = lcons(makeString($1), $2); }
2806 VALIDATOR handler_name { $$ = $2; }
2807 | NO VALIDATOR { $$ = NIL; }
2811 validator_clause { $$ = $1; }
2812 | /*EMPTY*/ { $$ = NIL; }
2816 LANCOMPILER Sconst { $$ = $2; }
2817 | /*EMPTY*/ { $$ = NULL; }
2821 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
2823 DropPLangStmt *n = makeNode(DropPLangStmt);
2826 n->missing_ok = false;
2829 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
2831 DropPLangStmt *n = makeNode(DropPLangStmt);
2834 n->missing_ok = true;
2844 /*****************************************************************************
2847 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
2849 *****************************************************************************/
2851 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
2853 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
2854 n->tablespacename = $3;
2861 OptTableSpaceOwner: OWNER name { $$ = $2; }
2862 | /*EMPTY */ { $$ = NULL; }
2865 /*****************************************************************************
2868 * DROP TABLESPACE <tablespace>
2870 * No need for drop behaviour as we cannot implement dependencies for
2871 * objects in other databases; we can only support RESTRICT.
2873 ****************************************************************************/
2875 DropTableSpaceStmt: DROP TABLESPACE name
2877 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2878 n->tablespacename = $3;
2879 n->missing_ok = false;
2882 | DROP TABLESPACE IF_P EXISTS name
2884 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2885 n->tablespacename = $5;
2886 n->missing_ok = true;
2891 /*****************************************************************************
2894 * CREATE FOREIGN DATA WRAPPER name [ VALIDATOR name ]
2896 *****************************************************************************/
2898 CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_validator create_generic_options
2900 CreateFdwStmt *n = makeNode(CreateFdwStmt);
2908 /*****************************************************************************
2911 * DROP FOREIGN DATA WRAPPER name
2913 ****************************************************************************/
2915 DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
2917 DropFdwStmt *n = makeNode(DropFdwStmt);
2919 n->missing_ok = false;
2923 | DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior
2925 DropFdwStmt *n = makeNode(DropFdwStmt);
2927 n->missing_ok = true;
2933 /*****************************************************************************
2936 * ALTER FOREIGN DATA WRAPPER name
2938 ****************************************************************************/
2940 AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name validator_clause alter_generic_options
2942 AlterFdwStmt *n = makeNode(AlterFdwStmt);
2945 n->change_validator = true;
2949 | ALTER FOREIGN DATA_P WRAPPER name validator_clause
2951 AlterFdwStmt *n = makeNode(AlterFdwStmt);
2954 n->change_validator = true;
2957 | ALTER FOREIGN DATA_P WRAPPER name alter_generic_options
2959 AlterFdwStmt *n = makeNode(AlterFdwStmt);
2966 /* Options definition for CREATE FDW, SERVER and USER MAPPING */
2967 create_generic_options:
2968 OPTIONS '(' generic_option_list ')' { $$ = $3; }
2969 | /*EMPTY*/ { $$ = NIL; }
2972 generic_option_list:
2975 $$ = list_make1($1);
2977 | generic_option_list ',' generic_option_elem
2979 $$ = lappend($1, $3);
2983 /* Options definition for ALTER FDW, SERVER and USER MAPPING */
2984 alter_generic_options:
2985 OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
2988 alter_generic_option_list:
2989 alter_generic_option_elem
2991 $$ = list_make1($1);
2993 | alter_generic_option_list ',' alter_generic_option_elem
2995 $$ = lappend($1, $3);
2999 alter_generic_option_elem:
3004 | SET generic_option_elem
3007 $$->defaction = DEFELEM_SET;
3009 | ADD_P generic_option_elem
3012 $$->defaction = DEFELEM_ADD;
3014 | DROP generic_option_name
3016 $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP);
3020 generic_option_elem:
3021 generic_option_name generic_option_arg
3023 $$ = makeDefElem($1, $2);
3027 generic_option_name:
3028 ColLabel { $$ = $1; }
3031 /* We could use def_arg here, but the spec only requires string literals */
3033 Sconst { $$ = (Node *) makeString($1); }
3036 /*****************************************************************************
3039 * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
3041 *****************************************************************************/
3043 CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
3044 FOREIGN DATA_P WRAPPER name create_generic_options
3046 CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
3057 TYPE_P Sconst { $$ = $2; }
3058 | /*EMPTY*/ { $$ = NULL; }
3062 foreign_server_version:
3063 VERSION_P Sconst { $$ = $2; }
3064 | VERSION_P NULL_P { $$ = NULL; }
3067 opt_foreign_server_version:
3068 foreign_server_version { $$ = $1; }
3069 | /*EMPTY*/ { $$ = NULL; }
3072 /*****************************************************************************
3077 ****************************************************************************/
3079 DropForeignServerStmt: DROP SERVER name opt_drop_behavior
3081 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3083 n->missing_ok = false;
3087 | DROP SERVER IF_P EXISTS name opt_drop_behavior
3089 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3091 n->missing_ok = true;
3097 /*****************************************************************************
3100 * ALTER SERVER name [VERSION] [OPTIONS]
3102 ****************************************************************************/
3104 AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
3106 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3110 n->has_version = true;
3113 | ALTER SERVER name foreign_server_version
3115 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3118 n->has_version = true;
3121 | ALTER SERVER name alter_generic_options
3123 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3130 /*****************************************************************************
3133 * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
3135 *****************************************************************************/
3137 CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
3139 CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
3147 /* User mapping authorization identifier */
3149 CURRENT_USER { $$ = "current_user"; }
3150 | USER { $$ = "current_user"; }
3151 | RoleId { $$ = (strcmp($1, "public") == 0) ? NULL : $1; }
3154 /*****************************************************************************
3157 * DROP USER MAPPING FOR auth_ident SERVER name
3159 ****************************************************************************/
3161 DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
3163 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3166 n->missing_ok = false;
3169 | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
3171 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3174 n->missing_ok = true;
3179 /*****************************************************************************
3182 * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
3184 ****************************************************************************/
3186 AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
3188 AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
3196 /*****************************************************************************
3199 * CREATE TRIGGER ...
3202 *****************************************************************************/
3205 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
3206 qualified_name TriggerForSpec EXECUTE PROCEDURE
3207 func_name '(' TriggerFuncArgs ')'
3209 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3217 n->isconstraint = FALSE;
3218 n->deferrable = FALSE;
3219 n->initdeferred = FALSE;
3220 n->constrrel = NULL;
3223 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
3224 qualified_name OptConstrFromTable
3225 ConstraintAttributeSpec
3226 FOR EACH ROW EXECUTE PROCEDURE
3227 func_name '(' TriggerFuncArgs ')'
3229 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3237 n->isconstraint = TRUE;
3238 n->deferrable = ($10 & 1) != 0;
3239 n->initdeferred = ($10 & 2) != 0;
3246 BEFORE { $$ = TRUE; }
3247 | AFTER { $$ = FALSE; }
3253 | TriggerEvents OR TriggerOneEvent
3256 parser_yyerror("duplicate trigger events specified");
3262 INSERT { $$ = TRIGGER_TYPE_INSERT; }
3263 | DELETE_P { $$ = TRIGGER_TYPE_DELETE; }
3264 | UPDATE { $$ = TRIGGER_TYPE_UPDATE; }
3265 | TRUNCATE { $$ = TRIGGER_TYPE_TRUNCATE; }
3269 FOR TriggerForOpt TriggerForType
3276 * If ROW/STATEMENT not specified, default to
3277 * STATEMENT, per SQL
3290 | STATEMENT { $$ = FALSE; }
3294 TriggerFuncArg { $$ = list_make1($1); }
3295 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
3296 | /*EMPTY*/ { $$ = NIL; }
3303 snprintf(buf, sizeof(buf), "%d", $1);
3304 $$ = makeString(pstrdup(buf));
3306 | FCONST { $$ = makeString($1); }
3307 | Sconst { $$ = makeString($1); }
3308 | BCONST { $$ = makeString($1); }
3309 | XCONST { $$ = makeString($1); }
3310 | ColId { $$ = makeString($1); }
3314 FROM qualified_name { $$ = $2; }
3315 | /*EMPTY*/ { $$ = NULL; }
3318 ConstraintAttributeSpec:
3319 ConstraintDeferrabilitySpec
3321 | ConstraintDeferrabilitySpec ConstraintTimeSpec
3323 if ($1 == 0 && $2 != 0)
3325 (errcode(ERRCODE_SYNTAX_ERROR),
3326 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3327 parser_errposition(@1)));
3330 | ConstraintTimeSpec
3337 | ConstraintTimeSpec ConstraintDeferrabilitySpec
3339 if ($2 == 0 && $1 != 0)
3341 (errcode(ERRCODE_SYNTAX_ERROR),
3342 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3343 parser_errposition(@1)));
3350 ConstraintDeferrabilitySpec:
3351 NOT DEFERRABLE { $$ = 0; }
3352 | DEFERRABLE { $$ = 1; }
3356 INITIALLY IMMEDIATE { $$ = 0; }
3357 | INITIALLY DEFERRED { $$ = 2; }
3362 DROP TRIGGER name ON qualified_name opt_drop_behavior
3364 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3368 n->removeType = OBJECT_TRIGGER;
3369 n->missing_ok = false;
3372 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
3374 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3378 n->removeType = OBJECT_TRIGGER;
3379 n->missing_ok = true;
3385 /*****************************************************************************
3388 * CREATE ASSERTION ...
3389 * DROP ASSERTION ...
3391 *****************************************************************************/
3394 CREATE ASSERTION name CHECK '(' a_expr ')'
3395 ConstraintAttributeSpec
3397 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3399 n->args = list_make1($6);
3400 n->isconstraint = TRUE;
3401 n->deferrable = ($8 & 1) != 0;
3402 n->initdeferred = ($8 & 2) != 0;
3405 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3406 errmsg("CREATE ASSERTION is not yet implemented")));
3413 DROP ASSERTION name opt_drop_behavior
3415 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3419 n->removeType = OBJECT_TRIGGER; /* XXX */
3421 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3422 errmsg("DROP ASSERTION is not yet implemented")));
3428 /*****************************************************************************
3431 * define (aggregate,operator,type)
3433 *****************************************************************************/
3436 CREATE AGGREGATE func_name aggr_args definition
3438 DefineStmt *n = makeNode(DefineStmt);
3439 n->kind = OBJECT_AGGREGATE;
3440 n->oldstyle = false;
3446 | CREATE AGGREGATE func_name old_aggr_definition
3448 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
3449 DefineStmt *n = makeNode(DefineStmt);
3450 n->kind = OBJECT_AGGREGATE;
3457 | CREATE OPERATOR any_operator definition
3459 DefineStmt *n = makeNode(DefineStmt);
3460 n->kind = OBJECT_OPERATOR;
3461 n->oldstyle = false;
3467 | CREATE TYPE_P any_name definition
3469 DefineStmt *n = makeNode(DefineStmt);
3470 n->kind = OBJECT_TYPE;
3471 n->oldstyle = false;
3477 | CREATE TYPE_P any_name
3479 /* Shell type (identified by lack of definition) */
3480 DefineStmt *n = makeNode(DefineStmt);
3481 n->kind = OBJECT_TYPE;
3482 n->oldstyle = false;
3485 n->definition = NIL;
3488 | CREATE TYPE_P any_name AS '(' TableFuncElementList ')'
3490 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
3491 RangeVar *r = makeNode(RangeVar);
3493 /* can't use qualified_name, sigh */
3494 switch (list_length($3))
3497 r->catalogname = NULL;
3498 r->schemaname = NULL;
3499 r->relname = strVal(linitial($3));
3502 r->catalogname = NULL;
3503 r->schemaname = strVal(linitial($3));
3504 r->relname = strVal(lsecond($3));
3507 r->catalogname = strVal(linitial($3));
3508 r->schemaname = strVal(lsecond($3));
3509 r->relname = strVal(lthird($3));
3513 (errcode(ERRCODE_SYNTAX_ERROR),
3514 errmsg("improper qualified name (too many dotted names): %s",
3515 NameListToString($3)),
3516 parser_errposition(@3)));
3524 | CREATE TYPE_P any_name AS ENUM_P '(' enum_val_list ')'
3526 CreateEnumStmt *n = makeNode(CreateEnumStmt);
3531 | CREATE TEXT_P SEARCH PARSER any_name definition
3533 DefineStmt *n = makeNode(DefineStmt);
3534 n->kind = OBJECT_TSPARSER;
3540 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
3542 DefineStmt *n = makeNode(DefineStmt);
3543 n->kind = OBJECT_TSDICTIONARY;
3549 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
3551 DefineStmt *n = makeNode(DefineStmt);
3552 n->kind = OBJECT_TSTEMPLATE;
3558 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
3560 DefineStmt *n = makeNode(DefineStmt);
3561 n->kind = OBJECT_TSCONFIGURATION;
3569 definition: '(' def_list ')' { $$ = $2; }
3572 def_list: def_elem { $$ = list_make1($1); }
3573 | def_list ',' def_elem { $$ = lappend($1, $3); }
3576 def_elem: ColLabel '=' def_arg
3578 $$ = makeDefElem($1, (Node *) $3);
3582 $$ = makeDefElem($1, NULL);
3586 /* Note: any simple identifier will be returned as a type name! */
3587 def_arg: func_type { $$ = (Node *)$1; }
3588 | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
3589 | qual_all_Op { $$ = (Node *)$1; }
3590 | NumericOnly { $$ = (Node *)$1; }
3591 | Sconst { $$ = (Node *)makeString($1); }
3594 aggr_args: '(' type_list ')' { $$ = $2; }
3595 | '(' '*' ')' { $$ = NIL; }
3598 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
3601 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
3602 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
3606 * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
3607 * the item names needed in old aggregate definitions are likely to become
3610 old_aggr_elem: IDENT '=' def_arg
3612 $$ = makeDefElem($1, (Node *)$3);
3616 enum_val_list: Sconst
3617 { $$ = list_make1(makeString($1)); }
3618 | enum_val_list ',' Sconst
3619 { $$ = lappend($1, makeString($3)); }
3623 /*****************************************************************************
3626 * CREATE OPERATOR CLASS ...
3627 * CREATE OPERATOR FAMILY ...
3628 * ALTER OPERATOR FAMILY ...
3629 * DROP OPERATOR CLASS ...
3630 * DROP OPERATOR FAMILY ...
3632 *****************************************************************************/
3635 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
3636 USING access_method opt_opfamily AS opclass_item_list
3638 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
3639 n->opclassname = $4;
3643 n->opfamilyname = $11;
3650 opclass_item { $$ = list_make1($1); }
3651 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
3655 OPERATOR Iconst any_operator opt_recheck
3657 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3658 n->itemtype = OPCLASS_ITEM_OPERATOR;
3664 | OPERATOR Iconst any_operator oper_argtypes opt_recheck
3666 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3667 n->itemtype = OPCLASS_ITEM_OPERATOR;
3673 | FUNCTION Iconst func_name func_args
3675 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3676 n->itemtype = OPCLASS_ITEM_FUNCTION;
3678 n->args = extractArgTypes($4);
3682 | FUNCTION Iconst '(' type_list ')' func_name func_args
3684 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3685 n->itemtype = OPCLASS_ITEM_FUNCTION;
3687 n->args = extractArgTypes($7);
3694 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3695 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
3701 opt_default: DEFAULT { $$ = TRUE; }
3702 | /*EMPTY*/ { $$ = FALSE; }
3705 opt_opfamily: FAMILY any_name { $$ = $2; }
3706 | /*EMPTY*/ { $$ = NIL; }
3709 opt_recheck: RECHECK
3712 * RECHECK no longer does anything in opclass definitions,
3713 * but we still accept it to ease porting of old database
3717 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3718 errmsg("RECHECK is no longer required"),
3719 errhint("Update your data type."),
3720 parser_errposition(@1)));
3723 | /*EMPTY*/ { $$ = FALSE; }
3728 CREATE OPERATOR FAMILY any_name USING access_method
3730 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
3731 n->opfamilyname = $4;
3738 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
3740 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3741 n->opfamilyname = $4;
3747 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
3749 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3750 n->opfamilyname = $4;
3759 opclass_drop { $$ = list_make1($1); }
3760 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
3764 OPERATOR Iconst '(' type_list ')'
3766 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3767 n->itemtype = OPCLASS_ITEM_OPERATOR;
3772 | FUNCTION Iconst '(' type_list ')'
3774 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3775 n->itemtype = OPCLASS_ITEM_FUNCTION;
3784 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
3786 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3787 n->opclassname = $4;
3790 n->missing_ok = false;
3793 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
3795 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3796 n->opclassname = $6;
3799 n->missing_ok = true;
3805 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
3807 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3808 n->opfamilyname = $4;
3811 n->missing_ok = false;
3814 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
3816 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3817 n->opfamilyname = $6;
3820 n->missing_ok = true;
3826 /*****************************************************************************
3830 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
3831 * REASSIGN OWNED BY username [, username ...] TO username
3833 *****************************************************************************/
3835 DROP OWNED BY name_list opt_drop_behavior
3837 DropOwnedStmt *n = makeNode(DropOwnedStmt);
3845 REASSIGN OWNED BY name_list TO name
3847 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
3854 /*****************************************************************************
3858 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
3859 * [ RESTRICT | CASCADE ]
3861 *****************************************************************************/
3863 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
3865 DropStmt *n = makeNode(DropStmt);
3867 n->missing_ok = TRUE;
3872 | DROP drop_type any_name_list opt_drop_behavior
3874 DropStmt *n = makeNode(DropStmt);
3876 n->missing_ok = FALSE;
3884 drop_type: TABLE { $$ = OBJECT_TABLE; }
3885 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
3886 | VIEW { $$ = OBJECT_VIEW; }
3887 | INDEX { $$ = OBJECT_INDEX; }
3888 | TYPE_P { $$ = OBJECT_TYPE; }
3889 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
3890 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
3891 | SCHEMA { $$ = OBJECT_SCHEMA; }
3892 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
3893 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
3894 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
3895 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
3899 any_name { $$ = list_make1($1); }
3900 | any_name_list ',' any_name { $$ = lappend($1, $3); }
3903 any_name: ColId { $$ = list_make1(makeString($1)); }
3904 | ColId attrs { $$ = lcons(makeString($1), $2); }
3907 attrs: '.' attr_name
3908 { $$ = list_make1(makeString($2)); }
3909 | attrs '.' attr_name
3910 { $$ = lappend($1, makeString($3)); }
3914 /*****************************************************************************
3917 * truncate table relname1, relname2, ...
3919 *****************************************************************************/
3922 TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
3924 TruncateStmt *n = makeNode(TruncateStmt);
3926 n->restart_seqs = $4;
3933 CONTINUE_P IDENTITY_P { $$ = false; }
3934 | RESTART IDENTITY_P { $$ = true; }
3935 | /* EMPTY */ { $$ = false; }
3938 /*****************************************************************************
3940 * The COMMENT ON statement can take different forms based upon the type of
3941 * the object associated with the comment. The form of the statement is:
3943 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
3944 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
3945 * CAST | COLUMN | SCHEMA | TABLESPACE | ROLE |
3946 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
3947 * TEXT SEARCH TEMPLATE |
3948 * TEXT SEARCH CONFIGURATION ] <objname> |
3949 * AGGREGATE <aggname> (arg1, ...) |
3950 * FUNCTION <funcname> (arg1, arg2, ...) |
3951 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
3952 * TRIGGER <triggername> ON <relname> |
3953 * CONSTRAINT <constraintname> ON <relname> |
3954 * RULE <rulename> ON <relname> ]
3957 *****************************************************************************/
3960 COMMENT ON comment_type any_name IS comment_text
3962 CommentStmt *n = makeNode(CommentStmt);
3969 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
3971 CommentStmt *n = makeNode(CommentStmt);
3972 n->objtype = OBJECT_AGGREGATE;
3978 | COMMENT ON FUNCTION func_name func_args IS comment_text
3980 CommentStmt *n = makeNode(CommentStmt);
3981 n->objtype = OBJECT_FUNCTION;
3983 n->objargs = extractArgTypes($5);
3987 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
3989 CommentStmt *n = makeNode(CommentStmt);
3990 n->objtype = OBJECT_OPERATOR;
3996 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
3998 CommentStmt *n = makeNode(CommentStmt);
3999 n->objtype = OBJECT_CONSTRAINT;
4000 n->objname = lappend($6, makeString($4));
4005 | COMMENT ON RULE name ON any_name IS comment_text
4007 CommentStmt *n = makeNode(CommentStmt);
4008 n->objtype = OBJECT_RULE;
4009 n->objname = lappend($6, makeString($4));
4014 | COMMENT ON RULE name IS comment_text
4016 /* Obsolete syntax supported for awhile for compatibility */
4017 CommentStmt *n = makeNode(CommentStmt);
4018 n->objtype = OBJECT_RULE;
4019 n->objname = list_make1(makeString($4));
4024 | COMMENT ON TRIGGER name ON any_name IS comment_text
4026 CommentStmt *n = makeNode(CommentStmt);
4027 n->objtype = OBJECT_TRIGGER;
4028 n->objname = lappend($6, makeString($4));
4033 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
4035 CommentStmt *n = makeNode(CommentStmt);
4036 n->objtype = OBJECT_OPCLASS;
4038 n->objargs = list_make1(makeString($7));
4042 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
4044 CommentStmt *n = makeNode(CommentStmt);
4045 n->objtype = OBJECT_OPFAMILY;
4047 n->objargs = list_make1(makeString($7));
4051 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
4053 CommentStmt *n = makeNode(CommentStmt);
4054 n->objtype = OBJECT_LARGEOBJECT;
4055 n->objname = list_make1($5);
4060 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
4062 CommentStmt *n = makeNode(CommentStmt);
4063 n->objtype = OBJECT_CAST;
4064 n->objname = list_make1($5);
4065 n->objargs = list_make1($7);
4069 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
4071 CommentStmt *n = makeNode(CommentStmt);
4072 n->objtype = OBJECT_LANGUAGE;
4078 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
4080 CommentStmt *n = makeNode(CommentStmt);
4081 n->objtype = OBJECT_TSPARSER;
4086 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
4088 CommentStmt *n = makeNode(CommentStmt);
4089 n->objtype = OBJECT_TSDICTIONARY;
4094 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
4096 CommentStmt *n = makeNode(CommentStmt);
4097 n->objtype = OBJECT_TSTEMPLATE;
4102 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
4104 CommentStmt *n = makeNode(CommentStmt);
4105 n->objtype = OBJECT_TSCONFIGURATION;
4113 COLUMN { $$ = OBJECT_COLUMN; }
4114 | DATABASE { $$ = OBJECT_DATABASE; }
4115 | SCHEMA { $$ = OBJECT_SCHEMA; }
4116 | INDEX { $$ = OBJECT_INDEX; }
4117 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4118 | TABLE { $$ = OBJECT_TABLE; }
4119 | DOMAIN_P { $$ = OBJECT_TYPE; }
4120 | TYPE_P { $$ = OBJECT_TYPE; }
4121 | VIEW { $$ = OBJECT_VIEW; }
4122 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4123 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
4124 | ROLE { $$ = OBJECT_ROLE; }
4129 | NULL_P { $$ = NULL; }
4132 /*****************************************************************************
4137 *****************************************************************************/
4139 FetchStmt: FETCH fetch_direction from_in name
4141 FetchStmt *n = (FetchStmt *) $2;
4148 FetchStmt *n = makeNode(FetchStmt);
4149 n->direction = FETCH_FORWARD;
4155 | MOVE fetch_direction from_in name
4157 FetchStmt *n = (FetchStmt *) $2;
4164 FetchStmt *n = makeNode(FetchStmt);
4165 n->direction = FETCH_FORWARD;
4176 FetchStmt *n = makeNode(FetchStmt);
4177 n->direction = FETCH_FORWARD;
4183 FetchStmt *n = makeNode(FetchStmt);
4184 n->direction = FETCH_FORWARD;
4190 FetchStmt *n = makeNode(FetchStmt);
4191 n->direction = FETCH_BACKWARD;
4197 FetchStmt *n = makeNode(FetchStmt);
4198 n->direction = FETCH_ABSOLUTE;
4204 FetchStmt *n = makeNode(FetchStmt);
4205 n->direction = FETCH_ABSOLUTE;
4209 | ABSOLUTE_P SignedIconst
4211 FetchStmt *n = makeNode(FetchStmt);
4212 n->direction = FETCH_ABSOLUTE;
4216 | RELATIVE_P SignedIconst
4218 FetchStmt *n = makeNode(FetchStmt);
4219 n->direction = FETCH_RELATIVE;
4225 FetchStmt *n = makeNode(FetchStmt);
4226 n->direction = FETCH_FORWARD;
4232 FetchStmt *n = makeNode(FetchStmt);
4233 n->direction = FETCH_FORWARD;
4234 n->howMany = FETCH_ALL;
4239 FetchStmt *n = makeNode(FetchStmt);
4240 n->direction = FETCH_FORWARD;
4244 | FORWARD SignedIconst
4246 FetchStmt *n = makeNode(FetchStmt);
4247 n->direction = FETCH_FORWARD;
4253 FetchStmt *n = makeNode(FetchStmt);
4254 n->direction = FETCH_FORWARD;
4255 n->howMany = FETCH_ALL;
4260 FetchStmt *n = makeNode(FetchStmt);
4261 n->direction = FETCH_BACKWARD;
4265 | BACKWARD SignedIconst
4267 FetchStmt *n = makeNode(FetchStmt);
4268 n->direction = FETCH_BACKWARD;
4274 FetchStmt *n = makeNode(FetchStmt);
4275 n->direction = FETCH_BACKWARD;
4276 n->howMany = FETCH_ALL;
4286 /*****************************************************************************
4288 * GRANT and REVOKE statements
4290 *****************************************************************************/
4292 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
4293 opt_grant_grant_option
4295 GrantStmt *n = makeNode(GrantStmt);
4298 n->objtype = ($4)->objtype;
4299 n->objects = ($4)->objs;
4301 n->grant_option = $7;
4307 REVOKE privileges ON privilege_target
4308 FROM grantee_list opt_drop_behavior
4310 GrantStmt *n = makeNode(GrantStmt);
4311 n->is_grant = false;
4312 n->grant_option = false;
4314 n->objtype = ($4)->objtype;
4315 n->objects = ($4)->objs;
4320 | REVOKE GRANT OPTION FOR privileges ON privilege_target
4321 FROM grantee_list opt_drop_behavior
4323 GrantStmt *n = makeNode(GrantStmt);
4324 n->is_grant = false;
4325 n->grant_option = true;
4327 n->objtype = ($7)->objtype;
4328 n->objects = ($7)->objs;
4337 * Privilege names are represented as strings; the validity of the privilege
4338 * names gets checked at execution. This is a bit annoying but we have little
4339 * choice because of the syntactic conflict with lists of role names in
4340 * GRANT/REVOKE. What's more, we have to call out in the "privilege"
4341 * production any reserved keywords that need to be usable as privilege names.
4344 /* either ALL [PRIVILEGES] or a list of individual privileges */
4345 privileges: privilege_list
4351 | ALL '(' columnList ')'
4353 AccessPriv *n = makeNode(AccessPriv);
4354 n->priv_name = NULL;
4358 | ALL PRIVILEGES '(' columnList ')'
4360 AccessPriv *n = makeNode(AccessPriv);
4361 n->priv_name = NULL;
4367 privilege_list: privilege { $$ = list_make1($1); }
4368 | privilege_list ',' privilege { $$ = lappend($1, $3); }
4371 privilege: SELECT opt_column_list
4373 AccessPriv *n = makeNode(AccessPriv);
4374 n->priv_name = pstrdup($1);
4378 | REFERENCES opt_column_list
4380 AccessPriv *n = makeNode(AccessPriv);
4381 n->priv_name = pstrdup($1);
4385 | CREATE opt_column_list
4387 AccessPriv *n = makeNode(AccessPriv);
4388 n->priv_name = pstrdup($1);
4392 | ColId opt_column_list
4394 AccessPriv *n = makeNode(AccessPriv);
4402 /* Don't bother trying to fold the first two rules into one using
4403 * opt_table. You're going to get conflicts.
4408 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4409 n->objtype = ACL_OBJECT_RELATION;
4413 | TABLE qualified_name_list
4415 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4416 n->objtype = ACL_OBJECT_RELATION;
4420 | SEQUENCE qualified_name_list
4422 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4423 n->objtype = ACL_OBJECT_SEQUENCE;
4427 | FOREIGN DATA_P WRAPPER name_list
4429 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4430 n->objtype = ACL_OBJECT_FDW;
4434 | FOREIGN SERVER name_list
4436 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4437 n->objtype = ACL_OBJECT_FOREIGN_SERVER;
4441 | FUNCTION function_with_argtypes_list
4443 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4444 n->objtype = ACL_OBJECT_FUNCTION;
4448 | DATABASE name_list
4450 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4451 n->objtype = ACL_OBJECT_DATABASE;
4455 | LANGUAGE name_list
4457 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4458 n->objtype = ACL_OBJECT_LANGUAGE;
4464 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4465 n->objtype = ACL_OBJECT_NAMESPACE;
4469 | TABLESPACE name_list
4471 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4472 n->objtype = ACL_OBJECT_TABLESPACE;
4480 grantee { $$ = list_make1($1); }
4481 | grantee_list ',' grantee { $$ = lappend($1, $3); }
4486 PrivGrantee *n = makeNode(PrivGrantee);
4487 /* This hack lets us avoid reserving PUBLIC as a keyword*/
4488 if (strcmp($1, "public") == 0)
4496 PrivGrantee *n = makeNode(PrivGrantee);
4497 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
4498 if (strcmp($2, "public") == 0)
4507 opt_grant_grant_option:
4508 WITH GRANT OPTION { $$ = TRUE; }
4509 | /*EMPTY*/ { $$ = FALSE; }
4512 function_with_argtypes_list:
4513 function_with_argtypes { $$ = list_make1($1); }
4514 | function_with_argtypes_list ',' function_with_argtypes
4515 { $$ = lappend($1, $3); }
4518 function_with_argtypes:
4521 FuncWithArgs *n = makeNode(FuncWithArgs);
4523 n->funcargs = extractArgTypes($2);
4528 /*****************************************************************************
4530 * GRANT and REVOKE ROLE statements
4532 *****************************************************************************/
4535 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4537 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4539 n->granted_roles = $2;
4540 n->grantee_roles = $4;
4548 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4550 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4551 n->is_grant = false;
4552 n->admin_opt = false;
4553 n->granted_roles = $2;
4554 n->grantee_roles = $4;
4558 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4560 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4561 n->is_grant = false;
4562 n->admin_opt = true;
4563 n->granted_roles = $5;
4564 n->grantee_roles = $7;
4570 opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
4571 | /*EMPTY*/ { $$ = FALSE; }
4574 opt_granted_by: GRANTED BY RoleId { $$ = $3; }
4575 | /*EMPTY*/ { $$ = NULL; }
4579 /*****************************************************************************
4581 * QUERY: CREATE INDEX
4583 * Note: we can't factor CONCURRENTLY into a separate production without
4584 * making it a reserved word.
4586 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
4587 * willing to make TABLESPACE a fully reserved word.
4588 *****************************************************************************/
4590 IndexStmt: CREATE index_opt_unique INDEX index_name
4591 ON qualified_name access_method_clause '(' index_params ')'
4592 opt_reloptions OptTableSpace where_clause
4594 IndexStmt *n = makeNode(IndexStmt);
4596 n->concurrent = false;
4599 n->accessMethod = $7;
4600 n->indexParams = $9;
4602 n->tableSpace = $12;
4603 n->whereClause = $13;
4606 | CREATE index_opt_unique INDEX CONCURRENTLY index_name
4607 ON qualified_name access_method_clause '(' index_params ')'
4608 opt_reloptions OptTableSpace where_clause
4610 IndexStmt *n = makeNode(IndexStmt);
4612 n->concurrent = true;
4615 n->accessMethod = $8;
4616 n->indexParams = $10;
4618 n->tableSpace = $13;
4619 n->whereClause = $14;
4625 UNIQUE { $$ = TRUE; }
4626 | /*EMPTY*/ { $$ = FALSE; }
4629 access_method_clause:
4630 USING access_method { $$ = $2; }
4631 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
4634 index_params: index_elem { $$ = list_make1($1); }
4635 | index_params ',' index_elem { $$ = lappend($1, $3); }
4639 * Index attributes can be either simple column references, or arbitrary
4640 * expressions in parens. For backwards-compatibility reasons, we allow
4641 * an expression that's just a function call to be written without parens.
4643 index_elem: ColId opt_class opt_asc_desc opt_nulls_order
4645 $$ = makeNode(IndexElem);
4650 $$->nulls_ordering = $4;
4652 | func_expr opt_class opt_asc_desc opt_nulls_order
4654 $$ = makeNode(IndexElem);
4659 $$->nulls_ordering = $4;
4661 | '(' a_expr ')' opt_class opt_asc_desc opt_nulls_order
4663 $$ = makeNode(IndexElem);
4668 $$->nulls_ordering = $6;
4672 opt_class: any_name { $$ = $1; }
4673 | USING any_name { $$ = $2; }
4674 | /*EMPTY*/ { $$ = NIL; }
4677 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
4678 | DESC { $$ = SORTBY_DESC; }
4679 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
4682 opt_nulls_order: NULLS_FIRST { $$ = SORTBY_NULLS_FIRST; }
4683 | NULLS_LAST { $$ = SORTBY_NULLS_LAST; }
4684 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
4688 /*****************************************************************************
4691 * create [or replace] function <fname>
4692 * [(<type-1> { , <type-n>})]
4694 * as <filename or code in language as appropriate>
4695 * language <lang> [with parameters]
4697 *****************************************************************************/
4700 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4701 RETURNS func_return createfunc_opt_list opt_definition
4703 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4712 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4713 RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
4715 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4718 n->parameters = mergeTableFuncParameters($5, $9);
4719 n->returnType = TableFuncTypeName($9);
4720 n->returnType->location = @7;
4722 n->withClause = $12;
4725 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4726 createfunc_opt_list opt_definition
4728 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4732 n->returnType = NULL;
4740 OR REPLACE { $$ = TRUE; }
4741 | /*EMPTY*/ { $$ = FALSE; }
4744 func_args: '(' func_args_list ')' { $$ = $2; }
4745 | '(' ')' { $$ = NIL; }
4749 func_arg { $$ = list_make1($1); }
4750 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
4754 * func_args_with_defaults is separate because we only want to accept
4755 * defaults in CREATE FUNCTION, not in ALTER etc.
4757 func_args_with_defaults:
4758 '(' func_args_with_defaults_list ')' { $$ = $2; }
4759 | '(' ')' { $$ = NIL; }
4762 func_args_with_defaults_list:
4763 func_arg_with_default { $$ = list_make1($1); }
4764 | func_args_with_defaults_list ',' func_arg_with_default
4765 { $$ = lappend($1, $3); }
4769 * The style with arg_class first is SQL99 standard, but Oracle puts
4770 * param_name first; accept both since it's likely people will try both
4771 * anyway. Don't bother trying to save productions by letting arg_class
4772 * have an empty alternative ... you'll get shift/reduce conflicts.
4774 * We can catch over-specified arguments here if we want to,
4775 * but for now better to silently swallow typmod, etc.
4776 * - thomas 2000-03-22
4779 arg_class param_name func_type
4781 FunctionParameter *n = makeNode(FunctionParameter);
4788 | param_name arg_class func_type
4790 FunctionParameter *n = makeNode(FunctionParameter);
4797 | param_name func_type
4799 FunctionParameter *n = makeNode(FunctionParameter);
4802 n->mode = FUNC_PARAM_IN;
4806 | arg_class func_type
4808 FunctionParameter *n = makeNode(FunctionParameter);
4817 FunctionParameter *n = makeNode(FunctionParameter);
4820 n->mode = FUNC_PARAM_IN;
4826 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
4827 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
4828 | OUT_P { $$ = FUNC_PARAM_OUT; }
4829 | INOUT { $$ = FUNC_PARAM_INOUT; }
4830 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
4831 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
4835 * Ideally param_name should be ColId, but that causes too many conflicts.
4837 param_name: type_function_name
4843 /* We can catch over-specified results here if we want to,
4844 * but for now better to silently swallow typmod, etc.
4845 * - thomas 2000-03-22
4852 * We would like to make the %TYPE productions here be ColId attrs etc,
4853 * but that causes reduce/reduce conflicts. type_function_name
4854 * is next best choice.
4856 func_type: Typename { $$ = $1; }
4857 | type_function_name attrs '%' TYPE_P
4859 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
4860 $$->pct_type = true;
4863 | SETOF type_function_name attrs '%' TYPE_P
4865 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
4866 $$->pct_type = true;
4872 func_arg_with_default:
4877 | func_arg DEFAULT a_expr
4882 | func_arg '=' a_expr
4890 createfunc_opt_list:
4891 /* Must be at least one to prevent conflict */
4892 createfunc_opt_item { $$ = list_make1($1); }
4893 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
4897 * Options common to both CREATE FUNCTION and ALTER FUNCTION
4899 common_func_opt_item:
4900 CALLED ON NULL_P INPUT_P
4902 $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
4904 | RETURNS NULL_P ON NULL_P INPUT_P
4906 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
4910 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
4914 $$ = makeDefElem("volatility", (Node *)makeString("immutable"));
4918 $$ = makeDefElem("volatility", (Node *)makeString("stable"));
4922 $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
4924 | EXTERNAL SECURITY DEFINER
4926 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
4928 | EXTERNAL SECURITY INVOKER
4930 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
4934 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
4938 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
4942 $$ = makeDefElem("cost", (Node *)$2);
4946 $$ = makeDefElem("rows", (Node *)$2);
4950 /* we abuse the normal content of a DefElem here */
4951 $$ = makeDefElem("set", (Node *)$1);
4955 createfunc_opt_item:
4958 $$ = makeDefElem("as", (Node *)$2);
4960 | LANGUAGE ColId_or_Sconst
4962 $$ = makeDefElem("language", (Node *)makeString($2));
4966 $$ = makeDefElem("window", (Node *)makeInteger(TRUE));
4968 | common_func_opt_item
4974 func_as: Sconst { $$ = list_make1(makeString($1)); }
4977 $$ = list_make2(makeString($1), makeString($3));
4982 WITH definition { $$ = $2; }
4983 | /*EMPTY*/ { $$ = NIL; }
4986 table_func_column: param_name func_type
4988 FunctionParameter *n = makeNode(FunctionParameter);
4991 n->mode = FUNC_PARAM_TABLE;
4997 table_func_column_list:
5000 $$ = list_make1($1);
5002 | table_func_column_list ',' table_func_column
5004 $$ = lappend($1, $3);
5008 /*****************************************************************************
5011 * RENAME and OWNER subcommands are already provided by the generic
5012 * ALTER infrastructure, here we just specify alterations that can
5013 * only be applied to functions.
5015 *****************************************************************************/
5017 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
5019 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
5027 /* At least one option must be specified */
5028 common_func_opt_item { $$ = list_make1($1); }
5029 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
5032 /* Ignored, merely for SQL compliance */
5039 /*****************************************************************************
5043 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
5044 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
5045 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
5047 *****************************************************************************/
5050 DROP FUNCTION func_name func_args opt_drop_behavior
5052 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5053 n->kind = OBJECT_FUNCTION;
5055 n->args = extractArgTypes($4);
5057 n->missing_ok = false;
5060 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
5062 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5063 n->kind = OBJECT_FUNCTION;
5065 n->args = extractArgTypes($6);
5067 n->missing_ok = true;
5073 DROP AGGREGATE func_name aggr_args opt_drop_behavior
5075 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5076 n->kind = OBJECT_AGGREGATE;
5080 n->missing_ok = false;
5083 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
5085 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5086 n->kind = OBJECT_AGGREGATE;
5090 n->missing_ok = true;
5096 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
5098 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5099 n->kind = OBJECT_OPERATOR;
5103 n->missing_ok = false;
5106 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
5108 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5109 n->kind = OBJECT_OPERATOR;
5113 n->missing_ok = true;
5122 (errcode(ERRCODE_SYNTAX_ERROR),
5123 errmsg("missing argument"),
5124 errhint("Use NONE to denote the missing argument of a unary operator."),
5125 parser_errposition(@3)));
5127 | '(' Typename ',' Typename ')'
5128 { $$ = list_make2($2, $4); }
5129 | '(' NONE ',' Typename ')' /* left unary */
5130 { $$ = list_make2(NULL, $4); }
5131 | '(' Typename ',' NONE ')' /* right unary */
5132 { $$ = list_make2($2, NULL); }
5137 { $$ = list_make1(makeString($1)); }
5138 | ColId '.' any_operator
5139 { $$ = lcons(makeString($1), $3); }
5143 /*****************************************************************************
5145 * CREATE CAST / DROP CAST
5147 *****************************************************************************/
5149 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
5150 WITH FUNCTION function_with_argtypes cast_context
5152 CreateCastStmt *n = makeNode(CreateCastStmt);
5156 n->context = (CoercionContext) $11;
5160 | CREATE CAST '(' Typename AS Typename ')'
5161 WITHOUT FUNCTION cast_context
5163 CreateCastStmt *n = makeNode(CreateCastStmt);
5167 n->context = (CoercionContext) $10;
5171 | CREATE CAST '(' Typename AS Typename ')'
5172 WITH INOUT cast_context
5174 CreateCastStmt *n = makeNode(CreateCastStmt);
5178 n->context = (CoercionContext) $10;
5184 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
5185 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
5186 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
5190 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
5192 DropCastStmt *n = makeNode(DropCastStmt);
5201 opt_if_exists: IF_P EXISTS { $$ = TRUE; }
5202 | /*EMPTY*/ { $$ = FALSE; }
5206 /*****************************************************************************
5210 * REINDEX type <name> [FORCE]
5212 * FORCE no longer does anything, but we accept it for backwards compatibility
5213 *****************************************************************************/
5216 REINDEX reindex_type qualified_name opt_force
5218 ReindexStmt *n = makeNode(ReindexStmt);
5224 | REINDEX SYSTEM_P name opt_force
5226 ReindexStmt *n = makeNode(ReindexStmt);
5227 n->kind = OBJECT_DATABASE;
5230 n->do_system = true;
5234 | REINDEX DATABASE name opt_force
5236 ReindexStmt *n = makeNode(ReindexStmt);
5237 n->kind = OBJECT_DATABASE;
5240 n->do_system = true;
5247 INDEX { $$ = OBJECT_INDEX; }
5248 | TABLE { $$ = OBJECT_TABLE; }
5251 opt_force: FORCE { $$ = TRUE; }
5252 | /* EMPTY */ { $$ = FALSE; }
5256 /*****************************************************************************
5258 * ALTER THING name RENAME TO newname
5260 *****************************************************************************/
5262 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
5264 RenameStmt *n = makeNode(RenameStmt);
5265 n->renameType = OBJECT_AGGREGATE;
5271 | ALTER CONVERSION_P any_name RENAME TO name
5273 RenameStmt *n = makeNode(RenameStmt);
5274 n->renameType = OBJECT_CONVERSION;
5279 | ALTER DATABASE database_name RENAME TO database_name
5281 RenameStmt *n = makeNode(RenameStmt);
5282 n->renameType = OBJECT_DATABASE;
5287 | ALTER FUNCTION function_with_argtypes RENAME TO name
5289 RenameStmt *n = makeNode(RenameStmt);
5290 n->renameType = OBJECT_FUNCTION;
5291 n->object = $3->funcname;
5292 n->objarg = $3->funcargs;
5296 | ALTER GROUP_P RoleId RENAME TO RoleId
5298 RenameStmt *n = makeNode(RenameStmt);
5299 n->renameType = OBJECT_ROLE;
5304 | ALTER opt_procedural LANGUAGE name RENAME TO name
5306 RenameStmt *n = makeNode(RenameStmt);
5307 n->renameType = OBJECT_LANGUAGE;
5312 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
5314 RenameStmt *n = makeNode(RenameStmt);
5315 n->renameType = OBJECT_OPCLASS;
5321 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
5323 RenameStmt *n = makeNode(RenameStmt);
5324 n->renameType = OBJECT_OPFAMILY;
5330 | ALTER SCHEMA name RENAME TO name
5332 RenameStmt *n = makeNode(RenameStmt);
5333 n->renameType = OBJECT_SCHEMA;
5338 | ALTER TABLE relation_expr RENAME TO name
5340 RenameStmt *n = makeNode(RenameStmt);
5341 n->renameType = OBJECT_TABLE;
5347 | ALTER SEQUENCE qualified_name RENAME TO name
5349 RenameStmt *n = makeNode(RenameStmt);
5350 n->renameType = OBJECT_SEQUENCE;
5356 | ALTER VIEW qualified_name RENAME TO name
5358 RenameStmt *n = makeNode(RenameStmt);
5359 n->renameType = OBJECT_VIEW;
5365 | ALTER INDEX qualified_name RENAME TO name
5367 RenameStmt *n = makeNode(RenameStmt);
5368 n->renameType = OBJECT_INDEX;
5374 | ALTER TABLE relation_expr RENAME opt_column name TO name
5376 RenameStmt *n = makeNode(RenameStmt);
5377 n->renameType = OBJECT_COLUMN;
5383 | ALTER TRIGGER name ON qualified_name RENAME TO name
5385 RenameStmt *n = makeNode(RenameStmt);
5386 n->renameType = OBJECT_TRIGGER;
5392 | ALTER ROLE RoleId RENAME TO RoleId
5394 RenameStmt *n = makeNode(RenameStmt);
5395 n->renameType = OBJECT_ROLE;
5400 | ALTER USER RoleId RENAME TO RoleId
5402 RenameStmt *n = makeNode(RenameStmt);
5403 n->renameType = OBJECT_ROLE;
5408 | ALTER TABLESPACE name RENAME TO name
5410 RenameStmt *n = makeNode(RenameStmt);
5411 n->renameType = OBJECT_TABLESPACE;
5416 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
5418 RenameStmt *n = makeNode(RenameStmt);
5419 n->renameType = OBJECT_TSPARSER;
5424 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
5426 RenameStmt *n = makeNode(RenameStmt);
5427 n->renameType = OBJECT_TSDICTIONARY;
5432 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
5434 RenameStmt *n = makeNode(RenameStmt);
5435 n->renameType = OBJECT_TSTEMPLATE;
5440 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
5442 RenameStmt *n = makeNode(RenameStmt);
5443 n->renameType = OBJECT_TSCONFIGURATION;
5448 | ALTER TYPE_P any_name RENAME TO name
5450 RenameStmt *n = makeNode(RenameStmt);
5451 n->renameType = OBJECT_TYPE;
5458 opt_column: COLUMN { $$ = COLUMN; }
5459 | /*EMPTY*/ { $$ = 0; }
5462 opt_set_data: SET DATA_P { $$ = 1; }
5463 | /*EMPTY*/ { $$ = 0; }
5466 /*****************************************************************************
5468 * ALTER THING name SET SCHEMA name
5470 *****************************************************************************/
5472 AlterObjectSchemaStmt:
5473 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
5475 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5476 n->objectType = OBJECT_AGGREGATE;
5482 | ALTER DOMAIN_P any_name SET SCHEMA name
5484 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5485 n->objectType = OBJECT_DOMAIN;
5490 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
5492 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5493 n->objectType = OBJECT_FUNCTION;
5494 n->object = $3->funcname;
5495 n->objarg = $3->funcargs;
5499 | ALTER TABLE relation_expr SET SCHEMA name
5501 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5502 n->objectType = OBJECT_TABLE;
5507 | ALTER SEQUENCE qualified_name SET SCHEMA name
5509 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5510 n->objectType = OBJECT_SEQUENCE;
5515 | ALTER VIEW qualified_name SET SCHEMA name
5517 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5518 n->objectType = OBJECT_VIEW;
5523 | ALTER TYPE_P any_name SET SCHEMA name
5525 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5526 n->objectType = OBJECT_TYPE;
5533 /*****************************************************************************
5535 * ALTER THING name OWNER TO newname
5537 *****************************************************************************/
5539 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
5541 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5542 n->objectType = OBJECT_AGGREGATE;
5548 | ALTER CONVERSION_P any_name OWNER TO RoleId
5550 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5551 n->objectType = OBJECT_CONVERSION;
5556 | ALTER DATABASE database_name OWNER TO RoleId
5558 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5559 n->objectType = OBJECT_DATABASE;
5560 n->object = list_make1(makeString($3));
5564 | ALTER DOMAIN_P any_name OWNER TO RoleId
5566 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5567 n->objectType = OBJECT_DOMAIN;
5572 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
5574 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5575 n->objectType = OBJECT_FUNCTION;
5576 n->object = $3->funcname;
5577 n->objarg = $3->funcargs;
5581 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
5583 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5584 n->objectType = OBJECT_LANGUAGE;
5585 n->object = list_make1(makeString($4));
5589 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
5591 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5592 n->objectType = OBJECT_OPERATOR;
5598 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
5600 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5601 n->objectType = OBJECT_OPCLASS;
5607 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
5609 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5610 n->objectType = OBJECT_OPFAMILY;
5616 | ALTER SCHEMA name OWNER TO RoleId
5618 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5619 n->objectType = OBJECT_SCHEMA;
5620 n->object = list_make1(makeString($3));
5624 | ALTER TYPE_P any_name OWNER TO RoleId
5626 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5627 n->objectType = OBJECT_TYPE;
5632 | ALTER TABLESPACE name OWNER TO RoleId
5634 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5635 n->objectType = OBJECT_TABLESPACE;
5636 n->object = list_make1(makeString($3));
5640 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
5642 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5643 n->objectType = OBJECT_TSDICTIONARY;
5648 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
5650 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5651 n->objectType = OBJECT_TSCONFIGURATION;
5656 | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleId
5658 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5659 n->objectType = OBJECT_FDW;
5660 n->object = list_make1(makeString($5));
5664 | ALTER SERVER name OWNER TO RoleId
5666 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5667 n->objectType = OBJECT_FOREIGN_SERVER;
5668 n->object = list_make1(makeString($3));
5675 /*****************************************************************************
5677 * QUERY: Define Rewrite Rule
5679 *****************************************************************************/
5681 RuleStmt: CREATE opt_or_replace RULE name AS
5682 { pg_yyget_extra(yyscanner)->QueryIsRule = TRUE; }
5683 ON event TO qualified_name where_clause
5684 DO opt_instead RuleActionList
5686 RuleStmt *n = makeNode(RuleStmt);
5690 n->whereClause = $11;
5695 pg_yyget_extra(yyscanner)->QueryIsRule = FALSE;
5700 NOTHING { $$ = NIL; }
5701 | RuleActionStmt { $$ = list_make1($1); }
5702 | '(' RuleActionMulti ')' { $$ = $2; }
5705 /* the thrashing around here is to discard "empty" statements... */
5707 RuleActionMulti ';' RuleActionStmtOrEmpty
5709 $$ = lappend($1, $3);
5713 | RuleActionStmtOrEmpty
5715 $$ = list_make1($1);
5729 RuleActionStmtOrEmpty:
5730 RuleActionStmt { $$ = $1; }
5731 | /*EMPTY*/ { $$ = NULL; }
5734 event: SELECT { $$ = CMD_SELECT; }
5735 | UPDATE { $$ = CMD_UPDATE; }
5736 | DELETE_P { $$ = CMD_DELETE; }
5737 | INSERT { $$ = CMD_INSERT; }
5741 INSTEAD { $$ = TRUE; }
5742 | ALSO { $$ = FALSE; }
5743 | /*EMPTY*/ { $$ = FALSE; }
5748 DROP RULE name ON qualified_name opt_drop_behavior
5750 DropPropertyStmt *n = makeNode(DropPropertyStmt);
5754 n->removeType = OBJECT_RULE;
5755 n->missing_ok = false;
5758 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
5760 DropPropertyStmt *n = makeNode(DropPropertyStmt);
5764 n->removeType = OBJECT_RULE;
5765 n->missing_ok = true;
5771 /*****************************************************************************
5774 * NOTIFY <identifier> can appear both in rule bodies and
5775 * as a query-level command
5777 *****************************************************************************/
5779 NotifyStmt: NOTIFY ColId
5781 NotifyStmt *n = makeNode(NotifyStmt);
5782 n->conditionname = $2;
5787 ListenStmt: LISTEN ColId
5789 ListenStmt *n = makeNode(ListenStmt);
5790 n->conditionname = $2;
5798 UnlistenStmt *n = makeNode(UnlistenStmt);
5799 n->conditionname = $2;
5804 UnlistenStmt *n = makeNode(UnlistenStmt);
5805 n->conditionname = NULL;
5811 /*****************************************************************************
5815 * BEGIN / COMMIT / ROLLBACK
5816 * (also older versions END / ABORT)
5818 *****************************************************************************/
5821 ABORT_P opt_transaction
5823 TransactionStmt *n = makeNode(TransactionStmt);
5824 n->kind = TRANS_STMT_ROLLBACK;
5828 | BEGIN_P opt_transaction transaction_mode_list_or_empty
5830 TransactionStmt *n = makeNode(TransactionStmt);
5831 n->kind = TRANS_STMT_BEGIN;
5835 | START TRANSACTION transaction_mode_list_or_empty
5837 TransactionStmt *n = makeNode(TransactionStmt);
5838 n->kind = TRANS_STMT_START;
5842 | COMMIT opt_transaction
5844 TransactionStmt *n = makeNode(TransactionStmt);
5845 n->kind = TRANS_STMT_COMMIT;
5849 | END_P opt_transaction
5851 TransactionStmt *n = makeNode(TransactionStmt);
5852 n->kind = TRANS_STMT_COMMIT;
5856 | ROLLBACK opt_transaction
5858 TransactionStmt *n = makeNode(TransactionStmt);
5859 n->kind = TRANS_STMT_ROLLBACK;
5865 TransactionStmt *n = makeNode(TransactionStmt);
5866 n->kind = TRANS_STMT_SAVEPOINT;
5867 n->options = list_make1(makeDefElem("savepoint_name",
5868 (Node *)makeString($2)));
5871 | RELEASE SAVEPOINT ColId
5873 TransactionStmt *n = makeNode(TransactionStmt);
5874 n->kind = TRANS_STMT_RELEASE;
5875 n->options = list_make1(makeDefElem("savepoint_name",
5876 (Node *)makeString($3)));
5881 TransactionStmt *n = makeNode(TransactionStmt);
5882 n->kind = TRANS_STMT_RELEASE;
5883 n->options = list_make1(makeDefElem("savepoint_name",
5884 (Node *)makeString($2)));
5887 | ROLLBACK opt_transaction TO SAVEPOINT ColId
5889 TransactionStmt *n = makeNode(TransactionStmt);
5890 n->kind = TRANS_STMT_ROLLBACK_TO;
5891 n->options = list_make1(makeDefElem("savepoint_name",
5892 (Node *)makeString($5)));
5895 | ROLLBACK opt_transaction TO ColId
5897 TransactionStmt *n = makeNode(TransactionStmt);
5898 n->kind = TRANS_STMT_ROLLBACK_TO;
5899 n->options = list_make1(makeDefElem("savepoint_name",
5900 (Node *)makeString($4)));
5903 | PREPARE TRANSACTION Sconst
5905 TransactionStmt *n = makeNode(TransactionStmt);
5906 n->kind = TRANS_STMT_PREPARE;
5910 | COMMIT PREPARED Sconst
5912 TransactionStmt *n = makeNode(TransactionStmt);
5913 n->kind = TRANS_STMT_COMMIT_PREPARED;
5917 | ROLLBACK PREPARED Sconst
5919 TransactionStmt *n = makeNode(TransactionStmt);
5920 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
5926 opt_transaction: WORK {}
5931 transaction_mode_item:
5932 ISOLATION LEVEL iso_level
5933 { $$ = makeDefElem("transaction_isolation",
5934 makeStringConst($3, @3)); }
5936 { $$ = makeDefElem("transaction_read_only",
5937 makeIntConst(TRUE, @1)); }
5939 { $$ = makeDefElem("transaction_read_only",
5940 makeIntConst(FALSE, @1)); }
5943 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
5944 transaction_mode_list:
5945 transaction_mode_item
5946 { $$ = list_make1($1); }
5947 | transaction_mode_list ',' transaction_mode_item
5948 { $$ = lappend($1, $3); }
5949 | transaction_mode_list transaction_mode_item
5950 { $$ = lappend($1, $2); }
5953 transaction_mode_list_or_empty:
5954 transaction_mode_list
5960 /*****************************************************************************
5963 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
5964 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
5966 *****************************************************************************/
5968 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
5969 AS SelectStmt opt_check_option
5971 ViewStmt *n = makeNode(ViewStmt);
5973 n->view->istemp = $2;
5979 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
5980 AS SelectStmt opt_check_option
5982 ViewStmt *n = makeNode(ViewStmt);
5984 n->view->istemp = $4;
5996 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5997 errmsg("WITH CHECK OPTION is not implemented")));
5999 | WITH CASCADED CHECK OPTION
6002 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6003 errmsg("WITH CHECK OPTION is not implemented")));
6005 | WITH LOCAL CHECK OPTION
6008 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6009 errmsg("WITH CHECK OPTION is not implemented")));
6011 | /* EMPTY */ { $$ = NIL; }
6014 /*****************************************************************************
6019 *****************************************************************************/
6021 LoadStmt: LOAD file_name
6023 LoadStmt *n = makeNode(LoadStmt);
6030 /*****************************************************************************
6034 *****************************************************************************/
6037 CREATE DATABASE database_name opt_with createdb_opt_list
6039 CreatedbStmt *n = makeNode(CreatedbStmt);
6047 createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
6048 | /* EMPTY */ { $$ = NIL; }
6052 TABLESPACE opt_equal name
6054 $$ = makeDefElem("tablespace", (Node *)makeString($3));
6056 | TABLESPACE opt_equal DEFAULT
6058 $$ = makeDefElem("tablespace", NULL);
6060 | LOCATION opt_equal Sconst
6062 $$ = makeDefElem("location", (Node *)makeString($3));
6064 | LOCATION opt_equal DEFAULT
6066 $$ = makeDefElem("location", NULL);
6068 | TEMPLATE opt_equal name
6070 $$ = makeDefElem("template", (Node *)makeString($3));
6072 | TEMPLATE opt_equal DEFAULT
6074 $$ = makeDefElem("template", NULL);
6076 | ENCODING opt_equal Sconst
6078 $$ = makeDefElem("encoding", (Node *)makeString($3));
6080 | ENCODING opt_equal Iconst
6082 $$ = makeDefElem("encoding", (Node *)makeInteger($3));
6084 | ENCODING opt_equal DEFAULT
6086 $$ = makeDefElem("encoding", NULL);
6088 | LC_COLLATE_P opt_equal Sconst
6090 $$ = makeDefElem("lc_collate", (Node *)makeString($3));
6092 | LC_COLLATE_P opt_equal DEFAULT
6094 $$ = makeDefElem("lc_collate", NULL);
6096 | LC_CTYPE_P opt_equal Sconst
6098 $$ = makeDefElem("lc_ctype", (Node *)makeString($3));
6100 | LC_CTYPE_P opt_equal DEFAULT
6102 $$ = makeDefElem("lc_ctype", NULL);
6104 | CONNECTION LIMIT opt_equal SignedIconst
6106 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6108 | OWNER opt_equal name
6110 $$ = makeDefElem("owner", (Node *)makeString($3));
6112 | OWNER opt_equal DEFAULT
6114 $$ = makeDefElem("owner", NULL);
6119 * Though the equals sign doesn't match other WITH options, pg_dump uses
6120 * equals for backward compatibility, and it doesn't seem worth removing it.
6127 /*****************************************************************************
6131 *****************************************************************************/
6134 ALTER DATABASE database_name opt_with alterdb_opt_list
6136 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6141 | ALTER DATABASE database_name SET TABLESPACE name
6143 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6145 n->options = list_make1(makeDefElem("tablespace",
6146 (Node *)makeString($6)));
6151 AlterDatabaseSetStmt:
6152 ALTER DATABASE database_name SetResetClause
6154 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
6163 alterdb_opt_list alterdb_opt_item { $$ = lappend($1, $2); }
6164 | /* EMPTY */ { $$ = NIL; }
6168 CONNECTION LIMIT opt_equal SignedIconst
6170 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6175 /*****************************************************************************
6177 * DROP DATABASE [ IF EXISTS ]
6179 * This is implicitly CASCADE, no need for drop behavior
6180 *****************************************************************************/
6182 DropdbStmt: DROP DATABASE database_name
6184 DropdbStmt *n = makeNode(DropdbStmt);
6186 n->missing_ok = FALSE;
6189 | DROP DATABASE IF_P EXISTS database_name
6191 DropdbStmt *n = makeNode(DropdbStmt);
6193 n->missing_ok = TRUE;
6199 /*****************************************************************************
6201 * Manipulate a domain
6203 *****************************************************************************/
6206 CREATE DOMAIN_P any_name opt_as Typename ColQualList
6208 CreateDomainStmt *n = makeNode(CreateDomainStmt);
6211 n->constraints = $6;
6217 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
6218 ALTER DOMAIN_P any_name alter_column_default
6220 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6226 /* ALTER DOMAIN <domain> DROP NOT NULL */
6227 | ALTER DOMAIN_P any_name DROP NOT NULL_P
6229 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6234 /* ALTER DOMAIN <domain> SET NOT NULL */
6235 | ALTER DOMAIN_P any_name SET NOT NULL_P
6237 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6242 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
6243 | ALTER DOMAIN_P any_name ADD_P TableConstraint
6245 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6251 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
6252 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
6254 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6268 /*****************************************************************************
6270 * Manipulate a text search dictionary or configuration
6272 *****************************************************************************/
6274 AlterTSDictionaryStmt:
6275 ALTER TEXT_P SEARCH DICTIONARY any_name definition
6277 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
6284 AlterTSConfigurationStmt:
6285 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
6287 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6291 n->override = false;
6295 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
6297 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6305 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
6307 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6310 n->dicts = list_make2($9,$11);
6311 n->override = false;
6315 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
6317 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6320 n->dicts = list_make2($11,$13);
6321 n->override = false;
6325 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
6327 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6330 n->missing_ok = false;
6333 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
6335 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6338 n->missing_ok = true;
6344 /*****************************************************************************
6346 * Manipulate a conversion
6348 * CREATE [DEFAULT] CONVERSION <conversion_name>
6349 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
6351 *****************************************************************************/
6353 CreateConversionStmt:
6354 CREATE opt_default CONVERSION_P any_name FOR Sconst
6355 TO Sconst FROM any_name
6357 CreateConversionStmt *n = makeNode(CreateConversionStmt);
6358 n->conversion_name = $4;
6359 n->for_encoding_name = $6;
6360 n->to_encoding_name = $8;
6367 /*****************************************************************************
6370 * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
6372 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
6374 *****************************************************************************/
6377 CLUSTER opt_verbose qualified_name cluster_index_specification
6379 ClusterStmt *n = makeNode(ClusterStmt);
6385 | CLUSTER opt_verbose
6387 ClusterStmt *n = makeNode(ClusterStmt);
6389 n->indexname = NULL;
6393 /* kept for pre-8.3 compatibility */
6394 | CLUSTER opt_verbose index_name ON qualified_name
6396 ClusterStmt *n = makeNode(ClusterStmt);
6404 cluster_index_specification:
6405 USING index_name { $$ = $2; }
6406 | /*EMPTY*/ { $$ = NULL; }
6410 /*****************************************************************************
6416 *****************************************************************************/
6418 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
6420 VacuumStmt *n = makeNode(VacuumStmt);
6424 n->freeze_min_age = $3 ? 0 : -1;
6425 n->freeze_table_age = $3 ? 0 : -1;
6431 | VACUUM opt_full opt_freeze opt_verbose qualified_name
6433 VacuumStmt *n = makeNode(VacuumStmt);
6437 n->freeze_min_age = $3 ? 0 : -1;
6438 n->freeze_table_age = $3 ? 0 : -1;
6444 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
6446 VacuumStmt *n = (VacuumStmt *) $5;
6449 n->freeze_min_age = $3 ? 0 : -1;
6450 n->freeze_table_age = $3 ? 0 : -1;
6457 analyze_keyword opt_verbose
6459 VacuumStmt *n = makeNode(VacuumStmt);
6463 n->freeze_min_age = -1;
6464 n->freeze_table_age = -1;
6470 | analyze_keyword opt_verbose qualified_name opt_name_list
6472 VacuumStmt *n = makeNode(VacuumStmt);
6476 n->freeze_min_age = -1;
6477 n->freeze_table_age = -1;
6487 | ANALYSE /* British */ {}
6491 VERBOSE { $$ = TRUE; }
6492 | /*EMPTY*/ { $$ = FALSE; }
6495 opt_full: FULL { $$ = TRUE; }
6496 | /*EMPTY*/ { $$ = FALSE; }
6499 opt_freeze: FREEZE { $$ = TRUE; }
6500 | /*EMPTY*/ { $$ = FALSE; }
6504 '(' name_list ')' { $$ = $2; }
6505 | /*EMPTY*/ { $$ = NIL; }
6509 /*****************************************************************************
6512 * EXPLAIN [ANALYZE] [VERBOSE] query
6513 * EXPLAIN ( options ) query
6515 *****************************************************************************/
6518 EXPLAIN ExplainableStmt
6520 ExplainStmt *n = makeNode(ExplainStmt);
6525 | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
6527 ExplainStmt *n = makeNode(ExplainStmt);
6529 n->options = list_make1(makeDefElem("analyze", NULL));
6531 n->options = lappend(n->options,
6532 makeDefElem("verbose", NULL));
6535 | EXPLAIN VERBOSE ExplainableStmt
6537 ExplainStmt *n = makeNode(ExplainStmt);
6539 n->options = list_make1(makeDefElem("verbose", NULL));
6542 | EXPLAIN '(' explain_option_list ')' ExplainableStmt
6544 ExplainStmt *n = makeNode(ExplainStmt);
6558 | ExecuteStmt /* by default all are $$=$1 */
6561 explain_option_list:
6564 $$ = list_make1($1);
6566 | explain_option_list ',' explain_option_elem
6568 $$ = lappend($1, $3);
6572 explain_option_elem:
6573 explain_option_name explain_option_arg
6575 $$ = makeDefElem($1, $2);
6579 explain_option_name:
6581 | analyze_keyword { $$ = "analyze"; }
6582 | VERBOSE { $$ = "verbose"; }
6586 opt_boolean { $$ = (Node *) makeString($1); }
6587 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
6588 | NumericOnly { $$ = (Node *) $1; }
6589 | /* EMPTY */ { $$ = NULL; }
6592 /*****************************************************************************
6595 * PREPARE <plan_name> [(args, ...)] AS <query>
6597 *****************************************************************************/
6599 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
6601 PrepareStmt *n = makeNode(PrepareStmt);
6609 prep_type_clause: '(' type_list ')' { $$ = $2; }
6610 | /* EMPTY */ { $$ = NIL; }
6617 | DeleteStmt /* by default all are $$=$1 */
6620 /*****************************************************************************
6622 * EXECUTE <plan_name> [(params, ...)]
6623 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
6625 *****************************************************************************/
6627 ExecuteStmt: EXECUTE name execute_param_clause
6629 ExecuteStmt *n = makeNode(ExecuteStmt);
6635 | CREATE OptTemp TABLE create_as_target AS
6636 EXECUTE name execute_param_clause
6638 ExecuteStmt *n = makeNode(ExecuteStmt);
6641 $4->rel->istemp = $2;
6645 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6646 errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
6647 /* ... because it's not implemented, but it could be */
6652 execute_param_clause: '(' expr_list ')' { $$ = $2; }
6653 | /* EMPTY */ { $$ = NIL; }
6656 /*****************************************************************************
6659 * DEALLOCATE [PREPARE] <plan_name>
6661 *****************************************************************************/
6663 DeallocateStmt: DEALLOCATE name
6665 DeallocateStmt *n = makeNode(DeallocateStmt);
6669 | DEALLOCATE PREPARE name
6671 DeallocateStmt *n = makeNode(DeallocateStmt);
6677 DeallocateStmt *n = makeNode(DeallocateStmt);
6681 | DEALLOCATE PREPARE ALL
6683 DeallocateStmt *n = makeNode(DeallocateStmt);
6689 /*****************************************************************************
6694 *****************************************************************************/
6697 INSERT INTO qualified_name insert_rest returning_clause
6700 $4->returningList = $5;
6708 $$ = makeNode(InsertStmt);
6710 $$->selectStmt = $1;
6712 | '(' insert_column_list ')' SelectStmt
6714 $$ = makeNode(InsertStmt);
6716 $$->selectStmt = $4;
6720 $$ = makeNode(InsertStmt);
6722 $$->selectStmt = NULL;
6728 { $$ = list_make1($1); }
6729 | insert_column_list ',' insert_column_item
6730 { $$ = lappend($1, $3); }
6734 ColId opt_indirection
6736 $$ = makeNode(ResTarget);
6738 $$->indirection = check_indirection($2, yyscanner);
6745 RETURNING target_list { $$ = $2; }
6746 | /* EMPTY */ { $$ = NIL; }
6750 /*****************************************************************************
6755 *****************************************************************************/
6757 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
6758 using_clause where_or_current_clause returning_clause
6760 DeleteStmt *n = makeNode(DeleteStmt);
6762 n->usingClause = $4;
6763 n->whereClause = $5;
6764 n->returningList = $6;
6770 USING from_list { $$ = $2; }
6771 | /*EMPTY*/ { $$ = NIL; }
6775 /*****************************************************************************
6780 *****************************************************************************/
6782 LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
6784 LockStmt *n = makeNode(LockStmt);
6793 opt_lock: IN_P lock_type MODE { $$ = $2; }
6794 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
6797 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
6798 | ROW SHARE { $$ = RowShareLock; }
6799 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
6800 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
6801 | SHARE { $$ = ShareLock; }
6802 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
6803 | EXCLUSIVE { $$ = ExclusiveLock; }
6804 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
6807 opt_nowait: NOWAIT { $$ = TRUE; }
6808 | /*EMPTY*/ { $$ = FALSE; }
6812 /*****************************************************************************
6815 * UpdateStmt (UPDATE)
6817 *****************************************************************************/
6819 UpdateStmt: UPDATE relation_expr_opt_alias
6822 where_or_current_clause
6825 UpdateStmt *n = makeNode(UpdateStmt);
6829 n->whereClause = $6;
6830 n->returningList = $7;
6836 set_clause { $$ = $1; }
6837 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
6841 single_set_clause { $$ = list_make1($1); }
6842 | multiple_set_clause { $$ = $1; }
6846 set_target '=' ctext_expr
6849 $$->val = (Node *) $3;
6853 multiple_set_clause:
6854 '(' set_target_list ')' '=' ctext_row
6860 * Break the ctext_row apart, merge individual expressions
6861 * into the destination ResTargets. XXX this approach
6862 * cannot work for general row expressions as sources.
6864 if (list_length($2) != list_length($5))
6866 (errcode(ERRCODE_SYNTAX_ERROR),
6867 errmsg("number of columns does not match number of values"),
6868 parser_errposition(@1)));
6869 forboth(col_cell, $2, val_cell, $5)
6871 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
6872 Node *res_val = (Node *) lfirst(val_cell);
6874 res_col->val = res_val;
6882 ColId opt_indirection
6884 $$ = makeNode(ResTarget);
6886 $$->indirection = check_indirection($2, yyscanner);
6887 $$->val = NULL; /* upper production sets this */
6893 set_target { $$ = list_make1($1); }
6894 | set_target_list ',' set_target { $$ = lappend($1,$3); }
6898 /*****************************************************************************
6903 *****************************************************************************/
6904 DeclareCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR SelectStmt
6906 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
6908 /* currently we always set FAST_PLAN option */
6909 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
6915 cursor_options: /*EMPTY*/ { $$ = 0; }
6916 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
6917 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
6918 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
6919 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
6922 opt_hold: /* EMPTY */ { $$ = 0; }
6923 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
6924 | WITHOUT HOLD { $$ = 0; }
6927 /*****************************************************************************
6932 *****************************************************************************/
6934 /* A complete SELECT statement looks like this.
6936 * The rule returns either a single SelectStmt node or a tree of them,
6937 * representing a set-operation tree.
6939 * There is an ambiguity when a sub-SELECT is within an a_expr and there
6940 * are excess parentheses: do the parentheses belong to the sub-SELECT or
6941 * to the surrounding a_expr? We don't really care, but bison wants to know.
6942 * To resolve the ambiguity, we are careful to define the grammar so that
6943 * the decision is staved off as long as possible: as long as we can keep
6944 * absorbing parentheses into the sub-SELECT, we will do so, and only when
6945 * it's no longer possible to do that will we decide that parens belong to
6946 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
6947 * parentheses are treated as part of the sub-select. The necessity of doing
6948 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
6949 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
6950 * SELECT viewpoint when we see the UNION.
6952 * This approach is implemented by defining a nonterminal select_with_parens,
6953 * which represents a SELECT with at least one outer layer of parentheses,
6954 * and being careful to use select_with_parens, never '(' SelectStmt ')',
6955 * in the expression grammar. We will then have shift-reduce conflicts
6956 * which we can resolve in favor of always treating '(' <select> ')' as
6957 * a select_with_parens. To resolve the conflicts, the productions that
6958 * conflict with the select_with_parens productions are manually given
6959 * precedences lower than the precedence of ')', thereby ensuring that we
6960 * shift ')' (and then reduce to select_with_parens) rather than trying to
6961 * reduce the inner <select> nonterminal to something else. We use UMINUS
6962 * precedence for this, which is a fairly arbitrary choice.
6964 * To be able to define select_with_parens itself without ambiguity, we need
6965 * a nonterminal select_no_parens that represents a SELECT structure with no
6966 * outermost parentheses. This is a little bit tedious, but it works.
6968 * In non-expression contexts, we use SelectStmt which can represent a SELECT
6969 * with or without outer parentheses.
6972 SelectStmt: select_no_parens %prec UMINUS
6973 | select_with_parens %prec UMINUS
6977 '(' select_no_parens ')' { $$ = $2; }
6978 | '(' select_with_parens ')' { $$ = $2; }
6982 * This rule parses the equivalent of the standard's <query expression>.
6983 * The duplicative productions are annoying, but hard to get rid of without
6984 * creating shift/reduce conflicts.
6986 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
6987 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
6988 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
6992 simple_select { $$ = $1; }
6993 | select_clause sort_clause
6995 insertSelectOptions((SelectStmt *) $1, $2, NIL,
7000 | select_clause opt_sort_clause for_locking_clause opt_select_limit
7002 insertSelectOptions((SelectStmt *) $1, $2, $3,
7003 list_nth($4, 0), list_nth($4, 1),
7008 | select_clause opt_sort_clause select_limit opt_for_locking_clause
7010 insertSelectOptions((SelectStmt *) $1, $2, $4,
7011 list_nth($3, 0), list_nth($3, 1),
7016 | with_clause select_clause
7018 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
7024 | with_clause select_clause sort_clause
7026 insertSelectOptions((SelectStmt *) $2, $3, NIL,
7032 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
7034 insertSelectOptions((SelectStmt *) $2, $3, $4,
7035 list_nth($5, 0), list_nth($5, 1),
7040 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
7042 insertSelectOptions((SelectStmt *) $2, $3, $5,
7043 list_nth($4, 0), list_nth($4, 1),
7051 simple_select { $$ = $1; }
7052 | select_with_parens { $$ = $1; }
7056 * This rule parses SELECT statements that can appear within set operations,
7057 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
7058 * the ordering of the set operations. Without '(' and ')' we want the
7059 * operations to be ordered per the precedence specs at the head of this file.
7061 * As with select_no_parens, simple_select cannot have outer parentheses,
7062 * but can have parenthesized subclauses.
7064 * Note that sort clauses cannot be included at this level --- SQL92 requires
7065 * SELECT foo UNION SELECT bar ORDER BY baz
7067 * (SELECT foo UNION SELECT bar) ORDER BY baz
7069 * SELECT foo UNION (SELECT bar ORDER BY baz)
7070 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
7071 * described as part of the select_no_parens production, not simple_select.
7072 * This does not limit functionality, because you can reintroduce these
7073 * clauses inside parentheses.
7075 * NOTE: only the leftmost component SelectStmt should have INTO.
7076 * However, this is not checked by the grammar; parse analysis must check it.
7079 SELECT opt_distinct target_list
7080 into_clause from_clause where_clause
7081 group_clause having_clause window_clause
7083 SelectStmt *n = makeNode(SelectStmt);
7084 n->distinctClause = $2;
7088 n->whereClause = $6;
7089 n->groupClause = $7;
7090 n->havingClause = $8;
7091 n->windowClause = $9;
7094 | values_clause { $$ = $1; }
7095 | TABLE relation_expr
7097 /* same as SELECT * FROM relation_expr */
7098 ColumnRef *cr = makeNode(ColumnRef);
7099 ResTarget *rt = makeNode(ResTarget);
7100 SelectStmt *n = makeNode(SelectStmt);
7102 cr->fields = list_make1(makeNode(A_Star));
7106 rt->indirection = NIL;
7107 rt->val = (Node *)cr;
7110 n->targetList = list_make1(rt);
7111 n->fromClause = list_make1($2);
7114 | select_clause UNION opt_all select_clause
7116 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
7118 | select_clause INTERSECT opt_all select_clause
7120 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
7122 | select_clause EXCEPT opt_all select_clause
7124 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
7129 * SQL standard WITH clause looks like:
7131 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
7132 * AS (query) [ SEARCH or CYCLE clause ]
7134 * We don't currently support the SEARCH or CYCLE clause.
7139 $$ = makeNode(WithClause);
7141 $$->recursive = false;
7144 | WITH RECURSIVE cte_list
7146 $$ = makeNode(WithClause);
7148 $$->recursive = true;
7154 common_table_expr { $$ = list_make1($1); }
7155 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
7158 common_table_expr: name opt_name_list AS select_with_parens
7160 CommonTableExpr *n = makeNode(CommonTableExpr);
7162 n->aliascolnames = $2;
7170 INTO OptTempTableName
7172 $$ = makeNode(IntoClause);
7176 $$->onCommit = ONCOMMIT_NOOP;
7177 $$->tableSpaceName = NULL;
7184 * Redundancy here is needed to avoid shift/reduce conflicts,
7185 * since TEMP is not a reserved word. See also OptTemp.
7188 TEMPORARY opt_table qualified_name
7193 | TEMP opt_table qualified_name
7198 | LOCAL TEMPORARY opt_table qualified_name
7203 | LOCAL TEMP opt_table qualified_name
7208 | GLOBAL TEMPORARY opt_table qualified_name
7213 | GLOBAL TEMP opt_table qualified_name
7218 | TABLE qualified_name
7234 opt_all: ALL { $$ = TRUE; }
7235 | DISTINCT { $$ = FALSE; }
7236 | /*EMPTY*/ { $$ = FALSE; }
7239 /* We use (NIL) as a placeholder to indicate that all target expressions
7240 * should be placed in the DISTINCT list during parsetree analysis.
7243 DISTINCT { $$ = list_make1(NIL); }
7244 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
7246 | /*EMPTY*/ { $$ = NIL; }
7250 sort_clause { $$ = $1;}
7251 | /*EMPTY*/ { $$ = NIL; }
7255 ORDER BY sortby_list { $$ = $3; }
7259 sortby { $$ = list_make1($1); }
7260 | sortby_list ',' sortby { $$ = lappend($1, $3); }
7263 sortby: a_expr USING qual_all_Op opt_nulls_order
7265 $$ = makeNode(SortBy);
7267 $$->sortby_dir = SORTBY_USING;
7268 $$->sortby_nulls = $4;
7272 | a_expr opt_asc_desc opt_nulls_order
7274 $$ = makeNode(SortBy);
7276 $$->sortby_dir = $2;
7277 $$->sortby_nulls = $3;
7279 $$->location = -1; /* no operator */
7285 limit_clause offset_clause { $$ = list_make2($2, $1); }
7286 | offset_clause limit_clause { $$ = list_make2($1, $2); }
7287 | limit_clause { $$ = list_make2(NULL, $1); }
7288 | offset_clause { $$ = list_make2($1, NULL); }
7292 select_limit { $$ = $1; }
7293 | /* EMPTY */ { $$ = list_make2(NULL,NULL); }
7297 LIMIT select_limit_value
7299 | LIMIT select_limit_value ',' select_offset_value
7301 /* Disabled because it was too confusing, bjm 2002-02-18 */
7303 (errcode(ERRCODE_SYNTAX_ERROR),
7304 errmsg("LIMIT #,# syntax is not supported"),
7305 errhint("Use separate LIMIT and OFFSET clauses."),
7306 parser_errposition(@1)));
7308 /* SQL:2008 syntax */
7309 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
7314 OFFSET select_offset_value
7316 /* SQL:2008 syntax */
7317 | OFFSET select_offset_value2 row_or_rows
7325 /* LIMIT ALL is represented as a NULL constant */
7326 $$ = makeNullAConst(@1);
7330 select_offset_value:
7335 * Allowing full expressions without parentheses causes various parsing
7336 * problems with the trailing ROW/ROWS key words. SQL only calls for
7337 * constants, so we allow the rest only with parentheses. If omitted,
7340 opt_select_fetch_first_value:
7341 SignedIconst { $$ = makeIntConst($1, @1); }
7342 | '(' a_expr ')' { $$ = $2; }
7343 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
7347 * Again, the trailing ROW/ROWS in this case prevent the full expression
7348 * syntax. c_expr is the best we can do.
7350 select_offset_value2:
7355 row_or_rows: ROW { $$ = 0; }
7359 first_or_next: FIRST_P { $$ = 0; }
7365 GROUP_P BY expr_list { $$ = $3; }
7366 | /*EMPTY*/ { $$ = NIL; }
7370 HAVING a_expr { $$ = $2; }
7371 | /*EMPTY*/ { $$ = NULL; }
7375 for_locking_items { $$ = $1; }
7376 | FOR READ ONLY { $$ = NIL; }
7379 opt_for_locking_clause:
7380 for_locking_clause { $$ = $1; }
7381 | /* EMPTY */ { $$ = NIL; }
7385 for_locking_item { $$ = list_make1($1); }
7386 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
7390 FOR UPDATE locked_rels_list opt_nowait
7392 LockingClause *n = makeNode(LockingClause);
7394 n->forUpdate = TRUE;
7398 | FOR SHARE locked_rels_list opt_nowait
7400 LockingClause *n = makeNode(LockingClause);
7402 n->forUpdate = FALSE;
7409 OF qualified_name_list { $$ = $2; }
7410 | /* EMPTY */ { $$ = NIL; }
7417 SelectStmt *n = makeNode(SelectStmt);
7418 n->valuesLists = list_make1($2);
7421 | values_clause ',' ctext_row
7423 SelectStmt *n = (SelectStmt *) $1;
7424 n->valuesLists = lappend(n->valuesLists, $3);
7430 /*****************************************************************************
7432 * clauses common to all Optimizable Stmts:
7433 * from_clause - allow list of both JOIN expressions and table names
7434 * where_clause - qualifications for joins or restrictions
7436 *****************************************************************************/
7439 FROM from_list { $$ = $2; }
7440 | /*EMPTY*/ { $$ = NIL; }
7444 table_ref { $$ = list_make1($1); }
7445 | from_list ',' table_ref { $$ = lappend($1, $3); }
7449 * table_ref is where an alias clause can be attached. Note we cannot make
7450 * alias_clause have an empty production because that causes parse conflicts
7451 * between table_ref := '(' joined_table ')' alias_clause
7452 * and joined_table := '(' joined_table ')'. So, we must have the
7453 * redundant-looking productions here instead.
7455 table_ref: relation_expr
7459 | relation_expr alias_clause
7466 RangeFunction *n = makeNode(RangeFunction);
7467 n->funccallnode = $1;
7468 n->coldeflist = NIL;
7471 | func_table alias_clause
7473 RangeFunction *n = makeNode(RangeFunction);
7474 n->funccallnode = $1;
7476 n->coldeflist = NIL;
7479 | func_table AS '(' TableFuncElementList ')'
7481 RangeFunction *n = makeNode(RangeFunction);
7482 n->funccallnode = $1;
7486 | func_table AS ColId '(' TableFuncElementList ')'
7488 RangeFunction *n = makeNode(RangeFunction);
7489 Alias *a = makeNode(Alias);
7490 n->funccallnode = $1;
7496 | func_table ColId '(' TableFuncElementList ')'
7498 RangeFunction *n = makeNode(RangeFunction);
7499 Alias *a = makeNode(Alias);
7500 n->funccallnode = $1;
7506 | select_with_parens
7509 * The SQL spec does not permit a subselect
7510 * (<derived_table>) without an alias clause,
7511 * so we don't either. This avoids the problem
7512 * of needing to invent a unique refname for it.
7513 * That could be surmounted if there's sufficient
7514 * popular demand, but for now let's just implement
7515 * the spec and see if anyone complains.
7516 * However, it does seem like a good idea to emit
7517 * an error message that's better than "syntax error".
7519 if (IsA($1, SelectStmt) &&
7520 ((SelectStmt *) $1)->valuesLists)
7522 (errcode(ERRCODE_SYNTAX_ERROR),
7523 errmsg("VALUES in FROM must have an alias"),
7524 errhint("For example, FROM (VALUES ...) [AS] foo."),
7525 parser_errposition(@1)));
7528 (errcode(ERRCODE_SYNTAX_ERROR),
7529 errmsg("subquery in FROM must have an alias"),
7530 errhint("For example, FROM (SELECT ...) [AS] foo."),
7531 parser_errposition(@1)));
7534 | select_with_parens alias_clause
7536 RangeSubselect *n = makeNode(RangeSubselect);
7545 | '(' joined_table ')' alias_clause
7554 * It may seem silly to separate joined_table from table_ref, but there is
7555 * method in SQL92's madness: if you don't do it this way you get reduce-
7556 * reduce conflicts, because it's not clear to the parser generator whether
7557 * to expect alias_clause after ')' or not. For the same reason we must
7558 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
7559 * join_type to expand to empty; if we try it, the parser generator can't
7560 * figure out when to reduce an empty join_type right after table_ref.
7562 * Note that a CROSS JOIN is the same as an unqualified
7563 * INNER JOIN, and an INNER JOIN/ON has the same shape
7564 * but a qualification expression to limit membership.
7565 * A NATURAL JOIN implicitly matches column names between
7566 * tables and the shape is determined by which columns are
7567 * in common. We'll collect columns during the later transformations.
7571 '(' joined_table ')'
7575 | table_ref CROSS JOIN table_ref
7577 /* CROSS JOIN is same as unqualified inner join */
7578 JoinExpr *n = makeNode(JoinExpr);
7579 n->jointype = JOIN_INNER;
7580 n->isNatural = FALSE;
7583 n->usingClause = NIL;
7587 | table_ref join_type JOIN table_ref join_qual
7589 JoinExpr *n = makeNode(JoinExpr);
7591 n->isNatural = FALSE;
7594 if ($5 != NULL && IsA($5, List))
7595 n->usingClause = (List *) $5; /* USING clause */
7597 n->quals = $5; /* ON clause */
7600 | table_ref JOIN table_ref join_qual
7602 /* letting join_type reduce to empty doesn't work */
7603 JoinExpr *n = makeNode(JoinExpr);
7604 n->jointype = JOIN_INNER;
7605 n->isNatural = FALSE;
7608 if ($4 != NULL && IsA($4, List))
7609 n->usingClause = (List *) $4; /* USING clause */
7611 n->quals = $4; /* ON clause */
7614 | table_ref NATURAL join_type JOIN table_ref
7616 JoinExpr *n = makeNode(JoinExpr);
7618 n->isNatural = TRUE;
7621 n->usingClause = NIL; /* figure out which columns later... */
7622 n->quals = NULL; /* fill later */
7625 | table_ref NATURAL JOIN table_ref
7627 /* letting join_type reduce to empty doesn't work */
7628 JoinExpr *n = makeNode(JoinExpr);
7629 n->jointype = JOIN_INNER;
7630 n->isNatural = TRUE;
7633 n->usingClause = NIL; /* figure out which columns later... */
7634 n->quals = NULL; /* fill later */
7640 AS ColId '(' name_list ')'
7642 $$ = makeNode(Alias);
7648 $$ = makeNode(Alias);
7651 | ColId '(' name_list ')'
7653 $$ = makeNode(Alias);
7659 $$ = makeNode(Alias);
7664 join_type: FULL join_outer { $$ = JOIN_FULL; }
7665 | LEFT join_outer { $$ = JOIN_LEFT; }
7666 | RIGHT join_outer { $$ = JOIN_RIGHT; }
7667 | INNER_P { $$ = JOIN_INNER; }
7670 /* OUTER is just noise... */
7671 join_outer: OUTER_P { $$ = NULL; }
7672 | /*EMPTY*/ { $$ = NULL; }
7675 /* JOIN qualification clauses
7676 * Possibilities are:
7677 * USING ( column list ) allows only unqualified column names,
7678 * which must match between tables.
7679 * ON expr allows more general qualifications.
7681 * We return USING as a List node, while an ON-expr will not be a List.
7684 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
7685 | ON a_expr { $$ = $2; }
7692 /* default inheritance */
7694 $$->inhOpt = INH_DEFAULT;
7697 | qualified_name '*'
7699 /* inheritance query */
7701 $$->inhOpt = INH_YES;
7704 | ONLY qualified_name
7706 /* no inheritance */
7708 $$->inhOpt = INH_NO;
7711 | ONLY '(' qualified_name ')'
7713 /* no inheritance, SQL99-style syntax */
7715 $$->inhOpt = INH_NO;
7722 relation_expr { $$ = list_make1($1); }
7723 | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
7728 * Given "UPDATE foo set set ...", we have to decide without looking any
7729 * further ahead whether the first "set" is an alias or the UPDATE's SET
7730 * keyword. Since "set" is allowed as a column name both interpretations
7731 * are feasible. We resolve the shift/reduce conflict by giving the first
7732 * relation_expr_opt_alias production a higher precedence than the SET token
7733 * has, causing the parser to prefer to reduce, in effect assuming that the
7734 * SET is not an alias.
7736 relation_expr_opt_alias: relation_expr %prec UMINUS
7740 | relation_expr ColId
7742 Alias *alias = makeNode(Alias);
7743 alias->aliasname = $2;
7747 | relation_expr AS ColId
7749 Alias *alias = makeNode(Alias);
7750 alias->aliasname = $3;
7757 func_table: func_expr { $$ = $1; }
7762 WHERE a_expr { $$ = $2; }
7763 | /*EMPTY*/ { $$ = NULL; }
7766 /* variant for UPDATE and DELETE */
7767 where_or_current_clause:
7768 WHERE a_expr { $$ = $2; }
7769 | WHERE CURRENT_P OF name
7771 CurrentOfExpr *n = makeNode(CurrentOfExpr);
7772 /* cvarno is filled in by parse analysis */
7773 n->cursor_name = $4;
7774 n->cursor_param = 0;
7777 | WHERE CURRENT_P OF PARAM
7779 CurrentOfExpr *n = makeNode(CurrentOfExpr);
7780 /* cvarno is filled in by parse analysis */
7781 n->cursor_name = NULL;
7782 n->cursor_param = $4;
7785 | /*EMPTY*/ { $$ = NULL; }
7789 TableFuncElementList:
7792 $$ = list_make1($1);
7794 | TableFuncElementList ',' TableFuncElement
7796 $$ = lappend($1, $3);
7800 TableFuncElement: ColId Typename
7802 ColumnDef *n = makeNode(ColumnDef);
7805 n->constraints = NIL;
7811 /*****************************************************************************
7814 * SQL92 introduces a large amount of type-specific syntax.
7815 * Define individual clauses to handle these cases, and use
7816 * the generic case to handle regular type-extensible Postgres syntax.
7817 * - thomas 1997-10-10
7819 *****************************************************************************/
7821 Typename: SimpleTypename opt_array_bounds
7824 $$->arrayBounds = $2;
7826 | SETOF SimpleTypename opt_array_bounds
7829 $$->arrayBounds = $3;
7832 /* SQL standard syntax, currently only one-dimensional */
7833 | SimpleTypename ARRAY '[' Iconst ']'
7836 $$->arrayBounds = list_make1(makeInteger($4));
7838 | SETOF SimpleTypename ARRAY '[' Iconst ']'
7841 $$->arrayBounds = list_make1(makeInteger($5));
7844 | SimpleTypename ARRAY
7847 $$->arrayBounds = list_make1(makeInteger(-1));
7849 | SETOF SimpleTypename ARRAY
7852 $$->arrayBounds = list_make1(makeInteger(-1));
7858 opt_array_bounds '[' ']'
7859 { $$ = lappend($1, makeInteger(-1)); }
7860 | opt_array_bounds '[' Iconst ']'
7861 { $$ = lappend($1, makeInteger($3)); }
7867 GenericType { $$ = $1; }
7868 | Numeric { $$ = $1; }
7870 | Character { $$ = $1; }
7871 | ConstDatetime { $$ = $1; }
7872 | ConstInterval opt_interval
7877 | ConstInterval '(' Iconst ')' opt_interval
7882 if (list_length($5) != 1)
7884 (errcode(ERRCODE_SYNTAX_ERROR),
7885 errmsg("interval precision specified twice"),
7886 parser_errposition(@1)));
7887 $$->typmods = lappend($5, makeIntConst($3, @3));
7890 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
7891 makeIntConst($3, @3));
7895 /* We have a separate ConstTypename to allow defaulting fixed-length
7896 * types such as CHAR() and BIT() to an unspecified length.
7897 * SQL9x requires that these default to a length of one, but this
7898 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
7899 * where there is an obvious better choice to make.
7900 * Note that ConstInterval is not included here since it must
7901 * be pushed up higher in the rules to accomodate the postfix
7902 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
7903 * the generic-type-name case in AExprConst to avoid premature
7904 * reduce/reduce conflicts against function names.
7907 Numeric { $$ = $1; }
7908 | ConstBit { $$ = $1; }
7909 | ConstCharacter { $$ = $1; }
7910 | ConstDatetime { $$ = $1; }
7914 * GenericType covers all type names that don't have special syntax mandated
7915 * by the standard, including qualified names. We also allow type modifiers.
7916 * To avoid parsing conflicts against function invocations, the modifiers
7917 * have to be shown as expr_list here, but parse analysis will only accept
7918 * constants for them.
7921 type_function_name opt_type_modifiers
7923 $$ = makeTypeName($1);
7927 | type_function_name attrs opt_type_modifiers
7929 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
7935 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
7936 | /* EMPTY */ { $$ = NIL; }
7940 * SQL92 numeric data types
7944 $$ = SystemTypeName("int4");
7949 $$ = SystemTypeName("int4");
7954 $$ = SystemTypeName("int2");
7959 $$ = SystemTypeName("int8");
7964 $$ = SystemTypeName("float4");
7972 | DOUBLE_P PRECISION
7974 $$ = SystemTypeName("float8");
7977 | DECIMAL_P opt_type_modifiers
7979 $$ = SystemTypeName("numeric");
7983 | DEC opt_type_modifiers
7985 $$ = SystemTypeName("numeric");
7989 | NUMERIC opt_type_modifiers
7991 $$ = SystemTypeName("numeric");
7997 $$ = SystemTypeName("bool");
8002 opt_float: '(' Iconst ')'
8005 * Check FLOAT() precision limits assuming IEEE floating
8006 * types - thomas 1997-09-18
8010 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8011 errmsg("precision for type float must be at least 1 bit"),
8012 parser_errposition(@2)));
8014 $$ = SystemTypeName("float4");
8016 $$ = SystemTypeName("float8");
8019 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8020 errmsg("precision for type float must be less than 54 bits"),
8021 parser_errposition(@2)));
8025 $$ = SystemTypeName("float8");
8030 * SQL92 bit-field data types
8031 * The following implements BIT() and BIT VARYING().
8043 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
8044 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
8045 ConstBit: BitWithLength
8057 BIT opt_varying '(' expr_list ')'
8061 typname = $2 ? "varbit" : "bit";
8062 $$ = SystemTypeName(typname);
8071 /* bit defaults to bit(1), varbit to no limit */
8074 $$ = SystemTypeName("varbit");
8078 $$ = SystemTypeName("bit");
8079 $$->typmods = list_make1(makeIntConst(1, -1));
8087 * SQL92 character data types
8088 * The following implements CHAR() and VARCHAR().
8090 Character: CharacterWithLength
8094 | CharacterWithoutLength
8100 ConstCharacter: CharacterWithLength
8104 | CharacterWithoutLength
8106 /* Length was not specified so allow to be unrestricted.
8107 * This handles problems with fixed-length (bpchar) strings
8108 * which in column definitions must default to a length
8109 * of one, but should not be constrained if the length
8110 * was not specified.
8117 CharacterWithLength: character '(' Iconst ')' opt_charset
8119 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
8123 type = palloc(strlen($1) + 1 + strlen($5) + 1);
8130 $$ = SystemTypeName($1);
8131 $$->typmods = list_make1(makeIntConst($3, @3));
8136 CharacterWithoutLength: character opt_charset
8138 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
8142 type = palloc(strlen($1) + 1 + strlen($2) + 1);
8149 $$ = SystemTypeName($1);
8151 /* char defaults to char(1), varchar to no limit */
8152 if (strcmp($1, "bpchar") == 0)
8153 $$->typmods = list_make1(makeIntConst(1, -1));
8159 character: CHARACTER opt_varying
8160 { $$ = $2 ? "varchar": "bpchar"; }
8161 | CHAR_P opt_varying
8162 { $$ = $2 ? "varchar": "bpchar"; }
8165 | NATIONAL CHARACTER opt_varying
8166 { $$ = $3 ? "varchar": "bpchar"; }
8167 | NATIONAL CHAR_P opt_varying
8168 { $$ = $3 ? "varchar": "bpchar"; }
8170 { $$ = $2 ? "varchar": "bpchar"; }
8174 VARYING { $$ = TRUE; }
8175 | /*EMPTY*/ { $$ = FALSE; }
8179 CHARACTER SET ColId { $$ = $3; }
8180 | /*EMPTY*/ { $$ = NULL; }
8184 * SQL92 date/time types
8187 TIMESTAMP '(' Iconst ')' opt_timezone
8190 $$ = SystemTypeName("timestamptz");
8192 $$ = SystemTypeName("timestamp");
8193 $$->typmods = list_make1(makeIntConst($3, @3));
8196 | TIMESTAMP opt_timezone
8199 $$ = SystemTypeName("timestamptz");
8201 $$ = SystemTypeName("timestamp");
8204 | TIME '(' Iconst ')' opt_timezone
8207 $$ = SystemTypeName("timetz");
8209 $$ = SystemTypeName("time");
8210 $$->typmods = list_make1(makeIntConst($3, @3));
8216 $$ = SystemTypeName("timetz");
8218 $$ = SystemTypeName("time");
8226 $$ = SystemTypeName("interval");
8232 WITH_TIME ZONE { $$ = TRUE; }
8233 | WITHOUT TIME ZONE { $$ = FALSE; }
8234 | /*EMPTY*/ { $$ = FALSE; }
8239 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
8241 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
8243 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
8245 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
8247 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
8252 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
8253 INTERVAL_MASK(MONTH), @1));
8257 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8258 INTERVAL_MASK(HOUR), @1));
8262 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8263 INTERVAL_MASK(HOUR) |
8264 INTERVAL_MASK(MINUTE), @1));
8266 | DAY_P TO interval_second
8269 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
8270 INTERVAL_MASK(HOUR) |
8271 INTERVAL_MASK(MINUTE) |
8272 INTERVAL_MASK(SECOND), @1);
8274 | HOUR_P TO MINUTE_P
8276 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
8277 INTERVAL_MASK(MINUTE), @1));
8279 | HOUR_P TO interval_second
8282 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
8283 INTERVAL_MASK(MINUTE) |
8284 INTERVAL_MASK(SECOND), @1);
8286 | MINUTE_P TO interval_second
8289 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
8290 INTERVAL_MASK(SECOND), @1);
8299 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
8301 | SECOND_P '(' Iconst ')'
8303 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
8304 makeIntConst($3, @3));
8309 /*****************************************************************************
8311 * expression grammar
8313 *****************************************************************************/
8316 * General expressions
8317 * This is the heart of the expression syntax.
8319 * We have two expression types: a_expr is the unrestricted kind, and
8320 * b_expr is a subset that must be used in some places to avoid shift/reduce
8321 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
8322 * because that use of AND conflicts with AND as a boolean operator. So,
8323 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
8325 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
8326 * always be used by surrounding it with parens.
8328 * c_expr is all the productions that are common to a_expr and b_expr;
8329 * it's factored out just to eliminate redundant coding.
8331 a_expr: c_expr { $$ = $1; }
8332 | a_expr TYPECAST Typename
8333 { $$ = makeTypeCast($1, $3, @2); }
8334 | a_expr AT TIME ZONE a_expr
8336 FuncCall *n = makeNode(FuncCall);
8337 n->funcname = SystemFuncName("timezone");
8338 n->args = list_make2($5, $1);
8339 n->agg_star = FALSE;
8340 n->agg_distinct = FALSE;
8341 n->func_variadic = FALSE;
8347 * These operators must be called out explicitly in order to make use
8348 * of bison's automatic operator-precedence handling. All other
8349 * operator names are handled by the generic productions using "Op",
8350 * below; and all those operators will have the same precedence.
8352 * If you add more explicitly-known operators, be sure to add them
8353 * also to b_expr and to the MathOp list above.
8355 | '+' a_expr %prec UMINUS
8356 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
8357 | '-' a_expr %prec UMINUS
8358 { $$ = doNegate($2, @1); }
8360 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
8362 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
8364 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
8366 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
8368 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
8370 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
8372 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
8374 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
8376 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
8378 | a_expr qual_Op a_expr %prec Op
8379 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
8380 | qual_Op a_expr %prec Op
8381 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
8382 | a_expr qual_Op %prec POSTFIXOP
8383 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
8386 { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
8388 { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
8390 { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
8392 | a_expr LIKE a_expr
8393 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
8394 | a_expr LIKE a_expr ESCAPE a_expr
8396 FuncCall *n = makeNode(FuncCall);
8397 n->funcname = SystemFuncName("like_escape");
8398 n->args = list_make2($3, $5);
8399 n->agg_star = FALSE;
8400 n->agg_distinct = FALSE;
8401 n->func_variadic = FALSE;
8404 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
8406 | a_expr NOT LIKE a_expr
8407 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
8408 | a_expr NOT LIKE a_expr ESCAPE a_expr
8410 FuncCall *n = makeNode(FuncCall);
8411 n->funcname = SystemFuncName("like_escape");
8412 n->args = list_make2($4, $6);
8413 n->agg_star = FALSE;
8414 n->agg_distinct = FALSE;
8415 n->func_variadic = FALSE;
8418 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
8420 | a_expr ILIKE a_expr
8421 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
8422 | a_expr ILIKE a_expr ESCAPE a_expr
8424 FuncCall *n = makeNode(FuncCall);
8425 n->funcname = SystemFuncName("like_escape");
8426 n->args = list_make2($3, $5);
8427 n->agg_star = FALSE;
8428 n->agg_distinct = FALSE;
8429 n->func_variadic = FALSE;
8432 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n, @2);
8434 | a_expr NOT ILIKE a_expr
8435 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
8436 | a_expr NOT ILIKE a_expr ESCAPE a_expr
8438 FuncCall *n = makeNode(FuncCall);
8439 n->funcname = SystemFuncName("like_escape");
8440 n->args = list_make2($4, $6);
8441 n->agg_star = FALSE;
8442 n->agg_distinct = FALSE;
8443 n->func_variadic = FALSE;
8446 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n, @2);
8449 | a_expr SIMILAR TO a_expr %prec SIMILAR
8451 FuncCall *n = makeNode(FuncCall);
8452 n->funcname = SystemFuncName("similar_escape");
8453 n->args = list_make2($4, makeNullAConst(-1));
8454 n->agg_star = FALSE;
8455 n->agg_distinct = FALSE;
8456 n->func_variadic = FALSE;
8459 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8461 | a_expr SIMILAR TO a_expr ESCAPE a_expr
8463 FuncCall *n = makeNode(FuncCall);
8464 n->funcname = SystemFuncName("similar_escape");
8465 n->args = list_make2($4, $6);
8466 n->agg_star = FALSE;
8467 n->agg_distinct = FALSE;
8468 n->func_variadic = FALSE;
8471 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8473 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
8475 FuncCall *n = makeNode(FuncCall);
8476 n->funcname = SystemFuncName("similar_escape");
8477 n->args = list_make2($5, makeNullAConst(-1));
8478 n->agg_star = FALSE;
8479 n->agg_distinct = FALSE;
8480 n->func_variadic = FALSE;
8483 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8485 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
8487 FuncCall *n = makeNode(FuncCall);
8488 n->funcname = SystemFuncName("similar_escape");
8489 n->args = list_make2($5, $7);
8490 n->agg_star = FALSE;
8491 n->agg_distinct = FALSE;
8492 n->func_variadic = FALSE;
8495 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8499 * Define SQL92-style Null test clause.
8500 * Allow two forms described in the standard:
8503 * Allow two SQL extensions
8509 NullTest *n = makeNode(NullTest);
8510 n->arg = (Expr *) $1;
8511 n->nulltesttype = IS_NULL;
8516 NullTest *n = makeNode(NullTest);
8517 n->arg = (Expr *) $1;
8518 n->nulltesttype = IS_NULL;
8521 | a_expr IS NOT NULL_P
8523 NullTest *n = makeNode(NullTest);
8524 n->arg = (Expr *) $1;
8525 n->nulltesttype = IS_NOT_NULL;
8530 NullTest *n = makeNode(NullTest);
8531 n->arg = (Expr *) $1;
8532 n->nulltesttype = IS_NOT_NULL;
8537 $$ = (Node *)makeOverlaps($1, $3, @2, yyscanner);
8541 BooleanTest *b = makeNode(BooleanTest);
8542 b->arg = (Expr *) $1;
8543 b->booltesttype = IS_TRUE;
8546 | a_expr IS NOT TRUE_P
8548 BooleanTest *b = makeNode(BooleanTest);
8549 b->arg = (Expr *) $1;
8550 b->booltesttype = IS_NOT_TRUE;
8555 BooleanTest *b = makeNode(BooleanTest);
8556 b->arg = (Expr *) $1;
8557 b->booltesttype = IS_FALSE;
8560 | a_expr IS NOT FALSE_P
8562 BooleanTest *b = makeNode(BooleanTest);
8563 b->arg = (Expr *) $1;
8564 b->booltesttype = IS_NOT_FALSE;
8569 BooleanTest *b = makeNode(BooleanTest);
8570 b->arg = (Expr *) $1;
8571 b->booltesttype = IS_UNKNOWN;
8574 | a_expr IS NOT UNKNOWN
8576 BooleanTest *b = makeNode(BooleanTest);
8577 b->arg = (Expr *) $1;
8578 b->booltesttype = IS_NOT_UNKNOWN;
8581 | a_expr IS DISTINCT FROM a_expr %prec IS
8583 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
8585 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
8587 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8588 (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
8593 | a_expr IS OF '(' type_list ')' %prec IS
8595 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
8597 | a_expr IS NOT OF '(' type_list ')' %prec IS
8599 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
8602 * Ideally we would not use hard-wired operators below but instead use
8603 * opclasses. However, mixed data types and other issues make this
8604 * difficult: http://archives.postgresql.org/pgsql-hackers/2008-08/msg01142.php
8606 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
8608 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
8609 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
8610 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
8613 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
8615 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
8616 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
8617 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
8620 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
8622 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
8623 (Node *) makeA_Expr(AEXPR_AND, NIL,
8624 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
8625 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
8627 (Node *) makeA_Expr(AEXPR_AND, NIL,
8628 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
8629 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
8633 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
8635 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
8636 (Node *) makeA_Expr(AEXPR_OR, NIL,
8637 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
8638 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
8640 (Node *) makeA_Expr(AEXPR_OR, NIL,
8641 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
8642 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
8646 | a_expr IN_P in_expr
8648 /* in_expr returns a SubLink or a list of a_exprs */
8649 if (IsA($3, SubLink))
8651 /* generate foo = ANY (subquery) */
8652 SubLink *n = (SubLink *) $3;
8653 n->subLinkType = ANY_SUBLINK;
8655 n->operName = list_make1(makeString("="));
8661 /* generate scalar IN expression */
8662 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
8665 | a_expr NOT IN_P in_expr
8667 /* in_expr returns a SubLink or a list of a_exprs */
8668 if (IsA($4, SubLink))
8670 /* generate NOT (foo = ANY (subquery)) */
8671 /* Make an = ANY node */
8672 SubLink *n = (SubLink *) $4;
8673 n->subLinkType = ANY_SUBLINK;
8675 n->operName = list_make1(makeString("="));
8677 /* Stick a NOT on top */
8678 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
8682 /* generate scalar NOT IN expression */
8683 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
8686 | a_expr subquery_Op sub_type select_with_parens %prec Op
8688 SubLink *n = makeNode(SubLink);
8689 n->subLinkType = $3;
8696 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
8698 if ($3 == ANY_SUBLINK)
8699 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
8701 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
8703 | UNIQUE select_with_parens
8705 /* Not sure how to get rid of the parentheses
8706 * but there are lots of shift/reduce errors without them.
8708 * Should be able to implement this by plopping the entire
8709 * select into a node, then transforming the target expressions
8710 * from whatever they are into count(*), and testing the
8711 * entire result equal to one.
8712 * But, will probably implement a separate node in the executor.
8715 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8716 errmsg("UNIQUE predicate is not yet implemented"),
8717 parser_errposition(@1)));
8719 | a_expr IS DOCUMENT_P %prec IS
8721 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8722 list_make1($1), @2);
8724 | a_expr IS NOT DOCUMENT_P %prec IS
8726 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8727 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8728 list_make1($1), @2),
8734 * Restricted expressions
8736 * b_expr is a subset of the complete expression syntax defined by a_expr.
8738 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
8739 * cause trouble in the places where b_expr is used. For simplicity, we
8740 * just eliminate all the boolean-keyword-operator productions from b_expr.
8744 | b_expr TYPECAST Typename
8745 { $$ = makeTypeCast($1, $3, @2); }
8746 | '+' b_expr %prec UMINUS
8747 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
8748 | '-' b_expr %prec UMINUS
8749 { $$ = doNegate($2, @1); }
8751 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
8753 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
8755 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
8757 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
8759 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
8761 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
8763 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
8765 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
8767 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
8768 | b_expr qual_Op b_expr %prec Op
8769 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
8770 | qual_Op b_expr %prec Op
8771 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
8772 | b_expr qual_Op %prec POSTFIXOP
8773 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
8774 | b_expr IS DISTINCT FROM b_expr %prec IS
8776 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
8778 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
8780 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
8781 NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
8783 | b_expr IS OF '(' type_list ')' %prec IS
8785 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
8787 | b_expr IS NOT OF '(' type_list ')' %prec IS
8789 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
8791 | b_expr IS DOCUMENT_P %prec IS
8793 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8794 list_make1($1), @2);
8796 | b_expr IS NOT DOCUMENT_P %prec IS
8798 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8799 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
8800 list_make1($1), @2),
8806 * Productions that can be used in both a_expr and b_expr.
8808 * Note: productions that refer recursively to a_expr or b_expr mostly
8809 * cannot appear here. However, it's OK to refer to a_exprs that occur
8810 * inside parentheses, such as function arguments; that cannot introduce
8811 * ambiguity to the b_expr syntax.
8813 c_expr: columnref { $$ = $1; }
8814 | AexprConst { $$ = $1; }
8815 | PARAM opt_indirection
8817 ParamRef *p = makeNode(ParamRef);
8822 A_Indirection *n = makeNode(A_Indirection);
8823 n->arg = (Node *) p;
8824 n->indirection = check_indirection($2, yyscanner);
8830 | '(' a_expr ')' opt_indirection
8834 A_Indirection *n = makeNode(A_Indirection);
8836 n->indirection = check_indirection($4, yyscanner);
8846 | select_with_parens %prec UMINUS
8848 SubLink *n = makeNode(SubLink);
8849 n->subLinkType = EXPR_SUBLINK;
8856 | EXISTS select_with_parens
8858 SubLink *n = makeNode(SubLink);
8859 n->subLinkType = EXISTS_SUBLINK;
8866 | ARRAY select_with_parens
8868 SubLink *n = makeNode(SubLink);
8869 n->subLinkType = ARRAY_SUBLINK;
8878 A_ArrayExpr *n = (A_ArrayExpr *) $2;
8879 Assert(IsA(n, A_ArrayExpr));
8880 /* point outermost A_ArrayExpr to the ARRAY keyword */
8886 RowExpr *r = makeNode(RowExpr);
8888 r->row_typeid = InvalidOid; /* not analyzed yet */
8895 * func_expr is split out from c_expr just so that we have a classification
8896 * for "everything that is a function call or looks like one". This isn't
8897 * very important, but it saves us having to document which variants are
8898 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
8899 * (Note that many of the special SQL functions wouldn't actually make any
8900 * sense as functional index entries, but we ignore that consideration here.)
8902 func_expr: func_name '(' ')' over_clause
8904 FuncCall *n = makeNode(FuncCall);
8907 n->agg_star = FALSE;
8908 n->agg_distinct = FALSE;
8909 n->func_variadic = FALSE;
8914 | func_name '(' expr_list ')' over_clause
8916 FuncCall *n = makeNode(FuncCall);
8919 n->agg_star = FALSE;
8920 n->agg_distinct = FALSE;
8921 n->func_variadic = FALSE;
8926 | func_name '(' VARIADIC a_expr ')' over_clause
8928 FuncCall *n = makeNode(FuncCall);
8930 n->args = list_make1($4);
8931 n->agg_star = FALSE;
8932 n->agg_distinct = FALSE;
8933 n->func_variadic = TRUE;
8938 | func_name '(' expr_list ',' VARIADIC a_expr ')' over_clause
8940 FuncCall *n = makeNode(FuncCall);
8942 n->args = lappend($3, $6);
8943 n->agg_star = FALSE;
8944 n->agg_distinct = FALSE;
8945 n->func_variadic = TRUE;
8950 | func_name '(' ALL expr_list ')' over_clause
8952 FuncCall *n = makeNode(FuncCall);
8955 n->agg_star = FALSE;
8956 n->agg_distinct = FALSE;
8957 /* Ideally we'd mark the FuncCall node to indicate
8958 * "must be an aggregate", but there's no provision
8959 * for that in FuncCall at the moment.
8961 n->func_variadic = FALSE;
8966 | func_name '(' DISTINCT expr_list ')' over_clause
8968 FuncCall *n = makeNode(FuncCall);
8971 n->agg_star = FALSE;
8972 n->agg_distinct = TRUE;
8973 n->func_variadic = FALSE;
8978 | func_name '(' '*' ')' over_clause
8981 * We consider AGGREGATE(*) to invoke a parameterless
8982 * aggregate. This does the right thing for COUNT(*),
8983 * and there are no other aggregates in SQL92 that accept
8986 * The FuncCall node is also marked agg_star = true,
8987 * so that later processing can detect what the argument
8990 FuncCall *n = makeNode(FuncCall);
8994 n->agg_distinct = FALSE;
8995 n->func_variadic = FALSE;
9003 * Translate as "'now'::text::date".
9005 * We cannot use "'now'::date" because coerce_type() will
9006 * immediately reduce that to a constant representing
9007 * today's date. We need to delay the conversion until
9008 * runtime, else the wrong things will happen when
9009 * CURRENT_DATE is used in a column default value or rule.
9011 * This could be simplified if we had a way to generate
9012 * an expression tree representing runtime application
9013 * of type-input conversion functions. (As of PG 7.3
9014 * that is actually possible, but not clear that we want
9018 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9019 $$ = makeTypeCast(n, SystemTypeName("date"), -1);
9024 * Translate as "'now'::text::timetz".
9025 * See comments for CURRENT_DATE.
9028 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9029 $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
9031 | CURRENT_TIME '(' Iconst ')'
9034 * Translate as "'now'::text::timetz(n)".
9035 * See comments for CURRENT_DATE.
9039 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9040 d = SystemTypeName("timetz");
9041 d->typmods = list_make1(makeIntConst($3, @3));
9042 $$ = makeTypeCast(n, d, -1);
9047 * Translate as "now()", since we have a function that
9048 * does exactly what is needed.
9050 FuncCall *n = makeNode(FuncCall);
9051 n->funcname = SystemFuncName("now");
9053 n->agg_star = FALSE;
9054 n->agg_distinct = FALSE;
9055 n->func_variadic = FALSE;
9060 | CURRENT_TIMESTAMP '(' Iconst ')'
9063 * Translate as "'now'::text::timestamptz(n)".
9064 * See comments for CURRENT_DATE.
9068 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9069 d = SystemTypeName("timestamptz");
9070 d->typmods = list_make1(makeIntConst($3, @3));
9071 $$ = makeTypeCast(n, d, -1);
9076 * Translate as "'now'::text::time".
9077 * See comments for CURRENT_DATE.
9080 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9081 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
9083 | LOCALTIME '(' Iconst ')'
9086 * Translate as "'now'::text::time(n)".
9087 * See comments for CURRENT_DATE.
9091 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9092 d = SystemTypeName("time");
9093 d->typmods = list_make1(makeIntConst($3, @3));
9094 $$ = makeTypeCast((Node *)n, d, -1);
9099 * Translate as "'now'::text::timestamp".
9100 * See comments for CURRENT_DATE.
9103 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9104 $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
9106 | LOCALTIMESTAMP '(' Iconst ')'
9109 * Translate as "'now'::text::timestamp(n)".
9110 * See comments for CURRENT_DATE.
9114 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9115 d = SystemTypeName("timestamp");
9116 d->typmods = list_make1(makeIntConst($3, @3));
9117 $$ = makeTypeCast(n, d, -1);
9121 FuncCall *n = makeNode(FuncCall);
9122 n->funcname = SystemFuncName("current_user");
9124 n->agg_star = FALSE;
9125 n->agg_distinct = FALSE;
9126 n->func_variadic = FALSE;
9133 FuncCall *n = makeNode(FuncCall);
9134 n->funcname = SystemFuncName("current_user");
9136 n->agg_star = FALSE;
9137 n->agg_distinct = FALSE;
9138 n->func_variadic = FALSE;
9145 FuncCall *n = makeNode(FuncCall);
9146 n->funcname = SystemFuncName("session_user");
9148 n->agg_star = FALSE;
9149 n->agg_distinct = FALSE;
9150 n->func_variadic = FALSE;
9157 FuncCall *n = makeNode(FuncCall);
9158 n->funcname = SystemFuncName("current_user");
9160 n->agg_star = FALSE;
9161 n->agg_distinct = FALSE;
9162 n->func_variadic = FALSE;
9169 FuncCall *n = makeNode(FuncCall);
9170 n->funcname = SystemFuncName("current_database");
9172 n->agg_star = FALSE;
9173 n->agg_distinct = FALSE;
9174 n->func_variadic = FALSE;
9181 FuncCall *n = makeNode(FuncCall);
9182 n->funcname = SystemFuncName("current_schema");
9184 n->agg_star = FALSE;
9185 n->agg_distinct = FALSE;
9186 n->func_variadic = FALSE;
9191 | CAST '(' a_expr AS Typename ')'
9192 { $$ = makeTypeCast($3, $5, @1); }
9193 | EXTRACT '(' extract_list ')'
9195 FuncCall *n = makeNode(FuncCall);
9196 n->funcname = SystemFuncName("date_part");
9198 n->agg_star = FALSE;
9199 n->agg_distinct = FALSE;
9200 n->func_variadic = FALSE;
9205 | OVERLAY '(' overlay_list ')'
9207 /* overlay(A PLACING B FROM C FOR D) is converted to
9208 * substring(A, 1, C-1) || B || substring(A, C+1, C+D)
9209 * overlay(A PLACING B FROM C) is converted to
9210 * substring(A, 1, C-1) || B || substring(A, C+1, C+char_length(B))
9212 FuncCall *n = makeNode(FuncCall);
9213 n->funcname = SystemFuncName("overlay");
9215 n->agg_star = FALSE;
9216 n->agg_distinct = FALSE;
9217 n->func_variadic = FALSE;
9222 | POSITION '(' position_list ')'
9224 /* position(A in B) is converted to position(B, A) */
9225 FuncCall *n = makeNode(FuncCall);
9226 n->funcname = SystemFuncName("position");
9228 n->agg_star = FALSE;
9229 n->agg_distinct = FALSE;
9230 n->func_variadic = FALSE;
9235 | SUBSTRING '(' substr_list ')'
9237 /* substring(A from B for C) is converted to
9238 * substring(A, B, C) - thomas 2000-11-28
9240 FuncCall *n = makeNode(FuncCall);
9241 n->funcname = SystemFuncName("substring");
9243 n->agg_star = FALSE;
9244 n->agg_distinct = FALSE;
9245 n->func_variadic = FALSE;
9250 | TREAT '(' a_expr AS Typename ')'
9252 /* TREAT(expr AS target) converts expr of a particular type to target,
9253 * which is defined to be a subtype of the original expression.
9254 * In SQL99, this is intended for use with structured UDTs,
9255 * but let's make this a generally useful form allowing stronger
9256 * coercions than are handled by implicit casting.
9258 FuncCall *n = makeNode(FuncCall);
9259 /* Convert SystemTypeName() to SystemFuncName() even though
9260 * at the moment they result in the same thing.
9262 n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
9263 n->args = list_make1($3);
9264 n->agg_star = FALSE;
9265 n->agg_distinct = FALSE;
9266 n->func_variadic = FALSE;
9271 | TRIM '(' BOTH trim_list ')'
9273 /* various trim expressions are defined in SQL92
9274 * - thomas 1997-07-19
9276 FuncCall *n = makeNode(FuncCall);
9277 n->funcname = SystemFuncName("btrim");
9279 n->agg_star = FALSE;
9280 n->agg_distinct = FALSE;
9281 n->func_variadic = FALSE;
9286 | TRIM '(' LEADING trim_list ')'
9288 FuncCall *n = makeNode(FuncCall);
9289 n->funcname = SystemFuncName("ltrim");
9291 n->agg_star = FALSE;
9292 n->agg_distinct = FALSE;
9293 n->func_variadic = FALSE;
9298 | TRIM '(' TRAILING trim_list ')'
9300 FuncCall *n = makeNode(FuncCall);
9301 n->funcname = SystemFuncName("rtrim");
9303 n->agg_star = FALSE;
9304 n->agg_distinct = FALSE;
9305 n->func_variadic = FALSE;
9310 | TRIM '(' trim_list ')'
9312 FuncCall *n = makeNode(FuncCall);
9313 n->funcname = SystemFuncName("btrim");
9315 n->agg_star = FALSE;
9316 n->agg_distinct = FALSE;
9317 n->func_variadic = FALSE;
9322 | NULLIF '(' a_expr ',' a_expr ')'
9324 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
9326 | COALESCE '(' expr_list ')'
9328 CoalesceExpr *c = makeNode(CoalesceExpr);
9333 | GREATEST '(' expr_list ')'
9335 MinMaxExpr *v = makeNode(MinMaxExpr);
9337 v->op = IS_GREATEST;
9341 | LEAST '(' expr_list ')'
9343 MinMaxExpr *v = makeNode(MinMaxExpr);
9349 | XMLCONCAT '(' expr_list ')'
9351 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
9353 | XMLELEMENT '(' NAME_P ColLabel ')'
9355 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
9357 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
9359 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
9361 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
9363 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
9365 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
9367 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
9369 | XMLFOREST '(' xml_attribute_list ')'
9371 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
9373 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
9375 XmlExpr *x = (XmlExpr *)
9376 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
9377 list_make2($4, makeBoolAConst($5, -1)),
9382 | XMLPI '(' NAME_P ColLabel ')'
9384 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
9386 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
9388 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
9390 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
9392 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
9393 list_make3($3, $5, $6), @1);
9395 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
9397 XmlSerialize *n = makeNode(XmlSerialize);
9409 xml_root_version: VERSION_P a_expr
9411 | VERSION_P NO VALUE_P
9412 { $$ = makeNullAConst(-1); }
9415 opt_xml_root_standalone: ',' STANDALONE_P YES_P
9416 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
9417 | ',' STANDALONE_P NO
9418 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
9419 | ',' STANDALONE_P NO VALUE_P
9420 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
9422 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
9425 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
9428 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
9429 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
9432 xml_attribute_el: a_expr AS ColLabel
9434 $$ = makeNode(ResTarget);
9436 $$->indirection = NIL;
9437 $$->val = (Node *) $1;
9442 $$ = makeNode(ResTarget);
9444 $$->indirection = NIL;
9445 $$->val = (Node *) $1;
9450 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
9451 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
9454 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
9455 | STRIP_P WHITESPACE_P { $$ = FALSE; }
9456 | /*EMPTY*/ { $$ = FALSE; }
9460 * Window Definitions
9463 WINDOW window_definition_list { $$ = $2; }
9464 | /*EMPTY*/ { $$ = NIL; }
9467 window_definition_list:
9468 window_definition { $$ = list_make1($1); }
9469 | window_definition_list ',' window_definition
9470 { $$ = lappend($1, $3); }
9474 ColId AS window_specification
9482 over_clause: OVER window_specification
9486 WindowDef *n = makeNode(WindowDef);
9489 n->partitionClause = NIL;
9490 n->orderClause = NIL;
9491 n->frameOptions = FRAMEOPTION_DEFAULTS;
9499 window_specification: '(' opt_existing_window_name opt_partition_clause
9500 opt_sort_clause opt_frame_clause ')'
9502 WindowDef *n = makeNode(WindowDef);
9505 n->partitionClause = $3;
9506 n->orderClause = $4;
9507 n->frameOptions = $5;
9514 * If we see PARTITION, RANGE, or ROWS as the first token after the '('
9515 * of a window_specification, we want the assumption to be that there is
9516 * no existing_window_name; but those keywords are unreserved and so could
9517 * be ColIds. We fix this by making them have the same precedence as IDENT
9518 * and giving the empty production here a slightly higher precedence, so
9519 * that the shift/reduce conflict is resolved in favor of reducing the rule.
9520 * These keywords are thus precluded from being an existing_window_name but
9521 * are not reserved for any other purpose.
9523 opt_existing_window_name: ColId { $$ = $1; }
9524 | /*EMPTY*/ %prec Op { $$ = NULL; }
9527 opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
9528 | /*EMPTY*/ { $$ = NIL; }
9532 * This is only a subset of the full SQL:2008 frame_clause grammar.
9533 * We don't support <expression> PRECEDING, <expression> FOLLOWING,
9534 * nor <window frame exclusion> yet.
9539 $$ = FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE | $2;
9543 $$ = FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS | $2;
9546 { $$ = FRAMEOPTION_DEFAULTS; }
9549 frame_extent: frame_bound
9551 /* reject invalid cases */
9552 if ($1 & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
9554 (errcode(ERRCODE_WINDOWING_ERROR),
9555 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
9556 parser_errposition(@1)));
9557 if ($1 & FRAMEOPTION_START_CURRENT_ROW)
9559 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9560 errmsg("frame start at CURRENT ROW is not implemented"),
9561 parser_errposition(@1)));
9562 $$ = $1 | FRAMEOPTION_END_CURRENT_ROW;
9564 | BETWEEN frame_bound AND frame_bound
9566 /* reject invalid cases */
9567 if ($2 & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
9569 (errcode(ERRCODE_WINDOWING_ERROR),
9570 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
9571 parser_errposition(@2)));
9572 if ($2 & FRAMEOPTION_START_CURRENT_ROW)
9574 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9575 errmsg("frame start at CURRENT ROW is not implemented"),
9576 parser_errposition(@2)));
9577 if ($4 & FRAMEOPTION_START_UNBOUNDED_PRECEDING)
9579 (errcode(ERRCODE_WINDOWING_ERROR),
9580 errmsg("frame end cannot be UNBOUNDED PRECEDING"),
9581 parser_errposition(@4)));
9582 /* shift converts START_ options to END_ options */
9583 $$ = FRAMEOPTION_BETWEEN | $2 | ($4 << 1);
9588 * This is used for both frame start and frame end, with output set up on
9589 * the assumption it's frame start; the frame_extent productions must reject
9595 $$ = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
9597 | UNBOUNDED FOLLOWING
9599 $$ = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
9603 $$ = FRAMEOPTION_START_CURRENT_ROW;
9609 * Supporting nonterminals for expressions.
9612 /* Explicit row production.
9614 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
9615 * without conflicting with the parenthesized a_expr production. Without the
9616 * ROW keyword, there must be more than one a_expr inside the parens.
9618 row: ROW '(' expr_list ')' { $$ = $3; }
9619 | ROW '(' ')' { $$ = NIL; }
9620 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
9623 sub_type: ANY { $$ = ANY_SUBLINK; }
9624 | SOME { $$ = ANY_SUBLINK; }
9625 | ALL { $$ = ALL_SUBLINK; }
9628 all_Op: Op { $$ = $1; }
9629 | MathOp { $$ = $1; }
9632 MathOp: '+' { $$ = "+"; }
9644 { $$ = list_make1(makeString($1)); }
9645 | OPERATOR '(' any_operator ')'
9651 { $$ = list_make1(makeString($1)); }
9652 | OPERATOR '(' any_operator ')'
9658 { $$ = list_make1(makeString($1)); }
9659 | OPERATOR '(' any_operator ')'
9662 { $$ = list_make1(makeString("~~")); }
9664 { $$ = list_make1(makeString("!~~")); }
9666 { $$ = list_make1(makeString("~~*")); }
9668 { $$ = list_make1(makeString("!~~*")); }
9669 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
9670 * the regular expression is preprocessed by a function (similar_escape),
9671 * and the ~ operator for posix regular expressions is used.
9672 * x SIMILAR TO y -> x ~ similar_escape(y)
9673 * this transformation is made on the fly by the parser upwards.
9674 * however the SubLink structure which handles any/some/all stuff
9675 * is not ready for such a thing.
9681 $$ = list_make1($1);
9683 | expr_list ',' a_expr
9685 $$ = lappend($1, $3);
9689 type_list: Typename { $$ = list_make1($1); }
9690 | type_list ',' Typename { $$ = lappend($1, $3); }
9693 array_expr: '[' expr_list ']'
9695 $$ = makeAArrayExpr($2, @1);
9697 | '[' array_expr_list ']'
9699 $$ = makeAArrayExpr($2, @1);
9703 $$ = makeAArrayExpr(NIL, @1);
9707 array_expr_list: array_expr { $$ = list_make1($1); }
9708 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
9713 extract_arg FROM a_expr
9715 $$ = list_make2(makeStringConst($1, @1), $3);
9717 | /*EMPTY*/ { $$ = NIL; }
9720 /* Allow delimited string Sconst in extract_arg as an SQL extension.
9721 * - thomas 2001-04-12
9725 | YEAR_P { $$ = "year"; }
9726 | MONTH_P { $$ = "month"; }
9727 | DAY_P { $$ = "day"; }
9728 | HOUR_P { $$ = "hour"; }
9729 | MINUTE_P { $$ = "minute"; }
9730 | SECOND_P { $$ = "second"; }
9731 | Sconst { $$ = $1; }
9734 /* OVERLAY() arguments
9735 * SQL99 defines the OVERLAY() function:
9736 * o overlay(text placing text from int for int)
9737 * o overlay(text placing text from int)
9740 a_expr overlay_placing substr_from substr_for
9742 $$ = list_make4($1, $2, $3, $4);
9744 | a_expr overlay_placing substr_from
9746 $$ = list_make3($1, $2, $3);
9755 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
9758 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
9759 | /*EMPTY*/ { $$ = NIL; }
9762 /* SUBSTRING() arguments
9763 * SQL9x defines a specific syntax for arguments to SUBSTRING():
9764 * o substring(text from int for int)
9765 * o substring(text from int) get entire string from starting point "int"
9766 * o substring(text for int) get first "int" characters of string
9767 * o substring(text from pattern) get entire string matching pattern
9768 * o substring(text from pattern for escape) same with specified escape char
9769 * We also want to support generic substring functions which accept
9770 * the usual generic list of arguments. So we will accept both styles
9771 * here, and convert the SQL9x style to the generic list for further
9772 * processing. - thomas 2000-11-28
9775 a_expr substr_from substr_for
9777 $$ = list_make3($1, $2, $3);
9779 | a_expr substr_for substr_from
9781 /* not legal per SQL99, but might as well allow it */
9782 $$ = list_make3($1, $3, $2);
9784 | a_expr substr_from
9786 $$ = list_make2($1, $2);
9791 * Since there are no cases where this syntax allows
9792 * a textual FOR value, we forcibly cast the argument
9793 * to int4. The possible matches in pg_proc are
9794 * substring(text,int4) and substring(text,text),
9795 * and we don't want the parser to choose the latter,
9796 * which it is likely to do if the second argument
9797 * is unknown or doesn't have an implicit cast to int4.
9799 $$ = list_make3($1, makeIntConst(1, -1),
9801 SystemTypeName("int4"), -1));
9812 FROM a_expr { $$ = $2; }
9815 substr_for: FOR a_expr { $$ = $2; }
9818 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
9819 | FROM expr_list { $$ = $2; }
9820 | expr_list { $$ = $1; }
9823 in_expr: select_with_parens
9825 SubLink *n = makeNode(SubLink);
9827 /* other fields will be filled later */
9830 | '(' expr_list ')' { $$ = (Node *)$2; }
9834 * Define SQL92-style case clause.
9835 * - Full specification
9836 * CASE WHEN a = b THEN c ... ELSE d END
9837 * - Implicit argument
9838 * CASE a WHEN b THEN c ... ELSE d END
9840 case_expr: CASE case_arg when_clause_list case_default END_P
9842 CaseExpr *c = makeNode(CaseExpr);
9843 c->casetype = InvalidOid; /* not analyzed yet */
9844 c->arg = (Expr *) $2;
9846 c->defresult = (Expr *) $4;
9853 /* There must be at least one */
9854 when_clause { $$ = list_make1($1); }
9855 | when_clause_list when_clause { $$ = lappend($1, $2); }
9859 WHEN a_expr THEN a_expr
9861 CaseWhen *w = makeNode(CaseWhen);
9862 w->expr = (Expr *) $2;
9863 w->result = (Expr *) $4;
9870 ELSE a_expr { $$ = $2; }
9871 | /*EMPTY*/ { $$ = NULL; }
9874 case_arg: a_expr { $$ = $1; }
9875 | /*EMPTY*/ { $$ = NULL; }
9879 * columnref starts with relation_name not ColId, so that OLD and NEW
9880 * references can be accepted. Note that when there are more than two
9881 * dotted names, the first name is not actually a relation name...
9883 columnref: relation_name
9885 $$ = makeColumnRef($1, NIL, @1, yyscanner);
9887 | relation_name indirection
9889 $$ = makeColumnRef($1, $2, @1, yyscanner);
9896 $$ = (Node *) makeString($2);
9900 $$ = (Node *) makeNode(A_Star);
9904 A_Indices *ai = makeNode(A_Indices);
9909 | '[' a_expr ':' a_expr ']'
9911 A_Indices *ai = makeNode(A_Indices);
9919 indirection_el { $$ = list_make1($1); }
9920 | indirection indirection_el { $$ = lappend($1, $2); }
9924 /*EMPTY*/ { $$ = NIL; }
9925 | opt_indirection indirection_el { $$ = lappend($1, $2); }
9928 opt_asymmetric: ASYMMETRIC
9933 * The SQL spec defines "contextually typed value expressions" and
9934 * "contextually typed row value constructors", which for our purposes
9935 * are the same as "a_expr" and "row" except that DEFAULT can appear at
9940 a_expr { $$ = (Node *) $1; }
9943 SetToDefault *n = makeNode(SetToDefault);
9950 ctext_expr { $$ = list_make1($1); }
9951 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
9955 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
9956 * making VALUES a fully reserved word, which will probably break more apps
9957 * than allowing the noise-word is worth.
9959 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
9963 /*****************************************************************************
9965 * target list for SELECT
9967 *****************************************************************************/
9970 target_el { $$ = list_make1($1); }
9971 | target_list ',' target_el { $$ = lappend($1, $3); }
9974 target_el: a_expr AS ColLabel
9976 $$ = makeNode(ResTarget);
9978 $$->indirection = NIL;
9979 $$->val = (Node *)$1;
9983 * We support omitting AS only for column labels that aren't
9984 * any known keyword. There is an ambiguity against postfix
9985 * operators: is "a ! b" an infix expression, or a postfix
9986 * expression and a column label? We prefer to resolve this
9987 * as an infix expression, which we accomplish by assigning
9988 * IDENT a precedence higher than POSTFIXOP.
9992 $$ = makeNode(ResTarget);
9994 $$->indirection = NIL;
9995 $$->val = (Node *)$1;
10000 $$ = makeNode(ResTarget);
10002 $$->indirection = NIL;
10003 $$->val = (Node *)$1;
10008 ColumnRef *n = makeNode(ColumnRef);
10009 n->fields = list_make1(makeNode(A_Star));
10012 $$ = makeNode(ResTarget);
10014 $$->indirection = NIL;
10015 $$->val = (Node *)n;
10021 /*****************************************************************************
10023 * Names and constants
10025 *****************************************************************************/
10028 SpecialRuleRelation { $$ = $1; }
10029 | ColId { $$ = $1; }
10032 qualified_name_list:
10033 qualified_name { $$ = list_make1($1); }
10034 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
10038 * The production for a qualified relation name has to exactly match the
10039 * production for a qualified func_name, because in a FROM clause we cannot
10040 * tell which we are parsing until we see what comes after it ('(' for a
10041 * func_name, something else for a relation). Therefore we allow 'indirection'
10042 * which may contain subscripts, and reject that case in the C code.
10047 $$ = makeNode(RangeVar);
10048 $$->catalogname = NULL;
10049 $$->schemaname = NULL;
10053 | relation_name indirection
10055 check_qualified_name($2, yyscanner);
10056 $$ = makeNode(RangeVar);
10057 switch (list_length($2))
10060 $$->catalogname = NULL;
10061 $$->schemaname = $1;
10062 $$->relname = strVal(linitial($2));
10065 $$->catalogname = $1;
10066 $$->schemaname = strVal(linitial($2));
10067 $$->relname = strVal(lsecond($2));
10071 (errcode(ERRCODE_SYNTAX_ERROR),
10072 errmsg("improper qualified name (too many dotted names): %s",
10073 NameListToString(lcons(makeString($1), $2))),
10074 parser_errposition(@1)));
10082 { $$ = list_make1(makeString($1)); }
10083 | name_list ',' name
10084 { $$ = lappend($1, makeString($3)); }
10088 name: ColId { $$ = $1; };
10091 ColId { $$ = $1; };
10094 ColId { $$ = $1; };
10096 attr_name: ColLabel { $$ = $1; };
10098 index_name: ColId { $$ = $1; };
10100 file_name: Sconst { $$ = $1; };
10103 * The production for a qualified func_name has to exactly match the
10104 * production for a qualified columnref, because we cannot tell which we
10105 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
10106 * anything else for a columnref). Therefore we allow 'indirection' which
10107 * may contain subscripts, and reject that case in the C code. (If we
10108 * ever implement SQL99-like methods, such syntax may actually become legal!)
10110 func_name: type_function_name
10111 { $$ = list_make1(makeString($1)); }
10112 | relation_name indirection
10114 $$ = check_func_name(lcons(makeString($1), $2),
10125 $$ = makeIntConst($1, @1);
10129 $$ = makeFloatConst($1, @1);
10133 $$ = makeStringConst($1, @1);
10137 $$ = makeBitStringConst($1, @1);
10141 /* This is a bit constant per SQL99:
10142 * Without Feature F511, "BIT data type",
10143 * a <general literal> shall not be a
10144 * <bit string literal> or a <hex string literal>.
10146 $$ = makeBitStringConst($1, @1);
10150 /* generic type 'literal' syntax */
10151 TypeName *t = makeTypeNameFromNameList($1);
10153 $$ = makeStringConstCast($2, @2, t);
10155 | func_name '(' expr_list ')' Sconst
10157 /* generic syntax with a type modifier */
10158 TypeName *t = makeTypeNameFromNameList($1);
10161 $$ = makeStringConstCast($5, @5, t);
10163 | ConstTypename Sconst
10165 $$ = makeStringConstCast($2, @2, $1);
10167 | ConstInterval Sconst opt_interval
10171 $$ = makeStringConstCast($2, @2, t);
10173 | ConstInterval '(' Iconst ')' Sconst opt_interval
10178 if (list_length($6) != 1)
10180 (errcode(ERRCODE_SYNTAX_ERROR),
10181 errmsg("interval precision specified twice"),
10182 parser_errposition(@1)));
10183 t->typmods = lappend($6, makeIntConst($3, @3));
10186 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
10187 makeIntConst($3, @3));
10188 $$ = makeStringConstCast($5, @5, t);
10192 $$ = makeBoolAConst(TRUE, @1);
10196 $$ = makeBoolAConst(FALSE, @1);
10200 $$ = makeNullAConst(@1);
10204 Iconst: ICONST { $$ = $1; };
10205 Sconst: SCONST { $$ = $1; };
10206 RoleId: ColId { $$ = $1; };
10208 SignedIconst: Iconst { $$ = $1; }
10209 | '+' Iconst { $$ = + $2; }
10210 | '-' Iconst { $$ = - $2; }
10214 * Name classification hierarchy.
10216 * IDENT is the lexeme returned by the lexer for identifiers that match
10217 * no known keyword. In most cases, we can accept certain keywords as
10218 * names, not only IDENTs. We prefer to accept as many such keywords
10219 * as possible to minimize the impact of "reserved words" on programmers.
10220 * So, we divide names into several possible classes. The classification
10221 * is chosen in part to make keywords acceptable as names wherever possible.
10224 /* Column identifier --- names that can be column, table, etc names.
10226 ColId: IDENT { $$ = $1; }
10227 | unreserved_keyword { $$ = pstrdup($1); }
10228 | col_name_keyword { $$ = pstrdup($1); }
10231 /* Type/function identifier --- names that can be type or function names.
10233 type_function_name: IDENT { $$ = $1; }
10234 | unreserved_keyword { $$ = pstrdup($1); }
10235 | type_func_name_keyword { $$ = pstrdup($1); }
10238 /* Column label --- allowed labels in "AS" clauses.
10239 * This presently includes *all* Postgres keywords.
10241 ColLabel: IDENT { $$ = $1; }
10242 | unreserved_keyword { $$ = pstrdup($1); }
10243 | col_name_keyword { $$ = pstrdup($1); }
10244 | type_func_name_keyword { $$ = pstrdup($1); }
10245 | reserved_keyword { $$ = pstrdup($1); }
10250 * Keyword category lists. Generally, every keyword present in
10251 * the Postgres grammar should appear in exactly one of these lists.
10253 * Put a new keyword into the first list that it can go into without causing
10254 * shift or reduce conflicts. The earlier lists define "less reserved"
10255 * categories of keywords.
10257 * Make sure that each keyword's category in keywords.c matches where
10258 * it is listed here. (Someday we may be able to generate these lists and
10259 * keywords.c's table from a common master list.)
10262 /* "Unreserved" keywords --- available for use as any kind of name.
10264 unreserved_keyword:
10513 /* Column identifier --- keywords that can be column, table, etc names.
10515 * Many of these keywords will in fact be recognized as type or function
10516 * names too; but they have special productions for the purpose, and so
10517 * can't be treated as "generic" type or function names.
10519 * The type names appearing here are not usable as function names
10520 * because they can be followed by '(' in typename productions, which
10521 * looks too much like a function call for an LR(1) parser.
10571 /* Type/function identifier --- keywords that can be type or function names.
10573 * Most of these are keywords that are used as operators in expressions;
10574 * in general such keywords can't be column names because they would be
10575 * ambiguous with variables, but they are unambiguous as function identifiers.
10577 * Do not include POSITION, SUBSTRING, etc here since they have explicit
10578 * productions in a_expr to support the goofy SQL9x argument syntax.
10579 * - thomas 2000-11-28
10581 type_func_name_keyword:
10606 /* Reserved keyword --- these keywords are usable only as a ColLabel.
10608 * Keywords appear here if they could not be distinguished from variable,
10609 * type, or function names in some contexts. Don't put things here unless
10634 | CURRENT_TIMESTAMP
10695 SpecialRuleRelation:
10698 if (pg_yyget_extra(yyscanner)->QueryIsRule)
10702 (errcode(ERRCODE_SYNTAX_ERROR),
10703 errmsg("OLD used in query that is not in a rule"),
10704 parser_errposition(@1)));
10708 if (pg_yyget_extra(yyscanner)->QueryIsRule)
10712 (errcode(ERRCODE_SYNTAX_ERROR),
10713 errmsg("NEW used in query that is not in a rule"),
10714 parser_errposition(@1)));
10721 * The signature of this function is required by bison. However, we
10722 * ignore the passed yylloc and instead use the last token position
10723 * available from the scanner.
10726 base_yyerror(YYLTYPE *yylloc, base_yyscan_t yyscanner, const char *msg)
10728 parser_yyerror(msg);
10732 makeColumnRef(char *colname, List *indirection,
10733 int location, base_yyscan_t yyscanner)
10736 * Generate a ColumnRef node, with an A_Indirection node added if there
10737 * is any subscripting in the specified indirection list. However,
10738 * any field selection at the start of the indirection list must be
10739 * transposed into the "fields" part of the ColumnRef node.
10741 ColumnRef *c = makeNode(ColumnRef);
10745 c->location = location;
10746 foreach(l, indirection)
10748 if (IsA(lfirst(l), A_Indices))
10750 A_Indirection *i = makeNode(A_Indirection);
10754 /* easy case - all indirection goes to A_Indirection */
10755 c->fields = list_make1(makeString(colname));
10756 i->indirection = check_indirection(indirection, yyscanner);
10760 /* got to split the list in two */
10761 i->indirection = check_indirection(list_copy_tail(indirection,
10764 indirection = list_truncate(indirection, nfields);
10765 c->fields = lcons(makeString(colname), indirection);
10767 i->arg = (Node *) c;
10770 else if (IsA(lfirst(l), A_Star))
10772 /* We only allow '*' at the end of a ColumnRef */
10773 if (lnext(l) != NULL)
10774 parser_yyerror("improper use of \"*\"");
10778 /* No subscripting, so all indirection gets added to field list */
10779 c->fields = lcons(makeString(colname), indirection);
10784 makeTypeCast(Node *arg, TypeName *typename, int location)
10786 TypeCast *n = makeNode(TypeCast);
10788 n->typeName = typename;
10789 n->location = location;
10794 makeStringConst(char *str, int location)
10796 A_Const *n = makeNode(A_Const);
10798 n->val.type = T_String;
10799 n->val.val.str = str;
10800 n->location = location;
10806 makeStringConstCast(char *str, int location, TypeName *typename)
10808 Node *s = makeStringConst(str, location);
10810 return makeTypeCast(s, typename, -1);
10814 makeIntConst(int val, int location)
10816 A_Const *n = makeNode(A_Const);
10818 n->val.type = T_Integer;
10819 n->val.val.ival = val;
10820 n->location = location;
10826 makeFloatConst(char *str, int location)
10828 A_Const *n = makeNode(A_Const);
10830 n->val.type = T_Float;
10831 n->val.val.str = str;
10832 n->location = location;
10838 makeBitStringConst(char *str, int location)
10840 A_Const *n = makeNode(A_Const);
10842 n->val.type = T_BitString;
10843 n->val.val.str = str;
10844 n->location = location;
10850 makeNullAConst(int location)
10852 A_Const *n = makeNode(A_Const);
10854 n->val.type = T_Null;
10855 n->location = location;
10861 makeAConst(Value *v, int location)
10868 n = makeFloatConst(v->val.str, location);
10872 n = makeIntConst(v->val.ival, location);
10877 n = makeStringConst(v->val.str, location);
10884 /* makeBoolAConst()
10885 * Create an A_Const string node and put it inside a boolean cast.
10888 makeBoolAConst(bool state, int location)
10890 A_Const *n = makeNode(A_Const);
10892 n->val.type = T_String;
10893 n->val.val.str = (state ? "t" : "f");
10894 n->location = location;
10896 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
10900 * Create and populate a FuncCall node to support the OVERLAPS operator.
10903 makeOverlaps(List *largs, List *rargs, int location, base_yyscan_t yyscanner)
10905 FuncCall *n = makeNode(FuncCall);
10907 n->funcname = SystemFuncName("overlaps");
10908 if (list_length(largs) == 1)
10909 largs = lappend(largs, largs);
10910 else if (list_length(largs) != 2)
10912 (errcode(ERRCODE_SYNTAX_ERROR),
10913 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
10914 parser_errposition(location)));
10915 if (list_length(rargs) == 1)
10916 rargs = lappend(rargs, rargs);
10917 else if (list_length(rargs) != 2)
10919 (errcode(ERRCODE_SYNTAX_ERROR),
10920 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
10921 parser_errposition(location)));
10922 n->args = list_concat(largs, rargs);
10923 n->agg_star = FALSE;
10924 n->agg_distinct = FALSE;
10925 n->func_variadic = FALSE;
10927 n->location = location;
10931 /* check_qualified_name --- check the result of qualified_name production
10933 * It's easiest to let the grammar production for qualified_name allow
10934 * subscripts and '*', which we then must reject here.
10937 check_qualified_name(List *names, base_yyscan_t yyscanner)
10943 if (!IsA(lfirst(i), String))
10944 parser_yyerror("syntax error");
10948 /* check_func_name --- check the result of func_name production
10950 * It's easiest to let the grammar production for func_name allow subscripts
10951 * and '*', which we then must reject here.
10954 check_func_name(List *names, base_yyscan_t yyscanner)
10960 if (!IsA(lfirst(i), String))
10961 parser_yyerror("syntax error");
10966 /* check_indirection --- check the result of indirection production
10968 * We only allow '*' at the end of the list, but it's hard to enforce that
10969 * in the grammar, so do it here.
10972 check_indirection(List *indirection, base_yyscan_t yyscanner)
10976 foreach(l, indirection)
10978 if (IsA(lfirst(l), A_Star))
10980 if (lnext(l) != NULL)
10981 parser_yyerror("improper use of \"*\"");
10984 return indirection;
10987 /* extractArgTypes()
10988 * Given a list of FunctionParameter nodes, extract a list of just the
10989 * argument types (TypeNames) for input parameters only. This is what
10990 * is needed to look up an existing function, which is what is wanted by
10991 * the productions that use this call.
10994 extractArgTypes(List *parameters)
10996 List *result = NIL;
10999 foreach(i, parameters)
11001 FunctionParameter *p = (FunctionParameter *) lfirst(i);
11003 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
11004 result = lappend(result, p->argType);
11009 /* findLeftmostSelect()
11010 * Find the leftmost component SelectStmt in a set-operation parsetree.
11012 static SelectStmt *
11013 findLeftmostSelect(SelectStmt *node)
11015 while (node && node->op != SETOP_NONE)
11017 Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
11021 /* insertSelectOptions()
11022 * Insert ORDER BY, etc into an already-constructed SelectStmt.
11024 * This routine is just to avoid duplicating code in SelectStmt productions.
11027 insertSelectOptions(SelectStmt *stmt,
11028 List *sortClause, List *lockingClause,
11029 Node *limitOffset, Node *limitCount,
11030 WithClause *withClause,
11031 base_yyscan_t yyscanner)
11033 Assert(IsA(stmt, SelectStmt));
11036 * Tests here are to reject constructs like
11037 * (SELECT foo ORDER BY bar) ORDER BY baz
11041 if (stmt->sortClause)
11043 (errcode(ERRCODE_SYNTAX_ERROR),
11044 errmsg("multiple ORDER BY clauses not allowed"),
11045 parser_errposition(exprLocation((Node *) sortClause))));
11046 stmt->sortClause = sortClause;
11048 /* We can handle multiple locking clauses, though */
11049 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
11052 if (stmt->limitOffset)
11054 (errcode(ERRCODE_SYNTAX_ERROR),
11055 errmsg("multiple OFFSET clauses not allowed"),
11056 parser_errposition(exprLocation(limitOffset))));
11057 stmt->limitOffset = limitOffset;
11061 if (stmt->limitCount)
11063 (errcode(ERRCODE_SYNTAX_ERROR),
11064 errmsg("multiple LIMIT clauses not allowed"),
11065 parser_errposition(exprLocation(limitCount))));
11066 stmt->limitCount = limitCount;
11070 if (stmt->withClause)
11072 (errcode(ERRCODE_SYNTAX_ERROR),
11073 errmsg("multiple WITH clauses not allowed"),
11074 parser_errposition(exprLocation((Node *) withClause))));
11075 stmt->withClause = withClause;
11080 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
11082 SelectStmt *n = makeNode(SelectStmt);
11086 n->larg = (SelectStmt *) larg;
11087 n->rarg = (SelectStmt *) rarg;
11091 /* SystemFuncName()
11092 * Build a properly-qualified reference to a built-in function.
11095 SystemFuncName(char *name)
11097 return list_make2(makeString("pg_catalog"), makeString(name));
11100 /* SystemTypeName()
11101 * Build a properly-qualified reference to a built-in type.
11103 * typmod is defaulted, but may be changed afterwards by caller.
11104 * Likewise for the location.
11107 SystemTypeName(char *name)
11109 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
11110 makeString(name)));
11114 * Handle negation of a numeric constant.
11116 * Formerly, we did this here because the optimizer couldn't cope with
11117 * indexquals that looked like "var = -4" --- it wants "var = const"
11118 * and a unary minus operator applied to a constant didn't qualify.
11119 * As of Postgres 7.0, that problem doesn't exist anymore because there
11120 * is a constant-subexpression simplifier in the optimizer. However,
11121 * there's still a good reason for doing this here, which is that we can
11122 * postpone committing to a particular internal representation for simple
11123 * negative constants. It's better to leave "-123.456" in string form
11124 * until we know what the desired type is.
11127 doNegate(Node *n, int location)
11129 if (IsA(n, A_Const))
11131 A_Const *con = (A_Const *)n;
11133 /* report the constant's location as that of the '-' sign */
11134 con->location = location;
11136 if (con->val.type == T_Integer)
11138 con->val.val.ival = -con->val.val.ival;
11141 if (con->val.type == T_Float)
11143 doNegateFloat(&con->val);
11148 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
11152 doNegateFloat(Value *v)
11154 char *oldval = v->val.str;
11156 Assert(IsA(v, Float));
11157 if (*oldval == '+')
11159 if (*oldval == '-')
11160 v->val.str = oldval+1; /* just strip the '-' */
11163 char *newval = (char *) palloc(strlen(oldval) + 2);
11166 strcpy(newval+1, oldval);
11167 v->val.str = newval;
11172 makeAArrayExpr(List *elements, int location)
11174 A_ArrayExpr *n = makeNode(A_ArrayExpr);
11176 n->elements = elements;
11177 n->location = location;
11182 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
11185 XmlExpr *x = makeNode(XmlExpr);
11190 * named_args is a list of ResTarget; it'll be split apart into separate
11191 * expression and name lists in transformXmlExpr().
11193 x->named_args = named_args;
11194 x->arg_names = NIL;
11196 /* xmloption, if relevant, must be filled in by caller */
11197 /* type and typmod will be filled in during parse analysis */
11198 x->location = location;
11203 * Initialize to parse one query string
11206 parser_init(base_yy_extra_type *yyext)
11208 yyext->parsetree = NIL; /* in case grammar forgets to set it */
11209 yyext->QueryIsRule = FALSE;
11213 * Merge the input and output parameters of a table function.
11216 mergeTableFuncParameters(List *func_args, List *columns)
11220 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
11221 foreach(lc, func_args)
11223 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
11225 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
11227 (errcode(ERRCODE_SYNTAX_ERROR),
11228 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
11231 return list_concat(func_args, columns);
11235 * Determine return type of a TABLE function. A single result column
11236 * returns setof that column's type; otherwise return setof record.
11239 TableFuncTypeName(List *columns)
11243 if (list_length(columns) == 1)
11245 FunctionParameter *p = (FunctionParameter *) linitial(columns);
11247 result = (TypeName *) copyObject(p->argType);
11250 result = SystemTypeName("record");
11252 result->setof = true;
11258 * Must undefine base_yylex before including scan.c, since we want it
11259 * to create the function base_yylex not filtered_base_yylex.
11263 /* Undefine some other stuff that would conflict in scan.c, too */