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.695 2009/12/07 05:22:22 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 * Bison doesn't allocate anything that needs to live across parser calls,
80 * so we can easily have it use palloc instead of malloc. This prevents
81 * memory leaks if we error out during parsing. Note this only works with
82 * bison >= 2.0. However, in bison 1.875 the default is to use alloca()
83 * if possible, so there's not really much problem anyhow, at least if
84 * you're building with gcc.
86 #define YYMALLOC palloc
89 /* Private struct for the result of privilege_target production */
90 typedef struct PrivTarget
92 GrantTargetType targtype;
93 GrantObjectType objtype;
98 #define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
99 #define parser_errposition(pos) scanner_errposition(pos, yyscanner)
101 static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
103 static Node *makeColumnRef(char *colname, List *indirection,
104 int location, core_yyscan_t yyscanner);
105 static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
106 static Node *makeStringConst(char *str, int location);
107 static Node *makeStringConstCast(char *str, int location, TypeName *typename);
108 static Node *makeIntConst(int val, int location);
109 static Node *makeFloatConst(char *str, int location);
110 static Node *makeBitStringConst(char *str, int location);
111 static Node *makeNullAConst(int location);
112 static Node *makeAConst(Value *v, int location);
113 static Node *makeBoolAConst(bool state, int location);
114 static FuncCall *makeOverlaps(List *largs, List *rargs,
115 int location, core_yyscan_t yyscanner);
116 static void check_qualified_name(List *names, core_yyscan_t yyscanner);
117 static List *check_func_name(List *names, core_yyscan_t yyscanner);
118 static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
119 static List *extractArgTypes(List *parameters);
120 static SelectStmt *findLeftmostSelect(SelectStmt *node);
121 static void insertSelectOptions(SelectStmt *stmt,
122 List *sortClause, List *lockingClause,
123 Node *limitOffset, Node *limitCount,
124 WithClause *withClause,
125 core_yyscan_t yyscanner);
126 static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
127 static Node *doNegate(Node *n, int location);
128 static void doNegateFloat(Value *v);
129 static Node *makeAArrayExpr(List *elements, int location);
130 static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
131 List *args, int location);
132 static List *mergeTableFuncParameters(List *func_args, List *columns);
133 static TypeName *TableFuncTypeName(List *columns);
139 %name-prefix="base_yy"
142 %parse-param {core_yyscan_t yyscanner}
143 %lex-param {core_yyscan_t yyscanner}
147 core_YYSTYPE core_yystype;
148 /* these fields must match core_YYSTYPE: */
156 DropBehavior dbehavior;
157 OnCommitAction oncommit;
163 FunctionParameter *fun_param;
164 FunctionParameterMode fun_param_mode;
165 FuncWithArgs *funwithargs;
177 struct PrivTarget *privtarget;
178 AccessPriv *accesspriv;
180 VariableSetStmt *vsetstmt;
183 %type <node> stmt schema_stmt
184 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterFdwStmt
185 AlterForeignServerStmt AlterGroupStmt
186 AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterTableStmt
187 AlterUserStmt AlterUserMappingStmt AlterUserSetStmt
188 AlterRoleStmt AlterRoleSetStmt
189 AlterDefaultPrivilegesStmt DefACLAction
190 AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
191 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
192 CreateDomainStmt CreateGroupStmt CreateOpClassStmt
193 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
194 CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
195 CreateFdwStmt CreateForeignServerStmt CreateAssertStmt CreateTrigStmt
196 CreateUserStmt CreateUserMappingStmt CreateRoleStmt
197 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
198 DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
199 DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
200 DropUserStmt DropdbStmt DropTableSpaceStmt DropFdwStmt
201 DropForeignServerStmt DropUserMappingStmt ExplainStmt FetchStmt
202 GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
203 LockStmt NotifyStmt ExplainableStmt PreparableStmt
204 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
205 RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
206 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
207 SelectStmt TransactionStmt TruncateStmt
208 UnlistenStmt UpdateStmt VacuumStmt
209 VariableResetStmt VariableSetStmt VariableShowStmt
210 ViewStmt CheckPointStmt CreateConversionStmt
211 DeallocateStmt PrepareStmt ExecuteStmt
212 DropOwnedStmt ReassignOwnedStmt
213 AlterTSConfigurationStmt AlterTSDictionaryStmt
215 %type <node> select_no_parens select_with_parens select_clause
216 simple_select values_clause
218 %type <node> alter_column_default opclass_item opclass_drop alter_using
219 %type <ival> add_drop opt_asc_desc opt_nulls_order
221 %type <node> alter_table_cmd
222 %type <list> alter_table_cmds
224 %type <dbehavior> opt_drop_behavior
226 %type <list> createdb_opt_list alterdb_opt_list copy_opt_list
227 transaction_mode_list
228 %type <defelt> createdb_opt_item alterdb_opt_item copy_opt_item
229 transaction_mode_item
231 %type <ival> opt_lock lock_type cast_context
232 %type <ival> vacuum_option_list vacuum_option_elem
233 %type <boolean> opt_force opt_or_replace
234 opt_grant_grant_option opt_grant_admin_option
235 opt_nowait opt_if_exists opt_with_data
237 %type <list> OptRoleList AlterOptRoleList
238 %type <defelt> CreateOptRoleElem AlterOptRoleElem
241 %type <str> foreign_server_version opt_foreign_server_version
242 %type <str> auth_ident
243 %type <str> opt_in_database
245 %type <str> OptSchemaName
246 %type <list> OptSchemaEltList
248 %type <boolean> TriggerActionTime TriggerForSpec opt_trusted opt_restart_seqs
250 %type <list> TriggerEvents TriggerOneEvent
251 %type <value> TriggerFuncArg
252 %type <node> TriggerWhen
254 %type <str> copy_file_name
255 database_name access_method_clause access_method attr_name
256 index_name name cursor_name file_name cluster_index_specification
258 %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
259 opt_class opt_inline_handler opt_validator validator_clause
261 %type <range> qualified_name OptConstrFromTable
263 %type <str> all_Op MathOp
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
273 %type <ival> defacl_privilege_target
274 %type <defelt> DefACLOption
275 %type <list> DefACLOptionList
277 %type <list> stmtblock stmtmulti
278 OptTableElementList TableElementList OptInherit definition
279 reloptions opt_reloptions
280 OptWith opt_distinct opt_definition func_args func_args_list
281 func_args_with_defaults func_args_with_defaults_list
282 func_as createfunc_opt_list alterfunc_opt_list
283 aggr_args old_aggr_definition old_aggr_list
284 oper_argtypes RuleActionList RuleActionMulti
285 opt_column_list columnList opt_name_list
286 sort_clause opt_sort_clause sortby_list index_params
287 name_list from_clause from_list opt_array_bounds
288 qualified_name_list any_name any_name_list
289 any_operator expr_list attrs
290 target_list insert_column_list set_target_list
291 set_clause_list set_clause multiple_set_clause
292 ctext_expr_list ctext_row def_list indirection opt_indirection
293 reloption_list group_clause TriggerFuncArgs select_limit
294 opt_select_limit opclass_item_list opclass_drop_list
295 opt_opfamily transaction_mode_list_or_empty
296 TableFuncElementList opt_type_modifiers
298 execute_param_clause using_clause returning_clause
299 enum_val_list table_func_column_list
300 create_generic_options alter_generic_options
301 relation_expr_list dostmt_opt_list
303 %type <range> OptTempTableName
304 %type <into> into_clause create_as_target
306 %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
307 %type <fun_param> func_arg func_arg_with_default table_func_column
308 %type <fun_param_mode> arg_class
309 %type <typnam> func_return func_type
311 %type <boolean> TriggerForType OptTemp
312 %type <oncommit> OnCommitOption
314 %type <node> for_locking_item
315 %type <list> for_locking_clause opt_for_locking_clause for_locking_items
316 %type <list> locked_rels_list
317 %type <boolean> opt_all
319 %type <node> join_outer join_qual
320 %type <jtype> join_type
322 %type <list> extract_list overlay_list position_list
323 %type <list> substr_list trim_list
324 %type <list> opt_interval interval_second
325 %type <node> overlay_placing substr_from substr_for
327 %type <boolean> opt_instead
328 %type <boolean> index_opt_unique opt_verbose opt_full
329 %type <boolean> opt_freeze opt_default opt_recheck
330 %type <defelt> opt_binary opt_oids copy_delimiter
332 %type <boolean> copy_from
334 %type <ival> opt_column event cursor_options opt_hold opt_set_data
335 %type <objtype> reindex_type drop_type comment_type
337 %type <node> fetch_args limit_clause select_limit_value
338 offset_clause select_offset_value
339 select_offset_value2 opt_select_fetch_first_value
340 %type <ival> row_or_rows first_or_next
342 %type <list> OptSeqOptList SeqOptList
343 %type <defelt> SeqOptElem
345 %type <istmt> insert_rest
347 %type <vsetstmt> set_rest SetResetClause
349 %type <node> TableElement ConstraintElem TableFuncElement
350 %type <node> columnDef
351 %type <defelt> def_elem reloption_elem old_aggr_elem
352 %type <node> def_arg columnElem where_clause where_or_current_clause
353 a_expr b_expr c_expr func_expr AexprConst indirection_el
354 columnref in_expr having_clause func_table array_expr
356 %type <list> ExclusionConstraintList ExclusionConstraintElem
357 %type <list> func_arg_list
358 %type <node> func_arg_expr
359 %type <list> row type_list array_expr_list
360 %type <node> case_expr case_arg when_clause case_default
361 %type <list> when_clause_list
362 %type <ival> sub_type
363 %type <list> OptCreateAs CreateAsList
364 %type <node> CreateAsElement ctext_expr
365 %type <value> NumericOnly
366 %type <alias> alias_clause
367 %type <sortby> sortby
368 %type <ielem> index_elem
369 %type <node> table_ref
370 %type <jexpr> joined_table
371 %type <range> relation_expr
372 %type <range> relation_expr_opt_alias
373 %type <target> target_el single_set_clause set_target insert_column_item
375 %type <str> generic_option_name
376 %type <node> generic_option_arg
377 %type <defelt> generic_option_elem alter_generic_option_elem
378 %type <list> generic_option_list alter_generic_option_list
379 %type <str> explain_option_name
380 %type <node> explain_option_arg
381 %type <defelt> explain_option_elem
382 %type <list> explain_option_list
383 %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
384 %type <defelt> copy_generic_opt_elem
385 %type <list> copy_generic_opt_list copy_generic_opt_arg_list
386 %type <list> copy_options
388 %type <typnam> Typename SimpleTypename ConstTypename
389 GenericType Numeric opt_float
390 Character ConstCharacter
391 CharacterWithLength CharacterWithoutLength
392 ConstDatetime ConstInterval
393 Bit ConstBit BitWithLength BitWithoutLength
394 %type <str> character
395 %type <str> extract_arg
396 %type <str> opt_charset
397 %type <boolean> opt_varying opt_timezone
399 %type <ival> Iconst SignedIconst
400 %type <str> Sconst comment_text
401 %type <str> RoleId opt_granted_by opt_boolean ColId_or_Sconst
402 %type <list> var_list
403 %type <str> ColId ColLabel var_name type_function_name param_name
404 %type <node> var_value zone_value
406 %type <keyword> unreserved_keyword type_func_name_keyword
407 %type <keyword> col_name_keyword reserved_keyword
409 %type <node> TableConstraint TableLikeClause
410 %type <ival> TableLikeOptionList TableLikeOption
411 %type <list> ColQualList
412 %type <node> ColConstraint ColConstraintElem ConstraintAttr
413 %type <ival> key_actions key_delete key_match key_update key_action
414 %type <ival> ConstraintAttributeSpec ConstraintDeferrabilitySpec
417 %type <list> constraints_set_list
418 %type <boolean> constraints_set_mode
419 %type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
420 %type <list> opt_check_option
422 %type <target> xml_attribute_el
423 %type <list> xml_attribute_list xml_attributes
424 %type <node> xml_root_version opt_xml_root_standalone
425 %type <ival> document_or_content
426 %type <boolean> xml_whitespace_option
428 %type <node> common_table_expr
429 %type <with> with_clause
430 %type <list> cte_list
432 %type <list> window_clause window_definition_list opt_partition_clause
433 %type <windef> window_definition over_clause window_specification
434 %type <str> opt_existing_window_name
435 %type <ival> opt_frame_clause frame_extent frame_bound
439 * Non-keyword token types. These are hard-wired into the "flex" lexer.
440 * They must be listed first so that their numeric codes do not depend on
441 * the set of keywords. PL/pgsql depends on this so that it can share the
442 * same lexer. If you add/change tokens here, fix PL/pgsql to match!
444 * DOT_DOT and COLON_EQUALS are unused in the core SQL grammar, and so will
445 * always provoke parse errors. They are needed by PL/pgsql.
447 %token <str> IDENT FCONST SCONST BCONST XCONST Op
448 %token <ival> ICONST PARAM
449 %token TYPECAST DOT_DOT COLON_EQUALS
452 * If you want to make any keyword changes, update the keyword table in
453 * src/include/parser/kwlist.h and add new keywords to the appropriate one
454 * of the reserved-or-not-so-reserved keyword lists, below; search
455 * this file for "Keyword category lists".
458 /* ordinary key words in alphabetical order */
459 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
460 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
461 ASSERTION ASSIGNMENT ASYMMETRIC AT AUTHORIZATION
463 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
466 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
467 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
468 CLUSTER COALESCE COLLATE COLUMN COMMENT COMMENTS COMMIT
469 COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
470 CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
471 CREATEROLE CREATEUSER CROSS CSV CURRENT_P
472 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
473 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
475 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
476 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
477 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
479 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT
480 EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
482 FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOLLOWING FOR FORCE FOREIGN FORWARD
483 FREEZE FROM FULL FUNCTION FUNCTIONS
485 GLOBAL GRANT GRANTED GREATEST GROUP_P
487 HANDLER HAVING HEADER_P HOLD HOUR_P
489 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
490 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
491 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
492 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
498 LANGUAGE LARGE_P LAST_P LC_COLLATE_P LC_CTYPE_P LEADING
499 LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP
500 LOCATION LOCK_P LOGIN_P
502 MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
504 NAME_P NAMES NATIONAL NATURAL NCHAR NEXT NO NOCREATEDB
505 NOCREATEROLE NOCREATEUSER NOINHERIT NOLOGIN_P NONE NOSUPERUSER
506 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NULLS_P NUMERIC
508 OBJECT_P OF OFF OFFSET OIDS ON ONLY OPERATOR OPTION OPTIONS OR
509 ORDER OUT_P OUTER_P OVER OVERLAPS OVERLAY OWNED OWNER
511 PARSER PARTIAL PARTITION PASSWORD PLACING PLANS POSITION
512 PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
513 PRIOR PRIVILEGES PROCEDURAL PROCEDURE
517 RANGE READ REAL REASSIGN RECHECK RECURSIVE REFERENCES REINDEX
518 RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA RESET RESTART
519 RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROW ROWS RULE
521 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE SEQUENCES
522 SERIALIZABLE SERVER SESSION SESSION_USER SET SETOF SHARE
523 SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT
524 STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING SUPERUSER_P
525 SYMMETRIC SYSID SYSTEM_P
527 TABLE TABLES TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
528 TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
529 TRUNCATE TRUSTED TYPE_P
531 UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
534 VACUUM VALID VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
535 VERBOSE VERSION_P VIEW VOLATILE
537 WHEN WHERE WHITESPACE_P WINDOW WITH WITHOUT WORK WRAPPER WRITE
539 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLFOREST XMLPARSE
540 XMLPI XMLROOT XMLSERIALIZE
547 * The grammar thinks these are keywords, but they are not in the kwlist.h
548 * list and so can never be entered directly. The filter in parser.c
549 * creates these tokens when required.
551 %token NULLS_FIRST NULLS_LAST WITH_TIME
554 /* Precedence: lowest to highest */
555 %nonassoc SET /* see relation_expr_opt_alias */
563 %nonassoc LIKE ILIKE SIMILAR
568 %left POSTFIXOP /* dummy for postfix Op rules */
570 * To support target_el without AS, we must give IDENT an explicit priority
571 * between POSTFIXOP and Op. We can safely assign the same priority to
572 * various unreserved keywords as needed to resolve ambiguities (this can't
573 * have any bad effects since obviously the keywords will still behave the
574 * same as if they weren't keywords). We need to do this for PARTITION,
575 * RANGE, ROWS to support opt_existing_window_name; and for RANGE, ROWS
576 * so that they can follow a_expr without creating
577 * postfix-operator problems.
579 %nonassoc IDENT PARTITION RANGE ROWS
580 %left Op OPERATOR /* multi-character ops and user-defined operators */
583 %nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN /* sets precedence for IS NULL, etc */
587 /* Unary Operators */
588 %left AT ZONE /* sets precedence for AT TIME ZONE */
595 * These might seem to be low-precedence, but actually they are not part
596 * of the arithmetic hierarchy at all in their use as JOIN operators.
597 * We make them high-precedence to support their use as function names.
598 * They wouldn't be given a precedence at all, were it not that we need
599 * left-associativity among the JOIN rules themselves.
601 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
602 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
603 %right PRESERVE STRIP_P
608 * The target production for the whole parse.
612 pg_yyget_extra(yyscanner)->parsetree = $1;
616 /* the thrashing around here is to discard "empty" statements... */
617 stmtmulti: stmtmulti ';' stmt
620 $$ = lappend($1, $3);
635 | AlterDatabaseSetStmt
636 | AlterDefaultPrivilegesStmt
639 | AlterForeignServerStmt
642 | AlterObjectSchemaStmt
648 | AlterTSConfigurationStmt
649 | AlterTSDictionaryStmt
650 | AlterUserMappingStmt
663 | CreateConversionStmt
666 | CreateForeignServerStmt
676 | CreateTableSpaceStmt
680 | CreateUserMappingStmt
691 | DropForeignServerStmt
703 | DropUserMappingStmt
740 /*****************************************************************************
742 * Create a new Postgres DBMS role
744 *****************************************************************************/
747 CREATE ROLE RoleId opt_with OptRoleList
749 CreateRoleStmt *n = makeNode(CreateRoleStmt);
750 n->stmt_type = ROLESTMT_ROLE;
763 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
764 * for backwards compatibility). Note: the only option required by SQL99
765 * is "WITH ADMIN name".
768 OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
769 | /* EMPTY */ { $$ = NIL; }
773 AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
774 | /* EMPTY */ { $$ = NIL; }
780 $$ = makeDefElem("password",
781 (Node *)makeString($2));
785 $$ = makeDefElem("password", NULL);
787 | ENCRYPTED PASSWORD Sconst
789 $$ = makeDefElem("encryptedPassword",
790 (Node *)makeString($3));
792 | UNENCRYPTED PASSWORD Sconst
794 $$ = makeDefElem("unencryptedPassword",
795 (Node *)makeString($3));
799 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
803 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
807 $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE));
811 $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE));
815 $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
819 $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
823 $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE));
827 $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE));
831 /* For backwards compatibility, synonym for SUPERUSER */
832 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
836 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
840 $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE));
844 $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE));
846 | CONNECTION LIMIT SignedIconst
848 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3));
852 $$ = makeDefElem("validUntil", (Node *)makeString($3));
854 /* Supported but not documented for roles, for use by ALTER GROUP. */
857 $$ = makeDefElem("rolemembers", (Node *)$2);
862 AlterOptRoleElem { $$ = $1; }
863 /* The following are not supported by ALTER ROLE/USER/GROUP */
866 $$ = makeDefElem("sysid", (Node *)makeInteger($2));
870 $$ = makeDefElem("adminmembers", (Node *)$2);
874 $$ = makeDefElem("rolemembers", (Node *)$2);
876 | IN_P ROLE name_list
878 $$ = makeDefElem("addroleto", (Node *)$3);
880 | IN_P GROUP_P name_list
882 $$ = makeDefElem("addroleto", (Node *)$3);
887 /*****************************************************************************
889 * Create a new Postgres DBMS user (role with implied login ability)
891 *****************************************************************************/
894 CREATE USER RoleId opt_with OptRoleList
896 CreateRoleStmt *n = makeNode(CreateRoleStmt);
897 n->stmt_type = ROLESTMT_USER;
905 /*****************************************************************************
907 * Alter a postgresql DBMS role
909 *****************************************************************************/
912 ALTER ROLE RoleId opt_with AlterOptRoleList
914 AlterRoleStmt *n = makeNode(AlterRoleStmt);
916 n->action = +1; /* add, if there are members */
923 /* EMPTY */ { $$ = NULL; }
924 | IN_P DATABASE database_name { $$ = $3; }
928 ALTER ROLE RoleId opt_in_database SetResetClause
930 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
939 /*****************************************************************************
941 * Alter a postgresql DBMS user
943 *****************************************************************************/
946 ALTER USER RoleId opt_with AlterOptRoleList
948 AlterRoleStmt *n = makeNode(AlterRoleStmt);
950 n->action = +1; /* add, if there are members */
958 ALTER USER RoleId SetResetClause
960 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
969 /*****************************************************************************
971 * Drop a postgresql DBMS role
973 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
974 * might own objects in multiple databases, there is presently no way to
975 * implement either cascading or restricting. Caveat DBA.
976 *****************************************************************************/
981 DropRoleStmt *n = makeNode(DropRoleStmt);
982 n->missing_ok = FALSE;
986 | DROP ROLE IF_P EXISTS name_list
988 DropRoleStmt *n = makeNode(DropRoleStmt);
989 n->missing_ok = TRUE;
995 /*****************************************************************************
997 * Drop a postgresql DBMS user
999 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
1000 * might own objects in multiple databases, there is presently no way to
1001 * implement either cascading or restricting. Caveat DBA.
1002 *****************************************************************************/
1007 DropRoleStmt *n = makeNode(DropRoleStmt);
1008 n->missing_ok = FALSE;
1012 | DROP USER IF_P EXISTS name_list
1014 DropRoleStmt *n = makeNode(DropRoleStmt);
1016 n->missing_ok = TRUE;
1022 /*****************************************************************************
1024 * Create a postgresql group (role without login ability)
1026 *****************************************************************************/
1029 CREATE GROUP_P RoleId opt_with OptRoleList
1031 CreateRoleStmt *n = makeNode(CreateRoleStmt);
1032 n->stmt_type = ROLESTMT_GROUP;
1040 /*****************************************************************************
1042 * Alter a postgresql group
1044 *****************************************************************************/
1047 ALTER GROUP_P RoleId add_drop USER name_list
1049 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1052 n->options = list_make1(makeDefElem("rolemembers",
1058 add_drop: ADD_P { $$ = +1; }
1063 /*****************************************************************************
1065 * Drop a postgresql group
1067 * XXX see above notes about cascading DROP USER; groups have same problem.
1068 *****************************************************************************/
1071 DROP GROUP_P name_list
1073 DropRoleStmt *n = makeNode(DropRoleStmt);
1074 n->missing_ok = FALSE;
1078 | DROP GROUP_P IF_P EXISTS name_list
1080 DropRoleStmt *n = makeNode(DropRoleStmt);
1081 n->missing_ok = TRUE;
1088 /*****************************************************************************
1090 * Manipulate a schema
1092 *****************************************************************************/
1095 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
1097 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1098 /* One can omit the schema name or the authorization id. */
1107 | CREATE SCHEMA ColId OptSchemaEltList
1109 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1110 /* ...but not both */
1120 | /* EMPTY */ { $$ = NULL; }
1124 OptSchemaEltList schema_stmt { $$ = lappend($1, $2); }
1125 | /* EMPTY */ { $$ = NIL; }
1129 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1130 * statement (in addition to by themselves).
1142 /*****************************************************************************
1144 * Set PG internal variable
1145 * SET name TO 'var_value'
1146 * Include SQL92 syntax (thomas 1997-10-22):
1147 * SET TIME ZONE 'var_value'
1149 *****************************************************************************/
1154 VariableSetStmt *n = $2;
1155 n->is_local = false;
1158 | SET LOCAL set_rest
1160 VariableSetStmt *n = $3;
1164 | SET SESSION set_rest
1166 VariableSetStmt *n = $3;
1167 n->is_local = false;
1172 set_rest: /* Generic SET syntaxes: */
1173 var_name TO var_list
1175 VariableSetStmt *n = makeNode(VariableSetStmt);
1176 n->kind = VAR_SET_VALUE;
1181 | var_name '=' var_list
1183 VariableSetStmt *n = makeNode(VariableSetStmt);
1184 n->kind = VAR_SET_VALUE;
1189 | var_name TO DEFAULT
1191 VariableSetStmt *n = makeNode(VariableSetStmt);
1192 n->kind = VAR_SET_DEFAULT;
1196 | var_name '=' DEFAULT
1198 VariableSetStmt *n = makeNode(VariableSetStmt);
1199 n->kind = VAR_SET_DEFAULT;
1203 | var_name FROM CURRENT_P
1205 VariableSetStmt *n = makeNode(VariableSetStmt);
1206 n->kind = VAR_SET_CURRENT;
1210 /* Special syntaxes mandated by SQL standard: */
1211 | TIME ZONE zone_value
1213 VariableSetStmt *n = makeNode(VariableSetStmt);
1214 n->kind = VAR_SET_VALUE;
1215 n->name = "timezone";
1217 n->args = list_make1($3);
1219 n->kind = VAR_SET_DEFAULT;
1222 | TRANSACTION transaction_mode_list
1224 VariableSetStmt *n = makeNode(VariableSetStmt);
1225 n->kind = VAR_SET_MULTI;
1226 n->name = "TRANSACTION";
1230 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1232 VariableSetStmt *n = makeNode(VariableSetStmt);
1233 n->kind = VAR_SET_MULTI;
1234 n->name = "SESSION CHARACTERISTICS";
1241 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1242 errmsg("current database cannot be changed"),
1243 parser_errposition(@2)));
1244 $$ = NULL; /*not reached*/
1248 VariableSetStmt *n = makeNode(VariableSetStmt);
1249 n->kind = VAR_SET_VALUE;
1250 n->name = "search_path";
1251 n->args = list_make1(makeStringConst($2, @2));
1254 | NAMES opt_encoding
1256 VariableSetStmt *n = makeNode(VariableSetStmt);
1257 n->kind = VAR_SET_VALUE;
1258 n->name = "client_encoding";
1260 n->args = list_make1(makeStringConst($2, @2));
1262 n->kind = VAR_SET_DEFAULT;
1265 | ROLE ColId_or_Sconst
1267 VariableSetStmt *n = makeNode(VariableSetStmt);
1268 n->kind = VAR_SET_VALUE;
1270 n->args = list_make1(makeStringConst($2, @2));
1273 | SESSION AUTHORIZATION ColId_or_Sconst
1275 VariableSetStmt *n = makeNode(VariableSetStmt);
1276 n->kind = VAR_SET_VALUE;
1277 n->name = "session_authorization";
1278 n->args = list_make1(makeStringConst($3, @3));
1281 | SESSION AUTHORIZATION DEFAULT
1283 VariableSetStmt *n = makeNode(VariableSetStmt);
1284 n->kind = VAR_SET_DEFAULT;
1285 n->name = "session_authorization";
1288 | XML_P OPTION document_or_content
1290 VariableSetStmt *n = makeNode(VariableSetStmt);
1291 n->kind = VAR_SET_VALUE;
1292 n->name = "xmloption";
1293 n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1298 var_name: ColId { $$ = $1; }
1299 | var_name '.' ColId
1301 $$ = palloc(strlen($1) + strlen($3) + 2);
1302 sprintf($$, "%s.%s", $1, $3);
1306 var_list: var_value { $$ = list_make1($1); }
1307 | var_list ',' var_value { $$ = lappend($1, $3); }
1310 var_value: opt_boolean
1311 { $$ = makeStringConst($1, @1); }
1313 { $$ = makeStringConst($1, @1); }
1315 { $$ = makeAConst($1, @1); }
1318 iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1319 | READ COMMITTED { $$ = "read committed"; }
1320 | REPEATABLE READ { $$ = "repeatable read"; }
1321 | SERIALIZABLE { $$ = "serializable"; }
1325 TRUE_P { $$ = "true"; }
1326 | FALSE_P { $$ = "false"; }
1328 | OFF { $$ = "off"; }
1331 /* Timezone values can be:
1332 * - a string such as 'pst8pdt'
1333 * - an identifier such as "pst8pdt"
1334 * - an integer or floating point number
1335 * - a time interval per SQL99
1336 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1337 * so use IDENT (meaning we reject anything that is a key word).
1342 $$ = makeStringConst($1, @1);
1346 $$ = makeStringConst($1, @1);
1348 | ConstInterval Sconst opt_interval
1353 A_Const *n = (A_Const *) linitial($3);
1354 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1356 (errcode(ERRCODE_SYNTAX_ERROR),
1357 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1358 parser_errposition(@3)));
1361 $$ = makeStringConstCast($2, @2, t);
1363 | ConstInterval '(' Iconst ')' Sconst opt_interval
1368 A_Const *n = (A_Const *) linitial($6);
1369 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1371 (errcode(ERRCODE_SYNTAX_ERROR),
1372 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1373 parser_errposition(@6)));
1374 if (list_length($6) != 1)
1376 (errcode(ERRCODE_SYNTAX_ERROR),
1377 errmsg("interval precision specified twice"),
1378 parser_errposition(@1)));
1379 t->typmods = lappend($6, makeIntConst($3, @3));
1382 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1383 makeIntConst($3, @3));
1384 $$ = makeStringConstCast($5, @5, t);
1386 | NumericOnly { $$ = makeAConst($1, @1); }
1387 | DEFAULT { $$ = NULL; }
1388 | LOCAL { $$ = NULL; }
1393 | DEFAULT { $$ = NULL; }
1394 | /*EMPTY*/ { $$ = NULL; }
1399 | Sconst { $$ = $1; }
1405 VariableSetStmt *n = makeNode(VariableSetStmt);
1406 n->kind = VAR_RESET;
1412 VariableSetStmt *n = makeNode(VariableSetStmt);
1413 n->kind = VAR_RESET;
1414 n->name = "timezone";
1417 | RESET TRANSACTION ISOLATION LEVEL
1419 VariableSetStmt *n = makeNode(VariableSetStmt);
1420 n->kind = VAR_RESET;
1421 n->name = "transaction_isolation";
1424 | RESET SESSION AUTHORIZATION
1426 VariableSetStmt *n = makeNode(VariableSetStmt);
1427 n->kind = VAR_RESET;
1428 n->name = "session_authorization";
1433 VariableSetStmt *n = makeNode(VariableSetStmt);
1434 n->kind = VAR_RESET_ALL;
1439 /* SetResetClause allows SET or RESET without LOCAL */
1441 SET set_rest { $$ = $2; }
1442 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1449 VariableShowStmt *n = makeNode(VariableShowStmt);
1455 VariableShowStmt *n = makeNode(VariableShowStmt);
1456 n->name = "timezone";
1459 | SHOW TRANSACTION ISOLATION LEVEL
1461 VariableShowStmt *n = makeNode(VariableShowStmt);
1462 n->name = "transaction_isolation";
1465 | SHOW SESSION AUTHORIZATION
1467 VariableShowStmt *n = makeNode(VariableShowStmt);
1468 n->name = "session_authorization";
1473 VariableShowStmt *n = makeNode(VariableShowStmt);
1481 SET CONSTRAINTS constraints_set_list constraints_set_mode
1483 ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
1484 n->constraints = $3;
1490 constraints_set_list:
1492 | qualified_name_list { $$ = $1; }
1495 constraints_set_mode:
1496 DEFERRED { $$ = TRUE; }
1497 | IMMEDIATE { $$ = FALSE; }
1502 * Checkpoint statement
1507 CheckPointStmt *n = makeNode(CheckPointStmt);
1513 /*****************************************************************************
1515 * DISCARD { ALL | TEMP | PLANS }
1517 *****************************************************************************/
1522 DiscardStmt *n = makeNode(DiscardStmt);
1523 n->target = DISCARD_ALL;
1528 DiscardStmt *n = makeNode(DiscardStmt);
1529 n->target = DISCARD_TEMP;
1534 DiscardStmt *n = makeNode(DiscardStmt);
1535 n->target = DISCARD_TEMP;
1540 DiscardStmt *n = makeNode(DiscardStmt);
1541 n->target = DISCARD_PLANS;
1547 /*****************************************************************************
1549 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations
1551 * Note: we accept all subcommands for each of the four variants, and sort
1552 * out what's really legal at execution time.
1553 *****************************************************************************/
1556 ALTER TABLE relation_expr alter_table_cmds
1558 AlterTableStmt *n = makeNode(AlterTableStmt);
1561 n->relkind = OBJECT_TABLE;
1564 | ALTER INDEX qualified_name alter_table_cmds
1566 AlterTableStmt *n = makeNode(AlterTableStmt);
1569 n->relkind = OBJECT_INDEX;
1572 | ALTER SEQUENCE qualified_name alter_table_cmds
1574 AlterTableStmt *n = makeNode(AlterTableStmt);
1577 n->relkind = OBJECT_SEQUENCE;
1580 | ALTER VIEW qualified_name alter_table_cmds
1582 AlterTableStmt *n = makeNode(AlterTableStmt);
1585 n->relkind = OBJECT_VIEW;
1591 alter_table_cmd { $$ = list_make1($1); }
1592 | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
1596 /* ALTER TABLE <name> ADD <coldef> */
1599 AlterTableCmd *n = makeNode(AlterTableCmd);
1600 n->subtype = AT_AddColumn;
1604 /* ALTER TABLE <name> ADD COLUMN <coldef> */
1605 | ADD_P COLUMN columnDef
1607 AlterTableCmd *n = makeNode(AlterTableCmd);
1608 n->subtype = AT_AddColumn;
1612 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1613 | ALTER opt_column ColId alter_column_default
1615 AlterTableCmd *n = makeNode(AlterTableCmd);
1616 n->subtype = AT_ColumnDefault;
1621 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1622 | ALTER opt_column ColId DROP NOT NULL_P
1624 AlterTableCmd *n = makeNode(AlterTableCmd);
1625 n->subtype = AT_DropNotNull;
1629 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1630 | ALTER opt_column ColId SET NOT NULL_P
1632 AlterTableCmd *n = makeNode(AlterTableCmd);
1633 n->subtype = AT_SetNotNull;
1637 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
1638 | ALTER opt_column ColId SET STATISTICS SignedIconst
1640 AlterTableCmd *n = makeNode(AlterTableCmd);
1641 n->subtype = AT_SetStatistics;
1643 n->def = (Node *) makeInteger($6);
1646 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS DISTINCT <NumericOnly> */
1647 | ALTER opt_column ColId SET STATISTICS DISTINCT NumericOnly
1649 AlterTableCmd *n = makeNode(AlterTableCmd);
1650 n->subtype = AT_SetDistinct;
1652 n->def = (Node *) $7;
1655 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1656 | ALTER opt_column ColId SET STORAGE ColId
1658 AlterTableCmd *n = makeNode(AlterTableCmd);
1659 n->subtype = AT_SetStorage;
1661 n->def = (Node *) makeString($6);
1664 /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
1665 | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
1667 AlterTableCmd *n = makeNode(AlterTableCmd);
1668 n->subtype = AT_DropColumn;
1671 n->missing_ok = TRUE;
1674 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1675 | DROP opt_column ColId opt_drop_behavior
1677 AlterTableCmd *n = makeNode(AlterTableCmd);
1678 n->subtype = AT_DropColumn;
1681 n->missing_ok = FALSE;
1685 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
1686 * [ USING <expression> ]
1688 | ALTER opt_column ColId opt_set_data TYPE_P Typename alter_using
1690 AlterTableCmd *n = makeNode(AlterTableCmd);
1691 n->subtype = AT_AlterColumnType;
1693 n->def = (Node *) $6;
1697 /* ALTER TABLE <name> ADD CONSTRAINT ... */
1698 | ADD_P TableConstraint
1700 AlterTableCmd *n = makeNode(AlterTableCmd);
1701 n->subtype = AT_AddConstraint;
1705 /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
1706 | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
1708 AlterTableCmd *n = makeNode(AlterTableCmd);
1709 n->subtype = AT_DropConstraint;
1712 n->missing_ok = TRUE;
1715 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1716 | DROP CONSTRAINT name opt_drop_behavior
1718 AlterTableCmd *n = makeNode(AlterTableCmd);
1719 n->subtype = AT_DropConstraint;
1722 n->missing_ok = FALSE;
1725 /* ALTER TABLE <name> SET WITH OIDS */
1728 AlterTableCmd *n = makeNode(AlterTableCmd);
1729 n->subtype = AT_AddOids;
1732 /* ALTER TABLE <name> SET WITHOUT OIDS */
1735 AlterTableCmd *n = makeNode(AlterTableCmd);
1736 n->subtype = AT_DropOids;
1739 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1742 AlterTableCmd *n = makeNode(AlterTableCmd);
1743 n->subtype = AT_ClusterOn;
1747 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1748 | SET WITHOUT CLUSTER
1750 AlterTableCmd *n = makeNode(AlterTableCmd);
1751 n->subtype = AT_DropCluster;
1755 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
1756 | ENABLE_P TRIGGER name
1758 AlterTableCmd *n = makeNode(AlterTableCmd);
1759 n->subtype = AT_EnableTrig;
1763 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
1764 | ENABLE_P ALWAYS TRIGGER name
1766 AlterTableCmd *n = makeNode(AlterTableCmd);
1767 n->subtype = AT_EnableAlwaysTrig;
1771 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
1772 | ENABLE_P REPLICA TRIGGER name
1774 AlterTableCmd *n = makeNode(AlterTableCmd);
1775 n->subtype = AT_EnableReplicaTrig;
1779 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
1780 | ENABLE_P TRIGGER ALL
1782 AlterTableCmd *n = makeNode(AlterTableCmd);
1783 n->subtype = AT_EnableTrigAll;
1786 /* ALTER TABLE <name> ENABLE TRIGGER USER */
1787 | ENABLE_P TRIGGER USER
1789 AlterTableCmd *n = makeNode(AlterTableCmd);
1790 n->subtype = AT_EnableTrigUser;
1793 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
1794 | DISABLE_P TRIGGER name
1796 AlterTableCmd *n = makeNode(AlterTableCmd);
1797 n->subtype = AT_DisableTrig;
1801 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
1802 | DISABLE_P TRIGGER ALL
1804 AlterTableCmd *n = makeNode(AlterTableCmd);
1805 n->subtype = AT_DisableTrigAll;
1808 /* ALTER TABLE <name> DISABLE TRIGGER USER */
1809 | DISABLE_P TRIGGER USER
1811 AlterTableCmd *n = makeNode(AlterTableCmd);
1812 n->subtype = AT_DisableTrigUser;
1815 /* ALTER TABLE <name> ENABLE RULE <rule> */
1816 | ENABLE_P RULE name
1818 AlterTableCmd *n = makeNode(AlterTableCmd);
1819 n->subtype = AT_EnableRule;
1823 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
1824 | ENABLE_P ALWAYS RULE name
1826 AlterTableCmd *n = makeNode(AlterTableCmd);
1827 n->subtype = AT_EnableAlwaysRule;
1831 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
1832 | ENABLE_P REPLICA RULE name
1834 AlterTableCmd *n = makeNode(AlterTableCmd);
1835 n->subtype = AT_EnableReplicaRule;
1839 /* ALTER TABLE <name> DISABLE RULE <rule> */
1840 | DISABLE_P RULE name
1842 AlterTableCmd *n = makeNode(AlterTableCmd);
1843 n->subtype = AT_DisableRule;
1847 /* ALTER TABLE <name> INHERIT <parent> */
1848 | INHERIT qualified_name
1850 AlterTableCmd *n = makeNode(AlterTableCmd);
1851 n->subtype = AT_AddInherit;
1852 n->def = (Node *) $2;
1855 /* ALTER TABLE <name> NO INHERIT <parent> */
1856 | NO INHERIT qualified_name
1858 AlterTableCmd *n = makeNode(AlterTableCmd);
1859 n->subtype = AT_DropInherit;
1860 n->def = (Node *) $3;
1863 /* ALTER TABLE <name> OWNER TO RoleId */
1866 AlterTableCmd *n = makeNode(AlterTableCmd);
1867 n->subtype = AT_ChangeOwner;
1871 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1872 | SET TABLESPACE name
1874 AlterTableCmd *n = makeNode(AlterTableCmd);
1875 n->subtype = AT_SetTableSpace;
1879 /* ALTER TABLE <name> SET (...) */
1882 AlterTableCmd *n = makeNode(AlterTableCmd);
1883 n->subtype = AT_SetRelOptions;
1884 n->def = (Node *)$2;
1887 /* ALTER TABLE <name> RESET (...) */
1890 AlterTableCmd *n = makeNode(AlterTableCmd);
1891 n->subtype = AT_ResetRelOptions;
1892 n->def = (Node *)$2;
1897 alter_column_default:
1898 SET DEFAULT a_expr { $$ = $3; }
1899 | DROP DEFAULT { $$ = NULL; }
1903 CASCADE { $$ = DROP_CASCADE; }
1904 | RESTRICT { $$ = DROP_RESTRICT; }
1905 | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1909 USING a_expr { $$ = $2; }
1910 | /* EMPTY */ { $$ = NULL; }
1914 '(' reloption_list ')' { $$ = $2; }
1917 opt_reloptions: WITH reloptions { $$ = $2; }
1918 | /* EMPTY */ { $$ = NIL; }
1922 reloption_elem { $$ = list_make1($1); }
1923 | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
1926 /* This should match def_elem and also allow qualified names */
1928 ColLabel '=' def_arg
1930 $$ = makeDefElem($1, (Node *) $3);
1934 $$ = makeDefElem($1, NULL);
1936 | ColLabel '.' ColLabel '=' def_arg
1938 $$ = makeDefElemExtended($1, $3, (Node *) $5,
1941 | ColLabel '.' ColLabel
1943 $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC);
1948 /*****************************************************************************
1951 * close <portalname>
1953 *****************************************************************************/
1958 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1964 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1965 n->portalname = NULL;
1971 /*****************************************************************************
1974 * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
1975 * COPY ( SELECT ... ) TO file [WITH] [(options)]
1977 * In the preferred syntax the options are comma-separated
1978 * and use generic identifiers instead of keywords. The pre-8.5
1979 * syntax had a hard-wired, space-separated set of options.
1981 * Really old syntax, from versions 7.2 and prior:
1982 * COPY [ BINARY ] table [ WITH OIDS ] FROM/TO file
1983 * [ [ USING ] DELIMITERS 'delimiter' ] ]
1984 * [ WITH NULL AS 'null string' ]
1985 * This option placement is not supported with COPY (SELECT...).
1987 *****************************************************************************/
1989 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
1990 copy_from copy_file_name copy_delimiter opt_with copy_options
1992 CopyStmt *n = makeNode(CopyStmt);
2000 /* Concatenate user-supplied flags */
2002 n->options = lappend(n->options, $2);
2004 n->options = lappend(n->options, $5);
2006 n->options = lappend(n->options, $8);
2008 n->options = list_concat(n->options, $10);
2011 | COPY select_with_parens TO copy_file_name opt_with copy_options
2013 CopyStmt *n = makeNode(CopyStmt);
2026 | TO { $$ = FALSE; }
2030 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
2031 * used depends on the direction. (It really doesn't make sense to copy from
2032 * stdout. We silently correct the "typo".) - AY 9/94
2036 | STDIN { $$ = NULL; }
2037 | STDOUT { $$ = NULL; }
2040 copy_options: copy_opt_list { $$ = $1; }
2041 | '(' copy_generic_opt_list ')' { $$ = $2; }
2044 /* old COPY option syntax */
2046 copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
2047 | /* EMPTY */ { $$ = NIL; }
2053 $$ = makeDefElem("format", (Node *)makeString("binary"));
2057 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2059 | DELIMITER opt_as Sconst
2061 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2063 | NULL_P opt_as Sconst
2065 $$ = makeDefElem("null", (Node *)makeString($3));
2069 $$ = makeDefElem("format", (Node *)makeString("csv"));
2073 $$ = makeDefElem("header", (Node *)makeInteger(TRUE));
2075 | QUOTE opt_as Sconst
2077 $$ = makeDefElem("quote", (Node *)makeString($3));
2079 | ESCAPE opt_as Sconst
2081 $$ = makeDefElem("escape", (Node *)makeString($3));
2083 | FORCE QUOTE columnList
2085 $$ = makeDefElem("force_quote", (Node *)$3);
2089 $$ = makeDefElem("force_quote", (Node *)makeNode(A_Star));
2091 | FORCE NOT NULL_P columnList
2093 $$ = makeDefElem("force_not_null", (Node *)$4);
2097 /* The following exist for backward compatibility with very old versions */
2102 $$ = makeDefElem("format", (Node *)makeString("binary"));
2104 | /*EMPTY*/ { $$ = NULL; }
2110 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2112 | /*EMPTY*/ { $$ = NULL; }
2116 opt_using DELIMITERS Sconst
2118 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2120 | /*EMPTY*/ { $$ = NULL; }
2128 /* new COPY option syntax */
2129 copy_generic_opt_list:
2130 copy_generic_opt_elem
2132 $$ = list_make1($1);
2134 | copy_generic_opt_list ',' copy_generic_opt_elem
2136 $$ = lappend($1, $3);
2140 copy_generic_opt_elem:
2141 ColLabel copy_generic_opt_arg
2143 $$ = makeDefElem($1, $2);
2147 copy_generic_opt_arg:
2148 opt_boolean { $$ = (Node *) makeString($1); }
2149 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
2150 | NumericOnly { $$ = (Node *) $1; }
2151 | '*' { $$ = (Node *) makeNode(A_Star); }
2152 | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
2153 | /* EMPTY */ { $$ = NULL; }
2156 copy_generic_opt_arg_list:
2157 copy_generic_opt_arg_list_item
2159 $$ = list_make1($1);
2161 | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
2163 $$ = lappend($1, $3);
2167 /* beware of emitting non-string list elements here; see commands/define.c */
2168 copy_generic_opt_arg_list_item:
2169 opt_boolean { $$ = (Node *) makeString($1); }
2170 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
2174 /*****************************************************************************
2177 * CREATE TABLE relname
2179 *****************************************************************************/
2181 CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
2182 OptInherit OptWith OnCommitOption OptTableSpace
2184 CreateStmt *n = makeNode(CreateStmt);
2188 n->inhRelations = $8;
2189 n->constraints = NIL;
2192 n->tablespacename = $11;
2195 | CREATE OptTemp TABLE qualified_name OF qualified_name
2196 '(' OptTableElementList ')' OptWith OnCommitOption OptTableSpace
2198 /* SQL99 CREATE TABLE OF <UDT> (cols) seems to be satisfied
2199 * by our inheritance capabilities. Let's try it...
2201 CreateStmt *n = makeNode(CreateStmt);
2205 n->inhRelations = list_make1($6);
2206 n->constraints = NIL;
2209 n->tablespacename = $12;
2215 * Redundancy here is needed to avoid shift/reduce conflicts,
2216 * since TEMP is not a reserved word. See also OptTempTableName.
2218 * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
2219 * the LOCAL keyword is really meaningless.
2221 OptTemp: TEMPORARY { $$ = TRUE; }
2222 | TEMP { $$ = TRUE; }
2223 | LOCAL TEMPORARY { $$ = TRUE; }
2224 | LOCAL TEMP { $$ = TRUE; }
2225 | GLOBAL TEMPORARY { $$ = TRUE; }
2226 | GLOBAL TEMP { $$ = TRUE; }
2227 | /*EMPTY*/ { $$ = FALSE; }
2230 OptTableElementList:
2231 TableElementList { $$ = $1; }
2232 | /*EMPTY*/ { $$ = NIL; }
2238 $$ = list_make1($1);
2240 | TableElementList ',' TableElement
2242 $$ = lappend($1, $3);
2247 columnDef { $$ = $1; }
2248 | TableLikeClause { $$ = $1; }
2249 | TableConstraint { $$ = $1; }
2252 columnDef: ColId Typename ColQualList
2254 ColumnDef *n = makeNode(ColumnDef);
2257 n->constraints = $3;
2264 ColQualList ColConstraint { $$ = lappend($1, $2); }
2265 | /*EMPTY*/ { $$ = NIL; }
2269 CONSTRAINT name ColConstraintElem
2271 Constraint *n = (Constraint *) $3;
2272 Assert(IsA(n, Constraint));
2277 | ColConstraintElem { $$ = $1; }
2278 | ConstraintAttr { $$ = $1; }
2281 /* DEFAULT NULL is already the default for Postgres.
2282 * But define it here and carry it forward into the system
2283 * to make it explicit.
2284 * - thomas 1998-09-13
2286 * WITH NULL and NULL are not SQL92-standard syntax elements,
2287 * so leave them out. Use DEFAULT NULL to explicitly indicate
2288 * that a column may have that value. WITH NULL leads to
2289 * shift/reduce conflicts with WITH TIME ZONE anyway.
2290 * - thomas 1999-01-08
2292 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
2293 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
2294 * or be part of a_expr NOT LIKE or similar constructs).
2299 Constraint *n = makeNode(Constraint);
2300 n->contype = CONSTR_NOTNULL;
2306 Constraint *n = makeNode(Constraint);
2307 n->contype = CONSTR_NULL;
2311 | UNIQUE opt_definition OptConsTableSpace
2313 Constraint *n = makeNode(Constraint);
2314 n->contype = CONSTR_UNIQUE;
2321 | PRIMARY KEY opt_definition OptConsTableSpace
2323 Constraint *n = makeNode(Constraint);
2324 n->contype = CONSTR_PRIMARY;
2331 | CHECK '(' a_expr ')'
2333 Constraint *n = makeNode(Constraint);
2334 n->contype = CONSTR_CHECK;
2337 n->cooked_expr = NULL;
2342 Constraint *n = makeNode(Constraint);
2343 n->contype = CONSTR_DEFAULT;
2346 n->cooked_expr = NULL;
2349 | REFERENCES qualified_name opt_column_list key_match key_actions
2351 Constraint *n = makeNode(Constraint);
2352 n->contype = CONSTR_FOREIGN;
2357 n->fk_matchtype = $4;
2358 n->fk_upd_action = (char) ($5 >> 8);
2359 n->fk_del_action = (char) ($5 & 0xFF);
2360 n->skip_validation = FALSE;
2366 * ConstraintAttr represents constraint attributes, which we parse as if
2367 * they were independent constraint clauses, in order to avoid shift/reduce
2368 * conflicts (since NOT might start either an independent NOT NULL clause
2369 * or an attribute). parse_utilcmd.c is responsible for attaching the
2370 * attribute information to the preceding "real" constraint node, and for
2371 * complaining if attribute clauses appear in the wrong place or wrong
2374 * See also ConstraintAttributeSpec, which can be used in places where
2375 * there is no parsing conflict.
2380 Constraint *n = makeNode(Constraint);
2381 n->contype = CONSTR_ATTR_DEFERRABLE;
2387 Constraint *n = makeNode(Constraint);
2388 n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
2392 | INITIALLY DEFERRED
2394 Constraint *n = makeNode(Constraint);
2395 n->contype = CONSTR_ATTR_DEFERRED;
2399 | INITIALLY IMMEDIATE
2401 Constraint *n = makeNode(Constraint);
2402 n->contype = CONSTR_ATTR_IMMEDIATE;
2410 * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2411 * This seems to be a poor man's inheritance capability, with the resulting
2412 * tables completely decoupled except for the original commonality in definitions.
2414 * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2415 * which is a part of SQL:2003.
2418 LIKE qualified_name TableLikeOptionList
2420 InhRelation *n = makeNode(InhRelation);
2427 TableLikeOptionList:
2428 TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
2429 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
2430 | /* EMPTY */ { $$ = 0; }
2434 DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
2435 | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
2436 | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
2437 | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
2438 | COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
2439 | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
2443 /* ConstraintElem specifies constraint syntax which is not embedded into
2444 * a column definition. ColConstraintElem specifies the embedded form.
2445 * - thomas 1997-12-03
2448 CONSTRAINT name ConstraintElem
2450 Constraint *n = (Constraint *) $3;
2451 Assert(IsA(n, Constraint));
2456 | ConstraintElem { $$ = $1; }
2460 CHECK '(' a_expr ')' ConstraintAttributeSpec
2462 Constraint *n = makeNode(Constraint);
2463 n->contype = CONSTR_CHECK;
2466 n->cooked_expr = NULL;
2469 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2470 errmsg("CHECK constraints cannot be deferred"),
2471 parser_errposition(@5)));
2474 | UNIQUE '(' columnList ')' opt_definition OptConsTableSpace
2475 ConstraintAttributeSpec
2477 Constraint *n = makeNode(Constraint);
2478 n->contype = CONSTR_UNIQUE;
2483 n->deferrable = ($7 & 1) != 0;
2484 n->initdeferred = ($7 & 2) != 0;
2487 | PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace
2488 ConstraintAttributeSpec
2490 Constraint *n = makeNode(Constraint);
2491 n->contype = CONSTR_PRIMARY;
2496 n->deferrable = ($8 & 1) != 0;
2497 n->initdeferred = ($8 & 2) != 0;
2500 | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
2501 opt_definition OptConsTableSpace ExclusionWhereClause
2502 ConstraintAttributeSpec
2504 Constraint *n = makeNode(Constraint);
2505 n->contype = CONSTR_EXCLUSION;
2507 n->access_method = $2;
2511 n->where_clause = $8;
2512 n->deferrable = ($9 & 1) != 0;
2513 n->initdeferred = ($9 & 2) != 0;
2516 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
2517 opt_column_list key_match key_actions ConstraintAttributeSpec
2519 Constraint *n = makeNode(Constraint);
2520 n->contype = CONSTR_FOREIGN;
2525 n->fk_matchtype = $9;
2526 n->fk_upd_action = (char) ($10 >> 8);
2527 n->fk_del_action = (char) ($10 & 0xFF);
2528 n->skip_validation = FALSE;
2529 n->deferrable = ($11 & 1) != 0;
2530 n->initdeferred = ($11 & 2) != 0;
2536 '(' columnList ')' { $$ = $2; }
2537 | /*EMPTY*/ { $$ = NIL; }
2541 columnElem { $$ = list_make1($1); }
2542 | columnList ',' columnElem { $$ = lappend($1, $3); }
2547 $$ = (Node *) makeString($1);
2551 key_match: MATCH FULL
2553 $$ = FKCONSTR_MATCH_FULL;
2558 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2559 errmsg("MATCH PARTIAL not yet implemented"),
2560 parser_errposition(@1)));
2561 $$ = FKCONSTR_MATCH_PARTIAL;
2565 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2569 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2573 ExclusionConstraintList:
2574 ExclusionConstraintElem { $$ = list_make1($1); }
2575 | ExclusionConstraintList ',' ExclusionConstraintElem
2576 { $$ = lappend($1, $3); }
2579 ExclusionConstraintElem: index_elem WITH any_operator
2581 $$ = list_make2($1, $3);
2583 /* allow OPERATOR() decoration for the benefit of ruleutils.c */
2584 | index_elem WITH OPERATOR '(' any_operator ')'
2586 $$ = list_make2($1, $5);
2590 ExclusionWhereClause:
2591 WHERE '(' a_expr ')' { $$ = $3; }
2592 | /*EMPTY*/ { $$ = NULL; }
2596 * We combine the update and delete actions into one value temporarily
2597 * for simplicity of parsing, and then break them down again in the
2598 * calling production. update is in the left 8 bits, delete in the right.
2599 * Note that NOACTION is the default.
2603 { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2605 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
2606 | key_update key_delete
2607 { $$ = ($1 << 8) | ($2 & 0xFF); }
2608 | key_delete key_update
2609 { $$ = ($2 << 8) | ($1 & 0xFF); }
2611 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2614 key_update: ON UPDATE key_action { $$ = $3; }
2617 key_delete: ON DELETE_P key_action { $$ = $3; }
2621 NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; }
2622 | RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; }
2623 | CASCADE { $$ = FKCONSTR_ACTION_CASCADE; }
2624 | SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; }
2625 | SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; }
2628 OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
2629 | /*EMPTY*/ { $$ = NIL; }
2632 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
2634 WITH reloptions { $$ = $2; }
2635 | WITH OIDS { $$ = list_make1(defWithOids(true)); }
2636 | WITHOUT OIDS { $$ = list_make1(defWithOids(false)); }
2637 | /*EMPTY*/ { $$ = NIL; }
2640 OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
2641 | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
2642 | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
2643 | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
2646 OptTableSpace: TABLESPACE name { $$ = $2; }
2647 | /*EMPTY*/ { $$ = NULL; }
2650 OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
2651 | /*EMPTY*/ { $$ = NULL; }
2656 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
2661 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
2664 * When the SelectStmt is a set-operation tree, we must
2665 * stuff the INTO information into the leftmost component
2666 * Select, because that's where analyze.c will expect
2667 * to find it. Similarly, the output column names must
2668 * be attached to that Select's target list.
2670 SelectStmt *n = findLeftmostSelect((SelectStmt *) $6);
2671 if (n->intoClause != NULL)
2673 (errcode(ERRCODE_SYNTAX_ERROR),
2674 errmsg("CREATE TABLE AS cannot specify INTO"),
2675 parser_errposition(exprLocation((Node *) n->intoClause))));
2676 $4->rel->istemp = $2;
2678 /* Implement WITH NO DATA by forcing top-level LIMIT 0 */
2680 ((SelectStmt *) $6)->limitCount = makeIntConst(0, -1);
2686 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
2688 $$ = makeNode(IntoClause);
2693 $$->tableSpaceName = $5;
2698 '(' CreateAsList ')' { $$ = $2; }
2699 | /*EMPTY*/ { $$ = NIL; }
2703 CreateAsElement { $$ = list_make1($1); }
2704 | CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); }
2710 ColumnDef *n = makeNode(ColumnDef);
2715 n->is_not_null = false;
2716 n->raw_default = NULL;
2717 n->cooked_default = NULL;
2718 n->constraints = NIL;
2724 WITH DATA_P { $$ = TRUE; }
2725 | WITH NO DATA_P { $$ = FALSE; }
2726 | /*EMPTY*/ { $$ = TRUE; }
2730 /*****************************************************************************
2733 * CREATE SEQUENCE seqname
2734 * ALTER SEQUENCE seqname
2736 *****************************************************************************/
2739 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
2741 CreateSeqStmt *n = makeNode(CreateSeqStmt);
2750 ALTER SEQUENCE qualified_name SeqOptList
2752 AlterSeqStmt *n = makeNode(AlterSeqStmt);
2759 OptSeqOptList: SeqOptList { $$ = $1; }
2760 | /*EMPTY*/ { $$ = NIL; }
2763 SeqOptList: SeqOptElem { $$ = list_make1($1); }
2764 | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
2767 SeqOptElem: CACHE NumericOnly
2769 $$ = makeDefElem("cache", (Node *)$2);
2773 $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE));
2777 $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE));
2779 | INCREMENT opt_by NumericOnly
2781 $$ = makeDefElem("increment", (Node *)$3);
2783 | MAXVALUE NumericOnly
2785 $$ = makeDefElem("maxvalue", (Node *)$2);
2787 | MINVALUE NumericOnly
2789 $$ = makeDefElem("minvalue", (Node *)$2);
2793 $$ = makeDefElem("maxvalue", NULL);
2797 $$ = makeDefElem("minvalue", NULL);
2801 $$ = makeDefElem("owned_by", (Node *)$3);
2803 | START opt_with NumericOnly
2805 $$ = makeDefElem("start", (Node *)$3);
2809 $$ = makeDefElem("restart", NULL);
2811 | RESTART opt_with NumericOnly
2813 $$ = makeDefElem("restart", (Node *)$3);
2822 FCONST { $$ = makeFloat($1); }
2828 | SignedIconst { $$ = makeInteger($1); }
2831 /*****************************************************************************
2834 * CREATE PROCEDURAL LANGUAGE ...
2835 * DROP PROCEDURAL LANGUAGE ...
2837 *****************************************************************************/
2840 CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2842 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2844 /* parameters are all to be supplied by system */
2847 n->plvalidator = NIL;
2848 n->pltrusted = false;
2851 | CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2852 HANDLER handler_name opt_inline_handler opt_validator
2854 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2858 n->plvalidator = $9;
2865 TRUSTED { $$ = TRUE; }
2866 | /*EMPTY*/ { $$ = FALSE; }
2869 /* This ought to be just func_name, but that causes reduce/reduce conflicts
2870 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
2871 * Work around by using simple names, instead.
2874 name { $$ = list_make1(makeString($1)); }
2875 | name attrs { $$ = lcons(makeString($1), $2); }
2879 INLINE_P handler_name { $$ = $2; }
2880 | /*EMPTY*/ { $$ = NIL; }
2884 VALIDATOR handler_name { $$ = $2; }
2885 | NO VALIDATOR { $$ = NIL; }
2889 validator_clause { $$ = $1; }
2890 | /*EMPTY*/ { $$ = NIL; }
2894 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
2896 DropPLangStmt *n = makeNode(DropPLangStmt);
2899 n->missing_ok = false;
2902 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
2904 DropPLangStmt *n = makeNode(DropPLangStmt);
2907 n->missing_ok = true;
2917 /*****************************************************************************
2920 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
2922 *****************************************************************************/
2924 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
2926 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
2927 n->tablespacename = $3;
2934 OptTableSpaceOwner: OWNER name { $$ = $2; }
2935 | /*EMPTY */ { $$ = NULL; }
2938 /*****************************************************************************
2941 * DROP TABLESPACE <tablespace>
2943 * No need for drop behaviour as we cannot implement dependencies for
2944 * objects in other databases; we can only support RESTRICT.
2946 ****************************************************************************/
2948 DropTableSpaceStmt: DROP TABLESPACE name
2950 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2951 n->tablespacename = $3;
2952 n->missing_ok = false;
2955 | DROP TABLESPACE IF_P EXISTS name
2957 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2958 n->tablespacename = $5;
2959 n->missing_ok = true;
2964 /*****************************************************************************
2967 * CREATE FOREIGN DATA WRAPPER name [ VALIDATOR name ]
2969 *****************************************************************************/
2971 CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_validator create_generic_options
2973 CreateFdwStmt *n = makeNode(CreateFdwStmt);
2981 /*****************************************************************************
2984 * DROP FOREIGN DATA WRAPPER name
2986 ****************************************************************************/
2988 DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
2990 DropFdwStmt *n = makeNode(DropFdwStmt);
2992 n->missing_ok = false;
2996 | DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior
2998 DropFdwStmt *n = makeNode(DropFdwStmt);
3000 n->missing_ok = true;
3006 /*****************************************************************************
3009 * ALTER FOREIGN DATA WRAPPER name
3011 ****************************************************************************/
3013 AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name validator_clause alter_generic_options
3015 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3018 n->change_validator = true;
3022 | ALTER FOREIGN DATA_P WRAPPER name validator_clause
3024 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3027 n->change_validator = true;
3030 | ALTER FOREIGN DATA_P WRAPPER name alter_generic_options
3032 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3039 /* Options definition for CREATE FDW, SERVER and USER MAPPING */
3040 create_generic_options:
3041 OPTIONS '(' generic_option_list ')' { $$ = $3; }
3042 | /*EMPTY*/ { $$ = NIL; }
3045 generic_option_list:
3048 $$ = list_make1($1);
3050 | generic_option_list ',' generic_option_elem
3052 $$ = lappend($1, $3);
3056 /* Options definition for ALTER FDW, SERVER and USER MAPPING */
3057 alter_generic_options:
3058 OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
3061 alter_generic_option_list:
3062 alter_generic_option_elem
3064 $$ = list_make1($1);
3066 | alter_generic_option_list ',' alter_generic_option_elem
3068 $$ = lappend($1, $3);
3072 alter_generic_option_elem:
3077 | SET generic_option_elem
3080 $$->defaction = DEFELEM_SET;
3082 | ADD_P generic_option_elem
3085 $$->defaction = DEFELEM_ADD;
3087 | DROP generic_option_name
3089 $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP);
3093 generic_option_elem:
3094 generic_option_name generic_option_arg
3096 $$ = makeDefElem($1, $2);
3100 generic_option_name:
3101 ColLabel { $$ = $1; }
3104 /* We could use def_arg here, but the spec only requires string literals */
3106 Sconst { $$ = (Node *) makeString($1); }
3109 /*****************************************************************************
3112 * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
3114 *****************************************************************************/
3116 CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
3117 FOREIGN DATA_P WRAPPER name create_generic_options
3119 CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
3130 TYPE_P Sconst { $$ = $2; }
3131 | /*EMPTY*/ { $$ = NULL; }
3135 foreign_server_version:
3136 VERSION_P Sconst { $$ = $2; }
3137 | VERSION_P NULL_P { $$ = NULL; }
3140 opt_foreign_server_version:
3141 foreign_server_version { $$ = $1; }
3142 | /*EMPTY*/ { $$ = NULL; }
3145 /*****************************************************************************
3150 ****************************************************************************/
3152 DropForeignServerStmt: DROP SERVER name opt_drop_behavior
3154 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3156 n->missing_ok = false;
3160 | DROP SERVER IF_P EXISTS name opt_drop_behavior
3162 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3164 n->missing_ok = true;
3170 /*****************************************************************************
3173 * ALTER SERVER name [VERSION] [OPTIONS]
3175 ****************************************************************************/
3177 AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
3179 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3183 n->has_version = true;
3186 | ALTER SERVER name foreign_server_version
3188 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3191 n->has_version = true;
3194 | ALTER SERVER name alter_generic_options
3196 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3203 /*****************************************************************************
3206 * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
3208 *****************************************************************************/
3210 CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
3212 CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
3220 /* User mapping authorization identifier */
3222 CURRENT_USER { $$ = "current_user"; }
3223 | USER { $$ = "current_user"; }
3224 | RoleId { $$ = (strcmp($1, "public") == 0) ? NULL : $1; }
3227 /*****************************************************************************
3230 * DROP USER MAPPING FOR auth_ident SERVER name
3232 ****************************************************************************/
3234 DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
3236 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3239 n->missing_ok = false;
3242 | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
3244 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3247 n->missing_ok = true;
3252 /*****************************************************************************
3255 * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
3257 ****************************************************************************/
3259 AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
3261 AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
3269 /*****************************************************************************
3272 * CREATE TRIGGER ...
3275 *****************************************************************************/
3278 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
3279 qualified_name TriggerForSpec TriggerWhen
3280 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3282 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3289 n->events = intVal(linitial($5));
3290 n->columns = (List *) lsecond($5);
3292 n->isconstraint = FALSE;
3293 n->deferrable = FALSE;
3294 n->initdeferred = FALSE;
3295 n->constrrel = NULL;
3298 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
3299 qualified_name OptConstrFromTable ConstraintAttributeSpec
3300 FOR EACH ROW TriggerWhen
3301 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3303 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3310 n->events = intVal(linitial($6));
3311 n->columns = (List *) lsecond($6);
3312 n->whenClause = $14;
3313 n->isconstraint = TRUE;
3314 n->deferrable = ($10 & 1) != 0;
3315 n->initdeferred = ($10 & 2) != 0;
3322 BEFORE { $$ = TRUE; }
3323 | AFTER { $$ = FALSE; }
3329 | TriggerEvents OR TriggerOneEvent
3331 int events1 = intVal(linitial($1));
3332 int events2 = intVal(linitial($3));
3333 List *columns1 = (List *) lsecond($1);
3334 List *columns2 = (List *) lsecond($3);
3336 if (events1 & events2)
3337 parser_yyerror("duplicate trigger events specified");
3339 * concat'ing the columns lists loses information about
3340 * which columns went with which event, but so long as
3341 * only UPDATE carries columns and we disallow multiple
3342 * UPDATE items, it doesn't matter. Command execution
3343 * should just ignore the columns for non-UPDATE events.
3345 $$ = list_make2(makeInteger(events1 | events2),
3346 list_concat(columns1, columns2));
3352 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
3354 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
3356 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
3357 | UPDATE OF columnList
3358 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
3360 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
3364 FOR TriggerForOpt TriggerForType
3371 * If ROW/STATEMENT not specified, default to
3372 * STATEMENT, per SQL
3385 | STATEMENT { $$ = FALSE; }
3389 WHEN '(' a_expr ')' { $$ = $3; }
3390 | /*EMPTY*/ { $$ = NULL; }
3394 TriggerFuncArg { $$ = list_make1($1); }
3395 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
3396 | /*EMPTY*/ { $$ = NIL; }
3403 snprintf(buf, sizeof(buf), "%d", $1);
3404 $$ = makeString(pstrdup(buf));
3406 | FCONST { $$ = makeString($1); }
3407 | Sconst { $$ = makeString($1); }
3408 | BCONST { $$ = makeString($1); }
3409 | XCONST { $$ = makeString($1); }
3410 | ColId { $$ = makeString($1); }
3414 FROM qualified_name { $$ = $2; }
3415 | /*EMPTY*/ { $$ = NULL; }
3418 ConstraintAttributeSpec:
3419 ConstraintDeferrabilitySpec
3421 | ConstraintDeferrabilitySpec ConstraintTimeSpec
3423 if ($1 == 0 && $2 != 0)
3425 (errcode(ERRCODE_SYNTAX_ERROR),
3426 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3427 parser_errposition(@1)));
3430 | ConstraintTimeSpec
3437 | ConstraintTimeSpec ConstraintDeferrabilitySpec
3439 if ($2 == 0 && $1 != 0)
3441 (errcode(ERRCODE_SYNTAX_ERROR),
3442 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3443 parser_errposition(@1)));
3450 ConstraintDeferrabilitySpec:
3451 NOT DEFERRABLE { $$ = 0; }
3452 | DEFERRABLE { $$ = 1; }
3456 INITIALLY IMMEDIATE { $$ = 0; }
3457 | INITIALLY DEFERRED { $$ = 2; }
3462 DROP TRIGGER name ON qualified_name opt_drop_behavior
3464 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3468 n->removeType = OBJECT_TRIGGER;
3469 n->missing_ok = false;
3472 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
3474 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3478 n->removeType = OBJECT_TRIGGER;
3479 n->missing_ok = true;
3485 /*****************************************************************************
3488 * CREATE ASSERTION ...
3489 * DROP ASSERTION ...
3491 *****************************************************************************/
3494 CREATE ASSERTION name CHECK '(' a_expr ')'
3495 ConstraintAttributeSpec
3497 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3499 n->args = list_make1($6);
3500 n->isconstraint = TRUE;
3501 n->deferrable = ($8 & 1) != 0;
3502 n->initdeferred = ($8 & 2) != 0;
3505 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3506 errmsg("CREATE ASSERTION is not yet implemented")));
3513 DROP ASSERTION name opt_drop_behavior
3515 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3519 n->removeType = OBJECT_TRIGGER; /* XXX */
3521 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3522 errmsg("DROP ASSERTION is not yet implemented")));
3528 /*****************************************************************************
3531 * define (aggregate,operator,type)
3533 *****************************************************************************/
3536 CREATE AGGREGATE func_name aggr_args definition
3538 DefineStmt *n = makeNode(DefineStmt);
3539 n->kind = OBJECT_AGGREGATE;
3540 n->oldstyle = false;
3546 | CREATE AGGREGATE func_name old_aggr_definition
3548 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
3549 DefineStmt *n = makeNode(DefineStmt);
3550 n->kind = OBJECT_AGGREGATE;
3557 | CREATE OPERATOR any_operator definition
3559 DefineStmt *n = makeNode(DefineStmt);
3560 n->kind = OBJECT_OPERATOR;
3561 n->oldstyle = false;
3567 | CREATE TYPE_P any_name definition
3569 DefineStmt *n = makeNode(DefineStmt);
3570 n->kind = OBJECT_TYPE;
3571 n->oldstyle = false;
3577 | CREATE TYPE_P any_name
3579 /* Shell type (identified by lack of definition) */
3580 DefineStmt *n = makeNode(DefineStmt);
3581 n->kind = OBJECT_TYPE;
3582 n->oldstyle = false;
3585 n->definition = NIL;
3588 | CREATE TYPE_P any_name AS '(' TableFuncElementList ')'
3590 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
3591 RangeVar *r = makeNode(RangeVar);
3593 /* can't use qualified_name, sigh */
3594 switch (list_length($3))
3597 r->catalogname = NULL;
3598 r->schemaname = NULL;
3599 r->relname = strVal(linitial($3));
3602 r->catalogname = NULL;
3603 r->schemaname = strVal(linitial($3));
3604 r->relname = strVal(lsecond($3));
3607 r->catalogname = strVal(linitial($3));
3608 r->schemaname = strVal(lsecond($3));
3609 r->relname = strVal(lthird($3));
3613 (errcode(ERRCODE_SYNTAX_ERROR),
3614 errmsg("improper qualified name (too many dotted names): %s",
3615 NameListToString($3)),
3616 parser_errposition(@3)));
3624 | CREATE TYPE_P any_name AS ENUM_P '(' enum_val_list ')'
3626 CreateEnumStmt *n = makeNode(CreateEnumStmt);
3631 | CREATE TEXT_P SEARCH PARSER any_name definition
3633 DefineStmt *n = makeNode(DefineStmt);
3634 n->kind = OBJECT_TSPARSER;
3640 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
3642 DefineStmt *n = makeNode(DefineStmt);
3643 n->kind = OBJECT_TSDICTIONARY;
3649 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
3651 DefineStmt *n = makeNode(DefineStmt);
3652 n->kind = OBJECT_TSTEMPLATE;
3658 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
3660 DefineStmt *n = makeNode(DefineStmt);
3661 n->kind = OBJECT_TSCONFIGURATION;
3669 definition: '(' def_list ')' { $$ = $2; }
3672 def_list: def_elem { $$ = list_make1($1); }
3673 | def_list ',' def_elem { $$ = lappend($1, $3); }
3676 def_elem: ColLabel '=' def_arg
3678 $$ = makeDefElem($1, (Node *) $3);
3682 $$ = makeDefElem($1, NULL);
3686 /* Note: any simple identifier will be returned as a type name! */
3687 def_arg: func_type { $$ = (Node *)$1; }
3688 | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
3689 | qual_all_Op { $$ = (Node *)$1; }
3690 | NumericOnly { $$ = (Node *)$1; }
3691 | Sconst { $$ = (Node *)makeString($1); }
3694 aggr_args: '(' type_list ')' { $$ = $2; }
3695 | '(' '*' ')' { $$ = NIL; }
3698 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
3701 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
3702 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
3706 * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
3707 * the item names needed in old aggregate definitions are likely to become
3710 old_aggr_elem: IDENT '=' def_arg
3712 $$ = makeDefElem($1, (Node *)$3);
3716 enum_val_list: Sconst
3717 { $$ = list_make1(makeString($1)); }
3718 | enum_val_list ',' Sconst
3719 { $$ = lappend($1, makeString($3)); }
3723 /*****************************************************************************
3726 * CREATE OPERATOR CLASS ...
3727 * CREATE OPERATOR FAMILY ...
3728 * ALTER OPERATOR FAMILY ...
3729 * DROP OPERATOR CLASS ...
3730 * DROP OPERATOR FAMILY ...
3732 *****************************************************************************/
3735 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
3736 USING access_method opt_opfamily AS opclass_item_list
3738 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
3739 n->opclassname = $4;
3743 n->opfamilyname = $11;
3750 opclass_item { $$ = list_make1($1); }
3751 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
3755 OPERATOR Iconst any_operator opt_recheck
3757 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3758 n->itemtype = OPCLASS_ITEM_OPERATOR;
3764 | OPERATOR Iconst any_operator oper_argtypes opt_recheck
3766 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3767 n->itemtype = OPCLASS_ITEM_OPERATOR;
3773 | FUNCTION Iconst func_name func_args
3775 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3776 n->itemtype = OPCLASS_ITEM_FUNCTION;
3778 n->args = extractArgTypes($4);
3782 | FUNCTION Iconst '(' type_list ')' func_name func_args
3784 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3785 n->itemtype = OPCLASS_ITEM_FUNCTION;
3787 n->args = extractArgTypes($7);
3794 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3795 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
3801 opt_default: DEFAULT { $$ = TRUE; }
3802 | /*EMPTY*/ { $$ = FALSE; }
3805 opt_opfamily: FAMILY any_name { $$ = $2; }
3806 | /*EMPTY*/ { $$ = NIL; }
3809 opt_recheck: RECHECK
3812 * RECHECK no longer does anything in opclass definitions,
3813 * but we still accept it to ease porting of old database
3817 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3818 errmsg("RECHECK is no longer required"),
3819 errhint("Update your data type."),
3820 parser_errposition(@1)));
3823 | /*EMPTY*/ { $$ = FALSE; }
3828 CREATE OPERATOR FAMILY any_name USING access_method
3830 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
3831 n->opfamilyname = $4;
3838 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
3840 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3841 n->opfamilyname = $4;
3847 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
3849 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3850 n->opfamilyname = $4;
3859 opclass_drop { $$ = list_make1($1); }
3860 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
3864 OPERATOR Iconst '(' type_list ')'
3866 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3867 n->itemtype = OPCLASS_ITEM_OPERATOR;
3872 | FUNCTION Iconst '(' type_list ')'
3874 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3875 n->itemtype = OPCLASS_ITEM_FUNCTION;
3884 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
3886 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3887 n->opclassname = $4;
3890 n->missing_ok = false;
3893 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
3895 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3896 n->opclassname = $6;
3899 n->missing_ok = true;
3905 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
3907 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3908 n->opfamilyname = $4;
3911 n->missing_ok = false;
3914 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
3916 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3917 n->opfamilyname = $6;
3920 n->missing_ok = true;
3926 /*****************************************************************************
3930 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
3931 * REASSIGN OWNED BY username [, username ...] TO username
3933 *****************************************************************************/
3935 DROP OWNED BY name_list opt_drop_behavior
3937 DropOwnedStmt *n = makeNode(DropOwnedStmt);
3945 REASSIGN OWNED BY name_list TO name
3947 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
3954 /*****************************************************************************
3958 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
3959 * [ RESTRICT | CASCADE ]
3961 *****************************************************************************/
3963 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
3965 DropStmt *n = makeNode(DropStmt);
3967 n->missing_ok = TRUE;
3972 | DROP drop_type any_name_list opt_drop_behavior
3974 DropStmt *n = makeNode(DropStmt);
3976 n->missing_ok = FALSE;
3984 drop_type: TABLE { $$ = OBJECT_TABLE; }
3985 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
3986 | VIEW { $$ = OBJECT_VIEW; }
3987 | INDEX { $$ = OBJECT_INDEX; }
3988 | TYPE_P { $$ = OBJECT_TYPE; }
3989 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
3990 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
3991 | SCHEMA { $$ = OBJECT_SCHEMA; }
3992 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
3993 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
3994 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
3995 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
3999 any_name { $$ = list_make1($1); }
4000 | any_name_list ',' any_name { $$ = lappend($1, $3); }
4003 any_name: ColId { $$ = list_make1(makeString($1)); }
4004 | ColId attrs { $$ = lcons(makeString($1), $2); }
4007 attrs: '.' attr_name
4008 { $$ = list_make1(makeString($2)); }
4009 | attrs '.' attr_name
4010 { $$ = lappend($1, makeString($3)); }
4014 /*****************************************************************************
4017 * truncate table relname1, relname2, ...
4019 *****************************************************************************/
4022 TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
4024 TruncateStmt *n = makeNode(TruncateStmt);
4026 n->restart_seqs = $4;
4033 CONTINUE_P IDENTITY_P { $$ = false; }
4034 | RESTART IDENTITY_P { $$ = true; }
4035 | /* EMPTY */ { $$ = false; }
4038 /*****************************************************************************
4040 * The COMMENT ON statement can take different forms based upon the type of
4041 * the object associated with the comment. The form of the statement is:
4043 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
4044 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
4045 * CAST | COLUMN | SCHEMA | TABLESPACE | ROLE |
4046 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
4047 * TEXT SEARCH TEMPLATE |
4048 * TEXT SEARCH CONFIGURATION ] <objname> |
4049 * AGGREGATE <aggname> (arg1, ...) |
4050 * FUNCTION <funcname> (arg1, arg2, ...) |
4051 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
4052 * TRIGGER <triggername> ON <relname> |
4053 * CONSTRAINT <constraintname> ON <relname> |
4054 * RULE <rulename> ON <relname> ]
4057 *****************************************************************************/
4060 COMMENT ON comment_type any_name IS comment_text
4062 CommentStmt *n = makeNode(CommentStmt);
4069 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
4071 CommentStmt *n = makeNode(CommentStmt);
4072 n->objtype = OBJECT_AGGREGATE;
4078 | COMMENT ON FUNCTION func_name func_args IS comment_text
4080 CommentStmt *n = makeNode(CommentStmt);
4081 n->objtype = OBJECT_FUNCTION;
4083 n->objargs = extractArgTypes($5);
4087 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
4089 CommentStmt *n = makeNode(CommentStmt);
4090 n->objtype = OBJECT_OPERATOR;
4096 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
4098 CommentStmt *n = makeNode(CommentStmt);
4099 n->objtype = OBJECT_CONSTRAINT;
4100 n->objname = lappend($6, makeString($4));
4105 | COMMENT ON RULE name ON any_name IS comment_text
4107 CommentStmt *n = makeNode(CommentStmt);
4108 n->objtype = OBJECT_RULE;
4109 n->objname = lappend($6, makeString($4));
4114 | COMMENT ON RULE name IS comment_text
4116 /* Obsolete syntax supported for awhile for compatibility */
4117 CommentStmt *n = makeNode(CommentStmt);
4118 n->objtype = OBJECT_RULE;
4119 n->objname = list_make1(makeString($4));
4124 | COMMENT ON TRIGGER name ON any_name IS comment_text
4126 CommentStmt *n = makeNode(CommentStmt);
4127 n->objtype = OBJECT_TRIGGER;
4128 n->objname = lappend($6, makeString($4));
4133 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
4135 CommentStmt *n = makeNode(CommentStmt);
4136 n->objtype = OBJECT_OPCLASS;
4138 n->objargs = list_make1(makeString($7));
4142 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
4144 CommentStmt *n = makeNode(CommentStmt);
4145 n->objtype = OBJECT_OPFAMILY;
4147 n->objargs = list_make1(makeString($7));
4151 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
4153 CommentStmt *n = makeNode(CommentStmt);
4154 n->objtype = OBJECT_LARGEOBJECT;
4155 n->objname = list_make1($5);
4160 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
4162 CommentStmt *n = makeNode(CommentStmt);
4163 n->objtype = OBJECT_CAST;
4164 n->objname = list_make1($5);
4165 n->objargs = list_make1($7);
4169 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
4171 CommentStmt *n = makeNode(CommentStmt);
4172 n->objtype = OBJECT_LANGUAGE;
4178 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
4180 CommentStmt *n = makeNode(CommentStmt);
4181 n->objtype = OBJECT_TSPARSER;
4186 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
4188 CommentStmt *n = makeNode(CommentStmt);
4189 n->objtype = OBJECT_TSDICTIONARY;
4194 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
4196 CommentStmt *n = makeNode(CommentStmt);
4197 n->objtype = OBJECT_TSTEMPLATE;
4202 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
4204 CommentStmt *n = makeNode(CommentStmt);
4205 n->objtype = OBJECT_TSCONFIGURATION;
4213 COLUMN { $$ = OBJECT_COLUMN; }
4214 | DATABASE { $$ = OBJECT_DATABASE; }
4215 | SCHEMA { $$ = OBJECT_SCHEMA; }
4216 | INDEX { $$ = OBJECT_INDEX; }
4217 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4218 | TABLE { $$ = OBJECT_TABLE; }
4219 | DOMAIN_P { $$ = OBJECT_TYPE; }
4220 | TYPE_P { $$ = OBJECT_TYPE; }
4221 | VIEW { $$ = OBJECT_VIEW; }
4222 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4223 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
4224 | ROLE { $$ = OBJECT_ROLE; }
4229 | NULL_P { $$ = NULL; }
4232 /*****************************************************************************
4237 *****************************************************************************/
4239 FetchStmt: FETCH fetch_args
4241 FetchStmt *n = (FetchStmt *) $2;
4247 FetchStmt *n = (FetchStmt *) $2;
4253 fetch_args: cursor_name
4255 FetchStmt *n = makeNode(FetchStmt);
4257 n->direction = FETCH_FORWARD;
4261 | from_in cursor_name
4263 FetchStmt *n = makeNode(FetchStmt);
4265 n->direction = FETCH_FORWARD;
4269 | NEXT opt_from_in cursor_name
4271 FetchStmt *n = makeNode(FetchStmt);
4273 n->direction = FETCH_FORWARD;
4277 | PRIOR opt_from_in cursor_name
4279 FetchStmt *n = makeNode(FetchStmt);
4281 n->direction = FETCH_BACKWARD;
4285 | FIRST_P opt_from_in cursor_name
4287 FetchStmt *n = makeNode(FetchStmt);
4289 n->direction = FETCH_ABSOLUTE;
4293 | LAST_P opt_from_in cursor_name
4295 FetchStmt *n = makeNode(FetchStmt);
4297 n->direction = FETCH_ABSOLUTE;
4301 | ABSOLUTE_P SignedIconst opt_from_in cursor_name
4303 FetchStmt *n = makeNode(FetchStmt);
4305 n->direction = FETCH_ABSOLUTE;
4309 | RELATIVE_P SignedIconst opt_from_in cursor_name
4311 FetchStmt *n = makeNode(FetchStmt);
4313 n->direction = FETCH_RELATIVE;
4317 | SignedIconst opt_from_in cursor_name
4319 FetchStmt *n = makeNode(FetchStmt);
4321 n->direction = FETCH_FORWARD;
4325 | ALL opt_from_in cursor_name
4327 FetchStmt *n = makeNode(FetchStmt);
4329 n->direction = FETCH_FORWARD;
4330 n->howMany = FETCH_ALL;
4333 | FORWARD opt_from_in cursor_name
4335 FetchStmt *n = makeNode(FetchStmt);
4337 n->direction = FETCH_FORWARD;
4341 | FORWARD SignedIconst opt_from_in cursor_name
4343 FetchStmt *n = makeNode(FetchStmt);
4345 n->direction = FETCH_FORWARD;
4349 | FORWARD ALL opt_from_in cursor_name
4351 FetchStmt *n = makeNode(FetchStmt);
4353 n->direction = FETCH_FORWARD;
4354 n->howMany = FETCH_ALL;
4357 | BACKWARD opt_from_in cursor_name
4359 FetchStmt *n = makeNode(FetchStmt);
4361 n->direction = FETCH_BACKWARD;
4365 | BACKWARD SignedIconst opt_from_in cursor_name
4367 FetchStmt *n = makeNode(FetchStmt);
4369 n->direction = FETCH_BACKWARD;
4373 | BACKWARD ALL opt_from_in cursor_name
4375 FetchStmt *n = makeNode(FetchStmt);
4377 n->direction = FETCH_BACKWARD;
4378 n->howMany = FETCH_ALL;
4387 opt_from_in: from_in {}
4392 /*****************************************************************************
4394 * GRANT and REVOKE statements
4396 *****************************************************************************/
4398 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
4399 opt_grant_grant_option
4401 GrantStmt *n = makeNode(GrantStmt);
4404 n->targtype = ($4)->targtype;
4405 n->objtype = ($4)->objtype;
4406 n->objects = ($4)->objs;
4408 n->grant_option = $7;
4414 REVOKE privileges ON privilege_target
4415 FROM grantee_list opt_drop_behavior
4417 GrantStmt *n = makeNode(GrantStmt);
4418 n->is_grant = false;
4419 n->grant_option = false;
4421 n->targtype = ($4)->targtype;
4422 n->objtype = ($4)->objtype;
4423 n->objects = ($4)->objs;
4428 | REVOKE GRANT OPTION FOR privileges ON privilege_target
4429 FROM grantee_list opt_drop_behavior
4431 GrantStmt *n = makeNode(GrantStmt);
4432 n->is_grant = false;
4433 n->grant_option = true;
4435 n->targtype = ($7)->targtype;
4436 n->objtype = ($7)->objtype;
4437 n->objects = ($7)->objs;
4446 * Privilege names are represented as strings; the validity of the privilege
4447 * names gets checked at execution. This is a bit annoying but we have little
4448 * choice because of the syntactic conflict with lists of role names in
4449 * GRANT/REVOKE. What's more, we have to call out in the "privilege"
4450 * production any reserved keywords that need to be usable as privilege names.
4453 /* either ALL [PRIVILEGES] or a list of individual privileges */
4454 privileges: privilege_list
4460 | ALL '(' columnList ')'
4462 AccessPriv *n = makeNode(AccessPriv);
4463 n->priv_name = NULL;
4467 | ALL PRIVILEGES '(' columnList ')'
4469 AccessPriv *n = makeNode(AccessPriv);
4470 n->priv_name = NULL;
4476 privilege_list: privilege { $$ = list_make1($1); }
4477 | privilege_list ',' privilege { $$ = lappend($1, $3); }
4480 privilege: SELECT opt_column_list
4482 AccessPriv *n = makeNode(AccessPriv);
4483 n->priv_name = pstrdup($1);
4487 | REFERENCES opt_column_list
4489 AccessPriv *n = makeNode(AccessPriv);
4490 n->priv_name = pstrdup($1);
4494 | CREATE opt_column_list
4496 AccessPriv *n = makeNode(AccessPriv);
4497 n->priv_name = pstrdup($1);
4501 | ColId opt_column_list
4503 AccessPriv *n = makeNode(AccessPriv);
4511 /* Don't bother trying to fold the first two rules into one using
4512 * opt_table. You're going to get conflicts.
4517 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4518 n->targtype = ACL_TARGET_OBJECT;
4519 n->objtype = ACL_OBJECT_RELATION;
4523 | TABLE qualified_name_list
4525 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4526 n->targtype = ACL_TARGET_OBJECT;
4527 n->objtype = ACL_OBJECT_RELATION;
4531 | SEQUENCE qualified_name_list
4533 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4534 n->targtype = ACL_TARGET_OBJECT;
4535 n->objtype = ACL_OBJECT_SEQUENCE;
4539 | FOREIGN DATA_P WRAPPER name_list
4541 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4542 n->targtype = ACL_TARGET_OBJECT;
4543 n->objtype = ACL_OBJECT_FDW;
4547 | FOREIGN SERVER name_list
4549 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4550 n->targtype = ACL_TARGET_OBJECT;
4551 n->objtype = ACL_OBJECT_FOREIGN_SERVER;
4555 | FUNCTION function_with_argtypes_list
4557 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4558 n->targtype = ACL_TARGET_OBJECT;
4559 n->objtype = ACL_OBJECT_FUNCTION;
4563 | DATABASE name_list
4565 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4566 n->targtype = ACL_TARGET_OBJECT;
4567 n->objtype = ACL_OBJECT_DATABASE;
4571 | LANGUAGE name_list
4573 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4574 n->targtype = ACL_TARGET_OBJECT;
4575 n->objtype = ACL_OBJECT_LANGUAGE;
4581 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4582 n->targtype = ACL_TARGET_OBJECT;
4583 n->objtype = ACL_OBJECT_NAMESPACE;
4587 | TABLESPACE name_list
4589 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4590 n->targtype = ACL_TARGET_OBJECT;
4591 n->objtype = ACL_OBJECT_TABLESPACE;
4595 | ALL TABLES IN_P SCHEMA name_list
4597 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4598 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4599 n->objtype = ACL_OBJECT_RELATION;
4603 | ALL SEQUENCES IN_P SCHEMA name_list
4605 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4606 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4607 n->objtype = ACL_OBJECT_SEQUENCE;
4611 | ALL FUNCTIONS IN_P SCHEMA name_list
4613 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4614 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4615 n->objtype = ACL_OBJECT_FUNCTION;
4623 grantee { $$ = list_make1($1); }
4624 | grantee_list ',' grantee { $$ = lappend($1, $3); }
4629 PrivGrantee *n = makeNode(PrivGrantee);
4630 /* This hack lets us avoid reserving PUBLIC as a keyword*/
4631 if (strcmp($1, "public") == 0)
4639 PrivGrantee *n = makeNode(PrivGrantee);
4640 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
4641 if (strcmp($2, "public") == 0)
4650 opt_grant_grant_option:
4651 WITH GRANT OPTION { $$ = TRUE; }
4652 | /*EMPTY*/ { $$ = FALSE; }
4655 function_with_argtypes_list:
4656 function_with_argtypes { $$ = list_make1($1); }
4657 | function_with_argtypes_list ',' function_with_argtypes
4658 { $$ = lappend($1, $3); }
4661 function_with_argtypes:
4664 FuncWithArgs *n = makeNode(FuncWithArgs);
4666 n->funcargs = extractArgTypes($2);
4671 /*****************************************************************************
4673 * GRANT and REVOKE ROLE statements
4675 *****************************************************************************/
4678 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4680 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4682 n->granted_roles = $2;
4683 n->grantee_roles = $4;
4691 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4693 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4694 n->is_grant = false;
4695 n->admin_opt = false;
4696 n->granted_roles = $2;
4697 n->grantee_roles = $4;
4701 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4703 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4704 n->is_grant = false;
4705 n->admin_opt = true;
4706 n->granted_roles = $5;
4707 n->grantee_roles = $7;
4713 opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
4714 | /*EMPTY*/ { $$ = FALSE; }
4717 opt_granted_by: GRANTED BY RoleId { $$ = $3; }
4718 | /*EMPTY*/ { $$ = NULL; }
4721 /*****************************************************************************
4723 * ALTER DEFAULT PRIVILEGES statement
4725 *****************************************************************************/
4727 AlterDefaultPrivilegesStmt:
4728 ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
4730 AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
4732 n->action = (GrantStmt *) $5;
4738 DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
4739 | /* EMPTY */ { $$ = NIL; }
4743 IN_P SCHEMA name_list
4745 $$ = makeDefElem("schemas", (Node *)$3);
4747 | FOR ROLE name_list
4749 $$ = makeDefElem("roles", (Node *)$3);
4751 | FOR USER name_list
4753 $$ = makeDefElem("roles", (Node *)$3);
4758 * This should match GRANT/REVOKE, except that individual target objects
4759 * are not mentioned and we only allow a subset of object types.
4762 GRANT privileges ON defacl_privilege_target TO grantee_list
4763 opt_grant_grant_option
4765 GrantStmt *n = makeNode(GrantStmt);
4768 n->targtype = ACL_TARGET_DEFAULTS;
4772 n->grant_option = $7;
4775 | REVOKE privileges ON defacl_privilege_target
4776 FROM grantee_list opt_drop_behavior
4778 GrantStmt *n = makeNode(GrantStmt);
4779 n->is_grant = false;
4780 n->grant_option = false;
4782 n->targtype = ACL_TARGET_DEFAULTS;
4789 | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
4790 FROM grantee_list opt_drop_behavior
4792 GrantStmt *n = makeNode(GrantStmt);
4793 n->is_grant = false;
4794 n->grant_option = true;
4796 n->targtype = ACL_TARGET_DEFAULTS;
4805 defacl_privilege_target:
4806 TABLES { $$ = ACL_OBJECT_RELATION; }
4807 | FUNCTIONS { $$ = ACL_OBJECT_FUNCTION; }
4808 | SEQUENCES { $$ = ACL_OBJECT_SEQUENCE; }
4812 /*****************************************************************************
4814 * QUERY: CREATE INDEX
4816 * Note: we can't factor CONCURRENTLY into a separate production without
4817 * making it a reserved word.
4819 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
4820 * willing to make TABLESPACE a fully reserved word.
4821 *****************************************************************************/
4823 IndexStmt: CREATE index_opt_unique INDEX index_name
4824 ON qualified_name access_method_clause '(' index_params ')'
4825 opt_reloptions OptTableSpace where_clause
4827 IndexStmt *n = makeNode(IndexStmt);
4829 n->concurrent = false;
4832 n->accessMethod = $7;
4833 n->indexParams = $9;
4835 n->tableSpace = $12;
4836 n->whereClause = $13;
4839 | CREATE index_opt_unique INDEX CONCURRENTLY index_name
4840 ON qualified_name access_method_clause '(' index_params ')'
4841 opt_reloptions OptTableSpace where_clause
4843 IndexStmt *n = makeNode(IndexStmt);
4845 n->concurrent = true;
4848 n->accessMethod = $8;
4849 n->indexParams = $10;
4851 n->tableSpace = $13;
4852 n->whereClause = $14;
4858 UNIQUE { $$ = TRUE; }
4859 | /*EMPTY*/ { $$ = FALSE; }
4862 access_method_clause:
4863 USING access_method { $$ = $2; }
4864 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
4867 index_params: index_elem { $$ = list_make1($1); }
4868 | index_params ',' index_elem { $$ = lappend($1, $3); }
4872 * Index attributes can be either simple column references, or arbitrary
4873 * expressions in parens. For backwards-compatibility reasons, we allow
4874 * an expression that's just a function call to be written without parens.
4876 index_elem: ColId opt_class opt_asc_desc opt_nulls_order
4878 $$ = makeNode(IndexElem);
4883 $$->nulls_ordering = $4;
4885 | func_expr opt_class opt_asc_desc opt_nulls_order
4887 $$ = makeNode(IndexElem);
4892 $$->nulls_ordering = $4;
4894 | '(' a_expr ')' opt_class opt_asc_desc opt_nulls_order
4896 $$ = makeNode(IndexElem);
4901 $$->nulls_ordering = $6;
4905 opt_class: any_name { $$ = $1; }
4906 | USING any_name { $$ = $2; }
4907 | /*EMPTY*/ { $$ = NIL; }
4910 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
4911 | DESC { $$ = SORTBY_DESC; }
4912 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
4915 opt_nulls_order: NULLS_FIRST { $$ = SORTBY_NULLS_FIRST; }
4916 | NULLS_LAST { $$ = SORTBY_NULLS_LAST; }
4917 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
4921 /*****************************************************************************
4924 * create [or replace] function <fname>
4925 * [(<type-1> { , <type-n>})]
4927 * as <filename or code in language as appropriate>
4928 * language <lang> [with parameters]
4930 *****************************************************************************/
4933 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4934 RETURNS func_return createfunc_opt_list opt_definition
4936 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4945 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4946 RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
4948 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4951 n->parameters = mergeTableFuncParameters($5, $9);
4952 n->returnType = TableFuncTypeName($9);
4953 n->returnType->location = @7;
4955 n->withClause = $12;
4958 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4959 createfunc_opt_list opt_definition
4961 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4965 n->returnType = NULL;
4973 OR REPLACE { $$ = TRUE; }
4974 | /*EMPTY*/ { $$ = FALSE; }
4977 func_args: '(' func_args_list ')' { $$ = $2; }
4978 | '(' ')' { $$ = NIL; }
4982 func_arg { $$ = list_make1($1); }
4983 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
4987 * func_args_with_defaults is separate because we only want to accept
4988 * defaults in CREATE FUNCTION, not in ALTER etc.
4990 func_args_with_defaults:
4991 '(' func_args_with_defaults_list ')' { $$ = $2; }
4992 | '(' ')' { $$ = NIL; }
4995 func_args_with_defaults_list:
4996 func_arg_with_default { $$ = list_make1($1); }
4997 | func_args_with_defaults_list ',' func_arg_with_default
4998 { $$ = lappend($1, $3); }
5002 * The style with arg_class first is SQL99 standard, but Oracle puts
5003 * param_name first; accept both since it's likely people will try both
5004 * anyway. Don't bother trying to save productions by letting arg_class
5005 * have an empty alternative ... you'll get shift/reduce conflicts.
5007 * We can catch over-specified arguments here if we want to,
5008 * but for now better to silently swallow typmod, etc.
5009 * - thomas 2000-03-22
5012 arg_class param_name func_type
5014 FunctionParameter *n = makeNode(FunctionParameter);
5021 | param_name arg_class func_type
5023 FunctionParameter *n = makeNode(FunctionParameter);
5030 | param_name func_type
5032 FunctionParameter *n = makeNode(FunctionParameter);
5035 n->mode = FUNC_PARAM_IN;
5039 | arg_class func_type
5041 FunctionParameter *n = makeNode(FunctionParameter);
5050 FunctionParameter *n = makeNode(FunctionParameter);
5053 n->mode = FUNC_PARAM_IN;
5059 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
5060 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
5061 | OUT_P { $$ = FUNC_PARAM_OUT; }
5062 | INOUT { $$ = FUNC_PARAM_INOUT; }
5063 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
5064 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
5068 * Ideally param_name should be ColId, but that causes too many conflicts.
5070 param_name: type_function_name
5076 /* We can catch over-specified results here if we want to,
5077 * but for now better to silently swallow typmod, etc.
5078 * - thomas 2000-03-22
5085 * We would like to make the %TYPE productions here be ColId attrs etc,
5086 * but that causes reduce/reduce conflicts. type_function_name
5087 * is next best choice.
5089 func_type: Typename { $$ = $1; }
5090 | type_function_name attrs '%' TYPE_P
5092 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
5093 $$->pct_type = true;
5096 | SETOF type_function_name attrs '%' TYPE_P
5098 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
5099 $$->pct_type = true;
5105 func_arg_with_default:
5110 | func_arg DEFAULT a_expr
5115 | func_arg '=' a_expr
5123 createfunc_opt_list:
5124 /* Must be at least one to prevent conflict */
5125 createfunc_opt_item { $$ = list_make1($1); }
5126 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
5130 * Options common to both CREATE FUNCTION and ALTER FUNCTION
5132 common_func_opt_item:
5133 CALLED ON NULL_P INPUT_P
5135 $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
5137 | RETURNS NULL_P ON NULL_P INPUT_P
5139 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5143 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5147 $$ = makeDefElem("volatility", (Node *)makeString("immutable"));
5151 $$ = makeDefElem("volatility", (Node *)makeString("stable"));
5155 $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
5157 | EXTERNAL SECURITY DEFINER
5159 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5161 | EXTERNAL SECURITY INVOKER
5163 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5167 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5171 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5175 $$ = makeDefElem("cost", (Node *)$2);
5179 $$ = makeDefElem("rows", (Node *)$2);
5183 /* we abuse the normal content of a DefElem here */
5184 $$ = makeDefElem("set", (Node *)$1);
5188 createfunc_opt_item:
5191 $$ = makeDefElem("as", (Node *)$2);
5193 | LANGUAGE ColId_or_Sconst
5195 $$ = makeDefElem("language", (Node *)makeString($2));
5199 $$ = makeDefElem("window", (Node *)makeInteger(TRUE));
5201 | common_func_opt_item
5207 func_as: Sconst { $$ = list_make1(makeString($1)); }
5210 $$ = list_make2(makeString($1), makeString($3));
5215 WITH definition { $$ = $2; }
5216 | /*EMPTY*/ { $$ = NIL; }
5219 table_func_column: param_name func_type
5221 FunctionParameter *n = makeNode(FunctionParameter);
5224 n->mode = FUNC_PARAM_TABLE;
5230 table_func_column_list:
5233 $$ = list_make1($1);
5235 | table_func_column_list ',' table_func_column
5237 $$ = lappend($1, $3);
5241 /*****************************************************************************
5244 * RENAME and OWNER subcommands are already provided by the generic
5245 * ALTER infrastructure, here we just specify alterations that can
5246 * only be applied to functions.
5248 *****************************************************************************/
5250 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
5252 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
5260 /* At least one option must be specified */
5261 common_func_opt_item { $$ = list_make1($1); }
5262 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
5265 /* Ignored, merely for SQL compliance */
5272 /*****************************************************************************
5276 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
5277 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
5278 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
5280 *****************************************************************************/
5283 DROP FUNCTION func_name func_args opt_drop_behavior
5285 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5286 n->kind = OBJECT_FUNCTION;
5288 n->args = extractArgTypes($4);
5290 n->missing_ok = false;
5293 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
5295 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5296 n->kind = OBJECT_FUNCTION;
5298 n->args = extractArgTypes($6);
5300 n->missing_ok = true;
5306 DROP AGGREGATE func_name aggr_args opt_drop_behavior
5308 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5309 n->kind = OBJECT_AGGREGATE;
5313 n->missing_ok = false;
5316 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
5318 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5319 n->kind = OBJECT_AGGREGATE;
5323 n->missing_ok = true;
5329 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
5331 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5332 n->kind = OBJECT_OPERATOR;
5336 n->missing_ok = false;
5339 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
5341 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5342 n->kind = OBJECT_OPERATOR;
5346 n->missing_ok = true;
5355 (errcode(ERRCODE_SYNTAX_ERROR),
5356 errmsg("missing argument"),
5357 errhint("Use NONE to denote the missing argument of a unary operator."),
5358 parser_errposition(@3)));
5360 | '(' Typename ',' Typename ')'
5361 { $$ = list_make2($2, $4); }
5362 | '(' NONE ',' Typename ')' /* left unary */
5363 { $$ = list_make2(NULL, $4); }
5364 | '(' Typename ',' NONE ')' /* right unary */
5365 { $$ = list_make2($2, NULL); }
5370 { $$ = list_make1(makeString($1)); }
5371 | ColId '.' any_operator
5372 { $$ = lcons(makeString($1), $3); }
5375 /*****************************************************************************
5377 * DO <anonymous code block> [ LANGUAGE language ]
5379 * We use a DefElem list for future extensibility, and to allow flexibility
5380 * in the clause order.
5382 *****************************************************************************/
5384 DoStmt: DO dostmt_opt_list
5386 DoStmt *n = makeNode(DoStmt);
5393 dostmt_opt_item { $$ = list_make1($1); }
5394 | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
5400 $$ = makeDefElem("as", (Node *)makeString($1));
5402 | LANGUAGE ColId_or_Sconst
5404 $$ = makeDefElem("language", (Node *)makeString($2));
5408 /*****************************************************************************
5410 * CREATE CAST / DROP CAST
5412 *****************************************************************************/
5414 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
5415 WITH FUNCTION function_with_argtypes cast_context
5417 CreateCastStmt *n = makeNode(CreateCastStmt);
5421 n->context = (CoercionContext) $11;
5425 | CREATE CAST '(' Typename AS Typename ')'
5426 WITHOUT FUNCTION cast_context
5428 CreateCastStmt *n = makeNode(CreateCastStmt);
5432 n->context = (CoercionContext) $10;
5436 | CREATE CAST '(' Typename AS Typename ')'
5437 WITH INOUT cast_context
5439 CreateCastStmt *n = makeNode(CreateCastStmt);
5443 n->context = (CoercionContext) $10;
5449 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
5450 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
5451 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
5455 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
5457 DropCastStmt *n = makeNode(DropCastStmt);
5466 opt_if_exists: IF_P EXISTS { $$ = TRUE; }
5467 | /*EMPTY*/ { $$ = FALSE; }
5471 /*****************************************************************************
5475 * REINDEX type <name> [FORCE]
5477 * FORCE no longer does anything, but we accept it for backwards compatibility
5478 *****************************************************************************/
5481 REINDEX reindex_type qualified_name opt_force
5483 ReindexStmt *n = makeNode(ReindexStmt);
5489 | REINDEX SYSTEM_P name opt_force
5491 ReindexStmt *n = makeNode(ReindexStmt);
5492 n->kind = OBJECT_DATABASE;
5495 n->do_system = true;
5499 | REINDEX DATABASE name opt_force
5501 ReindexStmt *n = makeNode(ReindexStmt);
5502 n->kind = OBJECT_DATABASE;
5505 n->do_system = true;
5512 INDEX { $$ = OBJECT_INDEX; }
5513 | TABLE { $$ = OBJECT_TABLE; }
5516 opt_force: FORCE { $$ = TRUE; }
5517 | /* EMPTY */ { $$ = FALSE; }
5521 /*****************************************************************************
5523 * ALTER THING name RENAME TO newname
5525 *****************************************************************************/
5527 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
5529 RenameStmt *n = makeNode(RenameStmt);
5530 n->renameType = OBJECT_AGGREGATE;
5536 | ALTER CONVERSION_P any_name RENAME TO name
5538 RenameStmt *n = makeNode(RenameStmt);
5539 n->renameType = OBJECT_CONVERSION;
5544 | ALTER DATABASE database_name RENAME TO database_name
5546 RenameStmt *n = makeNode(RenameStmt);
5547 n->renameType = OBJECT_DATABASE;
5552 | ALTER FUNCTION function_with_argtypes RENAME TO name
5554 RenameStmt *n = makeNode(RenameStmt);
5555 n->renameType = OBJECT_FUNCTION;
5556 n->object = $3->funcname;
5557 n->objarg = $3->funcargs;
5561 | ALTER GROUP_P RoleId RENAME TO RoleId
5563 RenameStmt *n = makeNode(RenameStmt);
5564 n->renameType = OBJECT_ROLE;
5569 | ALTER opt_procedural LANGUAGE name RENAME TO name
5571 RenameStmt *n = makeNode(RenameStmt);
5572 n->renameType = OBJECT_LANGUAGE;
5577 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
5579 RenameStmt *n = makeNode(RenameStmt);
5580 n->renameType = OBJECT_OPCLASS;
5586 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
5588 RenameStmt *n = makeNode(RenameStmt);
5589 n->renameType = OBJECT_OPFAMILY;
5595 | ALTER SCHEMA name RENAME TO name
5597 RenameStmt *n = makeNode(RenameStmt);
5598 n->renameType = OBJECT_SCHEMA;
5603 | ALTER TABLE relation_expr RENAME TO name
5605 RenameStmt *n = makeNode(RenameStmt);
5606 n->renameType = OBJECT_TABLE;
5612 | ALTER SEQUENCE qualified_name RENAME TO name
5614 RenameStmt *n = makeNode(RenameStmt);
5615 n->renameType = OBJECT_SEQUENCE;
5621 | ALTER VIEW qualified_name RENAME TO name
5623 RenameStmt *n = makeNode(RenameStmt);
5624 n->renameType = OBJECT_VIEW;
5630 | ALTER INDEX qualified_name RENAME TO name
5632 RenameStmt *n = makeNode(RenameStmt);
5633 n->renameType = OBJECT_INDEX;
5639 | ALTER TABLE relation_expr RENAME opt_column name TO name
5641 RenameStmt *n = makeNode(RenameStmt);
5642 n->renameType = OBJECT_COLUMN;
5648 | ALTER TRIGGER name ON qualified_name RENAME TO name
5650 RenameStmt *n = makeNode(RenameStmt);
5651 n->renameType = OBJECT_TRIGGER;
5657 | ALTER ROLE RoleId RENAME TO RoleId
5659 RenameStmt *n = makeNode(RenameStmt);
5660 n->renameType = OBJECT_ROLE;
5665 | ALTER USER RoleId RENAME TO RoleId
5667 RenameStmt *n = makeNode(RenameStmt);
5668 n->renameType = OBJECT_ROLE;
5673 | ALTER TABLESPACE name RENAME TO name
5675 RenameStmt *n = makeNode(RenameStmt);
5676 n->renameType = OBJECT_TABLESPACE;
5681 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
5683 RenameStmt *n = makeNode(RenameStmt);
5684 n->renameType = OBJECT_TSPARSER;
5689 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
5691 RenameStmt *n = makeNode(RenameStmt);
5692 n->renameType = OBJECT_TSDICTIONARY;
5697 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
5699 RenameStmt *n = makeNode(RenameStmt);
5700 n->renameType = OBJECT_TSTEMPLATE;
5705 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
5707 RenameStmt *n = makeNode(RenameStmt);
5708 n->renameType = OBJECT_TSCONFIGURATION;
5713 | ALTER TYPE_P any_name RENAME TO name
5715 RenameStmt *n = makeNode(RenameStmt);
5716 n->renameType = OBJECT_TYPE;
5723 opt_column: COLUMN { $$ = COLUMN; }
5724 | /*EMPTY*/ { $$ = 0; }
5727 opt_set_data: SET DATA_P { $$ = 1; }
5728 | /*EMPTY*/ { $$ = 0; }
5731 /*****************************************************************************
5733 * ALTER THING name SET SCHEMA name
5735 *****************************************************************************/
5737 AlterObjectSchemaStmt:
5738 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
5740 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5741 n->objectType = OBJECT_AGGREGATE;
5747 | ALTER DOMAIN_P any_name SET SCHEMA name
5749 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5750 n->objectType = OBJECT_DOMAIN;
5755 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
5757 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5758 n->objectType = OBJECT_FUNCTION;
5759 n->object = $3->funcname;
5760 n->objarg = $3->funcargs;
5764 | ALTER TABLE relation_expr SET SCHEMA name
5766 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5767 n->objectType = OBJECT_TABLE;
5772 | ALTER SEQUENCE qualified_name SET SCHEMA name
5774 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5775 n->objectType = OBJECT_SEQUENCE;
5780 | ALTER VIEW qualified_name SET SCHEMA name
5782 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5783 n->objectType = OBJECT_VIEW;
5788 | ALTER TYPE_P any_name SET SCHEMA name
5790 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5791 n->objectType = OBJECT_TYPE;
5798 /*****************************************************************************
5800 * ALTER THING name OWNER TO newname
5802 *****************************************************************************/
5804 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
5806 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5807 n->objectType = OBJECT_AGGREGATE;
5813 | ALTER CONVERSION_P any_name OWNER TO RoleId
5815 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5816 n->objectType = OBJECT_CONVERSION;
5821 | ALTER DATABASE database_name OWNER TO RoleId
5823 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5824 n->objectType = OBJECT_DATABASE;
5825 n->object = list_make1(makeString($3));
5829 | ALTER DOMAIN_P any_name OWNER TO RoleId
5831 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5832 n->objectType = OBJECT_DOMAIN;
5837 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
5839 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5840 n->objectType = OBJECT_FUNCTION;
5841 n->object = $3->funcname;
5842 n->objarg = $3->funcargs;
5846 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
5848 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5849 n->objectType = OBJECT_LANGUAGE;
5850 n->object = list_make1(makeString($4));
5854 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
5856 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5857 n->objectType = OBJECT_OPERATOR;
5863 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
5865 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5866 n->objectType = OBJECT_OPCLASS;
5872 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
5874 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5875 n->objectType = OBJECT_OPFAMILY;
5881 | ALTER SCHEMA name OWNER TO RoleId
5883 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5884 n->objectType = OBJECT_SCHEMA;
5885 n->object = list_make1(makeString($3));
5889 | ALTER TYPE_P any_name OWNER TO RoleId
5891 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5892 n->objectType = OBJECT_TYPE;
5897 | ALTER TABLESPACE name OWNER TO RoleId
5899 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5900 n->objectType = OBJECT_TABLESPACE;
5901 n->object = list_make1(makeString($3));
5905 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
5907 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5908 n->objectType = OBJECT_TSDICTIONARY;
5913 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
5915 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5916 n->objectType = OBJECT_TSCONFIGURATION;
5921 | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleId
5923 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5924 n->objectType = OBJECT_FDW;
5925 n->object = list_make1(makeString($5));
5929 | ALTER SERVER name OWNER TO RoleId
5931 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5932 n->objectType = OBJECT_FOREIGN_SERVER;
5933 n->object = list_make1(makeString($3));
5940 /*****************************************************************************
5942 * QUERY: Define Rewrite Rule
5944 *****************************************************************************/
5946 RuleStmt: CREATE opt_or_replace RULE name AS
5947 ON event TO qualified_name where_clause
5948 DO opt_instead RuleActionList
5950 RuleStmt *n = makeNode(RuleStmt);
5954 n->whereClause = $10;
5963 NOTHING { $$ = NIL; }
5964 | RuleActionStmt { $$ = list_make1($1); }
5965 | '(' RuleActionMulti ')' { $$ = $2; }
5968 /* the thrashing around here is to discard "empty" statements... */
5970 RuleActionMulti ';' RuleActionStmtOrEmpty
5972 $$ = lappend($1, $3);
5976 | RuleActionStmtOrEmpty
5978 $$ = list_make1($1);
5992 RuleActionStmtOrEmpty:
5993 RuleActionStmt { $$ = $1; }
5994 | /*EMPTY*/ { $$ = NULL; }
5997 event: SELECT { $$ = CMD_SELECT; }
5998 | UPDATE { $$ = CMD_UPDATE; }
5999 | DELETE_P { $$ = CMD_DELETE; }
6000 | INSERT { $$ = CMD_INSERT; }
6004 INSTEAD { $$ = TRUE; }
6005 | ALSO { $$ = FALSE; }
6006 | /*EMPTY*/ { $$ = FALSE; }
6011 DROP RULE name ON qualified_name opt_drop_behavior
6013 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6017 n->removeType = OBJECT_RULE;
6018 n->missing_ok = false;
6021 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
6023 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6027 n->removeType = OBJECT_RULE;
6028 n->missing_ok = true;
6034 /*****************************************************************************
6037 * NOTIFY <identifier> can appear both in rule bodies and
6038 * as a query-level command
6040 *****************************************************************************/
6042 NotifyStmt: NOTIFY ColId
6044 NotifyStmt *n = makeNode(NotifyStmt);
6045 n->conditionname = $2;
6050 ListenStmt: LISTEN ColId
6052 ListenStmt *n = makeNode(ListenStmt);
6053 n->conditionname = $2;
6061 UnlistenStmt *n = makeNode(UnlistenStmt);
6062 n->conditionname = $2;
6067 UnlistenStmt *n = makeNode(UnlistenStmt);
6068 n->conditionname = NULL;
6074 /*****************************************************************************
6078 * BEGIN / COMMIT / ROLLBACK
6079 * (also older versions END / ABORT)
6081 *****************************************************************************/
6084 ABORT_P opt_transaction
6086 TransactionStmt *n = makeNode(TransactionStmt);
6087 n->kind = TRANS_STMT_ROLLBACK;
6091 | BEGIN_P opt_transaction transaction_mode_list_or_empty
6093 TransactionStmt *n = makeNode(TransactionStmt);
6094 n->kind = TRANS_STMT_BEGIN;
6098 | START TRANSACTION transaction_mode_list_or_empty
6100 TransactionStmt *n = makeNode(TransactionStmt);
6101 n->kind = TRANS_STMT_START;
6105 | COMMIT opt_transaction
6107 TransactionStmt *n = makeNode(TransactionStmt);
6108 n->kind = TRANS_STMT_COMMIT;
6112 | END_P opt_transaction
6114 TransactionStmt *n = makeNode(TransactionStmt);
6115 n->kind = TRANS_STMT_COMMIT;
6119 | ROLLBACK opt_transaction
6121 TransactionStmt *n = makeNode(TransactionStmt);
6122 n->kind = TRANS_STMT_ROLLBACK;
6128 TransactionStmt *n = makeNode(TransactionStmt);
6129 n->kind = TRANS_STMT_SAVEPOINT;
6130 n->options = list_make1(makeDefElem("savepoint_name",
6131 (Node *)makeString($2)));
6134 | RELEASE SAVEPOINT ColId
6136 TransactionStmt *n = makeNode(TransactionStmt);
6137 n->kind = TRANS_STMT_RELEASE;
6138 n->options = list_make1(makeDefElem("savepoint_name",
6139 (Node *)makeString($3)));
6144 TransactionStmt *n = makeNode(TransactionStmt);
6145 n->kind = TRANS_STMT_RELEASE;
6146 n->options = list_make1(makeDefElem("savepoint_name",
6147 (Node *)makeString($2)));
6150 | ROLLBACK opt_transaction TO SAVEPOINT ColId
6152 TransactionStmt *n = makeNode(TransactionStmt);
6153 n->kind = TRANS_STMT_ROLLBACK_TO;
6154 n->options = list_make1(makeDefElem("savepoint_name",
6155 (Node *)makeString($5)));
6158 | ROLLBACK opt_transaction TO ColId
6160 TransactionStmt *n = makeNode(TransactionStmt);
6161 n->kind = TRANS_STMT_ROLLBACK_TO;
6162 n->options = list_make1(makeDefElem("savepoint_name",
6163 (Node *)makeString($4)));
6166 | PREPARE TRANSACTION Sconst
6168 TransactionStmt *n = makeNode(TransactionStmt);
6169 n->kind = TRANS_STMT_PREPARE;
6173 | COMMIT PREPARED Sconst
6175 TransactionStmt *n = makeNode(TransactionStmt);
6176 n->kind = TRANS_STMT_COMMIT_PREPARED;
6180 | ROLLBACK PREPARED Sconst
6182 TransactionStmt *n = makeNode(TransactionStmt);
6183 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
6189 opt_transaction: WORK {}
6194 transaction_mode_item:
6195 ISOLATION LEVEL iso_level
6196 { $$ = makeDefElem("transaction_isolation",
6197 makeStringConst($3, @3)); }
6199 { $$ = makeDefElem("transaction_read_only",
6200 makeIntConst(TRUE, @1)); }
6202 { $$ = makeDefElem("transaction_read_only",
6203 makeIntConst(FALSE, @1)); }
6206 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
6207 transaction_mode_list:
6208 transaction_mode_item
6209 { $$ = list_make1($1); }
6210 | transaction_mode_list ',' transaction_mode_item
6211 { $$ = lappend($1, $3); }
6212 | transaction_mode_list transaction_mode_item
6213 { $$ = lappend($1, $2); }
6216 transaction_mode_list_or_empty:
6217 transaction_mode_list
6223 /*****************************************************************************
6226 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
6227 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
6229 *****************************************************************************/
6231 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
6232 AS SelectStmt opt_check_option
6234 ViewStmt *n = makeNode(ViewStmt);
6236 n->view->istemp = $2;
6242 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
6243 AS SelectStmt opt_check_option
6245 ViewStmt *n = makeNode(ViewStmt);
6247 n->view->istemp = $4;
6259 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6260 errmsg("WITH CHECK OPTION is not implemented")));
6262 | WITH CASCADED CHECK OPTION
6265 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6266 errmsg("WITH CHECK OPTION is not implemented")));
6268 | WITH LOCAL CHECK OPTION
6271 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6272 errmsg("WITH CHECK OPTION is not implemented")));
6274 | /* EMPTY */ { $$ = NIL; }
6277 /*****************************************************************************
6282 *****************************************************************************/
6284 LoadStmt: LOAD file_name
6286 LoadStmt *n = makeNode(LoadStmt);
6293 /*****************************************************************************
6297 *****************************************************************************/
6300 CREATE DATABASE database_name opt_with createdb_opt_list
6302 CreatedbStmt *n = makeNode(CreatedbStmt);
6310 createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
6311 | /* EMPTY */ { $$ = NIL; }
6315 TABLESPACE opt_equal name
6317 $$ = makeDefElem("tablespace", (Node *)makeString($3));
6319 | TABLESPACE opt_equal DEFAULT
6321 $$ = makeDefElem("tablespace", NULL);
6323 | LOCATION opt_equal Sconst
6325 $$ = makeDefElem("location", (Node *)makeString($3));
6327 | LOCATION opt_equal DEFAULT
6329 $$ = makeDefElem("location", NULL);
6331 | TEMPLATE opt_equal name
6333 $$ = makeDefElem("template", (Node *)makeString($3));
6335 | TEMPLATE opt_equal DEFAULT
6337 $$ = makeDefElem("template", NULL);
6339 | ENCODING opt_equal Sconst
6341 $$ = makeDefElem("encoding", (Node *)makeString($3));
6343 | ENCODING opt_equal Iconst
6345 $$ = makeDefElem("encoding", (Node *)makeInteger($3));
6347 | ENCODING opt_equal DEFAULT
6349 $$ = makeDefElem("encoding", NULL);
6351 | LC_COLLATE_P opt_equal Sconst
6353 $$ = makeDefElem("lc_collate", (Node *)makeString($3));
6355 | LC_COLLATE_P opt_equal DEFAULT
6357 $$ = makeDefElem("lc_collate", NULL);
6359 | LC_CTYPE_P opt_equal Sconst
6361 $$ = makeDefElem("lc_ctype", (Node *)makeString($3));
6363 | LC_CTYPE_P opt_equal DEFAULT
6365 $$ = makeDefElem("lc_ctype", NULL);
6367 | CONNECTION LIMIT opt_equal SignedIconst
6369 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6371 | OWNER opt_equal name
6373 $$ = makeDefElem("owner", (Node *)makeString($3));
6375 | OWNER opt_equal DEFAULT
6377 $$ = makeDefElem("owner", NULL);
6382 * Though the equals sign doesn't match other WITH options, pg_dump uses
6383 * equals for backward compatibility, and it doesn't seem worth removing it.
6390 /*****************************************************************************
6394 *****************************************************************************/
6397 ALTER DATABASE database_name opt_with alterdb_opt_list
6399 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6404 | ALTER DATABASE database_name SET TABLESPACE name
6406 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6408 n->options = list_make1(makeDefElem("tablespace",
6409 (Node *)makeString($6)));
6414 AlterDatabaseSetStmt:
6415 ALTER DATABASE database_name SetResetClause
6417 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
6426 alterdb_opt_list alterdb_opt_item { $$ = lappend($1, $2); }
6427 | /* EMPTY */ { $$ = NIL; }
6431 CONNECTION LIMIT opt_equal SignedIconst
6433 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6438 /*****************************************************************************
6440 * DROP DATABASE [ IF EXISTS ]
6442 * This is implicitly CASCADE, no need for drop behavior
6443 *****************************************************************************/
6445 DropdbStmt: DROP DATABASE database_name
6447 DropdbStmt *n = makeNode(DropdbStmt);
6449 n->missing_ok = FALSE;
6452 | DROP DATABASE IF_P EXISTS database_name
6454 DropdbStmt *n = makeNode(DropdbStmt);
6456 n->missing_ok = TRUE;
6462 /*****************************************************************************
6464 * Manipulate a domain
6466 *****************************************************************************/
6469 CREATE DOMAIN_P any_name opt_as Typename ColQualList
6471 CreateDomainStmt *n = makeNode(CreateDomainStmt);
6474 n->constraints = $6;
6480 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
6481 ALTER DOMAIN_P any_name alter_column_default
6483 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6489 /* ALTER DOMAIN <domain> DROP NOT NULL */
6490 | ALTER DOMAIN_P any_name DROP NOT NULL_P
6492 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6497 /* ALTER DOMAIN <domain> SET NOT NULL */
6498 | ALTER DOMAIN_P any_name SET NOT NULL_P
6500 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6505 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
6506 | ALTER DOMAIN_P any_name ADD_P TableConstraint
6508 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6514 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
6515 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
6517 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6531 /*****************************************************************************
6533 * Manipulate a text search dictionary or configuration
6535 *****************************************************************************/
6537 AlterTSDictionaryStmt:
6538 ALTER TEXT_P SEARCH DICTIONARY any_name definition
6540 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
6547 AlterTSConfigurationStmt:
6548 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
6550 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6554 n->override = false;
6558 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
6560 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6568 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
6570 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6573 n->dicts = list_make2($9,$11);
6574 n->override = false;
6578 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
6580 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6583 n->dicts = list_make2($11,$13);
6584 n->override = false;
6588 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
6590 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6593 n->missing_ok = false;
6596 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
6598 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6601 n->missing_ok = true;
6607 /*****************************************************************************
6609 * Manipulate a conversion
6611 * CREATE [DEFAULT] CONVERSION <conversion_name>
6612 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
6614 *****************************************************************************/
6616 CreateConversionStmt:
6617 CREATE opt_default CONVERSION_P any_name FOR Sconst
6618 TO Sconst FROM any_name
6620 CreateConversionStmt *n = makeNode(CreateConversionStmt);
6621 n->conversion_name = $4;
6622 n->for_encoding_name = $6;
6623 n->to_encoding_name = $8;
6630 /*****************************************************************************
6633 * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
6635 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
6637 *****************************************************************************/
6640 CLUSTER opt_verbose qualified_name cluster_index_specification
6642 ClusterStmt *n = makeNode(ClusterStmt);
6648 | CLUSTER opt_verbose
6650 ClusterStmt *n = makeNode(ClusterStmt);
6652 n->indexname = NULL;
6656 /* kept for pre-8.3 compatibility */
6657 | CLUSTER opt_verbose index_name ON qualified_name
6659 ClusterStmt *n = makeNode(ClusterStmt);
6667 cluster_index_specification:
6668 USING index_name { $$ = $2; }
6669 | /*EMPTY*/ { $$ = NULL; }
6673 /*****************************************************************************
6679 *****************************************************************************/
6681 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
6683 VacuumStmt *n = makeNode(VacuumStmt);
6684 n->options = VACOPT_VACUUM;
6686 n->options |= VACOPT_FULL;
6688 n->options |= VACOPT_VERBOSE;
6689 n->freeze_min_age = $3 ? 0 : -1;
6690 n->freeze_table_age = $3 ? 0 : -1;
6695 | VACUUM opt_full opt_freeze opt_verbose qualified_name
6697 VacuumStmt *n = makeNode(VacuumStmt);
6698 n->options = VACOPT_VACUUM;
6700 n->options |= VACOPT_FULL;
6702 n->options |= VACOPT_VERBOSE;
6703 n->freeze_min_age = $3 ? 0 : -1;
6704 n->freeze_table_age = $3 ? 0 : -1;
6709 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
6711 VacuumStmt *n = (VacuumStmt *) $5;
6712 n->options |= VACOPT_VACUUM;
6714 n->options |= VACOPT_FULL;
6716 n->options |= VACOPT_VERBOSE;
6717 n->freeze_min_age = $3 ? 0 : -1;
6718 n->freeze_table_age = $3 ? 0 : -1;
6721 | VACUUM '(' vacuum_option_list ')'
6723 VacuumStmt *n = makeNode(VacuumStmt);
6724 n->options = VACOPT_VACUUM | $3;
6725 if (n->options & VACOPT_FREEZE)
6726 n->freeze_min_age = n->freeze_table_age = 0;
6728 n->freeze_min_age = n->freeze_table_age = -1;
6733 | VACUUM '(' vacuum_option_list ')' qualified_name opt_name_list
6735 VacuumStmt *n = makeNode(VacuumStmt);
6736 n->options = VACOPT_VACUUM | $3;
6737 if (n->options & VACOPT_FREEZE)
6738 n->freeze_min_age = n->freeze_table_age = 0;
6740 n->freeze_min_age = n->freeze_table_age = -1;
6743 if (n->va_cols != NIL) /* implies analyze */
6744 n->options |= VACOPT_ANALYZE;
6750 vacuum_option_elem { $$ = $1; }
6751 | vacuum_option_list ',' vacuum_option_elem { $$ = $1 | $3; }
6755 analyze_keyword { $$ = VACOPT_ANALYZE; }
6756 | VERBOSE { $$ = VACOPT_VERBOSE; }
6757 | FREEZE { $$ = VACOPT_FREEZE; }
6758 | FULL { $$ = VACOPT_FULL; }
6762 analyze_keyword opt_verbose
6764 VacuumStmt *n = makeNode(VacuumStmt);
6765 n->options = VACOPT_ANALYZE;
6767 n->options |= VACOPT_VERBOSE;
6768 n->freeze_min_age = -1;
6769 n->freeze_table_age = -1;
6774 | analyze_keyword opt_verbose qualified_name opt_name_list
6776 VacuumStmt *n = makeNode(VacuumStmt);
6777 n->options = VACOPT_ANALYZE;
6779 n->options |= VACOPT_VERBOSE;
6780 n->freeze_min_age = -1;
6781 n->freeze_table_age = -1;
6790 | ANALYSE /* British */ {}
6794 VERBOSE { $$ = TRUE; }
6795 | /*EMPTY*/ { $$ = FALSE; }
6798 opt_full: FULL { $$ = TRUE; }
6799 | /*EMPTY*/ { $$ = FALSE; }
6802 opt_freeze: FREEZE { $$ = TRUE; }
6803 | /*EMPTY*/ { $$ = FALSE; }
6807 '(' name_list ')' { $$ = $2; }
6808 | /*EMPTY*/ { $$ = NIL; }
6812 /*****************************************************************************
6815 * EXPLAIN [ANALYZE] [VERBOSE] query
6816 * EXPLAIN ( options ) query
6818 *****************************************************************************/
6821 EXPLAIN ExplainableStmt
6823 ExplainStmt *n = makeNode(ExplainStmt);
6828 | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
6830 ExplainStmt *n = makeNode(ExplainStmt);
6832 n->options = list_make1(makeDefElem("analyze", NULL));
6834 n->options = lappend(n->options,
6835 makeDefElem("verbose", NULL));
6838 | EXPLAIN VERBOSE ExplainableStmt
6840 ExplainStmt *n = makeNode(ExplainStmt);
6842 n->options = list_make1(makeDefElem("verbose", NULL));
6845 | EXPLAIN '(' explain_option_list ')' ExplainableStmt
6847 ExplainStmt *n = makeNode(ExplainStmt);
6861 | ExecuteStmt /* by default all are $$=$1 */
6864 explain_option_list:
6867 $$ = list_make1($1);
6869 | explain_option_list ',' explain_option_elem
6871 $$ = lappend($1, $3);
6875 explain_option_elem:
6876 explain_option_name explain_option_arg
6878 $$ = makeDefElem($1, $2);
6882 explain_option_name:
6884 | analyze_keyword { $$ = "analyze"; }
6885 | VERBOSE { $$ = "verbose"; }
6889 opt_boolean { $$ = (Node *) makeString($1); }
6890 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
6891 | NumericOnly { $$ = (Node *) $1; }
6892 | /* EMPTY */ { $$ = NULL; }
6895 /*****************************************************************************
6898 * PREPARE <plan_name> [(args, ...)] AS <query>
6900 *****************************************************************************/
6902 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
6904 PrepareStmt *n = makeNode(PrepareStmt);
6912 prep_type_clause: '(' type_list ')' { $$ = $2; }
6913 | /* EMPTY */ { $$ = NIL; }
6920 | DeleteStmt /* by default all are $$=$1 */
6923 /*****************************************************************************
6925 * EXECUTE <plan_name> [(params, ...)]
6926 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
6928 *****************************************************************************/
6930 ExecuteStmt: EXECUTE name execute_param_clause
6932 ExecuteStmt *n = makeNode(ExecuteStmt);
6938 | CREATE OptTemp TABLE create_as_target AS
6939 EXECUTE name execute_param_clause
6941 ExecuteStmt *n = makeNode(ExecuteStmt);
6944 $4->rel->istemp = $2;
6948 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6949 errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
6950 /* ... because it's not implemented, but it could be */
6955 execute_param_clause: '(' expr_list ')' { $$ = $2; }
6956 | /* EMPTY */ { $$ = NIL; }
6959 /*****************************************************************************
6962 * DEALLOCATE [PREPARE] <plan_name>
6964 *****************************************************************************/
6966 DeallocateStmt: DEALLOCATE name
6968 DeallocateStmt *n = makeNode(DeallocateStmt);
6972 | DEALLOCATE PREPARE name
6974 DeallocateStmt *n = makeNode(DeallocateStmt);
6980 DeallocateStmt *n = makeNode(DeallocateStmt);
6984 | DEALLOCATE PREPARE ALL
6986 DeallocateStmt *n = makeNode(DeallocateStmt);
6992 /*****************************************************************************
6997 *****************************************************************************/
7000 INSERT INTO qualified_name insert_rest returning_clause
7003 $4->returningList = $5;
7011 $$ = makeNode(InsertStmt);
7013 $$->selectStmt = $1;
7015 | '(' insert_column_list ')' SelectStmt
7017 $$ = makeNode(InsertStmt);
7019 $$->selectStmt = $4;
7023 $$ = makeNode(InsertStmt);
7025 $$->selectStmt = NULL;
7031 { $$ = list_make1($1); }
7032 | insert_column_list ',' insert_column_item
7033 { $$ = lappend($1, $3); }
7037 ColId opt_indirection
7039 $$ = makeNode(ResTarget);
7041 $$->indirection = check_indirection($2, yyscanner);
7048 RETURNING target_list { $$ = $2; }
7049 | /* EMPTY */ { $$ = NIL; }
7053 /*****************************************************************************
7058 *****************************************************************************/
7060 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
7061 using_clause where_or_current_clause returning_clause
7063 DeleteStmt *n = makeNode(DeleteStmt);
7065 n->usingClause = $4;
7066 n->whereClause = $5;
7067 n->returningList = $6;
7073 USING from_list { $$ = $2; }
7074 | /*EMPTY*/ { $$ = NIL; }
7078 /*****************************************************************************
7083 *****************************************************************************/
7085 LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
7087 LockStmt *n = makeNode(LockStmt);
7096 opt_lock: IN_P lock_type MODE { $$ = $2; }
7097 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
7100 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
7101 | ROW SHARE { $$ = RowShareLock; }
7102 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
7103 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
7104 | SHARE { $$ = ShareLock; }
7105 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
7106 | EXCLUSIVE { $$ = ExclusiveLock; }
7107 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
7110 opt_nowait: NOWAIT { $$ = TRUE; }
7111 | /*EMPTY*/ { $$ = FALSE; }
7115 /*****************************************************************************
7118 * UpdateStmt (UPDATE)
7120 *****************************************************************************/
7122 UpdateStmt: UPDATE relation_expr_opt_alias
7125 where_or_current_clause
7128 UpdateStmt *n = makeNode(UpdateStmt);
7132 n->whereClause = $6;
7133 n->returningList = $7;
7139 set_clause { $$ = $1; }
7140 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
7144 single_set_clause { $$ = list_make1($1); }
7145 | multiple_set_clause { $$ = $1; }
7149 set_target '=' ctext_expr
7152 $$->val = (Node *) $3;
7156 multiple_set_clause:
7157 '(' set_target_list ')' '=' ctext_row
7163 * Break the ctext_row apart, merge individual expressions
7164 * into the destination ResTargets. XXX this approach
7165 * cannot work for general row expressions as sources.
7167 if (list_length($2) != list_length($5))
7169 (errcode(ERRCODE_SYNTAX_ERROR),
7170 errmsg("number of columns does not match number of values"),
7171 parser_errposition(@1)));
7172 forboth(col_cell, $2, val_cell, $5)
7174 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
7175 Node *res_val = (Node *) lfirst(val_cell);
7177 res_col->val = res_val;
7185 ColId opt_indirection
7187 $$ = makeNode(ResTarget);
7189 $$->indirection = check_indirection($2, yyscanner);
7190 $$->val = NULL; /* upper production sets this */
7196 set_target { $$ = list_make1($1); }
7197 | set_target_list ',' set_target { $$ = lappend($1,$3); }
7201 /*****************************************************************************
7206 *****************************************************************************/
7207 DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
7209 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
7211 /* currently we always set FAST_PLAN option */
7212 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
7218 cursor_name: name { $$ = $1; }
7221 cursor_options: /*EMPTY*/ { $$ = 0; }
7222 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
7223 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
7224 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
7225 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
7228 opt_hold: /* EMPTY */ { $$ = 0; }
7229 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
7230 | WITHOUT HOLD { $$ = 0; }
7233 /*****************************************************************************
7238 *****************************************************************************/
7240 /* A complete SELECT statement looks like this.
7242 * The rule returns either a single SelectStmt node or a tree of them,
7243 * representing a set-operation tree.
7245 * There is an ambiguity when a sub-SELECT is within an a_expr and there
7246 * are excess parentheses: do the parentheses belong to the sub-SELECT or
7247 * to the surrounding a_expr? We don't really care, but bison wants to know.
7248 * To resolve the ambiguity, we are careful to define the grammar so that
7249 * the decision is staved off as long as possible: as long as we can keep
7250 * absorbing parentheses into the sub-SELECT, we will do so, and only when
7251 * it's no longer possible to do that will we decide that parens belong to
7252 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
7253 * parentheses are treated as part of the sub-select. The necessity of doing
7254 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
7255 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
7256 * SELECT viewpoint when we see the UNION.
7258 * This approach is implemented by defining a nonterminal select_with_parens,
7259 * which represents a SELECT with at least one outer layer of parentheses,
7260 * and being careful to use select_with_parens, never '(' SelectStmt ')',
7261 * in the expression grammar. We will then have shift-reduce conflicts
7262 * which we can resolve in favor of always treating '(' <select> ')' as
7263 * a select_with_parens. To resolve the conflicts, the productions that
7264 * conflict with the select_with_parens productions are manually given
7265 * precedences lower than the precedence of ')', thereby ensuring that we
7266 * shift ')' (and then reduce to select_with_parens) rather than trying to
7267 * reduce the inner <select> nonterminal to something else. We use UMINUS
7268 * precedence for this, which is a fairly arbitrary choice.
7270 * To be able to define select_with_parens itself without ambiguity, we need
7271 * a nonterminal select_no_parens that represents a SELECT structure with no
7272 * outermost parentheses. This is a little bit tedious, but it works.
7274 * In non-expression contexts, we use SelectStmt which can represent a SELECT
7275 * with or without outer parentheses.
7278 SelectStmt: select_no_parens %prec UMINUS
7279 | select_with_parens %prec UMINUS
7283 '(' select_no_parens ')' { $$ = $2; }
7284 | '(' select_with_parens ')' { $$ = $2; }
7288 * This rule parses the equivalent of the standard's <query expression>.
7289 * The duplicative productions are annoying, but hard to get rid of without
7290 * creating shift/reduce conflicts.
7292 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
7293 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
7294 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
7298 simple_select { $$ = $1; }
7299 | select_clause sort_clause
7301 insertSelectOptions((SelectStmt *) $1, $2, NIL,
7306 | select_clause opt_sort_clause for_locking_clause opt_select_limit
7308 insertSelectOptions((SelectStmt *) $1, $2, $3,
7309 list_nth($4, 0), list_nth($4, 1),
7314 | select_clause opt_sort_clause select_limit opt_for_locking_clause
7316 insertSelectOptions((SelectStmt *) $1, $2, $4,
7317 list_nth($3, 0), list_nth($3, 1),
7322 | with_clause select_clause
7324 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
7330 | with_clause select_clause sort_clause
7332 insertSelectOptions((SelectStmt *) $2, $3, NIL,
7338 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
7340 insertSelectOptions((SelectStmt *) $2, $3, $4,
7341 list_nth($5, 0), list_nth($5, 1),
7346 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
7348 insertSelectOptions((SelectStmt *) $2, $3, $5,
7349 list_nth($4, 0), list_nth($4, 1),
7357 simple_select { $$ = $1; }
7358 | select_with_parens { $$ = $1; }
7362 * This rule parses SELECT statements that can appear within set operations,
7363 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
7364 * the ordering of the set operations. Without '(' and ')' we want the
7365 * operations to be ordered per the precedence specs at the head of this file.
7367 * As with select_no_parens, simple_select cannot have outer parentheses,
7368 * but can have parenthesized subclauses.
7370 * Note that sort clauses cannot be included at this level --- SQL92 requires
7371 * SELECT foo UNION SELECT bar ORDER BY baz
7373 * (SELECT foo UNION SELECT bar) ORDER BY baz
7375 * SELECT foo UNION (SELECT bar ORDER BY baz)
7376 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
7377 * described as part of the select_no_parens production, not simple_select.
7378 * This does not limit functionality, because you can reintroduce these
7379 * clauses inside parentheses.
7381 * NOTE: only the leftmost component SelectStmt should have INTO.
7382 * However, this is not checked by the grammar; parse analysis must check it.
7385 SELECT opt_distinct target_list
7386 into_clause from_clause where_clause
7387 group_clause having_clause window_clause
7389 SelectStmt *n = makeNode(SelectStmt);
7390 n->distinctClause = $2;
7394 n->whereClause = $6;
7395 n->groupClause = $7;
7396 n->havingClause = $8;
7397 n->windowClause = $9;
7400 | values_clause { $$ = $1; }
7401 | TABLE relation_expr
7403 /* same as SELECT * FROM relation_expr */
7404 ColumnRef *cr = makeNode(ColumnRef);
7405 ResTarget *rt = makeNode(ResTarget);
7406 SelectStmt *n = makeNode(SelectStmt);
7408 cr->fields = list_make1(makeNode(A_Star));
7412 rt->indirection = NIL;
7413 rt->val = (Node *)cr;
7416 n->targetList = list_make1(rt);
7417 n->fromClause = list_make1($2);
7420 | select_clause UNION opt_all select_clause
7422 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
7424 | select_clause INTERSECT opt_all select_clause
7426 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
7428 | select_clause EXCEPT opt_all select_clause
7430 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
7435 * SQL standard WITH clause looks like:
7437 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
7438 * AS (query) [ SEARCH or CYCLE clause ]
7440 * We don't currently support the SEARCH or CYCLE clause.
7445 $$ = makeNode(WithClause);
7447 $$->recursive = false;
7450 | WITH RECURSIVE cte_list
7452 $$ = makeNode(WithClause);
7454 $$->recursive = true;
7460 common_table_expr { $$ = list_make1($1); }
7461 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
7464 common_table_expr: name opt_name_list AS select_with_parens
7466 CommonTableExpr *n = makeNode(CommonTableExpr);
7468 n->aliascolnames = $2;
7476 INTO OptTempTableName
7478 $$ = makeNode(IntoClause);
7482 $$->onCommit = ONCOMMIT_NOOP;
7483 $$->tableSpaceName = NULL;
7490 * Redundancy here is needed to avoid shift/reduce conflicts,
7491 * since TEMP is not a reserved word. See also OptTemp.
7494 TEMPORARY opt_table qualified_name
7499 | TEMP opt_table qualified_name
7504 | LOCAL TEMPORARY opt_table qualified_name
7509 | LOCAL TEMP opt_table qualified_name
7514 | GLOBAL TEMPORARY opt_table qualified_name
7519 | GLOBAL TEMP opt_table qualified_name
7524 | TABLE qualified_name
7540 opt_all: ALL { $$ = TRUE; }
7541 | DISTINCT { $$ = FALSE; }
7542 | /*EMPTY*/ { $$ = FALSE; }
7545 /* We use (NIL) as a placeholder to indicate that all target expressions
7546 * should be placed in the DISTINCT list during parsetree analysis.
7549 DISTINCT { $$ = list_make1(NIL); }
7550 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
7552 | /*EMPTY*/ { $$ = NIL; }
7556 sort_clause { $$ = $1;}
7557 | /*EMPTY*/ { $$ = NIL; }
7561 ORDER BY sortby_list { $$ = $3; }
7565 sortby { $$ = list_make1($1); }
7566 | sortby_list ',' sortby { $$ = lappend($1, $3); }
7569 sortby: a_expr USING qual_all_Op opt_nulls_order
7571 $$ = makeNode(SortBy);
7573 $$->sortby_dir = SORTBY_USING;
7574 $$->sortby_nulls = $4;
7578 | a_expr opt_asc_desc opt_nulls_order
7580 $$ = makeNode(SortBy);
7582 $$->sortby_dir = $2;
7583 $$->sortby_nulls = $3;
7585 $$->location = -1; /* no operator */
7591 limit_clause offset_clause { $$ = list_make2($2, $1); }
7592 | offset_clause limit_clause { $$ = list_make2($1, $2); }
7593 | limit_clause { $$ = list_make2(NULL, $1); }
7594 | offset_clause { $$ = list_make2($1, NULL); }
7598 select_limit { $$ = $1; }
7599 | /* EMPTY */ { $$ = list_make2(NULL,NULL); }
7603 LIMIT select_limit_value
7605 | LIMIT select_limit_value ',' select_offset_value
7607 /* Disabled because it was too confusing, bjm 2002-02-18 */
7609 (errcode(ERRCODE_SYNTAX_ERROR),
7610 errmsg("LIMIT #,# syntax is not supported"),
7611 errhint("Use separate LIMIT and OFFSET clauses."),
7612 parser_errposition(@1)));
7614 /* SQL:2008 syntax */
7615 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
7620 OFFSET select_offset_value
7622 /* SQL:2008 syntax */
7623 | OFFSET select_offset_value2 row_or_rows
7631 /* LIMIT ALL is represented as a NULL constant */
7632 $$ = makeNullAConst(@1);
7636 select_offset_value:
7641 * Allowing full expressions without parentheses causes various parsing
7642 * problems with the trailing ROW/ROWS key words. SQL only calls for
7643 * constants, so we allow the rest only with parentheses. If omitted,
7646 opt_select_fetch_first_value:
7647 SignedIconst { $$ = makeIntConst($1, @1); }
7648 | '(' a_expr ')' { $$ = $2; }
7649 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
7653 * Again, the trailing ROW/ROWS in this case prevent the full expression
7654 * syntax. c_expr is the best we can do.
7656 select_offset_value2:
7661 row_or_rows: ROW { $$ = 0; }
7665 first_or_next: FIRST_P { $$ = 0; }
7671 GROUP_P BY expr_list { $$ = $3; }
7672 | /*EMPTY*/ { $$ = NIL; }
7676 HAVING a_expr { $$ = $2; }
7677 | /*EMPTY*/ { $$ = NULL; }
7681 for_locking_items { $$ = $1; }
7682 | FOR READ ONLY { $$ = NIL; }
7685 opt_for_locking_clause:
7686 for_locking_clause { $$ = $1; }
7687 | /* EMPTY */ { $$ = NIL; }
7691 for_locking_item { $$ = list_make1($1); }
7692 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
7696 FOR UPDATE locked_rels_list opt_nowait
7698 LockingClause *n = makeNode(LockingClause);
7700 n->forUpdate = TRUE;
7704 | FOR SHARE locked_rels_list opt_nowait
7706 LockingClause *n = makeNode(LockingClause);
7708 n->forUpdate = FALSE;
7715 OF qualified_name_list { $$ = $2; }
7716 | /* EMPTY */ { $$ = NIL; }
7723 SelectStmt *n = makeNode(SelectStmt);
7724 n->valuesLists = list_make1($2);
7727 | values_clause ',' ctext_row
7729 SelectStmt *n = (SelectStmt *) $1;
7730 n->valuesLists = lappend(n->valuesLists, $3);
7736 /*****************************************************************************
7738 * clauses common to all Optimizable Stmts:
7739 * from_clause - allow list of both JOIN expressions and table names
7740 * where_clause - qualifications for joins or restrictions
7742 *****************************************************************************/
7745 FROM from_list { $$ = $2; }
7746 | /*EMPTY*/ { $$ = NIL; }
7750 table_ref { $$ = list_make1($1); }
7751 | from_list ',' table_ref { $$ = lappend($1, $3); }
7755 * table_ref is where an alias clause can be attached. Note we cannot make
7756 * alias_clause have an empty production because that causes parse conflicts
7757 * between table_ref := '(' joined_table ')' alias_clause
7758 * and joined_table := '(' joined_table ')'. So, we must have the
7759 * redundant-looking productions here instead.
7761 table_ref: relation_expr
7765 | relation_expr alias_clause
7772 RangeFunction *n = makeNode(RangeFunction);
7773 n->funccallnode = $1;
7774 n->coldeflist = NIL;
7777 | func_table alias_clause
7779 RangeFunction *n = makeNode(RangeFunction);
7780 n->funccallnode = $1;
7782 n->coldeflist = NIL;
7785 | func_table AS '(' TableFuncElementList ')'
7787 RangeFunction *n = makeNode(RangeFunction);
7788 n->funccallnode = $1;
7792 | func_table AS ColId '(' TableFuncElementList ')'
7794 RangeFunction *n = makeNode(RangeFunction);
7795 Alias *a = makeNode(Alias);
7796 n->funccallnode = $1;
7802 | func_table ColId '(' TableFuncElementList ')'
7804 RangeFunction *n = makeNode(RangeFunction);
7805 Alias *a = makeNode(Alias);
7806 n->funccallnode = $1;
7812 | select_with_parens
7815 * The SQL spec does not permit a subselect
7816 * (<derived_table>) without an alias clause,
7817 * so we don't either. This avoids the problem
7818 * of needing to invent a unique refname for it.
7819 * That could be surmounted if there's sufficient
7820 * popular demand, but for now let's just implement
7821 * the spec and see if anyone complains.
7822 * However, it does seem like a good idea to emit
7823 * an error message that's better than "syntax error".
7825 if (IsA($1, SelectStmt) &&
7826 ((SelectStmt *) $1)->valuesLists)
7828 (errcode(ERRCODE_SYNTAX_ERROR),
7829 errmsg("VALUES in FROM must have an alias"),
7830 errhint("For example, FROM (VALUES ...) [AS] foo."),
7831 parser_errposition(@1)));
7834 (errcode(ERRCODE_SYNTAX_ERROR),
7835 errmsg("subquery in FROM must have an alias"),
7836 errhint("For example, FROM (SELECT ...) [AS] foo."),
7837 parser_errposition(@1)));
7840 | select_with_parens alias_clause
7842 RangeSubselect *n = makeNode(RangeSubselect);
7851 | '(' joined_table ')' alias_clause
7860 * It may seem silly to separate joined_table from table_ref, but there is
7861 * method in SQL92's madness: if you don't do it this way you get reduce-
7862 * reduce conflicts, because it's not clear to the parser generator whether
7863 * to expect alias_clause after ')' or not. For the same reason we must
7864 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
7865 * join_type to expand to empty; if we try it, the parser generator can't
7866 * figure out when to reduce an empty join_type right after table_ref.
7868 * Note that a CROSS JOIN is the same as an unqualified
7869 * INNER JOIN, and an INNER JOIN/ON has the same shape
7870 * but a qualification expression to limit membership.
7871 * A NATURAL JOIN implicitly matches column names between
7872 * tables and the shape is determined by which columns are
7873 * in common. We'll collect columns during the later transformations.
7877 '(' joined_table ')'
7881 | table_ref CROSS JOIN table_ref
7883 /* CROSS JOIN is same as unqualified inner join */
7884 JoinExpr *n = makeNode(JoinExpr);
7885 n->jointype = JOIN_INNER;
7886 n->isNatural = FALSE;
7889 n->usingClause = NIL;
7893 | table_ref join_type JOIN table_ref join_qual
7895 JoinExpr *n = makeNode(JoinExpr);
7897 n->isNatural = FALSE;
7900 if ($5 != NULL && IsA($5, List))
7901 n->usingClause = (List *) $5; /* USING clause */
7903 n->quals = $5; /* ON clause */
7906 | table_ref JOIN table_ref join_qual
7908 /* letting join_type reduce to empty doesn't work */
7909 JoinExpr *n = makeNode(JoinExpr);
7910 n->jointype = JOIN_INNER;
7911 n->isNatural = FALSE;
7914 if ($4 != NULL && IsA($4, List))
7915 n->usingClause = (List *) $4; /* USING clause */
7917 n->quals = $4; /* ON clause */
7920 | table_ref NATURAL join_type JOIN table_ref
7922 JoinExpr *n = makeNode(JoinExpr);
7924 n->isNatural = TRUE;
7927 n->usingClause = NIL; /* figure out which columns later... */
7928 n->quals = NULL; /* fill later */
7931 | table_ref NATURAL JOIN table_ref
7933 /* letting join_type reduce to empty doesn't work */
7934 JoinExpr *n = makeNode(JoinExpr);
7935 n->jointype = JOIN_INNER;
7936 n->isNatural = TRUE;
7939 n->usingClause = NIL; /* figure out which columns later... */
7940 n->quals = NULL; /* fill later */
7946 AS ColId '(' name_list ')'
7948 $$ = makeNode(Alias);
7954 $$ = makeNode(Alias);
7957 | ColId '(' name_list ')'
7959 $$ = makeNode(Alias);
7965 $$ = makeNode(Alias);
7970 join_type: FULL join_outer { $$ = JOIN_FULL; }
7971 | LEFT join_outer { $$ = JOIN_LEFT; }
7972 | RIGHT join_outer { $$ = JOIN_RIGHT; }
7973 | INNER_P { $$ = JOIN_INNER; }
7976 /* OUTER is just noise... */
7977 join_outer: OUTER_P { $$ = NULL; }
7978 | /*EMPTY*/ { $$ = NULL; }
7981 /* JOIN qualification clauses
7982 * Possibilities are:
7983 * USING ( column list ) allows only unqualified column names,
7984 * which must match between tables.
7985 * ON expr allows more general qualifications.
7987 * We return USING as a List node, while an ON-expr will not be a List.
7990 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
7991 | ON a_expr { $$ = $2; }
7998 /* default inheritance */
8000 $$->inhOpt = INH_DEFAULT;
8003 | qualified_name '*'
8005 /* inheritance query */
8007 $$->inhOpt = INH_YES;
8010 | ONLY qualified_name
8012 /* no inheritance */
8014 $$->inhOpt = INH_NO;
8017 | ONLY '(' qualified_name ')'
8019 /* no inheritance, SQL99-style syntax */
8021 $$->inhOpt = INH_NO;
8028 relation_expr { $$ = list_make1($1); }
8029 | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
8034 * Given "UPDATE foo set set ...", we have to decide without looking any
8035 * further ahead whether the first "set" is an alias or the UPDATE's SET
8036 * keyword. Since "set" is allowed as a column name both interpretations
8037 * are feasible. We resolve the shift/reduce conflict by giving the first
8038 * relation_expr_opt_alias production a higher precedence than the SET token
8039 * has, causing the parser to prefer to reduce, in effect assuming that the
8040 * SET is not an alias.
8042 relation_expr_opt_alias: relation_expr %prec UMINUS
8046 | relation_expr ColId
8048 Alias *alias = makeNode(Alias);
8049 alias->aliasname = $2;
8053 | relation_expr AS ColId
8055 Alias *alias = makeNode(Alias);
8056 alias->aliasname = $3;
8063 func_table: func_expr { $$ = $1; }
8068 WHERE a_expr { $$ = $2; }
8069 | /*EMPTY*/ { $$ = NULL; }
8072 /* variant for UPDATE and DELETE */
8073 where_or_current_clause:
8074 WHERE a_expr { $$ = $2; }
8075 | WHERE CURRENT_P OF name
8077 CurrentOfExpr *n = makeNode(CurrentOfExpr);
8078 /* cvarno is filled in by parse analysis */
8079 n->cursor_name = $4;
8080 n->cursor_param = 0;
8083 | /*EMPTY*/ { $$ = NULL; }
8087 TableFuncElementList:
8090 $$ = list_make1($1);
8092 | TableFuncElementList ',' TableFuncElement
8094 $$ = lappend($1, $3);
8098 TableFuncElement: ColId Typename
8100 ColumnDef *n = makeNode(ColumnDef);
8103 n->constraints = NIL;
8109 /*****************************************************************************
8112 * SQL92 introduces a large amount of type-specific syntax.
8113 * Define individual clauses to handle these cases, and use
8114 * the generic case to handle regular type-extensible Postgres syntax.
8115 * - thomas 1997-10-10
8117 *****************************************************************************/
8119 Typename: SimpleTypename opt_array_bounds
8122 $$->arrayBounds = $2;
8124 | SETOF SimpleTypename opt_array_bounds
8127 $$->arrayBounds = $3;
8130 /* SQL standard syntax, currently only one-dimensional */
8131 | SimpleTypename ARRAY '[' Iconst ']'
8134 $$->arrayBounds = list_make1(makeInteger($4));
8136 | SETOF SimpleTypename ARRAY '[' Iconst ']'
8139 $$->arrayBounds = list_make1(makeInteger($5));
8142 | SimpleTypename ARRAY
8145 $$->arrayBounds = list_make1(makeInteger(-1));
8147 | SETOF SimpleTypename ARRAY
8150 $$->arrayBounds = list_make1(makeInteger(-1));
8156 opt_array_bounds '[' ']'
8157 { $$ = lappend($1, makeInteger(-1)); }
8158 | opt_array_bounds '[' Iconst ']'
8159 { $$ = lappend($1, makeInteger($3)); }
8165 GenericType { $$ = $1; }
8166 | Numeric { $$ = $1; }
8168 | Character { $$ = $1; }
8169 | ConstDatetime { $$ = $1; }
8170 | ConstInterval opt_interval
8175 | ConstInterval '(' Iconst ')' opt_interval
8180 if (list_length($5) != 1)
8182 (errcode(ERRCODE_SYNTAX_ERROR),
8183 errmsg("interval precision specified twice"),
8184 parser_errposition(@1)));
8185 $$->typmods = lappend($5, makeIntConst($3, @3));
8188 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
8189 makeIntConst($3, @3));
8193 /* We have a separate ConstTypename to allow defaulting fixed-length
8194 * types such as CHAR() and BIT() to an unspecified length.
8195 * SQL9x requires that these default to a length of one, but this
8196 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
8197 * where there is an obvious better choice to make.
8198 * Note that ConstInterval is not included here since it must
8199 * be pushed up higher in the rules to accomodate the postfix
8200 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
8201 * the generic-type-name case in AExprConst to avoid premature
8202 * reduce/reduce conflicts against function names.
8205 Numeric { $$ = $1; }
8206 | ConstBit { $$ = $1; }
8207 | ConstCharacter { $$ = $1; }
8208 | ConstDatetime { $$ = $1; }
8212 * GenericType covers all type names that don't have special syntax mandated
8213 * by the standard, including qualified names. We also allow type modifiers.
8214 * To avoid parsing conflicts against function invocations, the modifiers
8215 * have to be shown as expr_list here, but parse analysis will only accept
8216 * constants for them.
8219 type_function_name opt_type_modifiers
8221 $$ = makeTypeName($1);
8225 | type_function_name attrs opt_type_modifiers
8227 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8233 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
8234 | /* EMPTY */ { $$ = NIL; }
8238 * SQL92 numeric data types
8242 $$ = SystemTypeName("int4");
8247 $$ = SystemTypeName("int4");
8252 $$ = SystemTypeName("int2");
8257 $$ = SystemTypeName("int8");
8262 $$ = SystemTypeName("float4");
8270 | DOUBLE_P PRECISION
8272 $$ = SystemTypeName("float8");
8275 | DECIMAL_P opt_type_modifiers
8277 $$ = SystemTypeName("numeric");
8281 | DEC opt_type_modifiers
8283 $$ = SystemTypeName("numeric");
8287 | NUMERIC opt_type_modifiers
8289 $$ = SystemTypeName("numeric");
8295 $$ = SystemTypeName("bool");
8300 opt_float: '(' Iconst ')'
8303 * Check FLOAT() precision limits assuming IEEE floating
8304 * types - thomas 1997-09-18
8308 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8309 errmsg("precision for type float must be at least 1 bit"),
8310 parser_errposition(@2)));
8312 $$ = SystemTypeName("float4");
8314 $$ = SystemTypeName("float8");
8317 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8318 errmsg("precision for type float must be less than 54 bits"),
8319 parser_errposition(@2)));
8323 $$ = SystemTypeName("float8");
8328 * SQL92 bit-field data types
8329 * The following implements BIT() and BIT VARYING().
8341 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
8342 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
8343 ConstBit: BitWithLength
8355 BIT opt_varying '(' expr_list ')'
8359 typname = $2 ? "varbit" : "bit";
8360 $$ = SystemTypeName(typname);
8369 /* bit defaults to bit(1), varbit to no limit */
8372 $$ = SystemTypeName("varbit");
8376 $$ = SystemTypeName("bit");
8377 $$->typmods = list_make1(makeIntConst(1, -1));
8385 * SQL92 character data types
8386 * The following implements CHAR() and VARCHAR().
8388 Character: CharacterWithLength
8392 | CharacterWithoutLength
8398 ConstCharacter: CharacterWithLength
8402 | CharacterWithoutLength
8404 /* Length was not specified so allow to be unrestricted.
8405 * This handles problems with fixed-length (bpchar) strings
8406 * which in column definitions must default to a length
8407 * of one, but should not be constrained if the length
8408 * was not specified.
8415 CharacterWithLength: character '(' Iconst ')' opt_charset
8417 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
8421 type = palloc(strlen($1) + 1 + strlen($5) + 1);
8428 $$ = SystemTypeName($1);
8429 $$->typmods = list_make1(makeIntConst($3, @3));
8434 CharacterWithoutLength: character opt_charset
8436 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
8440 type = palloc(strlen($1) + 1 + strlen($2) + 1);
8447 $$ = SystemTypeName($1);
8449 /* char defaults to char(1), varchar to no limit */
8450 if (strcmp($1, "bpchar") == 0)
8451 $$->typmods = list_make1(makeIntConst(1, -1));
8457 character: CHARACTER opt_varying
8458 { $$ = $2 ? "varchar": "bpchar"; }
8459 | CHAR_P opt_varying
8460 { $$ = $2 ? "varchar": "bpchar"; }
8463 | NATIONAL CHARACTER opt_varying
8464 { $$ = $3 ? "varchar": "bpchar"; }
8465 | NATIONAL CHAR_P opt_varying
8466 { $$ = $3 ? "varchar": "bpchar"; }
8468 { $$ = $2 ? "varchar": "bpchar"; }
8472 VARYING { $$ = TRUE; }
8473 | /*EMPTY*/ { $$ = FALSE; }
8477 CHARACTER SET ColId { $$ = $3; }
8478 | /*EMPTY*/ { $$ = NULL; }
8482 * SQL92 date/time types
8485 TIMESTAMP '(' Iconst ')' opt_timezone
8488 $$ = SystemTypeName("timestamptz");
8490 $$ = SystemTypeName("timestamp");
8491 $$->typmods = list_make1(makeIntConst($3, @3));
8494 | TIMESTAMP opt_timezone
8497 $$ = SystemTypeName("timestamptz");
8499 $$ = SystemTypeName("timestamp");
8502 | TIME '(' Iconst ')' opt_timezone
8505 $$ = SystemTypeName("timetz");
8507 $$ = SystemTypeName("time");
8508 $$->typmods = list_make1(makeIntConst($3, @3));
8514 $$ = SystemTypeName("timetz");
8516 $$ = SystemTypeName("time");
8524 $$ = SystemTypeName("interval");
8530 WITH_TIME ZONE { $$ = TRUE; }
8531 | WITHOUT TIME ZONE { $$ = FALSE; }
8532 | /*EMPTY*/ { $$ = FALSE; }
8537 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
8539 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
8541 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
8543 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
8545 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
8550 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
8551 INTERVAL_MASK(MONTH), @1));
8555 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8556 INTERVAL_MASK(HOUR), @1));
8560 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8561 INTERVAL_MASK(HOUR) |
8562 INTERVAL_MASK(MINUTE), @1));
8564 | DAY_P TO interval_second
8567 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
8568 INTERVAL_MASK(HOUR) |
8569 INTERVAL_MASK(MINUTE) |
8570 INTERVAL_MASK(SECOND), @1);
8572 | HOUR_P TO MINUTE_P
8574 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
8575 INTERVAL_MASK(MINUTE), @1));
8577 | HOUR_P TO interval_second
8580 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
8581 INTERVAL_MASK(MINUTE) |
8582 INTERVAL_MASK(SECOND), @1);
8584 | MINUTE_P TO interval_second
8587 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
8588 INTERVAL_MASK(SECOND), @1);
8597 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
8599 | SECOND_P '(' Iconst ')'
8601 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
8602 makeIntConst($3, @3));
8607 /*****************************************************************************
8609 * expression grammar
8611 *****************************************************************************/
8614 * General expressions
8615 * This is the heart of the expression syntax.
8617 * We have two expression types: a_expr is the unrestricted kind, and
8618 * b_expr is a subset that must be used in some places to avoid shift/reduce
8619 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
8620 * because that use of AND conflicts with AND as a boolean operator. So,
8621 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
8623 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
8624 * always be used by surrounding it with parens.
8626 * c_expr is all the productions that are common to a_expr and b_expr;
8627 * it's factored out just to eliminate redundant coding.
8629 a_expr: c_expr { $$ = $1; }
8630 | a_expr TYPECAST Typename
8631 { $$ = makeTypeCast($1, $3, @2); }
8632 | a_expr AT TIME ZONE a_expr
8634 FuncCall *n = makeNode(FuncCall);
8635 n->funcname = SystemFuncName("timezone");
8636 n->args = list_make2($5, $1);
8637 n->agg_star = FALSE;
8638 n->agg_distinct = FALSE;
8639 n->func_variadic = FALSE;
8645 * These operators must be called out explicitly in order to make use
8646 * of bison's automatic operator-precedence handling. All other
8647 * operator names are handled by the generic productions using "Op",
8648 * below; and all those operators will have the same precedence.
8650 * If you add more explicitly-known operators, be sure to add them
8651 * also to b_expr and to the MathOp list above.
8653 | '+' a_expr %prec UMINUS
8654 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
8655 | '-' a_expr %prec UMINUS
8656 { $$ = doNegate($2, @1); }
8658 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
8660 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
8662 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
8664 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
8666 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
8668 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
8670 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
8672 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
8674 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
8676 | a_expr qual_Op a_expr %prec Op
8677 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
8678 | qual_Op a_expr %prec Op
8679 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
8680 | a_expr qual_Op %prec POSTFIXOP
8681 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
8684 { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
8686 { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
8688 { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
8690 | a_expr LIKE a_expr
8691 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
8692 | a_expr LIKE a_expr ESCAPE a_expr
8694 FuncCall *n = makeNode(FuncCall);
8695 n->funcname = SystemFuncName("like_escape");
8696 n->args = list_make2($3, $5);
8697 n->agg_star = FALSE;
8698 n->agg_distinct = FALSE;
8699 n->func_variadic = FALSE;
8702 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
8704 | a_expr NOT LIKE a_expr
8705 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
8706 | a_expr NOT LIKE a_expr ESCAPE a_expr
8708 FuncCall *n = makeNode(FuncCall);
8709 n->funcname = SystemFuncName("like_escape");
8710 n->args = list_make2($4, $6);
8711 n->agg_star = FALSE;
8712 n->agg_distinct = FALSE;
8713 n->func_variadic = FALSE;
8716 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
8718 | a_expr ILIKE a_expr
8719 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
8720 | a_expr ILIKE a_expr ESCAPE a_expr
8722 FuncCall *n = makeNode(FuncCall);
8723 n->funcname = SystemFuncName("like_escape");
8724 n->args = list_make2($3, $5);
8725 n->agg_star = FALSE;
8726 n->agg_distinct = FALSE;
8727 n->func_variadic = FALSE;
8730 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n, @2);
8732 | a_expr NOT ILIKE a_expr
8733 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
8734 | a_expr NOT ILIKE a_expr ESCAPE a_expr
8736 FuncCall *n = makeNode(FuncCall);
8737 n->funcname = SystemFuncName("like_escape");
8738 n->args = list_make2($4, $6);
8739 n->agg_star = FALSE;
8740 n->agg_distinct = FALSE;
8741 n->func_variadic = FALSE;
8744 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n, @2);
8747 | a_expr SIMILAR TO a_expr %prec SIMILAR
8749 FuncCall *n = makeNode(FuncCall);
8750 n->funcname = SystemFuncName("similar_escape");
8751 n->args = list_make2($4, makeNullAConst(-1));
8752 n->agg_star = FALSE;
8753 n->agg_distinct = FALSE;
8754 n->func_variadic = FALSE;
8757 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8759 | a_expr SIMILAR TO a_expr ESCAPE a_expr
8761 FuncCall *n = makeNode(FuncCall);
8762 n->funcname = SystemFuncName("similar_escape");
8763 n->args = list_make2($4, $6);
8764 n->agg_star = FALSE;
8765 n->agg_distinct = FALSE;
8766 n->func_variadic = FALSE;
8769 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8771 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
8773 FuncCall *n = makeNode(FuncCall);
8774 n->funcname = SystemFuncName("similar_escape");
8775 n->args = list_make2($5, makeNullAConst(-1));
8776 n->agg_star = FALSE;
8777 n->agg_distinct = FALSE;
8778 n->func_variadic = FALSE;
8781 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8783 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
8785 FuncCall *n = makeNode(FuncCall);
8786 n->funcname = SystemFuncName("similar_escape");
8787 n->args = list_make2($5, $7);
8788 n->agg_star = FALSE;
8789 n->agg_distinct = FALSE;
8790 n->func_variadic = FALSE;
8793 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8797 * Define SQL92-style Null test clause.
8798 * Allow two forms described in the standard:
8801 * Allow two SQL extensions
8807 NullTest *n = makeNode(NullTest);
8808 n->arg = (Expr *) $1;
8809 n->nulltesttype = IS_NULL;
8814 NullTest *n = makeNode(NullTest);
8815 n->arg = (Expr *) $1;
8816 n->nulltesttype = IS_NULL;
8819 | a_expr IS NOT NULL_P
8821 NullTest *n = makeNode(NullTest);
8822 n->arg = (Expr *) $1;
8823 n->nulltesttype = IS_NOT_NULL;
8828 NullTest *n = makeNode(NullTest);
8829 n->arg = (Expr *) $1;
8830 n->nulltesttype = IS_NOT_NULL;
8835 $$ = (Node *)makeOverlaps($1, $3, @2, yyscanner);
8839 BooleanTest *b = makeNode(BooleanTest);
8840 b->arg = (Expr *) $1;
8841 b->booltesttype = IS_TRUE;
8844 | a_expr IS NOT TRUE_P
8846 BooleanTest *b = makeNode(BooleanTest);
8847 b->arg = (Expr *) $1;
8848 b->booltesttype = IS_NOT_TRUE;
8853 BooleanTest *b = makeNode(BooleanTest);
8854 b->arg = (Expr *) $1;
8855 b->booltesttype = IS_FALSE;
8858 | a_expr IS NOT FALSE_P
8860 BooleanTest *b = makeNode(BooleanTest);
8861 b->arg = (Expr *) $1;
8862 b->booltesttype = IS_NOT_FALSE;
8867 BooleanTest *b = makeNode(BooleanTest);
8868 b->arg = (Expr *) $1;
8869 b->booltesttype = IS_UNKNOWN;
8872 | a_expr IS NOT UNKNOWN
8874 BooleanTest *b = makeNode(BooleanTest);
8875 b->arg = (Expr *) $1;
8876 b->booltesttype = IS_NOT_UNKNOWN;
8879 | a_expr IS DISTINCT FROM a_expr %prec IS
8881 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
8883 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
8885 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8886 (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
8891 | a_expr IS OF '(' type_list ')' %prec IS
8893 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
8895 | a_expr IS NOT OF '(' type_list ')' %prec IS
8897 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
8900 * Ideally we would not use hard-wired operators below but
8901 * instead use opclasses. However, mixed data types and other
8902 * issues make this difficult:
8903 * http://archives.postgresql.org/pgsql-hackers/2008-08/msg01142.php
8905 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
8907 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
8908 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
8909 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
8912 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
8914 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
8915 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
8916 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
8919 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
8921 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
8922 (Node *) makeA_Expr(AEXPR_AND, NIL,
8923 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
8924 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
8926 (Node *) makeA_Expr(AEXPR_AND, NIL,
8927 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
8928 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
8932 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
8934 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
8935 (Node *) makeA_Expr(AEXPR_OR, NIL,
8936 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
8937 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
8939 (Node *) makeA_Expr(AEXPR_OR, NIL,
8940 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
8941 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
8945 | a_expr IN_P in_expr
8947 /* in_expr returns a SubLink or a list of a_exprs */
8948 if (IsA($3, SubLink))
8950 /* generate foo = ANY (subquery) */
8951 SubLink *n = (SubLink *) $3;
8952 n->subLinkType = ANY_SUBLINK;
8954 n->operName = list_make1(makeString("="));
8960 /* generate scalar IN expression */
8961 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
8964 | a_expr NOT IN_P in_expr
8966 /* in_expr returns a SubLink or a list of a_exprs */
8967 if (IsA($4, SubLink))
8969 /* generate NOT (foo = ANY (subquery)) */
8970 /* Make an = ANY node */
8971 SubLink *n = (SubLink *) $4;
8972 n->subLinkType = ANY_SUBLINK;
8974 n->operName = list_make1(makeString("="));
8976 /* Stick a NOT on top */
8977 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
8981 /* generate scalar NOT IN expression */
8982 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
8985 | a_expr subquery_Op sub_type select_with_parens %prec Op
8987 SubLink *n = makeNode(SubLink);
8988 n->subLinkType = $3;
8995 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
8997 if ($3 == ANY_SUBLINK)
8998 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
9000 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
9002 | UNIQUE select_with_parens
9004 /* Not sure how to get rid of the parentheses
9005 * but there are lots of shift/reduce errors without them.
9007 * Should be able to implement this by plopping the entire
9008 * select into a node, then transforming the target expressions
9009 * from whatever they are into count(*), and testing the
9010 * entire result equal to one.
9011 * But, will probably implement a separate node in the executor.
9014 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9015 errmsg("UNIQUE predicate is not yet implemented"),
9016 parser_errposition(@1)));
9018 | a_expr IS DOCUMENT_P %prec IS
9020 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9021 list_make1($1), @2);
9023 | a_expr IS NOT DOCUMENT_P %prec IS
9025 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9026 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9027 list_make1($1), @2),
9033 * Restricted expressions
9035 * b_expr is a subset of the complete expression syntax defined by a_expr.
9037 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
9038 * cause trouble in the places where b_expr is used. For simplicity, we
9039 * just eliminate all the boolean-keyword-operator productions from b_expr.
9043 | b_expr TYPECAST Typename
9044 { $$ = makeTypeCast($1, $3, @2); }
9045 | '+' b_expr %prec UMINUS
9046 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
9047 | '-' b_expr %prec UMINUS
9048 { $$ = doNegate($2, @1); }
9050 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
9052 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
9054 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
9056 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
9058 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
9060 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
9062 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
9064 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
9066 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
9067 | b_expr qual_Op b_expr %prec Op
9068 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
9069 | qual_Op b_expr %prec Op
9070 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
9071 | b_expr qual_Op %prec POSTFIXOP
9072 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
9073 | b_expr IS DISTINCT FROM b_expr %prec IS
9075 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
9077 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
9079 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
9080 NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
9082 | b_expr IS OF '(' type_list ')' %prec IS
9084 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
9086 | b_expr IS NOT OF '(' type_list ')' %prec IS
9088 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
9090 | b_expr IS DOCUMENT_P %prec IS
9092 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9093 list_make1($1), @2);
9095 | b_expr IS NOT DOCUMENT_P %prec IS
9097 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9098 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9099 list_make1($1), @2),
9105 * Productions that can be used in both a_expr and b_expr.
9107 * Note: productions that refer recursively to a_expr or b_expr mostly
9108 * cannot appear here. However, it's OK to refer to a_exprs that occur
9109 * inside parentheses, such as function arguments; that cannot introduce
9110 * ambiguity to the b_expr syntax.
9112 c_expr: columnref { $$ = $1; }
9113 | AexprConst { $$ = $1; }
9114 | PARAM opt_indirection
9116 ParamRef *p = makeNode(ParamRef);
9121 A_Indirection *n = makeNode(A_Indirection);
9122 n->arg = (Node *) p;
9123 n->indirection = check_indirection($2, yyscanner);
9129 | '(' a_expr ')' opt_indirection
9133 A_Indirection *n = makeNode(A_Indirection);
9135 n->indirection = check_indirection($4, yyscanner);
9145 | select_with_parens %prec UMINUS
9147 SubLink *n = makeNode(SubLink);
9148 n->subLinkType = EXPR_SUBLINK;
9155 | EXISTS select_with_parens
9157 SubLink *n = makeNode(SubLink);
9158 n->subLinkType = EXISTS_SUBLINK;
9165 | ARRAY select_with_parens
9167 SubLink *n = makeNode(SubLink);
9168 n->subLinkType = ARRAY_SUBLINK;
9177 A_ArrayExpr *n = (A_ArrayExpr *) $2;
9178 Assert(IsA(n, A_ArrayExpr));
9179 /* point outermost A_ArrayExpr to the ARRAY keyword */
9185 RowExpr *r = makeNode(RowExpr);
9187 r->row_typeid = InvalidOid; /* not analyzed yet */
9194 * func_expr is split out from c_expr just so that we have a classification
9195 * for "everything that is a function call or looks like one". This isn't
9196 * very important, but it saves us having to document which variants are
9197 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
9198 * (Note that many of the special SQL functions wouldn't actually make any
9199 * sense as functional index entries, but we ignore that consideration here.)
9201 func_expr: func_name '(' ')' over_clause
9203 FuncCall *n = makeNode(FuncCall);
9206 n->agg_star = FALSE;
9207 n->agg_distinct = FALSE;
9208 n->func_variadic = FALSE;
9213 | func_name '(' func_arg_list ')' over_clause
9215 FuncCall *n = makeNode(FuncCall);
9218 n->agg_star = FALSE;
9219 n->agg_distinct = FALSE;
9220 n->func_variadic = FALSE;
9225 | func_name '(' VARIADIC func_arg_expr ')' over_clause
9227 FuncCall *n = makeNode(FuncCall);
9229 n->args = list_make1($4);
9230 n->agg_star = FALSE;
9231 n->agg_distinct = FALSE;
9232 n->func_variadic = TRUE;
9237 | func_name '(' func_arg_list ',' VARIADIC func_arg_expr ')' over_clause
9239 FuncCall *n = makeNode(FuncCall);
9241 n->args = lappend($3, $6);
9242 n->agg_star = FALSE;
9243 n->agg_distinct = FALSE;
9244 n->func_variadic = TRUE;
9249 | func_name '(' ALL func_arg_list ')' over_clause
9251 FuncCall *n = makeNode(FuncCall);
9254 n->agg_star = FALSE;
9255 n->agg_distinct = FALSE;
9256 /* Ideally we'd mark the FuncCall node to indicate
9257 * "must be an aggregate", but there's no provision
9258 * for that in FuncCall at the moment.
9260 n->func_variadic = FALSE;
9265 | func_name '(' DISTINCT func_arg_list ')' over_clause
9267 FuncCall *n = makeNode(FuncCall);
9270 n->agg_star = FALSE;
9271 n->agg_distinct = TRUE;
9272 n->func_variadic = FALSE;
9277 | func_name '(' '*' ')' over_clause
9280 * We consider AGGREGATE(*) to invoke a parameterless
9281 * aggregate. This does the right thing for COUNT(*),
9282 * and there are no other aggregates in SQL92 that accept
9285 * The FuncCall node is also marked agg_star = true,
9286 * so that later processing can detect what the argument
9289 FuncCall *n = makeNode(FuncCall);
9293 n->agg_distinct = FALSE;
9294 n->func_variadic = FALSE;
9302 * Translate as "'now'::text::date".
9304 * We cannot use "'now'::date" because coerce_type() will
9305 * immediately reduce that to a constant representing
9306 * today's date. We need to delay the conversion until
9307 * runtime, else the wrong things will happen when
9308 * CURRENT_DATE is used in a column default value or rule.
9310 * This could be simplified if we had a way to generate
9311 * an expression tree representing runtime application
9312 * of type-input conversion functions. (As of PG 7.3
9313 * that is actually possible, but not clear that we want
9317 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9318 $$ = makeTypeCast(n, SystemTypeName("date"), -1);
9323 * Translate as "'now'::text::timetz".
9324 * See comments for CURRENT_DATE.
9327 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9328 $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
9330 | CURRENT_TIME '(' Iconst ')'
9333 * Translate as "'now'::text::timetz(n)".
9334 * See comments for CURRENT_DATE.
9338 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9339 d = SystemTypeName("timetz");
9340 d->typmods = list_make1(makeIntConst($3, @3));
9341 $$ = makeTypeCast(n, d, -1);
9346 * Translate as "now()", since we have a function that
9347 * does exactly what is needed.
9349 FuncCall *n = makeNode(FuncCall);
9350 n->funcname = SystemFuncName("now");
9352 n->agg_star = FALSE;
9353 n->agg_distinct = FALSE;
9354 n->func_variadic = FALSE;
9359 | CURRENT_TIMESTAMP '(' Iconst ')'
9362 * Translate as "'now'::text::timestamptz(n)".
9363 * See comments for CURRENT_DATE.
9367 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9368 d = SystemTypeName("timestamptz");
9369 d->typmods = list_make1(makeIntConst($3, @3));
9370 $$ = makeTypeCast(n, d, -1);
9375 * Translate as "'now'::text::time".
9376 * See comments for CURRENT_DATE.
9379 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9380 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
9382 | LOCALTIME '(' Iconst ')'
9385 * Translate as "'now'::text::time(n)".
9386 * See comments for CURRENT_DATE.
9390 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9391 d = SystemTypeName("time");
9392 d->typmods = list_make1(makeIntConst($3, @3));
9393 $$ = makeTypeCast((Node *)n, d, -1);
9398 * Translate as "'now'::text::timestamp".
9399 * See comments for CURRENT_DATE.
9402 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9403 $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
9405 | LOCALTIMESTAMP '(' Iconst ')'
9408 * Translate as "'now'::text::timestamp(n)".
9409 * See comments for CURRENT_DATE.
9413 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9414 d = SystemTypeName("timestamp");
9415 d->typmods = list_make1(makeIntConst($3, @3));
9416 $$ = makeTypeCast(n, d, -1);
9420 FuncCall *n = makeNode(FuncCall);
9421 n->funcname = SystemFuncName("current_user");
9423 n->agg_star = FALSE;
9424 n->agg_distinct = FALSE;
9425 n->func_variadic = FALSE;
9432 FuncCall *n = makeNode(FuncCall);
9433 n->funcname = SystemFuncName("current_user");
9435 n->agg_star = FALSE;
9436 n->agg_distinct = FALSE;
9437 n->func_variadic = FALSE;
9444 FuncCall *n = makeNode(FuncCall);
9445 n->funcname = SystemFuncName("session_user");
9447 n->agg_star = FALSE;
9448 n->agg_distinct = FALSE;
9449 n->func_variadic = FALSE;
9456 FuncCall *n = makeNode(FuncCall);
9457 n->funcname = SystemFuncName("current_user");
9459 n->agg_star = FALSE;
9460 n->agg_distinct = FALSE;
9461 n->func_variadic = FALSE;
9468 FuncCall *n = makeNode(FuncCall);
9469 n->funcname = SystemFuncName("current_database");
9471 n->agg_star = FALSE;
9472 n->agg_distinct = FALSE;
9473 n->func_variadic = FALSE;
9480 FuncCall *n = makeNode(FuncCall);
9481 n->funcname = SystemFuncName("current_schema");
9483 n->agg_star = FALSE;
9484 n->agg_distinct = FALSE;
9485 n->func_variadic = FALSE;
9490 | CAST '(' a_expr AS Typename ')'
9491 { $$ = makeTypeCast($3, $5, @1); }
9492 | EXTRACT '(' extract_list ')'
9494 FuncCall *n = makeNode(FuncCall);
9495 n->funcname = SystemFuncName("date_part");
9497 n->agg_star = FALSE;
9498 n->agg_distinct = FALSE;
9499 n->func_variadic = FALSE;
9504 | OVERLAY '(' overlay_list ')'
9506 /* overlay(A PLACING B FROM C FOR D) is converted to
9507 * substring(A, 1, C-1) || B || substring(A, C+1, C+D)
9508 * overlay(A PLACING B FROM C) is converted to
9509 * substring(A, 1, C-1) || B || substring(A, C+1, C+char_length(B))
9511 FuncCall *n = makeNode(FuncCall);
9512 n->funcname = SystemFuncName("overlay");
9514 n->agg_star = FALSE;
9515 n->agg_distinct = FALSE;
9516 n->func_variadic = FALSE;
9521 | POSITION '(' position_list ')'
9523 /* position(A in B) is converted to position(B, A) */
9524 FuncCall *n = makeNode(FuncCall);
9525 n->funcname = SystemFuncName("position");
9527 n->agg_star = FALSE;
9528 n->agg_distinct = FALSE;
9529 n->func_variadic = FALSE;
9534 | SUBSTRING '(' substr_list ')'
9536 /* substring(A from B for C) is converted to
9537 * substring(A, B, C) - thomas 2000-11-28
9539 FuncCall *n = makeNode(FuncCall);
9540 n->funcname = SystemFuncName("substring");
9542 n->agg_star = FALSE;
9543 n->agg_distinct = FALSE;
9544 n->func_variadic = FALSE;
9549 | TREAT '(' a_expr AS Typename ')'
9551 /* TREAT(expr AS target) converts expr of a particular type to target,
9552 * which is defined to be a subtype of the original expression.
9553 * In SQL99, this is intended for use with structured UDTs,
9554 * but let's make this a generally useful form allowing stronger
9555 * coercions than are handled by implicit casting.
9557 FuncCall *n = makeNode(FuncCall);
9558 /* Convert SystemTypeName() to SystemFuncName() even though
9559 * at the moment they result in the same thing.
9561 n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
9562 n->args = list_make1($3);
9563 n->agg_star = FALSE;
9564 n->agg_distinct = FALSE;
9565 n->func_variadic = FALSE;
9570 | TRIM '(' BOTH trim_list ')'
9572 /* various trim expressions are defined in SQL92
9573 * - thomas 1997-07-19
9575 FuncCall *n = makeNode(FuncCall);
9576 n->funcname = SystemFuncName("btrim");
9578 n->agg_star = FALSE;
9579 n->agg_distinct = FALSE;
9580 n->func_variadic = FALSE;
9585 | TRIM '(' LEADING trim_list ')'
9587 FuncCall *n = makeNode(FuncCall);
9588 n->funcname = SystemFuncName("ltrim");
9590 n->agg_star = FALSE;
9591 n->agg_distinct = FALSE;
9592 n->func_variadic = FALSE;
9597 | TRIM '(' TRAILING trim_list ')'
9599 FuncCall *n = makeNode(FuncCall);
9600 n->funcname = SystemFuncName("rtrim");
9602 n->agg_star = FALSE;
9603 n->agg_distinct = FALSE;
9604 n->func_variadic = FALSE;
9609 | TRIM '(' trim_list ')'
9611 FuncCall *n = makeNode(FuncCall);
9612 n->funcname = SystemFuncName("btrim");
9614 n->agg_star = FALSE;
9615 n->agg_distinct = FALSE;
9616 n->func_variadic = FALSE;
9621 | NULLIF '(' a_expr ',' a_expr ')'
9623 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
9625 | COALESCE '(' expr_list ')'
9627 CoalesceExpr *c = makeNode(CoalesceExpr);
9632 | GREATEST '(' expr_list ')'
9634 MinMaxExpr *v = makeNode(MinMaxExpr);
9636 v->op = IS_GREATEST;
9640 | LEAST '(' expr_list ')'
9642 MinMaxExpr *v = makeNode(MinMaxExpr);
9648 | XMLCONCAT '(' expr_list ')'
9650 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
9652 | XMLELEMENT '(' NAME_P ColLabel ')'
9654 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
9656 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
9658 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
9660 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
9662 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
9664 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
9666 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
9668 | XMLFOREST '(' xml_attribute_list ')'
9670 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
9672 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
9674 XmlExpr *x = (XmlExpr *)
9675 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
9676 list_make2($4, makeBoolAConst($5, -1)),
9681 | XMLPI '(' NAME_P ColLabel ')'
9683 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
9685 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
9687 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
9689 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
9691 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
9692 list_make3($3, $5, $6), @1);
9694 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
9696 XmlSerialize *n = makeNode(XmlSerialize);
9708 xml_root_version: VERSION_P a_expr
9710 | VERSION_P NO VALUE_P
9711 { $$ = makeNullAConst(-1); }
9714 opt_xml_root_standalone: ',' STANDALONE_P YES_P
9715 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
9716 | ',' STANDALONE_P NO
9717 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
9718 | ',' STANDALONE_P NO VALUE_P
9719 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
9721 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
9724 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
9727 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
9728 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
9731 xml_attribute_el: a_expr AS ColLabel
9733 $$ = makeNode(ResTarget);
9735 $$->indirection = NIL;
9736 $$->val = (Node *) $1;
9741 $$ = makeNode(ResTarget);
9743 $$->indirection = NIL;
9744 $$->val = (Node *) $1;
9749 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
9750 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
9753 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
9754 | STRIP_P WHITESPACE_P { $$ = FALSE; }
9755 | /*EMPTY*/ { $$ = FALSE; }
9759 * Window Definitions
9762 WINDOW window_definition_list { $$ = $2; }
9763 | /*EMPTY*/ { $$ = NIL; }
9766 window_definition_list:
9767 window_definition { $$ = list_make1($1); }
9768 | window_definition_list ',' window_definition
9769 { $$ = lappend($1, $3); }
9773 ColId AS window_specification
9781 over_clause: OVER window_specification
9785 WindowDef *n = makeNode(WindowDef);
9788 n->partitionClause = NIL;
9789 n->orderClause = NIL;
9790 n->frameOptions = FRAMEOPTION_DEFAULTS;
9798 window_specification: '(' opt_existing_window_name opt_partition_clause
9799 opt_sort_clause opt_frame_clause ')'
9801 WindowDef *n = makeNode(WindowDef);
9804 n->partitionClause = $3;
9805 n->orderClause = $4;
9806 n->frameOptions = $5;
9813 * If we see PARTITION, RANGE, or ROWS as the first token after the '('
9814 * of a window_specification, we want the assumption to be that there is
9815 * no existing_window_name; but those keywords are unreserved and so could
9816 * be ColIds. We fix this by making them have the same precedence as IDENT
9817 * and giving the empty production here a slightly higher precedence, so
9818 * that the shift/reduce conflict is resolved in favor of reducing the rule.
9819 * These keywords are thus precluded from being an existing_window_name but
9820 * are not reserved for any other purpose.
9822 opt_existing_window_name: ColId { $$ = $1; }
9823 | /*EMPTY*/ %prec Op { $$ = NULL; }
9826 opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
9827 | /*EMPTY*/ { $$ = NIL; }
9831 * This is only a subset of the full SQL:2008 frame_clause grammar.
9832 * We don't support <expression> PRECEDING, <expression> FOLLOWING,
9833 * nor <window frame exclusion> yet.
9838 $$ = FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE | $2;
9842 $$ = FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS | $2;
9845 { $$ = FRAMEOPTION_DEFAULTS; }
9848 frame_extent: frame_bound
9850 /* reject invalid cases */
9851 if ($1 & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
9853 (errcode(ERRCODE_WINDOWING_ERROR),
9854 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
9855 parser_errposition(@1)));
9856 if ($1 & FRAMEOPTION_START_CURRENT_ROW)
9858 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9859 errmsg("frame start at CURRENT ROW is not implemented"),
9860 parser_errposition(@1)));
9861 $$ = $1 | FRAMEOPTION_END_CURRENT_ROW;
9863 | BETWEEN frame_bound AND frame_bound
9865 /* reject invalid cases */
9866 if ($2 & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
9868 (errcode(ERRCODE_WINDOWING_ERROR),
9869 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
9870 parser_errposition(@2)));
9871 if ($2 & FRAMEOPTION_START_CURRENT_ROW)
9873 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9874 errmsg("frame start at CURRENT ROW is not implemented"),
9875 parser_errposition(@2)));
9876 if ($4 & FRAMEOPTION_START_UNBOUNDED_PRECEDING)
9878 (errcode(ERRCODE_WINDOWING_ERROR),
9879 errmsg("frame end cannot be UNBOUNDED PRECEDING"),
9880 parser_errposition(@4)));
9881 /* shift converts START_ options to END_ options */
9882 $$ = FRAMEOPTION_BETWEEN | $2 | ($4 << 1);
9887 * This is used for both frame start and frame end, with output set up on
9888 * the assumption it's frame start; the frame_extent productions must reject
9894 $$ = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
9896 | UNBOUNDED FOLLOWING
9898 $$ = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
9902 $$ = FRAMEOPTION_START_CURRENT_ROW;
9908 * Supporting nonterminals for expressions.
9911 /* Explicit row production.
9913 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
9914 * without conflicting with the parenthesized a_expr production. Without the
9915 * ROW keyword, there must be more than one a_expr inside the parens.
9917 row: ROW '(' expr_list ')' { $$ = $3; }
9918 | ROW '(' ')' { $$ = NIL; }
9919 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
9922 sub_type: ANY { $$ = ANY_SUBLINK; }
9923 | SOME { $$ = ANY_SUBLINK; }
9924 | ALL { $$ = ALL_SUBLINK; }
9927 all_Op: Op { $$ = $1; }
9928 | MathOp { $$ = $1; }
9931 MathOp: '+' { $$ = "+"; }
9943 { $$ = list_make1(makeString($1)); }
9944 | OPERATOR '(' any_operator ')'
9950 { $$ = list_make1(makeString($1)); }
9951 | OPERATOR '(' any_operator ')'
9957 { $$ = list_make1(makeString($1)); }
9958 | OPERATOR '(' any_operator ')'
9961 { $$ = list_make1(makeString("~~")); }
9963 { $$ = list_make1(makeString("!~~")); }
9965 { $$ = list_make1(makeString("~~*")); }
9967 { $$ = list_make1(makeString("!~~*")); }
9968 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
9969 * the regular expression is preprocessed by a function (similar_escape),
9970 * and the ~ operator for posix regular expressions is used.
9971 * x SIMILAR TO y -> x ~ similar_escape(y)
9972 * this transformation is made on the fly by the parser upwards.
9973 * however the SubLink structure which handles any/some/all stuff
9974 * is not ready for such a thing.
9980 $$ = list_make1($1);
9982 | expr_list ',' a_expr
9984 $$ = lappend($1, $3);
9988 /* function arguments can have names */
9989 func_arg_list: func_arg_expr
9991 $$ = list_make1($1);
9993 | func_arg_list ',' func_arg_expr
9995 $$ = lappend($1, $3);
9999 func_arg_expr: a_expr
10003 | a_expr AS param_name
10005 NamedArgExpr *na = makeNode(NamedArgExpr);
10006 na->arg = (Expr *) $1;
10008 na->argnumber = -1; /* until determined */
10014 type_list: Typename { $$ = list_make1($1); }
10015 | type_list ',' Typename { $$ = lappend($1, $3); }
10018 array_expr: '[' expr_list ']'
10020 $$ = makeAArrayExpr($2, @1);
10022 | '[' array_expr_list ']'
10024 $$ = makeAArrayExpr($2, @1);
10028 $$ = makeAArrayExpr(NIL, @1);
10032 array_expr_list: array_expr { $$ = list_make1($1); }
10033 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
10038 extract_arg FROM a_expr
10040 $$ = list_make2(makeStringConst($1, @1), $3);
10042 | /*EMPTY*/ { $$ = NIL; }
10045 /* Allow delimited string Sconst in extract_arg as an SQL extension.
10046 * - thomas 2001-04-12
10050 | YEAR_P { $$ = "year"; }
10051 | MONTH_P { $$ = "month"; }
10052 | DAY_P { $$ = "day"; }
10053 | HOUR_P { $$ = "hour"; }
10054 | MINUTE_P { $$ = "minute"; }
10055 | SECOND_P { $$ = "second"; }
10056 | Sconst { $$ = $1; }
10059 /* OVERLAY() arguments
10060 * SQL99 defines the OVERLAY() function:
10061 * o overlay(text placing text from int for int)
10062 * o overlay(text placing text from int)
10065 a_expr overlay_placing substr_from substr_for
10067 $$ = list_make4($1, $2, $3, $4);
10069 | a_expr overlay_placing substr_from
10071 $$ = list_make3($1, $2, $3);
10080 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
10083 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
10084 | /*EMPTY*/ { $$ = NIL; }
10087 /* SUBSTRING() arguments
10088 * SQL9x defines a specific syntax for arguments to SUBSTRING():
10089 * o substring(text from int for int)
10090 * o substring(text from int) get entire string from starting point "int"
10091 * o substring(text for int) get first "int" characters of string
10092 * o substring(text from pattern) get entire string matching pattern
10093 * o substring(text from pattern for escape) same with specified escape char
10094 * We also want to support generic substring functions which accept
10095 * the usual generic list of arguments. So we will accept both styles
10096 * here, and convert the SQL9x style to the generic list for further
10097 * processing. - thomas 2000-11-28
10100 a_expr substr_from substr_for
10102 $$ = list_make3($1, $2, $3);
10104 | a_expr substr_for substr_from
10106 /* not legal per SQL99, but might as well allow it */
10107 $$ = list_make3($1, $3, $2);
10109 | a_expr substr_from
10111 $$ = list_make2($1, $2);
10113 | a_expr substr_for
10116 * Since there are no cases where this syntax allows
10117 * a textual FOR value, we forcibly cast the argument
10118 * to int4. The possible matches in pg_proc are
10119 * substring(text,int4) and substring(text,text),
10120 * and we don't want the parser to choose the latter,
10121 * which it is likely to do if the second argument
10122 * is unknown or doesn't have an implicit cast to int4.
10124 $$ = list_make3($1, makeIntConst(1, -1),
10126 SystemTypeName("int4"), -1));
10137 FROM a_expr { $$ = $2; }
10140 substr_for: FOR a_expr { $$ = $2; }
10143 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
10144 | FROM expr_list { $$ = $2; }
10145 | expr_list { $$ = $1; }
10148 in_expr: select_with_parens
10150 SubLink *n = makeNode(SubLink);
10152 /* other fields will be filled later */
10155 | '(' expr_list ')' { $$ = (Node *)$2; }
10159 * Define SQL92-style case clause.
10160 * - Full specification
10161 * CASE WHEN a = b THEN c ... ELSE d END
10162 * - Implicit argument
10163 * CASE a WHEN b THEN c ... ELSE d END
10165 case_expr: CASE case_arg when_clause_list case_default END_P
10167 CaseExpr *c = makeNode(CaseExpr);
10168 c->casetype = InvalidOid; /* not analyzed yet */
10169 c->arg = (Expr *) $2;
10171 c->defresult = (Expr *) $4;
10178 /* There must be at least one */
10179 when_clause { $$ = list_make1($1); }
10180 | when_clause_list when_clause { $$ = lappend($1, $2); }
10184 WHEN a_expr THEN a_expr
10186 CaseWhen *w = makeNode(CaseWhen);
10187 w->expr = (Expr *) $2;
10188 w->result = (Expr *) $4;
10195 ELSE a_expr { $$ = $2; }
10196 | /*EMPTY*/ { $$ = NULL; }
10199 case_arg: a_expr { $$ = $1; }
10200 | /*EMPTY*/ { $$ = NULL; }
10205 $$ = makeColumnRef($1, NIL, @1, yyscanner);
10207 | ColId indirection
10209 $$ = makeColumnRef($1, $2, @1, yyscanner);
10216 $$ = (Node *) makeString($2);
10220 $$ = (Node *) makeNode(A_Star);
10224 A_Indices *ai = makeNode(A_Indices);
10229 | '[' a_expr ':' a_expr ']'
10231 A_Indices *ai = makeNode(A_Indices);
10239 indirection_el { $$ = list_make1($1); }
10240 | indirection indirection_el { $$ = lappend($1, $2); }
10244 /*EMPTY*/ { $$ = NIL; }
10245 | opt_indirection indirection_el { $$ = lappend($1, $2); }
10248 opt_asymmetric: ASYMMETRIC
10253 * The SQL spec defines "contextually typed value expressions" and
10254 * "contextually typed row value constructors", which for our purposes
10255 * are the same as "a_expr" and "row" except that DEFAULT can appear at
10260 a_expr { $$ = (Node *) $1; }
10263 SetToDefault *n = makeNode(SetToDefault);
10270 ctext_expr { $$ = list_make1($1); }
10271 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
10275 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
10276 * making VALUES a fully reserved word, which will probably break more apps
10277 * than allowing the noise-word is worth.
10279 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
10283 /*****************************************************************************
10285 * target list for SELECT
10287 *****************************************************************************/
10290 target_el { $$ = list_make1($1); }
10291 | target_list ',' target_el { $$ = lappend($1, $3); }
10294 target_el: a_expr AS ColLabel
10296 $$ = makeNode(ResTarget);
10298 $$->indirection = NIL;
10299 $$->val = (Node *)$1;
10303 * We support omitting AS only for column labels that aren't
10304 * any known keyword. There is an ambiguity against postfix
10305 * operators: is "a ! b" an infix expression, or a postfix
10306 * expression and a column label? We prefer to resolve this
10307 * as an infix expression, which we accomplish by assigning
10308 * IDENT a precedence higher than POSTFIXOP.
10312 $$ = makeNode(ResTarget);
10314 $$->indirection = NIL;
10315 $$->val = (Node *)$1;
10320 $$ = makeNode(ResTarget);
10322 $$->indirection = NIL;
10323 $$->val = (Node *)$1;
10328 ColumnRef *n = makeNode(ColumnRef);
10329 n->fields = list_make1(makeNode(A_Star));
10332 $$ = makeNode(ResTarget);
10334 $$->indirection = NIL;
10335 $$->val = (Node *)n;
10341 /*****************************************************************************
10343 * Names and constants
10345 *****************************************************************************/
10347 qualified_name_list:
10348 qualified_name { $$ = list_make1($1); }
10349 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
10353 * The production for a qualified relation name has to exactly match the
10354 * production for a qualified func_name, because in a FROM clause we cannot
10355 * tell which we are parsing until we see what comes after it ('(' for a
10356 * func_name, something else for a relation). Therefore we allow 'indirection'
10357 * which may contain subscripts, and reject that case in the C code.
10362 $$ = makeNode(RangeVar);
10363 $$->catalogname = NULL;
10364 $$->schemaname = NULL;
10368 | ColId indirection
10370 check_qualified_name($2, yyscanner);
10371 $$ = makeNode(RangeVar);
10372 switch (list_length($2))
10375 $$->catalogname = NULL;
10376 $$->schemaname = $1;
10377 $$->relname = strVal(linitial($2));
10380 $$->catalogname = $1;
10381 $$->schemaname = strVal(linitial($2));
10382 $$->relname = strVal(lsecond($2));
10386 (errcode(ERRCODE_SYNTAX_ERROR),
10387 errmsg("improper qualified name (too many dotted names): %s",
10388 NameListToString(lcons(makeString($1), $2))),
10389 parser_errposition(@1)));
10397 { $$ = list_make1(makeString($1)); }
10398 | name_list ',' name
10399 { $$ = lappend($1, makeString($3)); }
10403 name: ColId { $$ = $1; };
10406 ColId { $$ = $1; };
10409 ColId { $$ = $1; };
10411 attr_name: ColLabel { $$ = $1; };
10413 index_name: ColId { $$ = $1; };
10415 file_name: Sconst { $$ = $1; };
10418 * The production for a qualified func_name has to exactly match the
10419 * production for a qualified columnref, because we cannot tell which we
10420 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
10421 * anything else for a columnref). Therefore we allow 'indirection' which
10422 * may contain subscripts, and reject that case in the C code. (If we
10423 * ever implement SQL99-like methods, such syntax may actually become legal!)
10425 func_name: type_function_name
10426 { $$ = list_make1(makeString($1)); }
10427 | ColId indirection
10429 $$ = check_func_name(lcons(makeString($1), $2),
10440 $$ = makeIntConst($1, @1);
10444 $$ = makeFloatConst($1, @1);
10448 $$ = makeStringConst($1, @1);
10452 $$ = makeBitStringConst($1, @1);
10456 /* This is a bit constant per SQL99:
10457 * Without Feature F511, "BIT data type",
10458 * a <general literal> shall not be a
10459 * <bit string literal> or a <hex string literal>.
10461 $$ = makeBitStringConst($1, @1);
10465 /* generic type 'literal' syntax */
10466 TypeName *t = makeTypeNameFromNameList($1);
10468 $$ = makeStringConstCast($2, @2, t);
10470 | func_name '(' func_arg_list ')' Sconst
10472 /* generic syntax with a type modifier */
10473 TypeName *t = makeTypeNameFromNameList($1);
10477 * We must use func_arg_list in the production to avoid
10478 * reduce/reduce conflicts, but we don't actually wish
10479 * to allow NamedArgExpr in this context.
10483 NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
10485 if (IsA(arg, NamedArgExpr))
10487 (errcode(ERRCODE_SYNTAX_ERROR),
10488 errmsg("type modifier cannot have AS name"),
10489 parser_errposition(arg->location)));
10493 $$ = makeStringConstCast($5, @5, t);
10495 | ConstTypename Sconst
10497 $$ = makeStringConstCast($2, @2, $1);
10499 | ConstInterval Sconst opt_interval
10503 $$ = makeStringConstCast($2, @2, t);
10505 | ConstInterval '(' Iconst ')' Sconst opt_interval
10510 if (list_length($6) != 1)
10512 (errcode(ERRCODE_SYNTAX_ERROR),
10513 errmsg("interval precision specified twice"),
10514 parser_errposition(@1)));
10515 t->typmods = lappend($6, makeIntConst($3, @3));
10518 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
10519 makeIntConst($3, @3));
10520 $$ = makeStringConstCast($5, @5, t);
10524 $$ = makeBoolAConst(TRUE, @1);
10528 $$ = makeBoolAConst(FALSE, @1);
10532 $$ = makeNullAConst(@1);
10536 Iconst: ICONST { $$ = $1; };
10537 Sconst: SCONST { $$ = $1; };
10538 RoleId: ColId { $$ = $1; };
10540 SignedIconst: Iconst { $$ = $1; }
10541 | '+' Iconst { $$ = + $2; }
10542 | '-' Iconst { $$ = - $2; }
10546 * Name classification hierarchy.
10548 * IDENT is the lexeme returned by the lexer for identifiers that match
10549 * no known keyword. In most cases, we can accept certain keywords as
10550 * names, not only IDENTs. We prefer to accept as many such keywords
10551 * as possible to minimize the impact of "reserved words" on programmers.
10552 * So, we divide names into several possible classes. The classification
10553 * is chosen in part to make keywords acceptable as names wherever possible.
10556 /* Column identifier --- names that can be column, table, etc names.
10558 ColId: IDENT { $$ = $1; }
10559 | unreserved_keyword { $$ = pstrdup($1); }
10560 | col_name_keyword { $$ = pstrdup($1); }
10563 /* Type/function identifier --- names that can be type or function names.
10565 type_function_name: IDENT { $$ = $1; }
10566 | unreserved_keyword { $$ = pstrdup($1); }
10567 | type_func_name_keyword { $$ = pstrdup($1); }
10570 /* Column label --- allowed labels in "AS" clauses.
10571 * This presently includes *all* Postgres keywords.
10573 ColLabel: IDENT { $$ = $1; }
10574 | unreserved_keyword { $$ = pstrdup($1); }
10575 | col_name_keyword { $$ = pstrdup($1); }
10576 | type_func_name_keyword { $$ = pstrdup($1); }
10577 | reserved_keyword { $$ = pstrdup($1); }
10582 * Keyword category lists. Generally, every keyword present in
10583 * the Postgres grammar should appear in exactly one of these lists.
10585 * Put a new keyword into the first list that it can go into without causing
10586 * shift or reduce conflicts. The earlier lists define "less reserved"
10587 * categories of keywords.
10589 * Make sure that each keyword's category in keywords.c matches where
10590 * it is listed here. (Someday we may be able to generate these lists and
10591 * keywords.c's table from a common master list.)
10594 /* "Unreserved" keywords --- available for use as any kind of name.
10596 unreserved_keyword:
10850 /* Column identifier --- keywords that can be column, table, etc names.
10852 * Many of these keywords will in fact be recognized as type or function
10853 * names too; but they have special productions for the purpose, and so
10854 * can't be treated as "generic" type or function names.
10856 * The type names appearing here are not usable as function names
10857 * because they can be followed by '(' in typename productions, which
10858 * looks too much like a function call for an LR(1) parser.
10908 /* Type/function identifier --- keywords that can be type or function names.
10910 * Most of these are keywords that are used as operators in expressions;
10911 * in general such keywords can't be column names because they would be
10912 * ambiguous with variables, but they are unambiguous as function identifiers.
10914 * Do not include POSITION, SUBSTRING, etc here since they have explicit
10915 * productions in a_expr to support the goofy SQL9x argument syntax.
10916 * - thomas 2000-11-28
10918 type_func_name_keyword:
10943 /* Reserved keyword --- these keywords are usable only as a ColLabel.
10945 * Keywords appear here if they could not be distinguished from variable,
10946 * type, or function names in some contexts. Don't put things here unless
10971 | CURRENT_TIMESTAMP
11032 * The signature of this function is required by bison. However, we
11033 * ignore the passed yylloc and instead use the last token position
11034 * available from the scanner.
11037 base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
11039 parser_yyerror(msg);
11043 makeColumnRef(char *colname, List *indirection,
11044 int location, core_yyscan_t yyscanner)
11047 * Generate a ColumnRef node, with an A_Indirection node added if there
11048 * is any subscripting in the specified indirection list. However,
11049 * any field selection at the start of the indirection list must be
11050 * transposed into the "fields" part of the ColumnRef node.
11052 ColumnRef *c = makeNode(ColumnRef);
11056 c->location = location;
11057 foreach(l, indirection)
11059 if (IsA(lfirst(l), A_Indices))
11061 A_Indirection *i = makeNode(A_Indirection);
11065 /* easy case - all indirection goes to A_Indirection */
11066 c->fields = list_make1(makeString(colname));
11067 i->indirection = check_indirection(indirection, yyscanner);
11071 /* got to split the list in two */
11072 i->indirection = check_indirection(list_copy_tail(indirection,
11075 indirection = list_truncate(indirection, nfields);
11076 c->fields = lcons(makeString(colname), indirection);
11078 i->arg = (Node *) c;
11081 else if (IsA(lfirst(l), A_Star))
11083 /* We only allow '*' at the end of a ColumnRef */
11084 if (lnext(l) != NULL)
11085 parser_yyerror("improper use of \"*\"");
11089 /* No subscripting, so all indirection gets added to field list */
11090 c->fields = lcons(makeString(colname), indirection);
11095 makeTypeCast(Node *arg, TypeName *typename, int location)
11097 TypeCast *n = makeNode(TypeCast);
11099 n->typeName = typename;
11100 n->location = location;
11105 makeStringConst(char *str, int location)
11107 A_Const *n = makeNode(A_Const);
11109 n->val.type = T_String;
11110 n->val.val.str = str;
11111 n->location = location;
11117 makeStringConstCast(char *str, int location, TypeName *typename)
11119 Node *s = makeStringConst(str, location);
11121 return makeTypeCast(s, typename, -1);
11125 makeIntConst(int val, int location)
11127 A_Const *n = makeNode(A_Const);
11129 n->val.type = T_Integer;
11130 n->val.val.ival = val;
11131 n->location = location;
11137 makeFloatConst(char *str, int location)
11139 A_Const *n = makeNode(A_Const);
11141 n->val.type = T_Float;
11142 n->val.val.str = str;
11143 n->location = location;
11149 makeBitStringConst(char *str, int location)
11151 A_Const *n = makeNode(A_Const);
11153 n->val.type = T_BitString;
11154 n->val.val.str = str;
11155 n->location = location;
11161 makeNullAConst(int location)
11163 A_Const *n = makeNode(A_Const);
11165 n->val.type = T_Null;
11166 n->location = location;
11172 makeAConst(Value *v, int location)
11179 n = makeFloatConst(v->val.str, location);
11183 n = makeIntConst(v->val.ival, location);
11188 n = makeStringConst(v->val.str, location);
11195 /* makeBoolAConst()
11196 * Create an A_Const string node and put it inside a boolean cast.
11199 makeBoolAConst(bool state, int location)
11201 A_Const *n = makeNode(A_Const);
11203 n->val.type = T_String;
11204 n->val.val.str = (state ? "t" : "f");
11205 n->location = location;
11207 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
11211 * Create and populate a FuncCall node to support the OVERLAPS operator.
11214 makeOverlaps(List *largs, List *rargs, int location, core_yyscan_t yyscanner)
11216 FuncCall *n = makeNode(FuncCall);
11218 n->funcname = SystemFuncName("overlaps");
11219 if (list_length(largs) == 1)
11220 largs = lappend(largs, largs);
11221 else if (list_length(largs) != 2)
11223 (errcode(ERRCODE_SYNTAX_ERROR),
11224 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
11225 parser_errposition(location)));
11226 if (list_length(rargs) == 1)
11227 rargs = lappend(rargs, rargs);
11228 else if (list_length(rargs) != 2)
11230 (errcode(ERRCODE_SYNTAX_ERROR),
11231 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
11232 parser_errposition(location)));
11233 n->args = list_concat(largs, rargs);
11234 n->agg_star = FALSE;
11235 n->agg_distinct = FALSE;
11236 n->func_variadic = FALSE;
11238 n->location = location;
11242 /* check_qualified_name --- check the result of qualified_name production
11244 * It's easiest to let the grammar production for qualified_name allow
11245 * subscripts and '*', which we then must reject here.
11248 check_qualified_name(List *names, core_yyscan_t yyscanner)
11254 if (!IsA(lfirst(i), String))
11255 parser_yyerror("syntax error");
11259 /* check_func_name --- check the result of func_name production
11261 * It's easiest to let the grammar production for func_name allow subscripts
11262 * and '*', which we then must reject here.
11265 check_func_name(List *names, core_yyscan_t yyscanner)
11271 if (!IsA(lfirst(i), String))
11272 parser_yyerror("syntax error");
11277 /* check_indirection --- check the result of indirection production
11279 * We only allow '*' at the end of the list, but it's hard to enforce that
11280 * in the grammar, so do it here.
11283 check_indirection(List *indirection, core_yyscan_t yyscanner)
11287 foreach(l, indirection)
11289 if (IsA(lfirst(l), A_Star))
11291 if (lnext(l) != NULL)
11292 parser_yyerror("improper use of \"*\"");
11295 return indirection;
11298 /* extractArgTypes()
11299 * Given a list of FunctionParameter nodes, extract a list of just the
11300 * argument types (TypeNames) for input parameters only. This is what
11301 * is needed to look up an existing function, which is what is wanted by
11302 * the productions that use this call.
11305 extractArgTypes(List *parameters)
11307 List *result = NIL;
11310 foreach(i, parameters)
11312 FunctionParameter *p = (FunctionParameter *) lfirst(i);
11314 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
11315 result = lappend(result, p->argType);
11320 /* findLeftmostSelect()
11321 * Find the leftmost component SelectStmt in a set-operation parsetree.
11323 static SelectStmt *
11324 findLeftmostSelect(SelectStmt *node)
11326 while (node && node->op != SETOP_NONE)
11328 Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
11332 /* insertSelectOptions()
11333 * Insert ORDER BY, etc into an already-constructed SelectStmt.
11335 * This routine is just to avoid duplicating code in SelectStmt productions.
11338 insertSelectOptions(SelectStmt *stmt,
11339 List *sortClause, List *lockingClause,
11340 Node *limitOffset, Node *limitCount,
11341 WithClause *withClause,
11342 core_yyscan_t yyscanner)
11344 Assert(IsA(stmt, SelectStmt));
11347 * Tests here are to reject constructs like
11348 * (SELECT foo ORDER BY bar) ORDER BY baz
11352 if (stmt->sortClause)
11354 (errcode(ERRCODE_SYNTAX_ERROR),
11355 errmsg("multiple ORDER BY clauses not allowed"),
11356 parser_errposition(exprLocation((Node *) sortClause))));
11357 stmt->sortClause = sortClause;
11359 /* We can handle multiple locking clauses, though */
11360 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
11363 if (stmt->limitOffset)
11365 (errcode(ERRCODE_SYNTAX_ERROR),
11366 errmsg("multiple OFFSET clauses not allowed"),
11367 parser_errposition(exprLocation(limitOffset))));
11368 stmt->limitOffset = limitOffset;
11372 if (stmt->limitCount)
11374 (errcode(ERRCODE_SYNTAX_ERROR),
11375 errmsg("multiple LIMIT clauses not allowed"),
11376 parser_errposition(exprLocation(limitCount))));
11377 stmt->limitCount = limitCount;
11381 if (stmt->withClause)
11383 (errcode(ERRCODE_SYNTAX_ERROR),
11384 errmsg("multiple WITH clauses not allowed"),
11385 parser_errposition(exprLocation((Node *) withClause))));
11386 stmt->withClause = withClause;
11391 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
11393 SelectStmt *n = makeNode(SelectStmt);
11397 n->larg = (SelectStmt *) larg;
11398 n->rarg = (SelectStmt *) rarg;
11402 /* SystemFuncName()
11403 * Build a properly-qualified reference to a built-in function.
11406 SystemFuncName(char *name)
11408 return list_make2(makeString("pg_catalog"), makeString(name));
11411 /* SystemTypeName()
11412 * Build a properly-qualified reference to a built-in type.
11414 * typmod is defaulted, but may be changed afterwards by caller.
11415 * Likewise for the location.
11418 SystemTypeName(char *name)
11420 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
11421 makeString(name)));
11425 * Handle negation of a numeric constant.
11427 * Formerly, we did this here because the optimizer couldn't cope with
11428 * indexquals that looked like "var = -4" --- it wants "var = const"
11429 * and a unary minus operator applied to a constant didn't qualify.
11430 * As of Postgres 7.0, that problem doesn't exist anymore because there
11431 * is a constant-subexpression simplifier in the optimizer. However,
11432 * there's still a good reason for doing this here, which is that we can
11433 * postpone committing to a particular internal representation for simple
11434 * negative constants. It's better to leave "-123.456" in string form
11435 * until we know what the desired type is.
11438 doNegate(Node *n, int location)
11440 if (IsA(n, A_Const))
11442 A_Const *con = (A_Const *)n;
11444 /* report the constant's location as that of the '-' sign */
11445 con->location = location;
11447 if (con->val.type == T_Integer)
11449 con->val.val.ival = -con->val.val.ival;
11452 if (con->val.type == T_Float)
11454 doNegateFloat(&con->val);
11459 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
11463 doNegateFloat(Value *v)
11465 char *oldval = v->val.str;
11467 Assert(IsA(v, Float));
11468 if (*oldval == '+')
11470 if (*oldval == '-')
11471 v->val.str = oldval+1; /* just strip the '-' */
11474 char *newval = (char *) palloc(strlen(oldval) + 2);
11477 strcpy(newval+1, oldval);
11478 v->val.str = newval;
11483 makeAArrayExpr(List *elements, int location)
11485 A_ArrayExpr *n = makeNode(A_ArrayExpr);
11487 n->elements = elements;
11488 n->location = location;
11493 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
11496 XmlExpr *x = makeNode(XmlExpr);
11501 * named_args is a list of ResTarget; it'll be split apart into separate
11502 * expression and name lists in transformXmlExpr().
11504 x->named_args = named_args;
11505 x->arg_names = NIL;
11507 /* xmloption, if relevant, must be filled in by caller */
11508 /* type and typmod will be filled in during parse analysis */
11509 x->location = location;
11514 * Initialize to parse one query string
11517 parser_init(base_yy_extra_type *yyext)
11519 yyext->parsetree = NIL; /* in case grammar forgets to set it */
11523 * Merge the input and output parameters of a table function.
11526 mergeTableFuncParameters(List *func_args, List *columns)
11530 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
11531 foreach(lc, func_args)
11533 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
11535 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
11537 (errcode(ERRCODE_SYNTAX_ERROR),
11538 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
11541 return list_concat(func_args, columns);
11545 * Determine return type of a TABLE function. A single result column
11546 * returns setof that column's type; otherwise return setof record.
11549 TableFuncTypeName(List *columns)
11553 if (list_length(columns) == 1)
11555 FunctionParameter *p = (FunctionParameter *) linitial(columns);
11557 result = (TypeName *) copyObject(p->argType);
11560 result = SystemTypeName("record");
11562 result->setof = true;
11568 * Must undefine this stuff before including scan.c, since it has different
11569 * definitions for these macros.