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.697 2009/12/15 17:57:47 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 <list> Iconst_list
401 %type <str> Sconst comment_text
402 %type <str> RoleId opt_granted_by opt_boolean ColId_or_Sconst
403 %type <list> var_list
404 %type <str> ColId ColLabel var_name type_function_name param_name
405 %type <node> var_value zone_value
407 %type <keyword> unreserved_keyword type_func_name_keyword
408 %type <keyword> col_name_keyword reserved_keyword
410 %type <node> TableConstraint TableLikeClause
411 %type <ival> TableLikeOptionList TableLikeOption
412 %type <list> ColQualList
413 %type <node> ColConstraint ColConstraintElem ConstraintAttr
414 %type <ival> key_actions key_delete key_match key_update key_action
415 %type <ival> ConstraintAttributeSpec ConstraintDeferrabilitySpec
418 %type <list> constraints_set_list
419 %type <boolean> constraints_set_mode
420 %type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
421 %type <list> opt_check_option
423 %type <target> xml_attribute_el
424 %type <list> xml_attribute_list xml_attributes
425 %type <node> xml_root_version opt_xml_root_standalone
426 %type <ival> document_or_content
427 %type <boolean> xml_whitespace_option
429 %type <node> common_table_expr
430 %type <with> with_clause
431 %type <list> cte_list
433 %type <list> window_clause window_definition_list opt_partition_clause
434 %type <windef> window_definition over_clause window_specification
435 %type <str> opt_existing_window_name
436 %type <ival> opt_frame_clause frame_extent frame_bound
440 * Non-keyword token types. These are hard-wired into the "flex" lexer.
441 * They must be listed first so that their numeric codes do not depend on
442 * the set of keywords. PL/pgsql depends on this so that it can share the
443 * same lexer. If you add/change tokens here, fix PL/pgsql to match!
445 * DOT_DOT and COLON_EQUALS are unused in the core SQL grammar, and so will
446 * always provoke parse errors. They are needed by PL/pgsql.
448 %token <str> IDENT FCONST SCONST BCONST XCONST Op
449 %token <ival> ICONST PARAM
450 %token TYPECAST DOT_DOT COLON_EQUALS
453 * If you want to make any keyword changes, update the keyword table in
454 * src/include/parser/kwlist.h and add new keywords to the appropriate one
455 * of the reserved-or-not-so-reserved keyword lists, below; search
456 * this file for "Keyword category lists".
459 /* ordinary key words in alphabetical order */
460 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
461 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
462 ASSERTION ASSIGNMENT ASYMMETRIC AT AUTHORIZATION
464 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
467 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
468 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
469 CLUSTER COALESCE COLLATE COLUMN COMMENT COMMENTS COMMIT
470 COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
471 CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
472 CREATEROLE CREATEUSER CROSS CSV CURRENT_P
473 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
474 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
476 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
477 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
478 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
480 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT
481 EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
483 FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOLLOWING FOR FORCE FOREIGN FORWARD
484 FREEZE FROM FULL FUNCTION FUNCTIONS
486 GLOBAL GRANT GRANTED GREATEST GROUP_P
488 HANDLER HAVING HEADER_P HOLD HOUR_P
490 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
491 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
492 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
493 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
499 LANGUAGE LARGE_P LAST_P LC_COLLATE_P LC_CTYPE_P LEADING
500 LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP
501 LOCATION LOCK_P LOGIN_P
503 MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
505 NAME_P NAMES NATIONAL NATURAL NCHAR NEXT NO NOCREATEDB
506 NOCREATEROLE NOCREATEUSER NOINHERIT NOLOGIN_P NONE NOSUPERUSER
507 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NULLS_P NUMERIC
509 OBJECT_P OF OFF OFFSET OIDS ON ONLY OPERATOR OPTION OPTIONS OR
510 ORDER OUT_P OUTER_P OVER OVERLAPS OVERLAY OWNED OWNER
512 PARSER PARTIAL PARTITION PASSWORD PLACING PLANS POSITION
513 PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
514 PRIOR PRIVILEGES PROCEDURAL PROCEDURE
518 RANGE READ REAL REASSIGN RECHECK RECURSIVE REFERENCES REINDEX
519 RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA RESET RESTART
520 RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROW ROWS RULE
522 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE SEQUENCES
523 SERIALIZABLE SERVER SESSION SESSION_USER SET SETOF SHARE
524 SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT
525 STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING SUPERUSER_P
526 SYMMETRIC SYSID SYSTEM_P
528 TABLE TABLES TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
529 TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
530 TRUNCATE TRUSTED TYPE_P
532 UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
535 VACUUM VALID VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
536 VERBOSE VERSION_P VIEW VOLATILE
538 WHEN WHERE WHITESPACE_P WINDOW WITH WITHOUT WORK WRAPPER WRITE
540 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLFOREST XMLPARSE
541 XMLPI XMLROOT XMLSERIALIZE
548 * The grammar thinks these are keywords, but they are not in the kwlist.h
549 * list and so can never be entered directly. The filter in parser.c
550 * creates these tokens when required.
552 %token NULLS_FIRST NULLS_LAST WITH_TIME
555 /* Precedence: lowest to highest */
556 %nonassoc SET /* see relation_expr_opt_alias */
564 %nonassoc LIKE ILIKE SIMILAR
569 %left POSTFIXOP /* dummy for postfix Op rules */
571 * To support target_el without AS, we must give IDENT an explicit priority
572 * between POSTFIXOP and Op. We can safely assign the same priority to
573 * various unreserved keywords as needed to resolve ambiguities (this can't
574 * have any bad effects since obviously the keywords will still behave the
575 * same as if they weren't keywords). We need to do this for PARTITION,
576 * RANGE, ROWS to support opt_existing_window_name; and for RANGE, ROWS
577 * so that they can follow a_expr without creating
578 * postfix-operator problems.
580 %nonassoc IDENT PARTITION RANGE ROWS
581 %left Op OPERATOR /* multi-character ops and user-defined operators */
584 %nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN /* sets precedence for IS NULL, etc */
588 /* Unary Operators */
589 %left AT ZONE /* sets precedence for AT TIME ZONE */
596 * These might seem to be low-precedence, but actually they are not part
597 * of the arithmetic hierarchy at all in their use as JOIN operators.
598 * We make them high-precedence to support their use as function names.
599 * They wouldn't be given a precedence at all, were it not that we need
600 * left-associativity among the JOIN rules themselves.
602 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
603 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
604 %right PRESERVE STRIP_P
609 * The target production for the whole parse.
613 pg_yyget_extra(yyscanner)->parsetree = $1;
617 /* the thrashing around here is to discard "empty" statements... */
618 stmtmulti: stmtmulti ';' stmt
621 $$ = lappend($1, $3);
636 | AlterDatabaseSetStmt
637 | AlterDefaultPrivilegesStmt
640 | AlterForeignServerStmt
643 | AlterObjectSchemaStmt
649 | AlterTSConfigurationStmt
650 | AlterTSDictionaryStmt
651 | AlterUserMappingStmt
664 | CreateConversionStmt
667 | CreateForeignServerStmt
677 | CreateTableSpaceStmt
681 | CreateUserMappingStmt
692 | DropForeignServerStmt
704 | DropUserMappingStmt
741 /*****************************************************************************
743 * Create a new Postgres DBMS role
745 *****************************************************************************/
748 CREATE ROLE RoleId opt_with OptRoleList
750 CreateRoleStmt *n = makeNode(CreateRoleStmt);
751 n->stmt_type = ROLESTMT_ROLE;
764 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
765 * for backwards compatibility). Note: the only option required by SQL99
766 * is "WITH ADMIN name".
769 OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
770 | /* EMPTY */ { $$ = NIL; }
774 AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
775 | /* EMPTY */ { $$ = NIL; }
781 $$ = makeDefElem("password",
782 (Node *)makeString($2));
786 $$ = makeDefElem("password", NULL);
788 | ENCRYPTED PASSWORD Sconst
790 $$ = makeDefElem("encryptedPassword",
791 (Node *)makeString($3));
793 | UNENCRYPTED PASSWORD Sconst
795 $$ = makeDefElem("unencryptedPassword",
796 (Node *)makeString($3));
800 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
804 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
808 $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE));
812 $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE));
816 $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
820 $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
824 $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE));
828 $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE));
832 /* For backwards compatibility, synonym for SUPERUSER */
833 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
837 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
841 $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE));
845 $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE));
847 | CONNECTION LIMIT SignedIconst
849 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3));
853 $$ = makeDefElem("validUntil", (Node *)makeString($3));
855 /* Supported but not documented for roles, for use by ALTER GROUP. */
858 $$ = makeDefElem("rolemembers", (Node *)$2);
863 AlterOptRoleElem { $$ = $1; }
864 /* The following are not supported by ALTER ROLE/USER/GROUP */
867 $$ = makeDefElem("sysid", (Node *)makeInteger($2));
871 $$ = makeDefElem("adminmembers", (Node *)$2);
875 $$ = makeDefElem("rolemembers", (Node *)$2);
877 | IN_P ROLE name_list
879 $$ = makeDefElem("addroleto", (Node *)$3);
881 | IN_P GROUP_P name_list
883 $$ = makeDefElem("addroleto", (Node *)$3);
888 /*****************************************************************************
890 * Create a new Postgres DBMS user (role with implied login ability)
892 *****************************************************************************/
895 CREATE USER RoleId opt_with OptRoleList
897 CreateRoleStmt *n = makeNode(CreateRoleStmt);
898 n->stmt_type = ROLESTMT_USER;
906 /*****************************************************************************
908 * Alter a postgresql DBMS role
910 *****************************************************************************/
913 ALTER ROLE RoleId opt_with AlterOptRoleList
915 AlterRoleStmt *n = makeNode(AlterRoleStmt);
917 n->action = +1; /* add, if there are members */
924 /* EMPTY */ { $$ = NULL; }
925 | IN_P DATABASE database_name { $$ = $3; }
929 ALTER ROLE RoleId opt_in_database SetResetClause
931 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
940 /*****************************************************************************
942 * Alter a postgresql DBMS user
944 *****************************************************************************/
947 ALTER USER RoleId opt_with AlterOptRoleList
949 AlterRoleStmt *n = makeNode(AlterRoleStmt);
951 n->action = +1; /* add, if there are members */
959 ALTER USER RoleId SetResetClause
961 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
970 /*****************************************************************************
972 * Drop a postgresql DBMS role
974 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
975 * might own objects in multiple databases, there is presently no way to
976 * implement either cascading or restricting. Caveat DBA.
977 *****************************************************************************/
982 DropRoleStmt *n = makeNode(DropRoleStmt);
983 n->missing_ok = FALSE;
987 | DROP ROLE IF_P EXISTS name_list
989 DropRoleStmt *n = makeNode(DropRoleStmt);
990 n->missing_ok = TRUE;
996 /*****************************************************************************
998 * Drop a postgresql DBMS user
1000 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
1001 * might own objects in multiple databases, there is presently no way to
1002 * implement either cascading or restricting. Caveat DBA.
1003 *****************************************************************************/
1008 DropRoleStmt *n = makeNode(DropRoleStmt);
1009 n->missing_ok = FALSE;
1013 | DROP USER IF_P EXISTS name_list
1015 DropRoleStmt *n = makeNode(DropRoleStmt);
1017 n->missing_ok = TRUE;
1023 /*****************************************************************************
1025 * Create a postgresql group (role without login ability)
1027 *****************************************************************************/
1030 CREATE GROUP_P RoleId opt_with OptRoleList
1032 CreateRoleStmt *n = makeNode(CreateRoleStmt);
1033 n->stmt_type = ROLESTMT_GROUP;
1041 /*****************************************************************************
1043 * Alter a postgresql group
1045 *****************************************************************************/
1048 ALTER GROUP_P RoleId add_drop USER name_list
1050 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1053 n->options = list_make1(makeDefElem("rolemembers",
1059 add_drop: ADD_P { $$ = +1; }
1064 /*****************************************************************************
1066 * Drop a postgresql group
1068 * XXX see above notes about cascading DROP USER; groups have same problem.
1069 *****************************************************************************/
1072 DROP GROUP_P name_list
1074 DropRoleStmt *n = makeNode(DropRoleStmt);
1075 n->missing_ok = FALSE;
1079 | DROP GROUP_P IF_P EXISTS name_list
1081 DropRoleStmt *n = makeNode(DropRoleStmt);
1082 n->missing_ok = TRUE;
1089 /*****************************************************************************
1091 * Manipulate a schema
1093 *****************************************************************************/
1096 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
1098 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1099 /* One can omit the schema name or the authorization id. */
1108 | CREATE SCHEMA ColId OptSchemaEltList
1110 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1111 /* ...but not both */
1121 | /* EMPTY */ { $$ = NULL; }
1125 OptSchemaEltList schema_stmt { $$ = lappend($1, $2); }
1126 | /* EMPTY */ { $$ = NIL; }
1130 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1131 * statement (in addition to by themselves).
1143 /*****************************************************************************
1145 * Set PG internal variable
1146 * SET name TO 'var_value'
1147 * Include SQL92 syntax (thomas 1997-10-22):
1148 * SET TIME ZONE 'var_value'
1150 *****************************************************************************/
1155 VariableSetStmt *n = $2;
1156 n->is_local = false;
1159 | SET LOCAL set_rest
1161 VariableSetStmt *n = $3;
1165 | SET SESSION set_rest
1167 VariableSetStmt *n = $3;
1168 n->is_local = false;
1173 set_rest: /* Generic SET syntaxes: */
1174 var_name TO var_list
1176 VariableSetStmt *n = makeNode(VariableSetStmt);
1177 n->kind = VAR_SET_VALUE;
1182 | var_name '=' var_list
1184 VariableSetStmt *n = makeNode(VariableSetStmt);
1185 n->kind = VAR_SET_VALUE;
1190 | var_name TO DEFAULT
1192 VariableSetStmt *n = makeNode(VariableSetStmt);
1193 n->kind = VAR_SET_DEFAULT;
1197 | var_name '=' DEFAULT
1199 VariableSetStmt *n = makeNode(VariableSetStmt);
1200 n->kind = VAR_SET_DEFAULT;
1204 | var_name FROM CURRENT_P
1206 VariableSetStmt *n = makeNode(VariableSetStmt);
1207 n->kind = VAR_SET_CURRENT;
1211 /* Special syntaxes mandated by SQL standard: */
1212 | TIME ZONE zone_value
1214 VariableSetStmt *n = makeNode(VariableSetStmt);
1215 n->kind = VAR_SET_VALUE;
1216 n->name = "timezone";
1218 n->args = list_make1($3);
1220 n->kind = VAR_SET_DEFAULT;
1223 | TRANSACTION transaction_mode_list
1225 VariableSetStmt *n = makeNode(VariableSetStmt);
1226 n->kind = VAR_SET_MULTI;
1227 n->name = "TRANSACTION";
1231 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1233 VariableSetStmt *n = makeNode(VariableSetStmt);
1234 n->kind = VAR_SET_MULTI;
1235 n->name = "SESSION CHARACTERISTICS";
1242 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1243 errmsg("current database cannot be changed"),
1244 parser_errposition(@2)));
1245 $$ = NULL; /*not reached*/
1249 VariableSetStmt *n = makeNode(VariableSetStmt);
1250 n->kind = VAR_SET_VALUE;
1251 n->name = "search_path";
1252 n->args = list_make1(makeStringConst($2, @2));
1255 | NAMES opt_encoding
1257 VariableSetStmt *n = makeNode(VariableSetStmt);
1258 n->kind = VAR_SET_VALUE;
1259 n->name = "client_encoding";
1261 n->args = list_make1(makeStringConst($2, @2));
1263 n->kind = VAR_SET_DEFAULT;
1266 | ROLE ColId_or_Sconst
1268 VariableSetStmt *n = makeNode(VariableSetStmt);
1269 n->kind = VAR_SET_VALUE;
1271 n->args = list_make1(makeStringConst($2, @2));
1274 | SESSION AUTHORIZATION ColId_or_Sconst
1276 VariableSetStmt *n = makeNode(VariableSetStmt);
1277 n->kind = VAR_SET_VALUE;
1278 n->name = "session_authorization";
1279 n->args = list_make1(makeStringConst($3, @3));
1282 | SESSION AUTHORIZATION DEFAULT
1284 VariableSetStmt *n = makeNode(VariableSetStmt);
1285 n->kind = VAR_SET_DEFAULT;
1286 n->name = "session_authorization";
1289 | XML_P OPTION document_or_content
1291 VariableSetStmt *n = makeNode(VariableSetStmt);
1292 n->kind = VAR_SET_VALUE;
1293 n->name = "xmloption";
1294 n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1299 var_name: ColId { $$ = $1; }
1300 | var_name '.' ColId
1302 $$ = palloc(strlen($1) + strlen($3) + 2);
1303 sprintf($$, "%s.%s", $1, $3);
1307 var_list: var_value { $$ = list_make1($1); }
1308 | var_list ',' var_value { $$ = lappend($1, $3); }
1311 var_value: opt_boolean
1312 { $$ = makeStringConst($1, @1); }
1314 { $$ = makeStringConst($1, @1); }
1316 { $$ = makeAConst($1, @1); }
1319 iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1320 | READ COMMITTED { $$ = "read committed"; }
1321 | REPEATABLE READ { $$ = "repeatable read"; }
1322 | SERIALIZABLE { $$ = "serializable"; }
1326 TRUE_P { $$ = "true"; }
1327 | FALSE_P { $$ = "false"; }
1329 | OFF { $$ = "off"; }
1332 /* Timezone values can be:
1333 * - a string such as 'pst8pdt'
1334 * - an identifier such as "pst8pdt"
1335 * - an integer or floating point number
1336 * - a time interval per SQL99
1337 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1338 * so use IDENT (meaning we reject anything that is a key word).
1343 $$ = makeStringConst($1, @1);
1347 $$ = makeStringConst($1, @1);
1349 | ConstInterval Sconst opt_interval
1354 A_Const *n = (A_Const *) linitial($3);
1355 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1357 (errcode(ERRCODE_SYNTAX_ERROR),
1358 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1359 parser_errposition(@3)));
1362 $$ = makeStringConstCast($2, @2, t);
1364 | ConstInterval '(' Iconst ')' Sconst opt_interval
1369 A_Const *n = (A_Const *) linitial($6);
1370 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1372 (errcode(ERRCODE_SYNTAX_ERROR),
1373 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1374 parser_errposition(@6)));
1375 if (list_length($6) != 1)
1377 (errcode(ERRCODE_SYNTAX_ERROR),
1378 errmsg("interval precision specified twice"),
1379 parser_errposition(@1)));
1380 t->typmods = lappend($6, makeIntConst($3, @3));
1383 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1384 makeIntConst($3, @3));
1385 $$ = makeStringConstCast($5, @5, t);
1387 | NumericOnly { $$ = makeAConst($1, @1); }
1388 | DEFAULT { $$ = NULL; }
1389 | LOCAL { $$ = NULL; }
1394 | DEFAULT { $$ = NULL; }
1395 | /*EMPTY*/ { $$ = NULL; }
1400 | Sconst { $$ = $1; }
1406 VariableSetStmt *n = makeNode(VariableSetStmt);
1407 n->kind = VAR_RESET;
1413 VariableSetStmt *n = makeNode(VariableSetStmt);
1414 n->kind = VAR_RESET;
1415 n->name = "timezone";
1418 | RESET TRANSACTION ISOLATION LEVEL
1420 VariableSetStmt *n = makeNode(VariableSetStmt);
1421 n->kind = VAR_RESET;
1422 n->name = "transaction_isolation";
1425 | RESET SESSION AUTHORIZATION
1427 VariableSetStmt *n = makeNode(VariableSetStmt);
1428 n->kind = VAR_RESET;
1429 n->name = "session_authorization";
1434 VariableSetStmt *n = makeNode(VariableSetStmt);
1435 n->kind = VAR_RESET_ALL;
1440 /* SetResetClause allows SET or RESET without LOCAL */
1442 SET set_rest { $$ = $2; }
1443 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1450 VariableShowStmt *n = makeNode(VariableShowStmt);
1456 VariableShowStmt *n = makeNode(VariableShowStmt);
1457 n->name = "timezone";
1460 | SHOW TRANSACTION ISOLATION LEVEL
1462 VariableShowStmt *n = makeNode(VariableShowStmt);
1463 n->name = "transaction_isolation";
1466 | SHOW SESSION AUTHORIZATION
1468 VariableShowStmt *n = makeNode(VariableShowStmt);
1469 n->name = "session_authorization";
1474 VariableShowStmt *n = makeNode(VariableShowStmt);
1482 SET CONSTRAINTS constraints_set_list constraints_set_mode
1484 ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
1485 n->constraints = $3;
1491 constraints_set_list:
1493 | qualified_name_list { $$ = $1; }
1496 constraints_set_mode:
1497 DEFERRED { $$ = TRUE; }
1498 | IMMEDIATE { $$ = FALSE; }
1503 * Checkpoint statement
1508 CheckPointStmt *n = makeNode(CheckPointStmt);
1514 /*****************************************************************************
1516 * DISCARD { ALL | TEMP | PLANS }
1518 *****************************************************************************/
1523 DiscardStmt *n = makeNode(DiscardStmt);
1524 n->target = DISCARD_ALL;
1529 DiscardStmt *n = makeNode(DiscardStmt);
1530 n->target = DISCARD_TEMP;
1535 DiscardStmt *n = makeNode(DiscardStmt);
1536 n->target = DISCARD_TEMP;
1541 DiscardStmt *n = makeNode(DiscardStmt);
1542 n->target = DISCARD_PLANS;
1548 /*****************************************************************************
1550 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations
1552 * Note: we accept all subcommands for each of the four variants, and sort
1553 * out what's really legal at execution time.
1554 *****************************************************************************/
1557 ALTER TABLE relation_expr alter_table_cmds
1559 AlterTableStmt *n = makeNode(AlterTableStmt);
1562 n->relkind = OBJECT_TABLE;
1565 | ALTER INDEX qualified_name alter_table_cmds
1567 AlterTableStmt *n = makeNode(AlterTableStmt);
1570 n->relkind = OBJECT_INDEX;
1573 | ALTER SEQUENCE qualified_name alter_table_cmds
1575 AlterTableStmt *n = makeNode(AlterTableStmt);
1578 n->relkind = OBJECT_SEQUENCE;
1581 | ALTER VIEW qualified_name alter_table_cmds
1583 AlterTableStmt *n = makeNode(AlterTableStmt);
1586 n->relkind = OBJECT_VIEW;
1592 alter_table_cmd { $$ = list_make1($1); }
1593 | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
1597 /* ALTER TABLE <name> ADD <coldef> */
1600 AlterTableCmd *n = makeNode(AlterTableCmd);
1601 n->subtype = AT_AddColumn;
1605 /* ALTER TABLE <name> ADD COLUMN <coldef> */
1606 | ADD_P COLUMN columnDef
1608 AlterTableCmd *n = makeNode(AlterTableCmd);
1609 n->subtype = AT_AddColumn;
1613 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1614 | ALTER opt_column ColId alter_column_default
1616 AlterTableCmd *n = makeNode(AlterTableCmd);
1617 n->subtype = AT_ColumnDefault;
1622 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1623 | ALTER opt_column ColId DROP NOT NULL_P
1625 AlterTableCmd *n = makeNode(AlterTableCmd);
1626 n->subtype = AT_DropNotNull;
1630 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1631 | ALTER opt_column ColId SET NOT NULL_P
1633 AlterTableCmd *n = makeNode(AlterTableCmd);
1634 n->subtype = AT_SetNotNull;
1638 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
1639 | ALTER opt_column ColId SET STATISTICS SignedIconst
1641 AlterTableCmd *n = makeNode(AlterTableCmd);
1642 n->subtype = AT_SetStatistics;
1644 n->def = (Node *) makeInteger($6);
1647 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS DISTINCT <NumericOnly> */
1648 | ALTER opt_column ColId SET STATISTICS DISTINCT NumericOnly
1650 AlterTableCmd *n = makeNode(AlterTableCmd);
1651 n->subtype = AT_SetDistinct;
1653 n->def = (Node *) $7;
1656 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1657 | ALTER opt_column ColId SET STORAGE ColId
1659 AlterTableCmd *n = makeNode(AlterTableCmd);
1660 n->subtype = AT_SetStorage;
1662 n->def = (Node *) makeString($6);
1665 /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
1666 | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
1668 AlterTableCmd *n = makeNode(AlterTableCmd);
1669 n->subtype = AT_DropColumn;
1672 n->missing_ok = TRUE;
1675 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1676 | DROP opt_column ColId opt_drop_behavior
1678 AlterTableCmd *n = makeNode(AlterTableCmd);
1679 n->subtype = AT_DropColumn;
1682 n->missing_ok = FALSE;
1686 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
1687 * [ USING <expression> ]
1689 | ALTER opt_column ColId opt_set_data TYPE_P Typename alter_using
1691 AlterTableCmd *n = makeNode(AlterTableCmd);
1692 n->subtype = AT_AlterColumnType;
1694 n->def = (Node *) $6;
1698 /* ALTER TABLE <name> ADD CONSTRAINT ... */
1699 | ADD_P TableConstraint
1701 AlterTableCmd *n = makeNode(AlterTableCmd);
1702 n->subtype = AT_AddConstraint;
1706 /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
1707 | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
1709 AlterTableCmd *n = makeNode(AlterTableCmd);
1710 n->subtype = AT_DropConstraint;
1713 n->missing_ok = TRUE;
1716 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1717 | DROP CONSTRAINT name opt_drop_behavior
1719 AlterTableCmd *n = makeNode(AlterTableCmd);
1720 n->subtype = AT_DropConstraint;
1723 n->missing_ok = FALSE;
1726 /* ALTER TABLE <name> SET WITH OIDS */
1729 AlterTableCmd *n = makeNode(AlterTableCmd);
1730 n->subtype = AT_AddOids;
1733 /* ALTER TABLE <name> SET WITHOUT OIDS */
1736 AlterTableCmd *n = makeNode(AlterTableCmd);
1737 n->subtype = AT_DropOids;
1740 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1743 AlterTableCmd *n = makeNode(AlterTableCmd);
1744 n->subtype = AT_ClusterOn;
1748 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1749 | SET WITHOUT CLUSTER
1751 AlterTableCmd *n = makeNode(AlterTableCmd);
1752 n->subtype = AT_DropCluster;
1756 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
1757 | ENABLE_P TRIGGER name
1759 AlterTableCmd *n = makeNode(AlterTableCmd);
1760 n->subtype = AT_EnableTrig;
1764 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
1765 | ENABLE_P ALWAYS TRIGGER name
1767 AlterTableCmd *n = makeNode(AlterTableCmd);
1768 n->subtype = AT_EnableAlwaysTrig;
1772 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
1773 | ENABLE_P REPLICA TRIGGER name
1775 AlterTableCmd *n = makeNode(AlterTableCmd);
1776 n->subtype = AT_EnableReplicaTrig;
1780 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
1781 | ENABLE_P TRIGGER ALL
1783 AlterTableCmd *n = makeNode(AlterTableCmd);
1784 n->subtype = AT_EnableTrigAll;
1787 /* ALTER TABLE <name> ENABLE TRIGGER USER */
1788 | ENABLE_P TRIGGER USER
1790 AlterTableCmd *n = makeNode(AlterTableCmd);
1791 n->subtype = AT_EnableTrigUser;
1794 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
1795 | DISABLE_P TRIGGER name
1797 AlterTableCmd *n = makeNode(AlterTableCmd);
1798 n->subtype = AT_DisableTrig;
1802 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
1803 | DISABLE_P TRIGGER ALL
1805 AlterTableCmd *n = makeNode(AlterTableCmd);
1806 n->subtype = AT_DisableTrigAll;
1809 /* ALTER TABLE <name> DISABLE TRIGGER USER */
1810 | DISABLE_P TRIGGER USER
1812 AlterTableCmd *n = makeNode(AlterTableCmd);
1813 n->subtype = AT_DisableTrigUser;
1816 /* ALTER TABLE <name> ENABLE RULE <rule> */
1817 | ENABLE_P RULE name
1819 AlterTableCmd *n = makeNode(AlterTableCmd);
1820 n->subtype = AT_EnableRule;
1824 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
1825 | ENABLE_P ALWAYS RULE name
1827 AlterTableCmd *n = makeNode(AlterTableCmd);
1828 n->subtype = AT_EnableAlwaysRule;
1832 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
1833 | ENABLE_P REPLICA RULE name
1835 AlterTableCmd *n = makeNode(AlterTableCmd);
1836 n->subtype = AT_EnableReplicaRule;
1840 /* ALTER TABLE <name> DISABLE RULE <rule> */
1841 | DISABLE_P RULE name
1843 AlterTableCmd *n = makeNode(AlterTableCmd);
1844 n->subtype = AT_DisableRule;
1848 /* ALTER TABLE <name> INHERIT <parent> */
1849 | INHERIT qualified_name
1851 AlterTableCmd *n = makeNode(AlterTableCmd);
1852 n->subtype = AT_AddInherit;
1853 n->def = (Node *) $2;
1856 /* ALTER TABLE <name> NO INHERIT <parent> */
1857 | NO INHERIT qualified_name
1859 AlterTableCmd *n = makeNode(AlterTableCmd);
1860 n->subtype = AT_DropInherit;
1861 n->def = (Node *) $3;
1864 /* ALTER TABLE <name> OWNER TO RoleId */
1867 AlterTableCmd *n = makeNode(AlterTableCmd);
1868 n->subtype = AT_ChangeOwner;
1872 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1873 | SET TABLESPACE name
1875 AlterTableCmd *n = makeNode(AlterTableCmd);
1876 n->subtype = AT_SetTableSpace;
1880 /* ALTER TABLE <name> SET (...) */
1883 AlterTableCmd *n = makeNode(AlterTableCmd);
1884 n->subtype = AT_SetRelOptions;
1885 n->def = (Node *)$2;
1888 /* ALTER TABLE <name> RESET (...) */
1891 AlterTableCmd *n = makeNode(AlterTableCmd);
1892 n->subtype = AT_ResetRelOptions;
1893 n->def = (Node *)$2;
1898 alter_column_default:
1899 SET DEFAULT a_expr { $$ = $3; }
1900 | DROP DEFAULT { $$ = NULL; }
1904 CASCADE { $$ = DROP_CASCADE; }
1905 | RESTRICT { $$ = DROP_RESTRICT; }
1906 | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1910 USING a_expr { $$ = $2; }
1911 | /* EMPTY */ { $$ = NULL; }
1915 '(' reloption_list ')' { $$ = $2; }
1918 opt_reloptions: WITH reloptions { $$ = $2; }
1919 | /* EMPTY */ { $$ = NIL; }
1923 reloption_elem { $$ = list_make1($1); }
1924 | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
1927 /* This should match def_elem and also allow qualified names */
1929 ColLabel '=' def_arg
1931 $$ = makeDefElem($1, (Node *) $3);
1935 $$ = makeDefElem($1, NULL);
1937 | ColLabel '.' ColLabel '=' def_arg
1939 $$ = makeDefElemExtended($1, $3, (Node *) $5,
1942 | ColLabel '.' ColLabel
1944 $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC);
1949 /*****************************************************************************
1952 * close <portalname>
1954 *****************************************************************************/
1959 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1965 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1966 n->portalname = NULL;
1972 /*****************************************************************************
1975 * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
1976 * COPY ( SELECT ... ) TO file [WITH] [(options)]
1978 * In the preferred syntax the options are comma-separated
1979 * and use generic identifiers instead of keywords. The pre-8.5
1980 * syntax had a hard-wired, space-separated set of options.
1982 * Really old syntax, from versions 7.2 and prior:
1983 * COPY [ BINARY ] table [ WITH OIDS ] FROM/TO file
1984 * [ [ USING ] DELIMITERS 'delimiter' ] ]
1985 * [ WITH NULL AS 'null string' ]
1986 * This option placement is not supported with COPY (SELECT...).
1988 *****************************************************************************/
1990 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
1991 copy_from copy_file_name copy_delimiter opt_with copy_options
1993 CopyStmt *n = makeNode(CopyStmt);
2001 /* Concatenate user-supplied flags */
2003 n->options = lappend(n->options, $2);
2005 n->options = lappend(n->options, $5);
2007 n->options = lappend(n->options, $8);
2009 n->options = list_concat(n->options, $10);
2012 | COPY select_with_parens TO copy_file_name opt_with copy_options
2014 CopyStmt *n = makeNode(CopyStmt);
2027 | TO { $$ = FALSE; }
2031 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
2032 * used depends on the direction. (It really doesn't make sense to copy from
2033 * stdout. We silently correct the "typo".) - AY 9/94
2037 | STDIN { $$ = NULL; }
2038 | STDOUT { $$ = NULL; }
2041 copy_options: copy_opt_list { $$ = $1; }
2042 | '(' copy_generic_opt_list ')' { $$ = $2; }
2045 /* old COPY option syntax */
2047 copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
2048 | /* EMPTY */ { $$ = NIL; }
2054 $$ = makeDefElem("format", (Node *)makeString("binary"));
2058 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2060 | DELIMITER opt_as Sconst
2062 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2064 | NULL_P opt_as Sconst
2066 $$ = makeDefElem("null", (Node *)makeString($3));
2070 $$ = makeDefElem("format", (Node *)makeString("csv"));
2074 $$ = makeDefElem("header", (Node *)makeInteger(TRUE));
2076 | QUOTE opt_as Sconst
2078 $$ = makeDefElem("quote", (Node *)makeString($3));
2080 | ESCAPE opt_as Sconst
2082 $$ = makeDefElem("escape", (Node *)makeString($3));
2084 | FORCE QUOTE columnList
2086 $$ = makeDefElem("force_quote", (Node *)$3);
2090 $$ = makeDefElem("force_quote", (Node *)makeNode(A_Star));
2092 | FORCE NOT NULL_P columnList
2094 $$ = makeDefElem("force_not_null", (Node *)$4);
2098 /* The following exist for backward compatibility with very old versions */
2103 $$ = makeDefElem("format", (Node *)makeString("binary"));
2105 | /*EMPTY*/ { $$ = NULL; }
2111 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2113 | /*EMPTY*/ { $$ = NULL; }
2117 opt_using DELIMITERS Sconst
2119 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2121 | /*EMPTY*/ { $$ = NULL; }
2129 /* new COPY option syntax */
2130 copy_generic_opt_list:
2131 copy_generic_opt_elem
2133 $$ = list_make1($1);
2135 | copy_generic_opt_list ',' copy_generic_opt_elem
2137 $$ = lappend($1, $3);
2141 copy_generic_opt_elem:
2142 ColLabel copy_generic_opt_arg
2144 $$ = makeDefElem($1, $2);
2148 copy_generic_opt_arg:
2149 opt_boolean { $$ = (Node *) makeString($1); }
2150 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
2151 | NumericOnly { $$ = (Node *) $1; }
2152 | '*' { $$ = (Node *) makeNode(A_Star); }
2153 | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
2154 | /* EMPTY */ { $$ = NULL; }
2157 copy_generic_opt_arg_list:
2158 copy_generic_opt_arg_list_item
2160 $$ = list_make1($1);
2162 | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
2164 $$ = lappend($1, $3);
2168 /* beware of emitting non-string list elements here; see commands/define.c */
2169 copy_generic_opt_arg_list_item:
2170 opt_boolean { $$ = (Node *) makeString($1); }
2171 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
2175 /*****************************************************************************
2178 * CREATE TABLE relname
2180 *****************************************************************************/
2182 CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
2183 OptInherit OptWith OnCommitOption OptTableSpace
2185 CreateStmt *n = makeNode(CreateStmt);
2189 n->inhRelations = $8;
2190 n->constraints = NIL;
2193 n->tablespacename = $11;
2196 | CREATE OptTemp TABLE qualified_name OF qualified_name
2197 '(' OptTableElementList ')' OptWith OnCommitOption OptTableSpace
2199 /* SQL99 CREATE TABLE OF <UDT> (cols) seems to be satisfied
2200 * by our inheritance capabilities. Let's try it...
2202 CreateStmt *n = makeNode(CreateStmt);
2206 n->inhRelations = list_make1($6);
2207 n->constraints = NIL;
2210 n->tablespacename = $12;
2216 * Redundancy here is needed to avoid shift/reduce conflicts,
2217 * since TEMP is not a reserved word. See also OptTempTableName.
2219 * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
2220 * the LOCAL keyword is really meaningless.
2222 OptTemp: TEMPORARY { $$ = TRUE; }
2223 | TEMP { $$ = TRUE; }
2224 | LOCAL TEMPORARY { $$ = TRUE; }
2225 | LOCAL TEMP { $$ = TRUE; }
2226 | GLOBAL TEMPORARY { $$ = TRUE; }
2227 | GLOBAL TEMP { $$ = TRUE; }
2228 | /*EMPTY*/ { $$ = FALSE; }
2231 OptTableElementList:
2232 TableElementList { $$ = $1; }
2233 | /*EMPTY*/ { $$ = NIL; }
2239 $$ = list_make1($1);
2241 | TableElementList ',' TableElement
2243 $$ = lappend($1, $3);
2248 columnDef { $$ = $1; }
2249 | TableLikeClause { $$ = $1; }
2250 | TableConstraint { $$ = $1; }
2253 columnDef: ColId Typename ColQualList
2255 ColumnDef *n = makeNode(ColumnDef);
2258 n->constraints = $3;
2265 ColQualList ColConstraint { $$ = lappend($1, $2); }
2266 | /*EMPTY*/ { $$ = NIL; }
2270 CONSTRAINT name ColConstraintElem
2272 Constraint *n = (Constraint *) $3;
2273 Assert(IsA(n, Constraint));
2278 | ColConstraintElem { $$ = $1; }
2279 | ConstraintAttr { $$ = $1; }
2282 /* DEFAULT NULL is already the default for Postgres.
2283 * But define it here and carry it forward into the system
2284 * to make it explicit.
2285 * - thomas 1998-09-13
2287 * WITH NULL and NULL are not SQL92-standard syntax elements,
2288 * so leave them out. Use DEFAULT NULL to explicitly indicate
2289 * that a column may have that value. WITH NULL leads to
2290 * shift/reduce conflicts with WITH TIME ZONE anyway.
2291 * - thomas 1999-01-08
2293 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
2294 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
2295 * or be part of a_expr NOT LIKE or similar constructs).
2300 Constraint *n = makeNode(Constraint);
2301 n->contype = CONSTR_NOTNULL;
2307 Constraint *n = makeNode(Constraint);
2308 n->contype = CONSTR_NULL;
2312 | UNIQUE opt_definition OptConsTableSpace
2314 Constraint *n = makeNode(Constraint);
2315 n->contype = CONSTR_UNIQUE;
2322 | PRIMARY KEY opt_definition OptConsTableSpace
2324 Constraint *n = makeNode(Constraint);
2325 n->contype = CONSTR_PRIMARY;
2332 | CHECK '(' a_expr ')'
2334 Constraint *n = makeNode(Constraint);
2335 n->contype = CONSTR_CHECK;
2338 n->cooked_expr = NULL;
2343 Constraint *n = makeNode(Constraint);
2344 n->contype = CONSTR_DEFAULT;
2347 n->cooked_expr = NULL;
2350 | REFERENCES qualified_name opt_column_list key_match key_actions
2352 Constraint *n = makeNode(Constraint);
2353 n->contype = CONSTR_FOREIGN;
2358 n->fk_matchtype = $4;
2359 n->fk_upd_action = (char) ($5 >> 8);
2360 n->fk_del_action = (char) ($5 & 0xFF);
2361 n->skip_validation = FALSE;
2367 * ConstraintAttr represents constraint attributes, which we parse as if
2368 * they were independent constraint clauses, in order to avoid shift/reduce
2369 * conflicts (since NOT might start either an independent NOT NULL clause
2370 * or an attribute). parse_utilcmd.c is responsible for attaching the
2371 * attribute information to the preceding "real" constraint node, and for
2372 * complaining if attribute clauses appear in the wrong place or wrong
2375 * See also ConstraintAttributeSpec, which can be used in places where
2376 * there is no parsing conflict.
2381 Constraint *n = makeNode(Constraint);
2382 n->contype = CONSTR_ATTR_DEFERRABLE;
2388 Constraint *n = makeNode(Constraint);
2389 n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
2393 | INITIALLY DEFERRED
2395 Constraint *n = makeNode(Constraint);
2396 n->contype = CONSTR_ATTR_DEFERRED;
2400 | INITIALLY IMMEDIATE
2402 Constraint *n = makeNode(Constraint);
2403 n->contype = CONSTR_ATTR_IMMEDIATE;
2411 * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2412 * This seems to be a poor man's inheritance capability, with the resulting
2413 * tables completely decoupled except for the original commonality in definitions.
2415 * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2416 * which is a part of SQL:2003.
2419 LIKE qualified_name TableLikeOptionList
2421 InhRelation *n = makeNode(InhRelation);
2428 TableLikeOptionList:
2429 TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
2430 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
2431 | /* EMPTY */ { $$ = 0; }
2435 DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
2436 | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
2437 | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
2438 | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
2439 | COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
2440 | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
2444 /* ConstraintElem specifies constraint syntax which is not embedded into
2445 * a column definition. ColConstraintElem specifies the embedded form.
2446 * - thomas 1997-12-03
2449 CONSTRAINT name ConstraintElem
2451 Constraint *n = (Constraint *) $3;
2452 Assert(IsA(n, Constraint));
2457 | ConstraintElem { $$ = $1; }
2461 CHECK '(' a_expr ')' ConstraintAttributeSpec
2463 Constraint *n = makeNode(Constraint);
2464 n->contype = CONSTR_CHECK;
2467 n->cooked_expr = NULL;
2470 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2471 errmsg("CHECK constraints cannot be deferred"),
2472 parser_errposition(@5)));
2475 | UNIQUE '(' columnList ')' opt_definition OptConsTableSpace
2476 ConstraintAttributeSpec
2478 Constraint *n = makeNode(Constraint);
2479 n->contype = CONSTR_UNIQUE;
2484 n->deferrable = ($7 & 1) != 0;
2485 n->initdeferred = ($7 & 2) != 0;
2488 | PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace
2489 ConstraintAttributeSpec
2491 Constraint *n = makeNode(Constraint);
2492 n->contype = CONSTR_PRIMARY;
2497 n->deferrable = ($8 & 1) != 0;
2498 n->initdeferred = ($8 & 2) != 0;
2501 | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
2502 opt_definition OptConsTableSpace ExclusionWhereClause
2503 ConstraintAttributeSpec
2505 Constraint *n = makeNode(Constraint);
2506 n->contype = CONSTR_EXCLUSION;
2508 n->access_method = $2;
2512 n->where_clause = $8;
2513 n->deferrable = ($9 & 1) != 0;
2514 n->initdeferred = ($9 & 2) != 0;
2517 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
2518 opt_column_list key_match key_actions ConstraintAttributeSpec
2520 Constraint *n = makeNode(Constraint);
2521 n->contype = CONSTR_FOREIGN;
2526 n->fk_matchtype = $9;
2527 n->fk_upd_action = (char) ($10 >> 8);
2528 n->fk_del_action = (char) ($10 & 0xFF);
2529 n->skip_validation = FALSE;
2530 n->deferrable = ($11 & 1) != 0;
2531 n->initdeferred = ($11 & 2) != 0;
2537 '(' columnList ')' { $$ = $2; }
2538 | /*EMPTY*/ { $$ = NIL; }
2542 columnElem { $$ = list_make1($1); }
2543 | columnList ',' columnElem { $$ = lappend($1, $3); }
2548 $$ = (Node *) makeString($1);
2552 key_match: MATCH FULL
2554 $$ = FKCONSTR_MATCH_FULL;
2559 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2560 errmsg("MATCH PARTIAL not yet implemented"),
2561 parser_errposition(@1)));
2562 $$ = FKCONSTR_MATCH_PARTIAL;
2566 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2570 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2574 ExclusionConstraintList:
2575 ExclusionConstraintElem { $$ = list_make1($1); }
2576 | ExclusionConstraintList ',' ExclusionConstraintElem
2577 { $$ = lappend($1, $3); }
2580 ExclusionConstraintElem: index_elem WITH any_operator
2582 $$ = list_make2($1, $3);
2584 /* allow OPERATOR() decoration for the benefit of ruleutils.c */
2585 | index_elem WITH OPERATOR '(' any_operator ')'
2587 $$ = list_make2($1, $5);
2591 ExclusionWhereClause:
2592 WHERE '(' a_expr ')' { $$ = $3; }
2593 | /*EMPTY*/ { $$ = NULL; }
2597 * We combine the update and delete actions into one value temporarily
2598 * for simplicity of parsing, and then break them down again in the
2599 * calling production. update is in the left 8 bits, delete in the right.
2600 * Note that NOACTION is the default.
2604 { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2606 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
2607 | key_update key_delete
2608 { $$ = ($1 << 8) | ($2 & 0xFF); }
2609 | key_delete key_update
2610 { $$ = ($2 << 8) | ($1 & 0xFF); }
2612 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2615 key_update: ON UPDATE key_action { $$ = $3; }
2618 key_delete: ON DELETE_P key_action { $$ = $3; }
2622 NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; }
2623 | RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; }
2624 | CASCADE { $$ = FKCONSTR_ACTION_CASCADE; }
2625 | SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; }
2626 | SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; }
2629 OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
2630 | /*EMPTY*/ { $$ = NIL; }
2633 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
2635 WITH reloptions { $$ = $2; }
2636 | WITH OIDS { $$ = list_make1(defWithOids(true)); }
2637 | WITHOUT OIDS { $$ = list_make1(defWithOids(false)); }
2638 | /*EMPTY*/ { $$ = NIL; }
2641 OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
2642 | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
2643 | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
2644 | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
2647 OptTableSpace: TABLESPACE name { $$ = $2; }
2648 | /*EMPTY*/ { $$ = NULL; }
2651 OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
2652 | /*EMPTY*/ { $$ = NULL; }
2657 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
2662 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
2665 * When the SelectStmt is a set-operation tree, we must
2666 * stuff the INTO information into the leftmost component
2667 * Select, because that's where analyze.c will expect
2668 * to find it. Similarly, the output column names must
2669 * be attached to that Select's target list.
2671 SelectStmt *n = findLeftmostSelect((SelectStmt *) $6);
2672 if (n->intoClause != NULL)
2674 (errcode(ERRCODE_SYNTAX_ERROR),
2675 errmsg("CREATE TABLE AS cannot specify INTO"),
2676 parser_errposition(exprLocation((Node *) n->intoClause))));
2677 $4->rel->istemp = $2;
2679 /* Implement WITH NO DATA by forcing top-level LIMIT 0 */
2681 ((SelectStmt *) $6)->limitCount = makeIntConst(0, -1);
2687 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
2689 $$ = makeNode(IntoClause);
2694 $$->tableSpaceName = $5;
2699 '(' CreateAsList ')' { $$ = $2; }
2700 | /*EMPTY*/ { $$ = NIL; }
2704 CreateAsElement { $$ = list_make1($1); }
2705 | CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); }
2711 ColumnDef *n = makeNode(ColumnDef);
2716 n->is_not_null = false;
2717 n->raw_default = NULL;
2718 n->cooked_default = NULL;
2719 n->constraints = NIL;
2725 WITH DATA_P { $$ = TRUE; }
2726 | WITH NO DATA_P { $$ = FALSE; }
2727 | /*EMPTY*/ { $$ = TRUE; }
2731 /*****************************************************************************
2734 * CREATE SEQUENCE seqname
2735 * ALTER SEQUENCE seqname
2737 *****************************************************************************/
2740 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
2742 CreateSeqStmt *n = makeNode(CreateSeqStmt);
2751 ALTER SEQUENCE qualified_name SeqOptList
2753 AlterSeqStmt *n = makeNode(AlterSeqStmt);
2760 OptSeqOptList: SeqOptList { $$ = $1; }
2761 | /*EMPTY*/ { $$ = NIL; }
2764 SeqOptList: SeqOptElem { $$ = list_make1($1); }
2765 | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
2768 SeqOptElem: CACHE NumericOnly
2770 $$ = makeDefElem("cache", (Node *)$2);
2774 $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE));
2778 $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE));
2780 | INCREMENT opt_by NumericOnly
2782 $$ = makeDefElem("increment", (Node *)$3);
2784 | MAXVALUE NumericOnly
2786 $$ = makeDefElem("maxvalue", (Node *)$2);
2788 | MINVALUE NumericOnly
2790 $$ = makeDefElem("minvalue", (Node *)$2);
2794 $$ = makeDefElem("maxvalue", NULL);
2798 $$ = makeDefElem("minvalue", NULL);
2802 $$ = makeDefElem("owned_by", (Node *)$3);
2804 | START opt_with NumericOnly
2806 $$ = makeDefElem("start", (Node *)$3);
2810 $$ = makeDefElem("restart", NULL);
2812 | RESTART opt_with NumericOnly
2814 $$ = makeDefElem("restart", (Node *)$3);
2823 FCONST { $$ = makeFloat($1); }
2829 | SignedIconst { $$ = makeInteger($1); }
2832 /*****************************************************************************
2835 * CREATE PROCEDURAL LANGUAGE ...
2836 * DROP PROCEDURAL LANGUAGE ...
2838 *****************************************************************************/
2841 CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2843 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2845 /* parameters are all to be supplied by system */
2848 n->plvalidator = NIL;
2849 n->pltrusted = false;
2852 | CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2853 HANDLER handler_name opt_inline_handler opt_validator
2855 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2859 n->plvalidator = $9;
2866 TRUSTED { $$ = TRUE; }
2867 | /*EMPTY*/ { $$ = FALSE; }
2870 /* This ought to be just func_name, but that causes reduce/reduce conflicts
2871 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
2872 * Work around by using simple names, instead.
2875 name { $$ = list_make1(makeString($1)); }
2876 | name attrs { $$ = lcons(makeString($1), $2); }
2880 INLINE_P handler_name { $$ = $2; }
2881 | /*EMPTY*/ { $$ = NIL; }
2885 VALIDATOR handler_name { $$ = $2; }
2886 | NO VALIDATOR { $$ = NIL; }
2890 validator_clause { $$ = $1; }
2891 | /*EMPTY*/ { $$ = NIL; }
2895 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
2897 DropPLangStmt *n = makeNode(DropPLangStmt);
2900 n->missing_ok = false;
2903 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
2905 DropPLangStmt *n = makeNode(DropPLangStmt);
2908 n->missing_ok = true;
2918 /*****************************************************************************
2921 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
2923 *****************************************************************************/
2925 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
2927 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
2928 n->tablespacename = $3;
2935 OptTableSpaceOwner: OWNER name { $$ = $2; }
2936 | /*EMPTY */ { $$ = NULL; }
2939 /*****************************************************************************
2942 * DROP TABLESPACE <tablespace>
2944 * No need for drop behaviour as we cannot implement dependencies for
2945 * objects in other databases; we can only support RESTRICT.
2947 ****************************************************************************/
2949 DropTableSpaceStmt: DROP TABLESPACE name
2951 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2952 n->tablespacename = $3;
2953 n->missing_ok = false;
2956 | DROP TABLESPACE IF_P EXISTS name
2958 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2959 n->tablespacename = $5;
2960 n->missing_ok = true;
2965 /*****************************************************************************
2968 * CREATE FOREIGN DATA WRAPPER name [ VALIDATOR name ]
2970 *****************************************************************************/
2972 CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_validator create_generic_options
2974 CreateFdwStmt *n = makeNode(CreateFdwStmt);
2982 /*****************************************************************************
2985 * DROP FOREIGN DATA WRAPPER name
2987 ****************************************************************************/
2989 DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
2991 DropFdwStmt *n = makeNode(DropFdwStmt);
2993 n->missing_ok = false;
2997 | DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior
2999 DropFdwStmt *n = makeNode(DropFdwStmt);
3001 n->missing_ok = true;
3007 /*****************************************************************************
3010 * ALTER FOREIGN DATA WRAPPER name
3012 ****************************************************************************/
3014 AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name validator_clause alter_generic_options
3016 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3019 n->change_validator = true;
3023 | ALTER FOREIGN DATA_P WRAPPER name validator_clause
3025 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3028 n->change_validator = true;
3031 | ALTER FOREIGN DATA_P WRAPPER name alter_generic_options
3033 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3040 /* Options definition for CREATE FDW, SERVER and USER MAPPING */
3041 create_generic_options:
3042 OPTIONS '(' generic_option_list ')' { $$ = $3; }
3043 | /*EMPTY*/ { $$ = NIL; }
3046 generic_option_list:
3049 $$ = list_make1($1);
3051 | generic_option_list ',' generic_option_elem
3053 $$ = lappend($1, $3);
3057 /* Options definition for ALTER FDW, SERVER and USER MAPPING */
3058 alter_generic_options:
3059 OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
3062 alter_generic_option_list:
3063 alter_generic_option_elem
3065 $$ = list_make1($1);
3067 | alter_generic_option_list ',' alter_generic_option_elem
3069 $$ = lappend($1, $3);
3073 alter_generic_option_elem:
3078 | SET generic_option_elem
3081 $$->defaction = DEFELEM_SET;
3083 | ADD_P generic_option_elem
3086 $$->defaction = DEFELEM_ADD;
3088 | DROP generic_option_name
3090 $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP);
3094 generic_option_elem:
3095 generic_option_name generic_option_arg
3097 $$ = makeDefElem($1, $2);
3101 generic_option_name:
3102 ColLabel { $$ = $1; }
3105 /* We could use def_arg here, but the spec only requires string literals */
3107 Sconst { $$ = (Node *) makeString($1); }
3110 /*****************************************************************************
3113 * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
3115 *****************************************************************************/
3117 CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
3118 FOREIGN DATA_P WRAPPER name create_generic_options
3120 CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
3131 TYPE_P Sconst { $$ = $2; }
3132 | /*EMPTY*/ { $$ = NULL; }
3136 foreign_server_version:
3137 VERSION_P Sconst { $$ = $2; }
3138 | VERSION_P NULL_P { $$ = NULL; }
3141 opt_foreign_server_version:
3142 foreign_server_version { $$ = $1; }
3143 | /*EMPTY*/ { $$ = NULL; }
3146 /*****************************************************************************
3151 ****************************************************************************/
3153 DropForeignServerStmt: DROP SERVER name opt_drop_behavior
3155 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3157 n->missing_ok = false;
3161 | DROP SERVER IF_P EXISTS name opt_drop_behavior
3163 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3165 n->missing_ok = true;
3171 /*****************************************************************************
3174 * ALTER SERVER name [VERSION] [OPTIONS]
3176 ****************************************************************************/
3178 AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
3180 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3184 n->has_version = true;
3187 | ALTER SERVER name foreign_server_version
3189 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3192 n->has_version = true;
3195 | ALTER SERVER name alter_generic_options
3197 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3204 /*****************************************************************************
3207 * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
3209 *****************************************************************************/
3211 CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
3213 CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
3221 /* User mapping authorization identifier */
3223 CURRENT_USER { $$ = "current_user"; }
3224 | USER { $$ = "current_user"; }
3225 | RoleId { $$ = (strcmp($1, "public") == 0) ? NULL : $1; }
3228 /*****************************************************************************
3231 * DROP USER MAPPING FOR auth_ident SERVER name
3233 ****************************************************************************/
3235 DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
3237 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3240 n->missing_ok = false;
3243 | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
3245 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3248 n->missing_ok = true;
3253 /*****************************************************************************
3256 * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
3258 ****************************************************************************/
3260 AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
3262 AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
3270 /*****************************************************************************
3273 * CREATE TRIGGER ...
3276 *****************************************************************************/
3279 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
3280 qualified_name TriggerForSpec TriggerWhen
3281 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3283 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3290 n->events = intVal(linitial($5));
3291 n->columns = (List *) lsecond($5);
3293 n->isconstraint = FALSE;
3294 n->deferrable = FALSE;
3295 n->initdeferred = FALSE;
3296 n->constrrel = NULL;
3299 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
3300 qualified_name OptConstrFromTable ConstraintAttributeSpec
3301 FOR EACH ROW TriggerWhen
3302 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3304 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3311 n->events = intVal(linitial($6));
3312 n->columns = (List *) lsecond($6);
3313 n->whenClause = $14;
3314 n->isconstraint = TRUE;
3315 n->deferrable = ($10 & 1) != 0;
3316 n->initdeferred = ($10 & 2) != 0;
3323 BEFORE { $$ = TRUE; }
3324 | AFTER { $$ = FALSE; }
3330 | TriggerEvents OR TriggerOneEvent
3332 int events1 = intVal(linitial($1));
3333 int events2 = intVal(linitial($3));
3334 List *columns1 = (List *) lsecond($1);
3335 List *columns2 = (List *) lsecond($3);
3337 if (events1 & events2)
3338 parser_yyerror("duplicate trigger events specified");
3340 * concat'ing the columns lists loses information about
3341 * which columns went with which event, but so long as
3342 * only UPDATE carries columns and we disallow multiple
3343 * UPDATE items, it doesn't matter. Command execution
3344 * should just ignore the columns for non-UPDATE events.
3346 $$ = list_make2(makeInteger(events1 | events2),
3347 list_concat(columns1, columns2));
3353 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
3355 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
3357 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
3358 | UPDATE OF columnList
3359 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
3361 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
3365 FOR TriggerForOpt TriggerForType
3372 * If ROW/STATEMENT not specified, default to
3373 * STATEMENT, per SQL
3386 | STATEMENT { $$ = FALSE; }
3390 WHEN '(' a_expr ')' { $$ = $3; }
3391 | /*EMPTY*/ { $$ = NULL; }
3395 TriggerFuncArg { $$ = list_make1($1); }
3396 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
3397 | /*EMPTY*/ { $$ = NIL; }
3404 snprintf(buf, sizeof(buf), "%d", $1);
3405 $$ = makeString(pstrdup(buf));
3407 | FCONST { $$ = makeString($1); }
3408 | Sconst { $$ = makeString($1); }
3409 | BCONST { $$ = makeString($1); }
3410 | XCONST { $$ = makeString($1); }
3411 | ColId { $$ = makeString($1); }
3415 FROM qualified_name { $$ = $2; }
3416 | /*EMPTY*/ { $$ = NULL; }
3419 ConstraintAttributeSpec:
3420 ConstraintDeferrabilitySpec
3422 | ConstraintDeferrabilitySpec ConstraintTimeSpec
3424 if ($1 == 0 && $2 != 0)
3426 (errcode(ERRCODE_SYNTAX_ERROR),
3427 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3428 parser_errposition(@1)));
3431 | ConstraintTimeSpec
3438 | ConstraintTimeSpec ConstraintDeferrabilitySpec
3440 if ($2 == 0 && $1 != 0)
3442 (errcode(ERRCODE_SYNTAX_ERROR),
3443 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3444 parser_errposition(@1)));
3451 ConstraintDeferrabilitySpec:
3452 NOT DEFERRABLE { $$ = 0; }
3453 | DEFERRABLE { $$ = 1; }
3457 INITIALLY IMMEDIATE { $$ = 0; }
3458 | INITIALLY DEFERRED { $$ = 2; }
3463 DROP TRIGGER name ON qualified_name opt_drop_behavior
3465 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3469 n->removeType = OBJECT_TRIGGER;
3470 n->missing_ok = false;
3473 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
3475 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3479 n->removeType = OBJECT_TRIGGER;
3480 n->missing_ok = true;
3486 /*****************************************************************************
3489 * CREATE ASSERTION ...
3490 * DROP ASSERTION ...
3492 *****************************************************************************/
3495 CREATE ASSERTION name CHECK '(' a_expr ')'
3496 ConstraintAttributeSpec
3498 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3500 n->args = list_make1($6);
3501 n->isconstraint = TRUE;
3502 n->deferrable = ($8 & 1) != 0;
3503 n->initdeferred = ($8 & 2) != 0;
3506 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3507 errmsg("CREATE ASSERTION is not yet implemented")));
3514 DROP ASSERTION name opt_drop_behavior
3516 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3520 n->removeType = OBJECT_TRIGGER; /* XXX */
3522 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3523 errmsg("DROP ASSERTION is not yet implemented")));
3529 /*****************************************************************************
3532 * define (aggregate,operator,type)
3534 *****************************************************************************/
3537 CREATE AGGREGATE func_name aggr_args definition
3539 DefineStmt *n = makeNode(DefineStmt);
3540 n->kind = OBJECT_AGGREGATE;
3541 n->oldstyle = false;
3547 | CREATE AGGREGATE func_name old_aggr_definition
3549 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
3550 DefineStmt *n = makeNode(DefineStmt);
3551 n->kind = OBJECT_AGGREGATE;
3558 | CREATE OPERATOR any_operator definition
3560 DefineStmt *n = makeNode(DefineStmt);
3561 n->kind = OBJECT_OPERATOR;
3562 n->oldstyle = false;
3568 | CREATE TYPE_P any_name definition
3570 DefineStmt *n = makeNode(DefineStmt);
3571 n->kind = OBJECT_TYPE;
3572 n->oldstyle = false;
3578 | CREATE TYPE_P any_name
3580 /* Shell type (identified by lack of definition) */
3581 DefineStmt *n = makeNode(DefineStmt);
3582 n->kind = OBJECT_TYPE;
3583 n->oldstyle = false;
3586 n->definition = NIL;
3589 | CREATE TYPE_P any_name AS '(' TableFuncElementList ')'
3591 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
3592 RangeVar *r = makeNode(RangeVar);
3594 /* can't use qualified_name, sigh */
3595 switch (list_length($3))
3598 r->catalogname = NULL;
3599 r->schemaname = NULL;
3600 r->relname = strVal(linitial($3));
3603 r->catalogname = NULL;
3604 r->schemaname = strVal(linitial($3));
3605 r->relname = strVal(lsecond($3));
3608 r->catalogname = strVal(linitial($3));
3609 r->schemaname = strVal(lsecond($3));
3610 r->relname = strVal(lthird($3));
3614 (errcode(ERRCODE_SYNTAX_ERROR),
3615 errmsg("improper qualified name (too many dotted names): %s",
3616 NameListToString($3)),
3617 parser_errposition(@3)));
3625 | CREATE TYPE_P any_name AS ENUM_P '(' enum_val_list ')'
3627 CreateEnumStmt *n = makeNode(CreateEnumStmt);
3632 | CREATE TEXT_P SEARCH PARSER any_name definition
3634 DefineStmt *n = makeNode(DefineStmt);
3635 n->kind = OBJECT_TSPARSER;
3641 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
3643 DefineStmt *n = makeNode(DefineStmt);
3644 n->kind = OBJECT_TSDICTIONARY;
3650 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
3652 DefineStmt *n = makeNode(DefineStmt);
3653 n->kind = OBJECT_TSTEMPLATE;
3659 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
3661 DefineStmt *n = makeNode(DefineStmt);
3662 n->kind = OBJECT_TSCONFIGURATION;
3670 definition: '(' def_list ')' { $$ = $2; }
3673 def_list: def_elem { $$ = list_make1($1); }
3674 | def_list ',' def_elem { $$ = lappend($1, $3); }
3677 def_elem: ColLabel '=' def_arg
3679 $$ = makeDefElem($1, (Node *) $3);
3683 $$ = makeDefElem($1, NULL);
3687 /* Note: any simple identifier will be returned as a type name! */
3688 def_arg: func_type { $$ = (Node *)$1; }
3689 | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
3690 | qual_all_Op { $$ = (Node *)$1; }
3691 | NumericOnly { $$ = (Node *)$1; }
3692 | Sconst { $$ = (Node *)makeString($1); }
3695 aggr_args: '(' type_list ')' { $$ = $2; }
3696 | '(' '*' ')' { $$ = NIL; }
3699 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
3702 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
3703 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
3707 * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
3708 * the item names needed in old aggregate definitions are likely to become
3711 old_aggr_elem: IDENT '=' def_arg
3713 $$ = makeDefElem($1, (Node *)$3);
3717 enum_val_list: Sconst
3718 { $$ = list_make1(makeString($1)); }
3719 | enum_val_list ',' Sconst
3720 { $$ = lappend($1, makeString($3)); }
3724 /*****************************************************************************
3727 * CREATE OPERATOR CLASS ...
3728 * CREATE OPERATOR FAMILY ...
3729 * ALTER OPERATOR FAMILY ...
3730 * DROP OPERATOR CLASS ...
3731 * DROP OPERATOR FAMILY ...
3733 *****************************************************************************/
3736 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
3737 USING access_method opt_opfamily AS opclass_item_list
3739 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
3740 n->opclassname = $4;
3744 n->opfamilyname = $11;
3751 opclass_item { $$ = list_make1($1); }
3752 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
3756 OPERATOR Iconst any_operator opt_recheck
3758 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3759 n->itemtype = OPCLASS_ITEM_OPERATOR;
3765 | OPERATOR Iconst any_operator oper_argtypes opt_recheck
3767 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3768 n->itemtype = OPCLASS_ITEM_OPERATOR;
3774 | FUNCTION Iconst func_name func_args
3776 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3777 n->itemtype = OPCLASS_ITEM_FUNCTION;
3779 n->args = extractArgTypes($4);
3783 | FUNCTION Iconst '(' type_list ')' func_name func_args
3785 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3786 n->itemtype = OPCLASS_ITEM_FUNCTION;
3788 n->args = extractArgTypes($7);
3795 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3796 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
3802 opt_default: DEFAULT { $$ = TRUE; }
3803 | /*EMPTY*/ { $$ = FALSE; }
3806 opt_opfamily: FAMILY any_name { $$ = $2; }
3807 | /*EMPTY*/ { $$ = NIL; }
3810 opt_recheck: RECHECK
3813 * RECHECK no longer does anything in opclass definitions,
3814 * but we still accept it to ease porting of old database
3818 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3819 errmsg("RECHECK is no longer required"),
3820 errhint("Update your data type."),
3821 parser_errposition(@1)));
3824 | /*EMPTY*/ { $$ = FALSE; }
3829 CREATE OPERATOR FAMILY any_name USING access_method
3831 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
3832 n->opfamilyname = $4;
3839 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
3841 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3842 n->opfamilyname = $4;
3848 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
3850 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3851 n->opfamilyname = $4;
3860 opclass_drop { $$ = list_make1($1); }
3861 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
3865 OPERATOR Iconst '(' type_list ')'
3867 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3868 n->itemtype = OPCLASS_ITEM_OPERATOR;
3873 | FUNCTION Iconst '(' type_list ')'
3875 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3876 n->itemtype = OPCLASS_ITEM_FUNCTION;
3885 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
3887 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3888 n->opclassname = $4;
3891 n->missing_ok = false;
3894 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
3896 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3897 n->opclassname = $6;
3900 n->missing_ok = true;
3906 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
3908 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3909 n->opfamilyname = $4;
3912 n->missing_ok = false;
3915 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
3917 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3918 n->opfamilyname = $6;
3921 n->missing_ok = true;
3927 /*****************************************************************************
3931 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
3932 * REASSIGN OWNED BY username [, username ...] TO username
3934 *****************************************************************************/
3936 DROP OWNED BY name_list opt_drop_behavior
3938 DropOwnedStmt *n = makeNode(DropOwnedStmt);
3946 REASSIGN OWNED BY name_list TO name
3948 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
3955 /*****************************************************************************
3959 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
3960 * [ RESTRICT | CASCADE ]
3962 *****************************************************************************/
3964 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
3966 DropStmt *n = makeNode(DropStmt);
3968 n->missing_ok = TRUE;
3973 | DROP drop_type any_name_list opt_drop_behavior
3975 DropStmt *n = makeNode(DropStmt);
3977 n->missing_ok = FALSE;
3985 drop_type: TABLE { $$ = OBJECT_TABLE; }
3986 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
3987 | VIEW { $$ = OBJECT_VIEW; }
3988 | INDEX { $$ = OBJECT_INDEX; }
3989 | TYPE_P { $$ = OBJECT_TYPE; }
3990 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
3991 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
3992 | SCHEMA { $$ = OBJECT_SCHEMA; }
3993 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
3994 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
3995 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
3996 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
4000 any_name { $$ = list_make1($1); }
4001 | any_name_list ',' any_name { $$ = lappend($1, $3); }
4004 any_name: ColId { $$ = list_make1(makeString($1)); }
4005 | ColId attrs { $$ = lcons(makeString($1), $2); }
4008 attrs: '.' attr_name
4009 { $$ = list_make1(makeString($2)); }
4010 | attrs '.' attr_name
4011 { $$ = lappend($1, makeString($3)); }
4015 /*****************************************************************************
4018 * truncate table relname1, relname2, ...
4020 *****************************************************************************/
4023 TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
4025 TruncateStmt *n = makeNode(TruncateStmt);
4027 n->restart_seqs = $4;
4034 CONTINUE_P IDENTITY_P { $$ = false; }
4035 | RESTART IDENTITY_P { $$ = true; }
4036 | /* EMPTY */ { $$ = false; }
4039 /*****************************************************************************
4041 * The COMMENT ON statement can take different forms based upon the type of
4042 * the object associated with the comment. The form of the statement is:
4044 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
4045 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
4046 * CAST | COLUMN | SCHEMA | TABLESPACE | ROLE |
4047 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
4048 * TEXT SEARCH TEMPLATE |
4049 * TEXT SEARCH CONFIGURATION ] <objname> |
4050 * AGGREGATE <aggname> (arg1, ...) |
4051 * FUNCTION <funcname> (arg1, arg2, ...) |
4052 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
4053 * TRIGGER <triggername> ON <relname> |
4054 * CONSTRAINT <constraintname> ON <relname> |
4055 * RULE <rulename> ON <relname> ]
4058 *****************************************************************************/
4061 COMMENT ON comment_type any_name IS comment_text
4063 CommentStmt *n = makeNode(CommentStmt);
4070 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
4072 CommentStmt *n = makeNode(CommentStmt);
4073 n->objtype = OBJECT_AGGREGATE;
4079 | COMMENT ON FUNCTION func_name func_args IS comment_text
4081 CommentStmt *n = makeNode(CommentStmt);
4082 n->objtype = OBJECT_FUNCTION;
4084 n->objargs = extractArgTypes($5);
4088 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
4090 CommentStmt *n = makeNode(CommentStmt);
4091 n->objtype = OBJECT_OPERATOR;
4097 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
4099 CommentStmt *n = makeNode(CommentStmt);
4100 n->objtype = OBJECT_CONSTRAINT;
4101 n->objname = lappend($6, makeString($4));
4106 | COMMENT ON RULE name ON any_name IS comment_text
4108 CommentStmt *n = makeNode(CommentStmt);
4109 n->objtype = OBJECT_RULE;
4110 n->objname = lappend($6, makeString($4));
4115 | COMMENT ON RULE name IS comment_text
4117 /* Obsolete syntax supported for awhile for compatibility */
4118 CommentStmt *n = makeNode(CommentStmt);
4119 n->objtype = OBJECT_RULE;
4120 n->objname = list_make1(makeString($4));
4125 | COMMENT ON TRIGGER name ON any_name IS comment_text
4127 CommentStmt *n = makeNode(CommentStmt);
4128 n->objtype = OBJECT_TRIGGER;
4129 n->objname = lappend($6, makeString($4));
4134 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
4136 CommentStmt *n = makeNode(CommentStmt);
4137 n->objtype = OBJECT_OPCLASS;
4139 n->objargs = list_make1(makeString($7));
4143 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
4145 CommentStmt *n = makeNode(CommentStmt);
4146 n->objtype = OBJECT_OPFAMILY;
4148 n->objargs = list_make1(makeString($7));
4152 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
4154 CommentStmt *n = makeNode(CommentStmt);
4155 n->objtype = OBJECT_LARGEOBJECT;
4156 n->objname = list_make1($5);
4161 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
4163 CommentStmt *n = makeNode(CommentStmt);
4164 n->objtype = OBJECT_CAST;
4165 n->objname = list_make1($5);
4166 n->objargs = list_make1($7);
4170 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
4172 CommentStmt *n = makeNode(CommentStmt);
4173 n->objtype = OBJECT_LANGUAGE;
4179 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
4181 CommentStmt *n = makeNode(CommentStmt);
4182 n->objtype = OBJECT_TSPARSER;
4187 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
4189 CommentStmt *n = makeNode(CommentStmt);
4190 n->objtype = OBJECT_TSDICTIONARY;
4195 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
4197 CommentStmt *n = makeNode(CommentStmt);
4198 n->objtype = OBJECT_TSTEMPLATE;
4203 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
4205 CommentStmt *n = makeNode(CommentStmt);
4206 n->objtype = OBJECT_TSCONFIGURATION;
4214 COLUMN { $$ = OBJECT_COLUMN; }
4215 | DATABASE { $$ = OBJECT_DATABASE; }
4216 | SCHEMA { $$ = OBJECT_SCHEMA; }
4217 | INDEX { $$ = OBJECT_INDEX; }
4218 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4219 | TABLE { $$ = OBJECT_TABLE; }
4220 | DOMAIN_P { $$ = OBJECT_TYPE; }
4221 | TYPE_P { $$ = OBJECT_TYPE; }
4222 | VIEW { $$ = OBJECT_VIEW; }
4223 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4224 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
4225 | ROLE { $$ = OBJECT_ROLE; }
4230 | NULL_P { $$ = NULL; }
4233 /*****************************************************************************
4238 *****************************************************************************/
4240 FetchStmt: FETCH fetch_args
4242 FetchStmt *n = (FetchStmt *) $2;
4248 FetchStmt *n = (FetchStmt *) $2;
4254 fetch_args: cursor_name
4256 FetchStmt *n = makeNode(FetchStmt);
4258 n->direction = FETCH_FORWARD;
4262 | from_in cursor_name
4264 FetchStmt *n = makeNode(FetchStmt);
4266 n->direction = FETCH_FORWARD;
4270 | NEXT opt_from_in cursor_name
4272 FetchStmt *n = makeNode(FetchStmt);
4274 n->direction = FETCH_FORWARD;
4278 | PRIOR opt_from_in cursor_name
4280 FetchStmt *n = makeNode(FetchStmt);
4282 n->direction = FETCH_BACKWARD;
4286 | FIRST_P opt_from_in cursor_name
4288 FetchStmt *n = makeNode(FetchStmt);
4290 n->direction = FETCH_ABSOLUTE;
4294 | LAST_P opt_from_in cursor_name
4296 FetchStmt *n = makeNode(FetchStmt);
4298 n->direction = FETCH_ABSOLUTE;
4302 | ABSOLUTE_P SignedIconst opt_from_in cursor_name
4304 FetchStmt *n = makeNode(FetchStmt);
4306 n->direction = FETCH_ABSOLUTE;
4310 | RELATIVE_P SignedIconst opt_from_in cursor_name
4312 FetchStmt *n = makeNode(FetchStmt);
4314 n->direction = FETCH_RELATIVE;
4318 | SignedIconst opt_from_in cursor_name
4320 FetchStmt *n = makeNode(FetchStmt);
4322 n->direction = FETCH_FORWARD;
4326 | ALL opt_from_in cursor_name
4328 FetchStmt *n = makeNode(FetchStmt);
4330 n->direction = FETCH_FORWARD;
4331 n->howMany = FETCH_ALL;
4334 | FORWARD opt_from_in cursor_name
4336 FetchStmt *n = makeNode(FetchStmt);
4338 n->direction = FETCH_FORWARD;
4342 | FORWARD SignedIconst opt_from_in cursor_name
4344 FetchStmt *n = makeNode(FetchStmt);
4346 n->direction = FETCH_FORWARD;
4350 | FORWARD ALL opt_from_in cursor_name
4352 FetchStmt *n = makeNode(FetchStmt);
4354 n->direction = FETCH_FORWARD;
4355 n->howMany = FETCH_ALL;
4358 | BACKWARD opt_from_in cursor_name
4360 FetchStmt *n = makeNode(FetchStmt);
4362 n->direction = FETCH_BACKWARD;
4366 | BACKWARD SignedIconst opt_from_in cursor_name
4368 FetchStmt *n = makeNode(FetchStmt);
4370 n->direction = FETCH_BACKWARD;
4374 | BACKWARD ALL opt_from_in cursor_name
4376 FetchStmt *n = makeNode(FetchStmt);
4378 n->direction = FETCH_BACKWARD;
4379 n->howMany = FETCH_ALL;
4388 opt_from_in: from_in {}
4393 /*****************************************************************************
4395 * GRANT and REVOKE statements
4397 *****************************************************************************/
4399 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
4400 opt_grant_grant_option
4402 GrantStmt *n = makeNode(GrantStmt);
4405 n->targtype = ($4)->targtype;
4406 n->objtype = ($4)->objtype;
4407 n->objects = ($4)->objs;
4409 n->grant_option = $7;
4415 REVOKE privileges ON privilege_target
4416 FROM grantee_list opt_drop_behavior
4418 GrantStmt *n = makeNode(GrantStmt);
4419 n->is_grant = false;
4420 n->grant_option = false;
4422 n->targtype = ($4)->targtype;
4423 n->objtype = ($4)->objtype;
4424 n->objects = ($4)->objs;
4429 | REVOKE GRANT OPTION FOR privileges ON privilege_target
4430 FROM grantee_list opt_drop_behavior
4432 GrantStmt *n = makeNode(GrantStmt);
4433 n->is_grant = false;
4434 n->grant_option = true;
4436 n->targtype = ($7)->targtype;
4437 n->objtype = ($7)->objtype;
4438 n->objects = ($7)->objs;
4447 * Privilege names are represented as strings; the validity of the privilege
4448 * names gets checked at execution. This is a bit annoying but we have little
4449 * choice because of the syntactic conflict with lists of role names in
4450 * GRANT/REVOKE. What's more, we have to call out in the "privilege"
4451 * production any reserved keywords that need to be usable as privilege names.
4454 /* either ALL [PRIVILEGES] or a list of individual privileges */
4455 privileges: privilege_list
4461 | ALL '(' columnList ')'
4463 AccessPriv *n = makeNode(AccessPriv);
4464 n->priv_name = NULL;
4468 | ALL PRIVILEGES '(' columnList ')'
4470 AccessPriv *n = makeNode(AccessPriv);
4471 n->priv_name = NULL;
4477 privilege_list: privilege { $$ = list_make1($1); }
4478 | privilege_list ',' privilege { $$ = lappend($1, $3); }
4481 privilege: SELECT opt_column_list
4483 AccessPriv *n = makeNode(AccessPriv);
4484 n->priv_name = pstrdup($1);
4488 | REFERENCES opt_column_list
4490 AccessPriv *n = makeNode(AccessPriv);
4491 n->priv_name = pstrdup($1);
4495 | CREATE opt_column_list
4497 AccessPriv *n = makeNode(AccessPriv);
4498 n->priv_name = pstrdup($1);
4502 | ColId opt_column_list
4504 AccessPriv *n = makeNode(AccessPriv);
4512 /* Don't bother trying to fold the first two rules into one using
4513 * opt_table. You're going to get conflicts.
4518 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4519 n->targtype = ACL_TARGET_OBJECT;
4520 n->objtype = ACL_OBJECT_RELATION;
4524 | TABLE qualified_name_list
4526 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4527 n->targtype = ACL_TARGET_OBJECT;
4528 n->objtype = ACL_OBJECT_RELATION;
4532 | SEQUENCE qualified_name_list
4534 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4535 n->targtype = ACL_TARGET_OBJECT;
4536 n->objtype = ACL_OBJECT_SEQUENCE;
4540 | FOREIGN DATA_P WRAPPER name_list
4542 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4543 n->targtype = ACL_TARGET_OBJECT;
4544 n->objtype = ACL_OBJECT_FDW;
4548 | FOREIGN SERVER name_list
4550 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4551 n->targtype = ACL_TARGET_OBJECT;
4552 n->objtype = ACL_OBJECT_FOREIGN_SERVER;
4556 | FUNCTION function_with_argtypes_list
4558 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4559 n->targtype = ACL_TARGET_OBJECT;
4560 n->objtype = ACL_OBJECT_FUNCTION;
4564 | DATABASE name_list
4566 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4567 n->targtype = ACL_TARGET_OBJECT;
4568 n->objtype = ACL_OBJECT_DATABASE;
4572 | LANGUAGE name_list
4574 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4575 n->targtype = ACL_TARGET_OBJECT;
4576 n->objtype = ACL_OBJECT_LANGUAGE;
4580 | LARGE_P OBJECT_P Iconst_list
4582 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4583 n->targtype = ACL_TARGET_OBJECT;
4584 n->objtype = ACL_OBJECT_LARGEOBJECT;
4590 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4591 n->targtype = ACL_TARGET_OBJECT;
4592 n->objtype = ACL_OBJECT_NAMESPACE;
4596 | TABLESPACE name_list
4598 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4599 n->targtype = ACL_TARGET_OBJECT;
4600 n->objtype = ACL_OBJECT_TABLESPACE;
4604 | ALL TABLES IN_P SCHEMA name_list
4606 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4607 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4608 n->objtype = ACL_OBJECT_RELATION;
4612 | ALL SEQUENCES IN_P SCHEMA name_list
4614 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4615 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4616 n->objtype = ACL_OBJECT_SEQUENCE;
4620 | ALL FUNCTIONS IN_P SCHEMA name_list
4622 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4623 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4624 n->objtype = ACL_OBJECT_FUNCTION;
4632 grantee { $$ = list_make1($1); }
4633 | grantee_list ',' grantee { $$ = lappend($1, $3); }
4638 PrivGrantee *n = makeNode(PrivGrantee);
4639 /* This hack lets us avoid reserving PUBLIC as a keyword*/
4640 if (strcmp($1, "public") == 0)
4648 PrivGrantee *n = makeNode(PrivGrantee);
4649 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
4650 if (strcmp($2, "public") == 0)
4659 opt_grant_grant_option:
4660 WITH GRANT OPTION { $$ = TRUE; }
4661 | /*EMPTY*/ { $$ = FALSE; }
4664 function_with_argtypes_list:
4665 function_with_argtypes { $$ = list_make1($1); }
4666 | function_with_argtypes_list ',' function_with_argtypes
4667 { $$ = lappend($1, $3); }
4670 function_with_argtypes:
4673 FuncWithArgs *n = makeNode(FuncWithArgs);
4675 n->funcargs = extractArgTypes($2);
4680 /*****************************************************************************
4682 * GRANT and REVOKE ROLE statements
4684 *****************************************************************************/
4687 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4689 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4691 n->granted_roles = $2;
4692 n->grantee_roles = $4;
4700 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4702 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4703 n->is_grant = false;
4704 n->admin_opt = false;
4705 n->granted_roles = $2;
4706 n->grantee_roles = $4;
4710 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4712 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4713 n->is_grant = false;
4714 n->admin_opt = true;
4715 n->granted_roles = $5;
4716 n->grantee_roles = $7;
4722 opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
4723 | /*EMPTY*/ { $$ = FALSE; }
4726 opt_granted_by: GRANTED BY RoleId { $$ = $3; }
4727 | /*EMPTY*/ { $$ = NULL; }
4730 /*****************************************************************************
4732 * ALTER DEFAULT PRIVILEGES statement
4734 *****************************************************************************/
4736 AlterDefaultPrivilegesStmt:
4737 ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
4739 AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
4741 n->action = (GrantStmt *) $5;
4747 DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
4748 | /* EMPTY */ { $$ = NIL; }
4752 IN_P SCHEMA name_list
4754 $$ = makeDefElem("schemas", (Node *)$3);
4756 | FOR ROLE name_list
4758 $$ = makeDefElem("roles", (Node *)$3);
4760 | FOR USER name_list
4762 $$ = makeDefElem("roles", (Node *)$3);
4767 * This should match GRANT/REVOKE, except that individual target objects
4768 * are not mentioned and we only allow a subset of object types.
4771 GRANT privileges ON defacl_privilege_target TO grantee_list
4772 opt_grant_grant_option
4774 GrantStmt *n = makeNode(GrantStmt);
4777 n->targtype = ACL_TARGET_DEFAULTS;
4781 n->grant_option = $7;
4784 | REVOKE privileges ON defacl_privilege_target
4785 FROM grantee_list opt_drop_behavior
4787 GrantStmt *n = makeNode(GrantStmt);
4788 n->is_grant = false;
4789 n->grant_option = false;
4791 n->targtype = ACL_TARGET_DEFAULTS;
4798 | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
4799 FROM grantee_list opt_drop_behavior
4801 GrantStmt *n = makeNode(GrantStmt);
4802 n->is_grant = false;
4803 n->grant_option = true;
4805 n->targtype = ACL_TARGET_DEFAULTS;
4814 defacl_privilege_target:
4815 TABLES { $$ = ACL_OBJECT_RELATION; }
4816 | FUNCTIONS { $$ = ACL_OBJECT_FUNCTION; }
4817 | SEQUENCES { $$ = ACL_OBJECT_SEQUENCE; }
4821 /*****************************************************************************
4823 * QUERY: CREATE INDEX
4825 * Note: we can't factor CONCURRENTLY into a separate production without
4826 * making it a reserved word.
4828 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
4829 * willing to make TABLESPACE a fully reserved word.
4830 *****************************************************************************/
4832 IndexStmt: CREATE index_opt_unique INDEX index_name
4833 ON qualified_name access_method_clause '(' index_params ')'
4834 opt_reloptions OptTableSpace where_clause
4836 IndexStmt *n = makeNode(IndexStmt);
4838 n->concurrent = false;
4841 n->accessMethod = $7;
4842 n->indexParams = $9;
4844 n->tableSpace = $12;
4845 n->whereClause = $13;
4848 | CREATE index_opt_unique INDEX CONCURRENTLY index_name
4849 ON qualified_name access_method_clause '(' index_params ')'
4850 opt_reloptions OptTableSpace where_clause
4852 IndexStmt *n = makeNode(IndexStmt);
4854 n->concurrent = true;
4857 n->accessMethod = $8;
4858 n->indexParams = $10;
4860 n->tableSpace = $13;
4861 n->whereClause = $14;
4867 UNIQUE { $$ = TRUE; }
4868 | /*EMPTY*/ { $$ = FALSE; }
4871 access_method_clause:
4872 USING access_method { $$ = $2; }
4873 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
4876 index_params: index_elem { $$ = list_make1($1); }
4877 | index_params ',' index_elem { $$ = lappend($1, $3); }
4881 * Index attributes can be either simple column references, or arbitrary
4882 * expressions in parens. For backwards-compatibility reasons, we allow
4883 * an expression that's just a function call to be written without parens.
4885 index_elem: ColId opt_class opt_asc_desc opt_nulls_order
4887 $$ = makeNode(IndexElem);
4892 $$->nulls_ordering = $4;
4894 | func_expr opt_class opt_asc_desc opt_nulls_order
4896 $$ = makeNode(IndexElem);
4901 $$->nulls_ordering = $4;
4903 | '(' a_expr ')' opt_class opt_asc_desc opt_nulls_order
4905 $$ = makeNode(IndexElem);
4910 $$->nulls_ordering = $6;
4914 opt_class: any_name { $$ = $1; }
4915 | USING any_name { $$ = $2; }
4916 | /*EMPTY*/ { $$ = NIL; }
4919 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
4920 | DESC { $$ = SORTBY_DESC; }
4921 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
4924 opt_nulls_order: NULLS_FIRST { $$ = SORTBY_NULLS_FIRST; }
4925 | NULLS_LAST { $$ = SORTBY_NULLS_LAST; }
4926 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
4930 /*****************************************************************************
4933 * create [or replace] function <fname>
4934 * [(<type-1> { , <type-n>})]
4936 * as <filename or code in language as appropriate>
4937 * language <lang> [with parameters]
4939 *****************************************************************************/
4942 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4943 RETURNS func_return createfunc_opt_list opt_definition
4945 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4954 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4955 RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
4957 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4960 n->parameters = mergeTableFuncParameters($5, $9);
4961 n->returnType = TableFuncTypeName($9);
4962 n->returnType->location = @7;
4964 n->withClause = $12;
4967 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4968 createfunc_opt_list opt_definition
4970 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4974 n->returnType = NULL;
4982 OR REPLACE { $$ = TRUE; }
4983 | /*EMPTY*/ { $$ = FALSE; }
4986 func_args: '(' func_args_list ')' { $$ = $2; }
4987 | '(' ')' { $$ = NIL; }
4991 func_arg { $$ = list_make1($1); }
4992 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
4996 * func_args_with_defaults is separate because we only want to accept
4997 * defaults in CREATE FUNCTION, not in ALTER etc.
4999 func_args_with_defaults:
5000 '(' func_args_with_defaults_list ')' { $$ = $2; }
5001 | '(' ')' { $$ = NIL; }
5004 func_args_with_defaults_list:
5005 func_arg_with_default { $$ = list_make1($1); }
5006 | func_args_with_defaults_list ',' func_arg_with_default
5007 { $$ = lappend($1, $3); }
5011 * The style with arg_class first is SQL99 standard, but Oracle puts
5012 * param_name first; accept both since it's likely people will try both
5013 * anyway. Don't bother trying to save productions by letting arg_class
5014 * have an empty alternative ... you'll get shift/reduce conflicts.
5016 * We can catch over-specified arguments here if we want to,
5017 * but for now better to silently swallow typmod, etc.
5018 * - thomas 2000-03-22
5021 arg_class param_name func_type
5023 FunctionParameter *n = makeNode(FunctionParameter);
5030 | param_name arg_class func_type
5032 FunctionParameter *n = makeNode(FunctionParameter);
5039 | param_name func_type
5041 FunctionParameter *n = makeNode(FunctionParameter);
5044 n->mode = FUNC_PARAM_IN;
5048 | arg_class func_type
5050 FunctionParameter *n = makeNode(FunctionParameter);
5059 FunctionParameter *n = makeNode(FunctionParameter);
5062 n->mode = FUNC_PARAM_IN;
5068 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
5069 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
5070 | OUT_P { $$ = FUNC_PARAM_OUT; }
5071 | INOUT { $$ = FUNC_PARAM_INOUT; }
5072 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
5073 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
5077 * Ideally param_name should be ColId, but that causes too many conflicts.
5079 param_name: type_function_name
5085 /* We can catch over-specified results here if we want to,
5086 * but for now better to silently swallow typmod, etc.
5087 * - thomas 2000-03-22
5094 * We would like to make the %TYPE productions here be ColId attrs etc,
5095 * but that causes reduce/reduce conflicts. type_function_name
5096 * is next best choice.
5098 func_type: Typename { $$ = $1; }
5099 | type_function_name attrs '%' TYPE_P
5101 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
5102 $$->pct_type = true;
5105 | SETOF type_function_name attrs '%' TYPE_P
5107 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
5108 $$->pct_type = true;
5114 func_arg_with_default:
5119 | func_arg DEFAULT a_expr
5124 | func_arg '=' a_expr
5132 createfunc_opt_list:
5133 /* Must be at least one to prevent conflict */
5134 createfunc_opt_item { $$ = list_make1($1); }
5135 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
5139 * Options common to both CREATE FUNCTION and ALTER FUNCTION
5141 common_func_opt_item:
5142 CALLED ON NULL_P INPUT_P
5144 $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
5146 | RETURNS NULL_P ON NULL_P INPUT_P
5148 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5152 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5156 $$ = makeDefElem("volatility", (Node *)makeString("immutable"));
5160 $$ = makeDefElem("volatility", (Node *)makeString("stable"));
5164 $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
5166 | EXTERNAL SECURITY DEFINER
5168 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5170 | EXTERNAL SECURITY INVOKER
5172 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5176 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5180 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5184 $$ = makeDefElem("cost", (Node *)$2);
5188 $$ = makeDefElem("rows", (Node *)$2);
5192 /* we abuse the normal content of a DefElem here */
5193 $$ = makeDefElem("set", (Node *)$1);
5197 createfunc_opt_item:
5200 $$ = makeDefElem("as", (Node *)$2);
5202 | LANGUAGE ColId_or_Sconst
5204 $$ = makeDefElem("language", (Node *)makeString($2));
5208 $$ = makeDefElem("window", (Node *)makeInteger(TRUE));
5210 | common_func_opt_item
5216 func_as: Sconst { $$ = list_make1(makeString($1)); }
5219 $$ = list_make2(makeString($1), makeString($3));
5224 WITH definition { $$ = $2; }
5225 | /*EMPTY*/ { $$ = NIL; }
5228 table_func_column: param_name func_type
5230 FunctionParameter *n = makeNode(FunctionParameter);
5233 n->mode = FUNC_PARAM_TABLE;
5239 table_func_column_list:
5242 $$ = list_make1($1);
5244 | table_func_column_list ',' table_func_column
5246 $$ = lappend($1, $3);
5250 /*****************************************************************************
5253 * RENAME and OWNER subcommands are already provided by the generic
5254 * ALTER infrastructure, here we just specify alterations that can
5255 * only be applied to functions.
5257 *****************************************************************************/
5259 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
5261 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
5269 /* At least one option must be specified */
5270 common_func_opt_item { $$ = list_make1($1); }
5271 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
5274 /* Ignored, merely for SQL compliance */
5281 /*****************************************************************************
5285 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
5286 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
5287 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
5289 *****************************************************************************/
5292 DROP FUNCTION func_name func_args opt_drop_behavior
5294 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5295 n->kind = OBJECT_FUNCTION;
5297 n->args = extractArgTypes($4);
5299 n->missing_ok = false;
5302 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
5304 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5305 n->kind = OBJECT_FUNCTION;
5307 n->args = extractArgTypes($6);
5309 n->missing_ok = true;
5315 DROP AGGREGATE func_name aggr_args opt_drop_behavior
5317 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5318 n->kind = OBJECT_AGGREGATE;
5322 n->missing_ok = false;
5325 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
5327 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5328 n->kind = OBJECT_AGGREGATE;
5332 n->missing_ok = true;
5338 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
5340 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5341 n->kind = OBJECT_OPERATOR;
5345 n->missing_ok = false;
5348 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
5350 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5351 n->kind = OBJECT_OPERATOR;
5355 n->missing_ok = true;
5364 (errcode(ERRCODE_SYNTAX_ERROR),
5365 errmsg("missing argument"),
5366 errhint("Use NONE to denote the missing argument of a unary operator."),
5367 parser_errposition(@3)));
5369 | '(' Typename ',' Typename ')'
5370 { $$ = list_make2($2, $4); }
5371 | '(' NONE ',' Typename ')' /* left unary */
5372 { $$ = list_make2(NULL, $4); }
5373 | '(' Typename ',' NONE ')' /* right unary */
5374 { $$ = list_make2($2, NULL); }
5379 { $$ = list_make1(makeString($1)); }
5380 | ColId '.' any_operator
5381 { $$ = lcons(makeString($1), $3); }
5384 /*****************************************************************************
5386 * DO <anonymous code block> [ LANGUAGE language ]
5388 * We use a DefElem list for future extensibility, and to allow flexibility
5389 * in the clause order.
5391 *****************************************************************************/
5393 DoStmt: DO dostmt_opt_list
5395 DoStmt *n = makeNode(DoStmt);
5402 dostmt_opt_item { $$ = list_make1($1); }
5403 | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
5409 $$ = makeDefElem("as", (Node *)makeString($1));
5411 | LANGUAGE ColId_or_Sconst
5413 $$ = makeDefElem("language", (Node *)makeString($2));
5417 /*****************************************************************************
5419 * CREATE CAST / DROP CAST
5421 *****************************************************************************/
5423 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
5424 WITH FUNCTION function_with_argtypes cast_context
5426 CreateCastStmt *n = makeNode(CreateCastStmt);
5430 n->context = (CoercionContext) $11;
5434 | CREATE CAST '(' Typename AS Typename ')'
5435 WITHOUT FUNCTION cast_context
5437 CreateCastStmt *n = makeNode(CreateCastStmt);
5441 n->context = (CoercionContext) $10;
5445 | CREATE CAST '(' Typename AS Typename ')'
5446 WITH INOUT cast_context
5448 CreateCastStmt *n = makeNode(CreateCastStmt);
5452 n->context = (CoercionContext) $10;
5458 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
5459 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
5460 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
5464 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
5466 DropCastStmt *n = makeNode(DropCastStmt);
5475 opt_if_exists: IF_P EXISTS { $$ = TRUE; }
5476 | /*EMPTY*/ { $$ = FALSE; }
5480 /*****************************************************************************
5484 * REINDEX type <name> [FORCE]
5486 * FORCE no longer does anything, but we accept it for backwards compatibility
5487 *****************************************************************************/
5490 REINDEX reindex_type qualified_name opt_force
5492 ReindexStmt *n = makeNode(ReindexStmt);
5498 | REINDEX SYSTEM_P name opt_force
5500 ReindexStmt *n = makeNode(ReindexStmt);
5501 n->kind = OBJECT_DATABASE;
5504 n->do_system = true;
5508 | REINDEX DATABASE name opt_force
5510 ReindexStmt *n = makeNode(ReindexStmt);
5511 n->kind = OBJECT_DATABASE;
5514 n->do_system = true;
5521 INDEX { $$ = OBJECT_INDEX; }
5522 | TABLE { $$ = OBJECT_TABLE; }
5525 opt_force: FORCE { $$ = TRUE; }
5526 | /* EMPTY */ { $$ = FALSE; }
5530 /*****************************************************************************
5532 * ALTER THING name RENAME TO newname
5534 *****************************************************************************/
5536 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
5538 RenameStmt *n = makeNode(RenameStmt);
5539 n->renameType = OBJECT_AGGREGATE;
5545 | ALTER CONVERSION_P any_name RENAME TO name
5547 RenameStmt *n = makeNode(RenameStmt);
5548 n->renameType = OBJECT_CONVERSION;
5553 | ALTER DATABASE database_name RENAME TO database_name
5555 RenameStmt *n = makeNode(RenameStmt);
5556 n->renameType = OBJECT_DATABASE;
5561 | ALTER FUNCTION function_with_argtypes RENAME TO name
5563 RenameStmt *n = makeNode(RenameStmt);
5564 n->renameType = OBJECT_FUNCTION;
5565 n->object = $3->funcname;
5566 n->objarg = $3->funcargs;
5570 | ALTER GROUP_P RoleId RENAME TO RoleId
5572 RenameStmt *n = makeNode(RenameStmt);
5573 n->renameType = OBJECT_ROLE;
5578 | ALTER opt_procedural LANGUAGE name RENAME TO name
5580 RenameStmt *n = makeNode(RenameStmt);
5581 n->renameType = OBJECT_LANGUAGE;
5586 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
5588 RenameStmt *n = makeNode(RenameStmt);
5589 n->renameType = OBJECT_OPCLASS;
5595 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
5597 RenameStmt *n = makeNode(RenameStmt);
5598 n->renameType = OBJECT_OPFAMILY;
5604 | ALTER SCHEMA name RENAME TO name
5606 RenameStmt *n = makeNode(RenameStmt);
5607 n->renameType = OBJECT_SCHEMA;
5612 | ALTER TABLE relation_expr RENAME TO name
5614 RenameStmt *n = makeNode(RenameStmt);
5615 n->renameType = OBJECT_TABLE;
5621 | ALTER SEQUENCE qualified_name RENAME TO name
5623 RenameStmt *n = makeNode(RenameStmt);
5624 n->renameType = OBJECT_SEQUENCE;
5630 | ALTER VIEW qualified_name RENAME TO name
5632 RenameStmt *n = makeNode(RenameStmt);
5633 n->renameType = OBJECT_VIEW;
5639 | ALTER INDEX qualified_name RENAME TO name
5641 RenameStmt *n = makeNode(RenameStmt);
5642 n->renameType = OBJECT_INDEX;
5648 | ALTER TABLE relation_expr RENAME opt_column name TO name
5650 RenameStmt *n = makeNode(RenameStmt);
5651 n->renameType = OBJECT_COLUMN;
5657 | ALTER TRIGGER name ON qualified_name RENAME TO name
5659 RenameStmt *n = makeNode(RenameStmt);
5660 n->renameType = OBJECT_TRIGGER;
5666 | ALTER ROLE RoleId RENAME TO RoleId
5668 RenameStmt *n = makeNode(RenameStmt);
5669 n->renameType = OBJECT_ROLE;
5674 | ALTER USER RoleId RENAME TO RoleId
5676 RenameStmt *n = makeNode(RenameStmt);
5677 n->renameType = OBJECT_ROLE;
5682 | ALTER TABLESPACE name RENAME TO name
5684 RenameStmt *n = makeNode(RenameStmt);
5685 n->renameType = OBJECT_TABLESPACE;
5690 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
5692 RenameStmt *n = makeNode(RenameStmt);
5693 n->renameType = OBJECT_TSPARSER;
5698 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
5700 RenameStmt *n = makeNode(RenameStmt);
5701 n->renameType = OBJECT_TSDICTIONARY;
5706 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
5708 RenameStmt *n = makeNode(RenameStmt);
5709 n->renameType = OBJECT_TSTEMPLATE;
5714 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
5716 RenameStmt *n = makeNode(RenameStmt);
5717 n->renameType = OBJECT_TSCONFIGURATION;
5722 | ALTER TYPE_P any_name RENAME TO name
5724 RenameStmt *n = makeNode(RenameStmt);
5725 n->renameType = OBJECT_TYPE;
5732 opt_column: COLUMN { $$ = COLUMN; }
5733 | /*EMPTY*/ { $$ = 0; }
5736 opt_set_data: SET DATA_P { $$ = 1; }
5737 | /*EMPTY*/ { $$ = 0; }
5740 /*****************************************************************************
5742 * ALTER THING name SET SCHEMA name
5744 *****************************************************************************/
5746 AlterObjectSchemaStmt:
5747 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
5749 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5750 n->objectType = OBJECT_AGGREGATE;
5756 | ALTER DOMAIN_P any_name SET SCHEMA name
5758 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5759 n->objectType = OBJECT_DOMAIN;
5764 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
5766 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5767 n->objectType = OBJECT_FUNCTION;
5768 n->object = $3->funcname;
5769 n->objarg = $3->funcargs;
5773 | ALTER TABLE relation_expr SET SCHEMA name
5775 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5776 n->objectType = OBJECT_TABLE;
5781 | ALTER SEQUENCE qualified_name SET SCHEMA name
5783 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5784 n->objectType = OBJECT_SEQUENCE;
5789 | ALTER VIEW qualified_name SET SCHEMA name
5791 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5792 n->objectType = OBJECT_VIEW;
5797 | ALTER TYPE_P any_name SET SCHEMA name
5799 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5800 n->objectType = OBJECT_TYPE;
5807 /*****************************************************************************
5809 * ALTER THING name OWNER TO newname
5811 *****************************************************************************/
5813 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
5815 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5816 n->objectType = OBJECT_AGGREGATE;
5822 | ALTER CONVERSION_P any_name OWNER TO RoleId
5824 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5825 n->objectType = OBJECT_CONVERSION;
5830 | ALTER DATABASE database_name OWNER TO RoleId
5832 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5833 n->objectType = OBJECT_DATABASE;
5834 n->object = list_make1(makeString($3));
5838 | ALTER DOMAIN_P any_name OWNER TO RoleId
5840 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5841 n->objectType = OBJECT_DOMAIN;
5846 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
5848 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5849 n->objectType = OBJECT_FUNCTION;
5850 n->object = $3->funcname;
5851 n->objarg = $3->funcargs;
5855 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
5857 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5858 n->objectType = OBJECT_LANGUAGE;
5859 n->object = list_make1(makeString($4));
5863 | ALTER LARGE_P OBJECT_P Iconst OWNER TO RoleId
5865 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5866 n->objectType = OBJECT_LARGEOBJECT;
5867 n->object = list_make1(makeInteger($4));
5871 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
5873 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5874 n->objectType = OBJECT_OPERATOR;
5880 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
5882 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5883 n->objectType = OBJECT_OPCLASS;
5889 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
5891 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5892 n->objectType = OBJECT_OPFAMILY;
5898 | ALTER SCHEMA name OWNER TO RoleId
5900 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5901 n->objectType = OBJECT_SCHEMA;
5902 n->object = list_make1(makeString($3));
5906 | ALTER TYPE_P any_name OWNER TO RoleId
5908 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5909 n->objectType = OBJECT_TYPE;
5914 | ALTER TABLESPACE name OWNER TO RoleId
5916 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5917 n->objectType = OBJECT_TABLESPACE;
5918 n->object = list_make1(makeString($3));
5922 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
5924 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5925 n->objectType = OBJECT_TSDICTIONARY;
5930 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
5932 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5933 n->objectType = OBJECT_TSCONFIGURATION;
5938 | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleId
5940 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5941 n->objectType = OBJECT_FDW;
5942 n->object = list_make1(makeString($5));
5946 | ALTER SERVER name OWNER TO RoleId
5948 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5949 n->objectType = OBJECT_FOREIGN_SERVER;
5950 n->object = list_make1(makeString($3));
5957 /*****************************************************************************
5959 * QUERY: Define Rewrite Rule
5961 *****************************************************************************/
5963 RuleStmt: CREATE opt_or_replace RULE name AS
5964 ON event TO qualified_name where_clause
5965 DO opt_instead RuleActionList
5967 RuleStmt *n = makeNode(RuleStmt);
5971 n->whereClause = $10;
5980 NOTHING { $$ = NIL; }
5981 | RuleActionStmt { $$ = list_make1($1); }
5982 | '(' RuleActionMulti ')' { $$ = $2; }
5985 /* the thrashing around here is to discard "empty" statements... */
5987 RuleActionMulti ';' RuleActionStmtOrEmpty
5989 $$ = lappend($1, $3);
5993 | RuleActionStmtOrEmpty
5995 $$ = list_make1($1);
6009 RuleActionStmtOrEmpty:
6010 RuleActionStmt { $$ = $1; }
6011 | /*EMPTY*/ { $$ = NULL; }
6014 event: SELECT { $$ = CMD_SELECT; }
6015 | UPDATE { $$ = CMD_UPDATE; }
6016 | DELETE_P { $$ = CMD_DELETE; }
6017 | INSERT { $$ = CMD_INSERT; }
6021 INSTEAD { $$ = TRUE; }
6022 | ALSO { $$ = FALSE; }
6023 | /*EMPTY*/ { $$ = FALSE; }
6028 DROP RULE name ON qualified_name opt_drop_behavior
6030 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6034 n->removeType = OBJECT_RULE;
6035 n->missing_ok = false;
6038 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
6040 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6044 n->removeType = OBJECT_RULE;
6045 n->missing_ok = true;
6051 /*****************************************************************************
6054 * NOTIFY <identifier> can appear both in rule bodies and
6055 * as a query-level command
6057 *****************************************************************************/
6059 NotifyStmt: NOTIFY ColId
6061 NotifyStmt *n = makeNode(NotifyStmt);
6062 n->conditionname = $2;
6067 ListenStmt: LISTEN ColId
6069 ListenStmt *n = makeNode(ListenStmt);
6070 n->conditionname = $2;
6078 UnlistenStmt *n = makeNode(UnlistenStmt);
6079 n->conditionname = $2;
6084 UnlistenStmt *n = makeNode(UnlistenStmt);
6085 n->conditionname = NULL;
6091 /*****************************************************************************
6095 * BEGIN / COMMIT / ROLLBACK
6096 * (also older versions END / ABORT)
6098 *****************************************************************************/
6101 ABORT_P opt_transaction
6103 TransactionStmt *n = makeNode(TransactionStmt);
6104 n->kind = TRANS_STMT_ROLLBACK;
6108 | BEGIN_P opt_transaction transaction_mode_list_or_empty
6110 TransactionStmt *n = makeNode(TransactionStmt);
6111 n->kind = TRANS_STMT_BEGIN;
6115 | START TRANSACTION transaction_mode_list_or_empty
6117 TransactionStmt *n = makeNode(TransactionStmt);
6118 n->kind = TRANS_STMT_START;
6122 | COMMIT opt_transaction
6124 TransactionStmt *n = makeNode(TransactionStmt);
6125 n->kind = TRANS_STMT_COMMIT;
6129 | END_P opt_transaction
6131 TransactionStmt *n = makeNode(TransactionStmt);
6132 n->kind = TRANS_STMT_COMMIT;
6136 | ROLLBACK opt_transaction
6138 TransactionStmt *n = makeNode(TransactionStmt);
6139 n->kind = TRANS_STMT_ROLLBACK;
6145 TransactionStmt *n = makeNode(TransactionStmt);
6146 n->kind = TRANS_STMT_SAVEPOINT;
6147 n->options = list_make1(makeDefElem("savepoint_name",
6148 (Node *)makeString($2)));
6151 | RELEASE SAVEPOINT ColId
6153 TransactionStmt *n = makeNode(TransactionStmt);
6154 n->kind = TRANS_STMT_RELEASE;
6155 n->options = list_make1(makeDefElem("savepoint_name",
6156 (Node *)makeString($3)));
6161 TransactionStmt *n = makeNode(TransactionStmt);
6162 n->kind = TRANS_STMT_RELEASE;
6163 n->options = list_make1(makeDefElem("savepoint_name",
6164 (Node *)makeString($2)));
6167 | ROLLBACK opt_transaction TO SAVEPOINT ColId
6169 TransactionStmt *n = makeNode(TransactionStmt);
6170 n->kind = TRANS_STMT_ROLLBACK_TO;
6171 n->options = list_make1(makeDefElem("savepoint_name",
6172 (Node *)makeString($5)));
6175 | ROLLBACK opt_transaction TO ColId
6177 TransactionStmt *n = makeNode(TransactionStmt);
6178 n->kind = TRANS_STMT_ROLLBACK_TO;
6179 n->options = list_make1(makeDefElem("savepoint_name",
6180 (Node *)makeString($4)));
6183 | PREPARE TRANSACTION Sconst
6185 TransactionStmt *n = makeNode(TransactionStmt);
6186 n->kind = TRANS_STMT_PREPARE;
6190 | COMMIT PREPARED Sconst
6192 TransactionStmt *n = makeNode(TransactionStmt);
6193 n->kind = TRANS_STMT_COMMIT_PREPARED;
6197 | ROLLBACK PREPARED Sconst
6199 TransactionStmt *n = makeNode(TransactionStmt);
6200 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
6206 opt_transaction: WORK {}
6211 transaction_mode_item:
6212 ISOLATION LEVEL iso_level
6213 { $$ = makeDefElem("transaction_isolation",
6214 makeStringConst($3, @3)); }
6216 { $$ = makeDefElem("transaction_read_only",
6217 makeIntConst(TRUE, @1)); }
6219 { $$ = makeDefElem("transaction_read_only",
6220 makeIntConst(FALSE, @1)); }
6223 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
6224 transaction_mode_list:
6225 transaction_mode_item
6226 { $$ = list_make1($1); }
6227 | transaction_mode_list ',' transaction_mode_item
6228 { $$ = lappend($1, $3); }
6229 | transaction_mode_list transaction_mode_item
6230 { $$ = lappend($1, $2); }
6233 transaction_mode_list_or_empty:
6234 transaction_mode_list
6240 /*****************************************************************************
6243 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
6244 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
6246 *****************************************************************************/
6248 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
6249 AS SelectStmt opt_check_option
6251 ViewStmt *n = makeNode(ViewStmt);
6253 n->view->istemp = $2;
6259 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
6260 AS SelectStmt opt_check_option
6262 ViewStmt *n = makeNode(ViewStmt);
6264 n->view->istemp = $4;
6276 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6277 errmsg("WITH CHECK OPTION is not implemented")));
6279 | WITH CASCADED CHECK OPTION
6282 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6283 errmsg("WITH CHECK OPTION is not implemented")));
6285 | WITH LOCAL CHECK OPTION
6288 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6289 errmsg("WITH CHECK OPTION is not implemented")));
6291 | /* EMPTY */ { $$ = NIL; }
6294 /*****************************************************************************
6299 *****************************************************************************/
6301 LoadStmt: LOAD file_name
6303 LoadStmt *n = makeNode(LoadStmt);
6310 /*****************************************************************************
6314 *****************************************************************************/
6317 CREATE DATABASE database_name opt_with createdb_opt_list
6319 CreatedbStmt *n = makeNode(CreatedbStmt);
6327 createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
6328 | /* EMPTY */ { $$ = NIL; }
6332 TABLESPACE opt_equal name
6334 $$ = makeDefElem("tablespace", (Node *)makeString($3));
6336 | TABLESPACE opt_equal DEFAULT
6338 $$ = makeDefElem("tablespace", NULL);
6340 | LOCATION opt_equal Sconst
6342 $$ = makeDefElem("location", (Node *)makeString($3));
6344 | LOCATION opt_equal DEFAULT
6346 $$ = makeDefElem("location", NULL);
6348 | TEMPLATE opt_equal name
6350 $$ = makeDefElem("template", (Node *)makeString($3));
6352 | TEMPLATE opt_equal DEFAULT
6354 $$ = makeDefElem("template", NULL);
6356 | ENCODING opt_equal Sconst
6358 $$ = makeDefElem("encoding", (Node *)makeString($3));
6360 | ENCODING opt_equal Iconst
6362 $$ = makeDefElem("encoding", (Node *)makeInteger($3));
6364 | ENCODING opt_equal DEFAULT
6366 $$ = makeDefElem("encoding", NULL);
6368 | LC_COLLATE_P opt_equal Sconst
6370 $$ = makeDefElem("lc_collate", (Node *)makeString($3));
6372 | LC_COLLATE_P opt_equal DEFAULT
6374 $$ = makeDefElem("lc_collate", NULL);
6376 | LC_CTYPE_P opt_equal Sconst
6378 $$ = makeDefElem("lc_ctype", (Node *)makeString($3));
6380 | LC_CTYPE_P opt_equal DEFAULT
6382 $$ = makeDefElem("lc_ctype", NULL);
6384 | CONNECTION LIMIT opt_equal SignedIconst
6386 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6388 | OWNER opt_equal name
6390 $$ = makeDefElem("owner", (Node *)makeString($3));
6392 | OWNER opt_equal DEFAULT
6394 $$ = makeDefElem("owner", NULL);
6399 * Though the equals sign doesn't match other WITH options, pg_dump uses
6400 * equals for backward compatibility, and it doesn't seem worth removing it.
6407 /*****************************************************************************
6411 *****************************************************************************/
6414 ALTER DATABASE database_name opt_with alterdb_opt_list
6416 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6421 | ALTER DATABASE database_name SET TABLESPACE name
6423 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6425 n->options = list_make1(makeDefElem("tablespace",
6426 (Node *)makeString($6)));
6431 AlterDatabaseSetStmt:
6432 ALTER DATABASE database_name SetResetClause
6434 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
6443 alterdb_opt_list alterdb_opt_item { $$ = lappend($1, $2); }
6444 | /* EMPTY */ { $$ = NIL; }
6448 CONNECTION LIMIT opt_equal SignedIconst
6450 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6455 /*****************************************************************************
6457 * DROP DATABASE [ IF EXISTS ]
6459 * This is implicitly CASCADE, no need for drop behavior
6460 *****************************************************************************/
6462 DropdbStmt: DROP DATABASE database_name
6464 DropdbStmt *n = makeNode(DropdbStmt);
6466 n->missing_ok = FALSE;
6469 | DROP DATABASE IF_P EXISTS database_name
6471 DropdbStmt *n = makeNode(DropdbStmt);
6473 n->missing_ok = TRUE;
6479 /*****************************************************************************
6481 * Manipulate a domain
6483 *****************************************************************************/
6486 CREATE DOMAIN_P any_name opt_as Typename ColQualList
6488 CreateDomainStmt *n = makeNode(CreateDomainStmt);
6491 n->constraints = $6;
6497 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
6498 ALTER DOMAIN_P any_name alter_column_default
6500 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6506 /* ALTER DOMAIN <domain> DROP NOT NULL */
6507 | ALTER DOMAIN_P any_name DROP NOT NULL_P
6509 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6514 /* ALTER DOMAIN <domain> SET NOT NULL */
6515 | ALTER DOMAIN_P any_name SET NOT NULL_P
6517 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6522 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
6523 | ALTER DOMAIN_P any_name ADD_P TableConstraint
6525 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6531 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
6532 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
6534 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6548 /*****************************************************************************
6550 * Manipulate a text search dictionary or configuration
6552 *****************************************************************************/
6554 AlterTSDictionaryStmt:
6555 ALTER TEXT_P SEARCH DICTIONARY any_name definition
6557 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
6564 AlterTSConfigurationStmt:
6565 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
6567 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6571 n->override = false;
6575 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
6577 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6585 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
6587 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6590 n->dicts = list_make2($9,$11);
6591 n->override = false;
6595 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
6597 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6600 n->dicts = list_make2($11,$13);
6601 n->override = false;
6605 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
6607 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6610 n->missing_ok = false;
6613 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
6615 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6618 n->missing_ok = true;
6624 /*****************************************************************************
6626 * Manipulate a conversion
6628 * CREATE [DEFAULT] CONVERSION <conversion_name>
6629 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
6631 *****************************************************************************/
6633 CreateConversionStmt:
6634 CREATE opt_default CONVERSION_P any_name FOR Sconst
6635 TO Sconst FROM any_name
6637 CreateConversionStmt *n = makeNode(CreateConversionStmt);
6638 n->conversion_name = $4;
6639 n->for_encoding_name = $6;
6640 n->to_encoding_name = $8;
6647 /*****************************************************************************
6650 * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
6652 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
6654 *****************************************************************************/
6657 CLUSTER opt_verbose qualified_name cluster_index_specification
6659 ClusterStmt *n = makeNode(ClusterStmt);
6665 | CLUSTER opt_verbose
6667 ClusterStmt *n = makeNode(ClusterStmt);
6669 n->indexname = NULL;
6673 /* kept for pre-8.3 compatibility */
6674 | CLUSTER opt_verbose index_name ON qualified_name
6676 ClusterStmt *n = makeNode(ClusterStmt);
6684 cluster_index_specification:
6685 USING index_name { $$ = $2; }
6686 | /*EMPTY*/ { $$ = NULL; }
6690 /*****************************************************************************
6696 *****************************************************************************/
6698 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
6700 VacuumStmt *n = makeNode(VacuumStmt);
6701 n->options = VACOPT_VACUUM;
6703 n->options |= VACOPT_FULL;
6705 n->options |= VACOPT_VERBOSE;
6706 n->freeze_min_age = $3 ? 0 : -1;
6707 n->freeze_table_age = $3 ? 0 : -1;
6712 | VACUUM opt_full opt_freeze opt_verbose qualified_name
6714 VacuumStmt *n = makeNode(VacuumStmt);
6715 n->options = VACOPT_VACUUM;
6717 n->options |= VACOPT_FULL;
6719 n->options |= VACOPT_VERBOSE;
6720 n->freeze_min_age = $3 ? 0 : -1;
6721 n->freeze_table_age = $3 ? 0 : -1;
6726 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
6728 VacuumStmt *n = (VacuumStmt *) $5;
6729 n->options |= VACOPT_VACUUM;
6731 n->options |= VACOPT_FULL;
6733 n->options |= VACOPT_VERBOSE;
6734 n->freeze_min_age = $3 ? 0 : -1;
6735 n->freeze_table_age = $3 ? 0 : -1;
6738 | VACUUM '(' vacuum_option_list ')'
6740 VacuumStmt *n = makeNode(VacuumStmt);
6741 n->options = VACOPT_VACUUM | $3;
6742 if (n->options & VACOPT_FREEZE)
6743 n->freeze_min_age = n->freeze_table_age = 0;
6745 n->freeze_min_age = n->freeze_table_age = -1;
6750 | VACUUM '(' vacuum_option_list ')' qualified_name opt_name_list
6752 VacuumStmt *n = makeNode(VacuumStmt);
6753 n->options = VACOPT_VACUUM | $3;
6754 if (n->options & VACOPT_FREEZE)
6755 n->freeze_min_age = n->freeze_table_age = 0;
6757 n->freeze_min_age = n->freeze_table_age = -1;
6760 if (n->va_cols != NIL) /* implies analyze */
6761 n->options |= VACOPT_ANALYZE;
6767 vacuum_option_elem { $$ = $1; }
6768 | vacuum_option_list ',' vacuum_option_elem { $$ = $1 | $3; }
6772 analyze_keyword { $$ = VACOPT_ANALYZE; }
6773 | VERBOSE { $$ = VACOPT_VERBOSE; }
6774 | FREEZE { $$ = VACOPT_FREEZE; }
6775 | FULL { $$ = VACOPT_FULL; }
6779 analyze_keyword opt_verbose
6781 VacuumStmt *n = makeNode(VacuumStmt);
6782 n->options = VACOPT_ANALYZE;
6784 n->options |= VACOPT_VERBOSE;
6785 n->freeze_min_age = -1;
6786 n->freeze_table_age = -1;
6791 | analyze_keyword opt_verbose qualified_name opt_name_list
6793 VacuumStmt *n = makeNode(VacuumStmt);
6794 n->options = VACOPT_ANALYZE;
6796 n->options |= VACOPT_VERBOSE;
6797 n->freeze_min_age = -1;
6798 n->freeze_table_age = -1;
6807 | ANALYSE /* British */ {}
6811 VERBOSE { $$ = TRUE; }
6812 | /*EMPTY*/ { $$ = FALSE; }
6815 opt_full: FULL { $$ = TRUE; }
6816 | /*EMPTY*/ { $$ = FALSE; }
6819 opt_freeze: FREEZE { $$ = TRUE; }
6820 | /*EMPTY*/ { $$ = FALSE; }
6824 '(' name_list ')' { $$ = $2; }
6825 | /*EMPTY*/ { $$ = NIL; }
6829 /*****************************************************************************
6832 * EXPLAIN [ANALYZE] [VERBOSE] query
6833 * EXPLAIN ( options ) query
6835 *****************************************************************************/
6838 EXPLAIN ExplainableStmt
6840 ExplainStmt *n = makeNode(ExplainStmt);
6845 | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
6847 ExplainStmt *n = makeNode(ExplainStmt);
6849 n->options = list_make1(makeDefElem("analyze", NULL));
6851 n->options = lappend(n->options,
6852 makeDefElem("verbose", NULL));
6855 | EXPLAIN VERBOSE ExplainableStmt
6857 ExplainStmt *n = makeNode(ExplainStmt);
6859 n->options = list_make1(makeDefElem("verbose", NULL));
6862 | EXPLAIN '(' explain_option_list ')' ExplainableStmt
6864 ExplainStmt *n = makeNode(ExplainStmt);
6878 | ExecuteStmt /* by default all are $$=$1 */
6881 explain_option_list:
6884 $$ = list_make1($1);
6886 | explain_option_list ',' explain_option_elem
6888 $$ = lappend($1, $3);
6892 explain_option_elem:
6893 explain_option_name explain_option_arg
6895 $$ = makeDefElem($1, $2);
6899 explain_option_name:
6901 | analyze_keyword { $$ = "analyze"; }
6902 | VERBOSE { $$ = "verbose"; }
6906 opt_boolean { $$ = (Node *) makeString($1); }
6907 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
6908 | NumericOnly { $$ = (Node *) $1; }
6909 | /* EMPTY */ { $$ = NULL; }
6912 /*****************************************************************************
6915 * PREPARE <plan_name> [(args, ...)] AS <query>
6917 *****************************************************************************/
6919 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
6921 PrepareStmt *n = makeNode(PrepareStmt);
6929 prep_type_clause: '(' type_list ')' { $$ = $2; }
6930 | /* EMPTY */ { $$ = NIL; }
6937 | DeleteStmt /* by default all are $$=$1 */
6940 /*****************************************************************************
6942 * EXECUTE <plan_name> [(params, ...)]
6943 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
6945 *****************************************************************************/
6947 ExecuteStmt: EXECUTE name execute_param_clause
6949 ExecuteStmt *n = makeNode(ExecuteStmt);
6955 | CREATE OptTemp TABLE create_as_target AS
6956 EXECUTE name execute_param_clause
6958 ExecuteStmt *n = makeNode(ExecuteStmt);
6961 $4->rel->istemp = $2;
6965 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6966 errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
6967 /* ... because it's not implemented, but it could be */
6972 execute_param_clause: '(' expr_list ')' { $$ = $2; }
6973 | /* EMPTY */ { $$ = NIL; }
6976 /*****************************************************************************
6979 * DEALLOCATE [PREPARE] <plan_name>
6981 *****************************************************************************/
6983 DeallocateStmt: DEALLOCATE name
6985 DeallocateStmt *n = makeNode(DeallocateStmt);
6989 | DEALLOCATE PREPARE name
6991 DeallocateStmt *n = makeNode(DeallocateStmt);
6997 DeallocateStmt *n = makeNode(DeallocateStmt);
7001 | DEALLOCATE PREPARE ALL
7003 DeallocateStmt *n = makeNode(DeallocateStmt);
7009 /*****************************************************************************
7014 *****************************************************************************/
7017 INSERT INTO qualified_name insert_rest returning_clause
7020 $4->returningList = $5;
7028 $$ = makeNode(InsertStmt);
7030 $$->selectStmt = $1;
7032 | '(' insert_column_list ')' SelectStmt
7034 $$ = makeNode(InsertStmt);
7036 $$->selectStmt = $4;
7040 $$ = makeNode(InsertStmt);
7042 $$->selectStmt = NULL;
7048 { $$ = list_make1($1); }
7049 | insert_column_list ',' insert_column_item
7050 { $$ = lappend($1, $3); }
7054 ColId opt_indirection
7056 $$ = makeNode(ResTarget);
7058 $$->indirection = check_indirection($2, yyscanner);
7065 RETURNING target_list { $$ = $2; }
7066 | /* EMPTY */ { $$ = NIL; }
7070 /*****************************************************************************
7075 *****************************************************************************/
7077 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
7078 using_clause where_or_current_clause returning_clause
7080 DeleteStmt *n = makeNode(DeleteStmt);
7082 n->usingClause = $4;
7083 n->whereClause = $5;
7084 n->returningList = $6;
7090 USING from_list { $$ = $2; }
7091 | /*EMPTY*/ { $$ = NIL; }
7095 /*****************************************************************************
7100 *****************************************************************************/
7102 LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
7104 LockStmt *n = makeNode(LockStmt);
7113 opt_lock: IN_P lock_type MODE { $$ = $2; }
7114 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
7117 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
7118 | ROW SHARE { $$ = RowShareLock; }
7119 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
7120 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
7121 | SHARE { $$ = ShareLock; }
7122 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
7123 | EXCLUSIVE { $$ = ExclusiveLock; }
7124 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
7127 opt_nowait: NOWAIT { $$ = TRUE; }
7128 | /*EMPTY*/ { $$ = FALSE; }
7132 /*****************************************************************************
7135 * UpdateStmt (UPDATE)
7137 *****************************************************************************/
7139 UpdateStmt: UPDATE relation_expr_opt_alias
7142 where_or_current_clause
7145 UpdateStmt *n = makeNode(UpdateStmt);
7149 n->whereClause = $6;
7150 n->returningList = $7;
7156 set_clause { $$ = $1; }
7157 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
7161 single_set_clause { $$ = list_make1($1); }
7162 | multiple_set_clause { $$ = $1; }
7166 set_target '=' ctext_expr
7169 $$->val = (Node *) $3;
7173 multiple_set_clause:
7174 '(' set_target_list ')' '=' ctext_row
7180 * Break the ctext_row apart, merge individual expressions
7181 * into the destination ResTargets. XXX this approach
7182 * cannot work for general row expressions as sources.
7184 if (list_length($2) != list_length($5))
7186 (errcode(ERRCODE_SYNTAX_ERROR),
7187 errmsg("number of columns does not match number of values"),
7188 parser_errposition(@1)));
7189 forboth(col_cell, $2, val_cell, $5)
7191 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
7192 Node *res_val = (Node *) lfirst(val_cell);
7194 res_col->val = res_val;
7202 ColId opt_indirection
7204 $$ = makeNode(ResTarget);
7206 $$->indirection = check_indirection($2, yyscanner);
7207 $$->val = NULL; /* upper production sets this */
7213 set_target { $$ = list_make1($1); }
7214 | set_target_list ',' set_target { $$ = lappend($1,$3); }
7218 /*****************************************************************************
7223 *****************************************************************************/
7224 DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
7226 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
7228 /* currently we always set FAST_PLAN option */
7229 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
7235 cursor_name: name { $$ = $1; }
7238 cursor_options: /*EMPTY*/ { $$ = 0; }
7239 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
7240 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
7241 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
7242 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
7245 opt_hold: /* EMPTY */ { $$ = 0; }
7246 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
7247 | WITHOUT HOLD { $$ = 0; }
7250 /*****************************************************************************
7255 *****************************************************************************/
7257 /* A complete SELECT statement looks like this.
7259 * The rule returns either a single SelectStmt node or a tree of them,
7260 * representing a set-operation tree.
7262 * There is an ambiguity when a sub-SELECT is within an a_expr and there
7263 * are excess parentheses: do the parentheses belong to the sub-SELECT or
7264 * to the surrounding a_expr? We don't really care, but bison wants to know.
7265 * To resolve the ambiguity, we are careful to define the grammar so that
7266 * the decision is staved off as long as possible: as long as we can keep
7267 * absorbing parentheses into the sub-SELECT, we will do so, and only when
7268 * it's no longer possible to do that will we decide that parens belong to
7269 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
7270 * parentheses are treated as part of the sub-select. The necessity of doing
7271 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
7272 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
7273 * SELECT viewpoint when we see the UNION.
7275 * This approach is implemented by defining a nonterminal select_with_parens,
7276 * which represents a SELECT with at least one outer layer of parentheses,
7277 * and being careful to use select_with_parens, never '(' SelectStmt ')',
7278 * in the expression grammar. We will then have shift-reduce conflicts
7279 * which we can resolve in favor of always treating '(' <select> ')' as
7280 * a select_with_parens. To resolve the conflicts, the productions that
7281 * conflict with the select_with_parens productions are manually given
7282 * precedences lower than the precedence of ')', thereby ensuring that we
7283 * shift ')' (and then reduce to select_with_parens) rather than trying to
7284 * reduce the inner <select> nonterminal to something else. We use UMINUS
7285 * precedence for this, which is a fairly arbitrary choice.
7287 * To be able to define select_with_parens itself without ambiguity, we need
7288 * a nonterminal select_no_parens that represents a SELECT structure with no
7289 * outermost parentheses. This is a little bit tedious, but it works.
7291 * In non-expression contexts, we use SelectStmt which can represent a SELECT
7292 * with or without outer parentheses.
7295 SelectStmt: select_no_parens %prec UMINUS
7296 | select_with_parens %prec UMINUS
7300 '(' select_no_parens ')' { $$ = $2; }
7301 | '(' select_with_parens ')' { $$ = $2; }
7305 * This rule parses the equivalent of the standard's <query expression>.
7306 * The duplicative productions are annoying, but hard to get rid of without
7307 * creating shift/reduce conflicts.
7309 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
7310 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
7311 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
7315 simple_select { $$ = $1; }
7316 | select_clause sort_clause
7318 insertSelectOptions((SelectStmt *) $1, $2, NIL,
7323 | select_clause opt_sort_clause for_locking_clause opt_select_limit
7325 insertSelectOptions((SelectStmt *) $1, $2, $3,
7326 list_nth($4, 0), list_nth($4, 1),
7331 | select_clause opt_sort_clause select_limit opt_for_locking_clause
7333 insertSelectOptions((SelectStmt *) $1, $2, $4,
7334 list_nth($3, 0), list_nth($3, 1),
7339 | with_clause select_clause
7341 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
7347 | with_clause select_clause sort_clause
7349 insertSelectOptions((SelectStmt *) $2, $3, NIL,
7355 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
7357 insertSelectOptions((SelectStmt *) $2, $3, $4,
7358 list_nth($5, 0), list_nth($5, 1),
7363 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
7365 insertSelectOptions((SelectStmt *) $2, $3, $5,
7366 list_nth($4, 0), list_nth($4, 1),
7374 simple_select { $$ = $1; }
7375 | select_with_parens { $$ = $1; }
7379 * This rule parses SELECT statements that can appear within set operations,
7380 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
7381 * the ordering of the set operations. Without '(' and ')' we want the
7382 * operations to be ordered per the precedence specs at the head of this file.
7384 * As with select_no_parens, simple_select cannot have outer parentheses,
7385 * but can have parenthesized subclauses.
7387 * Note that sort clauses cannot be included at this level --- SQL92 requires
7388 * SELECT foo UNION SELECT bar ORDER BY baz
7390 * (SELECT foo UNION SELECT bar) ORDER BY baz
7392 * SELECT foo UNION (SELECT bar ORDER BY baz)
7393 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
7394 * described as part of the select_no_parens production, not simple_select.
7395 * This does not limit functionality, because you can reintroduce these
7396 * clauses inside parentheses.
7398 * NOTE: only the leftmost component SelectStmt should have INTO.
7399 * However, this is not checked by the grammar; parse analysis must check it.
7402 SELECT opt_distinct target_list
7403 into_clause from_clause where_clause
7404 group_clause having_clause window_clause
7406 SelectStmt *n = makeNode(SelectStmt);
7407 n->distinctClause = $2;
7411 n->whereClause = $6;
7412 n->groupClause = $7;
7413 n->havingClause = $8;
7414 n->windowClause = $9;
7417 | values_clause { $$ = $1; }
7418 | TABLE relation_expr
7420 /* same as SELECT * FROM relation_expr */
7421 ColumnRef *cr = makeNode(ColumnRef);
7422 ResTarget *rt = makeNode(ResTarget);
7423 SelectStmt *n = makeNode(SelectStmt);
7425 cr->fields = list_make1(makeNode(A_Star));
7429 rt->indirection = NIL;
7430 rt->val = (Node *)cr;
7433 n->targetList = list_make1(rt);
7434 n->fromClause = list_make1($2);
7437 | select_clause UNION opt_all select_clause
7439 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
7441 | select_clause INTERSECT opt_all select_clause
7443 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
7445 | select_clause EXCEPT opt_all select_clause
7447 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
7452 * SQL standard WITH clause looks like:
7454 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
7455 * AS (query) [ SEARCH or CYCLE clause ]
7457 * We don't currently support the SEARCH or CYCLE clause.
7462 $$ = makeNode(WithClause);
7464 $$->recursive = false;
7467 | WITH RECURSIVE cte_list
7469 $$ = makeNode(WithClause);
7471 $$->recursive = true;
7477 common_table_expr { $$ = list_make1($1); }
7478 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
7481 common_table_expr: name opt_name_list AS select_with_parens
7483 CommonTableExpr *n = makeNode(CommonTableExpr);
7485 n->aliascolnames = $2;
7493 INTO OptTempTableName
7495 $$ = makeNode(IntoClause);
7499 $$->onCommit = ONCOMMIT_NOOP;
7500 $$->tableSpaceName = NULL;
7507 * Redundancy here is needed to avoid shift/reduce conflicts,
7508 * since TEMP is not a reserved word. See also OptTemp.
7511 TEMPORARY opt_table qualified_name
7516 | TEMP opt_table qualified_name
7521 | LOCAL TEMPORARY opt_table qualified_name
7526 | LOCAL TEMP opt_table qualified_name
7531 | GLOBAL TEMPORARY opt_table qualified_name
7536 | GLOBAL TEMP opt_table qualified_name
7541 | TABLE qualified_name
7557 opt_all: ALL { $$ = TRUE; }
7558 | DISTINCT { $$ = FALSE; }
7559 | /*EMPTY*/ { $$ = FALSE; }
7562 /* We use (NIL) as a placeholder to indicate that all target expressions
7563 * should be placed in the DISTINCT list during parsetree analysis.
7566 DISTINCT { $$ = list_make1(NIL); }
7567 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
7569 | /*EMPTY*/ { $$ = NIL; }
7573 sort_clause { $$ = $1;}
7574 | /*EMPTY*/ { $$ = NIL; }
7578 ORDER BY sortby_list { $$ = $3; }
7582 sortby { $$ = list_make1($1); }
7583 | sortby_list ',' sortby { $$ = lappend($1, $3); }
7586 sortby: a_expr USING qual_all_Op opt_nulls_order
7588 $$ = makeNode(SortBy);
7590 $$->sortby_dir = SORTBY_USING;
7591 $$->sortby_nulls = $4;
7595 | a_expr opt_asc_desc opt_nulls_order
7597 $$ = makeNode(SortBy);
7599 $$->sortby_dir = $2;
7600 $$->sortby_nulls = $3;
7602 $$->location = -1; /* no operator */
7608 limit_clause offset_clause { $$ = list_make2($2, $1); }
7609 | offset_clause limit_clause { $$ = list_make2($1, $2); }
7610 | limit_clause { $$ = list_make2(NULL, $1); }
7611 | offset_clause { $$ = list_make2($1, NULL); }
7615 select_limit { $$ = $1; }
7616 | /* EMPTY */ { $$ = list_make2(NULL,NULL); }
7620 LIMIT select_limit_value
7622 | LIMIT select_limit_value ',' select_offset_value
7624 /* Disabled because it was too confusing, bjm 2002-02-18 */
7626 (errcode(ERRCODE_SYNTAX_ERROR),
7627 errmsg("LIMIT #,# syntax is not supported"),
7628 errhint("Use separate LIMIT and OFFSET clauses."),
7629 parser_errposition(@1)));
7631 /* SQL:2008 syntax */
7632 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
7637 OFFSET select_offset_value
7639 /* SQL:2008 syntax */
7640 | OFFSET select_offset_value2 row_or_rows
7648 /* LIMIT ALL is represented as a NULL constant */
7649 $$ = makeNullAConst(@1);
7653 select_offset_value:
7658 * Allowing full expressions without parentheses causes various parsing
7659 * problems with the trailing ROW/ROWS key words. SQL only calls for
7660 * constants, so we allow the rest only with parentheses. If omitted,
7663 opt_select_fetch_first_value:
7664 SignedIconst { $$ = makeIntConst($1, @1); }
7665 | '(' a_expr ')' { $$ = $2; }
7666 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
7670 * Again, the trailing ROW/ROWS in this case prevent the full expression
7671 * syntax. c_expr is the best we can do.
7673 select_offset_value2:
7678 row_or_rows: ROW { $$ = 0; }
7682 first_or_next: FIRST_P { $$ = 0; }
7688 GROUP_P BY expr_list { $$ = $3; }
7689 | /*EMPTY*/ { $$ = NIL; }
7693 HAVING a_expr { $$ = $2; }
7694 | /*EMPTY*/ { $$ = NULL; }
7698 for_locking_items { $$ = $1; }
7699 | FOR READ ONLY { $$ = NIL; }
7702 opt_for_locking_clause:
7703 for_locking_clause { $$ = $1; }
7704 | /* EMPTY */ { $$ = NIL; }
7708 for_locking_item { $$ = list_make1($1); }
7709 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
7713 FOR UPDATE locked_rels_list opt_nowait
7715 LockingClause *n = makeNode(LockingClause);
7717 n->forUpdate = TRUE;
7721 | FOR SHARE locked_rels_list opt_nowait
7723 LockingClause *n = makeNode(LockingClause);
7725 n->forUpdate = FALSE;
7732 OF qualified_name_list { $$ = $2; }
7733 | /* EMPTY */ { $$ = NIL; }
7740 SelectStmt *n = makeNode(SelectStmt);
7741 n->valuesLists = list_make1($2);
7744 | values_clause ',' ctext_row
7746 SelectStmt *n = (SelectStmt *) $1;
7747 n->valuesLists = lappend(n->valuesLists, $3);
7753 /*****************************************************************************
7755 * clauses common to all Optimizable Stmts:
7756 * from_clause - allow list of both JOIN expressions and table names
7757 * where_clause - qualifications for joins or restrictions
7759 *****************************************************************************/
7762 FROM from_list { $$ = $2; }
7763 | /*EMPTY*/ { $$ = NIL; }
7767 table_ref { $$ = list_make1($1); }
7768 | from_list ',' table_ref { $$ = lappend($1, $3); }
7772 * table_ref is where an alias clause can be attached. Note we cannot make
7773 * alias_clause have an empty production because that causes parse conflicts
7774 * between table_ref := '(' joined_table ')' alias_clause
7775 * and joined_table := '(' joined_table ')'. So, we must have the
7776 * redundant-looking productions here instead.
7778 table_ref: relation_expr
7782 | relation_expr alias_clause
7789 RangeFunction *n = makeNode(RangeFunction);
7790 n->funccallnode = $1;
7791 n->coldeflist = NIL;
7794 | func_table alias_clause
7796 RangeFunction *n = makeNode(RangeFunction);
7797 n->funccallnode = $1;
7799 n->coldeflist = NIL;
7802 | func_table AS '(' TableFuncElementList ')'
7804 RangeFunction *n = makeNode(RangeFunction);
7805 n->funccallnode = $1;
7809 | func_table AS ColId '(' TableFuncElementList ')'
7811 RangeFunction *n = makeNode(RangeFunction);
7812 Alias *a = makeNode(Alias);
7813 n->funccallnode = $1;
7819 | func_table ColId '(' TableFuncElementList ')'
7821 RangeFunction *n = makeNode(RangeFunction);
7822 Alias *a = makeNode(Alias);
7823 n->funccallnode = $1;
7829 | select_with_parens
7832 * The SQL spec does not permit a subselect
7833 * (<derived_table>) without an alias clause,
7834 * so we don't either. This avoids the problem
7835 * of needing to invent a unique refname for it.
7836 * That could be surmounted if there's sufficient
7837 * popular demand, but for now let's just implement
7838 * the spec and see if anyone complains.
7839 * However, it does seem like a good idea to emit
7840 * an error message that's better than "syntax error".
7842 if (IsA($1, SelectStmt) &&
7843 ((SelectStmt *) $1)->valuesLists)
7845 (errcode(ERRCODE_SYNTAX_ERROR),
7846 errmsg("VALUES in FROM must have an alias"),
7847 errhint("For example, FROM (VALUES ...) [AS] foo."),
7848 parser_errposition(@1)));
7851 (errcode(ERRCODE_SYNTAX_ERROR),
7852 errmsg("subquery in FROM must have an alias"),
7853 errhint("For example, FROM (SELECT ...) [AS] foo."),
7854 parser_errposition(@1)));
7857 | select_with_parens alias_clause
7859 RangeSubselect *n = makeNode(RangeSubselect);
7868 | '(' joined_table ')' alias_clause
7877 * It may seem silly to separate joined_table from table_ref, but there is
7878 * method in SQL92's madness: if you don't do it this way you get reduce-
7879 * reduce conflicts, because it's not clear to the parser generator whether
7880 * to expect alias_clause after ')' or not. For the same reason we must
7881 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
7882 * join_type to expand to empty; if we try it, the parser generator can't
7883 * figure out when to reduce an empty join_type right after table_ref.
7885 * Note that a CROSS JOIN is the same as an unqualified
7886 * INNER JOIN, and an INNER JOIN/ON has the same shape
7887 * but a qualification expression to limit membership.
7888 * A NATURAL JOIN implicitly matches column names between
7889 * tables and the shape is determined by which columns are
7890 * in common. We'll collect columns during the later transformations.
7894 '(' joined_table ')'
7898 | table_ref CROSS JOIN table_ref
7900 /* CROSS JOIN is same as unqualified inner join */
7901 JoinExpr *n = makeNode(JoinExpr);
7902 n->jointype = JOIN_INNER;
7903 n->isNatural = FALSE;
7906 n->usingClause = NIL;
7910 | table_ref join_type JOIN table_ref join_qual
7912 JoinExpr *n = makeNode(JoinExpr);
7914 n->isNatural = FALSE;
7917 if ($5 != NULL && IsA($5, List))
7918 n->usingClause = (List *) $5; /* USING clause */
7920 n->quals = $5; /* ON clause */
7923 | table_ref JOIN table_ref join_qual
7925 /* letting join_type reduce to empty doesn't work */
7926 JoinExpr *n = makeNode(JoinExpr);
7927 n->jointype = JOIN_INNER;
7928 n->isNatural = FALSE;
7931 if ($4 != NULL && IsA($4, List))
7932 n->usingClause = (List *) $4; /* USING clause */
7934 n->quals = $4; /* ON clause */
7937 | table_ref NATURAL join_type JOIN table_ref
7939 JoinExpr *n = makeNode(JoinExpr);
7941 n->isNatural = TRUE;
7944 n->usingClause = NIL; /* figure out which columns later... */
7945 n->quals = NULL; /* fill later */
7948 | table_ref NATURAL JOIN table_ref
7950 /* letting join_type reduce to empty doesn't work */
7951 JoinExpr *n = makeNode(JoinExpr);
7952 n->jointype = JOIN_INNER;
7953 n->isNatural = TRUE;
7956 n->usingClause = NIL; /* figure out which columns later... */
7957 n->quals = NULL; /* fill later */
7963 AS ColId '(' name_list ')'
7965 $$ = makeNode(Alias);
7971 $$ = makeNode(Alias);
7974 | ColId '(' name_list ')'
7976 $$ = makeNode(Alias);
7982 $$ = makeNode(Alias);
7987 join_type: FULL join_outer { $$ = JOIN_FULL; }
7988 | LEFT join_outer { $$ = JOIN_LEFT; }
7989 | RIGHT join_outer { $$ = JOIN_RIGHT; }
7990 | INNER_P { $$ = JOIN_INNER; }
7993 /* OUTER is just noise... */
7994 join_outer: OUTER_P { $$ = NULL; }
7995 | /*EMPTY*/ { $$ = NULL; }
7998 /* JOIN qualification clauses
7999 * Possibilities are:
8000 * USING ( column list ) allows only unqualified column names,
8001 * which must match between tables.
8002 * ON expr allows more general qualifications.
8004 * We return USING as a List node, while an ON-expr will not be a List.
8007 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
8008 | ON a_expr { $$ = $2; }
8015 /* default inheritance */
8017 $$->inhOpt = INH_DEFAULT;
8020 | qualified_name '*'
8022 /* inheritance query */
8024 $$->inhOpt = INH_YES;
8027 | ONLY qualified_name
8029 /* no inheritance */
8031 $$->inhOpt = INH_NO;
8034 | ONLY '(' qualified_name ')'
8036 /* no inheritance, SQL99-style syntax */
8038 $$->inhOpt = INH_NO;
8045 relation_expr { $$ = list_make1($1); }
8046 | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
8051 * Given "UPDATE foo set set ...", we have to decide without looking any
8052 * further ahead whether the first "set" is an alias or the UPDATE's SET
8053 * keyword. Since "set" is allowed as a column name both interpretations
8054 * are feasible. We resolve the shift/reduce conflict by giving the first
8055 * relation_expr_opt_alias production a higher precedence than the SET token
8056 * has, causing the parser to prefer to reduce, in effect assuming that the
8057 * SET is not an alias.
8059 relation_expr_opt_alias: relation_expr %prec UMINUS
8063 | relation_expr ColId
8065 Alias *alias = makeNode(Alias);
8066 alias->aliasname = $2;
8070 | relation_expr AS ColId
8072 Alias *alias = makeNode(Alias);
8073 alias->aliasname = $3;
8080 func_table: func_expr { $$ = $1; }
8085 WHERE a_expr { $$ = $2; }
8086 | /*EMPTY*/ { $$ = NULL; }
8089 /* variant for UPDATE and DELETE */
8090 where_or_current_clause:
8091 WHERE a_expr { $$ = $2; }
8092 | WHERE CURRENT_P OF name
8094 CurrentOfExpr *n = makeNode(CurrentOfExpr);
8095 /* cvarno is filled in by parse analysis */
8096 n->cursor_name = $4;
8097 n->cursor_param = 0;
8100 | /*EMPTY*/ { $$ = NULL; }
8104 TableFuncElementList:
8107 $$ = list_make1($1);
8109 | TableFuncElementList ',' TableFuncElement
8111 $$ = lappend($1, $3);
8115 TableFuncElement: ColId Typename
8117 ColumnDef *n = makeNode(ColumnDef);
8120 n->constraints = NIL;
8126 /*****************************************************************************
8129 * SQL92 introduces a large amount of type-specific syntax.
8130 * Define individual clauses to handle these cases, and use
8131 * the generic case to handle regular type-extensible Postgres syntax.
8132 * - thomas 1997-10-10
8134 *****************************************************************************/
8136 Typename: SimpleTypename opt_array_bounds
8139 $$->arrayBounds = $2;
8141 | SETOF SimpleTypename opt_array_bounds
8144 $$->arrayBounds = $3;
8147 /* SQL standard syntax, currently only one-dimensional */
8148 | SimpleTypename ARRAY '[' Iconst ']'
8151 $$->arrayBounds = list_make1(makeInteger($4));
8153 | SETOF SimpleTypename ARRAY '[' Iconst ']'
8156 $$->arrayBounds = list_make1(makeInteger($5));
8159 | SimpleTypename ARRAY
8162 $$->arrayBounds = list_make1(makeInteger(-1));
8164 | SETOF SimpleTypename ARRAY
8167 $$->arrayBounds = list_make1(makeInteger(-1));
8173 opt_array_bounds '[' ']'
8174 { $$ = lappend($1, makeInteger(-1)); }
8175 | opt_array_bounds '[' Iconst ']'
8176 { $$ = lappend($1, makeInteger($3)); }
8182 GenericType { $$ = $1; }
8183 | Numeric { $$ = $1; }
8185 | Character { $$ = $1; }
8186 | ConstDatetime { $$ = $1; }
8187 | ConstInterval opt_interval
8192 | ConstInterval '(' Iconst ')' opt_interval
8197 if (list_length($5) != 1)
8199 (errcode(ERRCODE_SYNTAX_ERROR),
8200 errmsg("interval precision specified twice"),
8201 parser_errposition(@1)));
8202 $$->typmods = lappend($5, makeIntConst($3, @3));
8205 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
8206 makeIntConst($3, @3));
8210 /* We have a separate ConstTypename to allow defaulting fixed-length
8211 * types such as CHAR() and BIT() to an unspecified length.
8212 * SQL9x requires that these default to a length of one, but this
8213 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
8214 * where there is an obvious better choice to make.
8215 * Note that ConstInterval is not included here since it must
8216 * be pushed up higher in the rules to accomodate the postfix
8217 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
8218 * the generic-type-name case in AExprConst to avoid premature
8219 * reduce/reduce conflicts against function names.
8222 Numeric { $$ = $1; }
8223 | ConstBit { $$ = $1; }
8224 | ConstCharacter { $$ = $1; }
8225 | ConstDatetime { $$ = $1; }
8229 * GenericType covers all type names that don't have special syntax mandated
8230 * by the standard, including qualified names. We also allow type modifiers.
8231 * To avoid parsing conflicts against function invocations, the modifiers
8232 * have to be shown as expr_list here, but parse analysis will only accept
8233 * constants for them.
8236 type_function_name opt_type_modifiers
8238 $$ = makeTypeName($1);
8242 | type_function_name attrs opt_type_modifiers
8244 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8250 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
8251 | /* EMPTY */ { $$ = NIL; }
8255 * SQL92 numeric data types
8259 $$ = SystemTypeName("int4");
8264 $$ = SystemTypeName("int4");
8269 $$ = SystemTypeName("int2");
8274 $$ = SystemTypeName("int8");
8279 $$ = SystemTypeName("float4");
8287 | DOUBLE_P PRECISION
8289 $$ = SystemTypeName("float8");
8292 | DECIMAL_P opt_type_modifiers
8294 $$ = SystemTypeName("numeric");
8298 | DEC opt_type_modifiers
8300 $$ = SystemTypeName("numeric");
8304 | NUMERIC opt_type_modifiers
8306 $$ = SystemTypeName("numeric");
8312 $$ = SystemTypeName("bool");
8317 opt_float: '(' Iconst ')'
8320 * Check FLOAT() precision limits assuming IEEE floating
8321 * types - thomas 1997-09-18
8325 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8326 errmsg("precision for type float must be at least 1 bit"),
8327 parser_errposition(@2)));
8329 $$ = SystemTypeName("float4");
8331 $$ = SystemTypeName("float8");
8334 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8335 errmsg("precision for type float must be less than 54 bits"),
8336 parser_errposition(@2)));
8340 $$ = SystemTypeName("float8");
8345 * SQL92 bit-field data types
8346 * The following implements BIT() and BIT VARYING().
8358 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
8359 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
8360 ConstBit: BitWithLength
8372 BIT opt_varying '(' expr_list ')'
8376 typname = $2 ? "varbit" : "bit";
8377 $$ = SystemTypeName(typname);
8386 /* bit defaults to bit(1), varbit to no limit */
8389 $$ = SystemTypeName("varbit");
8393 $$ = SystemTypeName("bit");
8394 $$->typmods = list_make1(makeIntConst(1, -1));
8402 * SQL92 character data types
8403 * The following implements CHAR() and VARCHAR().
8405 Character: CharacterWithLength
8409 | CharacterWithoutLength
8415 ConstCharacter: CharacterWithLength
8419 | CharacterWithoutLength
8421 /* Length was not specified so allow to be unrestricted.
8422 * This handles problems with fixed-length (bpchar) strings
8423 * which in column definitions must default to a length
8424 * of one, but should not be constrained if the length
8425 * was not specified.
8432 CharacterWithLength: character '(' Iconst ')' opt_charset
8434 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
8438 type = palloc(strlen($1) + 1 + strlen($5) + 1);
8445 $$ = SystemTypeName($1);
8446 $$->typmods = list_make1(makeIntConst($3, @3));
8451 CharacterWithoutLength: character opt_charset
8453 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
8457 type = palloc(strlen($1) + 1 + strlen($2) + 1);
8464 $$ = SystemTypeName($1);
8466 /* char defaults to char(1), varchar to no limit */
8467 if (strcmp($1, "bpchar") == 0)
8468 $$->typmods = list_make1(makeIntConst(1, -1));
8474 character: CHARACTER opt_varying
8475 { $$ = $2 ? "varchar": "bpchar"; }
8476 | CHAR_P opt_varying
8477 { $$ = $2 ? "varchar": "bpchar"; }
8480 | NATIONAL CHARACTER opt_varying
8481 { $$ = $3 ? "varchar": "bpchar"; }
8482 | NATIONAL CHAR_P opt_varying
8483 { $$ = $3 ? "varchar": "bpchar"; }
8485 { $$ = $2 ? "varchar": "bpchar"; }
8489 VARYING { $$ = TRUE; }
8490 | /*EMPTY*/ { $$ = FALSE; }
8494 CHARACTER SET ColId { $$ = $3; }
8495 | /*EMPTY*/ { $$ = NULL; }
8499 * SQL92 date/time types
8502 TIMESTAMP '(' Iconst ')' opt_timezone
8505 $$ = SystemTypeName("timestamptz");
8507 $$ = SystemTypeName("timestamp");
8508 $$->typmods = list_make1(makeIntConst($3, @3));
8511 | TIMESTAMP opt_timezone
8514 $$ = SystemTypeName("timestamptz");
8516 $$ = SystemTypeName("timestamp");
8519 | TIME '(' Iconst ')' opt_timezone
8522 $$ = SystemTypeName("timetz");
8524 $$ = SystemTypeName("time");
8525 $$->typmods = list_make1(makeIntConst($3, @3));
8531 $$ = SystemTypeName("timetz");
8533 $$ = SystemTypeName("time");
8541 $$ = SystemTypeName("interval");
8547 WITH_TIME ZONE { $$ = TRUE; }
8548 | WITHOUT TIME ZONE { $$ = FALSE; }
8549 | /*EMPTY*/ { $$ = FALSE; }
8554 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
8556 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
8558 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
8560 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
8562 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
8567 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
8568 INTERVAL_MASK(MONTH), @1));
8572 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8573 INTERVAL_MASK(HOUR), @1));
8577 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8578 INTERVAL_MASK(HOUR) |
8579 INTERVAL_MASK(MINUTE), @1));
8581 | DAY_P TO interval_second
8584 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
8585 INTERVAL_MASK(HOUR) |
8586 INTERVAL_MASK(MINUTE) |
8587 INTERVAL_MASK(SECOND), @1);
8589 | HOUR_P TO MINUTE_P
8591 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
8592 INTERVAL_MASK(MINUTE), @1));
8594 | HOUR_P TO interval_second
8597 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
8598 INTERVAL_MASK(MINUTE) |
8599 INTERVAL_MASK(SECOND), @1);
8601 | MINUTE_P TO interval_second
8604 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
8605 INTERVAL_MASK(SECOND), @1);
8614 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
8616 | SECOND_P '(' Iconst ')'
8618 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
8619 makeIntConst($3, @3));
8624 /*****************************************************************************
8626 * expression grammar
8628 *****************************************************************************/
8631 * General expressions
8632 * This is the heart of the expression syntax.
8634 * We have two expression types: a_expr is the unrestricted kind, and
8635 * b_expr is a subset that must be used in some places to avoid shift/reduce
8636 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
8637 * because that use of AND conflicts with AND as a boolean operator. So,
8638 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
8640 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
8641 * always be used by surrounding it with parens.
8643 * c_expr is all the productions that are common to a_expr and b_expr;
8644 * it's factored out just to eliminate redundant coding.
8646 a_expr: c_expr { $$ = $1; }
8647 | a_expr TYPECAST Typename
8648 { $$ = makeTypeCast($1, $3, @2); }
8649 | a_expr AT TIME ZONE a_expr
8651 FuncCall *n = makeNode(FuncCall);
8652 n->funcname = SystemFuncName("timezone");
8653 n->args = list_make2($5, $1);
8655 n->agg_star = FALSE;
8656 n->agg_distinct = FALSE;
8657 n->func_variadic = FALSE;
8663 * These operators must be called out explicitly in order to make use
8664 * of bison's automatic operator-precedence handling. All other
8665 * operator names are handled by the generic productions using "Op",
8666 * below; and all those operators will have the same precedence.
8668 * If you add more explicitly-known operators, be sure to add them
8669 * also to b_expr and to the MathOp list above.
8671 | '+' a_expr %prec UMINUS
8672 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
8673 | '-' a_expr %prec UMINUS
8674 { $$ = doNegate($2, @1); }
8676 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
8678 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
8680 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
8682 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
8684 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
8686 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
8688 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
8690 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
8692 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
8694 | a_expr qual_Op a_expr %prec Op
8695 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
8696 | qual_Op a_expr %prec Op
8697 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
8698 | a_expr qual_Op %prec POSTFIXOP
8699 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
8702 { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
8704 { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
8706 { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
8708 | a_expr LIKE a_expr
8709 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
8710 | a_expr LIKE a_expr ESCAPE a_expr
8712 FuncCall *n = makeNode(FuncCall);
8713 n->funcname = SystemFuncName("like_escape");
8714 n->args = list_make2($3, $5);
8716 n->agg_star = FALSE;
8717 n->agg_distinct = FALSE;
8718 n->func_variadic = FALSE;
8721 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
8723 | a_expr NOT LIKE a_expr
8724 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
8725 | a_expr NOT LIKE a_expr ESCAPE a_expr
8727 FuncCall *n = makeNode(FuncCall);
8728 n->funcname = SystemFuncName("like_escape");
8729 n->args = list_make2($4, $6);
8731 n->agg_star = FALSE;
8732 n->agg_distinct = FALSE;
8733 n->func_variadic = FALSE;
8736 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
8738 | a_expr ILIKE a_expr
8739 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
8740 | a_expr ILIKE a_expr ESCAPE a_expr
8742 FuncCall *n = makeNode(FuncCall);
8743 n->funcname = SystemFuncName("like_escape");
8744 n->args = list_make2($3, $5);
8746 n->agg_star = FALSE;
8747 n->agg_distinct = FALSE;
8748 n->func_variadic = FALSE;
8751 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n, @2);
8753 | a_expr NOT ILIKE a_expr
8754 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
8755 | a_expr NOT ILIKE a_expr ESCAPE a_expr
8757 FuncCall *n = makeNode(FuncCall);
8758 n->funcname = SystemFuncName("like_escape");
8759 n->args = list_make2($4, $6);
8761 n->agg_star = FALSE;
8762 n->agg_distinct = FALSE;
8763 n->func_variadic = FALSE;
8766 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n, @2);
8769 | a_expr SIMILAR TO a_expr %prec SIMILAR
8771 FuncCall *n = makeNode(FuncCall);
8772 n->funcname = SystemFuncName("similar_escape");
8773 n->args = list_make2($4, makeNullAConst(-1));
8775 n->agg_star = FALSE;
8776 n->agg_distinct = FALSE;
8777 n->func_variadic = FALSE;
8780 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8782 | a_expr SIMILAR TO a_expr ESCAPE a_expr
8784 FuncCall *n = makeNode(FuncCall);
8785 n->funcname = SystemFuncName("similar_escape");
8786 n->args = list_make2($4, $6);
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);
8795 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
8797 FuncCall *n = makeNode(FuncCall);
8798 n->funcname = SystemFuncName("similar_escape");
8799 n->args = list_make2($5, makeNullAConst(-1));
8801 n->agg_star = FALSE;
8802 n->agg_distinct = FALSE;
8803 n->func_variadic = FALSE;
8806 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8808 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
8810 FuncCall *n = makeNode(FuncCall);
8811 n->funcname = SystemFuncName("similar_escape");
8812 n->args = list_make2($5, $7);
8814 n->agg_star = FALSE;
8815 n->agg_distinct = FALSE;
8816 n->func_variadic = FALSE;
8819 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8823 * Define SQL92-style Null test clause.
8824 * Allow two forms described in the standard:
8827 * Allow two SQL extensions
8833 NullTest *n = makeNode(NullTest);
8834 n->arg = (Expr *) $1;
8835 n->nulltesttype = IS_NULL;
8840 NullTest *n = makeNode(NullTest);
8841 n->arg = (Expr *) $1;
8842 n->nulltesttype = IS_NULL;
8845 | a_expr IS NOT NULL_P
8847 NullTest *n = makeNode(NullTest);
8848 n->arg = (Expr *) $1;
8849 n->nulltesttype = IS_NOT_NULL;
8854 NullTest *n = makeNode(NullTest);
8855 n->arg = (Expr *) $1;
8856 n->nulltesttype = IS_NOT_NULL;
8861 $$ = (Node *)makeOverlaps($1, $3, @2, yyscanner);
8865 BooleanTest *b = makeNode(BooleanTest);
8866 b->arg = (Expr *) $1;
8867 b->booltesttype = IS_TRUE;
8870 | a_expr IS NOT TRUE_P
8872 BooleanTest *b = makeNode(BooleanTest);
8873 b->arg = (Expr *) $1;
8874 b->booltesttype = IS_NOT_TRUE;
8879 BooleanTest *b = makeNode(BooleanTest);
8880 b->arg = (Expr *) $1;
8881 b->booltesttype = IS_FALSE;
8884 | a_expr IS NOT FALSE_P
8886 BooleanTest *b = makeNode(BooleanTest);
8887 b->arg = (Expr *) $1;
8888 b->booltesttype = IS_NOT_FALSE;
8893 BooleanTest *b = makeNode(BooleanTest);
8894 b->arg = (Expr *) $1;
8895 b->booltesttype = IS_UNKNOWN;
8898 | a_expr IS NOT UNKNOWN
8900 BooleanTest *b = makeNode(BooleanTest);
8901 b->arg = (Expr *) $1;
8902 b->booltesttype = IS_NOT_UNKNOWN;
8905 | a_expr IS DISTINCT FROM a_expr %prec IS
8907 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
8909 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
8911 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8912 (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
8917 | a_expr IS OF '(' type_list ')' %prec IS
8919 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
8921 | a_expr IS NOT OF '(' type_list ')' %prec IS
8923 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
8926 * Ideally we would not use hard-wired operators below but
8927 * instead use opclasses. However, mixed data types and other
8928 * issues make this difficult:
8929 * http://archives.postgresql.org/pgsql-hackers/2008-08/msg01142.php
8931 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
8933 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
8934 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
8935 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
8938 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
8940 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
8941 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
8942 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
8945 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
8947 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
8948 (Node *) makeA_Expr(AEXPR_AND, NIL,
8949 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
8950 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
8952 (Node *) makeA_Expr(AEXPR_AND, NIL,
8953 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
8954 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
8958 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
8960 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
8961 (Node *) makeA_Expr(AEXPR_OR, NIL,
8962 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
8963 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
8965 (Node *) makeA_Expr(AEXPR_OR, NIL,
8966 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
8967 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
8971 | a_expr IN_P in_expr
8973 /* in_expr returns a SubLink or a list of a_exprs */
8974 if (IsA($3, SubLink))
8976 /* generate foo = ANY (subquery) */
8977 SubLink *n = (SubLink *) $3;
8978 n->subLinkType = ANY_SUBLINK;
8980 n->operName = list_make1(makeString("="));
8986 /* generate scalar IN expression */
8987 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
8990 | a_expr NOT IN_P in_expr
8992 /* in_expr returns a SubLink or a list of a_exprs */
8993 if (IsA($4, SubLink))
8995 /* generate NOT (foo = ANY (subquery)) */
8996 /* Make an = ANY node */
8997 SubLink *n = (SubLink *) $4;
8998 n->subLinkType = ANY_SUBLINK;
9000 n->operName = list_make1(makeString("="));
9002 /* Stick a NOT on top */
9003 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
9007 /* generate scalar NOT IN expression */
9008 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
9011 | a_expr subquery_Op sub_type select_with_parens %prec Op
9013 SubLink *n = makeNode(SubLink);
9014 n->subLinkType = $3;
9021 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
9023 if ($3 == ANY_SUBLINK)
9024 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
9026 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
9028 | UNIQUE select_with_parens
9030 /* Not sure how to get rid of the parentheses
9031 * but there are lots of shift/reduce errors without them.
9033 * Should be able to implement this by plopping the entire
9034 * select into a node, then transforming the target expressions
9035 * from whatever they are into count(*), and testing the
9036 * entire result equal to one.
9037 * But, will probably implement a separate node in the executor.
9040 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9041 errmsg("UNIQUE predicate is not yet implemented"),
9042 parser_errposition(@1)));
9044 | a_expr IS DOCUMENT_P %prec IS
9046 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9047 list_make1($1), @2);
9049 | a_expr IS NOT DOCUMENT_P %prec IS
9051 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9052 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9053 list_make1($1), @2),
9059 * Restricted expressions
9061 * b_expr is a subset of the complete expression syntax defined by a_expr.
9063 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
9064 * cause trouble in the places where b_expr is used. For simplicity, we
9065 * just eliminate all the boolean-keyword-operator productions from b_expr.
9069 | b_expr TYPECAST Typename
9070 { $$ = makeTypeCast($1, $3, @2); }
9071 | '+' b_expr %prec UMINUS
9072 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
9073 | '-' b_expr %prec UMINUS
9074 { $$ = doNegate($2, @1); }
9076 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
9078 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
9080 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
9082 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
9084 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
9086 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
9088 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
9090 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
9092 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
9093 | b_expr qual_Op b_expr %prec Op
9094 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
9095 | qual_Op b_expr %prec Op
9096 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
9097 | b_expr qual_Op %prec POSTFIXOP
9098 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
9099 | b_expr IS DISTINCT FROM b_expr %prec IS
9101 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
9103 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
9105 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
9106 NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
9108 | b_expr IS OF '(' type_list ')' %prec IS
9110 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
9112 | b_expr IS NOT OF '(' type_list ')' %prec IS
9114 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
9116 | b_expr IS DOCUMENT_P %prec IS
9118 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9119 list_make1($1), @2);
9121 | b_expr IS NOT DOCUMENT_P %prec IS
9123 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9124 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9125 list_make1($1), @2),
9131 * Productions that can be used in both a_expr and b_expr.
9133 * Note: productions that refer recursively to a_expr or b_expr mostly
9134 * cannot appear here. However, it's OK to refer to a_exprs that occur
9135 * inside parentheses, such as function arguments; that cannot introduce
9136 * ambiguity to the b_expr syntax.
9138 c_expr: columnref { $$ = $1; }
9139 | AexprConst { $$ = $1; }
9140 | PARAM opt_indirection
9142 ParamRef *p = makeNode(ParamRef);
9147 A_Indirection *n = makeNode(A_Indirection);
9148 n->arg = (Node *) p;
9149 n->indirection = check_indirection($2, yyscanner);
9155 | '(' a_expr ')' opt_indirection
9159 A_Indirection *n = makeNode(A_Indirection);
9161 n->indirection = check_indirection($4, yyscanner);
9171 | select_with_parens %prec UMINUS
9173 SubLink *n = makeNode(SubLink);
9174 n->subLinkType = EXPR_SUBLINK;
9181 | EXISTS select_with_parens
9183 SubLink *n = makeNode(SubLink);
9184 n->subLinkType = EXISTS_SUBLINK;
9191 | ARRAY select_with_parens
9193 SubLink *n = makeNode(SubLink);
9194 n->subLinkType = ARRAY_SUBLINK;
9203 A_ArrayExpr *n = (A_ArrayExpr *) $2;
9204 Assert(IsA(n, A_ArrayExpr));
9205 /* point outermost A_ArrayExpr to the ARRAY keyword */
9211 RowExpr *r = makeNode(RowExpr);
9213 r->row_typeid = InvalidOid; /* not analyzed yet */
9220 * func_expr is split out from c_expr just so that we have a classification
9221 * for "everything that is a function call or looks like one". This isn't
9222 * very important, but it saves us having to document which variants are
9223 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
9224 * (Note that many of the special SQL functions wouldn't actually make any
9225 * sense as functional index entries, but we ignore that consideration here.)
9227 func_expr: func_name '(' ')' over_clause
9229 FuncCall *n = makeNode(FuncCall);
9233 n->agg_star = FALSE;
9234 n->agg_distinct = FALSE;
9235 n->func_variadic = FALSE;
9240 | func_name '(' func_arg_list ')' over_clause
9242 FuncCall *n = makeNode(FuncCall);
9246 n->agg_star = FALSE;
9247 n->agg_distinct = FALSE;
9248 n->func_variadic = FALSE;
9253 | func_name '(' VARIADIC func_arg_expr ')' over_clause
9255 FuncCall *n = makeNode(FuncCall);
9257 n->args = list_make1($4);
9259 n->agg_star = FALSE;
9260 n->agg_distinct = FALSE;
9261 n->func_variadic = TRUE;
9266 | func_name '(' func_arg_list ',' VARIADIC func_arg_expr ')' over_clause
9268 FuncCall *n = makeNode(FuncCall);
9270 n->args = lappend($3, $6);
9272 n->agg_star = FALSE;
9273 n->agg_distinct = FALSE;
9274 n->func_variadic = TRUE;
9279 | func_name '(' func_arg_list sort_clause ')' over_clause
9281 FuncCall *n = makeNode(FuncCall);
9285 n->agg_star = FALSE;
9286 n->agg_distinct = FALSE;
9287 n->func_variadic = FALSE;
9292 | func_name '(' ALL func_arg_list opt_sort_clause ')' over_clause
9294 FuncCall *n = makeNode(FuncCall);
9298 n->agg_star = FALSE;
9299 n->agg_distinct = FALSE;
9300 /* Ideally we'd mark the FuncCall node to indicate
9301 * "must be an aggregate", but there's no provision
9302 * for that in FuncCall at the moment.
9304 n->func_variadic = FALSE;
9309 | func_name '(' DISTINCT func_arg_list opt_sort_clause ')' over_clause
9311 FuncCall *n = makeNode(FuncCall);
9315 n->agg_star = FALSE;
9316 n->agg_distinct = TRUE;
9317 n->func_variadic = FALSE;
9322 | func_name '(' '*' ')' over_clause
9325 * We consider AGGREGATE(*) to invoke a parameterless
9326 * aggregate. This does the right thing for COUNT(*),
9327 * and there are no other aggregates in SQL92 that accept
9330 * The FuncCall node is also marked agg_star = true,
9331 * so that later processing can detect what the argument
9334 FuncCall *n = makeNode(FuncCall);
9339 n->agg_distinct = FALSE;
9340 n->func_variadic = FALSE;
9348 * Translate as "'now'::text::date".
9350 * We cannot use "'now'::date" because coerce_type() will
9351 * immediately reduce that to a constant representing
9352 * today's date. We need to delay the conversion until
9353 * runtime, else the wrong things will happen when
9354 * CURRENT_DATE is used in a column default value or rule.
9356 * This could be simplified if we had a way to generate
9357 * an expression tree representing runtime application
9358 * of type-input conversion functions. (As of PG 7.3
9359 * that is actually possible, but not clear that we want
9363 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9364 $$ = makeTypeCast(n, SystemTypeName("date"), -1);
9369 * Translate as "'now'::text::timetz".
9370 * See comments for CURRENT_DATE.
9373 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9374 $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
9376 | CURRENT_TIME '(' Iconst ')'
9379 * Translate as "'now'::text::timetz(n)".
9380 * See comments for CURRENT_DATE.
9384 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9385 d = SystemTypeName("timetz");
9386 d->typmods = list_make1(makeIntConst($3, @3));
9387 $$ = makeTypeCast(n, d, -1);
9392 * Translate as "now()", since we have a function that
9393 * does exactly what is needed.
9395 FuncCall *n = makeNode(FuncCall);
9396 n->funcname = SystemFuncName("now");
9399 n->agg_star = FALSE;
9400 n->agg_distinct = FALSE;
9401 n->func_variadic = FALSE;
9406 | CURRENT_TIMESTAMP '(' Iconst ')'
9409 * Translate as "'now'::text::timestamptz(n)".
9410 * See comments for CURRENT_DATE.
9414 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9415 d = SystemTypeName("timestamptz");
9416 d->typmods = list_make1(makeIntConst($3, @3));
9417 $$ = makeTypeCast(n, d, -1);
9422 * Translate as "'now'::text::time".
9423 * See comments for CURRENT_DATE.
9426 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9427 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
9429 | LOCALTIME '(' Iconst ')'
9432 * Translate as "'now'::text::time(n)".
9433 * See comments for CURRENT_DATE.
9437 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9438 d = SystemTypeName("time");
9439 d->typmods = list_make1(makeIntConst($3, @3));
9440 $$ = makeTypeCast((Node *)n, d, -1);
9445 * Translate as "'now'::text::timestamp".
9446 * See comments for CURRENT_DATE.
9449 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9450 $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
9452 | LOCALTIMESTAMP '(' Iconst ')'
9455 * Translate as "'now'::text::timestamp(n)".
9456 * See comments for CURRENT_DATE.
9460 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9461 d = SystemTypeName("timestamp");
9462 d->typmods = list_make1(makeIntConst($3, @3));
9463 $$ = makeTypeCast(n, d, -1);
9467 FuncCall *n = makeNode(FuncCall);
9468 n->funcname = SystemFuncName("current_user");
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_user");
9484 n->agg_star = FALSE;
9485 n->agg_distinct = FALSE;
9486 n->func_variadic = FALSE;
9493 FuncCall *n = makeNode(FuncCall);
9494 n->funcname = SystemFuncName("session_user");
9497 n->agg_star = FALSE;
9498 n->agg_distinct = FALSE;
9499 n->func_variadic = FALSE;
9506 FuncCall *n = makeNode(FuncCall);
9507 n->funcname = SystemFuncName("current_user");
9510 n->agg_star = FALSE;
9511 n->agg_distinct = FALSE;
9512 n->func_variadic = FALSE;
9519 FuncCall *n = makeNode(FuncCall);
9520 n->funcname = SystemFuncName("current_database");
9523 n->agg_star = FALSE;
9524 n->agg_distinct = FALSE;
9525 n->func_variadic = FALSE;
9532 FuncCall *n = makeNode(FuncCall);
9533 n->funcname = SystemFuncName("current_schema");
9536 n->agg_star = FALSE;
9537 n->agg_distinct = FALSE;
9538 n->func_variadic = FALSE;
9543 | CAST '(' a_expr AS Typename ')'
9544 { $$ = makeTypeCast($3, $5, @1); }
9545 | EXTRACT '(' extract_list ')'
9547 FuncCall *n = makeNode(FuncCall);
9548 n->funcname = SystemFuncName("date_part");
9551 n->agg_star = FALSE;
9552 n->agg_distinct = FALSE;
9553 n->func_variadic = FALSE;
9558 | OVERLAY '(' overlay_list ')'
9560 /* overlay(A PLACING B FROM C FOR D) is converted to
9561 * substring(A, 1, C-1) || B || substring(A, C+1, C+D)
9562 * overlay(A PLACING B FROM C) is converted to
9563 * substring(A, 1, C-1) || B || substring(A, C+1, C+char_length(B))
9565 FuncCall *n = makeNode(FuncCall);
9566 n->funcname = SystemFuncName("overlay");
9569 n->agg_star = FALSE;
9570 n->agg_distinct = FALSE;
9571 n->func_variadic = FALSE;
9576 | POSITION '(' position_list ')'
9578 /* position(A in B) is converted to position(B, A) */
9579 FuncCall *n = makeNode(FuncCall);
9580 n->funcname = SystemFuncName("position");
9583 n->agg_star = FALSE;
9584 n->agg_distinct = FALSE;
9585 n->func_variadic = FALSE;
9590 | SUBSTRING '(' substr_list ')'
9592 /* substring(A from B for C) is converted to
9593 * substring(A, B, C) - thomas 2000-11-28
9595 FuncCall *n = makeNode(FuncCall);
9596 n->funcname = SystemFuncName("substring");
9599 n->agg_star = FALSE;
9600 n->agg_distinct = FALSE;
9601 n->func_variadic = FALSE;
9606 | TREAT '(' a_expr AS Typename ')'
9608 /* TREAT(expr AS target) converts expr of a particular type to target,
9609 * which is defined to be a subtype of the original expression.
9610 * In SQL99, this is intended for use with structured UDTs,
9611 * but let's make this a generally useful form allowing stronger
9612 * coercions than are handled by implicit casting.
9614 FuncCall *n = makeNode(FuncCall);
9615 /* Convert SystemTypeName() to SystemFuncName() even though
9616 * at the moment they result in the same thing.
9618 n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
9619 n->args = list_make1($3);
9621 n->agg_star = FALSE;
9622 n->agg_distinct = FALSE;
9623 n->func_variadic = FALSE;
9628 | TRIM '(' BOTH trim_list ')'
9630 /* various trim expressions are defined in SQL92
9631 * - thomas 1997-07-19
9633 FuncCall *n = makeNode(FuncCall);
9634 n->funcname = SystemFuncName("btrim");
9637 n->agg_star = FALSE;
9638 n->agg_distinct = FALSE;
9639 n->func_variadic = FALSE;
9644 | TRIM '(' LEADING trim_list ')'
9646 FuncCall *n = makeNode(FuncCall);
9647 n->funcname = SystemFuncName("ltrim");
9650 n->agg_star = FALSE;
9651 n->agg_distinct = FALSE;
9652 n->func_variadic = FALSE;
9657 | TRIM '(' TRAILING trim_list ')'
9659 FuncCall *n = makeNode(FuncCall);
9660 n->funcname = SystemFuncName("rtrim");
9663 n->agg_star = FALSE;
9664 n->agg_distinct = FALSE;
9665 n->func_variadic = FALSE;
9670 | TRIM '(' trim_list ')'
9672 FuncCall *n = makeNode(FuncCall);
9673 n->funcname = SystemFuncName("btrim");
9676 n->agg_star = FALSE;
9677 n->agg_distinct = FALSE;
9678 n->func_variadic = FALSE;
9683 | NULLIF '(' a_expr ',' a_expr ')'
9685 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
9687 | COALESCE '(' expr_list ')'
9689 CoalesceExpr *c = makeNode(CoalesceExpr);
9694 | GREATEST '(' expr_list ')'
9696 MinMaxExpr *v = makeNode(MinMaxExpr);
9698 v->op = IS_GREATEST;
9702 | LEAST '(' expr_list ')'
9704 MinMaxExpr *v = makeNode(MinMaxExpr);
9710 | XMLCONCAT '(' expr_list ')'
9712 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
9714 | XMLELEMENT '(' NAME_P ColLabel ')'
9716 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
9718 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
9720 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
9722 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
9724 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
9726 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
9728 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
9730 | XMLFOREST '(' xml_attribute_list ')'
9732 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
9734 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
9736 XmlExpr *x = (XmlExpr *)
9737 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
9738 list_make2($4, makeBoolAConst($5, -1)),
9743 | XMLPI '(' NAME_P ColLabel ')'
9745 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
9747 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
9749 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
9751 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
9753 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
9754 list_make3($3, $5, $6), @1);
9756 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
9758 XmlSerialize *n = makeNode(XmlSerialize);
9770 xml_root_version: VERSION_P a_expr
9772 | VERSION_P NO VALUE_P
9773 { $$ = makeNullAConst(-1); }
9776 opt_xml_root_standalone: ',' STANDALONE_P YES_P
9777 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
9778 | ',' STANDALONE_P NO
9779 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
9780 | ',' STANDALONE_P NO VALUE_P
9781 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
9783 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
9786 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
9789 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
9790 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
9793 xml_attribute_el: a_expr AS ColLabel
9795 $$ = makeNode(ResTarget);
9797 $$->indirection = NIL;
9798 $$->val = (Node *) $1;
9803 $$ = makeNode(ResTarget);
9805 $$->indirection = NIL;
9806 $$->val = (Node *) $1;
9811 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
9812 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
9815 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
9816 | STRIP_P WHITESPACE_P { $$ = FALSE; }
9817 | /*EMPTY*/ { $$ = FALSE; }
9821 * Window Definitions
9824 WINDOW window_definition_list { $$ = $2; }
9825 | /*EMPTY*/ { $$ = NIL; }
9828 window_definition_list:
9829 window_definition { $$ = list_make1($1); }
9830 | window_definition_list ',' window_definition
9831 { $$ = lappend($1, $3); }
9835 ColId AS window_specification
9843 over_clause: OVER window_specification
9847 WindowDef *n = makeNode(WindowDef);
9850 n->partitionClause = NIL;
9851 n->orderClause = NIL;
9852 n->frameOptions = FRAMEOPTION_DEFAULTS;
9860 window_specification: '(' opt_existing_window_name opt_partition_clause
9861 opt_sort_clause opt_frame_clause ')'
9863 WindowDef *n = makeNode(WindowDef);
9866 n->partitionClause = $3;
9867 n->orderClause = $4;
9868 n->frameOptions = $5;
9875 * If we see PARTITION, RANGE, or ROWS as the first token after the '('
9876 * of a window_specification, we want the assumption to be that there is
9877 * no existing_window_name; but those keywords are unreserved and so could
9878 * be ColIds. We fix this by making them have the same precedence as IDENT
9879 * and giving the empty production here a slightly higher precedence, so
9880 * that the shift/reduce conflict is resolved in favor of reducing the rule.
9881 * These keywords are thus precluded from being an existing_window_name but
9882 * are not reserved for any other purpose.
9884 opt_existing_window_name: ColId { $$ = $1; }
9885 | /*EMPTY*/ %prec Op { $$ = NULL; }
9888 opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
9889 | /*EMPTY*/ { $$ = NIL; }
9893 * This is only a subset of the full SQL:2008 frame_clause grammar.
9894 * We don't support <expression> PRECEDING, <expression> FOLLOWING,
9895 * nor <window frame exclusion> yet.
9900 $$ = FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE | $2;
9904 $$ = FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS | $2;
9907 { $$ = FRAMEOPTION_DEFAULTS; }
9910 frame_extent: frame_bound
9912 /* reject invalid cases */
9913 if ($1 & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
9915 (errcode(ERRCODE_WINDOWING_ERROR),
9916 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
9917 parser_errposition(@1)));
9918 if ($1 & FRAMEOPTION_START_CURRENT_ROW)
9920 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9921 errmsg("frame start at CURRENT ROW is not implemented"),
9922 parser_errposition(@1)));
9923 $$ = $1 | FRAMEOPTION_END_CURRENT_ROW;
9925 | BETWEEN frame_bound AND frame_bound
9927 /* reject invalid cases */
9928 if ($2 & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
9930 (errcode(ERRCODE_WINDOWING_ERROR),
9931 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
9932 parser_errposition(@2)));
9933 if ($2 & FRAMEOPTION_START_CURRENT_ROW)
9935 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9936 errmsg("frame start at CURRENT ROW is not implemented"),
9937 parser_errposition(@2)));
9938 if ($4 & FRAMEOPTION_START_UNBOUNDED_PRECEDING)
9940 (errcode(ERRCODE_WINDOWING_ERROR),
9941 errmsg("frame end cannot be UNBOUNDED PRECEDING"),
9942 parser_errposition(@4)));
9943 /* shift converts START_ options to END_ options */
9944 $$ = FRAMEOPTION_BETWEEN | $2 | ($4 << 1);
9949 * This is used for both frame start and frame end, with output set up on
9950 * the assumption it's frame start; the frame_extent productions must reject
9956 $$ = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
9958 | UNBOUNDED FOLLOWING
9960 $$ = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
9964 $$ = FRAMEOPTION_START_CURRENT_ROW;
9970 * Supporting nonterminals for expressions.
9973 /* Explicit row production.
9975 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
9976 * without conflicting with the parenthesized a_expr production. Without the
9977 * ROW keyword, there must be more than one a_expr inside the parens.
9979 row: ROW '(' expr_list ')' { $$ = $3; }
9980 | ROW '(' ')' { $$ = NIL; }
9981 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
9984 sub_type: ANY { $$ = ANY_SUBLINK; }
9985 | SOME { $$ = ANY_SUBLINK; }
9986 | ALL { $$ = ALL_SUBLINK; }
9989 all_Op: Op { $$ = $1; }
9990 | MathOp { $$ = $1; }
9993 MathOp: '+' { $$ = "+"; }
10000 | '>' { $$ = ">"; }
10001 | '=' { $$ = "="; }
10005 { $$ = list_make1(makeString($1)); }
10006 | OPERATOR '(' any_operator ')'
10012 { $$ = list_make1(makeString($1)); }
10013 | OPERATOR '(' any_operator ')'
10019 { $$ = list_make1(makeString($1)); }
10020 | OPERATOR '(' any_operator ')'
10023 { $$ = list_make1(makeString("~~")); }
10025 { $$ = list_make1(makeString("!~~")); }
10027 { $$ = list_make1(makeString("~~*")); }
10029 { $$ = list_make1(makeString("!~~*")); }
10030 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
10031 * the regular expression is preprocessed by a function (similar_escape),
10032 * and the ~ operator for posix regular expressions is used.
10033 * x SIMILAR TO y -> x ~ similar_escape(y)
10034 * this transformation is made on the fly by the parser upwards.
10035 * however the SubLink structure which handles any/some/all stuff
10036 * is not ready for such a thing.
10042 $$ = list_make1($1);
10044 | expr_list ',' a_expr
10046 $$ = lappend($1, $3);
10050 /* function arguments can have names */
10051 func_arg_list: func_arg_expr
10053 $$ = list_make1($1);
10055 | func_arg_list ',' func_arg_expr
10057 $$ = lappend($1, $3);
10061 func_arg_expr: a_expr
10065 | a_expr AS param_name
10067 NamedArgExpr *na = makeNode(NamedArgExpr);
10068 na->arg = (Expr *) $1;
10070 na->argnumber = -1; /* until determined */
10076 type_list: Typename { $$ = list_make1($1); }
10077 | type_list ',' Typename { $$ = lappend($1, $3); }
10080 array_expr: '[' expr_list ']'
10082 $$ = makeAArrayExpr($2, @1);
10084 | '[' array_expr_list ']'
10086 $$ = makeAArrayExpr($2, @1);
10090 $$ = makeAArrayExpr(NIL, @1);
10094 array_expr_list: array_expr { $$ = list_make1($1); }
10095 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
10100 extract_arg FROM a_expr
10102 $$ = list_make2(makeStringConst($1, @1), $3);
10104 | /*EMPTY*/ { $$ = NIL; }
10107 /* Allow delimited string Sconst in extract_arg as an SQL extension.
10108 * - thomas 2001-04-12
10112 | YEAR_P { $$ = "year"; }
10113 | MONTH_P { $$ = "month"; }
10114 | DAY_P { $$ = "day"; }
10115 | HOUR_P { $$ = "hour"; }
10116 | MINUTE_P { $$ = "minute"; }
10117 | SECOND_P { $$ = "second"; }
10118 | Sconst { $$ = $1; }
10121 /* OVERLAY() arguments
10122 * SQL99 defines the OVERLAY() function:
10123 * o overlay(text placing text from int for int)
10124 * o overlay(text placing text from int)
10127 a_expr overlay_placing substr_from substr_for
10129 $$ = list_make4($1, $2, $3, $4);
10131 | a_expr overlay_placing substr_from
10133 $$ = list_make3($1, $2, $3);
10142 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
10145 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
10146 | /*EMPTY*/ { $$ = NIL; }
10149 /* SUBSTRING() arguments
10150 * SQL9x defines a specific syntax for arguments to SUBSTRING():
10151 * o substring(text from int for int)
10152 * o substring(text from int) get entire string from starting point "int"
10153 * o substring(text for int) get first "int" characters of string
10154 * o substring(text from pattern) get entire string matching pattern
10155 * o substring(text from pattern for escape) same with specified escape char
10156 * We also want to support generic substring functions which accept
10157 * the usual generic list of arguments. So we will accept both styles
10158 * here, and convert the SQL9x style to the generic list for further
10159 * processing. - thomas 2000-11-28
10162 a_expr substr_from substr_for
10164 $$ = list_make3($1, $2, $3);
10166 | a_expr substr_for substr_from
10168 /* not legal per SQL99, but might as well allow it */
10169 $$ = list_make3($1, $3, $2);
10171 | a_expr substr_from
10173 $$ = list_make2($1, $2);
10175 | a_expr substr_for
10178 * Since there are no cases where this syntax allows
10179 * a textual FOR value, we forcibly cast the argument
10180 * to int4. The possible matches in pg_proc are
10181 * substring(text,int4) and substring(text,text),
10182 * and we don't want the parser to choose the latter,
10183 * which it is likely to do if the second argument
10184 * is unknown or doesn't have an implicit cast to int4.
10186 $$ = list_make3($1, makeIntConst(1, -1),
10188 SystemTypeName("int4"), -1));
10199 FROM a_expr { $$ = $2; }
10202 substr_for: FOR a_expr { $$ = $2; }
10205 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
10206 | FROM expr_list { $$ = $2; }
10207 | expr_list { $$ = $1; }
10210 in_expr: select_with_parens
10212 SubLink *n = makeNode(SubLink);
10214 /* other fields will be filled later */
10217 | '(' expr_list ')' { $$ = (Node *)$2; }
10221 * Define SQL92-style case clause.
10222 * - Full specification
10223 * CASE WHEN a = b THEN c ... ELSE d END
10224 * - Implicit argument
10225 * CASE a WHEN b THEN c ... ELSE d END
10227 case_expr: CASE case_arg when_clause_list case_default END_P
10229 CaseExpr *c = makeNode(CaseExpr);
10230 c->casetype = InvalidOid; /* not analyzed yet */
10231 c->arg = (Expr *) $2;
10233 c->defresult = (Expr *) $4;
10240 /* There must be at least one */
10241 when_clause { $$ = list_make1($1); }
10242 | when_clause_list when_clause { $$ = lappend($1, $2); }
10246 WHEN a_expr THEN a_expr
10248 CaseWhen *w = makeNode(CaseWhen);
10249 w->expr = (Expr *) $2;
10250 w->result = (Expr *) $4;
10257 ELSE a_expr { $$ = $2; }
10258 | /*EMPTY*/ { $$ = NULL; }
10261 case_arg: a_expr { $$ = $1; }
10262 | /*EMPTY*/ { $$ = NULL; }
10267 $$ = makeColumnRef($1, NIL, @1, yyscanner);
10269 | ColId indirection
10271 $$ = makeColumnRef($1, $2, @1, yyscanner);
10278 $$ = (Node *) makeString($2);
10282 $$ = (Node *) makeNode(A_Star);
10286 A_Indices *ai = makeNode(A_Indices);
10291 | '[' a_expr ':' a_expr ']'
10293 A_Indices *ai = makeNode(A_Indices);
10301 indirection_el { $$ = list_make1($1); }
10302 | indirection indirection_el { $$ = lappend($1, $2); }
10306 /*EMPTY*/ { $$ = NIL; }
10307 | opt_indirection indirection_el { $$ = lappend($1, $2); }
10310 opt_asymmetric: ASYMMETRIC
10315 * The SQL spec defines "contextually typed value expressions" and
10316 * "contextually typed row value constructors", which for our purposes
10317 * are the same as "a_expr" and "row" except that DEFAULT can appear at
10322 a_expr { $$ = (Node *) $1; }
10325 SetToDefault *n = makeNode(SetToDefault);
10332 ctext_expr { $$ = list_make1($1); }
10333 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
10337 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
10338 * making VALUES a fully reserved word, which will probably break more apps
10339 * than allowing the noise-word is worth.
10341 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
10345 /*****************************************************************************
10347 * target list for SELECT
10349 *****************************************************************************/
10352 target_el { $$ = list_make1($1); }
10353 | target_list ',' target_el { $$ = lappend($1, $3); }
10356 target_el: a_expr AS ColLabel
10358 $$ = makeNode(ResTarget);
10360 $$->indirection = NIL;
10361 $$->val = (Node *)$1;
10365 * We support omitting AS only for column labels that aren't
10366 * any known keyword. There is an ambiguity against postfix
10367 * operators: is "a ! b" an infix expression, or a postfix
10368 * expression and a column label? We prefer to resolve this
10369 * as an infix expression, which we accomplish by assigning
10370 * IDENT a precedence higher than POSTFIXOP.
10374 $$ = makeNode(ResTarget);
10376 $$->indirection = NIL;
10377 $$->val = (Node *)$1;
10382 $$ = makeNode(ResTarget);
10384 $$->indirection = NIL;
10385 $$->val = (Node *)$1;
10390 ColumnRef *n = makeNode(ColumnRef);
10391 n->fields = list_make1(makeNode(A_Star));
10394 $$ = makeNode(ResTarget);
10396 $$->indirection = NIL;
10397 $$->val = (Node *)n;
10403 /*****************************************************************************
10405 * Names and constants
10407 *****************************************************************************/
10409 qualified_name_list:
10410 qualified_name { $$ = list_make1($1); }
10411 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
10415 * The production for a qualified relation name has to exactly match the
10416 * production for a qualified func_name, because in a FROM clause we cannot
10417 * tell which we are parsing until we see what comes after it ('(' for a
10418 * func_name, something else for a relation). Therefore we allow 'indirection'
10419 * which may contain subscripts, and reject that case in the C code.
10424 $$ = makeNode(RangeVar);
10425 $$->catalogname = NULL;
10426 $$->schemaname = NULL;
10430 | ColId indirection
10432 check_qualified_name($2, yyscanner);
10433 $$ = makeNode(RangeVar);
10434 switch (list_length($2))
10437 $$->catalogname = NULL;
10438 $$->schemaname = $1;
10439 $$->relname = strVal(linitial($2));
10442 $$->catalogname = $1;
10443 $$->schemaname = strVal(linitial($2));
10444 $$->relname = strVal(lsecond($2));
10448 (errcode(ERRCODE_SYNTAX_ERROR),
10449 errmsg("improper qualified name (too many dotted names): %s",
10450 NameListToString(lcons(makeString($1), $2))),
10451 parser_errposition(@1)));
10459 { $$ = list_make1(makeString($1)); }
10460 | name_list ',' name
10461 { $$ = lappend($1, makeString($3)); }
10465 name: ColId { $$ = $1; };
10468 ColId { $$ = $1; };
10471 ColId { $$ = $1; };
10473 attr_name: ColLabel { $$ = $1; };
10475 index_name: ColId { $$ = $1; };
10477 file_name: Sconst { $$ = $1; };
10480 * The production for a qualified func_name has to exactly match the
10481 * production for a qualified columnref, because we cannot tell which we
10482 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
10483 * anything else for a columnref). Therefore we allow 'indirection' which
10484 * may contain subscripts, and reject that case in the C code. (If we
10485 * ever implement SQL99-like methods, such syntax may actually become legal!)
10487 func_name: type_function_name
10488 { $$ = list_make1(makeString($1)); }
10489 | ColId indirection
10491 $$ = check_func_name(lcons(makeString($1), $2),
10502 $$ = makeIntConst($1, @1);
10506 $$ = makeFloatConst($1, @1);
10510 $$ = makeStringConst($1, @1);
10514 $$ = makeBitStringConst($1, @1);
10518 /* This is a bit constant per SQL99:
10519 * Without Feature F511, "BIT data type",
10520 * a <general literal> shall not be a
10521 * <bit string literal> or a <hex string literal>.
10523 $$ = makeBitStringConst($1, @1);
10527 /* generic type 'literal' syntax */
10528 TypeName *t = makeTypeNameFromNameList($1);
10530 $$ = makeStringConstCast($2, @2, t);
10532 | func_name '(' func_arg_list ')' Sconst
10534 /* generic syntax with a type modifier */
10535 TypeName *t = makeTypeNameFromNameList($1);
10539 * We must use func_arg_list in the production to avoid
10540 * reduce/reduce conflicts, but we don't actually wish
10541 * to allow NamedArgExpr in this context.
10545 NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
10547 if (IsA(arg, NamedArgExpr))
10549 (errcode(ERRCODE_SYNTAX_ERROR),
10550 errmsg("type modifier cannot have AS name"),
10551 parser_errposition(arg->location)));
10555 $$ = makeStringConstCast($5, @5, t);
10557 | ConstTypename Sconst
10559 $$ = makeStringConstCast($2, @2, $1);
10561 | ConstInterval Sconst opt_interval
10565 $$ = makeStringConstCast($2, @2, t);
10567 | ConstInterval '(' Iconst ')' Sconst opt_interval
10572 if (list_length($6) != 1)
10574 (errcode(ERRCODE_SYNTAX_ERROR),
10575 errmsg("interval precision specified twice"),
10576 parser_errposition(@1)));
10577 t->typmods = lappend($6, makeIntConst($3, @3));
10580 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
10581 makeIntConst($3, @3));
10582 $$ = makeStringConstCast($5, @5, t);
10586 $$ = makeBoolAConst(TRUE, @1);
10590 $$ = makeBoolAConst(FALSE, @1);
10594 $$ = makeNullAConst(@1);
10598 Iconst: ICONST { $$ = $1; };
10599 Sconst: SCONST { $$ = $1; };
10600 RoleId: ColId { $$ = $1; };
10602 SignedIconst: Iconst { $$ = $1; }
10603 | '+' Iconst { $$ = + $2; }
10604 | '-' Iconst { $$ = - $2; }
10607 Iconst_list: Iconst { $$ = list_make1(makeInteger($1)); }
10608 | Iconst_list ',' Iconst { $$ = lappend($1, makeInteger($3)); }
10612 * Name classification hierarchy.
10614 * IDENT is the lexeme returned by the lexer for identifiers that match
10615 * no known keyword. In most cases, we can accept certain keywords as
10616 * names, not only IDENTs. We prefer to accept as many such keywords
10617 * as possible to minimize the impact of "reserved words" on programmers.
10618 * So, we divide names into several possible classes. The classification
10619 * is chosen in part to make keywords acceptable as names wherever possible.
10622 /* Column identifier --- names that can be column, table, etc names.
10624 ColId: IDENT { $$ = $1; }
10625 | unreserved_keyword { $$ = pstrdup($1); }
10626 | col_name_keyword { $$ = pstrdup($1); }
10629 /* Type/function identifier --- names that can be type or function names.
10631 type_function_name: IDENT { $$ = $1; }
10632 | unreserved_keyword { $$ = pstrdup($1); }
10633 | type_func_name_keyword { $$ = pstrdup($1); }
10636 /* Column label --- allowed labels in "AS" clauses.
10637 * This presently includes *all* Postgres keywords.
10639 ColLabel: IDENT { $$ = $1; }
10640 | unreserved_keyword { $$ = pstrdup($1); }
10641 | col_name_keyword { $$ = pstrdup($1); }
10642 | type_func_name_keyword { $$ = pstrdup($1); }
10643 | reserved_keyword { $$ = pstrdup($1); }
10648 * Keyword category lists. Generally, every keyword present in
10649 * the Postgres grammar should appear in exactly one of these lists.
10651 * Put a new keyword into the first list that it can go into without causing
10652 * shift or reduce conflicts. The earlier lists define "less reserved"
10653 * categories of keywords.
10655 * Make sure that each keyword's category in keywords.c matches where
10656 * it is listed here. (Someday we may be able to generate these lists and
10657 * keywords.c's table from a common master list.)
10660 /* "Unreserved" keywords --- available for use as any kind of name.
10662 unreserved_keyword:
10916 /* Column identifier --- keywords that can be column, table, etc names.
10918 * Many of these keywords will in fact be recognized as type or function
10919 * names too; but they have special productions for the purpose, and so
10920 * can't be treated as "generic" type or function names.
10922 * The type names appearing here are not usable as function names
10923 * because they can be followed by '(' in typename productions, which
10924 * looks too much like a function call for an LR(1) parser.
10974 /* Type/function identifier --- keywords that can be type or function names.
10976 * Most of these are keywords that are used as operators in expressions;
10977 * in general such keywords can't be column names because they would be
10978 * ambiguous with variables, but they are unambiguous as function identifiers.
10980 * Do not include POSITION, SUBSTRING, etc here since they have explicit
10981 * productions in a_expr to support the goofy SQL9x argument syntax.
10982 * - thomas 2000-11-28
10984 type_func_name_keyword:
11009 /* Reserved keyword --- these keywords are usable only as a ColLabel.
11011 * Keywords appear here if they could not be distinguished from variable,
11012 * type, or function names in some contexts. Don't put things here unless
11037 | CURRENT_TIMESTAMP
11098 * The signature of this function is required by bison. However, we
11099 * ignore the passed yylloc and instead use the last token position
11100 * available from the scanner.
11103 base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
11105 parser_yyerror(msg);
11109 makeColumnRef(char *colname, List *indirection,
11110 int location, core_yyscan_t yyscanner)
11113 * Generate a ColumnRef node, with an A_Indirection node added if there
11114 * is any subscripting in the specified indirection list. However,
11115 * any field selection at the start of the indirection list must be
11116 * transposed into the "fields" part of the ColumnRef node.
11118 ColumnRef *c = makeNode(ColumnRef);
11122 c->location = location;
11123 foreach(l, indirection)
11125 if (IsA(lfirst(l), A_Indices))
11127 A_Indirection *i = makeNode(A_Indirection);
11131 /* easy case - all indirection goes to A_Indirection */
11132 c->fields = list_make1(makeString(colname));
11133 i->indirection = check_indirection(indirection, yyscanner);
11137 /* got to split the list in two */
11138 i->indirection = check_indirection(list_copy_tail(indirection,
11141 indirection = list_truncate(indirection, nfields);
11142 c->fields = lcons(makeString(colname), indirection);
11144 i->arg = (Node *) c;
11147 else if (IsA(lfirst(l), A_Star))
11149 /* We only allow '*' at the end of a ColumnRef */
11150 if (lnext(l) != NULL)
11151 parser_yyerror("improper use of \"*\"");
11155 /* No subscripting, so all indirection gets added to field list */
11156 c->fields = lcons(makeString(colname), indirection);
11161 makeTypeCast(Node *arg, TypeName *typename, int location)
11163 TypeCast *n = makeNode(TypeCast);
11165 n->typeName = typename;
11166 n->location = location;
11171 makeStringConst(char *str, int location)
11173 A_Const *n = makeNode(A_Const);
11175 n->val.type = T_String;
11176 n->val.val.str = str;
11177 n->location = location;
11183 makeStringConstCast(char *str, int location, TypeName *typename)
11185 Node *s = makeStringConst(str, location);
11187 return makeTypeCast(s, typename, -1);
11191 makeIntConst(int val, int location)
11193 A_Const *n = makeNode(A_Const);
11195 n->val.type = T_Integer;
11196 n->val.val.ival = val;
11197 n->location = location;
11203 makeFloatConst(char *str, int location)
11205 A_Const *n = makeNode(A_Const);
11207 n->val.type = T_Float;
11208 n->val.val.str = str;
11209 n->location = location;
11215 makeBitStringConst(char *str, int location)
11217 A_Const *n = makeNode(A_Const);
11219 n->val.type = T_BitString;
11220 n->val.val.str = str;
11221 n->location = location;
11227 makeNullAConst(int location)
11229 A_Const *n = makeNode(A_Const);
11231 n->val.type = T_Null;
11232 n->location = location;
11238 makeAConst(Value *v, int location)
11245 n = makeFloatConst(v->val.str, location);
11249 n = makeIntConst(v->val.ival, location);
11254 n = makeStringConst(v->val.str, location);
11261 /* makeBoolAConst()
11262 * Create an A_Const string node and put it inside a boolean cast.
11265 makeBoolAConst(bool state, int location)
11267 A_Const *n = makeNode(A_Const);
11269 n->val.type = T_String;
11270 n->val.val.str = (state ? "t" : "f");
11271 n->location = location;
11273 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
11277 * Create and populate a FuncCall node to support the OVERLAPS operator.
11280 makeOverlaps(List *largs, List *rargs, int location, core_yyscan_t yyscanner)
11282 FuncCall *n = makeNode(FuncCall);
11284 n->funcname = SystemFuncName("overlaps");
11285 if (list_length(largs) == 1)
11286 largs = lappend(largs, largs);
11287 else if (list_length(largs) != 2)
11289 (errcode(ERRCODE_SYNTAX_ERROR),
11290 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
11291 parser_errposition(location)));
11292 if (list_length(rargs) == 1)
11293 rargs = lappend(rargs, rargs);
11294 else if (list_length(rargs) != 2)
11296 (errcode(ERRCODE_SYNTAX_ERROR),
11297 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
11298 parser_errposition(location)));
11299 n->args = list_concat(largs, rargs);
11300 n->agg_order = NIL;
11301 n->agg_star = FALSE;
11302 n->agg_distinct = FALSE;
11303 n->func_variadic = FALSE;
11305 n->location = location;
11309 /* check_qualified_name --- check the result of qualified_name production
11311 * It's easiest to let the grammar production for qualified_name allow
11312 * subscripts and '*', which we then must reject here.
11315 check_qualified_name(List *names, core_yyscan_t yyscanner)
11321 if (!IsA(lfirst(i), String))
11322 parser_yyerror("syntax error");
11326 /* check_func_name --- check the result of func_name production
11328 * It's easiest to let the grammar production for func_name allow subscripts
11329 * and '*', which we then must reject here.
11332 check_func_name(List *names, core_yyscan_t yyscanner)
11338 if (!IsA(lfirst(i), String))
11339 parser_yyerror("syntax error");
11344 /* check_indirection --- check the result of indirection production
11346 * We only allow '*' at the end of the list, but it's hard to enforce that
11347 * in the grammar, so do it here.
11350 check_indirection(List *indirection, core_yyscan_t yyscanner)
11354 foreach(l, indirection)
11356 if (IsA(lfirst(l), A_Star))
11358 if (lnext(l) != NULL)
11359 parser_yyerror("improper use of \"*\"");
11362 return indirection;
11365 /* extractArgTypes()
11366 * Given a list of FunctionParameter nodes, extract a list of just the
11367 * argument types (TypeNames) for input parameters only. This is what
11368 * is needed to look up an existing function, which is what is wanted by
11369 * the productions that use this call.
11372 extractArgTypes(List *parameters)
11374 List *result = NIL;
11377 foreach(i, parameters)
11379 FunctionParameter *p = (FunctionParameter *) lfirst(i);
11381 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
11382 result = lappend(result, p->argType);
11387 /* findLeftmostSelect()
11388 * Find the leftmost component SelectStmt in a set-operation parsetree.
11390 static SelectStmt *
11391 findLeftmostSelect(SelectStmt *node)
11393 while (node && node->op != SETOP_NONE)
11395 Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
11399 /* insertSelectOptions()
11400 * Insert ORDER BY, etc into an already-constructed SelectStmt.
11402 * This routine is just to avoid duplicating code in SelectStmt productions.
11405 insertSelectOptions(SelectStmt *stmt,
11406 List *sortClause, List *lockingClause,
11407 Node *limitOffset, Node *limitCount,
11408 WithClause *withClause,
11409 core_yyscan_t yyscanner)
11411 Assert(IsA(stmt, SelectStmt));
11414 * Tests here are to reject constructs like
11415 * (SELECT foo ORDER BY bar) ORDER BY baz
11419 if (stmt->sortClause)
11421 (errcode(ERRCODE_SYNTAX_ERROR),
11422 errmsg("multiple ORDER BY clauses not allowed"),
11423 parser_errposition(exprLocation((Node *) sortClause))));
11424 stmt->sortClause = sortClause;
11426 /* We can handle multiple locking clauses, though */
11427 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
11430 if (stmt->limitOffset)
11432 (errcode(ERRCODE_SYNTAX_ERROR),
11433 errmsg("multiple OFFSET clauses not allowed"),
11434 parser_errposition(exprLocation(limitOffset))));
11435 stmt->limitOffset = limitOffset;
11439 if (stmt->limitCount)
11441 (errcode(ERRCODE_SYNTAX_ERROR),
11442 errmsg("multiple LIMIT clauses not allowed"),
11443 parser_errposition(exprLocation(limitCount))));
11444 stmt->limitCount = limitCount;
11448 if (stmt->withClause)
11450 (errcode(ERRCODE_SYNTAX_ERROR),
11451 errmsg("multiple WITH clauses not allowed"),
11452 parser_errposition(exprLocation((Node *) withClause))));
11453 stmt->withClause = withClause;
11458 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
11460 SelectStmt *n = makeNode(SelectStmt);
11464 n->larg = (SelectStmt *) larg;
11465 n->rarg = (SelectStmt *) rarg;
11469 /* SystemFuncName()
11470 * Build a properly-qualified reference to a built-in function.
11473 SystemFuncName(char *name)
11475 return list_make2(makeString("pg_catalog"), makeString(name));
11478 /* SystemTypeName()
11479 * Build a properly-qualified reference to a built-in type.
11481 * typmod is defaulted, but may be changed afterwards by caller.
11482 * Likewise for the location.
11485 SystemTypeName(char *name)
11487 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
11488 makeString(name)));
11492 * Handle negation of a numeric constant.
11494 * Formerly, we did this here because the optimizer couldn't cope with
11495 * indexquals that looked like "var = -4" --- it wants "var = const"
11496 * and a unary minus operator applied to a constant didn't qualify.
11497 * As of Postgres 7.0, that problem doesn't exist anymore because there
11498 * is a constant-subexpression simplifier in the optimizer. However,
11499 * there's still a good reason for doing this here, which is that we can
11500 * postpone committing to a particular internal representation for simple
11501 * negative constants. It's better to leave "-123.456" in string form
11502 * until we know what the desired type is.
11505 doNegate(Node *n, int location)
11507 if (IsA(n, A_Const))
11509 A_Const *con = (A_Const *)n;
11511 /* report the constant's location as that of the '-' sign */
11512 con->location = location;
11514 if (con->val.type == T_Integer)
11516 con->val.val.ival = -con->val.val.ival;
11519 if (con->val.type == T_Float)
11521 doNegateFloat(&con->val);
11526 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
11530 doNegateFloat(Value *v)
11532 char *oldval = v->val.str;
11534 Assert(IsA(v, Float));
11535 if (*oldval == '+')
11537 if (*oldval == '-')
11538 v->val.str = oldval+1; /* just strip the '-' */
11541 char *newval = (char *) palloc(strlen(oldval) + 2);
11544 strcpy(newval+1, oldval);
11545 v->val.str = newval;
11550 makeAArrayExpr(List *elements, int location)
11552 A_ArrayExpr *n = makeNode(A_ArrayExpr);
11554 n->elements = elements;
11555 n->location = location;
11560 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
11563 XmlExpr *x = makeNode(XmlExpr);
11568 * named_args is a list of ResTarget; it'll be split apart into separate
11569 * expression and name lists in transformXmlExpr().
11571 x->named_args = named_args;
11572 x->arg_names = NIL;
11574 /* xmloption, if relevant, must be filled in by caller */
11575 /* type and typmod will be filled in during parse analysis */
11576 x->location = location;
11581 * Initialize to parse one query string
11584 parser_init(base_yy_extra_type *yyext)
11586 yyext->parsetree = NIL; /* in case grammar forgets to set it */
11590 * Merge the input and output parameters of a table function.
11593 mergeTableFuncParameters(List *func_args, List *columns)
11597 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
11598 foreach(lc, func_args)
11600 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
11602 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
11604 (errcode(ERRCODE_SYNTAX_ERROR),
11605 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
11608 return list_concat(func_args, columns);
11612 * Determine return type of a TABLE function. A single result column
11613 * returns setof that column's type; otherwise return setof record.
11616 TableFuncTypeName(List *columns)
11620 if (list_length(columns) == 1)
11622 FunctionParameter *p = (FunctionParameter *) linitial(columns);
11624 result = (TypeName *) copyObject(p->argType);
11627 result = SystemTypeName("record");
11629 result->setof = true;
11635 * Must undefine this stuff before including scan.c, since it has different
11636 * definitions for these macros.