4 /*-------------------------------------------------------------------------
7 * POSTGRESQL BISON rules/actions
9 * Portions Copyright (c) 1996-2010, 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.706 2010/01/28 23:21:12 petere Exp $
17 * AUTHOR DATE MAJOR EVENT
18 * Andrew Yu Sept, 1994 POSTQUEL to SQL conversion
19 * Andrew Yu Oct, 1994 lispy code conversion
22 * CAPITALS are used to represent terminal symbols.
23 * non-capitals are used to represent non-terminals.
24 * SQL92-specific syntax is separated from plain SQL/Postgres syntax
25 * to help isolate the non-extensible portions of the parser.
27 * In general, nothing in this file should initiate database accesses
28 * nor depend on changeable state (such as SET variables). If you do
29 * database accesses, your code will fail when we have aborted the
30 * current transaction and are just parsing commands to find the next
31 * ROLLBACK or COMMIT. If you make use of SET variables, then you
32 * will do the wrong thing in multi-query strings like this:
33 * SET SQL_inheritance TO off; SELECT * FROM foo;
34 * because the entire string is parsed by gram.y before the SET gets
35 * executed. Anything that depends on the database or changeable state
36 * should be handled during parse analysis so that it happens at the
37 * right time not the wrong time. The handling of SQL_inheritance is
41 * If you use a list, make sure the datum is a node so that the printing
44 * Sometimes we assign constants to makeStrings. Make sure we don't free
47 *-------------------------------------------------------------------------
54 #include "catalog/index.h"
55 #include "catalog/namespace.h"
56 #include "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 name cursor_name file_name
257 index_name opt_index_name cluster_index_specification
259 %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
260 opt_class opt_inline_handler opt_validator validator_clause
262 %type <range> qualified_name OptConstrFromTable
264 %type <str> all_Op MathOp
266 %type <str> iso_level opt_encoding
268 %type <list> grantee_list
269 %type <accesspriv> privilege
270 %type <list> privileges privilege_list
271 %type <privtarget> privilege_target
272 %type <funwithargs> function_with_argtypes
273 %type <list> function_with_argtypes_list
274 %type <ival> defacl_privilege_target
275 %type <defelt> DefACLOption
276 %type <list> DefACLOptionList
278 %type <list> stmtblock stmtmulti
279 OptTableElementList TableElementList OptInherit definition
280 OptTypedTableElementList TypedTableElementList
281 reloptions opt_reloptions
282 OptWith opt_distinct opt_definition func_args func_args_list
283 func_args_with_defaults func_args_with_defaults_list
284 func_as createfunc_opt_list alterfunc_opt_list
285 aggr_args old_aggr_definition old_aggr_list
286 oper_argtypes RuleActionList RuleActionMulti
287 opt_column_list columnList opt_name_list
288 sort_clause opt_sort_clause sortby_list index_params
289 name_list from_clause from_list opt_array_bounds
290 qualified_name_list any_name any_name_list
291 any_operator expr_list attrs
292 target_list insert_column_list set_target_list
293 set_clause_list set_clause multiple_set_clause
294 ctext_expr_list ctext_row def_list indirection opt_indirection
295 reloption_list group_clause TriggerFuncArgs select_limit
296 opt_select_limit opclass_item_list opclass_drop_list
297 opt_opfamily transaction_mode_list_or_empty
298 TableFuncElementList opt_type_modifiers
300 execute_param_clause using_clause returning_clause
301 opt_enum_val_list enum_val_list table_func_column_list
302 create_generic_options alter_generic_options
303 relation_expr_list dostmt_opt_list
305 %type <range> OptTempTableName
306 %type <into> into_clause create_as_target
308 %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
309 %type <fun_param> func_arg func_arg_with_default table_func_column
310 %type <fun_param_mode> arg_class
311 %type <typnam> func_return func_type
313 %type <boolean> TriggerForType OptTemp
314 %type <oncommit> OnCommitOption
316 %type <node> for_locking_item
317 %type <list> for_locking_clause opt_for_locking_clause for_locking_items
318 %type <list> locked_rels_list
319 %type <boolean> opt_all
321 %type <node> join_outer join_qual
322 %type <jtype> join_type
324 %type <list> extract_list overlay_list position_list
325 %type <list> substr_list trim_list
326 %type <list> opt_interval interval_second
327 %type <node> overlay_placing substr_from substr_for
329 %type <boolean> opt_instead
330 %type <boolean> opt_unique opt_concurrently opt_verbose opt_full
331 %type <boolean> opt_freeze opt_default opt_recheck
332 %type <defelt> opt_binary opt_oids copy_delimiter
334 %type <boolean> copy_from
336 %type <ival> opt_column event cursor_options opt_hold opt_set_data
337 %type <objtype> reindex_type drop_type comment_type
339 %type <node> fetch_args limit_clause select_limit_value
340 offset_clause select_offset_value
341 select_offset_value2 opt_select_fetch_first_value
342 %type <ival> row_or_rows first_or_next
344 %type <list> OptSeqOptList SeqOptList
345 %type <defelt> SeqOptElem
347 %type <istmt> insert_rest
349 %type <vsetstmt> set_rest SetResetClause
351 %type <node> TableElement TypedTableElement ConstraintElem TableFuncElement
352 %type <node> columnDef columnOptions
353 %type <defelt> def_elem reloption_elem old_aggr_elem
354 %type <node> def_arg columnElem where_clause where_or_current_clause
355 a_expr b_expr c_expr func_expr AexprConst indirection_el
356 columnref in_expr having_clause func_table array_expr
358 %type <list> ExclusionConstraintList ExclusionConstraintElem
359 %type <list> func_arg_list
360 %type <node> func_arg_expr
361 %type <list> row type_list array_expr_list
362 %type <node> case_expr case_arg when_clause case_default
363 %type <list> when_clause_list
364 %type <ival> sub_type
365 %type <list> OptCreateAs CreateAsList
366 %type <node> CreateAsElement ctext_expr
367 %type <value> NumericOnly
368 %type <alias> alias_clause
369 %type <sortby> sortby
370 %type <ielem> index_elem
371 %type <node> table_ref
372 %type <jexpr> joined_table
373 %type <range> relation_expr
374 %type <range> relation_expr_opt_alias
375 %type <target> target_el single_set_clause set_target insert_column_item
377 %type <str> generic_option_name
378 %type <node> generic_option_arg
379 %type <defelt> generic_option_elem alter_generic_option_elem
380 %type <list> generic_option_list alter_generic_option_list
381 %type <str> explain_option_name
382 %type <node> explain_option_arg
383 %type <defelt> explain_option_elem
384 %type <list> explain_option_list
385 %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
386 %type <defelt> copy_generic_opt_elem
387 %type <list> copy_generic_opt_list copy_generic_opt_arg_list
388 %type <list> copy_options
390 %type <typnam> Typename SimpleTypename ConstTypename
391 GenericType Numeric opt_float
392 Character ConstCharacter
393 CharacterWithLength CharacterWithoutLength
394 ConstDatetime ConstInterval
395 Bit ConstBit BitWithLength BitWithoutLength
396 %type <str> character
397 %type <str> extract_arg
398 %type <str> opt_charset
399 %type <boolean> opt_varying opt_timezone
401 %type <ival> Iconst SignedIconst
402 %type <list> Iconst_list
403 %type <str> Sconst comment_text
404 %type <str> RoleId opt_granted_by opt_boolean ColId_or_Sconst
405 %type <list> var_list
406 %type <str> ColId ColLabel var_name type_function_name param_name
407 %type <node> var_value zone_value
409 %type <keyword> unreserved_keyword type_func_name_keyword
410 %type <keyword> col_name_keyword reserved_keyword
412 %type <node> TableConstraint TableLikeClause
413 %type <ival> TableLikeOptionList TableLikeOption
414 %type <list> ColQualList
415 %type <node> ColConstraint ColConstraintElem ConstraintAttr
416 %type <ival> key_actions key_delete key_match key_update key_action
417 %type <ival> ConstraintAttributeSpec ConstraintDeferrabilitySpec
420 %type <list> constraints_set_list
421 %type <boolean> constraints_set_mode
422 %type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
423 %type <list> opt_check_option
425 %type <target> xml_attribute_el
426 %type <list> xml_attribute_list xml_attributes
427 %type <node> xml_root_version opt_xml_root_standalone
428 %type <ival> document_or_content
429 %type <boolean> xml_whitespace_option
431 %type <node> common_table_expr
432 %type <with> with_clause
433 %type <list> cte_list
435 %type <list> window_clause window_definition_list opt_partition_clause
436 %type <windef> window_definition over_clause window_specification
437 %type <str> opt_existing_window_name
438 %type <ival> opt_frame_clause frame_extent frame_bound
442 * Non-keyword token types. These are hard-wired into the "flex" lexer.
443 * They must be listed first so that their numeric codes do not depend on
444 * the set of keywords. PL/pgsql depends on this so that it can share the
445 * same lexer. If you add/change tokens here, fix PL/pgsql to match!
447 * DOT_DOT and COLON_EQUALS are unused in the core SQL grammar, and so will
448 * always provoke parse errors. They are needed by PL/pgsql.
450 %token <str> IDENT FCONST SCONST BCONST XCONST Op
451 %token <ival> ICONST PARAM
452 %token TYPECAST DOT_DOT COLON_EQUALS
455 * If you want to make any keyword changes, update the keyword table in
456 * src/include/parser/kwlist.h and add new keywords to the appropriate one
457 * of the reserved-or-not-so-reserved keyword lists, below; search
458 * this file for "Keyword category lists".
461 /* ordinary key words in alphabetical order */
462 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
463 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
464 ASSERTION ASSIGNMENT ASYMMETRIC AT AUTHORIZATION
466 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
469 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
470 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
471 CLUSTER COALESCE COLLATE COLUMN COMMENT COMMENTS COMMIT
472 COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
473 CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
474 CREATEROLE CREATEUSER CROSS CSV CURRENT_P
475 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
476 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
478 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
479 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
480 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
482 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT
483 EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
485 FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOLLOWING FOR FORCE FOREIGN FORWARD
486 FREEZE FROM FULL FUNCTION FUNCTIONS
488 GLOBAL GRANT GRANTED GREATEST GROUP_P
490 HANDLER HAVING HEADER_P HOLD HOUR_P
492 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
493 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
494 INNER_P INOUT INPLACE INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
495 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
501 LANGUAGE LARGE_P LAST_P LC_COLLATE_P LC_CTYPE_P LEADING
502 LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP
503 LOCATION LOCK_P LOGIN_P
505 MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
507 NAME_P NAMES NATIONAL NATURAL NCHAR NEXT NO NOCREATEDB
508 NOCREATEROLE NOCREATEUSER NOINHERIT NOLOGIN_P NONE NOSUPERUSER
509 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NULLS_P NUMERIC
511 OBJECT_P OF OFF OFFSET OIDS ON ONLY OPERATOR OPTION OPTIONS OR
512 ORDER OUT_P OUTER_P OVER OVERLAPS OVERLAY OWNED OWNER
514 PARSER PARTIAL PARTITION PASSWORD PLACING PLANS POSITION
515 PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
516 PRIOR PRIVILEGES PROCEDURAL PROCEDURE
520 RANGE READ REAL REASSIGN RECHECK RECURSIVE REFERENCES REINDEX
521 RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA RESET RESTART
522 RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROW ROWS RULE
524 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE SEQUENCES
525 SERIALIZABLE SERVER SESSION SESSION_USER SET SETOF SHARE
526 SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT
527 STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING SUPERUSER_P
528 SYMMETRIC SYSID SYSTEM_P
530 TABLE TABLES TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
531 TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
532 TRUNCATE TRUSTED TYPE_P
534 UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
537 VACUUM VALID VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
538 VERBOSE VERSION_P VIEW VOLATILE
540 WHEN WHERE WHITESPACE_P WINDOW WITH WITHOUT WORK WRAPPER WRITE
542 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLFOREST XMLPARSE
543 XMLPI XMLROOT XMLSERIALIZE
550 * The grammar thinks these are keywords, but they are not in the kwlist.h
551 * list and so can never be entered directly. The filter in parser.c
552 * creates these tokens when required.
554 %token NULLS_FIRST NULLS_LAST WITH_TIME
557 /* Precedence: lowest to highest */
558 %nonassoc SET /* see relation_expr_opt_alias */
566 %nonassoc LIKE ILIKE SIMILAR
571 %left POSTFIXOP /* dummy for postfix Op rules */
573 * To support target_el without AS, we must give IDENT an explicit priority
574 * between POSTFIXOP and Op. We can safely assign the same priority to
575 * various unreserved keywords as needed to resolve ambiguities (this can't
576 * have any bad effects since obviously the keywords will still behave the
577 * same as if they weren't keywords). We need to do this for PARTITION,
578 * RANGE, ROWS to support opt_existing_window_name; and for RANGE, ROWS
579 * so that they can follow a_expr without creating
580 * postfix-operator problems.
582 %nonassoc IDENT PARTITION RANGE ROWS
583 %left Op OPERATOR /* multi-character ops and user-defined operators */
586 %nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN /* sets precedence for IS NULL, etc */
590 /* Unary Operators */
591 %left AT ZONE /* sets precedence for AT TIME ZONE */
598 * These might seem to be low-precedence, but actually they are not part
599 * of the arithmetic hierarchy at all in their use as JOIN operators.
600 * We make them high-precedence to support their use as function names.
601 * They wouldn't be given a precedence at all, were it not that we need
602 * left-associativity among the JOIN rules themselves.
604 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
605 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
606 %right PRESERVE STRIP_P
611 * The target production for the whole parse.
615 pg_yyget_extra(yyscanner)->parsetree = $1;
619 /* the thrashing around here is to discard "empty" statements... */
620 stmtmulti: stmtmulti ';' stmt
623 $$ = lappend($1, $3);
638 | AlterDatabaseSetStmt
639 | AlterDefaultPrivilegesStmt
642 | AlterForeignServerStmt
645 | AlterObjectSchemaStmt
651 | AlterTSConfigurationStmt
652 | AlterTSDictionaryStmt
653 | AlterUserMappingStmt
666 | CreateConversionStmt
669 | CreateForeignServerStmt
679 | CreateTableSpaceStmt
683 | CreateUserMappingStmt
694 | DropForeignServerStmt
706 | DropUserMappingStmt
743 /*****************************************************************************
745 * Create a new Postgres DBMS role
747 *****************************************************************************/
750 CREATE ROLE RoleId opt_with OptRoleList
752 CreateRoleStmt *n = makeNode(CreateRoleStmt);
753 n->stmt_type = ROLESTMT_ROLE;
766 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
767 * for backwards compatibility). Note: the only option required by SQL99
768 * is "WITH ADMIN name".
771 OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
772 | /* EMPTY */ { $$ = NIL; }
776 AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
777 | /* EMPTY */ { $$ = NIL; }
783 $$ = makeDefElem("password",
784 (Node *)makeString($2));
788 $$ = makeDefElem("password", NULL);
790 | ENCRYPTED PASSWORD Sconst
792 $$ = makeDefElem("encryptedPassword",
793 (Node *)makeString($3));
795 | UNENCRYPTED PASSWORD Sconst
797 $$ = makeDefElem("unencryptedPassword",
798 (Node *)makeString($3));
802 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
806 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
810 $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE));
814 $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE));
818 $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
822 $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
826 $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE));
830 $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE));
834 /* For backwards compatibility, synonym for SUPERUSER */
835 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
839 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
843 $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE));
847 $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE));
849 | CONNECTION LIMIT SignedIconst
851 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3));
855 $$ = makeDefElem("validUntil", (Node *)makeString($3));
857 /* Supported but not documented for roles, for use by ALTER GROUP. */
860 $$ = makeDefElem("rolemembers", (Node *)$2);
865 AlterOptRoleElem { $$ = $1; }
866 /* The following are not supported by ALTER ROLE/USER/GROUP */
869 $$ = makeDefElem("sysid", (Node *)makeInteger($2));
873 $$ = makeDefElem("adminmembers", (Node *)$2);
877 $$ = makeDefElem("rolemembers", (Node *)$2);
879 | IN_P ROLE name_list
881 $$ = makeDefElem("addroleto", (Node *)$3);
883 | IN_P GROUP_P name_list
885 $$ = makeDefElem("addroleto", (Node *)$3);
890 /*****************************************************************************
892 * Create a new Postgres DBMS user (role with implied login ability)
894 *****************************************************************************/
897 CREATE USER RoleId opt_with OptRoleList
899 CreateRoleStmt *n = makeNode(CreateRoleStmt);
900 n->stmt_type = ROLESTMT_USER;
908 /*****************************************************************************
910 * Alter a postgresql DBMS role
912 *****************************************************************************/
915 ALTER ROLE RoleId opt_with AlterOptRoleList
917 AlterRoleStmt *n = makeNode(AlterRoleStmt);
919 n->action = +1; /* add, if there are members */
926 /* EMPTY */ { $$ = NULL; }
927 | IN_P DATABASE database_name { $$ = $3; }
931 ALTER ROLE RoleId opt_in_database SetResetClause
933 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
942 /*****************************************************************************
944 * Alter a postgresql DBMS user
946 *****************************************************************************/
949 ALTER USER RoleId opt_with AlterOptRoleList
951 AlterRoleStmt *n = makeNode(AlterRoleStmt);
953 n->action = +1; /* add, if there are members */
961 ALTER USER RoleId SetResetClause
963 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
972 /*****************************************************************************
974 * Drop a postgresql DBMS role
976 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
977 * might own objects in multiple databases, there is presently no way to
978 * implement either cascading or restricting. Caveat DBA.
979 *****************************************************************************/
984 DropRoleStmt *n = makeNode(DropRoleStmt);
985 n->missing_ok = FALSE;
989 | DROP ROLE IF_P EXISTS name_list
991 DropRoleStmt *n = makeNode(DropRoleStmt);
992 n->missing_ok = TRUE;
998 /*****************************************************************************
1000 * Drop a postgresql DBMS user
1002 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
1003 * might own objects in multiple databases, there is presently no way to
1004 * implement either cascading or restricting. Caveat DBA.
1005 *****************************************************************************/
1010 DropRoleStmt *n = makeNode(DropRoleStmt);
1011 n->missing_ok = FALSE;
1015 | DROP USER IF_P EXISTS name_list
1017 DropRoleStmt *n = makeNode(DropRoleStmt);
1019 n->missing_ok = TRUE;
1025 /*****************************************************************************
1027 * Create a postgresql group (role without login ability)
1029 *****************************************************************************/
1032 CREATE GROUP_P RoleId opt_with OptRoleList
1034 CreateRoleStmt *n = makeNode(CreateRoleStmt);
1035 n->stmt_type = ROLESTMT_GROUP;
1043 /*****************************************************************************
1045 * Alter a postgresql group
1047 *****************************************************************************/
1050 ALTER GROUP_P RoleId add_drop USER name_list
1052 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1055 n->options = list_make1(makeDefElem("rolemembers",
1061 add_drop: ADD_P { $$ = +1; }
1066 /*****************************************************************************
1068 * Drop a postgresql group
1070 * XXX see above notes about cascading DROP USER; groups have same problem.
1071 *****************************************************************************/
1074 DROP GROUP_P name_list
1076 DropRoleStmt *n = makeNode(DropRoleStmt);
1077 n->missing_ok = FALSE;
1081 | DROP GROUP_P IF_P EXISTS name_list
1083 DropRoleStmt *n = makeNode(DropRoleStmt);
1084 n->missing_ok = TRUE;
1091 /*****************************************************************************
1093 * Manipulate a schema
1095 *****************************************************************************/
1098 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
1100 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1101 /* One can omit the schema name or the authorization id. */
1110 | CREATE SCHEMA ColId OptSchemaEltList
1112 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1113 /* ...but not both */
1123 | /* EMPTY */ { $$ = NULL; }
1127 OptSchemaEltList schema_stmt { $$ = lappend($1, $2); }
1128 | /* EMPTY */ { $$ = NIL; }
1132 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1133 * statement (in addition to by themselves).
1145 /*****************************************************************************
1147 * Set PG internal variable
1148 * SET name TO 'var_value'
1149 * Include SQL92 syntax (thomas 1997-10-22):
1150 * SET TIME ZONE 'var_value'
1152 *****************************************************************************/
1157 VariableSetStmt *n = $2;
1158 n->is_local = false;
1161 | SET LOCAL set_rest
1163 VariableSetStmt *n = $3;
1167 | SET SESSION set_rest
1169 VariableSetStmt *n = $3;
1170 n->is_local = false;
1175 set_rest: /* Generic SET syntaxes: */
1176 var_name TO var_list
1178 VariableSetStmt *n = makeNode(VariableSetStmt);
1179 n->kind = VAR_SET_VALUE;
1184 | var_name '=' var_list
1186 VariableSetStmt *n = makeNode(VariableSetStmt);
1187 n->kind = VAR_SET_VALUE;
1192 | var_name TO DEFAULT
1194 VariableSetStmt *n = makeNode(VariableSetStmt);
1195 n->kind = VAR_SET_DEFAULT;
1199 | var_name '=' DEFAULT
1201 VariableSetStmt *n = makeNode(VariableSetStmt);
1202 n->kind = VAR_SET_DEFAULT;
1206 | var_name FROM CURRENT_P
1208 VariableSetStmt *n = makeNode(VariableSetStmt);
1209 n->kind = VAR_SET_CURRENT;
1213 /* Special syntaxes mandated by SQL standard: */
1214 | TIME ZONE zone_value
1216 VariableSetStmt *n = makeNode(VariableSetStmt);
1217 n->kind = VAR_SET_VALUE;
1218 n->name = "timezone";
1220 n->args = list_make1($3);
1222 n->kind = VAR_SET_DEFAULT;
1225 | TRANSACTION transaction_mode_list
1227 VariableSetStmt *n = makeNode(VariableSetStmt);
1228 n->kind = VAR_SET_MULTI;
1229 n->name = "TRANSACTION";
1233 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1235 VariableSetStmt *n = makeNode(VariableSetStmt);
1236 n->kind = VAR_SET_MULTI;
1237 n->name = "SESSION CHARACTERISTICS";
1244 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1245 errmsg("current database cannot be changed"),
1246 parser_errposition(@2)));
1247 $$ = NULL; /*not reached*/
1251 VariableSetStmt *n = makeNode(VariableSetStmt);
1252 n->kind = VAR_SET_VALUE;
1253 n->name = "search_path";
1254 n->args = list_make1(makeStringConst($2, @2));
1257 | NAMES opt_encoding
1259 VariableSetStmt *n = makeNode(VariableSetStmt);
1260 n->kind = VAR_SET_VALUE;
1261 n->name = "client_encoding";
1263 n->args = list_make1(makeStringConst($2, @2));
1265 n->kind = VAR_SET_DEFAULT;
1268 | ROLE ColId_or_Sconst
1270 VariableSetStmt *n = makeNode(VariableSetStmt);
1271 n->kind = VAR_SET_VALUE;
1273 n->args = list_make1(makeStringConst($2, @2));
1276 | SESSION AUTHORIZATION ColId_or_Sconst
1278 VariableSetStmt *n = makeNode(VariableSetStmt);
1279 n->kind = VAR_SET_VALUE;
1280 n->name = "session_authorization";
1281 n->args = list_make1(makeStringConst($3, @3));
1284 | SESSION AUTHORIZATION DEFAULT
1286 VariableSetStmt *n = makeNode(VariableSetStmt);
1287 n->kind = VAR_SET_DEFAULT;
1288 n->name = "session_authorization";
1291 | XML_P OPTION document_or_content
1293 VariableSetStmt *n = makeNode(VariableSetStmt);
1294 n->kind = VAR_SET_VALUE;
1295 n->name = "xmloption";
1296 n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1301 var_name: ColId { $$ = $1; }
1302 | var_name '.' ColId
1304 $$ = palloc(strlen($1) + strlen($3) + 2);
1305 sprintf($$, "%s.%s", $1, $3);
1309 var_list: var_value { $$ = list_make1($1); }
1310 | var_list ',' var_value { $$ = lappend($1, $3); }
1313 var_value: opt_boolean
1314 { $$ = makeStringConst($1, @1); }
1316 { $$ = makeStringConst($1, @1); }
1318 { $$ = makeAConst($1, @1); }
1321 iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1322 | READ COMMITTED { $$ = "read committed"; }
1323 | REPEATABLE READ { $$ = "repeatable read"; }
1324 | SERIALIZABLE { $$ = "serializable"; }
1328 TRUE_P { $$ = "true"; }
1329 | FALSE_P { $$ = "false"; }
1331 | OFF { $$ = "off"; }
1334 /* Timezone values can be:
1335 * - a string such as 'pst8pdt'
1336 * - an identifier such as "pst8pdt"
1337 * - an integer or floating point number
1338 * - a time interval per SQL99
1339 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1340 * so use IDENT (meaning we reject anything that is a key word).
1345 $$ = makeStringConst($1, @1);
1349 $$ = makeStringConst($1, @1);
1351 | ConstInterval Sconst opt_interval
1356 A_Const *n = (A_Const *) linitial($3);
1357 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1359 (errcode(ERRCODE_SYNTAX_ERROR),
1360 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1361 parser_errposition(@3)));
1364 $$ = makeStringConstCast($2, @2, t);
1366 | ConstInterval '(' Iconst ')' Sconst opt_interval
1371 A_Const *n = (A_Const *) linitial($6);
1372 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1374 (errcode(ERRCODE_SYNTAX_ERROR),
1375 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1376 parser_errposition(@6)));
1377 if (list_length($6) != 1)
1379 (errcode(ERRCODE_SYNTAX_ERROR),
1380 errmsg("interval precision specified twice"),
1381 parser_errposition(@1)));
1382 t->typmods = lappend($6, makeIntConst($3, @3));
1385 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1386 makeIntConst($3, @3));
1387 $$ = makeStringConstCast($5, @5, t);
1389 | NumericOnly { $$ = makeAConst($1, @1); }
1390 | DEFAULT { $$ = NULL; }
1391 | LOCAL { $$ = NULL; }
1396 | DEFAULT { $$ = NULL; }
1397 | /*EMPTY*/ { $$ = NULL; }
1402 | Sconst { $$ = $1; }
1408 VariableSetStmt *n = makeNode(VariableSetStmt);
1409 n->kind = VAR_RESET;
1415 VariableSetStmt *n = makeNode(VariableSetStmt);
1416 n->kind = VAR_RESET;
1417 n->name = "timezone";
1420 | RESET TRANSACTION ISOLATION LEVEL
1422 VariableSetStmt *n = makeNode(VariableSetStmt);
1423 n->kind = VAR_RESET;
1424 n->name = "transaction_isolation";
1427 | RESET SESSION AUTHORIZATION
1429 VariableSetStmt *n = makeNode(VariableSetStmt);
1430 n->kind = VAR_RESET;
1431 n->name = "session_authorization";
1436 VariableSetStmt *n = makeNode(VariableSetStmt);
1437 n->kind = VAR_RESET_ALL;
1442 /* SetResetClause allows SET or RESET without LOCAL */
1444 SET set_rest { $$ = $2; }
1445 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1452 VariableShowStmt *n = makeNode(VariableShowStmt);
1458 VariableShowStmt *n = makeNode(VariableShowStmt);
1459 n->name = "timezone";
1462 | SHOW TRANSACTION ISOLATION LEVEL
1464 VariableShowStmt *n = makeNode(VariableShowStmt);
1465 n->name = "transaction_isolation";
1468 | SHOW SESSION AUTHORIZATION
1470 VariableShowStmt *n = makeNode(VariableShowStmt);
1471 n->name = "session_authorization";
1476 VariableShowStmt *n = makeNode(VariableShowStmt);
1484 SET CONSTRAINTS constraints_set_list constraints_set_mode
1486 ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
1487 n->constraints = $3;
1493 constraints_set_list:
1495 | qualified_name_list { $$ = $1; }
1498 constraints_set_mode:
1499 DEFERRED { $$ = TRUE; }
1500 | IMMEDIATE { $$ = FALSE; }
1505 * Checkpoint statement
1510 CheckPointStmt *n = makeNode(CheckPointStmt);
1516 /*****************************************************************************
1518 * DISCARD { ALL | TEMP | PLANS }
1520 *****************************************************************************/
1525 DiscardStmt *n = makeNode(DiscardStmt);
1526 n->target = DISCARD_ALL;
1531 DiscardStmt *n = makeNode(DiscardStmt);
1532 n->target = DISCARD_TEMP;
1537 DiscardStmt *n = makeNode(DiscardStmt);
1538 n->target = DISCARD_TEMP;
1543 DiscardStmt *n = makeNode(DiscardStmt);
1544 n->target = DISCARD_PLANS;
1550 /*****************************************************************************
1552 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations
1554 * Note: we accept all subcommands for each of the four variants, and sort
1555 * out what's really legal at execution time.
1556 *****************************************************************************/
1559 ALTER TABLE relation_expr alter_table_cmds
1561 AlterTableStmt *n = makeNode(AlterTableStmt);
1564 n->relkind = OBJECT_TABLE;
1567 | ALTER INDEX qualified_name alter_table_cmds
1569 AlterTableStmt *n = makeNode(AlterTableStmt);
1572 n->relkind = OBJECT_INDEX;
1575 | ALTER SEQUENCE qualified_name alter_table_cmds
1577 AlterTableStmt *n = makeNode(AlterTableStmt);
1580 n->relkind = OBJECT_SEQUENCE;
1583 | ALTER VIEW qualified_name alter_table_cmds
1585 AlterTableStmt *n = makeNode(AlterTableStmt);
1588 n->relkind = OBJECT_VIEW;
1594 alter_table_cmd { $$ = list_make1($1); }
1595 | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
1599 /* ALTER TABLE <name> ADD <coldef> */
1602 AlterTableCmd *n = makeNode(AlterTableCmd);
1603 n->subtype = AT_AddColumn;
1607 /* ALTER TABLE <name> ADD COLUMN <coldef> */
1608 | ADD_P COLUMN columnDef
1610 AlterTableCmd *n = makeNode(AlterTableCmd);
1611 n->subtype = AT_AddColumn;
1615 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1616 | ALTER opt_column ColId alter_column_default
1618 AlterTableCmd *n = makeNode(AlterTableCmd);
1619 n->subtype = AT_ColumnDefault;
1624 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1625 | ALTER opt_column ColId DROP NOT NULL_P
1627 AlterTableCmd *n = makeNode(AlterTableCmd);
1628 n->subtype = AT_DropNotNull;
1632 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1633 | ALTER opt_column ColId SET NOT NULL_P
1635 AlterTableCmd *n = makeNode(AlterTableCmd);
1636 n->subtype = AT_SetNotNull;
1640 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
1641 | ALTER opt_column ColId SET STATISTICS SignedIconst
1643 AlterTableCmd *n = makeNode(AlterTableCmd);
1644 n->subtype = AT_SetStatistics;
1646 n->def = (Node *) makeInteger($6);
1649 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
1650 | ALTER opt_column ColId SET reloptions
1652 AlterTableCmd *n = makeNode(AlterTableCmd);
1653 n->subtype = AT_SetOptions;
1655 n->def = (Node *) $5;
1658 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
1659 | ALTER opt_column ColId RESET reloptions
1661 AlterTableCmd *n = makeNode(AlterTableCmd);
1662 n->subtype = AT_ResetOptions;
1664 n->def = (Node *) $5;
1667 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1668 | ALTER opt_column ColId SET STORAGE ColId
1670 AlterTableCmd *n = makeNode(AlterTableCmd);
1671 n->subtype = AT_SetStorage;
1673 n->def = (Node *) makeString($6);
1676 /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
1677 | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
1679 AlterTableCmd *n = makeNode(AlterTableCmd);
1680 n->subtype = AT_DropColumn;
1683 n->missing_ok = TRUE;
1686 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1687 | DROP opt_column ColId opt_drop_behavior
1689 AlterTableCmd *n = makeNode(AlterTableCmd);
1690 n->subtype = AT_DropColumn;
1693 n->missing_ok = FALSE;
1697 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
1698 * [ USING <expression> ]
1700 | ALTER opt_column ColId opt_set_data TYPE_P Typename alter_using
1702 AlterTableCmd *n = makeNode(AlterTableCmd);
1703 n->subtype = AT_AlterColumnType;
1705 n->def = (Node *) $6;
1709 /* ALTER TABLE <name> ADD CONSTRAINT ... */
1710 | ADD_P TableConstraint
1712 AlterTableCmd *n = makeNode(AlterTableCmd);
1713 n->subtype = AT_AddConstraint;
1717 /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
1718 | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
1720 AlterTableCmd *n = makeNode(AlterTableCmd);
1721 n->subtype = AT_DropConstraint;
1724 n->missing_ok = TRUE;
1727 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1728 | DROP CONSTRAINT name opt_drop_behavior
1730 AlterTableCmd *n = makeNode(AlterTableCmd);
1731 n->subtype = AT_DropConstraint;
1734 n->missing_ok = FALSE;
1737 /* ALTER TABLE <name> SET WITH OIDS */
1740 AlterTableCmd *n = makeNode(AlterTableCmd);
1741 n->subtype = AT_AddOids;
1744 /* ALTER TABLE <name> SET WITHOUT OIDS */
1747 AlterTableCmd *n = makeNode(AlterTableCmd);
1748 n->subtype = AT_DropOids;
1751 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1754 AlterTableCmd *n = makeNode(AlterTableCmd);
1755 n->subtype = AT_ClusterOn;
1759 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1760 | SET WITHOUT CLUSTER
1762 AlterTableCmd *n = makeNode(AlterTableCmd);
1763 n->subtype = AT_DropCluster;
1767 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
1768 | ENABLE_P TRIGGER name
1770 AlterTableCmd *n = makeNode(AlterTableCmd);
1771 n->subtype = AT_EnableTrig;
1775 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
1776 | ENABLE_P ALWAYS TRIGGER name
1778 AlterTableCmd *n = makeNode(AlterTableCmd);
1779 n->subtype = AT_EnableAlwaysTrig;
1783 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
1784 | ENABLE_P REPLICA TRIGGER name
1786 AlterTableCmd *n = makeNode(AlterTableCmd);
1787 n->subtype = AT_EnableReplicaTrig;
1791 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
1792 | ENABLE_P TRIGGER ALL
1794 AlterTableCmd *n = makeNode(AlterTableCmd);
1795 n->subtype = AT_EnableTrigAll;
1798 /* ALTER TABLE <name> ENABLE TRIGGER USER */
1799 | ENABLE_P TRIGGER USER
1801 AlterTableCmd *n = makeNode(AlterTableCmd);
1802 n->subtype = AT_EnableTrigUser;
1805 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
1806 | DISABLE_P TRIGGER name
1808 AlterTableCmd *n = makeNode(AlterTableCmd);
1809 n->subtype = AT_DisableTrig;
1813 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
1814 | DISABLE_P TRIGGER ALL
1816 AlterTableCmd *n = makeNode(AlterTableCmd);
1817 n->subtype = AT_DisableTrigAll;
1820 /* ALTER TABLE <name> DISABLE TRIGGER USER */
1821 | DISABLE_P TRIGGER USER
1823 AlterTableCmd *n = makeNode(AlterTableCmd);
1824 n->subtype = AT_DisableTrigUser;
1827 /* ALTER TABLE <name> ENABLE RULE <rule> */
1828 | ENABLE_P RULE name
1830 AlterTableCmd *n = makeNode(AlterTableCmd);
1831 n->subtype = AT_EnableRule;
1835 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
1836 | ENABLE_P ALWAYS RULE name
1838 AlterTableCmd *n = makeNode(AlterTableCmd);
1839 n->subtype = AT_EnableAlwaysRule;
1843 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
1844 | ENABLE_P REPLICA RULE name
1846 AlterTableCmd *n = makeNode(AlterTableCmd);
1847 n->subtype = AT_EnableReplicaRule;
1851 /* ALTER TABLE <name> DISABLE RULE <rule> */
1852 | DISABLE_P RULE name
1854 AlterTableCmd *n = makeNode(AlterTableCmd);
1855 n->subtype = AT_DisableRule;
1859 /* ALTER TABLE <name> INHERIT <parent> */
1860 | INHERIT qualified_name
1862 AlterTableCmd *n = makeNode(AlterTableCmd);
1863 n->subtype = AT_AddInherit;
1864 n->def = (Node *) $2;
1867 /* ALTER TABLE <name> NO INHERIT <parent> */
1868 | NO INHERIT qualified_name
1870 AlterTableCmd *n = makeNode(AlterTableCmd);
1871 n->subtype = AT_DropInherit;
1872 n->def = (Node *) $3;
1875 /* ALTER TABLE <name> OWNER TO RoleId */
1878 AlterTableCmd *n = makeNode(AlterTableCmd);
1879 n->subtype = AT_ChangeOwner;
1883 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1884 | SET TABLESPACE name
1886 AlterTableCmd *n = makeNode(AlterTableCmd);
1887 n->subtype = AT_SetTableSpace;
1891 /* ALTER TABLE <name> SET (...) */
1894 AlterTableCmd *n = makeNode(AlterTableCmd);
1895 n->subtype = AT_SetRelOptions;
1896 n->def = (Node *)$2;
1899 /* ALTER TABLE <name> RESET (...) */
1902 AlterTableCmd *n = makeNode(AlterTableCmd);
1903 n->subtype = AT_ResetRelOptions;
1904 n->def = (Node *)$2;
1909 alter_column_default:
1910 SET DEFAULT a_expr { $$ = $3; }
1911 | DROP DEFAULT { $$ = NULL; }
1915 CASCADE { $$ = DROP_CASCADE; }
1916 | RESTRICT { $$ = DROP_RESTRICT; }
1917 | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1921 USING a_expr { $$ = $2; }
1922 | /* EMPTY */ { $$ = NULL; }
1926 '(' reloption_list ')' { $$ = $2; }
1929 opt_reloptions: WITH reloptions { $$ = $2; }
1930 | /* EMPTY */ { $$ = NIL; }
1934 reloption_elem { $$ = list_make1($1); }
1935 | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
1938 /* This should match def_elem and also allow qualified names */
1940 ColLabel '=' def_arg
1942 $$ = makeDefElem($1, (Node *) $3);
1946 $$ = makeDefElem($1, NULL);
1948 | ColLabel '.' ColLabel '=' def_arg
1950 $$ = makeDefElemExtended($1, $3, (Node *) $5,
1953 | ColLabel '.' ColLabel
1955 $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC);
1960 /*****************************************************************************
1963 * close <portalname>
1965 *****************************************************************************/
1970 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1976 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1977 n->portalname = NULL;
1983 /*****************************************************************************
1986 * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
1987 * COPY ( SELECT ... ) TO file [WITH] [(options)]
1989 * In the preferred syntax the options are comma-separated
1990 * and use generic identifiers instead of keywords. The pre-8.5
1991 * syntax had a hard-wired, space-separated set of options.
1993 * Really old syntax, from versions 7.2 and prior:
1994 * COPY [ BINARY ] table [ WITH OIDS ] FROM/TO file
1995 * [ [ USING ] DELIMITERS 'delimiter' ] ]
1996 * [ WITH NULL AS 'null string' ]
1997 * This option placement is not supported with COPY (SELECT...).
1999 *****************************************************************************/
2001 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
2002 copy_from copy_file_name copy_delimiter opt_with copy_options
2004 CopyStmt *n = makeNode(CopyStmt);
2012 /* Concatenate user-supplied flags */
2014 n->options = lappend(n->options, $2);
2016 n->options = lappend(n->options, $5);
2018 n->options = lappend(n->options, $8);
2020 n->options = list_concat(n->options, $10);
2023 | COPY select_with_parens TO copy_file_name opt_with copy_options
2025 CopyStmt *n = makeNode(CopyStmt);
2038 | TO { $$ = FALSE; }
2042 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
2043 * used depends on the direction. (It really doesn't make sense to copy from
2044 * stdout. We silently correct the "typo".) - AY 9/94
2048 | STDIN { $$ = NULL; }
2049 | STDOUT { $$ = NULL; }
2052 copy_options: copy_opt_list { $$ = $1; }
2053 | '(' copy_generic_opt_list ')' { $$ = $2; }
2056 /* old COPY option syntax */
2058 copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
2059 | /* EMPTY */ { $$ = NIL; }
2065 $$ = makeDefElem("format", (Node *)makeString("binary"));
2069 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2071 | DELIMITER opt_as Sconst
2073 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2075 | NULL_P opt_as Sconst
2077 $$ = makeDefElem("null", (Node *)makeString($3));
2081 $$ = makeDefElem("format", (Node *)makeString("csv"));
2085 $$ = makeDefElem("header", (Node *)makeInteger(TRUE));
2087 | QUOTE opt_as Sconst
2089 $$ = makeDefElem("quote", (Node *)makeString($3));
2091 | ESCAPE opt_as Sconst
2093 $$ = makeDefElem("escape", (Node *)makeString($3));
2095 | FORCE QUOTE columnList
2097 $$ = makeDefElem("force_quote", (Node *)$3);
2101 $$ = makeDefElem("force_quote", (Node *)makeNode(A_Star));
2103 | FORCE NOT NULL_P columnList
2105 $$ = makeDefElem("force_not_null", (Node *)$4);
2109 /* The following exist for backward compatibility with very old versions */
2114 $$ = makeDefElem("format", (Node *)makeString("binary"));
2116 | /*EMPTY*/ { $$ = NULL; }
2122 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2124 | /*EMPTY*/ { $$ = NULL; }
2128 opt_using DELIMITERS Sconst
2130 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2132 | /*EMPTY*/ { $$ = NULL; }
2140 /* new COPY option syntax */
2141 copy_generic_opt_list:
2142 copy_generic_opt_elem
2144 $$ = list_make1($1);
2146 | copy_generic_opt_list ',' copy_generic_opt_elem
2148 $$ = lappend($1, $3);
2152 copy_generic_opt_elem:
2153 ColLabel copy_generic_opt_arg
2155 $$ = makeDefElem($1, $2);
2159 copy_generic_opt_arg:
2160 opt_boolean { $$ = (Node *) makeString($1); }
2161 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
2162 | NumericOnly { $$ = (Node *) $1; }
2163 | '*' { $$ = (Node *) makeNode(A_Star); }
2164 | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
2165 | /* EMPTY */ { $$ = NULL; }
2168 copy_generic_opt_arg_list:
2169 copy_generic_opt_arg_list_item
2171 $$ = list_make1($1);
2173 | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
2175 $$ = lappend($1, $3);
2179 /* beware of emitting non-string list elements here; see commands/define.c */
2180 copy_generic_opt_arg_list_item:
2181 opt_boolean { $$ = (Node *) makeString($1); }
2182 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
2186 /*****************************************************************************
2189 * CREATE TABLE relname
2191 *****************************************************************************/
2193 CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
2194 OptInherit OptWith OnCommitOption OptTableSpace
2196 CreateStmt *n = makeNode(CreateStmt);
2200 n->inhRelations = $8;
2201 n->constraints = NIL;
2204 n->tablespacename = $11;
2207 | CREATE OptTemp TABLE qualified_name OF any_name
2208 OptTypedTableElementList OptWith OnCommitOption OptTableSpace
2210 CreateStmt *n = makeNode(CreateStmt);
2214 n->ofTypename = makeTypeNameFromNameList($6);
2215 n->ofTypename->location = @6;
2216 n->constraints = NIL;
2219 n->tablespacename = $10;
2225 * Redundancy here is needed to avoid shift/reduce conflicts,
2226 * since TEMP is not a reserved word. See also OptTempTableName.
2228 * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
2229 * the LOCAL keyword is really meaningless.
2231 OptTemp: TEMPORARY { $$ = TRUE; }
2232 | TEMP { $$ = TRUE; }
2233 | LOCAL TEMPORARY { $$ = TRUE; }
2234 | LOCAL TEMP { $$ = TRUE; }
2235 | GLOBAL TEMPORARY { $$ = TRUE; }
2236 | GLOBAL TEMP { $$ = TRUE; }
2237 | /*EMPTY*/ { $$ = FALSE; }
2240 OptTableElementList:
2241 TableElementList { $$ = $1; }
2242 | /*EMPTY*/ { $$ = NIL; }
2245 OptTypedTableElementList:
2246 '(' TypedTableElementList ')' { $$ = $2; }
2247 | /*EMPTY*/ { $$ = NIL; }
2253 $$ = list_make1($1);
2255 | TableElementList ',' TableElement
2257 $$ = lappend($1, $3);
2261 TypedTableElementList:
2264 $$ = list_make1($1);
2266 | TypedTableElementList ',' TypedTableElement
2268 $$ = lappend($1, $3);
2273 columnDef { $$ = $1; }
2274 | TableLikeClause { $$ = $1; }
2275 | TableConstraint { $$ = $1; }
2279 columnOptions { $$ = $1; }
2280 | TableConstraint { $$ = $1; }
2283 columnDef: ColId Typename ColQualList
2285 ColumnDef *n = makeNode(ColumnDef);
2288 n->constraints = $3;
2294 columnOptions: ColId WITH OPTIONS ColQualList
2296 ColumnDef *n = makeNode(ColumnDef);
2298 n->constraints = $4;
2305 ColQualList ColConstraint { $$ = lappend($1, $2); }
2306 | /*EMPTY*/ { $$ = NIL; }
2310 CONSTRAINT name ColConstraintElem
2312 Constraint *n = (Constraint *) $3;
2313 Assert(IsA(n, Constraint));
2318 | ColConstraintElem { $$ = $1; }
2319 | ConstraintAttr { $$ = $1; }
2322 /* DEFAULT NULL is already the default for Postgres.
2323 * But define it here and carry it forward into the system
2324 * to make it explicit.
2325 * - thomas 1998-09-13
2327 * WITH NULL and NULL are not SQL92-standard syntax elements,
2328 * so leave them out. Use DEFAULT NULL to explicitly indicate
2329 * that a column may have that value. WITH NULL leads to
2330 * shift/reduce conflicts with WITH TIME ZONE anyway.
2331 * - thomas 1999-01-08
2333 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
2334 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
2335 * or be part of a_expr NOT LIKE or similar constructs).
2340 Constraint *n = makeNode(Constraint);
2341 n->contype = CONSTR_NOTNULL;
2347 Constraint *n = makeNode(Constraint);
2348 n->contype = CONSTR_NULL;
2352 | UNIQUE opt_definition OptConsTableSpace
2354 Constraint *n = makeNode(Constraint);
2355 n->contype = CONSTR_UNIQUE;
2362 | PRIMARY KEY opt_definition OptConsTableSpace
2364 Constraint *n = makeNode(Constraint);
2365 n->contype = CONSTR_PRIMARY;
2372 | CHECK '(' a_expr ')'
2374 Constraint *n = makeNode(Constraint);
2375 n->contype = CONSTR_CHECK;
2378 n->cooked_expr = NULL;
2383 Constraint *n = makeNode(Constraint);
2384 n->contype = CONSTR_DEFAULT;
2387 n->cooked_expr = NULL;
2390 | REFERENCES qualified_name opt_column_list key_match key_actions
2392 Constraint *n = makeNode(Constraint);
2393 n->contype = CONSTR_FOREIGN;
2398 n->fk_matchtype = $4;
2399 n->fk_upd_action = (char) ($5 >> 8);
2400 n->fk_del_action = (char) ($5 & 0xFF);
2401 n->skip_validation = FALSE;
2407 * ConstraintAttr represents constraint attributes, which we parse as if
2408 * they were independent constraint clauses, in order to avoid shift/reduce
2409 * conflicts (since NOT might start either an independent NOT NULL clause
2410 * or an attribute). parse_utilcmd.c is responsible for attaching the
2411 * attribute information to the preceding "real" constraint node, and for
2412 * complaining if attribute clauses appear in the wrong place or wrong
2415 * See also ConstraintAttributeSpec, which can be used in places where
2416 * there is no parsing conflict.
2421 Constraint *n = makeNode(Constraint);
2422 n->contype = CONSTR_ATTR_DEFERRABLE;
2428 Constraint *n = makeNode(Constraint);
2429 n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
2433 | INITIALLY DEFERRED
2435 Constraint *n = makeNode(Constraint);
2436 n->contype = CONSTR_ATTR_DEFERRED;
2440 | INITIALLY IMMEDIATE
2442 Constraint *n = makeNode(Constraint);
2443 n->contype = CONSTR_ATTR_IMMEDIATE;
2451 * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2452 * This seems to be a poor man's inheritance capability, with the resulting
2453 * tables completely decoupled except for the original commonality in definitions.
2455 * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2456 * which is a part of SQL:2003.
2459 LIKE qualified_name TableLikeOptionList
2461 InhRelation *n = makeNode(InhRelation);
2468 TableLikeOptionList:
2469 TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
2470 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
2471 | /* EMPTY */ { $$ = 0; }
2475 DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
2476 | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
2477 | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
2478 | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
2479 | COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
2480 | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
2484 /* ConstraintElem specifies constraint syntax which is not embedded into
2485 * a column definition. ColConstraintElem specifies the embedded form.
2486 * - thomas 1997-12-03
2489 CONSTRAINT name ConstraintElem
2491 Constraint *n = (Constraint *) $3;
2492 Assert(IsA(n, Constraint));
2497 | ConstraintElem { $$ = $1; }
2501 CHECK '(' a_expr ')' ConstraintAttributeSpec
2503 Constraint *n = makeNode(Constraint);
2504 n->contype = CONSTR_CHECK;
2507 n->cooked_expr = NULL;
2510 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2511 errmsg("CHECK constraints cannot be deferred"),
2512 parser_errposition(@5)));
2515 | UNIQUE '(' columnList ')' opt_definition OptConsTableSpace
2516 ConstraintAttributeSpec
2518 Constraint *n = makeNode(Constraint);
2519 n->contype = CONSTR_UNIQUE;
2524 n->deferrable = ($7 & 1) != 0;
2525 n->initdeferred = ($7 & 2) != 0;
2528 | PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace
2529 ConstraintAttributeSpec
2531 Constraint *n = makeNode(Constraint);
2532 n->contype = CONSTR_PRIMARY;
2537 n->deferrable = ($8 & 1) != 0;
2538 n->initdeferred = ($8 & 2) != 0;
2541 | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
2542 opt_definition OptConsTableSpace ExclusionWhereClause
2543 ConstraintAttributeSpec
2545 Constraint *n = makeNode(Constraint);
2546 n->contype = CONSTR_EXCLUSION;
2548 n->access_method = $2;
2552 n->where_clause = $8;
2553 n->deferrable = ($9 & 1) != 0;
2554 n->initdeferred = ($9 & 2) != 0;
2557 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
2558 opt_column_list key_match key_actions ConstraintAttributeSpec
2560 Constraint *n = makeNode(Constraint);
2561 n->contype = CONSTR_FOREIGN;
2566 n->fk_matchtype = $9;
2567 n->fk_upd_action = (char) ($10 >> 8);
2568 n->fk_del_action = (char) ($10 & 0xFF);
2569 n->skip_validation = FALSE;
2570 n->deferrable = ($11 & 1) != 0;
2571 n->initdeferred = ($11 & 2) != 0;
2577 '(' columnList ')' { $$ = $2; }
2578 | /*EMPTY*/ { $$ = NIL; }
2582 columnElem { $$ = list_make1($1); }
2583 | columnList ',' columnElem { $$ = lappend($1, $3); }
2588 $$ = (Node *) makeString($1);
2592 key_match: MATCH FULL
2594 $$ = FKCONSTR_MATCH_FULL;
2599 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2600 errmsg("MATCH PARTIAL not yet implemented"),
2601 parser_errposition(@1)));
2602 $$ = FKCONSTR_MATCH_PARTIAL;
2606 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2610 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2614 ExclusionConstraintList:
2615 ExclusionConstraintElem { $$ = list_make1($1); }
2616 | ExclusionConstraintList ',' ExclusionConstraintElem
2617 { $$ = lappend($1, $3); }
2620 ExclusionConstraintElem: index_elem WITH any_operator
2622 $$ = list_make2($1, $3);
2624 /* allow OPERATOR() decoration for the benefit of ruleutils.c */
2625 | index_elem WITH OPERATOR '(' any_operator ')'
2627 $$ = list_make2($1, $5);
2631 ExclusionWhereClause:
2632 WHERE '(' a_expr ')' { $$ = $3; }
2633 | /*EMPTY*/ { $$ = NULL; }
2637 * We combine the update and delete actions into one value temporarily
2638 * for simplicity of parsing, and then break them down again in the
2639 * calling production. update is in the left 8 bits, delete in the right.
2640 * Note that NOACTION is the default.
2644 { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2646 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
2647 | key_update key_delete
2648 { $$ = ($1 << 8) | ($2 & 0xFF); }
2649 | key_delete key_update
2650 { $$ = ($2 << 8) | ($1 & 0xFF); }
2652 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2655 key_update: ON UPDATE key_action { $$ = $3; }
2658 key_delete: ON DELETE_P key_action { $$ = $3; }
2662 NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; }
2663 | RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; }
2664 | CASCADE { $$ = FKCONSTR_ACTION_CASCADE; }
2665 | SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; }
2666 | SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; }
2669 OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
2670 | /*EMPTY*/ { $$ = NIL; }
2673 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
2675 WITH reloptions { $$ = $2; }
2676 | WITH OIDS { $$ = list_make1(defWithOids(true)); }
2677 | WITHOUT OIDS { $$ = list_make1(defWithOids(false)); }
2678 | /*EMPTY*/ { $$ = NIL; }
2681 OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
2682 | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
2683 | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
2684 | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
2687 OptTableSpace: TABLESPACE name { $$ = $2; }
2688 | /*EMPTY*/ { $$ = NULL; }
2691 OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
2692 | /*EMPTY*/ { $$ = NULL; }
2697 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
2702 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
2705 * When the SelectStmt is a set-operation tree, we must
2706 * stuff the INTO information into the leftmost component
2707 * Select, because that's where analyze.c will expect
2708 * to find it. Similarly, the output column names must
2709 * be attached to that Select's target list.
2711 SelectStmt *n = findLeftmostSelect((SelectStmt *) $6);
2712 if (n->intoClause != NULL)
2714 (errcode(ERRCODE_SYNTAX_ERROR),
2715 errmsg("CREATE TABLE AS cannot specify INTO"),
2716 parser_errposition(exprLocation((Node *) n->intoClause))));
2717 $4->rel->istemp = $2;
2719 /* Implement WITH NO DATA by forcing top-level LIMIT 0 */
2721 ((SelectStmt *) $6)->limitCount = makeIntConst(0, -1);
2727 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
2729 $$ = makeNode(IntoClause);
2734 $$->tableSpaceName = $5;
2739 '(' CreateAsList ')' { $$ = $2; }
2740 | /*EMPTY*/ { $$ = NIL; }
2744 CreateAsElement { $$ = list_make1($1); }
2745 | CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); }
2751 ColumnDef *n = makeNode(ColumnDef);
2756 n->is_not_null = false;
2757 n->raw_default = NULL;
2758 n->cooked_default = NULL;
2759 n->constraints = NIL;
2765 WITH DATA_P { $$ = TRUE; }
2766 | WITH NO DATA_P { $$ = FALSE; }
2767 | /*EMPTY*/ { $$ = TRUE; }
2771 /*****************************************************************************
2774 * CREATE SEQUENCE seqname
2775 * ALTER SEQUENCE seqname
2777 *****************************************************************************/
2780 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
2782 CreateSeqStmt *n = makeNode(CreateSeqStmt);
2791 ALTER SEQUENCE qualified_name SeqOptList
2793 AlterSeqStmt *n = makeNode(AlterSeqStmt);
2800 OptSeqOptList: SeqOptList { $$ = $1; }
2801 | /*EMPTY*/ { $$ = NIL; }
2804 SeqOptList: SeqOptElem { $$ = list_make1($1); }
2805 | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
2808 SeqOptElem: CACHE NumericOnly
2810 $$ = makeDefElem("cache", (Node *)$2);
2814 $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE));
2818 $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE));
2820 | INCREMENT opt_by NumericOnly
2822 $$ = makeDefElem("increment", (Node *)$3);
2824 | MAXVALUE NumericOnly
2826 $$ = makeDefElem("maxvalue", (Node *)$2);
2828 | MINVALUE NumericOnly
2830 $$ = makeDefElem("minvalue", (Node *)$2);
2834 $$ = makeDefElem("maxvalue", NULL);
2838 $$ = makeDefElem("minvalue", NULL);
2842 $$ = makeDefElem("owned_by", (Node *)$3);
2844 | START opt_with NumericOnly
2846 $$ = makeDefElem("start", (Node *)$3);
2850 $$ = makeDefElem("restart", NULL);
2852 | RESTART opt_with NumericOnly
2854 $$ = makeDefElem("restart", (Node *)$3);
2863 FCONST { $$ = makeFloat($1); }
2869 | SignedIconst { $$ = makeInteger($1); }
2872 /*****************************************************************************
2875 * CREATE PROCEDURAL LANGUAGE ...
2876 * DROP PROCEDURAL LANGUAGE ...
2878 *****************************************************************************/
2881 CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2883 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2885 /* parameters are all to be supplied by system */
2888 n->plvalidator = NIL;
2889 n->pltrusted = false;
2892 | CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2893 HANDLER handler_name opt_inline_handler opt_validator
2895 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2899 n->plvalidator = $9;
2906 TRUSTED { $$ = TRUE; }
2907 | /*EMPTY*/ { $$ = FALSE; }
2910 /* This ought to be just func_name, but that causes reduce/reduce conflicts
2911 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
2912 * Work around by using simple names, instead.
2915 name { $$ = list_make1(makeString($1)); }
2916 | name attrs { $$ = lcons(makeString($1), $2); }
2920 INLINE_P handler_name { $$ = $2; }
2921 | /*EMPTY*/ { $$ = NIL; }
2925 VALIDATOR handler_name { $$ = $2; }
2926 | NO VALIDATOR { $$ = NIL; }
2930 validator_clause { $$ = $1; }
2931 | /*EMPTY*/ { $$ = NIL; }
2935 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
2937 DropPLangStmt *n = makeNode(DropPLangStmt);
2940 n->missing_ok = false;
2943 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
2945 DropPLangStmt *n = makeNode(DropPLangStmt);
2948 n->missing_ok = true;
2958 /*****************************************************************************
2961 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
2963 *****************************************************************************/
2965 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
2967 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
2968 n->tablespacename = $3;
2975 OptTableSpaceOwner: OWNER name { $$ = $2; }
2976 | /*EMPTY */ { $$ = NULL; }
2979 /*****************************************************************************
2982 * DROP TABLESPACE <tablespace>
2984 * No need for drop behaviour as we cannot implement dependencies for
2985 * objects in other databases; we can only support RESTRICT.
2987 ****************************************************************************/
2989 DropTableSpaceStmt: DROP TABLESPACE name
2991 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2992 n->tablespacename = $3;
2993 n->missing_ok = false;
2996 | DROP TABLESPACE IF_P EXISTS name
2998 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2999 n->tablespacename = $5;
3000 n->missing_ok = true;
3005 /*****************************************************************************
3008 * CREATE FOREIGN DATA WRAPPER name [ VALIDATOR name ]
3010 *****************************************************************************/
3012 CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_validator create_generic_options
3014 CreateFdwStmt *n = makeNode(CreateFdwStmt);
3022 /*****************************************************************************
3025 * DROP FOREIGN DATA WRAPPER name
3027 ****************************************************************************/
3029 DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
3031 DropFdwStmt *n = makeNode(DropFdwStmt);
3033 n->missing_ok = false;
3037 | DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior
3039 DropFdwStmt *n = makeNode(DropFdwStmt);
3041 n->missing_ok = true;
3047 /*****************************************************************************
3050 * ALTER FOREIGN DATA WRAPPER name
3052 ****************************************************************************/
3054 AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name validator_clause alter_generic_options
3056 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3059 n->change_validator = true;
3063 | ALTER FOREIGN DATA_P WRAPPER name validator_clause
3065 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3068 n->change_validator = true;
3071 | ALTER FOREIGN DATA_P WRAPPER name alter_generic_options
3073 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3080 /* Options definition for CREATE FDW, SERVER and USER MAPPING */
3081 create_generic_options:
3082 OPTIONS '(' generic_option_list ')' { $$ = $3; }
3083 | /*EMPTY*/ { $$ = NIL; }
3086 generic_option_list:
3089 $$ = list_make1($1);
3091 | generic_option_list ',' generic_option_elem
3093 $$ = lappend($1, $3);
3097 /* Options definition for ALTER FDW, SERVER and USER MAPPING */
3098 alter_generic_options:
3099 OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
3102 alter_generic_option_list:
3103 alter_generic_option_elem
3105 $$ = list_make1($1);
3107 | alter_generic_option_list ',' alter_generic_option_elem
3109 $$ = lappend($1, $3);
3113 alter_generic_option_elem:
3118 | SET generic_option_elem
3121 $$->defaction = DEFELEM_SET;
3123 | ADD_P generic_option_elem
3126 $$->defaction = DEFELEM_ADD;
3128 | DROP generic_option_name
3130 $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP);
3134 generic_option_elem:
3135 generic_option_name generic_option_arg
3137 $$ = makeDefElem($1, $2);
3141 generic_option_name:
3142 ColLabel { $$ = $1; }
3145 /* We could use def_arg here, but the spec only requires string literals */
3147 Sconst { $$ = (Node *) makeString($1); }
3150 /*****************************************************************************
3153 * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
3155 *****************************************************************************/
3157 CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
3158 FOREIGN DATA_P WRAPPER name create_generic_options
3160 CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
3171 TYPE_P Sconst { $$ = $2; }
3172 | /*EMPTY*/ { $$ = NULL; }
3176 foreign_server_version:
3177 VERSION_P Sconst { $$ = $2; }
3178 | VERSION_P NULL_P { $$ = NULL; }
3181 opt_foreign_server_version:
3182 foreign_server_version { $$ = $1; }
3183 | /*EMPTY*/ { $$ = NULL; }
3186 /*****************************************************************************
3191 ****************************************************************************/
3193 DropForeignServerStmt: DROP SERVER name opt_drop_behavior
3195 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3197 n->missing_ok = false;
3201 | DROP SERVER IF_P EXISTS name opt_drop_behavior
3203 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3205 n->missing_ok = true;
3211 /*****************************************************************************
3214 * ALTER SERVER name [VERSION] [OPTIONS]
3216 ****************************************************************************/
3218 AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
3220 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3224 n->has_version = true;
3227 | ALTER SERVER name foreign_server_version
3229 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3232 n->has_version = true;
3235 | ALTER SERVER name alter_generic_options
3237 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3244 /*****************************************************************************
3247 * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
3249 *****************************************************************************/
3251 CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
3253 CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
3261 /* User mapping authorization identifier */
3263 CURRENT_USER { $$ = "current_user"; }
3264 | USER { $$ = "current_user"; }
3265 | RoleId { $$ = (strcmp($1, "public") == 0) ? NULL : $1; }
3268 /*****************************************************************************
3271 * DROP USER MAPPING FOR auth_ident SERVER name
3273 ****************************************************************************/
3275 DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
3277 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3280 n->missing_ok = false;
3283 | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
3285 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3288 n->missing_ok = true;
3293 /*****************************************************************************
3296 * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
3298 ****************************************************************************/
3300 AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
3302 AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
3310 /*****************************************************************************
3313 * CREATE TRIGGER ...
3316 *****************************************************************************/
3319 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
3320 qualified_name TriggerForSpec TriggerWhen
3321 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3323 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3330 n->events = intVal(linitial($5));
3331 n->columns = (List *) lsecond($5);
3333 n->isconstraint = FALSE;
3334 n->deferrable = FALSE;
3335 n->initdeferred = FALSE;
3336 n->constrrel = NULL;
3339 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
3340 qualified_name OptConstrFromTable ConstraintAttributeSpec
3341 FOR EACH ROW TriggerWhen
3342 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3344 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3351 n->events = intVal(linitial($6));
3352 n->columns = (List *) lsecond($6);
3353 n->whenClause = $14;
3354 n->isconstraint = TRUE;
3355 n->deferrable = ($10 & 1) != 0;
3356 n->initdeferred = ($10 & 2) != 0;
3363 BEFORE { $$ = TRUE; }
3364 | AFTER { $$ = FALSE; }
3370 | TriggerEvents OR TriggerOneEvent
3372 int events1 = intVal(linitial($1));
3373 int events2 = intVal(linitial($3));
3374 List *columns1 = (List *) lsecond($1);
3375 List *columns2 = (List *) lsecond($3);
3377 if (events1 & events2)
3378 parser_yyerror("duplicate trigger events specified");
3380 * concat'ing the columns lists loses information about
3381 * which columns went with which event, but so long as
3382 * only UPDATE carries columns and we disallow multiple
3383 * UPDATE items, it doesn't matter. Command execution
3384 * should just ignore the columns for non-UPDATE events.
3386 $$ = list_make2(makeInteger(events1 | events2),
3387 list_concat(columns1, columns2));
3393 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
3395 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
3397 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
3398 | UPDATE OF columnList
3399 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
3401 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
3405 FOR TriggerForOpt TriggerForType
3412 * If ROW/STATEMENT not specified, default to
3413 * STATEMENT, per SQL
3426 | STATEMENT { $$ = FALSE; }
3430 WHEN '(' a_expr ')' { $$ = $3; }
3431 | /*EMPTY*/ { $$ = NULL; }
3435 TriggerFuncArg { $$ = list_make1($1); }
3436 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
3437 | /*EMPTY*/ { $$ = NIL; }
3444 snprintf(buf, sizeof(buf), "%d", $1);
3445 $$ = makeString(pstrdup(buf));
3447 | FCONST { $$ = makeString($1); }
3448 | Sconst { $$ = makeString($1); }
3449 | BCONST { $$ = makeString($1); }
3450 | XCONST { $$ = makeString($1); }
3451 | ColId { $$ = makeString($1); }
3455 FROM qualified_name { $$ = $2; }
3456 | /*EMPTY*/ { $$ = NULL; }
3459 ConstraintAttributeSpec:
3460 ConstraintDeferrabilitySpec
3462 | ConstraintDeferrabilitySpec ConstraintTimeSpec
3464 if ($1 == 0 && $2 != 0)
3466 (errcode(ERRCODE_SYNTAX_ERROR),
3467 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3468 parser_errposition(@1)));
3471 | ConstraintTimeSpec
3478 | ConstraintTimeSpec ConstraintDeferrabilitySpec
3480 if ($2 == 0 && $1 != 0)
3482 (errcode(ERRCODE_SYNTAX_ERROR),
3483 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3484 parser_errposition(@1)));
3491 ConstraintDeferrabilitySpec:
3492 NOT DEFERRABLE { $$ = 0; }
3493 | DEFERRABLE { $$ = 1; }
3497 INITIALLY IMMEDIATE { $$ = 0; }
3498 | INITIALLY DEFERRED { $$ = 2; }
3503 DROP TRIGGER name ON qualified_name opt_drop_behavior
3505 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3509 n->removeType = OBJECT_TRIGGER;
3510 n->missing_ok = false;
3513 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
3515 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3519 n->removeType = OBJECT_TRIGGER;
3520 n->missing_ok = true;
3526 /*****************************************************************************
3529 * CREATE ASSERTION ...
3530 * DROP ASSERTION ...
3532 *****************************************************************************/
3535 CREATE ASSERTION name CHECK '(' a_expr ')'
3536 ConstraintAttributeSpec
3538 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3540 n->args = list_make1($6);
3541 n->isconstraint = TRUE;
3542 n->deferrable = ($8 & 1) != 0;
3543 n->initdeferred = ($8 & 2) != 0;
3546 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3547 errmsg("CREATE ASSERTION is not yet implemented")));
3554 DROP ASSERTION name opt_drop_behavior
3556 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3560 n->removeType = OBJECT_TRIGGER; /* XXX */
3562 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3563 errmsg("DROP ASSERTION is not yet implemented")));
3569 /*****************************************************************************
3572 * define (aggregate,operator,type)
3574 *****************************************************************************/
3577 CREATE AGGREGATE func_name aggr_args definition
3579 DefineStmt *n = makeNode(DefineStmt);
3580 n->kind = OBJECT_AGGREGATE;
3581 n->oldstyle = false;
3587 | CREATE AGGREGATE func_name old_aggr_definition
3589 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
3590 DefineStmt *n = makeNode(DefineStmt);
3591 n->kind = OBJECT_AGGREGATE;
3598 | CREATE OPERATOR any_operator definition
3600 DefineStmt *n = makeNode(DefineStmt);
3601 n->kind = OBJECT_OPERATOR;
3602 n->oldstyle = false;
3608 | CREATE TYPE_P any_name definition
3610 DefineStmt *n = makeNode(DefineStmt);
3611 n->kind = OBJECT_TYPE;
3612 n->oldstyle = false;
3618 | CREATE TYPE_P any_name
3620 /* Shell type (identified by lack of definition) */
3621 DefineStmt *n = makeNode(DefineStmt);
3622 n->kind = OBJECT_TYPE;
3623 n->oldstyle = false;
3626 n->definition = NIL;
3629 | CREATE TYPE_P any_name AS '(' TableFuncElementList ')'
3631 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
3632 RangeVar *r = makeNode(RangeVar);
3634 /* can't use qualified_name, sigh */
3635 switch (list_length($3))
3638 r->catalogname = NULL;
3639 r->schemaname = NULL;
3640 r->relname = strVal(linitial($3));
3643 r->catalogname = NULL;
3644 r->schemaname = strVal(linitial($3));
3645 r->relname = strVal(lsecond($3));
3648 r->catalogname = strVal(linitial($3));
3649 r->schemaname = strVal(lsecond($3));
3650 r->relname = strVal(lthird($3));
3654 (errcode(ERRCODE_SYNTAX_ERROR),
3655 errmsg("improper qualified name (too many dotted names): %s",
3656 NameListToString($3)),
3657 parser_errposition(@3)));
3665 | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
3667 CreateEnumStmt *n = makeNode(CreateEnumStmt);
3672 | CREATE TEXT_P SEARCH PARSER any_name definition
3674 DefineStmt *n = makeNode(DefineStmt);
3675 n->kind = OBJECT_TSPARSER;
3681 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
3683 DefineStmt *n = makeNode(DefineStmt);
3684 n->kind = OBJECT_TSDICTIONARY;
3690 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
3692 DefineStmt *n = makeNode(DefineStmt);
3693 n->kind = OBJECT_TSTEMPLATE;
3699 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
3701 DefineStmt *n = makeNode(DefineStmt);
3702 n->kind = OBJECT_TSCONFIGURATION;
3710 definition: '(' def_list ')' { $$ = $2; }
3713 def_list: def_elem { $$ = list_make1($1); }
3714 | def_list ',' def_elem { $$ = lappend($1, $3); }
3717 def_elem: ColLabel '=' def_arg
3719 $$ = makeDefElem($1, (Node *) $3);
3723 $$ = makeDefElem($1, NULL);
3727 /* Note: any simple identifier will be returned as a type name! */
3728 def_arg: func_type { $$ = (Node *)$1; }
3729 | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
3730 | qual_all_Op { $$ = (Node *)$1; }
3731 | NumericOnly { $$ = (Node *)$1; }
3732 | Sconst { $$ = (Node *)makeString($1); }
3735 aggr_args: '(' type_list ')' { $$ = $2; }
3736 | '(' '*' ')' { $$ = NIL; }
3739 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
3742 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
3743 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
3747 * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
3748 * the item names needed in old aggregate definitions are likely to become
3751 old_aggr_elem: IDENT '=' def_arg
3753 $$ = makeDefElem($1, (Node *)$3);
3758 enum_val_list { $$ = $1; }
3759 | /*EMPTY*/ { $$ = NIL; }
3762 enum_val_list: Sconst
3763 { $$ = list_make1(makeString($1)); }
3764 | enum_val_list ',' Sconst
3765 { $$ = lappend($1, makeString($3)); }
3769 /*****************************************************************************
3772 * CREATE OPERATOR CLASS ...
3773 * CREATE OPERATOR FAMILY ...
3774 * ALTER OPERATOR FAMILY ...
3775 * DROP OPERATOR CLASS ...
3776 * DROP OPERATOR FAMILY ...
3778 *****************************************************************************/
3781 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
3782 USING access_method opt_opfamily AS opclass_item_list
3784 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
3785 n->opclassname = $4;
3789 n->opfamilyname = $11;
3796 opclass_item { $$ = list_make1($1); }
3797 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
3801 OPERATOR Iconst any_operator opt_recheck
3803 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3804 n->itemtype = OPCLASS_ITEM_OPERATOR;
3810 | OPERATOR Iconst any_operator oper_argtypes opt_recheck
3812 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3813 n->itemtype = OPCLASS_ITEM_OPERATOR;
3819 | FUNCTION Iconst func_name func_args
3821 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3822 n->itemtype = OPCLASS_ITEM_FUNCTION;
3824 n->args = extractArgTypes($4);
3828 | FUNCTION Iconst '(' type_list ')' func_name func_args
3830 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3831 n->itemtype = OPCLASS_ITEM_FUNCTION;
3833 n->args = extractArgTypes($7);
3840 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3841 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
3847 opt_default: DEFAULT { $$ = TRUE; }
3848 | /*EMPTY*/ { $$ = FALSE; }
3851 opt_opfamily: FAMILY any_name { $$ = $2; }
3852 | /*EMPTY*/ { $$ = NIL; }
3855 opt_recheck: RECHECK
3858 * RECHECK no longer does anything in opclass definitions,
3859 * but we still accept it to ease porting of old database
3863 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3864 errmsg("RECHECK is no longer required"),
3865 errhint("Update your data type."),
3866 parser_errposition(@1)));
3869 | /*EMPTY*/ { $$ = FALSE; }
3874 CREATE OPERATOR FAMILY any_name USING access_method
3876 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
3877 n->opfamilyname = $4;
3884 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
3886 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3887 n->opfamilyname = $4;
3893 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
3895 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3896 n->opfamilyname = $4;
3905 opclass_drop { $$ = list_make1($1); }
3906 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
3910 OPERATOR Iconst '(' type_list ')'
3912 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3913 n->itemtype = OPCLASS_ITEM_OPERATOR;
3918 | FUNCTION Iconst '(' type_list ')'
3920 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3921 n->itemtype = OPCLASS_ITEM_FUNCTION;
3930 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
3932 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3933 n->opclassname = $4;
3936 n->missing_ok = false;
3939 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
3941 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3942 n->opclassname = $6;
3945 n->missing_ok = true;
3951 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
3953 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3954 n->opfamilyname = $4;
3957 n->missing_ok = false;
3960 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
3962 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3963 n->opfamilyname = $6;
3966 n->missing_ok = true;
3972 /*****************************************************************************
3976 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
3977 * REASSIGN OWNED BY username [, username ...] TO username
3979 *****************************************************************************/
3981 DROP OWNED BY name_list opt_drop_behavior
3983 DropOwnedStmt *n = makeNode(DropOwnedStmt);
3991 REASSIGN OWNED BY name_list TO name
3993 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
4000 /*****************************************************************************
4004 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
4005 * [ RESTRICT | CASCADE ]
4007 *****************************************************************************/
4009 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
4011 DropStmt *n = makeNode(DropStmt);
4013 n->missing_ok = TRUE;
4018 | DROP drop_type any_name_list opt_drop_behavior
4020 DropStmt *n = makeNode(DropStmt);
4022 n->missing_ok = FALSE;
4030 drop_type: TABLE { $$ = OBJECT_TABLE; }
4031 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4032 | VIEW { $$ = OBJECT_VIEW; }
4033 | INDEX { $$ = OBJECT_INDEX; }
4034 | TYPE_P { $$ = OBJECT_TYPE; }
4035 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
4036 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4037 | SCHEMA { $$ = OBJECT_SCHEMA; }
4038 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
4039 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
4040 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
4041 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
4045 any_name { $$ = list_make1($1); }
4046 | any_name_list ',' any_name { $$ = lappend($1, $3); }
4049 any_name: ColId { $$ = list_make1(makeString($1)); }
4050 | ColId attrs { $$ = lcons(makeString($1), $2); }
4053 attrs: '.' attr_name
4054 { $$ = list_make1(makeString($2)); }
4055 | attrs '.' attr_name
4056 { $$ = lappend($1, makeString($3)); }
4060 /*****************************************************************************
4063 * truncate table relname1, relname2, ...
4065 *****************************************************************************/
4068 TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
4070 TruncateStmt *n = makeNode(TruncateStmt);
4072 n->restart_seqs = $4;
4079 CONTINUE_P IDENTITY_P { $$ = false; }
4080 | RESTART IDENTITY_P { $$ = true; }
4081 | /* EMPTY */ { $$ = false; }
4084 /*****************************************************************************
4086 * The COMMENT ON statement can take different forms based upon the type of
4087 * the object associated with the comment. The form of the statement is:
4089 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
4090 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
4091 * CAST | COLUMN | SCHEMA | TABLESPACE | ROLE |
4092 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
4093 * TEXT SEARCH TEMPLATE |
4094 * TEXT SEARCH CONFIGURATION ] <objname> |
4095 * AGGREGATE <aggname> (arg1, ...) |
4096 * FUNCTION <funcname> (arg1, arg2, ...) |
4097 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
4098 * TRIGGER <triggername> ON <relname> |
4099 * CONSTRAINT <constraintname> ON <relname> |
4100 * RULE <rulename> ON <relname> ]
4103 *****************************************************************************/
4106 COMMENT ON comment_type any_name IS comment_text
4108 CommentStmt *n = makeNode(CommentStmt);
4115 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
4117 CommentStmt *n = makeNode(CommentStmt);
4118 n->objtype = OBJECT_AGGREGATE;
4124 | COMMENT ON FUNCTION func_name func_args IS comment_text
4126 CommentStmt *n = makeNode(CommentStmt);
4127 n->objtype = OBJECT_FUNCTION;
4129 n->objargs = extractArgTypes($5);
4133 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
4135 CommentStmt *n = makeNode(CommentStmt);
4136 n->objtype = OBJECT_OPERATOR;
4142 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
4144 CommentStmt *n = makeNode(CommentStmt);
4145 n->objtype = OBJECT_CONSTRAINT;
4146 n->objname = lappend($6, makeString($4));
4151 | COMMENT ON RULE name ON any_name IS comment_text
4153 CommentStmt *n = makeNode(CommentStmt);
4154 n->objtype = OBJECT_RULE;
4155 n->objname = lappend($6, makeString($4));
4160 | COMMENT ON RULE name IS comment_text
4162 /* Obsolete syntax supported for awhile for compatibility */
4163 CommentStmt *n = makeNode(CommentStmt);
4164 n->objtype = OBJECT_RULE;
4165 n->objname = list_make1(makeString($4));
4170 | COMMENT ON TRIGGER name ON any_name IS comment_text
4172 CommentStmt *n = makeNode(CommentStmt);
4173 n->objtype = OBJECT_TRIGGER;
4174 n->objname = lappend($6, makeString($4));
4179 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
4181 CommentStmt *n = makeNode(CommentStmt);
4182 n->objtype = OBJECT_OPCLASS;
4184 n->objargs = list_make1(makeString($7));
4188 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
4190 CommentStmt *n = makeNode(CommentStmt);
4191 n->objtype = OBJECT_OPFAMILY;
4193 n->objargs = list_make1(makeString($7));
4197 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
4199 CommentStmt *n = makeNode(CommentStmt);
4200 n->objtype = OBJECT_LARGEOBJECT;
4201 n->objname = list_make1($5);
4206 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
4208 CommentStmt *n = makeNode(CommentStmt);
4209 n->objtype = OBJECT_CAST;
4210 n->objname = list_make1($5);
4211 n->objargs = list_make1($7);
4215 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
4217 CommentStmt *n = makeNode(CommentStmt);
4218 n->objtype = OBJECT_LANGUAGE;
4224 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
4226 CommentStmt *n = makeNode(CommentStmt);
4227 n->objtype = OBJECT_TSPARSER;
4232 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
4234 CommentStmt *n = makeNode(CommentStmt);
4235 n->objtype = OBJECT_TSDICTIONARY;
4240 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
4242 CommentStmt *n = makeNode(CommentStmt);
4243 n->objtype = OBJECT_TSTEMPLATE;
4248 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
4250 CommentStmt *n = makeNode(CommentStmt);
4251 n->objtype = OBJECT_TSCONFIGURATION;
4259 COLUMN { $$ = OBJECT_COLUMN; }
4260 | DATABASE { $$ = OBJECT_DATABASE; }
4261 | SCHEMA { $$ = OBJECT_SCHEMA; }
4262 | INDEX { $$ = OBJECT_INDEX; }
4263 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4264 | TABLE { $$ = OBJECT_TABLE; }
4265 | DOMAIN_P { $$ = OBJECT_TYPE; }
4266 | TYPE_P { $$ = OBJECT_TYPE; }
4267 | VIEW { $$ = OBJECT_VIEW; }
4268 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4269 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
4270 | ROLE { $$ = OBJECT_ROLE; }
4275 | NULL_P { $$ = NULL; }
4278 /*****************************************************************************
4283 *****************************************************************************/
4285 FetchStmt: FETCH fetch_args
4287 FetchStmt *n = (FetchStmt *) $2;
4293 FetchStmt *n = (FetchStmt *) $2;
4299 fetch_args: cursor_name
4301 FetchStmt *n = makeNode(FetchStmt);
4303 n->direction = FETCH_FORWARD;
4307 | from_in cursor_name
4309 FetchStmt *n = makeNode(FetchStmt);
4311 n->direction = FETCH_FORWARD;
4315 | NEXT opt_from_in cursor_name
4317 FetchStmt *n = makeNode(FetchStmt);
4319 n->direction = FETCH_FORWARD;
4323 | PRIOR opt_from_in cursor_name
4325 FetchStmt *n = makeNode(FetchStmt);
4327 n->direction = FETCH_BACKWARD;
4331 | FIRST_P opt_from_in cursor_name
4333 FetchStmt *n = makeNode(FetchStmt);
4335 n->direction = FETCH_ABSOLUTE;
4339 | LAST_P opt_from_in cursor_name
4341 FetchStmt *n = makeNode(FetchStmt);
4343 n->direction = FETCH_ABSOLUTE;
4347 | ABSOLUTE_P SignedIconst opt_from_in cursor_name
4349 FetchStmt *n = makeNode(FetchStmt);
4351 n->direction = FETCH_ABSOLUTE;
4355 | RELATIVE_P SignedIconst opt_from_in cursor_name
4357 FetchStmt *n = makeNode(FetchStmt);
4359 n->direction = FETCH_RELATIVE;
4363 | SignedIconst opt_from_in cursor_name
4365 FetchStmt *n = makeNode(FetchStmt);
4367 n->direction = FETCH_FORWARD;
4371 | ALL opt_from_in cursor_name
4373 FetchStmt *n = makeNode(FetchStmt);
4375 n->direction = FETCH_FORWARD;
4376 n->howMany = FETCH_ALL;
4379 | FORWARD opt_from_in cursor_name
4381 FetchStmt *n = makeNode(FetchStmt);
4383 n->direction = FETCH_FORWARD;
4387 | FORWARD SignedIconst opt_from_in cursor_name
4389 FetchStmt *n = makeNode(FetchStmt);
4391 n->direction = FETCH_FORWARD;
4395 | FORWARD ALL opt_from_in cursor_name
4397 FetchStmt *n = makeNode(FetchStmt);
4399 n->direction = FETCH_FORWARD;
4400 n->howMany = FETCH_ALL;
4403 | BACKWARD opt_from_in cursor_name
4405 FetchStmt *n = makeNode(FetchStmt);
4407 n->direction = FETCH_BACKWARD;
4411 | BACKWARD SignedIconst opt_from_in cursor_name
4413 FetchStmt *n = makeNode(FetchStmt);
4415 n->direction = FETCH_BACKWARD;
4419 | BACKWARD ALL opt_from_in cursor_name
4421 FetchStmt *n = makeNode(FetchStmt);
4423 n->direction = FETCH_BACKWARD;
4424 n->howMany = FETCH_ALL;
4433 opt_from_in: from_in {}
4438 /*****************************************************************************
4440 * GRANT and REVOKE statements
4442 *****************************************************************************/
4444 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
4445 opt_grant_grant_option
4447 GrantStmt *n = makeNode(GrantStmt);
4450 n->targtype = ($4)->targtype;
4451 n->objtype = ($4)->objtype;
4452 n->objects = ($4)->objs;
4454 n->grant_option = $7;
4460 REVOKE privileges ON privilege_target
4461 FROM grantee_list opt_drop_behavior
4463 GrantStmt *n = makeNode(GrantStmt);
4464 n->is_grant = false;
4465 n->grant_option = false;
4467 n->targtype = ($4)->targtype;
4468 n->objtype = ($4)->objtype;
4469 n->objects = ($4)->objs;
4474 | REVOKE GRANT OPTION FOR privileges ON privilege_target
4475 FROM grantee_list opt_drop_behavior
4477 GrantStmt *n = makeNode(GrantStmt);
4478 n->is_grant = false;
4479 n->grant_option = true;
4481 n->targtype = ($7)->targtype;
4482 n->objtype = ($7)->objtype;
4483 n->objects = ($7)->objs;
4492 * Privilege names are represented as strings; the validity of the privilege
4493 * names gets checked at execution. This is a bit annoying but we have little
4494 * choice because of the syntactic conflict with lists of role names in
4495 * GRANT/REVOKE. What's more, we have to call out in the "privilege"
4496 * production any reserved keywords that need to be usable as privilege names.
4499 /* either ALL [PRIVILEGES] or a list of individual privileges */
4500 privileges: privilege_list
4506 | ALL '(' columnList ')'
4508 AccessPriv *n = makeNode(AccessPriv);
4509 n->priv_name = NULL;
4513 | ALL PRIVILEGES '(' columnList ')'
4515 AccessPriv *n = makeNode(AccessPriv);
4516 n->priv_name = NULL;
4522 privilege_list: privilege { $$ = list_make1($1); }
4523 | privilege_list ',' privilege { $$ = lappend($1, $3); }
4526 privilege: SELECT opt_column_list
4528 AccessPriv *n = makeNode(AccessPriv);
4529 n->priv_name = pstrdup($1);
4533 | REFERENCES opt_column_list
4535 AccessPriv *n = makeNode(AccessPriv);
4536 n->priv_name = pstrdup($1);
4540 | CREATE opt_column_list
4542 AccessPriv *n = makeNode(AccessPriv);
4543 n->priv_name = pstrdup($1);
4547 | ColId opt_column_list
4549 AccessPriv *n = makeNode(AccessPriv);
4557 /* Don't bother trying to fold the first two rules into one using
4558 * opt_table. You're going to get conflicts.
4563 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4564 n->targtype = ACL_TARGET_OBJECT;
4565 n->objtype = ACL_OBJECT_RELATION;
4569 | TABLE qualified_name_list
4571 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4572 n->targtype = ACL_TARGET_OBJECT;
4573 n->objtype = ACL_OBJECT_RELATION;
4577 | SEQUENCE qualified_name_list
4579 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4580 n->targtype = ACL_TARGET_OBJECT;
4581 n->objtype = ACL_OBJECT_SEQUENCE;
4585 | FOREIGN DATA_P WRAPPER name_list
4587 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4588 n->targtype = ACL_TARGET_OBJECT;
4589 n->objtype = ACL_OBJECT_FDW;
4593 | FOREIGN SERVER name_list
4595 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4596 n->targtype = ACL_TARGET_OBJECT;
4597 n->objtype = ACL_OBJECT_FOREIGN_SERVER;
4601 | FUNCTION function_with_argtypes_list
4603 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4604 n->targtype = ACL_TARGET_OBJECT;
4605 n->objtype = ACL_OBJECT_FUNCTION;
4609 | DATABASE name_list
4611 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4612 n->targtype = ACL_TARGET_OBJECT;
4613 n->objtype = ACL_OBJECT_DATABASE;
4617 | LANGUAGE name_list
4619 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4620 n->targtype = ACL_TARGET_OBJECT;
4621 n->objtype = ACL_OBJECT_LANGUAGE;
4625 | LARGE_P OBJECT_P Iconst_list
4627 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4628 n->targtype = ACL_TARGET_OBJECT;
4629 n->objtype = ACL_OBJECT_LARGEOBJECT;
4635 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4636 n->targtype = ACL_TARGET_OBJECT;
4637 n->objtype = ACL_OBJECT_NAMESPACE;
4641 | TABLESPACE name_list
4643 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4644 n->targtype = ACL_TARGET_OBJECT;
4645 n->objtype = ACL_OBJECT_TABLESPACE;
4649 | ALL TABLES IN_P SCHEMA name_list
4651 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4652 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4653 n->objtype = ACL_OBJECT_RELATION;
4657 | ALL SEQUENCES IN_P SCHEMA name_list
4659 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4660 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4661 n->objtype = ACL_OBJECT_SEQUENCE;
4665 | ALL FUNCTIONS IN_P SCHEMA name_list
4667 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4668 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4669 n->objtype = ACL_OBJECT_FUNCTION;
4677 grantee { $$ = list_make1($1); }
4678 | grantee_list ',' grantee { $$ = lappend($1, $3); }
4683 PrivGrantee *n = makeNode(PrivGrantee);
4684 /* This hack lets us avoid reserving PUBLIC as a keyword*/
4685 if (strcmp($1, "public") == 0)
4693 PrivGrantee *n = makeNode(PrivGrantee);
4694 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
4695 if (strcmp($2, "public") == 0)
4704 opt_grant_grant_option:
4705 WITH GRANT OPTION { $$ = TRUE; }
4706 | /*EMPTY*/ { $$ = FALSE; }
4709 function_with_argtypes_list:
4710 function_with_argtypes { $$ = list_make1($1); }
4711 | function_with_argtypes_list ',' function_with_argtypes
4712 { $$ = lappend($1, $3); }
4715 function_with_argtypes:
4718 FuncWithArgs *n = makeNode(FuncWithArgs);
4720 n->funcargs = extractArgTypes($2);
4725 /*****************************************************************************
4727 * GRANT and REVOKE ROLE statements
4729 *****************************************************************************/
4732 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4734 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4736 n->granted_roles = $2;
4737 n->grantee_roles = $4;
4745 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4747 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4748 n->is_grant = false;
4749 n->admin_opt = false;
4750 n->granted_roles = $2;
4751 n->grantee_roles = $4;
4755 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4757 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4758 n->is_grant = false;
4759 n->admin_opt = true;
4760 n->granted_roles = $5;
4761 n->grantee_roles = $7;
4767 opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
4768 | /*EMPTY*/ { $$ = FALSE; }
4771 opt_granted_by: GRANTED BY RoleId { $$ = $3; }
4772 | /*EMPTY*/ { $$ = NULL; }
4775 /*****************************************************************************
4777 * ALTER DEFAULT PRIVILEGES statement
4779 *****************************************************************************/
4781 AlterDefaultPrivilegesStmt:
4782 ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
4784 AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
4786 n->action = (GrantStmt *) $5;
4792 DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
4793 | /* EMPTY */ { $$ = NIL; }
4797 IN_P SCHEMA name_list
4799 $$ = makeDefElem("schemas", (Node *)$3);
4801 | FOR ROLE name_list
4803 $$ = makeDefElem("roles", (Node *)$3);
4805 | FOR USER name_list
4807 $$ = makeDefElem("roles", (Node *)$3);
4812 * This should match GRANT/REVOKE, except that individual target objects
4813 * are not mentioned and we only allow a subset of object types.
4816 GRANT privileges ON defacl_privilege_target TO grantee_list
4817 opt_grant_grant_option
4819 GrantStmt *n = makeNode(GrantStmt);
4822 n->targtype = ACL_TARGET_DEFAULTS;
4826 n->grant_option = $7;
4829 | REVOKE privileges ON defacl_privilege_target
4830 FROM grantee_list opt_drop_behavior
4832 GrantStmt *n = makeNode(GrantStmt);
4833 n->is_grant = false;
4834 n->grant_option = false;
4836 n->targtype = ACL_TARGET_DEFAULTS;
4843 | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
4844 FROM grantee_list opt_drop_behavior
4846 GrantStmt *n = makeNode(GrantStmt);
4847 n->is_grant = false;
4848 n->grant_option = true;
4850 n->targtype = ACL_TARGET_DEFAULTS;
4859 defacl_privilege_target:
4860 TABLES { $$ = ACL_OBJECT_RELATION; }
4861 | FUNCTIONS { $$ = ACL_OBJECT_FUNCTION; }
4862 | SEQUENCES { $$ = ACL_OBJECT_SEQUENCE; }
4866 /*****************************************************************************
4868 * QUERY: CREATE INDEX
4870 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
4871 * willing to make TABLESPACE a fully reserved word.
4872 *****************************************************************************/
4874 IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_index_name
4875 ON qualified_name access_method_clause '(' index_params ')'
4876 opt_reloptions OptTableSpace where_clause
4878 IndexStmt *n = makeNode(IndexStmt);
4883 n->accessMethod = $8;
4884 n->indexParams = $10;
4886 n->tableSpace = $13;
4887 n->whereClause = $14;
4893 UNIQUE { $$ = TRUE; }
4894 | /*EMPTY*/ { $$ = FALSE; }
4898 CONCURRENTLY { $$ = TRUE; }
4899 | /*EMPTY*/ { $$ = FALSE; }
4903 index_name { $$ = $1; }
4904 | /*EMPTY*/ { $$ = NULL; }
4907 access_method_clause:
4908 USING access_method { $$ = $2; }
4909 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
4912 index_params: index_elem { $$ = list_make1($1); }
4913 | index_params ',' index_elem { $$ = lappend($1, $3); }
4917 * Index attributes can be either simple column references, or arbitrary
4918 * expressions in parens. For backwards-compatibility reasons, we allow
4919 * an expression that's just a function call to be written without parens.
4921 index_elem: ColId opt_class opt_asc_desc opt_nulls_order
4923 $$ = makeNode(IndexElem);
4926 $$->indexcolname = NULL;
4929 $$->nulls_ordering = $4;
4931 | func_expr opt_class opt_asc_desc opt_nulls_order
4933 $$ = makeNode(IndexElem);
4936 $$->indexcolname = NULL;
4939 $$->nulls_ordering = $4;
4941 | '(' a_expr ')' opt_class opt_asc_desc opt_nulls_order
4943 $$ = makeNode(IndexElem);
4946 $$->indexcolname = NULL;
4949 $$->nulls_ordering = $6;
4953 opt_class: any_name { $$ = $1; }
4954 | USING any_name { $$ = $2; }
4955 | /*EMPTY*/ { $$ = NIL; }
4958 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
4959 | DESC { $$ = SORTBY_DESC; }
4960 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
4963 opt_nulls_order: NULLS_FIRST { $$ = SORTBY_NULLS_FIRST; }
4964 | NULLS_LAST { $$ = SORTBY_NULLS_LAST; }
4965 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
4969 /*****************************************************************************
4972 * create [or replace] function <fname>
4973 * [(<type-1> { , <type-n>})]
4975 * as <filename or code in language as appropriate>
4976 * language <lang> [with parameters]
4978 *****************************************************************************/
4981 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4982 RETURNS func_return createfunc_opt_list opt_definition
4984 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4993 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4994 RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
4996 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4999 n->parameters = mergeTableFuncParameters($5, $9);
5000 n->returnType = TableFuncTypeName($9);
5001 n->returnType->location = @7;
5003 n->withClause = $12;
5006 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5007 createfunc_opt_list opt_definition
5009 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5013 n->returnType = NULL;
5021 OR REPLACE { $$ = TRUE; }
5022 | /*EMPTY*/ { $$ = FALSE; }
5025 func_args: '(' func_args_list ')' { $$ = $2; }
5026 | '(' ')' { $$ = NIL; }
5030 func_arg { $$ = list_make1($1); }
5031 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
5035 * func_args_with_defaults is separate because we only want to accept
5036 * defaults in CREATE FUNCTION, not in ALTER etc.
5038 func_args_with_defaults:
5039 '(' func_args_with_defaults_list ')' { $$ = $2; }
5040 | '(' ')' { $$ = NIL; }
5043 func_args_with_defaults_list:
5044 func_arg_with_default { $$ = list_make1($1); }
5045 | func_args_with_defaults_list ',' func_arg_with_default
5046 { $$ = lappend($1, $3); }
5050 * The style with arg_class first is SQL99 standard, but Oracle puts
5051 * param_name first; accept both since it's likely people will try both
5052 * anyway. Don't bother trying to save productions by letting arg_class
5053 * have an empty alternative ... you'll get shift/reduce conflicts.
5055 * We can catch over-specified arguments here if we want to,
5056 * but for now better to silently swallow typmod, etc.
5057 * - thomas 2000-03-22
5060 arg_class param_name func_type
5062 FunctionParameter *n = makeNode(FunctionParameter);
5069 | param_name arg_class func_type
5071 FunctionParameter *n = makeNode(FunctionParameter);
5078 | param_name func_type
5080 FunctionParameter *n = makeNode(FunctionParameter);
5083 n->mode = FUNC_PARAM_IN;
5087 | arg_class func_type
5089 FunctionParameter *n = makeNode(FunctionParameter);
5098 FunctionParameter *n = makeNode(FunctionParameter);
5101 n->mode = FUNC_PARAM_IN;
5107 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
5108 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
5109 | OUT_P { $$ = FUNC_PARAM_OUT; }
5110 | INOUT { $$ = FUNC_PARAM_INOUT; }
5111 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
5112 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
5116 * Ideally param_name should be ColId, but that causes too many conflicts.
5118 param_name: type_function_name
5124 /* We can catch over-specified results here if we want to,
5125 * but for now better to silently swallow typmod, etc.
5126 * - thomas 2000-03-22
5133 * We would like to make the %TYPE productions here be ColId attrs etc,
5134 * but that causes reduce/reduce conflicts. type_function_name
5135 * is next best choice.
5137 func_type: Typename { $$ = $1; }
5138 | type_function_name attrs '%' TYPE_P
5140 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
5141 $$->pct_type = true;
5144 | SETOF type_function_name attrs '%' TYPE_P
5146 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
5147 $$->pct_type = true;
5153 func_arg_with_default:
5158 | func_arg DEFAULT a_expr
5163 | func_arg '=' a_expr
5171 createfunc_opt_list:
5172 /* Must be at least one to prevent conflict */
5173 createfunc_opt_item { $$ = list_make1($1); }
5174 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
5178 * Options common to both CREATE FUNCTION and ALTER FUNCTION
5180 common_func_opt_item:
5181 CALLED ON NULL_P INPUT_P
5183 $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
5185 | RETURNS NULL_P ON NULL_P INPUT_P
5187 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5191 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5195 $$ = makeDefElem("volatility", (Node *)makeString("immutable"));
5199 $$ = makeDefElem("volatility", (Node *)makeString("stable"));
5203 $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
5205 | EXTERNAL SECURITY DEFINER
5207 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5209 | EXTERNAL SECURITY INVOKER
5211 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5215 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5219 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5223 $$ = makeDefElem("cost", (Node *)$2);
5227 $$ = makeDefElem("rows", (Node *)$2);
5231 /* we abuse the normal content of a DefElem here */
5232 $$ = makeDefElem("set", (Node *)$1);
5236 createfunc_opt_item:
5239 $$ = makeDefElem("as", (Node *)$2);
5241 | LANGUAGE ColId_or_Sconst
5243 $$ = makeDefElem("language", (Node *)makeString($2));
5247 $$ = makeDefElem("window", (Node *)makeInteger(TRUE));
5249 | common_func_opt_item
5255 func_as: Sconst { $$ = list_make1(makeString($1)); }
5258 $$ = list_make2(makeString($1), makeString($3));
5263 WITH definition { $$ = $2; }
5264 | /*EMPTY*/ { $$ = NIL; }
5267 table_func_column: param_name func_type
5269 FunctionParameter *n = makeNode(FunctionParameter);
5272 n->mode = FUNC_PARAM_TABLE;
5278 table_func_column_list:
5281 $$ = list_make1($1);
5283 | table_func_column_list ',' table_func_column
5285 $$ = lappend($1, $3);
5289 /*****************************************************************************
5292 * RENAME and OWNER subcommands are already provided by the generic
5293 * ALTER infrastructure, here we just specify alterations that can
5294 * only be applied to functions.
5296 *****************************************************************************/
5298 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
5300 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
5308 /* At least one option must be specified */
5309 common_func_opt_item { $$ = list_make1($1); }
5310 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
5313 /* Ignored, merely for SQL compliance */
5320 /*****************************************************************************
5324 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
5325 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
5326 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
5328 *****************************************************************************/
5331 DROP FUNCTION func_name func_args opt_drop_behavior
5333 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5334 n->kind = OBJECT_FUNCTION;
5336 n->args = extractArgTypes($4);
5338 n->missing_ok = false;
5341 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
5343 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5344 n->kind = OBJECT_FUNCTION;
5346 n->args = extractArgTypes($6);
5348 n->missing_ok = true;
5354 DROP AGGREGATE func_name aggr_args opt_drop_behavior
5356 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5357 n->kind = OBJECT_AGGREGATE;
5361 n->missing_ok = false;
5364 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
5366 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5367 n->kind = OBJECT_AGGREGATE;
5371 n->missing_ok = true;
5377 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
5379 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5380 n->kind = OBJECT_OPERATOR;
5384 n->missing_ok = false;
5387 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
5389 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5390 n->kind = OBJECT_OPERATOR;
5394 n->missing_ok = true;
5403 (errcode(ERRCODE_SYNTAX_ERROR),
5404 errmsg("missing argument"),
5405 errhint("Use NONE to denote the missing argument of a unary operator."),
5406 parser_errposition(@3)));
5408 | '(' Typename ',' Typename ')'
5409 { $$ = list_make2($2, $4); }
5410 | '(' NONE ',' Typename ')' /* left unary */
5411 { $$ = list_make2(NULL, $4); }
5412 | '(' Typename ',' NONE ')' /* right unary */
5413 { $$ = list_make2($2, NULL); }
5418 { $$ = list_make1(makeString($1)); }
5419 | ColId '.' any_operator
5420 { $$ = lcons(makeString($1), $3); }
5423 /*****************************************************************************
5425 * DO <anonymous code block> [ LANGUAGE language ]
5427 * We use a DefElem list for future extensibility, and to allow flexibility
5428 * in the clause order.
5430 *****************************************************************************/
5432 DoStmt: DO dostmt_opt_list
5434 DoStmt *n = makeNode(DoStmt);
5441 dostmt_opt_item { $$ = list_make1($1); }
5442 | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
5448 $$ = makeDefElem("as", (Node *)makeString($1));
5450 | LANGUAGE ColId_or_Sconst
5452 $$ = makeDefElem("language", (Node *)makeString($2));
5456 /*****************************************************************************
5458 * CREATE CAST / DROP CAST
5460 *****************************************************************************/
5462 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
5463 WITH FUNCTION function_with_argtypes cast_context
5465 CreateCastStmt *n = makeNode(CreateCastStmt);
5469 n->context = (CoercionContext) $11;
5473 | CREATE CAST '(' Typename AS Typename ')'
5474 WITHOUT FUNCTION cast_context
5476 CreateCastStmt *n = makeNode(CreateCastStmt);
5480 n->context = (CoercionContext) $10;
5484 | CREATE CAST '(' Typename AS Typename ')'
5485 WITH INOUT cast_context
5487 CreateCastStmt *n = makeNode(CreateCastStmt);
5491 n->context = (CoercionContext) $10;
5497 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
5498 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
5499 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
5503 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
5505 DropCastStmt *n = makeNode(DropCastStmt);
5514 opt_if_exists: IF_P EXISTS { $$ = TRUE; }
5515 | /*EMPTY*/ { $$ = FALSE; }
5519 /*****************************************************************************
5523 * REINDEX type <name> [FORCE]
5525 * FORCE no longer does anything, but we accept it for backwards compatibility
5526 *****************************************************************************/
5529 REINDEX reindex_type qualified_name opt_force
5531 ReindexStmt *n = makeNode(ReindexStmt);
5537 | REINDEX SYSTEM_P name opt_force
5539 ReindexStmt *n = makeNode(ReindexStmt);
5540 n->kind = OBJECT_DATABASE;
5543 n->do_system = true;
5547 | REINDEX DATABASE name opt_force
5549 ReindexStmt *n = makeNode(ReindexStmt);
5550 n->kind = OBJECT_DATABASE;
5553 n->do_system = true;
5560 INDEX { $$ = OBJECT_INDEX; }
5561 | TABLE { $$ = OBJECT_TABLE; }
5564 opt_force: FORCE { $$ = TRUE; }
5565 | /* EMPTY */ { $$ = FALSE; }
5569 /*****************************************************************************
5571 * ALTER THING name RENAME TO newname
5573 *****************************************************************************/
5575 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
5577 RenameStmt *n = makeNode(RenameStmt);
5578 n->renameType = OBJECT_AGGREGATE;
5584 | ALTER CONVERSION_P any_name RENAME TO name
5586 RenameStmt *n = makeNode(RenameStmt);
5587 n->renameType = OBJECT_CONVERSION;
5592 | ALTER DATABASE database_name RENAME TO database_name
5594 RenameStmt *n = makeNode(RenameStmt);
5595 n->renameType = OBJECT_DATABASE;
5600 | ALTER FUNCTION function_with_argtypes RENAME TO name
5602 RenameStmt *n = makeNode(RenameStmt);
5603 n->renameType = OBJECT_FUNCTION;
5604 n->object = $3->funcname;
5605 n->objarg = $3->funcargs;
5609 | ALTER GROUP_P RoleId RENAME TO RoleId
5611 RenameStmt *n = makeNode(RenameStmt);
5612 n->renameType = OBJECT_ROLE;
5617 | ALTER opt_procedural LANGUAGE name RENAME TO name
5619 RenameStmt *n = makeNode(RenameStmt);
5620 n->renameType = OBJECT_LANGUAGE;
5625 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
5627 RenameStmt *n = makeNode(RenameStmt);
5628 n->renameType = OBJECT_OPCLASS;
5634 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
5636 RenameStmt *n = makeNode(RenameStmt);
5637 n->renameType = OBJECT_OPFAMILY;
5643 | ALTER SCHEMA name RENAME TO name
5645 RenameStmt *n = makeNode(RenameStmt);
5646 n->renameType = OBJECT_SCHEMA;
5651 | ALTER TABLE relation_expr RENAME TO name
5653 RenameStmt *n = makeNode(RenameStmt);
5654 n->renameType = OBJECT_TABLE;
5660 | ALTER SEQUENCE qualified_name RENAME TO name
5662 RenameStmt *n = makeNode(RenameStmt);
5663 n->renameType = OBJECT_SEQUENCE;
5669 | ALTER VIEW qualified_name RENAME TO name
5671 RenameStmt *n = makeNode(RenameStmt);
5672 n->renameType = OBJECT_VIEW;
5678 | ALTER INDEX qualified_name RENAME TO name
5680 RenameStmt *n = makeNode(RenameStmt);
5681 n->renameType = OBJECT_INDEX;
5687 | ALTER TABLE relation_expr RENAME opt_column name TO name
5689 RenameStmt *n = makeNode(RenameStmt);
5690 n->renameType = OBJECT_COLUMN;
5696 | ALTER TRIGGER name ON qualified_name RENAME TO name
5698 RenameStmt *n = makeNode(RenameStmt);
5699 n->renameType = OBJECT_TRIGGER;
5705 | ALTER ROLE RoleId RENAME TO RoleId
5707 RenameStmt *n = makeNode(RenameStmt);
5708 n->renameType = OBJECT_ROLE;
5713 | ALTER USER RoleId RENAME TO RoleId
5715 RenameStmt *n = makeNode(RenameStmt);
5716 n->renameType = OBJECT_ROLE;
5721 | ALTER TABLESPACE name RENAME TO name
5723 RenameStmt *n = makeNode(RenameStmt);
5724 n->renameType = OBJECT_TABLESPACE;
5729 | ALTER TABLESPACE name SET reloptions
5731 AlterTableSpaceOptionsStmt *n =
5732 makeNode(AlterTableSpaceOptionsStmt);
5733 n->tablespacename = $3;
5738 | ALTER TABLESPACE name RESET reloptions
5740 AlterTableSpaceOptionsStmt *n =
5741 makeNode(AlterTableSpaceOptionsStmt);
5742 n->tablespacename = $3;
5747 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
5749 RenameStmt *n = makeNode(RenameStmt);
5750 n->renameType = OBJECT_TSPARSER;
5755 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
5757 RenameStmt *n = makeNode(RenameStmt);
5758 n->renameType = OBJECT_TSDICTIONARY;
5763 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
5765 RenameStmt *n = makeNode(RenameStmt);
5766 n->renameType = OBJECT_TSTEMPLATE;
5771 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
5773 RenameStmt *n = makeNode(RenameStmt);
5774 n->renameType = OBJECT_TSCONFIGURATION;
5779 | ALTER TYPE_P any_name RENAME TO name
5781 RenameStmt *n = makeNode(RenameStmt);
5782 n->renameType = OBJECT_TYPE;
5789 opt_column: COLUMN { $$ = COLUMN; }
5790 | /*EMPTY*/ { $$ = 0; }
5793 opt_set_data: SET DATA_P { $$ = 1; }
5794 | /*EMPTY*/ { $$ = 0; }
5797 /*****************************************************************************
5799 * ALTER THING name SET SCHEMA name
5801 *****************************************************************************/
5803 AlterObjectSchemaStmt:
5804 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
5806 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5807 n->objectType = OBJECT_AGGREGATE;
5813 | ALTER DOMAIN_P any_name SET SCHEMA name
5815 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5816 n->objectType = OBJECT_DOMAIN;
5821 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
5823 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5824 n->objectType = OBJECT_FUNCTION;
5825 n->object = $3->funcname;
5826 n->objarg = $3->funcargs;
5830 | ALTER TABLE relation_expr SET SCHEMA name
5832 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5833 n->objectType = OBJECT_TABLE;
5838 | ALTER SEQUENCE qualified_name SET SCHEMA name
5840 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5841 n->objectType = OBJECT_SEQUENCE;
5846 | ALTER VIEW qualified_name SET SCHEMA name
5848 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5849 n->objectType = OBJECT_VIEW;
5854 | ALTER TYPE_P any_name SET SCHEMA name
5856 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5857 n->objectType = OBJECT_TYPE;
5864 /*****************************************************************************
5866 * ALTER THING name OWNER TO newname
5868 *****************************************************************************/
5870 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
5872 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5873 n->objectType = OBJECT_AGGREGATE;
5879 | ALTER CONVERSION_P any_name OWNER TO RoleId
5881 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5882 n->objectType = OBJECT_CONVERSION;
5887 | ALTER DATABASE database_name OWNER TO RoleId
5889 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5890 n->objectType = OBJECT_DATABASE;
5891 n->object = list_make1(makeString($3));
5895 | ALTER DOMAIN_P any_name OWNER TO RoleId
5897 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5898 n->objectType = OBJECT_DOMAIN;
5903 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
5905 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5906 n->objectType = OBJECT_FUNCTION;
5907 n->object = $3->funcname;
5908 n->objarg = $3->funcargs;
5912 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
5914 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5915 n->objectType = OBJECT_LANGUAGE;
5916 n->object = list_make1(makeString($4));
5920 | ALTER LARGE_P OBJECT_P Iconst OWNER TO RoleId
5922 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5923 n->objectType = OBJECT_LARGEOBJECT;
5924 n->object = list_make1(makeInteger($4));
5928 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
5930 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5931 n->objectType = OBJECT_OPERATOR;
5937 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
5939 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5940 n->objectType = OBJECT_OPCLASS;
5946 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
5948 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5949 n->objectType = OBJECT_OPFAMILY;
5955 | ALTER SCHEMA name OWNER TO RoleId
5957 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5958 n->objectType = OBJECT_SCHEMA;
5959 n->object = list_make1(makeString($3));
5963 | ALTER TYPE_P any_name OWNER TO RoleId
5965 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5966 n->objectType = OBJECT_TYPE;
5971 | ALTER TABLESPACE name OWNER TO RoleId
5973 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5974 n->objectType = OBJECT_TABLESPACE;
5975 n->object = list_make1(makeString($3));
5979 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
5981 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5982 n->objectType = OBJECT_TSDICTIONARY;
5987 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
5989 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5990 n->objectType = OBJECT_TSCONFIGURATION;
5995 | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleId
5997 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5998 n->objectType = OBJECT_FDW;
5999 n->object = list_make1(makeString($5));
6003 | ALTER SERVER name OWNER TO RoleId
6005 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6006 n->objectType = OBJECT_FOREIGN_SERVER;
6007 n->object = list_make1(makeString($3));
6014 /*****************************************************************************
6016 * QUERY: Define Rewrite Rule
6018 *****************************************************************************/
6020 RuleStmt: CREATE opt_or_replace RULE name AS
6021 ON event TO qualified_name where_clause
6022 DO opt_instead RuleActionList
6024 RuleStmt *n = makeNode(RuleStmt);
6028 n->whereClause = $10;
6037 NOTHING { $$ = NIL; }
6038 | RuleActionStmt { $$ = list_make1($1); }
6039 | '(' RuleActionMulti ')' { $$ = $2; }
6042 /* the thrashing around here is to discard "empty" statements... */
6044 RuleActionMulti ';' RuleActionStmtOrEmpty
6046 $$ = lappend($1, $3);
6050 | RuleActionStmtOrEmpty
6052 $$ = list_make1($1);
6066 RuleActionStmtOrEmpty:
6067 RuleActionStmt { $$ = $1; }
6068 | /*EMPTY*/ { $$ = NULL; }
6071 event: SELECT { $$ = CMD_SELECT; }
6072 | UPDATE { $$ = CMD_UPDATE; }
6073 | DELETE_P { $$ = CMD_DELETE; }
6074 | INSERT { $$ = CMD_INSERT; }
6078 INSTEAD { $$ = TRUE; }
6079 | ALSO { $$ = FALSE; }
6080 | /*EMPTY*/ { $$ = FALSE; }
6085 DROP RULE name ON qualified_name opt_drop_behavior
6087 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6091 n->removeType = OBJECT_RULE;
6092 n->missing_ok = false;
6095 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
6097 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6101 n->removeType = OBJECT_RULE;
6102 n->missing_ok = true;
6108 /*****************************************************************************
6111 * NOTIFY <identifier> can appear both in rule bodies and
6112 * as a query-level command
6114 *****************************************************************************/
6116 NotifyStmt: NOTIFY ColId
6118 NotifyStmt *n = makeNode(NotifyStmt);
6119 n->conditionname = $2;
6124 ListenStmt: LISTEN ColId
6126 ListenStmt *n = makeNode(ListenStmt);
6127 n->conditionname = $2;
6135 UnlistenStmt *n = makeNode(UnlistenStmt);
6136 n->conditionname = $2;
6141 UnlistenStmt *n = makeNode(UnlistenStmt);
6142 n->conditionname = NULL;
6148 /*****************************************************************************
6152 * BEGIN / COMMIT / ROLLBACK
6153 * (also older versions END / ABORT)
6155 *****************************************************************************/
6158 ABORT_P opt_transaction
6160 TransactionStmt *n = makeNode(TransactionStmt);
6161 n->kind = TRANS_STMT_ROLLBACK;
6165 | BEGIN_P opt_transaction transaction_mode_list_or_empty
6167 TransactionStmt *n = makeNode(TransactionStmt);
6168 n->kind = TRANS_STMT_BEGIN;
6172 | START TRANSACTION transaction_mode_list_or_empty
6174 TransactionStmt *n = makeNode(TransactionStmt);
6175 n->kind = TRANS_STMT_START;
6179 | COMMIT opt_transaction
6181 TransactionStmt *n = makeNode(TransactionStmt);
6182 n->kind = TRANS_STMT_COMMIT;
6186 | END_P opt_transaction
6188 TransactionStmt *n = makeNode(TransactionStmt);
6189 n->kind = TRANS_STMT_COMMIT;
6193 | ROLLBACK opt_transaction
6195 TransactionStmt *n = makeNode(TransactionStmt);
6196 n->kind = TRANS_STMT_ROLLBACK;
6202 TransactionStmt *n = makeNode(TransactionStmt);
6203 n->kind = TRANS_STMT_SAVEPOINT;
6204 n->options = list_make1(makeDefElem("savepoint_name",
6205 (Node *)makeString($2)));
6208 | RELEASE SAVEPOINT ColId
6210 TransactionStmt *n = makeNode(TransactionStmt);
6211 n->kind = TRANS_STMT_RELEASE;
6212 n->options = list_make1(makeDefElem("savepoint_name",
6213 (Node *)makeString($3)));
6218 TransactionStmt *n = makeNode(TransactionStmt);
6219 n->kind = TRANS_STMT_RELEASE;
6220 n->options = list_make1(makeDefElem("savepoint_name",
6221 (Node *)makeString($2)));
6224 | ROLLBACK opt_transaction TO SAVEPOINT ColId
6226 TransactionStmt *n = makeNode(TransactionStmt);
6227 n->kind = TRANS_STMT_ROLLBACK_TO;
6228 n->options = list_make1(makeDefElem("savepoint_name",
6229 (Node *)makeString($5)));
6232 | ROLLBACK opt_transaction TO ColId
6234 TransactionStmt *n = makeNode(TransactionStmt);
6235 n->kind = TRANS_STMT_ROLLBACK_TO;
6236 n->options = list_make1(makeDefElem("savepoint_name",
6237 (Node *)makeString($4)));
6240 | PREPARE TRANSACTION Sconst
6242 TransactionStmt *n = makeNode(TransactionStmt);
6243 n->kind = TRANS_STMT_PREPARE;
6247 | COMMIT PREPARED Sconst
6249 TransactionStmt *n = makeNode(TransactionStmt);
6250 n->kind = TRANS_STMT_COMMIT_PREPARED;
6254 | ROLLBACK PREPARED Sconst
6256 TransactionStmt *n = makeNode(TransactionStmt);
6257 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
6263 opt_transaction: WORK {}
6268 transaction_mode_item:
6269 ISOLATION LEVEL iso_level
6270 { $$ = makeDefElem("transaction_isolation",
6271 makeStringConst($3, @3)); }
6273 { $$ = makeDefElem("transaction_read_only",
6274 makeIntConst(TRUE, @1)); }
6276 { $$ = makeDefElem("transaction_read_only",
6277 makeIntConst(FALSE, @1)); }
6280 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
6281 transaction_mode_list:
6282 transaction_mode_item
6283 { $$ = list_make1($1); }
6284 | transaction_mode_list ',' transaction_mode_item
6285 { $$ = lappend($1, $3); }
6286 | transaction_mode_list transaction_mode_item
6287 { $$ = lappend($1, $2); }
6290 transaction_mode_list_or_empty:
6291 transaction_mode_list
6297 /*****************************************************************************
6300 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
6301 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
6303 *****************************************************************************/
6305 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
6306 AS SelectStmt opt_check_option
6308 ViewStmt *n = makeNode(ViewStmt);
6310 n->view->istemp = $2;
6316 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
6317 AS SelectStmt opt_check_option
6319 ViewStmt *n = makeNode(ViewStmt);
6321 n->view->istemp = $4;
6333 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6334 errmsg("WITH CHECK OPTION is not implemented")));
6336 | WITH CASCADED CHECK OPTION
6339 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6340 errmsg("WITH CHECK OPTION is not implemented")));
6342 | WITH LOCAL CHECK OPTION
6345 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6346 errmsg("WITH CHECK OPTION is not implemented")));
6348 | /* EMPTY */ { $$ = NIL; }
6351 /*****************************************************************************
6356 *****************************************************************************/
6358 LoadStmt: LOAD file_name
6360 LoadStmt *n = makeNode(LoadStmt);
6367 /*****************************************************************************
6371 *****************************************************************************/
6374 CREATE DATABASE database_name opt_with createdb_opt_list
6376 CreatedbStmt *n = makeNode(CreatedbStmt);
6384 createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
6385 | /* EMPTY */ { $$ = NIL; }
6389 TABLESPACE opt_equal name
6391 $$ = makeDefElem("tablespace", (Node *)makeString($3));
6393 | TABLESPACE opt_equal DEFAULT
6395 $$ = makeDefElem("tablespace", NULL);
6397 | LOCATION opt_equal Sconst
6399 $$ = makeDefElem("location", (Node *)makeString($3));
6401 | LOCATION opt_equal DEFAULT
6403 $$ = makeDefElem("location", NULL);
6405 | TEMPLATE opt_equal name
6407 $$ = makeDefElem("template", (Node *)makeString($3));
6409 | TEMPLATE opt_equal DEFAULT
6411 $$ = makeDefElem("template", NULL);
6413 | ENCODING opt_equal Sconst
6415 $$ = makeDefElem("encoding", (Node *)makeString($3));
6417 | ENCODING opt_equal Iconst
6419 $$ = makeDefElem("encoding", (Node *)makeInteger($3));
6421 | ENCODING opt_equal DEFAULT
6423 $$ = makeDefElem("encoding", NULL);
6425 | LC_COLLATE_P opt_equal Sconst
6427 $$ = makeDefElem("lc_collate", (Node *)makeString($3));
6429 | LC_COLLATE_P opt_equal DEFAULT
6431 $$ = makeDefElem("lc_collate", NULL);
6433 | LC_CTYPE_P opt_equal Sconst
6435 $$ = makeDefElem("lc_ctype", (Node *)makeString($3));
6437 | LC_CTYPE_P opt_equal DEFAULT
6439 $$ = makeDefElem("lc_ctype", NULL);
6441 | CONNECTION LIMIT opt_equal SignedIconst
6443 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6445 | OWNER opt_equal name
6447 $$ = makeDefElem("owner", (Node *)makeString($3));
6449 | OWNER opt_equal DEFAULT
6451 $$ = makeDefElem("owner", NULL);
6456 * Though the equals sign doesn't match other WITH options, pg_dump uses
6457 * equals for backward compatibility, and it doesn't seem worth removing it.
6464 /*****************************************************************************
6468 *****************************************************************************/
6471 ALTER DATABASE database_name opt_with alterdb_opt_list
6473 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6478 | ALTER DATABASE database_name SET TABLESPACE name
6480 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6482 n->options = list_make1(makeDefElem("tablespace",
6483 (Node *)makeString($6)));
6488 AlterDatabaseSetStmt:
6489 ALTER DATABASE database_name SetResetClause
6491 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
6500 alterdb_opt_list alterdb_opt_item { $$ = lappend($1, $2); }
6501 | /* EMPTY */ { $$ = NIL; }
6505 CONNECTION LIMIT opt_equal SignedIconst
6507 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6512 /*****************************************************************************
6514 * DROP DATABASE [ IF EXISTS ]
6516 * This is implicitly CASCADE, no need for drop behavior
6517 *****************************************************************************/
6519 DropdbStmt: DROP DATABASE database_name
6521 DropdbStmt *n = makeNode(DropdbStmt);
6523 n->missing_ok = FALSE;
6526 | DROP DATABASE IF_P EXISTS database_name
6528 DropdbStmt *n = makeNode(DropdbStmt);
6530 n->missing_ok = TRUE;
6536 /*****************************************************************************
6538 * Manipulate a domain
6540 *****************************************************************************/
6543 CREATE DOMAIN_P any_name opt_as Typename ColQualList
6545 CreateDomainStmt *n = makeNode(CreateDomainStmt);
6548 n->constraints = $6;
6554 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
6555 ALTER DOMAIN_P any_name alter_column_default
6557 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6563 /* ALTER DOMAIN <domain> DROP NOT NULL */
6564 | ALTER DOMAIN_P any_name DROP NOT NULL_P
6566 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6571 /* ALTER DOMAIN <domain> SET NOT NULL */
6572 | ALTER DOMAIN_P any_name SET NOT NULL_P
6574 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6579 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
6580 | ALTER DOMAIN_P any_name ADD_P TableConstraint
6582 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6588 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
6589 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
6591 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6605 /*****************************************************************************
6607 * Manipulate a text search dictionary or configuration
6609 *****************************************************************************/
6611 AlterTSDictionaryStmt:
6612 ALTER TEXT_P SEARCH DICTIONARY any_name definition
6614 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
6621 AlterTSConfigurationStmt:
6622 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
6624 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6628 n->override = false;
6632 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
6634 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6642 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
6644 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6647 n->dicts = list_make2($9,$11);
6648 n->override = false;
6652 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
6654 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6657 n->dicts = list_make2($11,$13);
6658 n->override = false;
6662 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
6664 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6667 n->missing_ok = false;
6670 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
6672 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6675 n->missing_ok = true;
6681 /*****************************************************************************
6683 * Manipulate a conversion
6685 * CREATE [DEFAULT] CONVERSION <conversion_name>
6686 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
6688 *****************************************************************************/
6690 CreateConversionStmt:
6691 CREATE opt_default CONVERSION_P any_name FOR Sconst
6692 TO Sconst FROM any_name
6694 CreateConversionStmt *n = makeNode(CreateConversionStmt);
6695 n->conversion_name = $4;
6696 n->for_encoding_name = $6;
6697 n->to_encoding_name = $8;
6704 /*****************************************************************************
6707 * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
6709 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
6711 *****************************************************************************/
6714 CLUSTER opt_verbose qualified_name cluster_index_specification
6716 ClusterStmt *n = makeNode(ClusterStmt);
6722 | CLUSTER opt_verbose
6724 ClusterStmt *n = makeNode(ClusterStmt);
6726 n->indexname = NULL;
6730 /* kept for pre-8.3 compatibility */
6731 | CLUSTER opt_verbose index_name ON qualified_name
6733 ClusterStmt *n = makeNode(ClusterStmt);
6741 cluster_index_specification:
6742 USING index_name { $$ = $2; }
6743 | /*EMPTY*/ { $$ = NULL; }
6747 /*****************************************************************************
6753 *****************************************************************************/
6755 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
6757 VacuumStmt *n = makeNode(VacuumStmt);
6758 n->options = VACOPT_VACUUM;
6760 n->options |= VACOPT_FULL;
6762 n->options |= VACOPT_VERBOSE;
6763 n->freeze_min_age = $3 ? 0 : -1;
6764 n->freeze_table_age = $3 ? 0 : -1;
6769 | VACUUM opt_full opt_freeze opt_verbose qualified_name
6771 VacuumStmt *n = makeNode(VacuumStmt);
6772 n->options = VACOPT_VACUUM;
6774 n->options |= VACOPT_FULL;
6776 n->options |= VACOPT_VERBOSE;
6777 n->freeze_min_age = $3 ? 0 : -1;
6778 n->freeze_table_age = $3 ? 0 : -1;
6783 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
6785 VacuumStmt *n = (VacuumStmt *) $5;
6786 n->options |= VACOPT_VACUUM;
6788 n->options |= VACOPT_FULL;
6790 n->options |= VACOPT_VERBOSE;
6791 n->freeze_min_age = $3 ? 0 : -1;
6792 n->freeze_table_age = $3 ? 0 : -1;
6795 | VACUUM '(' vacuum_option_list ')'
6797 VacuumStmt *n = makeNode(VacuumStmt);
6798 n->options = VACOPT_VACUUM | $3;
6799 if (n->options & VACOPT_FREEZE)
6800 n->freeze_min_age = n->freeze_table_age = 0;
6802 n->freeze_min_age = n->freeze_table_age = -1;
6807 | VACUUM '(' vacuum_option_list ')' qualified_name opt_name_list
6809 VacuumStmt *n = makeNode(VacuumStmt);
6810 n->options = VACOPT_VACUUM | $3;
6811 if (n->options & VACOPT_FREEZE)
6812 n->freeze_min_age = n->freeze_table_age = 0;
6814 n->freeze_min_age = n->freeze_table_age = -1;
6817 if (n->va_cols != NIL) /* implies analyze */
6818 n->options |= VACOPT_ANALYZE;
6824 vacuum_option_elem { $$ = $1; }
6825 | vacuum_option_list ',' vacuum_option_elem { $$ = $1 | $3; }
6829 analyze_keyword { $$ = VACOPT_ANALYZE; }
6830 | VERBOSE { $$ = VACOPT_VERBOSE; }
6831 | FREEZE { $$ = VACOPT_FREEZE; }
6832 | FULL { $$ = VACOPT_FULL; }
6833 | FULL INPLACE { $$ = VACOPT_FULL | VACOPT_INPLACE; }
6837 analyze_keyword opt_verbose
6839 VacuumStmt *n = makeNode(VacuumStmt);
6840 n->options = VACOPT_ANALYZE;
6842 n->options |= VACOPT_VERBOSE;
6843 n->freeze_min_age = -1;
6844 n->freeze_table_age = -1;
6849 | analyze_keyword opt_verbose qualified_name opt_name_list
6851 VacuumStmt *n = makeNode(VacuumStmt);
6852 n->options = VACOPT_ANALYZE;
6854 n->options |= VACOPT_VERBOSE;
6855 n->freeze_min_age = -1;
6856 n->freeze_table_age = -1;
6865 | ANALYSE /* British */ {}
6869 VERBOSE { $$ = TRUE; }
6870 | /*EMPTY*/ { $$ = FALSE; }
6873 opt_full: FULL { $$ = TRUE; }
6874 | /*EMPTY*/ { $$ = FALSE; }
6877 opt_freeze: FREEZE { $$ = TRUE; }
6878 | /*EMPTY*/ { $$ = FALSE; }
6882 '(' name_list ')' { $$ = $2; }
6883 | /*EMPTY*/ { $$ = NIL; }
6887 /*****************************************************************************
6890 * EXPLAIN [ANALYZE] [VERBOSE] query
6891 * EXPLAIN ( options ) query
6893 *****************************************************************************/
6896 EXPLAIN ExplainableStmt
6898 ExplainStmt *n = makeNode(ExplainStmt);
6903 | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
6905 ExplainStmt *n = makeNode(ExplainStmt);
6907 n->options = list_make1(makeDefElem("analyze", NULL));
6909 n->options = lappend(n->options,
6910 makeDefElem("verbose", NULL));
6913 | EXPLAIN VERBOSE ExplainableStmt
6915 ExplainStmt *n = makeNode(ExplainStmt);
6917 n->options = list_make1(makeDefElem("verbose", NULL));
6920 | EXPLAIN '(' explain_option_list ')' ExplainableStmt
6922 ExplainStmt *n = makeNode(ExplainStmt);
6936 | ExecuteStmt /* by default all are $$=$1 */
6939 explain_option_list:
6942 $$ = list_make1($1);
6944 | explain_option_list ',' explain_option_elem
6946 $$ = lappend($1, $3);
6950 explain_option_elem:
6951 explain_option_name explain_option_arg
6953 $$ = makeDefElem($1, $2);
6957 explain_option_name:
6959 | analyze_keyword { $$ = "analyze"; }
6960 | VERBOSE { $$ = "verbose"; }
6964 opt_boolean { $$ = (Node *) makeString($1); }
6965 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
6966 | NumericOnly { $$ = (Node *) $1; }
6967 | /* EMPTY */ { $$ = NULL; }
6970 /*****************************************************************************
6973 * PREPARE <plan_name> [(args, ...)] AS <query>
6975 *****************************************************************************/
6977 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
6979 PrepareStmt *n = makeNode(PrepareStmt);
6987 prep_type_clause: '(' type_list ')' { $$ = $2; }
6988 | /* EMPTY */ { $$ = NIL; }
6995 | DeleteStmt /* by default all are $$=$1 */
6998 /*****************************************************************************
7000 * EXECUTE <plan_name> [(params, ...)]
7001 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
7003 *****************************************************************************/
7005 ExecuteStmt: EXECUTE name execute_param_clause
7007 ExecuteStmt *n = makeNode(ExecuteStmt);
7013 | CREATE OptTemp TABLE create_as_target AS
7014 EXECUTE name execute_param_clause
7016 ExecuteStmt *n = makeNode(ExecuteStmt);
7019 $4->rel->istemp = $2;
7023 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7024 errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
7025 /* ... because it's not implemented, but it could be */
7030 execute_param_clause: '(' expr_list ')' { $$ = $2; }
7031 | /* EMPTY */ { $$ = NIL; }
7034 /*****************************************************************************
7037 * DEALLOCATE [PREPARE] <plan_name>
7039 *****************************************************************************/
7041 DeallocateStmt: DEALLOCATE name
7043 DeallocateStmt *n = makeNode(DeallocateStmt);
7047 | DEALLOCATE PREPARE name
7049 DeallocateStmt *n = makeNode(DeallocateStmt);
7055 DeallocateStmt *n = makeNode(DeallocateStmt);
7059 | DEALLOCATE PREPARE ALL
7061 DeallocateStmt *n = makeNode(DeallocateStmt);
7067 /*****************************************************************************
7072 *****************************************************************************/
7075 INSERT INTO qualified_name insert_rest returning_clause
7078 $4->returningList = $5;
7086 $$ = makeNode(InsertStmt);
7088 $$->selectStmt = $1;
7090 | '(' insert_column_list ')' SelectStmt
7092 $$ = makeNode(InsertStmt);
7094 $$->selectStmt = $4;
7098 $$ = makeNode(InsertStmt);
7100 $$->selectStmt = NULL;
7106 { $$ = list_make1($1); }
7107 | insert_column_list ',' insert_column_item
7108 { $$ = lappend($1, $3); }
7112 ColId opt_indirection
7114 $$ = makeNode(ResTarget);
7116 $$->indirection = check_indirection($2, yyscanner);
7123 RETURNING target_list { $$ = $2; }
7124 | /* EMPTY */ { $$ = NIL; }
7128 /*****************************************************************************
7133 *****************************************************************************/
7135 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
7136 using_clause where_or_current_clause returning_clause
7138 DeleteStmt *n = makeNode(DeleteStmt);
7140 n->usingClause = $4;
7141 n->whereClause = $5;
7142 n->returningList = $6;
7148 USING from_list { $$ = $2; }
7149 | /*EMPTY*/ { $$ = NIL; }
7153 /*****************************************************************************
7158 *****************************************************************************/
7160 LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
7162 LockStmt *n = makeNode(LockStmt);
7171 opt_lock: IN_P lock_type MODE { $$ = $2; }
7172 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
7175 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
7176 | ROW SHARE { $$ = RowShareLock; }
7177 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
7178 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
7179 | SHARE { $$ = ShareLock; }
7180 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
7181 | EXCLUSIVE { $$ = ExclusiveLock; }
7182 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
7185 opt_nowait: NOWAIT { $$ = TRUE; }
7186 | /*EMPTY*/ { $$ = FALSE; }
7190 /*****************************************************************************
7193 * UpdateStmt (UPDATE)
7195 *****************************************************************************/
7197 UpdateStmt: UPDATE relation_expr_opt_alias
7200 where_or_current_clause
7203 UpdateStmt *n = makeNode(UpdateStmt);
7207 n->whereClause = $6;
7208 n->returningList = $7;
7214 set_clause { $$ = $1; }
7215 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
7219 single_set_clause { $$ = list_make1($1); }
7220 | multiple_set_clause { $$ = $1; }
7224 set_target '=' ctext_expr
7227 $$->val = (Node *) $3;
7231 multiple_set_clause:
7232 '(' set_target_list ')' '=' ctext_row
7238 * Break the ctext_row apart, merge individual expressions
7239 * into the destination ResTargets. XXX this approach
7240 * cannot work for general row expressions as sources.
7242 if (list_length($2) != list_length($5))
7244 (errcode(ERRCODE_SYNTAX_ERROR),
7245 errmsg("number of columns does not match number of values"),
7246 parser_errposition(@1)));
7247 forboth(col_cell, $2, val_cell, $5)
7249 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
7250 Node *res_val = (Node *) lfirst(val_cell);
7252 res_col->val = res_val;
7260 ColId opt_indirection
7262 $$ = makeNode(ResTarget);
7264 $$->indirection = check_indirection($2, yyscanner);
7265 $$->val = NULL; /* upper production sets this */
7271 set_target { $$ = list_make1($1); }
7272 | set_target_list ',' set_target { $$ = lappend($1,$3); }
7276 /*****************************************************************************
7281 *****************************************************************************/
7282 DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
7284 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
7286 /* currently we always set FAST_PLAN option */
7287 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
7293 cursor_name: name { $$ = $1; }
7296 cursor_options: /*EMPTY*/ { $$ = 0; }
7297 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
7298 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
7299 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
7300 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
7303 opt_hold: /* EMPTY */ { $$ = 0; }
7304 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
7305 | WITHOUT HOLD { $$ = 0; }
7308 /*****************************************************************************
7313 *****************************************************************************/
7315 /* A complete SELECT statement looks like this.
7317 * The rule returns either a single SelectStmt node or a tree of them,
7318 * representing a set-operation tree.
7320 * There is an ambiguity when a sub-SELECT is within an a_expr and there
7321 * are excess parentheses: do the parentheses belong to the sub-SELECT or
7322 * to the surrounding a_expr? We don't really care, but bison wants to know.
7323 * To resolve the ambiguity, we are careful to define the grammar so that
7324 * the decision is staved off as long as possible: as long as we can keep
7325 * absorbing parentheses into the sub-SELECT, we will do so, and only when
7326 * it's no longer possible to do that will we decide that parens belong to
7327 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
7328 * parentheses are treated as part of the sub-select. The necessity of doing
7329 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
7330 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
7331 * SELECT viewpoint when we see the UNION.
7333 * This approach is implemented by defining a nonterminal select_with_parens,
7334 * which represents a SELECT with at least one outer layer of parentheses,
7335 * and being careful to use select_with_parens, never '(' SelectStmt ')',
7336 * in the expression grammar. We will then have shift-reduce conflicts
7337 * which we can resolve in favor of always treating '(' <select> ')' as
7338 * a select_with_parens. To resolve the conflicts, the productions that
7339 * conflict with the select_with_parens productions are manually given
7340 * precedences lower than the precedence of ')', thereby ensuring that we
7341 * shift ')' (and then reduce to select_with_parens) rather than trying to
7342 * reduce the inner <select> nonterminal to something else. We use UMINUS
7343 * precedence for this, which is a fairly arbitrary choice.
7345 * To be able to define select_with_parens itself without ambiguity, we need
7346 * a nonterminal select_no_parens that represents a SELECT structure with no
7347 * outermost parentheses. This is a little bit tedious, but it works.
7349 * In non-expression contexts, we use SelectStmt which can represent a SELECT
7350 * with or without outer parentheses.
7353 SelectStmt: select_no_parens %prec UMINUS
7354 | select_with_parens %prec UMINUS
7358 '(' select_no_parens ')' { $$ = $2; }
7359 | '(' select_with_parens ')' { $$ = $2; }
7363 * This rule parses the equivalent of the standard's <query expression>.
7364 * The duplicative productions are annoying, but hard to get rid of without
7365 * creating shift/reduce conflicts.
7367 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
7368 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
7369 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
7373 simple_select { $$ = $1; }
7374 | select_clause sort_clause
7376 insertSelectOptions((SelectStmt *) $1, $2, NIL,
7381 | select_clause opt_sort_clause for_locking_clause opt_select_limit
7383 insertSelectOptions((SelectStmt *) $1, $2, $3,
7384 list_nth($4, 0), list_nth($4, 1),
7389 | select_clause opt_sort_clause select_limit opt_for_locking_clause
7391 insertSelectOptions((SelectStmt *) $1, $2, $4,
7392 list_nth($3, 0), list_nth($3, 1),
7397 | with_clause select_clause
7399 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
7405 | with_clause select_clause sort_clause
7407 insertSelectOptions((SelectStmt *) $2, $3, NIL,
7413 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
7415 insertSelectOptions((SelectStmt *) $2, $3, $4,
7416 list_nth($5, 0), list_nth($5, 1),
7421 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
7423 insertSelectOptions((SelectStmt *) $2, $3, $5,
7424 list_nth($4, 0), list_nth($4, 1),
7432 simple_select { $$ = $1; }
7433 | select_with_parens { $$ = $1; }
7437 * This rule parses SELECT statements that can appear within set operations,
7438 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
7439 * the ordering of the set operations. Without '(' and ')' we want the
7440 * operations to be ordered per the precedence specs at the head of this file.
7442 * As with select_no_parens, simple_select cannot have outer parentheses,
7443 * but can have parenthesized subclauses.
7445 * Note that sort clauses cannot be included at this level --- SQL92 requires
7446 * SELECT foo UNION SELECT bar ORDER BY baz
7448 * (SELECT foo UNION SELECT bar) ORDER BY baz
7450 * SELECT foo UNION (SELECT bar ORDER BY baz)
7451 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
7452 * described as part of the select_no_parens production, not simple_select.
7453 * This does not limit functionality, because you can reintroduce these
7454 * clauses inside parentheses.
7456 * NOTE: only the leftmost component SelectStmt should have INTO.
7457 * However, this is not checked by the grammar; parse analysis must check it.
7460 SELECT opt_distinct target_list
7461 into_clause from_clause where_clause
7462 group_clause having_clause window_clause
7464 SelectStmt *n = makeNode(SelectStmt);
7465 n->distinctClause = $2;
7469 n->whereClause = $6;
7470 n->groupClause = $7;
7471 n->havingClause = $8;
7472 n->windowClause = $9;
7475 | values_clause { $$ = $1; }
7476 | TABLE relation_expr
7478 /* same as SELECT * FROM relation_expr */
7479 ColumnRef *cr = makeNode(ColumnRef);
7480 ResTarget *rt = makeNode(ResTarget);
7481 SelectStmt *n = makeNode(SelectStmt);
7483 cr->fields = list_make1(makeNode(A_Star));
7487 rt->indirection = NIL;
7488 rt->val = (Node *)cr;
7491 n->targetList = list_make1(rt);
7492 n->fromClause = list_make1($2);
7495 | select_clause UNION opt_all select_clause
7497 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
7499 | select_clause INTERSECT opt_all select_clause
7501 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
7503 | select_clause EXCEPT opt_all select_clause
7505 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
7510 * SQL standard WITH clause looks like:
7512 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
7513 * AS (query) [ SEARCH or CYCLE clause ]
7515 * We don't currently support the SEARCH or CYCLE clause.
7520 $$ = makeNode(WithClause);
7522 $$->recursive = false;
7525 | WITH RECURSIVE cte_list
7527 $$ = makeNode(WithClause);
7529 $$->recursive = true;
7535 common_table_expr { $$ = list_make1($1); }
7536 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
7539 common_table_expr: name opt_name_list AS select_with_parens
7541 CommonTableExpr *n = makeNode(CommonTableExpr);
7543 n->aliascolnames = $2;
7551 INTO OptTempTableName
7553 $$ = makeNode(IntoClause);
7557 $$->onCommit = ONCOMMIT_NOOP;
7558 $$->tableSpaceName = NULL;
7565 * Redundancy here is needed to avoid shift/reduce conflicts,
7566 * since TEMP is not a reserved word. See also OptTemp.
7569 TEMPORARY opt_table qualified_name
7574 | TEMP opt_table qualified_name
7579 | LOCAL TEMPORARY opt_table qualified_name
7584 | LOCAL TEMP opt_table qualified_name
7589 | GLOBAL TEMPORARY opt_table qualified_name
7594 | GLOBAL TEMP opt_table qualified_name
7599 | TABLE qualified_name
7615 opt_all: ALL { $$ = TRUE; }
7616 | DISTINCT { $$ = FALSE; }
7617 | /*EMPTY*/ { $$ = FALSE; }
7620 /* We use (NIL) as a placeholder to indicate that all target expressions
7621 * should be placed in the DISTINCT list during parsetree analysis.
7624 DISTINCT { $$ = list_make1(NIL); }
7625 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
7627 | /*EMPTY*/ { $$ = NIL; }
7631 sort_clause { $$ = $1;}
7632 | /*EMPTY*/ { $$ = NIL; }
7636 ORDER BY sortby_list { $$ = $3; }
7640 sortby { $$ = list_make1($1); }
7641 | sortby_list ',' sortby { $$ = lappend($1, $3); }
7644 sortby: a_expr USING qual_all_Op opt_nulls_order
7646 $$ = makeNode(SortBy);
7648 $$->sortby_dir = SORTBY_USING;
7649 $$->sortby_nulls = $4;
7653 | a_expr opt_asc_desc opt_nulls_order
7655 $$ = makeNode(SortBy);
7657 $$->sortby_dir = $2;
7658 $$->sortby_nulls = $3;
7660 $$->location = -1; /* no operator */
7666 limit_clause offset_clause { $$ = list_make2($2, $1); }
7667 | offset_clause limit_clause { $$ = list_make2($1, $2); }
7668 | limit_clause { $$ = list_make2(NULL, $1); }
7669 | offset_clause { $$ = list_make2($1, NULL); }
7673 select_limit { $$ = $1; }
7674 | /* EMPTY */ { $$ = list_make2(NULL,NULL); }
7678 LIMIT select_limit_value
7680 | LIMIT select_limit_value ',' select_offset_value
7682 /* Disabled because it was too confusing, bjm 2002-02-18 */
7684 (errcode(ERRCODE_SYNTAX_ERROR),
7685 errmsg("LIMIT #,# syntax is not supported"),
7686 errhint("Use separate LIMIT and OFFSET clauses."),
7687 parser_errposition(@1)));
7689 /* SQL:2008 syntax */
7690 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
7695 OFFSET select_offset_value
7697 /* SQL:2008 syntax */
7698 | OFFSET select_offset_value2 row_or_rows
7706 /* LIMIT ALL is represented as a NULL constant */
7707 $$ = makeNullAConst(@1);
7711 select_offset_value:
7716 * Allowing full expressions without parentheses causes various parsing
7717 * problems with the trailing ROW/ROWS key words. SQL only calls for
7718 * constants, so we allow the rest only with parentheses. If omitted,
7721 opt_select_fetch_first_value:
7722 SignedIconst { $$ = makeIntConst($1, @1); }
7723 | '(' a_expr ')' { $$ = $2; }
7724 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
7728 * Again, the trailing ROW/ROWS in this case prevent the full expression
7729 * syntax. c_expr is the best we can do.
7731 select_offset_value2:
7736 row_or_rows: ROW { $$ = 0; }
7740 first_or_next: FIRST_P { $$ = 0; }
7746 GROUP_P BY expr_list { $$ = $3; }
7747 | /*EMPTY*/ { $$ = NIL; }
7751 HAVING a_expr { $$ = $2; }
7752 | /*EMPTY*/ { $$ = NULL; }
7756 for_locking_items { $$ = $1; }
7757 | FOR READ ONLY { $$ = NIL; }
7760 opt_for_locking_clause:
7761 for_locking_clause { $$ = $1; }
7762 | /* EMPTY */ { $$ = NIL; }
7766 for_locking_item { $$ = list_make1($1); }
7767 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
7771 FOR UPDATE locked_rels_list opt_nowait
7773 LockingClause *n = makeNode(LockingClause);
7775 n->forUpdate = TRUE;
7779 | FOR SHARE locked_rels_list opt_nowait
7781 LockingClause *n = makeNode(LockingClause);
7783 n->forUpdate = FALSE;
7790 OF qualified_name_list { $$ = $2; }
7791 | /* EMPTY */ { $$ = NIL; }
7798 SelectStmt *n = makeNode(SelectStmt);
7799 n->valuesLists = list_make1($2);
7802 | values_clause ',' ctext_row
7804 SelectStmt *n = (SelectStmt *) $1;
7805 n->valuesLists = lappend(n->valuesLists, $3);
7811 /*****************************************************************************
7813 * clauses common to all Optimizable Stmts:
7814 * from_clause - allow list of both JOIN expressions and table names
7815 * where_clause - qualifications for joins or restrictions
7817 *****************************************************************************/
7820 FROM from_list { $$ = $2; }
7821 | /*EMPTY*/ { $$ = NIL; }
7825 table_ref { $$ = list_make1($1); }
7826 | from_list ',' table_ref { $$ = lappend($1, $3); }
7830 * table_ref is where an alias clause can be attached. Note we cannot make
7831 * alias_clause have an empty production because that causes parse conflicts
7832 * between table_ref := '(' joined_table ')' alias_clause
7833 * and joined_table := '(' joined_table ')'. So, we must have the
7834 * redundant-looking productions here instead.
7836 table_ref: relation_expr
7840 | relation_expr alias_clause
7847 RangeFunction *n = makeNode(RangeFunction);
7848 n->funccallnode = $1;
7849 n->coldeflist = NIL;
7852 | func_table alias_clause
7854 RangeFunction *n = makeNode(RangeFunction);
7855 n->funccallnode = $1;
7857 n->coldeflist = NIL;
7860 | func_table AS '(' TableFuncElementList ')'
7862 RangeFunction *n = makeNode(RangeFunction);
7863 n->funccallnode = $1;
7867 | func_table AS ColId '(' TableFuncElementList ')'
7869 RangeFunction *n = makeNode(RangeFunction);
7870 Alias *a = makeNode(Alias);
7871 n->funccallnode = $1;
7877 | func_table ColId '(' TableFuncElementList ')'
7879 RangeFunction *n = makeNode(RangeFunction);
7880 Alias *a = makeNode(Alias);
7881 n->funccallnode = $1;
7887 | select_with_parens
7890 * The SQL spec does not permit a subselect
7891 * (<derived_table>) without an alias clause,
7892 * so we don't either. This avoids the problem
7893 * of needing to invent a unique refname for it.
7894 * That could be surmounted if there's sufficient
7895 * popular demand, but for now let's just implement
7896 * the spec and see if anyone complains.
7897 * However, it does seem like a good idea to emit
7898 * an error message that's better than "syntax error".
7900 if (IsA($1, SelectStmt) &&
7901 ((SelectStmt *) $1)->valuesLists)
7903 (errcode(ERRCODE_SYNTAX_ERROR),
7904 errmsg("VALUES in FROM must have an alias"),
7905 errhint("For example, FROM (VALUES ...) [AS] foo."),
7906 parser_errposition(@1)));
7909 (errcode(ERRCODE_SYNTAX_ERROR),
7910 errmsg("subquery in FROM must have an alias"),
7911 errhint("For example, FROM (SELECT ...) [AS] foo."),
7912 parser_errposition(@1)));
7915 | select_with_parens alias_clause
7917 RangeSubselect *n = makeNode(RangeSubselect);
7926 | '(' joined_table ')' alias_clause
7935 * It may seem silly to separate joined_table from table_ref, but there is
7936 * method in SQL92's madness: if you don't do it this way you get reduce-
7937 * reduce conflicts, because it's not clear to the parser generator whether
7938 * to expect alias_clause after ')' or not. For the same reason we must
7939 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
7940 * join_type to expand to empty; if we try it, the parser generator can't
7941 * figure out when to reduce an empty join_type right after table_ref.
7943 * Note that a CROSS JOIN is the same as an unqualified
7944 * INNER JOIN, and an INNER JOIN/ON has the same shape
7945 * but a qualification expression to limit membership.
7946 * A NATURAL JOIN implicitly matches column names between
7947 * tables and the shape is determined by which columns are
7948 * in common. We'll collect columns during the later transformations.
7952 '(' joined_table ')'
7956 | table_ref CROSS JOIN table_ref
7958 /* CROSS JOIN is same as unqualified inner join */
7959 JoinExpr *n = makeNode(JoinExpr);
7960 n->jointype = JOIN_INNER;
7961 n->isNatural = FALSE;
7964 n->usingClause = NIL;
7968 | table_ref join_type JOIN table_ref join_qual
7970 JoinExpr *n = makeNode(JoinExpr);
7972 n->isNatural = FALSE;
7975 if ($5 != NULL && IsA($5, List))
7976 n->usingClause = (List *) $5; /* USING clause */
7978 n->quals = $5; /* ON clause */
7981 | table_ref JOIN table_ref join_qual
7983 /* letting join_type reduce to empty doesn't work */
7984 JoinExpr *n = makeNode(JoinExpr);
7985 n->jointype = JOIN_INNER;
7986 n->isNatural = FALSE;
7989 if ($4 != NULL && IsA($4, List))
7990 n->usingClause = (List *) $4; /* USING clause */
7992 n->quals = $4; /* ON clause */
7995 | table_ref NATURAL join_type JOIN table_ref
7997 JoinExpr *n = makeNode(JoinExpr);
7999 n->isNatural = TRUE;
8002 n->usingClause = NIL; /* figure out which columns later... */
8003 n->quals = NULL; /* fill later */
8006 | table_ref NATURAL JOIN table_ref
8008 /* letting join_type reduce to empty doesn't work */
8009 JoinExpr *n = makeNode(JoinExpr);
8010 n->jointype = JOIN_INNER;
8011 n->isNatural = TRUE;
8014 n->usingClause = NIL; /* figure out which columns later... */
8015 n->quals = NULL; /* fill later */
8021 AS ColId '(' name_list ')'
8023 $$ = makeNode(Alias);
8029 $$ = makeNode(Alias);
8032 | ColId '(' name_list ')'
8034 $$ = makeNode(Alias);
8040 $$ = makeNode(Alias);
8045 join_type: FULL join_outer { $$ = JOIN_FULL; }
8046 | LEFT join_outer { $$ = JOIN_LEFT; }
8047 | RIGHT join_outer { $$ = JOIN_RIGHT; }
8048 | INNER_P { $$ = JOIN_INNER; }
8051 /* OUTER is just noise... */
8052 join_outer: OUTER_P { $$ = NULL; }
8053 | /*EMPTY*/ { $$ = NULL; }
8056 /* JOIN qualification clauses
8057 * Possibilities are:
8058 * USING ( column list ) allows only unqualified column names,
8059 * which must match between tables.
8060 * ON expr allows more general qualifications.
8062 * We return USING as a List node, while an ON-expr will not be a List.
8065 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
8066 | ON a_expr { $$ = $2; }
8073 /* default inheritance */
8075 $$->inhOpt = INH_DEFAULT;
8078 | qualified_name '*'
8080 /* inheritance query */
8082 $$->inhOpt = INH_YES;
8085 | ONLY qualified_name
8087 /* no inheritance */
8089 $$->inhOpt = INH_NO;
8092 | ONLY '(' qualified_name ')'
8094 /* no inheritance, SQL99-style syntax */
8096 $$->inhOpt = INH_NO;
8103 relation_expr { $$ = list_make1($1); }
8104 | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
8109 * Given "UPDATE foo set set ...", we have to decide without looking any
8110 * further ahead whether the first "set" is an alias or the UPDATE's SET
8111 * keyword. Since "set" is allowed as a column name both interpretations
8112 * are feasible. We resolve the shift/reduce conflict by giving the first
8113 * relation_expr_opt_alias production a higher precedence than the SET token
8114 * has, causing the parser to prefer to reduce, in effect assuming that the
8115 * SET is not an alias.
8117 relation_expr_opt_alias: relation_expr %prec UMINUS
8121 | relation_expr ColId
8123 Alias *alias = makeNode(Alias);
8124 alias->aliasname = $2;
8128 | relation_expr AS ColId
8130 Alias *alias = makeNode(Alias);
8131 alias->aliasname = $3;
8138 func_table: func_expr { $$ = $1; }
8143 WHERE a_expr { $$ = $2; }
8144 | /*EMPTY*/ { $$ = NULL; }
8147 /* variant for UPDATE and DELETE */
8148 where_or_current_clause:
8149 WHERE a_expr { $$ = $2; }
8150 | WHERE CURRENT_P OF name
8152 CurrentOfExpr *n = makeNode(CurrentOfExpr);
8153 /* cvarno is filled in by parse analysis */
8154 n->cursor_name = $4;
8155 n->cursor_param = 0;
8158 | /*EMPTY*/ { $$ = NULL; }
8162 TableFuncElementList:
8165 $$ = list_make1($1);
8167 | TableFuncElementList ',' TableFuncElement
8169 $$ = lappend($1, $3);
8173 TableFuncElement: ColId Typename
8175 ColumnDef *n = makeNode(ColumnDef);
8178 n->constraints = NIL;
8184 /*****************************************************************************
8187 * SQL92 introduces a large amount of type-specific syntax.
8188 * Define individual clauses to handle these cases, and use
8189 * the generic case to handle regular type-extensible Postgres syntax.
8190 * - thomas 1997-10-10
8192 *****************************************************************************/
8194 Typename: SimpleTypename opt_array_bounds
8197 $$->arrayBounds = $2;
8199 | SETOF SimpleTypename opt_array_bounds
8202 $$->arrayBounds = $3;
8205 /* SQL standard syntax, currently only one-dimensional */
8206 | SimpleTypename ARRAY '[' Iconst ']'
8209 $$->arrayBounds = list_make1(makeInteger($4));
8211 | SETOF SimpleTypename ARRAY '[' Iconst ']'
8214 $$->arrayBounds = list_make1(makeInteger($5));
8217 | SimpleTypename ARRAY
8220 $$->arrayBounds = list_make1(makeInteger(-1));
8222 | SETOF SimpleTypename ARRAY
8225 $$->arrayBounds = list_make1(makeInteger(-1));
8231 opt_array_bounds '[' ']'
8232 { $$ = lappend($1, makeInteger(-1)); }
8233 | opt_array_bounds '[' Iconst ']'
8234 { $$ = lappend($1, makeInteger($3)); }
8240 GenericType { $$ = $1; }
8241 | Numeric { $$ = $1; }
8243 | Character { $$ = $1; }
8244 | ConstDatetime { $$ = $1; }
8245 | ConstInterval opt_interval
8250 | ConstInterval '(' Iconst ')' opt_interval
8255 if (list_length($5) != 1)
8257 (errcode(ERRCODE_SYNTAX_ERROR),
8258 errmsg("interval precision specified twice"),
8259 parser_errposition(@1)));
8260 $$->typmods = lappend($5, makeIntConst($3, @3));
8263 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
8264 makeIntConst($3, @3));
8268 /* We have a separate ConstTypename to allow defaulting fixed-length
8269 * types such as CHAR() and BIT() to an unspecified length.
8270 * SQL9x requires that these default to a length of one, but this
8271 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
8272 * where there is an obvious better choice to make.
8273 * Note that ConstInterval is not included here since it must
8274 * be pushed up higher in the rules to accomodate the postfix
8275 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
8276 * the generic-type-name case in AExprConst to avoid premature
8277 * reduce/reduce conflicts against function names.
8280 Numeric { $$ = $1; }
8281 | ConstBit { $$ = $1; }
8282 | ConstCharacter { $$ = $1; }
8283 | ConstDatetime { $$ = $1; }
8287 * GenericType covers all type names that don't have special syntax mandated
8288 * by the standard, including qualified names. We also allow type modifiers.
8289 * To avoid parsing conflicts against function invocations, the modifiers
8290 * have to be shown as expr_list here, but parse analysis will only accept
8291 * constants for them.
8294 type_function_name opt_type_modifiers
8296 $$ = makeTypeName($1);
8300 | type_function_name attrs opt_type_modifiers
8302 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8308 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
8309 | /* EMPTY */ { $$ = NIL; }
8313 * SQL92 numeric data types
8317 $$ = SystemTypeName("int4");
8322 $$ = SystemTypeName("int4");
8327 $$ = SystemTypeName("int2");
8332 $$ = SystemTypeName("int8");
8337 $$ = SystemTypeName("float4");
8345 | DOUBLE_P PRECISION
8347 $$ = SystemTypeName("float8");
8350 | DECIMAL_P opt_type_modifiers
8352 $$ = SystemTypeName("numeric");
8356 | DEC opt_type_modifiers
8358 $$ = SystemTypeName("numeric");
8362 | NUMERIC opt_type_modifiers
8364 $$ = SystemTypeName("numeric");
8370 $$ = SystemTypeName("bool");
8375 opt_float: '(' Iconst ')'
8378 * Check FLOAT() precision limits assuming IEEE floating
8379 * types - thomas 1997-09-18
8383 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8384 errmsg("precision for type float must be at least 1 bit"),
8385 parser_errposition(@2)));
8387 $$ = SystemTypeName("float4");
8389 $$ = SystemTypeName("float8");
8392 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8393 errmsg("precision for type float must be less than 54 bits"),
8394 parser_errposition(@2)));
8398 $$ = SystemTypeName("float8");
8403 * SQL92 bit-field data types
8404 * The following implements BIT() and BIT VARYING().
8416 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
8417 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
8418 ConstBit: BitWithLength
8430 BIT opt_varying '(' expr_list ')'
8434 typname = $2 ? "varbit" : "bit";
8435 $$ = SystemTypeName(typname);
8444 /* bit defaults to bit(1), varbit to no limit */
8447 $$ = SystemTypeName("varbit");
8451 $$ = SystemTypeName("bit");
8452 $$->typmods = list_make1(makeIntConst(1, -1));
8460 * SQL92 character data types
8461 * The following implements CHAR() and VARCHAR().
8463 Character: CharacterWithLength
8467 | CharacterWithoutLength
8473 ConstCharacter: CharacterWithLength
8477 | CharacterWithoutLength
8479 /* Length was not specified so allow to be unrestricted.
8480 * This handles problems with fixed-length (bpchar) strings
8481 * which in column definitions must default to a length
8482 * of one, but should not be constrained if the length
8483 * was not specified.
8490 CharacterWithLength: character '(' Iconst ')' opt_charset
8492 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
8496 type = palloc(strlen($1) + 1 + strlen($5) + 1);
8503 $$ = SystemTypeName($1);
8504 $$->typmods = list_make1(makeIntConst($3, @3));
8509 CharacterWithoutLength: character opt_charset
8511 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
8515 type = palloc(strlen($1) + 1 + strlen($2) + 1);
8522 $$ = SystemTypeName($1);
8524 /* char defaults to char(1), varchar to no limit */
8525 if (strcmp($1, "bpchar") == 0)
8526 $$->typmods = list_make1(makeIntConst(1, -1));
8532 character: CHARACTER opt_varying
8533 { $$ = $2 ? "varchar": "bpchar"; }
8534 | CHAR_P opt_varying
8535 { $$ = $2 ? "varchar": "bpchar"; }
8538 | NATIONAL CHARACTER opt_varying
8539 { $$ = $3 ? "varchar": "bpchar"; }
8540 | NATIONAL CHAR_P opt_varying
8541 { $$ = $3 ? "varchar": "bpchar"; }
8543 { $$ = $2 ? "varchar": "bpchar"; }
8547 VARYING { $$ = TRUE; }
8548 | /*EMPTY*/ { $$ = FALSE; }
8552 CHARACTER SET ColId { $$ = $3; }
8553 | /*EMPTY*/ { $$ = NULL; }
8557 * SQL92 date/time types
8560 TIMESTAMP '(' Iconst ')' opt_timezone
8563 $$ = SystemTypeName("timestamptz");
8565 $$ = SystemTypeName("timestamp");
8566 $$->typmods = list_make1(makeIntConst($3, @3));
8569 | TIMESTAMP opt_timezone
8572 $$ = SystemTypeName("timestamptz");
8574 $$ = SystemTypeName("timestamp");
8577 | TIME '(' Iconst ')' opt_timezone
8580 $$ = SystemTypeName("timetz");
8582 $$ = SystemTypeName("time");
8583 $$->typmods = list_make1(makeIntConst($3, @3));
8589 $$ = SystemTypeName("timetz");
8591 $$ = SystemTypeName("time");
8599 $$ = SystemTypeName("interval");
8605 WITH_TIME ZONE { $$ = TRUE; }
8606 | WITHOUT TIME ZONE { $$ = FALSE; }
8607 | /*EMPTY*/ { $$ = FALSE; }
8612 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
8614 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
8616 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
8618 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
8620 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
8625 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
8626 INTERVAL_MASK(MONTH), @1));
8630 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8631 INTERVAL_MASK(HOUR), @1));
8635 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8636 INTERVAL_MASK(HOUR) |
8637 INTERVAL_MASK(MINUTE), @1));
8639 | DAY_P TO interval_second
8642 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
8643 INTERVAL_MASK(HOUR) |
8644 INTERVAL_MASK(MINUTE) |
8645 INTERVAL_MASK(SECOND), @1);
8647 | HOUR_P TO MINUTE_P
8649 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
8650 INTERVAL_MASK(MINUTE), @1));
8652 | HOUR_P TO interval_second
8655 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
8656 INTERVAL_MASK(MINUTE) |
8657 INTERVAL_MASK(SECOND), @1);
8659 | MINUTE_P TO interval_second
8662 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
8663 INTERVAL_MASK(SECOND), @1);
8672 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
8674 | SECOND_P '(' Iconst ')'
8676 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
8677 makeIntConst($3, @3));
8682 /*****************************************************************************
8684 * expression grammar
8686 *****************************************************************************/
8689 * General expressions
8690 * This is the heart of the expression syntax.
8692 * We have two expression types: a_expr is the unrestricted kind, and
8693 * b_expr is a subset that must be used in some places to avoid shift/reduce
8694 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
8695 * because that use of AND conflicts with AND as a boolean operator. So,
8696 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
8698 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
8699 * always be used by surrounding it with parens.
8701 * c_expr is all the productions that are common to a_expr and b_expr;
8702 * it's factored out just to eliminate redundant coding.
8704 a_expr: c_expr { $$ = $1; }
8705 | a_expr TYPECAST Typename
8706 { $$ = makeTypeCast($1, $3, @2); }
8707 | a_expr AT TIME ZONE a_expr
8709 FuncCall *n = makeNode(FuncCall);
8710 n->funcname = SystemFuncName("timezone");
8711 n->args = list_make2($5, $1);
8713 n->agg_star = FALSE;
8714 n->agg_distinct = FALSE;
8715 n->func_variadic = FALSE;
8721 * These operators must be called out explicitly in order to make use
8722 * of bison's automatic operator-precedence handling. All other
8723 * operator names are handled by the generic productions using "Op",
8724 * below; and all those operators will have the same precedence.
8726 * If you add more explicitly-known operators, be sure to add them
8727 * also to b_expr and to the MathOp list above.
8729 | '+' a_expr %prec UMINUS
8730 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
8731 | '-' a_expr %prec UMINUS
8732 { $$ = doNegate($2, @1); }
8734 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
8736 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
8738 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
8740 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
8742 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
8744 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
8746 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
8748 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
8750 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
8752 | a_expr qual_Op a_expr %prec Op
8753 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
8754 | qual_Op a_expr %prec Op
8755 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
8756 | a_expr qual_Op %prec POSTFIXOP
8757 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
8760 { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
8762 { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
8764 { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
8766 | a_expr LIKE a_expr
8767 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
8768 | a_expr LIKE a_expr ESCAPE a_expr
8770 FuncCall *n = makeNode(FuncCall);
8771 n->funcname = SystemFuncName("like_escape");
8772 n->args = list_make2($3, $5);
8774 n->agg_star = FALSE;
8775 n->agg_distinct = FALSE;
8776 n->func_variadic = FALSE;
8779 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
8781 | a_expr NOT LIKE a_expr
8782 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
8783 | a_expr NOT LIKE a_expr ESCAPE a_expr
8785 FuncCall *n = makeNode(FuncCall);
8786 n->funcname = SystemFuncName("like_escape");
8787 n->args = list_make2($4, $6);
8789 n->agg_star = FALSE;
8790 n->agg_distinct = FALSE;
8791 n->func_variadic = FALSE;
8794 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
8796 | a_expr ILIKE a_expr
8797 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
8798 | a_expr ILIKE a_expr ESCAPE a_expr
8800 FuncCall *n = makeNode(FuncCall);
8801 n->funcname = SystemFuncName("like_escape");
8802 n->args = list_make2($3, $5);
8804 n->agg_star = FALSE;
8805 n->agg_distinct = FALSE;
8806 n->func_variadic = FALSE;
8809 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n, @2);
8811 | a_expr NOT ILIKE a_expr
8812 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
8813 | a_expr NOT ILIKE a_expr ESCAPE a_expr
8815 FuncCall *n = makeNode(FuncCall);
8816 n->funcname = SystemFuncName("like_escape");
8817 n->args = list_make2($4, $6);
8819 n->agg_star = FALSE;
8820 n->agg_distinct = FALSE;
8821 n->func_variadic = FALSE;
8824 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n, @2);
8827 | a_expr SIMILAR TO a_expr %prec SIMILAR
8829 FuncCall *n = makeNode(FuncCall);
8830 n->funcname = SystemFuncName("similar_escape");
8831 n->args = list_make2($4, makeNullAConst(-1));
8833 n->agg_star = FALSE;
8834 n->agg_distinct = FALSE;
8835 n->func_variadic = FALSE;
8838 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8840 | a_expr SIMILAR TO a_expr ESCAPE a_expr
8842 FuncCall *n = makeNode(FuncCall);
8843 n->funcname = SystemFuncName("similar_escape");
8844 n->args = list_make2($4, $6);
8846 n->agg_star = FALSE;
8847 n->agg_distinct = FALSE;
8848 n->func_variadic = FALSE;
8851 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8853 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
8855 FuncCall *n = makeNode(FuncCall);
8856 n->funcname = SystemFuncName("similar_escape");
8857 n->args = list_make2($5, makeNullAConst(-1));
8859 n->agg_star = FALSE;
8860 n->agg_distinct = FALSE;
8861 n->func_variadic = FALSE;
8864 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8866 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
8868 FuncCall *n = makeNode(FuncCall);
8869 n->funcname = SystemFuncName("similar_escape");
8870 n->args = list_make2($5, $7);
8872 n->agg_star = FALSE;
8873 n->agg_distinct = FALSE;
8874 n->func_variadic = FALSE;
8877 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8881 * Define SQL92-style Null test clause.
8882 * Allow two forms described in the standard:
8885 * Allow two SQL extensions
8891 NullTest *n = makeNode(NullTest);
8892 n->arg = (Expr *) $1;
8893 n->nulltesttype = IS_NULL;
8898 NullTest *n = makeNode(NullTest);
8899 n->arg = (Expr *) $1;
8900 n->nulltesttype = IS_NULL;
8903 | a_expr IS NOT NULL_P
8905 NullTest *n = makeNode(NullTest);
8906 n->arg = (Expr *) $1;
8907 n->nulltesttype = IS_NOT_NULL;
8912 NullTest *n = makeNode(NullTest);
8913 n->arg = (Expr *) $1;
8914 n->nulltesttype = IS_NOT_NULL;
8919 $$ = (Node *)makeOverlaps($1, $3, @2, yyscanner);
8923 BooleanTest *b = makeNode(BooleanTest);
8924 b->arg = (Expr *) $1;
8925 b->booltesttype = IS_TRUE;
8928 | a_expr IS NOT TRUE_P
8930 BooleanTest *b = makeNode(BooleanTest);
8931 b->arg = (Expr *) $1;
8932 b->booltesttype = IS_NOT_TRUE;
8937 BooleanTest *b = makeNode(BooleanTest);
8938 b->arg = (Expr *) $1;
8939 b->booltesttype = IS_FALSE;
8942 | a_expr IS NOT FALSE_P
8944 BooleanTest *b = makeNode(BooleanTest);
8945 b->arg = (Expr *) $1;
8946 b->booltesttype = IS_NOT_FALSE;
8951 BooleanTest *b = makeNode(BooleanTest);
8952 b->arg = (Expr *) $1;
8953 b->booltesttype = IS_UNKNOWN;
8956 | a_expr IS NOT UNKNOWN
8958 BooleanTest *b = makeNode(BooleanTest);
8959 b->arg = (Expr *) $1;
8960 b->booltesttype = IS_NOT_UNKNOWN;
8963 | a_expr IS DISTINCT FROM a_expr %prec IS
8965 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
8967 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
8969 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8970 (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
8975 | a_expr IS OF '(' type_list ')' %prec IS
8977 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
8979 | a_expr IS NOT OF '(' type_list ')' %prec IS
8981 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
8984 * Ideally we would not use hard-wired operators below but
8985 * instead use opclasses. However, mixed data types and other
8986 * issues make this difficult:
8987 * http://archives.postgresql.org/pgsql-hackers/2008-08/msg01142.php
8989 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
8991 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
8992 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
8993 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
8996 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
8998 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
8999 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
9000 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
9003 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
9005 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
9006 (Node *) makeA_Expr(AEXPR_AND, NIL,
9007 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
9008 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
9010 (Node *) makeA_Expr(AEXPR_AND, NIL,
9011 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
9012 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
9016 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
9018 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
9019 (Node *) makeA_Expr(AEXPR_OR, NIL,
9020 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
9021 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
9023 (Node *) makeA_Expr(AEXPR_OR, NIL,
9024 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
9025 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
9029 | a_expr IN_P in_expr
9031 /* in_expr returns a SubLink or a list of a_exprs */
9032 if (IsA($3, SubLink))
9034 /* generate foo = ANY (subquery) */
9035 SubLink *n = (SubLink *) $3;
9036 n->subLinkType = ANY_SUBLINK;
9038 n->operName = list_make1(makeString("="));
9044 /* generate scalar IN expression */
9045 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
9048 | a_expr NOT IN_P in_expr
9050 /* in_expr returns a SubLink or a list of a_exprs */
9051 if (IsA($4, SubLink))
9053 /* generate NOT (foo = ANY (subquery)) */
9054 /* Make an = ANY node */
9055 SubLink *n = (SubLink *) $4;
9056 n->subLinkType = ANY_SUBLINK;
9058 n->operName = list_make1(makeString("="));
9060 /* Stick a NOT on top */
9061 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
9065 /* generate scalar NOT IN expression */
9066 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
9069 | a_expr subquery_Op sub_type select_with_parens %prec Op
9071 SubLink *n = makeNode(SubLink);
9072 n->subLinkType = $3;
9079 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
9081 if ($3 == ANY_SUBLINK)
9082 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
9084 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
9086 | UNIQUE select_with_parens
9088 /* Not sure how to get rid of the parentheses
9089 * but there are lots of shift/reduce errors without them.
9091 * Should be able to implement this by plopping the entire
9092 * select into a node, then transforming the target expressions
9093 * from whatever they are into count(*), and testing the
9094 * entire result equal to one.
9095 * But, will probably implement a separate node in the executor.
9098 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9099 errmsg("UNIQUE predicate is not yet implemented"),
9100 parser_errposition(@1)));
9102 | a_expr IS DOCUMENT_P %prec IS
9104 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9105 list_make1($1), @2);
9107 | a_expr IS NOT DOCUMENT_P %prec IS
9109 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9110 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9111 list_make1($1), @2),
9117 * Restricted expressions
9119 * b_expr is a subset of the complete expression syntax defined by a_expr.
9121 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
9122 * cause trouble in the places where b_expr is used. For simplicity, we
9123 * just eliminate all the boolean-keyword-operator productions from b_expr.
9127 | b_expr TYPECAST Typename
9128 { $$ = makeTypeCast($1, $3, @2); }
9129 | '+' b_expr %prec UMINUS
9130 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
9131 | '-' b_expr %prec UMINUS
9132 { $$ = doNegate($2, @1); }
9134 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
9136 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
9138 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
9140 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
9142 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
9144 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
9146 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
9148 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
9150 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
9151 | b_expr qual_Op b_expr %prec Op
9152 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
9153 | qual_Op b_expr %prec Op
9154 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
9155 | b_expr qual_Op %prec POSTFIXOP
9156 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
9157 | b_expr IS DISTINCT FROM b_expr %prec IS
9159 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
9161 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
9163 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
9164 NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
9166 | b_expr IS OF '(' type_list ')' %prec IS
9168 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
9170 | b_expr IS NOT OF '(' type_list ')' %prec IS
9172 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
9174 | b_expr IS DOCUMENT_P %prec IS
9176 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9177 list_make1($1), @2);
9179 | b_expr IS NOT DOCUMENT_P %prec IS
9181 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9182 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9183 list_make1($1), @2),
9189 * Productions that can be used in both a_expr and b_expr.
9191 * Note: productions that refer recursively to a_expr or b_expr mostly
9192 * cannot appear here. However, it's OK to refer to a_exprs that occur
9193 * inside parentheses, such as function arguments; that cannot introduce
9194 * ambiguity to the b_expr syntax.
9196 c_expr: columnref { $$ = $1; }
9197 | AexprConst { $$ = $1; }
9198 | PARAM opt_indirection
9200 ParamRef *p = makeNode(ParamRef);
9205 A_Indirection *n = makeNode(A_Indirection);
9206 n->arg = (Node *) p;
9207 n->indirection = check_indirection($2, yyscanner);
9213 | '(' a_expr ')' opt_indirection
9217 A_Indirection *n = makeNode(A_Indirection);
9219 n->indirection = check_indirection($4, yyscanner);
9229 | select_with_parens %prec UMINUS
9231 SubLink *n = makeNode(SubLink);
9232 n->subLinkType = EXPR_SUBLINK;
9239 | EXISTS select_with_parens
9241 SubLink *n = makeNode(SubLink);
9242 n->subLinkType = EXISTS_SUBLINK;
9249 | ARRAY select_with_parens
9251 SubLink *n = makeNode(SubLink);
9252 n->subLinkType = ARRAY_SUBLINK;
9261 A_ArrayExpr *n = (A_ArrayExpr *) $2;
9262 Assert(IsA(n, A_ArrayExpr));
9263 /* point outermost A_ArrayExpr to the ARRAY keyword */
9269 RowExpr *r = makeNode(RowExpr);
9271 r->row_typeid = InvalidOid; /* not analyzed yet */
9278 * func_expr is split out from c_expr just so that we have a classification
9279 * for "everything that is a function call or looks like one". This isn't
9280 * very important, but it saves us having to document which variants are
9281 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
9282 * (Note that many of the special SQL functions wouldn't actually make any
9283 * sense as functional index entries, but we ignore that consideration here.)
9285 func_expr: func_name '(' ')' over_clause
9287 FuncCall *n = makeNode(FuncCall);
9291 n->agg_star = FALSE;
9292 n->agg_distinct = FALSE;
9293 n->func_variadic = FALSE;
9298 | func_name '(' func_arg_list ')' over_clause
9300 FuncCall *n = makeNode(FuncCall);
9304 n->agg_star = FALSE;
9305 n->agg_distinct = FALSE;
9306 n->func_variadic = FALSE;
9311 | func_name '(' VARIADIC func_arg_expr ')' over_clause
9313 FuncCall *n = makeNode(FuncCall);
9315 n->args = list_make1($4);
9317 n->agg_star = FALSE;
9318 n->agg_distinct = FALSE;
9319 n->func_variadic = TRUE;
9324 | func_name '(' func_arg_list ',' VARIADIC func_arg_expr ')' over_clause
9326 FuncCall *n = makeNode(FuncCall);
9328 n->args = lappend($3, $6);
9330 n->agg_star = FALSE;
9331 n->agg_distinct = FALSE;
9332 n->func_variadic = TRUE;
9337 | func_name '(' func_arg_list sort_clause ')' over_clause
9339 FuncCall *n = makeNode(FuncCall);
9343 n->agg_star = FALSE;
9344 n->agg_distinct = FALSE;
9345 n->func_variadic = FALSE;
9350 | func_name '(' ALL func_arg_list opt_sort_clause ')' over_clause
9352 FuncCall *n = makeNode(FuncCall);
9356 n->agg_star = FALSE;
9357 n->agg_distinct = FALSE;
9358 /* Ideally we'd mark the FuncCall node to indicate
9359 * "must be an aggregate", but there's no provision
9360 * for that in FuncCall at the moment.
9362 n->func_variadic = FALSE;
9367 | func_name '(' DISTINCT func_arg_list opt_sort_clause ')' over_clause
9369 FuncCall *n = makeNode(FuncCall);
9373 n->agg_star = FALSE;
9374 n->agg_distinct = TRUE;
9375 n->func_variadic = FALSE;
9380 | func_name '(' '*' ')' over_clause
9383 * We consider AGGREGATE(*) to invoke a parameterless
9384 * aggregate. This does the right thing for COUNT(*),
9385 * and there are no other aggregates in SQL92 that accept
9388 * The FuncCall node is also marked agg_star = true,
9389 * so that later processing can detect what the argument
9392 FuncCall *n = makeNode(FuncCall);
9397 n->agg_distinct = FALSE;
9398 n->func_variadic = FALSE;
9406 * Translate as "'now'::text::date".
9408 * We cannot use "'now'::date" because coerce_type() will
9409 * immediately reduce that to a constant representing
9410 * today's date. We need to delay the conversion until
9411 * runtime, else the wrong things will happen when
9412 * CURRENT_DATE is used in a column default value or rule.
9414 * This could be simplified if we had a way to generate
9415 * an expression tree representing runtime application
9416 * of type-input conversion functions. (As of PG 7.3
9417 * that is actually possible, but not clear that we want
9421 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9422 $$ = makeTypeCast(n, SystemTypeName("date"), -1);
9427 * Translate as "'now'::text::timetz".
9428 * See comments for CURRENT_DATE.
9431 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9432 $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
9434 | CURRENT_TIME '(' Iconst ')'
9437 * Translate as "'now'::text::timetz(n)".
9438 * See comments for CURRENT_DATE.
9442 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9443 d = SystemTypeName("timetz");
9444 d->typmods = list_make1(makeIntConst($3, @3));
9445 $$ = makeTypeCast(n, d, -1);
9450 * Translate as "now()", since we have a function that
9451 * does exactly what is needed.
9453 FuncCall *n = makeNode(FuncCall);
9454 n->funcname = SystemFuncName("now");
9457 n->agg_star = FALSE;
9458 n->agg_distinct = FALSE;
9459 n->func_variadic = FALSE;
9464 | CURRENT_TIMESTAMP '(' Iconst ')'
9467 * Translate as "'now'::text::timestamptz(n)".
9468 * See comments for CURRENT_DATE.
9472 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9473 d = SystemTypeName("timestamptz");
9474 d->typmods = list_make1(makeIntConst($3, @3));
9475 $$ = makeTypeCast(n, d, -1);
9480 * Translate as "'now'::text::time".
9481 * See comments for CURRENT_DATE.
9484 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9485 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
9487 | LOCALTIME '(' Iconst ')'
9490 * Translate as "'now'::text::time(n)".
9491 * See comments for CURRENT_DATE.
9495 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9496 d = SystemTypeName("time");
9497 d->typmods = list_make1(makeIntConst($3, @3));
9498 $$ = makeTypeCast((Node *)n, d, -1);
9503 * Translate as "'now'::text::timestamp".
9504 * See comments for CURRENT_DATE.
9507 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9508 $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
9510 | LOCALTIMESTAMP '(' Iconst ')'
9513 * Translate as "'now'::text::timestamp(n)".
9514 * See comments for CURRENT_DATE.
9518 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9519 d = SystemTypeName("timestamp");
9520 d->typmods = list_make1(makeIntConst($3, @3));
9521 $$ = makeTypeCast(n, d, -1);
9525 FuncCall *n = makeNode(FuncCall);
9526 n->funcname = SystemFuncName("current_user");
9529 n->agg_star = FALSE;
9530 n->agg_distinct = FALSE;
9531 n->func_variadic = FALSE;
9538 FuncCall *n = makeNode(FuncCall);
9539 n->funcname = SystemFuncName("current_user");
9542 n->agg_star = FALSE;
9543 n->agg_distinct = FALSE;
9544 n->func_variadic = FALSE;
9551 FuncCall *n = makeNode(FuncCall);
9552 n->funcname = SystemFuncName("session_user");
9555 n->agg_star = FALSE;
9556 n->agg_distinct = FALSE;
9557 n->func_variadic = FALSE;
9564 FuncCall *n = makeNode(FuncCall);
9565 n->funcname = SystemFuncName("current_user");
9568 n->agg_star = FALSE;
9569 n->agg_distinct = FALSE;
9570 n->func_variadic = FALSE;
9577 FuncCall *n = makeNode(FuncCall);
9578 n->funcname = SystemFuncName("current_database");
9581 n->agg_star = FALSE;
9582 n->agg_distinct = FALSE;
9583 n->func_variadic = FALSE;
9590 FuncCall *n = makeNode(FuncCall);
9591 n->funcname = SystemFuncName("current_schema");
9594 n->agg_star = FALSE;
9595 n->agg_distinct = FALSE;
9596 n->func_variadic = FALSE;
9601 | CAST '(' a_expr AS Typename ')'
9602 { $$ = makeTypeCast($3, $5, @1); }
9603 | EXTRACT '(' extract_list ')'
9605 FuncCall *n = makeNode(FuncCall);
9606 n->funcname = SystemFuncName("date_part");
9609 n->agg_star = FALSE;
9610 n->agg_distinct = FALSE;
9611 n->func_variadic = FALSE;
9616 | OVERLAY '(' overlay_list ')'
9618 /* overlay(A PLACING B FROM C FOR D) is converted to
9619 * overlay(A, B, C, D)
9620 * overlay(A PLACING B FROM C) is converted to
9623 FuncCall *n = makeNode(FuncCall);
9624 n->funcname = SystemFuncName("overlay");
9627 n->agg_star = FALSE;
9628 n->agg_distinct = FALSE;
9629 n->func_variadic = FALSE;
9634 | POSITION '(' position_list ')'
9636 /* position(A in B) is converted to position(B, A) */
9637 FuncCall *n = makeNode(FuncCall);
9638 n->funcname = SystemFuncName("position");
9641 n->agg_star = FALSE;
9642 n->agg_distinct = FALSE;
9643 n->func_variadic = FALSE;
9648 | SUBSTRING '(' substr_list ')'
9650 /* substring(A from B for C) is converted to
9651 * substring(A, B, C) - thomas 2000-11-28
9653 FuncCall *n = makeNode(FuncCall);
9654 n->funcname = SystemFuncName("substring");
9657 n->agg_star = FALSE;
9658 n->agg_distinct = FALSE;
9659 n->func_variadic = FALSE;
9664 | TREAT '(' a_expr AS Typename ')'
9666 /* TREAT(expr AS target) converts expr of a particular type to target,
9667 * which is defined to be a subtype of the original expression.
9668 * In SQL99, this is intended for use with structured UDTs,
9669 * but let's make this a generally useful form allowing stronger
9670 * coercions than are handled by implicit casting.
9672 FuncCall *n = makeNode(FuncCall);
9673 /* Convert SystemTypeName() to SystemFuncName() even though
9674 * at the moment they result in the same thing.
9676 n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
9677 n->args = list_make1($3);
9679 n->agg_star = FALSE;
9680 n->agg_distinct = FALSE;
9681 n->func_variadic = FALSE;
9686 | TRIM '(' BOTH trim_list ')'
9688 /* various trim expressions are defined in SQL92
9689 * - thomas 1997-07-19
9691 FuncCall *n = makeNode(FuncCall);
9692 n->funcname = SystemFuncName("btrim");
9695 n->agg_star = FALSE;
9696 n->agg_distinct = FALSE;
9697 n->func_variadic = FALSE;
9702 | TRIM '(' LEADING trim_list ')'
9704 FuncCall *n = makeNode(FuncCall);
9705 n->funcname = SystemFuncName("ltrim");
9708 n->agg_star = FALSE;
9709 n->agg_distinct = FALSE;
9710 n->func_variadic = FALSE;
9715 | TRIM '(' TRAILING trim_list ')'
9717 FuncCall *n = makeNode(FuncCall);
9718 n->funcname = SystemFuncName("rtrim");
9721 n->agg_star = FALSE;
9722 n->agg_distinct = FALSE;
9723 n->func_variadic = FALSE;
9728 | TRIM '(' trim_list ')'
9730 FuncCall *n = makeNode(FuncCall);
9731 n->funcname = SystemFuncName("btrim");
9734 n->agg_star = FALSE;
9735 n->agg_distinct = FALSE;
9736 n->func_variadic = FALSE;
9741 | NULLIF '(' a_expr ',' a_expr ')'
9743 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
9745 | COALESCE '(' expr_list ')'
9747 CoalesceExpr *c = makeNode(CoalesceExpr);
9752 | GREATEST '(' expr_list ')'
9754 MinMaxExpr *v = makeNode(MinMaxExpr);
9756 v->op = IS_GREATEST;
9760 | LEAST '(' expr_list ')'
9762 MinMaxExpr *v = makeNode(MinMaxExpr);
9768 | XMLCONCAT '(' expr_list ')'
9770 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
9772 | XMLELEMENT '(' NAME_P ColLabel ')'
9774 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
9776 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
9778 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
9780 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
9782 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
9784 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
9786 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
9788 | XMLFOREST '(' xml_attribute_list ')'
9790 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
9792 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
9794 XmlExpr *x = (XmlExpr *)
9795 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
9796 list_make2($4, makeBoolAConst($5, -1)),
9801 | XMLPI '(' NAME_P ColLabel ')'
9803 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
9805 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
9807 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
9809 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
9811 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
9812 list_make3($3, $5, $6), @1);
9814 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
9816 XmlSerialize *n = makeNode(XmlSerialize);
9828 xml_root_version: VERSION_P a_expr
9830 | VERSION_P NO VALUE_P
9831 { $$ = makeNullAConst(-1); }
9834 opt_xml_root_standalone: ',' STANDALONE_P YES_P
9835 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
9836 | ',' STANDALONE_P NO
9837 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
9838 | ',' STANDALONE_P NO VALUE_P
9839 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
9841 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
9844 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
9847 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
9848 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
9851 xml_attribute_el: a_expr AS ColLabel
9853 $$ = makeNode(ResTarget);
9855 $$->indirection = NIL;
9856 $$->val = (Node *) $1;
9861 $$ = makeNode(ResTarget);
9863 $$->indirection = NIL;
9864 $$->val = (Node *) $1;
9869 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
9870 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
9873 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
9874 | STRIP_P WHITESPACE_P { $$ = FALSE; }
9875 | /*EMPTY*/ { $$ = FALSE; }
9879 * Window Definitions
9882 WINDOW window_definition_list { $$ = $2; }
9883 | /*EMPTY*/ { $$ = NIL; }
9886 window_definition_list:
9887 window_definition { $$ = list_make1($1); }
9888 | window_definition_list ',' window_definition
9889 { $$ = lappend($1, $3); }
9893 ColId AS window_specification
9901 over_clause: OVER window_specification
9905 WindowDef *n = makeNode(WindowDef);
9908 n->partitionClause = NIL;
9909 n->orderClause = NIL;
9910 n->frameOptions = FRAMEOPTION_DEFAULTS;
9918 window_specification: '(' opt_existing_window_name opt_partition_clause
9919 opt_sort_clause opt_frame_clause ')'
9921 WindowDef *n = makeNode(WindowDef);
9924 n->partitionClause = $3;
9925 n->orderClause = $4;
9926 n->frameOptions = $5;
9933 * If we see PARTITION, RANGE, or ROWS as the first token after the '('
9934 * of a window_specification, we want the assumption to be that there is
9935 * no existing_window_name; but those keywords are unreserved and so could
9936 * be ColIds. We fix this by making them have the same precedence as IDENT
9937 * and giving the empty production here a slightly higher precedence, so
9938 * that the shift/reduce conflict is resolved in favor of reducing the rule.
9939 * These keywords are thus precluded from being an existing_window_name but
9940 * are not reserved for any other purpose.
9942 opt_existing_window_name: ColId { $$ = $1; }
9943 | /*EMPTY*/ %prec Op { $$ = NULL; }
9946 opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
9947 | /*EMPTY*/ { $$ = NIL; }
9951 * This is only a subset of the full SQL:2008 frame_clause grammar.
9952 * We don't support <expression> PRECEDING, <expression> FOLLOWING,
9953 * nor <window frame exclusion> yet.
9958 $$ = FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE | $2;
9962 $$ = FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS | $2;
9965 { $$ = FRAMEOPTION_DEFAULTS; }
9968 frame_extent: frame_bound
9970 /* reject invalid cases */
9971 if ($1 & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
9973 (errcode(ERRCODE_WINDOWING_ERROR),
9974 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
9975 parser_errposition(@1)));
9976 if ($1 & FRAMEOPTION_START_CURRENT_ROW)
9978 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9979 errmsg("frame start at CURRENT ROW is not implemented"),
9980 parser_errposition(@1)));
9981 $$ = $1 | FRAMEOPTION_END_CURRENT_ROW;
9983 | BETWEEN frame_bound AND frame_bound
9985 /* reject invalid cases */
9986 if ($2 & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
9988 (errcode(ERRCODE_WINDOWING_ERROR),
9989 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
9990 parser_errposition(@2)));
9991 if ($2 & FRAMEOPTION_START_CURRENT_ROW)
9993 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9994 errmsg("frame start at CURRENT ROW is not implemented"),
9995 parser_errposition(@2)));
9996 if ($4 & FRAMEOPTION_START_UNBOUNDED_PRECEDING)
9998 (errcode(ERRCODE_WINDOWING_ERROR),
9999 errmsg("frame end cannot be UNBOUNDED PRECEDING"),
10000 parser_errposition(@4)));
10001 /* shift converts START_ options to END_ options */
10002 $$ = FRAMEOPTION_BETWEEN | $2 | ($4 << 1);
10007 * This is used for both frame start and frame end, with output set up on
10008 * the assumption it's frame start; the frame_extent productions must reject
10012 UNBOUNDED PRECEDING
10014 $$ = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
10016 | UNBOUNDED FOLLOWING
10018 $$ = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
10022 $$ = FRAMEOPTION_START_CURRENT_ROW;
10028 * Supporting nonterminals for expressions.
10031 /* Explicit row production.
10033 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
10034 * without conflicting with the parenthesized a_expr production. Without the
10035 * ROW keyword, there must be more than one a_expr inside the parens.
10037 row: ROW '(' expr_list ')' { $$ = $3; }
10038 | ROW '(' ')' { $$ = NIL; }
10039 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
10042 sub_type: ANY { $$ = ANY_SUBLINK; }
10043 | SOME { $$ = ANY_SUBLINK; }
10044 | ALL { $$ = ALL_SUBLINK; }
10047 all_Op: Op { $$ = $1; }
10048 | MathOp { $$ = $1; }
10051 MathOp: '+' { $$ = "+"; }
10052 | '-' { $$ = "-"; }
10053 | '*' { $$ = "*"; }
10054 | '/' { $$ = "/"; }
10055 | '%' { $$ = "%"; }
10056 | '^' { $$ = "^"; }
10057 | '<' { $$ = "<"; }
10058 | '>' { $$ = ">"; }
10059 | '=' { $$ = "="; }
10063 { $$ = list_make1(makeString($1)); }
10064 | OPERATOR '(' any_operator ')'
10070 { $$ = list_make1(makeString($1)); }
10071 | OPERATOR '(' any_operator ')'
10077 { $$ = list_make1(makeString($1)); }
10078 | OPERATOR '(' any_operator ')'
10081 { $$ = list_make1(makeString("~~")); }
10083 { $$ = list_make1(makeString("!~~")); }
10085 { $$ = list_make1(makeString("~~*")); }
10087 { $$ = list_make1(makeString("!~~*")); }
10088 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
10089 * the regular expression is preprocessed by a function (similar_escape),
10090 * and the ~ operator for posix regular expressions is used.
10091 * x SIMILAR TO y -> x ~ similar_escape(y)
10092 * this transformation is made on the fly by the parser upwards.
10093 * however the SubLink structure which handles any/some/all stuff
10094 * is not ready for such a thing.
10100 $$ = list_make1($1);
10102 | expr_list ',' a_expr
10104 $$ = lappend($1, $3);
10108 /* function arguments can have names */
10109 func_arg_list: func_arg_expr
10111 $$ = list_make1($1);
10113 | func_arg_list ',' func_arg_expr
10115 $$ = lappend($1, $3);
10119 func_arg_expr: a_expr
10123 | a_expr AS param_name
10125 NamedArgExpr *na = makeNode(NamedArgExpr);
10126 na->arg = (Expr *) $1;
10128 na->argnumber = -1; /* until determined */
10134 type_list: Typename { $$ = list_make1($1); }
10135 | type_list ',' Typename { $$ = lappend($1, $3); }
10138 array_expr: '[' expr_list ']'
10140 $$ = makeAArrayExpr($2, @1);
10142 | '[' array_expr_list ']'
10144 $$ = makeAArrayExpr($2, @1);
10148 $$ = makeAArrayExpr(NIL, @1);
10152 array_expr_list: array_expr { $$ = list_make1($1); }
10153 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
10158 extract_arg FROM a_expr
10160 $$ = list_make2(makeStringConst($1, @1), $3);
10162 | /*EMPTY*/ { $$ = NIL; }
10165 /* Allow delimited string Sconst in extract_arg as an SQL extension.
10166 * - thomas 2001-04-12
10170 | YEAR_P { $$ = "year"; }
10171 | MONTH_P { $$ = "month"; }
10172 | DAY_P { $$ = "day"; }
10173 | HOUR_P { $$ = "hour"; }
10174 | MINUTE_P { $$ = "minute"; }
10175 | SECOND_P { $$ = "second"; }
10176 | Sconst { $$ = $1; }
10179 /* OVERLAY() arguments
10180 * SQL99 defines the OVERLAY() function:
10181 * o overlay(text placing text from int for int)
10182 * o overlay(text placing text from int)
10183 * and similarly for binary strings
10186 a_expr overlay_placing substr_from substr_for
10188 $$ = list_make4($1, $2, $3, $4);
10190 | a_expr overlay_placing substr_from
10192 $$ = list_make3($1, $2, $3);
10201 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
10204 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
10205 | /*EMPTY*/ { $$ = NIL; }
10208 /* SUBSTRING() arguments
10209 * SQL9x defines a specific syntax for arguments to SUBSTRING():
10210 * o substring(text from int for int)
10211 * o substring(text from int) get entire string from starting point "int"
10212 * o substring(text for int) get first "int" characters of string
10213 * o substring(text from pattern) get entire string matching pattern
10214 * o substring(text from pattern for escape) same with specified escape char
10215 * We also want to support generic substring functions which accept
10216 * the usual generic list of arguments. So we will accept both styles
10217 * here, and convert the SQL9x style to the generic list for further
10218 * processing. - thomas 2000-11-28
10221 a_expr substr_from substr_for
10223 $$ = list_make3($1, $2, $3);
10225 | a_expr substr_for substr_from
10227 /* not legal per SQL99, but might as well allow it */
10228 $$ = list_make3($1, $3, $2);
10230 | a_expr substr_from
10232 $$ = list_make2($1, $2);
10234 | a_expr substr_for
10237 * Since there are no cases where this syntax allows
10238 * a textual FOR value, we forcibly cast the argument
10239 * to int4. The possible matches in pg_proc are
10240 * substring(text,int4) and substring(text,text),
10241 * and we don't want the parser to choose the latter,
10242 * which it is likely to do if the second argument
10243 * is unknown or doesn't have an implicit cast to int4.
10245 $$ = list_make3($1, makeIntConst(1, -1),
10247 SystemTypeName("int4"), -1));
10258 FROM a_expr { $$ = $2; }
10261 substr_for: FOR a_expr { $$ = $2; }
10264 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
10265 | FROM expr_list { $$ = $2; }
10266 | expr_list { $$ = $1; }
10269 in_expr: select_with_parens
10271 SubLink *n = makeNode(SubLink);
10273 /* other fields will be filled later */
10276 | '(' expr_list ')' { $$ = (Node *)$2; }
10280 * Define SQL92-style case clause.
10281 * - Full specification
10282 * CASE WHEN a = b THEN c ... ELSE d END
10283 * - Implicit argument
10284 * CASE a WHEN b THEN c ... ELSE d END
10286 case_expr: CASE case_arg when_clause_list case_default END_P
10288 CaseExpr *c = makeNode(CaseExpr);
10289 c->casetype = InvalidOid; /* not analyzed yet */
10290 c->arg = (Expr *) $2;
10292 c->defresult = (Expr *) $4;
10299 /* There must be at least one */
10300 when_clause { $$ = list_make1($1); }
10301 | when_clause_list when_clause { $$ = lappend($1, $2); }
10305 WHEN a_expr THEN a_expr
10307 CaseWhen *w = makeNode(CaseWhen);
10308 w->expr = (Expr *) $2;
10309 w->result = (Expr *) $4;
10316 ELSE a_expr { $$ = $2; }
10317 | /*EMPTY*/ { $$ = NULL; }
10320 case_arg: a_expr { $$ = $1; }
10321 | /*EMPTY*/ { $$ = NULL; }
10326 $$ = makeColumnRef($1, NIL, @1, yyscanner);
10328 | ColId indirection
10330 $$ = makeColumnRef($1, $2, @1, yyscanner);
10337 $$ = (Node *) makeString($2);
10341 $$ = (Node *) makeNode(A_Star);
10345 A_Indices *ai = makeNode(A_Indices);
10350 | '[' a_expr ':' a_expr ']'
10352 A_Indices *ai = makeNode(A_Indices);
10360 indirection_el { $$ = list_make1($1); }
10361 | indirection indirection_el { $$ = lappend($1, $2); }
10365 /*EMPTY*/ { $$ = NIL; }
10366 | opt_indirection indirection_el { $$ = lappend($1, $2); }
10369 opt_asymmetric: ASYMMETRIC
10374 * The SQL spec defines "contextually typed value expressions" and
10375 * "contextually typed row value constructors", which for our purposes
10376 * are the same as "a_expr" and "row" except that DEFAULT can appear at
10381 a_expr { $$ = (Node *) $1; }
10384 SetToDefault *n = makeNode(SetToDefault);
10391 ctext_expr { $$ = list_make1($1); }
10392 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
10396 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
10397 * making VALUES a fully reserved word, which will probably break more apps
10398 * than allowing the noise-word is worth.
10400 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
10404 /*****************************************************************************
10406 * target list for SELECT
10408 *****************************************************************************/
10411 target_el { $$ = list_make1($1); }
10412 | target_list ',' target_el { $$ = lappend($1, $3); }
10415 target_el: a_expr AS ColLabel
10417 $$ = makeNode(ResTarget);
10419 $$->indirection = NIL;
10420 $$->val = (Node *)$1;
10424 * We support omitting AS only for column labels that aren't
10425 * any known keyword. There is an ambiguity against postfix
10426 * operators: is "a ! b" an infix expression, or a postfix
10427 * expression and a column label? We prefer to resolve this
10428 * as an infix expression, which we accomplish by assigning
10429 * IDENT a precedence higher than POSTFIXOP.
10433 $$ = makeNode(ResTarget);
10435 $$->indirection = NIL;
10436 $$->val = (Node *)$1;
10441 $$ = makeNode(ResTarget);
10443 $$->indirection = NIL;
10444 $$->val = (Node *)$1;
10449 ColumnRef *n = makeNode(ColumnRef);
10450 n->fields = list_make1(makeNode(A_Star));
10453 $$ = makeNode(ResTarget);
10455 $$->indirection = NIL;
10456 $$->val = (Node *)n;
10462 /*****************************************************************************
10464 * Names and constants
10466 *****************************************************************************/
10468 qualified_name_list:
10469 qualified_name { $$ = list_make1($1); }
10470 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
10474 * The production for a qualified relation name has to exactly match the
10475 * production for a qualified func_name, because in a FROM clause we cannot
10476 * tell which we are parsing until we see what comes after it ('(' for a
10477 * func_name, something else for a relation). Therefore we allow 'indirection'
10478 * which may contain subscripts, and reject that case in the C code.
10483 $$ = makeNode(RangeVar);
10484 $$->catalogname = NULL;
10485 $$->schemaname = NULL;
10489 | ColId indirection
10491 check_qualified_name($2, yyscanner);
10492 $$ = makeNode(RangeVar);
10493 switch (list_length($2))
10496 $$->catalogname = NULL;
10497 $$->schemaname = $1;
10498 $$->relname = strVal(linitial($2));
10501 $$->catalogname = $1;
10502 $$->schemaname = strVal(linitial($2));
10503 $$->relname = strVal(lsecond($2));
10507 (errcode(ERRCODE_SYNTAX_ERROR),
10508 errmsg("improper qualified name (too many dotted names): %s",
10509 NameListToString(lcons(makeString($1), $2))),
10510 parser_errposition(@1)));
10518 { $$ = list_make1(makeString($1)); }
10519 | name_list ',' name
10520 { $$ = lappend($1, makeString($3)); }
10524 name: ColId { $$ = $1; };
10527 ColId { $$ = $1; };
10530 ColId { $$ = $1; };
10532 attr_name: ColLabel { $$ = $1; };
10534 index_name: ColId { $$ = $1; };
10536 file_name: Sconst { $$ = $1; };
10539 * The production for a qualified func_name has to exactly match the
10540 * production for a qualified columnref, because we cannot tell which we
10541 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
10542 * anything else for a columnref). Therefore we allow 'indirection' which
10543 * may contain subscripts, and reject that case in the C code. (If we
10544 * ever implement SQL99-like methods, such syntax may actually become legal!)
10546 func_name: type_function_name
10547 { $$ = list_make1(makeString($1)); }
10548 | ColId indirection
10550 $$ = check_func_name(lcons(makeString($1), $2),
10561 $$ = makeIntConst($1, @1);
10565 $$ = makeFloatConst($1, @1);
10569 $$ = makeStringConst($1, @1);
10573 $$ = makeBitStringConst($1, @1);
10577 /* This is a bit constant per SQL99:
10578 * Without Feature F511, "BIT data type",
10579 * a <general literal> shall not be a
10580 * <bit string literal> or a <hex string literal>.
10582 $$ = makeBitStringConst($1, @1);
10586 /* generic type 'literal' syntax */
10587 TypeName *t = makeTypeNameFromNameList($1);
10589 $$ = makeStringConstCast($2, @2, t);
10591 | func_name '(' func_arg_list ')' Sconst
10593 /* generic syntax with a type modifier */
10594 TypeName *t = makeTypeNameFromNameList($1);
10598 * We must use func_arg_list in the production to avoid
10599 * reduce/reduce conflicts, but we don't actually wish
10600 * to allow NamedArgExpr in this context.
10604 NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
10606 if (IsA(arg, NamedArgExpr))
10608 (errcode(ERRCODE_SYNTAX_ERROR),
10609 errmsg("type modifier cannot have AS name"),
10610 parser_errposition(arg->location)));
10614 $$ = makeStringConstCast($5, @5, t);
10616 | ConstTypename Sconst
10618 $$ = makeStringConstCast($2, @2, $1);
10620 | ConstInterval Sconst opt_interval
10624 $$ = makeStringConstCast($2, @2, t);
10626 | ConstInterval '(' Iconst ')' Sconst opt_interval
10631 if (list_length($6) != 1)
10633 (errcode(ERRCODE_SYNTAX_ERROR),
10634 errmsg("interval precision specified twice"),
10635 parser_errposition(@1)));
10636 t->typmods = lappend($6, makeIntConst($3, @3));
10639 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
10640 makeIntConst($3, @3));
10641 $$ = makeStringConstCast($5, @5, t);
10645 $$ = makeBoolAConst(TRUE, @1);
10649 $$ = makeBoolAConst(FALSE, @1);
10653 $$ = makeNullAConst(@1);
10657 Iconst: ICONST { $$ = $1; };
10658 Sconst: SCONST { $$ = $1; };
10659 RoleId: ColId { $$ = $1; };
10661 SignedIconst: Iconst { $$ = $1; }
10662 | '+' Iconst { $$ = + $2; }
10663 | '-' Iconst { $$ = - $2; }
10666 Iconst_list: Iconst { $$ = list_make1(makeInteger($1)); }
10667 | Iconst_list ',' Iconst { $$ = lappend($1, makeInteger($3)); }
10671 * Name classification hierarchy.
10673 * IDENT is the lexeme returned by the lexer for identifiers that match
10674 * no known keyword. In most cases, we can accept certain keywords as
10675 * names, not only IDENTs. We prefer to accept as many such keywords
10676 * as possible to minimize the impact of "reserved words" on programmers.
10677 * So, we divide names into several possible classes. The classification
10678 * is chosen in part to make keywords acceptable as names wherever possible.
10681 /* Column identifier --- names that can be column, table, etc names.
10683 ColId: IDENT { $$ = $1; }
10684 | unreserved_keyword { $$ = pstrdup($1); }
10685 | col_name_keyword { $$ = pstrdup($1); }
10688 /* Type/function identifier --- names that can be type or function names.
10690 type_function_name: IDENT { $$ = $1; }
10691 | unreserved_keyword { $$ = pstrdup($1); }
10692 | type_func_name_keyword { $$ = pstrdup($1); }
10695 /* Column label --- allowed labels in "AS" clauses.
10696 * This presently includes *all* Postgres keywords.
10698 ColLabel: IDENT { $$ = $1; }
10699 | unreserved_keyword { $$ = pstrdup($1); }
10700 | col_name_keyword { $$ = pstrdup($1); }
10701 | type_func_name_keyword { $$ = pstrdup($1); }
10702 | reserved_keyword { $$ = pstrdup($1); }
10707 * Keyword category lists. Generally, every keyword present in
10708 * the Postgres grammar should appear in exactly one of these lists.
10710 * Put a new keyword into the first list that it can go into without causing
10711 * shift or reduce conflicts. The earlier lists define "less reserved"
10712 * categories of keywords.
10714 * Make sure that each keyword's category in keywords.c matches where
10715 * it is listed here. (Someday we may be able to generate these lists and
10716 * keywords.c's table from a common master list.)
10719 /* "Unreserved" keywords --- available for use as any kind of name.
10721 unreserved_keyword:
10975 /* Column identifier --- keywords that can be column, table, etc names.
10977 * Many of these keywords will in fact be recognized as type or function
10978 * names too; but they have special productions for the purpose, and so
10979 * can't be treated as "generic" type or function names.
10981 * The type names appearing here are not usable as function names
10982 * because they can be followed by '(' in typename productions, which
10983 * looks too much like a function call for an LR(1) parser.
11033 /* Type/function identifier --- keywords that can be type or function names.
11035 * Most of these are keywords that are used as operators in expressions;
11036 * in general such keywords can't be column names because they would be
11037 * ambiguous with variables, but they are unambiguous as function identifiers.
11039 * Do not include POSITION, SUBSTRING, etc here since they have explicit
11040 * productions in a_expr to support the goofy SQL9x argument syntax.
11041 * - thomas 2000-11-28
11043 type_func_name_keyword:
11069 /* Reserved keyword --- these keywords are usable only as a ColLabel.
11071 * Keywords appear here if they could not be distinguished from variable,
11072 * type, or function names in some contexts. Don't put things here unless
11097 | CURRENT_TIMESTAMP
11158 * The signature of this function is required by bison. However, we
11159 * ignore the passed yylloc and instead use the last token position
11160 * available from the scanner.
11163 base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
11165 parser_yyerror(msg);
11169 makeColumnRef(char *colname, List *indirection,
11170 int location, core_yyscan_t yyscanner)
11173 * Generate a ColumnRef node, with an A_Indirection node added if there
11174 * is any subscripting in the specified indirection list. However,
11175 * any field selection at the start of the indirection list must be
11176 * transposed into the "fields" part of the ColumnRef node.
11178 ColumnRef *c = makeNode(ColumnRef);
11182 c->location = location;
11183 foreach(l, indirection)
11185 if (IsA(lfirst(l), A_Indices))
11187 A_Indirection *i = makeNode(A_Indirection);
11191 /* easy case - all indirection goes to A_Indirection */
11192 c->fields = list_make1(makeString(colname));
11193 i->indirection = check_indirection(indirection, yyscanner);
11197 /* got to split the list in two */
11198 i->indirection = check_indirection(list_copy_tail(indirection,
11201 indirection = list_truncate(indirection, nfields);
11202 c->fields = lcons(makeString(colname), indirection);
11204 i->arg = (Node *) c;
11207 else if (IsA(lfirst(l), A_Star))
11209 /* We only allow '*' at the end of a ColumnRef */
11210 if (lnext(l) != NULL)
11211 parser_yyerror("improper use of \"*\"");
11215 /* No subscripting, so all indirection gets added to field list */
11216 c->fields = lcons(makeString(colname), indirection);
11221 makeTypeCast(Node *arg, TypeName *typename, int location)
11223 TypeCast *n = makeNode(TypeCast);
11225 n->typeName = typename;
11226 n->location = location;
11231 makeStringConst(char *str, int location)
11233 A_Const *n = makeNode(A_Const);
11235 n->val.type = T_String;
11236 n->val.val.str = str;
11237 n->location = location;
11243 makeStringConstCast(char *str, int location, TypeName *typename)
11245 Node *s = makeStringConst(str, location);
11247 return makeTypeCast(s, typename, -1);
11251 makeIntConst(int val, int location)
11253 A_Const *n = makeNode(A_Const);
11255 n->val.type = T_Integer;
11256 n->val.val.ival = val;
11257 n->location = location;
11263 makeFloatConst(char *str, int location)
11265 A_Const *n = makeNode(A_Const);
11267 n->val.type = T_Float;
11268 n->val.val.str = str;
11269 n->location = location;
11275 makeBitStringConst(char *str, int location)
11277 A_Const *n = makeNode(A_Const);
11279 n->val.type = T_BitString;
11280 n->val.val.str = str;
11281 n->location = location;
11287 makeNullAConst(int location)
11289 A_Const *n = makeNode(A_Const);
11291 n->val.type = T_Null;
11292 n->location = location;
11298 makeAConst(Value *v, int location)
11305 n = makeFloatConst(v->val.str, location);
11309 n = makeIntConst(v->val.ival, location);
11314 n = makeStringConst(v->val.str, location);
11321 /* makeBoolAConst()
11322 * Create an A_Const string node and put it inside a boolean cast.
11325 makeBoolAConst(bool state, int location)
11327 A_Const *n = makeNode(A_Const);
11329 n->val.type = T_String;
11330 n->val.val.str = (state ? "t" : "f");
11331 n->location = location;
11333 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
11337 * Create and populate a FuncCall node to support the OVERLAPS operator.
11340 makeOverlaps(List *largs, List *rargs, int location, core_yyscan_t yyscanner)
11342 FuncCall *n = makeNode(FuncCall);
11344 n->funcname = SystemFuncName("overlaps");
11345 if (list_length(largs) == 1)
11346 largs = lappend(largs, largs);
11347 else if (list_length(largs) != 2)
11349 (errcode(ERRCODE_SYNTAX_ERROR),
11350 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
11351 parser_errposition(location)));
11352 if (list_length(rargs) == 1)
11353 rargs = lappend(rargs, rargs);
11354 else if (list_length(rargs) != 2)
11356 (errcode(ERRCODE_SYNTAX_ERROR),
11357 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
11358 parser_errposition(location)));
11359 n->args = list_concat(largs, rargs);
11360 n->agg_order = NIL;
11361 n->agg_star = FALSE;
11362 n->agg_distinct = FALSE;
11363 n->func_variadic = FALSE;
11365 n->location = location;
11369 /* check_qualified_name --- check the result of qualified_name production
11371 * It's easiest to let the grammar production for qualified_name allow
11372 * subscripts and '*', which we then must reject here.
11375 check_qualified_name(List *names, core_yyscan_t yyscanner)
11381 if (!IsA(lfirst(i), String))
11382 parser_yyerror("syntax error");
11386 /* check_func_name --- check the result of func_name production
11388 * It's easiest to let the grammar production for func_name allow subscripts
11389 * and '*', which we then must reject here.
11392 check_func_name(List *names, core_yyscan_t yyscanner)
11398 if (!IsA(lfirst(i), String))
11399 parser_yyerror("syntax error");
11404 /* check_indirection --- check the result of indirection production
11406 * We only allow '*' at the end of the list, but it's hard to enforce that
11407 * in the grammar, so do it here.
11410 check_indirection(List *indirection, core_yyscan_t yyscanner)
11414 foreach(l, indirection)
11416 if (IsA(lfirst(l), A_Star))
11418 if (lnext(l) != NULL)
11419 parser_yyerror("improper use of \"*\"");
11422 return indirection;
11425 /* extractArgTypes()
11426 * Given a list of FunctionParameter nodes, extract a list of just the
11427 * argument types (TypeNames) for input parameters only. This is what
11428 * is needed to look up an existing function, which is what is wanted by
11429 * the productions that use this call.
11432 extractArgTypes(List *parameters)
11434 List *result = NIL;
11437 foreach(i, parameters)
11439 FunctionParameter *p = (FunctionParameter *) lfirst(i);
11441 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
11442 result = lappend(result, p->argType);
11447 /* findLeftmostSelect()
11448 * Find the leftmost component SelectStmt in a set-operation parsetree.
11450 static SelectStmt *
11451 findLeftmostSelect(SelectStmt *node)
11453 while (node && node->op != SETOP_NONE)
11455 Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
11459 /* insertSelectOptions()
11460 * Insert ORDER BY, etc into an already-constructed SelectStmt.
11462 * This routine is just to avoid duplicating code in SelectStmt productions.
11465 insertSelectOptions(SelectStmt *stmt,
11466 List *sortClause, List *lockingClause,
11467 Node *limitOffset, Node *limitCount,
11468 WithClause *withClause,
11469 core_yyscan_t yyscanner)
11471 Assert(IsA(stmt, SelectStmt));
11474 * Tests here are to reject constructs like
11475 * (SELECT foo ORDER BY bar) ORDER BY baz
11479 if (stmt->sortClause)
11481 (errcode(ERRCODE_SYNTAX_ERROR),
11482 errmsg("multiple ORDER BY clauses not allowed"),
11483 parser_errposition(exprLocation((Node *) sortClause))));
11484 stmt->sortClause = sortClause;
11486 /* We can handle multiple locking clauses, though */
11487 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
11490 if (stmt->limitOffset)
11492 (errcode(ERRCODE_SYNTAX_ERROR),
11493 errmsg("multiple OFFSET clauses not allowed"),
11494 parser_errposition(exprLocation(limitOffset))));
11495 stmt->limitOffset = limitOffset;
11499 if (stmt->limitCount)
11501 (errcode(ERRCODE_SYNTAX_ERROR),
11502 errmsg("multiple LIMIT clauses not allowed"),
11503 parser_errposition(exprLocation(limitCount))));
11504 stmt->limitCount = limitCount;
11508 if (stmt->withClause)
11510 (errcode(ERRCODE_SYNTAX_ERROR),
11511 errmsg("multiple WITH clauses not allowed"),
11512 parser_errposition(exprLocation((Node *) withClause))));
11513 stmt->withClause = withClause;
11518 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
11520 SelectStmt *n = makeNode(SelectStmt);
11524 n->larg = (SelectStmt *) larg;
11525 n->rarg = (SelectStmt *) rarg;
11529 /* SystemFuncName()
11530 * Build a properly-qualified reference to a built-in function.
11533 SystemFuncName(char *name)
11535 return list_make2(makeString("pg_catalog"), makeString(name));
11538 /* SystemTypeName()
11539 * Build a properly-qualified reference to a built-in type.
11541 * typmod is defaulted, but may be changed afterwards by caller.
11542 * Likewise for the location.
11545 SystemTypeName(char *name)
11547 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
11548 makeString(name)));
11552 * Handle negation of a numeric constant.
11554 * Formerly, we did this here because the optimizer couldn't cope with
11555 * indexquals that looked like "var = -4" --- it wants "var = const"
11556 * and a unary minus operator applied to a constant didn't qualify.
11557 * As of Postgres 7.0, that problem doesn't exist anymore because there
11558 * is a constant-subexpression simplifier in the optimizer. However,
11559 * there's still a good reason for doing this here, which is that we can
11560 * postpone committing to a particular internal representation for simple
11561 * negative constants. It's better to leave "-123.456" in string form
11562 * until we know what the desired type is.
11565 doNegate(Node *n, int location)
11567 if (IsA(n, A_Const))
11569 A_Const *con = (A_Const *)n;
11571 /* report the constant's location as that of the '-' sign */
11572 con->location = location;
11574 if (con->val.type == T_Integer)
11576 con->val.val.ival = -con->val.val.ival;
11579 if (con->val.type == T_Float)
11581 doNegateFloat(&con->val);
11586 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
11590 doNegateFloat(Value *v)
11592 char *oldval = v->val.str;
11594 Assert(IsA(v, Float));
11595 if (*oldval == '+')
11597 if (*oldval == '-')
11598 v->val.str = oldval+1; /* just strip the '-' */
11601 char *newval = (char *) palloc(strlen(oldval) + 2);
11604 strcpy(newval+1, oldval);
11605 v->val.str = newval;
11610 makeAArrayExpr(List *elements, int location)
11612 A_ArrayExpr *n = makeNode(A_ArrayExpr);
11614 n->elements = elements;
11615 n->location = location;
11620 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
11623 XmlExpr *x = makeNode(XmlExpr);
11628 * named_args is a list of ResTarget; it'll be split apart into separate
11629 * expression and name lists in transformXmlExpr().
11631 x->named_args = named_args;
11632 x->arg_names = NIL;
11634 /* xmloption, if relevant, must be filled in by caller */
11635 /* type and typmod will be filled in during parse analysis */
11636 x->location = location;
11641 * Initialize to parse one query string
11644 parser_init(base_yy_extra_type *yyext)
11646 yyext->parsetree = NIL; /* in case grammar forgets to set it */
11650 * Merge the input and output parameters of a table function.
11653 mergeTableFuncParameters(List *func_args, List *columns)
11657 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
11658 foreach(lc, func_args)
11660 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
11662 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
11664 (errcode(ERRCODE_SYNTAX_ERROR),
11665 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
11668 return list_concat(func_args, columns);
11672 * Determine return type of a TABLE function. A single result column
11673 * returns setof that column's type; otherwise return setof record.
11676 TableFuncTypeName(List *columns)
11680 if (list_length(columns) == 1)
11682 FunctionParameter *p = (FunctionParameter *) linitial(columns);
11684 result = (TypeName *) copyObject(p->argType);
11687 result = SystemTypeName("record");
11689 result->setof = true;
11695 * Must undefine this stuff before including scan.c, since it has different
11696 * definitions for these macros.