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.705 2010/01/25 20:55:32 tgl Exp $
17 * AUTHOR DATE MAJOR EVENT
18 * Andrew Yu Sept, 1994 POSTQUEL to SQL conversion
19 * Andrew Yu Oct, 1994 lispy code conversion
22 * CAPITALS are used to represent terminal symbols.
23 * non-capitals are used to represent non-terminals.
24 * SQL92-specific syntax is separated from plain SQL/Postgres syntax
25 * to help isolate the non-extensible portions of the parser.
27 * In general, nothing in this file should initiate database accesses
28 * nor depend on changeable state (such as SET variables). If you do
29 * database accesses, your code will fail when we have aborted the
30 * current transaction and are just parsing commands to find the next
31 * ROLLBACK or COMMIT. If you make use of SET variables, then you
32 * will do the wrong thing in multi-query strings like this:
33 * SET SQL_inheritance TO off; SELECT * FROM foo;
34 * because the entire string is parsed by gram.y before the SET gets
35 * executed. Anything that depends on the database or changeable state
36 * should be handled during parse analysis so that it happens at the
37 * right time not the wrong time. The handling of SQL_inheritance is
41 * If you use a list, make sure the datum is a node so that the printing
44 * Sometimes we assign constants to makeStrings. Make sure we don't free
47 *-------------------------------------------------------------------------
54 #include "catalog/index.h"
55 #include "catalog/namespace.h"
56 #include "catalog/pg_trigger.h"
57 #include "commands/defrem.h"
58 #include "nodes/makefuncs.h"
59 #include "nodes/nodeFuncs.h"
60 #include "parser/gramparse.h"
61 #include "parser/parser.h"
62 #include "storage/lmgr.h"
63 #include "utils/date.h"
64 #include "utils/datetime.h"
65 #include "utils/numeric.h"
66 #include "utils/xml.h"
69 /* Location tracking support --- simpler than bison's default */
70 #define YYLLOC_DEFAULT(Current, Rhs, N) \
73 (Current) = (Rhs)[1]; \
75 (Current) = (Rhs)[0]; \
79 * Bison doesn't allocate anything that needs to live across parser calls,
80 * so we can easily have it use palloc instead of malloc. This prevents
81 * memory leaks if we error out during parsing. Note this only works with
82 * bison >= 2.0. However, in bison 1.875 the default is to use alloca()
83 * if possible, so there's not really much problem anyhow, at least if
84 * you're building with gcc.
86 #define YYMALLOC palloc
89 /* Private struct for the result of privilege_target production */
90 typedef struct PrivTarget
92 GrantTargetType targtype;
93 GrantObjectType objtype;
98 #define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
99 #define parser_errposition(pos) scanner_errposition(pos, yyscanner)
101 static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
103 static Node *makeColumnRef(char *colname, List *indirection,
104 int location, core_yyscan_t yyscanner);
105 static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
106 static Node *makeStringConst(char *str, int location);
107 static Node *makeStringConstCast(char *str, int location, TypeName *typename);
108 static Node *makeIntConst(int val, int location);
109 static Node *makeFloatConst(char *str, int location);
110 static Node *makeBitStringConst(char *str, int location);
111 static Node *makeNullAConst(int location);
112 static Node *makeAConst(Value *v, int location);
113 static Node *makeBoolAConst(bool state, int location);
114 static FuncCall *makeOverlaps(List *largs, List *rargs,
115 int location, core_yyscan_t yyscanner);
116 static void check_qualified_name(List *names, core_yyscan_t yyscanner);
117 static List *check_func_name(List *names, core_yyscan_t yyscanner);
118 static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
119 static List *extractArgTypes(List *parameters);
120 static SelectStmt *findLeftmostSelect(SelectStmt *node);
121 static void insertSelectOptions(SelectStmt *stmt,
122 List *sortClause, List *lockingClause,
123 Node *limitOffset, Node *limitCount,
124 WithClause *withClause,
125 core_yyscan_t yyscanner);
126 static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
127 static Node *doNegate(Node *n, int location);
128 static void doNegateFloat(Value *v);
129 static Node *makeAArrayExpr(List *elements, int location);
130 static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
131 List *args, int location);
132 static List *mergeTableFuncParameters(List *func_args, List *columns);
133 static TypeName *TableFuncTypeName(List *columns);
139 %name-prefix="base_yy"
142 %parse-param {core_yyscan_t yyscanner}
143 %lex-param {core_yyscan_t yyscanner}
147 core_YYSTYPE core_yystype;
148 /* these fields must match core_YYSTYPE: */
156 DropBehavior dbehavior;
157 OnCommitAction oncommit;
163 FunctionParameter *fun_param;
164 FunctionParameterMode fun_param_mode;
165 FuncWithArgs *funwithargs;
177 struct PrivTarget *privtarget;
178 AccessPriv *accesspriv;
180 VariableSetStmt *vsetstmt;
183 %type <node> stmt schema_stmt
184 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterFdwStmt
185 AlterForeignServerStmt AlterGroupStmt
186 AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterTableStmt
187 AlterUserStmt AlterUserMappingStmt AlterUserSetStmt
188 AlterRoleStmt AlterRoleSetStmt
189 AlterDefaultPrivilegesStmt DefACLAction
190 AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
191 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
192 CreateDomainStmt CreateGroupStmt CreateOpClassStmt
193 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
194 CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
195 CreateFdwStmt CreateForeignServerStmt CreateAssertStmt CreateTrigStmt
196 CreateUserStmt CreateUserMappingStmt CreateRoleStmt
197 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
198 DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
199 DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
200 DropUserStmt DropdbStmt DropTableSpaceStmt DropFdwStmt
201 DropForeignServerStmt DropUserMappingStmt ExplainStmt FetchStmt
202 GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
203 LockStmt NotifyStmt ExplainableStmt PreparableStmt
204 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
205 RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
206 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
207 SelectStmt TransactionStmt TruncateStmt
208 UnlistenStmt UpdateStmt VacuumStmt
209 VariableResetStmt VariableSetStmt VariableShowStmt
210 ViewStmt CheckPointStmt CreateConversionStmt
211 DeallocateStmt PrepareStmt ExecuteStmt
212 DropOwnedStmt ReassignOwnedStmt
213 AlterTSConfigurationStmt AlterTSDictionaryStmt
215 %type <node> select_no_parens select_with_parens select_clause
216 simple_select values_clause
218 %type <node> alter_column_default opclass_item opclass_drop alter_using
219 %type <ival> add_drop opt_asc_desc opt_nulls_order
221 %type <node> alter_table_cmd
222 %type <list> alter_table_cmds
224 %type <dbehavior> opt_drop_behavior
226 %type <list> createdb_opt_list alterdb_opt_list copy_opt_list
227 transaction_mode_list
228 %type <defelt> createdb_opt_item alterdb_opt_item copy_opt_item
229 transaction_mode_item
231 %type <ival> opt_lock lock_type cast_context
232 %type <ival> vacuum_option_list vacuum_option_elem
233 %type <boolean> opt_force opt_or_replace
234 opt_grant_grant_option opt_grant_admin_option
235 opt_nowait opt_if_exists opt_with_data
237 %type <list> OptRoleList AlterOptRoleList
238 %type <defelt> CreateOptRoleElem AlterOptRoleElem
241 %type <str> foreign_server_version opt_foreign_server_version
242 %type <str> auth_ident
243 %type <str> opt_in_database
245 %type <str> OptSchemaName
246 %type <list> OptSchemaEltList
248 %type <boolean> TriggerActionTime TriggerForSpec opt_trusted opt_restart_seqs
250 %type <list> TriggerEvents TriggerOneEvent
251 %type <value> TriggerFuncArg
252 %type <node> TriggerWhen
254 %type <str> copy_file_name
255 database_name access_method_clause access_method attr_name
256 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 reloptions opt_reloptions
281 OptWith opt_distinct opt_definition func_args func_args_list
282 func_args_with_defaults func_args_with_defaults_list
283 func_as createfunc_opt_list alterfunc_opt_list
284 aggr_args old_aggr_definition old_aggr_list
285 oper_argtypes RuleActionList RuleActionMulti
286 opt_column_list columnList opt_name_list
287 sort_clause opt_sort_clause sortby_list index_params
288 name_list from_clause from_list opt_array_bounds
289 qualified_name_list any_name any_name_list
290 any_operator expr_list attrs
291 target_list insert_column_list set_target_list
292 set_clause_list set_clause multiple_set_clause
293 ctext_expr_list ctext_row def_list indirection opt_indirection
294 reloption_list group_clause TriggerFuncArgs select_limit
295 opt_select_limit opclass_item_list opclass_drop_list
296 opt_opfamily transaction_mode_list_or_empty
297 TableFuncElementList opt_type_modifiers
299 execute_param_clause using_clause returning_clause
300 opt_enum_val_list enum_val_list table_func_column_list
301 create_generic_options alter_generic_options
302 relation_expr_list dostmt_opt_list
304 %type <range> OptTempTableName
305 %type <into> into_clause create_as_target
307 %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
308 %type <fun_param> func_arg func_arg_with_default table_func_column
309 %type <fun_param_mode> arg_class
310 %type <typnam> func_return func_type
312 %type <boolean> TriggerForType OptTemp
313 %type <oncommit> OnCommitOption
315 %type <node> for_locking_item
316 %type <list> for_locking_clause opt_for_locking_clause for_locking_items
317 %type <list> locked_rels_list
318 %type <boolean> opt_all
320 %type <node> join_outer join_qual
321 %type <jtype> join_type
323 %type <list> extract_list overlay_list position_list
324 %type <list> substr_list trim_list
325 %type <list> opt_interval interval_second
326 %type <node> overlay_placing substr_from substr_for
328 %type <boolean> opt_instead
329 %type <boolean> opt_unique opt_concurrently opt_verbose opt_full
330 %type <boolean> opt_freeze opt_default opt_recheck
331 %type <defelt> opt_binary opt_oids copy_delimiter
333 %type <boolean> copy_from
335 %type <ival> opt_column event cursor_options opt_hold opt_set_data
336 %type <objtype> reindex_type drop_type comment_type
338 %type <node> fetch_args limit_clause select_limit_value
339 offset_clause select_offset_value
340 select_offset_value2 opt_select_fetch_first_value
341 %type <ival> row_or_rows first_or_next
343 %type <list> OptSeqOptList SeqOptList
344 %type <defelt> SeqOptElem
346 %type <istmt> insert_rest
348 %type <vsetstmt> set_rest SetResetClause
350 %type <node> TableElement ConstraintElem TableFuncElement
351 %type <node> columnDef
352 %type <defelt> def_elem reloption_elem old_aggr_elem
353 %type <node> def_arg columnElem where_clause where_or_current_clause
354 a_expr b_expr c_expr func_expr AexprConst indirection_el
355 columnref in_expr having_clause func_table array_expr
357 %type <list> ExclusionConstraintList ExclusionConstraintElem
358 %type <list> func_arg_list
359 %type <node> func_arg_expr
360 %type <list> row type_list array_expr_list
361 %type <node> case_expr case_arg when_clause case_default
362 %type <list> when_clause_list
363 %type <ival> sub_type
364 %type <list> OptCreateAs CreateAsList
365 %type <node> CreateAsElement ctext_expr
366 %type <value> NumericOnly
367 %type <alias> alias_clause
368 %type <sortby> sortby
369 %type <ielem> index_elem
370 %type <node> table_ref
371 %type <jexpr> joined_table
372 %type <range> relation_expr
373 %type <range> relation_expr_opt_alias
374 %type <target> target_el single_set_clause set_target insert_column_item
376 %type <str> generic_option_name
377 %type <node> generic_option_arg
378 %type <defelt> generic_option_elem alter_generic_option_elem
379 %type <list> generic_option_list alter_generic_option_list
380 %type <str> explain_option_name
381 %type <node> explain_option_arg
382 %type <defelt> explain_option_elem
383 %type <list> explain_option_list
384 %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
385 %type <defelt> copy_generic_opt_elem
386 %type <list> copy_generic_opt_list copy_generic_opt_arg_list
387 %type <list> copy_options
389 %type <typnam> Typename SimpleTypename ConstTypename
390 GenericType Numeric opt_float
391 Character ConstCharacter
392 CharacterWithLength CharacterWithoutLength
393 ConstDatetime ConstInterval
394 Bit ConstBit BitWithLength BitWithoutLength
395 %type <str> character
396 %type <str> extract_arg
397 %type <str> opt_charset
398 %type <boolean> opt_varying opt_timezone
400 %type <ival> Iconst SignedIconst
401 %type <list> Iconst_list
402 %type <str> Sconst comment_text
403 %type <str> RoleId opt_granted_by opt_boolean ColId_or_Sconst
404 %type <list> var_list
405 %type <str> ColId ColLabel var_name type_function_name param_name
406 %type <node> var_value zone_value
408 %type <keyword> unreserved_keyword type_func_name_keyword
409 %type <keyword> col_name_keyword reserved_keyword
411 %type <node> TableConstraint TableLikeClause
412 %type <ival> TableLikeOptionList TableLikeOption
413 %type <list> ColQualList
414 %type <node> ColConstraint ColConstraintElem ConstraintAttr
415 %type <ival> key_actions key_delete key_match key_update key_action
416 %type <ival> ConstraintAttributeSpec ConstraintDeferrabilitySpec
419 %type <list> constraints_set_list
420 %type <boolean> constraints_set_mode
421 %type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
422 %type <list> opt_check_option
424 %type <target> xml_attribute_el
425 %type <list> xml_attribute_list xml_attributes
426 %type <node> xml_root_version opt_xml_root_standalone
427 %type <ival> document_or_content
428 %type <boolean> xml_whitespace_option
430 %type <node> common_table_expr
431 %type <with> with_clause
432 %type <list> cte_list
434 %type <list> window_clause window_definition_list opt_partition_clause
435 %type <windef> window_definition over_clause window_specification
436 %type <str> opt_existing_window_name
437 %type <ival> opt_frame_clause frame_extent frame_bound
441 * Non-keyword token types. These are hard-wired into the "flex" lexer.
442 * They must be listed first so that their numeric codes do not depend on
443 * the set of keywords. PL/pgsql depends on this so that it can share the
444 * same lexer. If you add/change tokens here, fix PL/pgsql to match!
446 * DOT_DOT and COLON_EQUALS are unused in the core SQL grammar, and so will
447 * always provoke parse errors. They are needed by PL/pgsql.
449 %token <str> IDENT FCONST SCONST BCONST XCONST Op
450 %token <ival> ICONST PARAM
451 %token TYPECAST DOT_DOT COLON_EQUALS
454 * If you want to make any keyword changes, update the keyword table in
455 * src/include/parser/kwlist.h and add new keywords to the appropriate one
456 * of the reserved-or-not-so-reserved keyword lists, below; search
457 * this file for "Keyword category lists".
460 /* ordinary key words in alphabetical order */
461 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
462 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
463 ASSERTION ASSIGNMENT ASYMMETRIC AT AUTHORIZATION
465 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
468 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
469 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
470 CLUSTER COALESCE COLLATE COLUMN COMMENT COMMENTS COMMIT
471 COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
472 CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
473 CREATEROLE CREATEUSER CROSS CSV CURRENT_P
474 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
475 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
477 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
478 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
479 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
481 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT
482 EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
484 FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOLLOWING FOR FORCE FOREIGN FORWARD
485 FREEZE FROM FULL FUNCTION FUNCTIONS
487 GLOBAL GRANT GRANTED GREATEST GROUP_P
489 HANDLER HAVING HEADER_P HOLD HOUR_P
491 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
492 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
493 INNER_P INOUT INPLACE INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
494 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
500 LANGUAGE LARGE_P LAST_P LC_COLLATE_P LC_CTYPE_P LEADING
501 LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP
502 LOCATION LOCK_P LOGIN_P
504 MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
506 NAME_P NAMES NATIONAL NATURAL NCHAR NEXT NO NOCREATEDB
507 NOCREATEROLE NOCREATEUSER NOINHERIT NOLOGIN_P NONE NOSUPERUSER
508 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NULLS_P NUMERIC
510 OBJECT_P OF OFF OFFSET OIDS ON ONLY OPERATOR OPTION OPTIONS OR
511 ORDER OUT_P OUTER_P OVER OVERLAPS OVERLAY OWNED OWNER
513 PARSER PARTIAL PARTITION PASSWORD PLACING PLANS POSITION
514 PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
515 PRIOR PRIVILEGES PROCEDURAL PROCEDURE
519 RANGE READ REAL REASSIGN RECHECK RECURSIVE REFERENCES REINDEX
520 RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA RESET RESTART
521 RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROW ROWS RULE
523 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE SEQUENCES
524 SERIALIZABLE SERVER SESSION SESSION_USER SET SETOF SHARE
525 SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT
526 STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING SUPERUSER_P
527 SYMMETRIC SYSID SYSTEM_P
529 TABLE TABLES TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
530 TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
531 TRUNCATE TRUSTED TYPE_P
533 UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
536 VACUUM VALID VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
537 VERBOSE VERSION_P VIEW VOLATILE
539 WHEN WHERE WHITESPACE_P WINDOW WITH WITHOUT WORK WRAPPER WRITE
541 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLFOREST XMLPARSE
542 XMLPI XMLROOT XMLSERIALIZE
549 * The grammar thinks these are keywords, but they are not in the kwlist.h
550 * list and so can never be entered directly. The filter in parser.c
551 * creates these tokens when required.
553 %token NULLS_FIRST NULLS_LAST WITH_TIME
556 /* Precedence: lowest to highest */
557 %nonassoc SET /* see relation_expr_opt_alias */
565 %nonassoc LIKE ILIKE SIMILAR
570 %left POSTFIXOP /* dummy for postfix Op rules */
572 * To support target_el without AS, we must give IDENT an explicit priority
573 * between POSTFIXOP and Op. We can safely assign the same priority to
574 * various unreserved keywords as needed to resolve ambiguities (this can't
575 * have any bad effects since obviously the keywords will still behave the
576 * same as if they weren't keywords). We need to do this for PARTITION,
577 * RANGE, ROWS to support opt_existing_window_name; and for RANGE, ROWS
578 * so that they can follow a_expr without creating
579 * postfix-operator problems.
581 %nonassoc IDENT PARTITION RANGE ROWS
582 %left Op OPERATOR /* multi-character ops and user-defined operators */
585 %nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN /* sets precedence for IS NULL, etc */
589 /* Unary Operators */
590 %left AT ZONE /* sets precedence for AT TIME ZONE */
597 * These might seem to be low-precedence, but actually they are not part
598 * of the arithmetic hierarchy at all in their use as JOIN operators.
599 * We make them high-precedence to support their use as function names.
600 * They wouldn't be given a precedence at all, were it not that we need
601 * left-associativity among the JOIN rules themselves.
603 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
604 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
605 %right PRESERVE STRIP_P
610 * The target production for the whole parse.
614 pg_yyget_extra(yyscanner)->parsetree = $1;
618 /* the thrashing around here is to discard "empty" statements... */
619 stmtmulti: stmtmulti ';' stmt
622 $$ = lappend($1, $3);
637 | AlterDatabaseSetStmt
638 | AlterDefaultPrivilegesStmt
641 | AlterForeignServerStmt
644 | AlterObjectSchemaStmt
650 | AlterTSConfigurationStmt
651 | AlterTSDictionaryStmt
652 | AlterUserMappingStmt
665 | CreateConversionStmt
668 | CreateForeignServerStmt
678 | CreateTableSpaceStmt
682 | CreateUserMappingStmt
693 | DropForeignServerStmt
705 | DropUserMappingStmt
742 /*****************************************************************************
744 * Create a new Postgres DBMS role
746 *****************************************************************************/
749 CREATE ROLE RoleId opt_with OptRoleList
751 CreateRoleStmt *n = makeNode(CreateRoleStmt);
752 n->stmt_type = ROLESTMT_ROLE;
765 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
766 * for backwards compatibility). Note: the only option required by SQL99
767 * is "WITH ADMIN name".
770 OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
771 | /* EMPTY */ { $$ = NIL; }
775 AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
776 | /* EMPTY */ { $$ = NIL; }
782 $$ = makeDefElem("password",
783 (Node *)makeString($2));
787 $$ = makeDefElem("password", NULL);
789 | ENCRYPTED PASSWORD Sconst
791 $$ = makeDefElem("encryptedPassword",
792 (Node *)makeString($3));
794 | UNENCRYPTED PASSWORD Sconst
796 $$ = makeDefElem("unencryptedPassword",
797 (Node *)makeString($3));
801 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
805 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
809 $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE));
813 $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE));
817 $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
821 $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
825 $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE));
829 $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE));
833 /* For backwards compatibility, synonym for SUPERUSER */
834 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
838 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
842 $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE));
846 $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE));
848 | CONNECTION LIMIT SignedIconst
850 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3));
854 $$ = makeDefElem("validUntil", (Node *)makeString($3));
856 /* Supported but not documented for roles, for use by ALTER GROUP. */
859 $$ = makeDefElem("rolemembers", (Node *)$2);
864 AlterOptRoleElem { $$ = $1; }
865 /* The following are not supported by ALTER ROLE/USER/GROUP */
868 $$ = makeDefElem("sysid", (Node *)makeInteger($2));
872 $$ = makeDefElem("adminmembers", (Node *)$2);
876 $$ = makeDefElem("rolemembers", (Node *)$2);
878 | IN_P ROLE name_list
880 $$ = makeDefElem("addroleto", (Node *)$3);
882 | IN_P GROUP_P name_list
884 $$ = makeDefElem("addroleto", (Node *)$3);
889 /*****************************************************************************
891 * Create a new Postgres DBMS user (role with implied login ability)
893 *****************************************************************************/
896 CREATE USER RoleId opt_with OptRoleList
898 CreateRoleStmt *n = makeNode(CreateRoleStmt);
899 n->stmt_type = ROLESTMT_USER;
907 /*****************************************************************************
909 * Alter a postgresql DBMS role
911 *****************************************************************************/
914 ALTER ROLE RoleId opt_with AlterOptRoleList
916 AlterRoleStmt *n = makeNode(AlterRoleStmt);
918 n->action = +1; /* add, if there are members */
925 /* EMPTY */ { $$ = NULL; }
926 | IN_P DATABASE database_name { $$ = $3; }
930 ALTER ROLE RoleId opt_in_database SetResetClause
932 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
941 /*****************************************************************************
943 * Alter a postgresql DBMS user
945 *****************************************************************************/
948 ALTER USER RoleId opt_with AlterOptRoleList
950 AlterRoleStmt *n = makeNode(AlterRoleStmt);
952 n->action = +1; /* add, if there are members */
960 ALTER USER RoleId SetResetClause
962 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
971 /*****************************************************************************
973 * Drop a postgresql DBMS role
975 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
976 * might own objects in multiple databases, there is presently no way to
977 * implement either cascading or restricting. Caveat DBA.
978 *****************************************************************************/
983 DropRoleStmt *n = makeNode(DropRoleStmt);
984 n->missing_ok = FALSE;
988 | DROP ROLE IF_P EXISTS name_list
990 DropRoleStmt *n = makeNode(DropRoleStmt);
991 n->missing_ok = TRUE;
997 /*****************************************************************************
999 * Drop a postgresql DBMS user
1001 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
1002 * might own objects in multiple databases, there is presently no way to
1003 * implement either cascading or restricting. Caveat DBA.
1004 *****************************************************************************/
1009 DropRoleStmt *n = makeNode(DropRoleStmt);
1010 n->missing_ok = FALSE;
1014 | DROP USER IF_P EXISTS name_list
1016 DropRoleStmt *n = makeNode(DropRoleStmt);
1018 n->missing_ok = TRUE;
1024 /*****************************************************************************
1026 * Create a postgresql group (role without login ability)
1028 *****************************************************************************/
1031 CREATE GROUP_P RoleId opt_with OptRoleList
1033 CreateRoleStmt *n = makeNode(CreateRoleStmt);
1034 n->stmt_type = ROLESTMT_GROUP;
1042 /*****************************************************************************
1044 * Alter a postgresql group
1046 *****************************************************************************/
1049 ALTER GROUP_P RoleId add_drop USER name_list
1051 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1054 n->options = list_make1(makeDefElem("rolemembers",
1060 add_drop: ADD_P { $$ = +1; }
1065 /*****************************************************************************
1067 * Drop a postgresql group
1069 * XXX see above notes about cascading DROP USER; groups have same problem.
1070 *****************************************************************************/
1073 DROP GROUP_P name_list
1075 DropRoleStmt *n = makeNode(DropRoleStmt);
1076 n->missing_ok = FALSE;
1080 | DROP GROUP_P IF_P EXISTS name_list
1082 DropRoleStmt *n = makeNode(DropRoleStmt);
1083 n->missing_ok = TRUE;
1090 /*****************************************************************************
1092 * Manipulate a schema
1094 *****************************************************************************/
1097 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
1099 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1100 /* One can omit the schema name or the authorization id. */
1109 | CREATE SCHEMA ColId OptSchemaEltList
1111 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1112 /* ...but not both */
1122 | /* EMPTY */ { $$ = NULL; }
1126 OptSchemaEltList schema_stmt { $$ = lappend($1, $2); }
1127 | /* EMPTY */ { $$ = NIL; }
1131 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1132 * statement (in addition to by themselves).
1144 /*****************************************************************************
1146 * Set PG internal variable
1147 * SET name TO 'var_value'
1148 * Include SQL92 syntax (thomas 1997-10-22):
1149 * SET TIME ZONE 'var_value'
1151 *****************************************************************************/
1156 VariableSetStmt *n = $2;
1157 n->is_local = false;
1160 | SET LOCAL set_rest
1162 VariableSetStmt *n = $3;
1166 | SET SESSION set_rest
1168 VariableSetStmt *n = $3;
1169 n->is_local = false;
1174 set_rest: /* Generic SET syntaxes: */
1175 var_name TO var_list
1177 VariableSetStmt *n = makeNode(VariableSetStmt);
1178 n->kind = VAR_SET_VALUE;
1183 | var_name '=' var_list
1185 VariableSetStmt *n = makeNode(VariableSetStmt);
1186 n->kind = VAR_SET_VALUE;
1191 | var_name TO DEFAULT
1193 VariableSetStmt *n = makeNode(VariableSetStmt);
1194 n->kind = VAR_SET_DEFAULT;
1198 | var_name '=' DEFAULT
1200 VariableSetStmt *n = makeNode(VariableSetStmt);
1201 n->kind = VAR_SET_DEFAULT;
1205 | var_name FROM CURRENT_P
1207 VariableSetStmt *n = makeNode(VariableSetStmt);
1208 n->kind = VAR_SET_CURRENT;
1212 /* Special syntaxes mandated by SQL standard: */
1213 | TIME ZONE zone_value
1215 VariableSetStmt *n = makeNode(VariableSetStmt);
1216 n->kind = VAR_SET_VALUE;
1217 n->name = "timezone";
1219 n->args = list_make1($3);
1221 n->kind = VAR_SET_DEFAULT;
1224 | TRANSACTION transaction_mode_list
1226 VariableSetStmt *n = makeNode(VariableSetStmt);
1227 n->kind = VAR_SET_MULTI;
1228 n->name = "TRANSACTION";
1232 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1234 VariableSetStmt *n = makeNode(VariableSetStmt);
1235 n->kind = VAR_SET_MULTI;
1236 n->name = "SESSION CHARACTERISTICS";
1243 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1244 errmsg("current database cannot be changed"),
1245 parser_errposition(@2)));
1246 $$ = NULL; /*not reached*/
1250 VariableSetStmt *n = makeNode(VariableSetStmt);
1251 n->kind = VAR_SET_VALUE;
1252 n->name = "search_path";
1253 n->args = list_make1(makeStringConst($2, @2));
1256 | NAMES opt_encoding
1258 VariableSetStmt *n = makeNode(VariableSetStmt);
1259 n->kind = VAR_SET_VALUE;
1260 n->name = "client_encoding";
1262 n->args = list_make1(makeStringConst($2, @2));
1264 n->kind = VAR_SET_DEFAULT;
1267 | ROLE ColId_or_Sconst
1269 VariableSetStmt *n = makeNode(VariableSetStmt);
1270 n->kind = VAR_SET_VALUE;
1272 n->args = list_make1(makeStringConst($2, @2));
1275 | SESSION AUTHORIZATION ColId_or_Sconst
1277 VariableSetStmt *n = makeNode(VariableSetStmt);
1278 n->kind = VAR_SET_VALUE;
1279 n->name = "session_authorization";
1280 n->args = list_make1(makeStringConst($3, @3));
1283 | SESSION AUTHORIZATION DEFAULT
1285 VariableSetStmt *n = makeNode(VariableSetStmt);
1286 n->kind = VAR_SET_DEFAULT;
1287 n->name = "session_authorization";
1290 | XML_P OPTION document_or_content
1292 VariableSetStmt *n = makeNode(VariableSetStmt);
1293 n->kind = VAR_SET_VALUE;
1294 n->name = "xmloption";
1295 n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1300 var_name: ColId { $$ = $1; }
1301 | var_name '.' ColId
1303 $$ = palloc(strlen($1) + strlen($3) + 2);
1304 sprintf($$, "%s.%s", $1, $3);
1308 var_list: var_value { $$ = list_make1($1); }
1309 | var_list ',' var_value { $$ = lappend($1, $3); }
1312 var_value: opt_boolean
1313 { $$ = makeStringConst($1, @1); }
1315 { $$ = makeStringConst($1, @1); }
1317 { $$ = makeAConst($1, @1); }
1320 iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1321 | READ COMMITTED { $$ = "read committed"; }
1322 | REPEATABLE READ { $$ = "repeatable read"; }
1323 | SERIALIZABLE { $$ = "serializable"; }
1327 TRUE_P { $$ = "true"; }
1328 | FALSE_P { $$ = "false"; }
1330 | OFF { $$ = "off"; }
1333 /* Timezone values can be:
1334 * - a string such as 'pst8pdt'
1335 * - an identifier such as "pst8pdt"
1336 * - an integer or floating point number
1337 * - a time interval per SQL99
1338 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1339 * so use IDENT (meaning we reject anything that is a key word).
1344 $$ = makeStringConst($1, @1);
1348 $$ = makeStringConst($1, @1);
1350 | ConstInterval Sconst opt_interval
1355 A_Const *n = (A_Const *) linitial($3);
1356 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1358 (errcode(ERRCODE_SYNTAX_ERROR),
1359 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1360 parser_errposition(@3)));
1363 $$ = makeStringConstCast($2, @2, t);
1365 | ConstInterval '(' Iconst ')' Sconst opt_interval
1370 A_Const *n = (A_Const *) linitial($6);
1371 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1373 (errcode(ERRCODE_SYNTAX_ERROR),
1374 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1375 parser_errposition(@6)));
1376 if (list_length($6) != 1)
1378 (errcode(ERRCODE_SYNTAX_ERROR),
1379 errmsg("interval precision specified twice"),
1380 parser_errposition(@1)));
1381 t->typmods = lappend($6, makeIntConst($3, @3));
1384 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1385 makeIntConst($3, @3));
1386 $$ = makeStringConstCast($5, @5, t);
1388 | NumericOnly { $$ = makeAConst($1, @1); }
1389 | DEFAULT { $$ = NULL; }
1390 | LOCAL { $$ = NULL; }
1395 | DEFAULT { $$ = NULL; }
1396 | /*EMPTY*/ { $$ = NULL; }
1401 | Sconst { $$ = $1; }
1407 VariableSetStmt *n = makeNode(VariableSetStmt);
1408 n->kind = VAR_RESET;
1414 VariableSetStmt *n = makeNode(VariableSetStmt);
1415 n->kind = VAR_RESET;
1416 n->name = "timezone";
1419 | RESET TRANSACTION ISOLATION LEVEL
1421 VariableSetStmt *n = makeNode(VariableSetStmt);
1422 n->kind = VAR_RESET;
1423 n->name = "transaction_isolation";
1426 | RESET SESSION AUTHORIZATION
1428 VariableSetStmt *n = makeNode(VariableSetStmt);
1429 n->kind = VAR_RESET;
1430 n->name = "session_authorization";
1435 VariableSetStmt *n = makeNode(VariableSetStmt);
1436 n->kind = VAR_RESET_ALL;
1441 /* SetResetClause allows SET or RESET without LOCAL */
1443 SET set_rest { $$ = $2; }
1444 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1451 VariableShowStmt *n = makeNode(VariableShowStmt);
1457 VariableShowStmt *n = makeNode(VariableShowStmt);
1458 n->name = "timezone";
1461 | SHOW TRANSACTION ISOLATION LEVEL
1463 VariableShowStmt *n = makeNode(VariableShowStmt);
1464 n->name = "transaction_isolation";
1467 | SHOW SESSION AUTHORIZATION
1469 VariableShowStmt *n = makeNode(VariableShowStmt);
1470 n->name = "session_authorization";
1475 VariableShowStmt *n = makeNode(VariableShowStmt);
1483 SET CONSTRAINTS constraints_set_list constraints_set_mode
1485 ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
1486 n->constraints = $3;
1492 constraints_set_list:
1494 | qualified_name_list { $$ = $1; }
1497 constraints_set_mode:
1498 DEFERRED { $$ = TRUE; }
1499 | IMMEDIATE { $$ = FALSE; }
1504 * Checkpoint statement
1509 CheckPointStmt *n = makeNode(CheckPointStmt);
1515 /*****************************************************************************
1517 * DISCARD { ALL | TEMP | PLANS }
1519 *****************************************************************************/
1524 DiscardStmt *n = makeNode(DiscardStmt);
1525 n->target = DISCARD_ALL;
1530 DiscardStmt *n = makeNode(DiscardStmt);
1531 n->target = DISCARD_TEMP;
1536 DiscardStmt *n = makeNode(DiscardStmt);
1537 n->target = DISCARD_TEMP;
1542 DiscardStmt *n = makeNode(DiscardStmt);
1543 n->target = DISCARD_PLANS;
1549 /*****************************************************************************
1551 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations
1553 * Note: we accept all subcommands for each of the four variants, and sort
1554 * out what's really legal at execution time.
1555 *****************************************************************************/
1558 ALTER TABLE relation_expr alter_table_cmds
1560 AlterTableStmt *n = makeNode(AlterTableStmt);
1563 n->relkind = OBJECT_TABLE;
1566 | ALTER INDEX qualified_name alter_table_cmds
1568 AlterTableStmt *n = makeNode(AlterTableStmt);
1571 n->relkind = OBJECT_INDEX;
1574 | ALTER SEQUENCE qualified_name alter_table_cmds
1576 AlterTableStmt *n = makeNode(AlterTableStmt);
1579 n->relkind = OBJECT_SEQUENCE;
1582 | ALTER VIEW qualified_name alter_table_cmds
1584 AlterTableStmt *n = makeNode(AlterTableStmt);
1587 n->relkind = OBJECT_VIEW;
1593 alter_table_cmd { $$ = list_make1($1); }
1594 | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
1598 /* ALTER TABLE <name> ADD <coldef> */
1601 AlterTableCmd *n = makeNode(AlterTableCmd);
1602 n->subtype = AT_AddColumn;
1606 /* ALTER TABLE <name> ADD COLUMN <coldef> */
1607 | ADD_P COLUMN columnDef
1609 AlterTableCmd *n = makeNode(AlterTableCmd);
1610 n->subtype = AT_AddColumn;
1614 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1615 | ALTER opt_column ColId alter_column_default
1617 AlterTableCmd *n = makeNode(AlterTableCmd);
1618 n->subtype = AT_ColumnDefault;
1623 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1624 | ALTER opt_column ColId DROP NOT NULL_P
1626 AlterTableCmd *n = makeNode(AlterTableCmd);
1627 n->subtype = AT_DropNotNull;
1631 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1632 | ALTER opt_column ColId SET NOT NULL_P
1634 AlterTableCmd *n = makeNode(AlterTableCmd);
1635 n->subtype = AT_SetNotNull;
1639 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
1640 | ALTER opt_column ColId SET STATISTICS SignedIconst
1642 AlterTableCmd *n = makeNode(AlterTableCmd);
1643 n->subtype = AT_SetStatistics;
1645 n->def = (Node *) makeInteger($6);
1648 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
1649 | ALTER opt_column ColId SET reloptions
1651 AlterTableCmd *n = makeNode(AlterTableCmd);
1652 n->subtype = AT_SetOptions;
1654 n->def = (Node *) $5;
1657 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
1658 | ALTER opt_column ColId RESET reloptions
1660 AlterTableCmd *n = makeNode(AlterTableCmd);
1661 n->subtype = AT_ResetOptions;
1663 n->def = (Node *) $5;
1666 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1667 | ALTER opt_column ColId SET STORAGE ColId
1669 AlterTableCmd *n = makeNode(AlterTableCmd);
1670 n->subtype = AT_SetStorage;
1672 n->def = (Node *) makeString($6);
1675 /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
1676 | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
1678 AlterTableCmd *n = makeNode(AlterTableCmd);
1679 n->subtype = AT_DropColumn;
1682 n->missing_ok = TRUE;
1685 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1686 | DROP opt_column ColId opt_drop_behavior
1688 AlterTableCmd *n = makeNode(AlterTableCmd);
1689 n->subtype = AT_DropColumn;
1692 n->missing_ok = FALSE;
1696 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
1697 * [ USING <expression> ]
1699 | ALTER opt_column ColId opt_set_data TYPE_P Typename alter_using
1701 AlterTableCmd *n = makeNode(AlterTableCmd);
1702 n->subtype = AT_AlterColumnType;
1704 n->def = (Node *) $6;
1708 /* ALTER TABLE <name> ADD CONSTRAINT ... */
1709 | ADD_P TableConstraint
1711 AlterTableCmd *n = makeNode(AlterTableCmd);
1712 n->subtype = AT_AddConstraint;
1716 /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
1717 | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
1719 AlterTableCmd *n = makeNode(AlterTableCmd);
1720 n->subtype = AT_DropConstraint;
1723 n->missing_ok = TRUE;
1726 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1727 | DROP CONSTRAINT name opt_drop_behavior
1729 AlterTableCmd *n = makeNode(AlterTableCmd);
1730 n->subtype = AT_DropConstraint;
1733 n->missing_ok = FALSE;
1736 /* ALTER TABLE <name> SET WITH OIDS */
1739 AlterTableCmd *n = makeNode(AlterTableCmd);
1740 n->subtype = AT_AddOids;
1743 /* ALTER TABLE <name> SET WITHOUT OIDS */
1746 AlterTableCmd *n = makeNode(AlterTableCmd);
1747 n->subtype = AT_DropOids;
1750 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1753 AlterTableCmd *n = makeNode(AlterTableCmd);
1754 n->subtype = AT_ClusterOn;
1758 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1759 | SET WITHOUT CLUSTER
1761 AlterTableCmd *n = makeNode(AlterTableCmd);
1762 n->subtype = AT_DropCluster;
1766 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
1767 | ENABLE_P TRIGGER name
1769 AlterTableCmd *n = makeNode(AlterTableCmd);
1770 n->subtype = AT_EnableTrig;
1774 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
1775 | ENABLE_P ALWAYS TRIGGER name
1777 AlterTableCmd *n = makeNode(AlterTableCmd);
1778 n->subtype = AT_EnableAlwaysTrig;
1782 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
1783 | ENABLE_P REPLICA TRIGGER name
1785 AlterTableCmd *n = makeNode(AlterTableCmd);
1786 n->subtype = AT_EnableReplicaTrig;
1790 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
1791 | ENABLE_P TRIGGER ALL
1793 AlterTableCmd *n = makeNode(AlterTableCmd);
1794 n->subtype = AT_EnableTrigAll;
1797 /* ALTER TABLE <name> ENABLE TRIGGER USER */
1798 | ENABLE_P TRIGGER USER
1800 AlterTableCmd *n = makeNode(AlterTableCmd);
1801 n->subtype = AT_EnableTrigUser;
1804 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
1805 | DISABLE_P TRIGGER name
1807 AlterTableCmd *n = makeNode(AlterTableCmd);
1808 n->subtype = AT_DisableTrig;
1812 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
1813 | DISABLE_P TRIGGER ALL
1815 AlterTableCmd *n = makeNode(AlterTableCmd);
1816 n->subtype = AT_DisableTrigAll;
1819 /* ALTER TABLE <name> DISABLE TRIGGER USER */
1820 | DISABLE_P TRIGGER USER
1822 AlterTableCmd *n = makeNode(AlterTableCmd);
1823 n->subtype = AT_DisableTrigUser;
1826 /* ALTER TABLE <name> ENABLE RULE <rule> */
1827 | ENABLE_P RULE name
1829 AlterTableCmd *n = makeNode(AlterTableCmd);
1830 n->subtype = AT_EnableRule;
1834 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
1835 | ENABLE_P ALWAYS RULE name
1837 AlterTableCmd *n = makeNode(AlterTableCmd);
1838 n->subtype = AT_EnableAlwaysRule;
1842 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
1843 | ENABLE_P REPLICA RULE name
1845 AlterTableCmd *n = makeNode(AlterTableCmd);
1846 n->subtype = AT_EnableReplicaRule;
1850 /* ALTER TABLE <name> DISABLE RULE <rule> */
1851 | DISABLE_P RULE name
1853 AlterTableCmd *n = makeNode(AlterTableCmd);
1854 n->subtype = AT_DisableRule;
1858 /* ALTER TABLE <name> INHERIT <parent> */
1859 | INHERIT qualified_name
1861 AlterTableCmd *n = makeNode(AlterTableCmd);
1862 n->subtype = AT_AddInherit;
1863 n->def = (Node *) $2;
1866 /* ALTER TABLE <name> NO INHERIT <parent> */
1867 | NO INHERIT qualified_name
1869 AlterTableCmd *n = makeNode(AlterTableCmd);
1870 n->subtype = AT_DropInherit;
1871 n->def = (Node *) $3;
1874 /* ALTER TABLE <name> OWNER TO RoleId */
1877 AlterTableCmd *n = makeNode(AlterTableCmd);
1878 n->subtype = AT_ChangeOwner;
1882 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1883 | SET TABLESPACE name
1885 AlterTableCmd *n = makeNode(AlterTableCmd);
1886 n->subtype = AT_SetTableSpace;
1890 /* ALTER TABLE <name> SET (...) */
1893 AlterTableCmd *n = makeNode(AlterTableCmd);
1894 n->subtype = AT_SetRelOptions;
1895 n->def = (Node *)$2;
1898 /* ALTER TABLE <name> RESET (...) */
1901 AlterTableCmd *n = makeNode(AlterTableCmd);
1902 n->subtype = AT_ResetRelOptions;
1903 n->def = (Node *)$2;
1908 alter_column_default:
1909 SET DEFAULT a_expr { $$ = $3; }
1910 | DROP DEFAULT { $$ = NULL; }
1914 CASCADE { $$ = DROP_CASCADE; }
1915 | RESTRICT { $$ = DROP_RESTRICT; }
1916 | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1920 USING a_expr { $$ = $2; }
1921 | /* EMPTY */ { $$ = NULL; }
1925 '(' reloption_list ')' { $$ = $2; }
1928 opt_reloptions: WITH reloptions { $$ = $2; }
1929 | /* EMPTY */ { $$ = NIL; }
1933 reloption_elem { $$ = list_make1($1); }
1934 | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
1937 /* This should match def_elem and also allow qualified names */
1939 ColLabel '=' def_arg
1941 $$ = makeDefElem($1, (Node *) $3);
1945 $$ = makeDefElem($1, NULL);
1947 | ColLabel '.' ColLabel '=' def_arg
1949 $$ = makeDefElemExtended($1, $3, (Node *) $5,
1952 | ColLabel '.' ColLabel
1954 $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC);
1959 /*****************************************************************************
1962 * close <portalname>
1964 *****************************************************************************/
1969 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1975 ClosePortalStmt *n = makeNode(ClosePortalStmt);
1976 n->portalname = NULL;
1982 /*****************************************************************************
1985 * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
1986 * COPY ( SELECT ... ) TO file [WITH] [(options)]
1988 * In the preferred syntax the options are comma-separated
1989 * and use generic identifiers instead of keywords. The pre-8.5
1990 * syntax had a hard-wired, space-separated set of options.
1992 * Really old syntax, from versions 7.2 and prior:
1993 * COPY [ BINARY ] table [ WITH OIDS ] FROM/TO file
1994 * [ [ USING ] DELIMITERS 'delimiter' ] ]
1995 * [ WITH NULL AS 'null string' ]
1996 * This option placement is not supported with COPY (SELECT...).
1998 *****************************************************************************/
2000 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
2001 copy_from copy_file_name copy_delimiter opt_with copy_options
2003 CopyStmt *n = makeNode(CopyStmt);
2011 /* Concatenate user-supplied flags */
2013 n->options = lappend(n->options, $2);
2015 n->options = lappend(n->options, $5);
2017 n->options = lappend(n->options, $8);
2019 n->options = list_concat(n->options, $10);
2022 | COPY select_with_parens TO copy_file_name opt_with copy_options
2024 CopyStmt *n = makeNode(CopyStmt);
2037 | TO { $$ = FALSE; }
2041 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
2042 * used depends on the direction. (It really doesn't make sense to copy from
2043 * stdout. We silently correct the "typo".) - AY 9/94
2047 | STDIN { $$ = NULL; }
2048 | STDOUT { $$ = NULL; }
2051 copy_options: copy_opt_list { $$ = $1; }
2052 | '(' copy_generic_opt_list ')' { $$ = $2; }
2055 /* old COPY option syntax */
2057 copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
2058 | /* EMPTY */ { $$ = NIL; }
2064 $$ = makeDefElem("format", (Node *)makeString("binary"));
2068 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2070 | DELIMITER opt_as Sconst
2072 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2074 | NULL_P opt_as Sconst
2076 $$ = makeDefElem("null", (Node *)makeString($3));
2080 $$ = makeDefElem("format", (Node *)makeString("csv"));
2084 $$ = makeDefElem("header", (Node *)makeInteger(TRUE));
2086 | QUOTE opt_as Sconst
2088 $$ = makeDefElem("quote", (Node *)makeString($3));
2090 | ESCAPE opt_as Sconst
2092 $$ = makeDefElem("escape", (Node *)makeString($3));
2094 | FORCE QUOTE columnList
2096 $$ = makeDefElem("force_quote", (Node *)$3);
2100 $$ = makeDefElem("force_quote", (Node *)makeNode(A_Star));
2102 | FORCE NOT NULL_P columnList
2104 $$ = makeDefElem("force_not_null", (Node *)$4);
2108 /* The following exist for backward compatibility with very old versions */
2113 $$ = makeDefElem("format", (Node *)makeString("binary"));
2115 | /*EMPTY*/ { $$ = NULL; }
2121 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2123 | /*EMPTY*/ { $$ = NULL; }
2127 opt_using DELIMITERS Sconst
2129 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2131 | /*EMPTY*/ { $$ = NULL; }
2139 /* new COPY option syntax */
2140 copy_generic_opt_list:
2141 copy_generic_opt_elem
2143 $$ = list_make1($1);
2145 | copy_generic_opt_list ',' copy_generic_opt_elem
2147 $$ = lappend($1, $3);
2151 copy_generic_opt_elem:
2152 ColLabel copy_generic_opt_arg
2154 $$ = makeDefElem($1, $2);
2158 copy_generic_opt_arg:
2159 opt_boolean { $$ = (Node *) makeString($1); }
2160 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
2161 | NumericOnly { $$ = (Node *) $1; }
2162 | '*' { $$ = (Node *) makeNode(A_Star); }
2163 | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
2164 | /* EMPTY */ { $$ = NULL; }
2167 copy_generic_opt_arg_list:
2168 copy_generic_opt_arg_list_item
2170 $$ = list_make1($1);
2172 | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
2174 $$ = lappend($1, $3);
2178 /* beware of emitting non-string list elements here; see commands/define.c */
2179 copy_generic_opt_arg_list_item:
2180 opt_boolean { $$ = (Node *) makeString($1); }
2181 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
2185 /*****************************************************************************
2188 * CREATE TABLE relname
2190 *****************************************************************************/
2192 CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
2193 OptInherit OptWith OnCommitOption OptTableSpace
2195 CreateStmt *n = makeNode(CreateStmt);
2199 n->inhRelations = $8;
2200 n->constraints = NIL;
2203 n->tablespacename = $11;
2206 | CREATE OptTemp TABLE qualified_name OF qualified_name
2207 '(' OptTableElementList ')' OptWith OnCommitOption OptTableSpace
2209 /* SQL99 CREATE TABLE OF <UDT> (cols) seems to be satisfied
2210 * by our inheritance capabilities. Let's try it...
2212 CreateStmt *n = makeNode(CreateStmt);
2216 n->inhRelations = list_make1($6);
2217 n->constraints = NIL;
2220 n->tablespacename = $12;
2226 * Redundancy here is needed to avoid shift/reduce conflicts,
2227 * since TEMP is not a reserved word. See also OptTempTableName.
2229 * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
2230 * the LOCAL keyword is really meaningless.
2232 OptTemp: TEMPORARY { $$ = TRUE; }
2233 | TEMP { $$ = TRUE; }
2234 | LOCAL TEMPORARY { $$ = TRUE; }
2235 | LOCAL TEMP { $$ = TRUE; }
2236 | GLOBAL TEMPORARY { $$ = TRUE; }
2237 | GLOBAL TEMP { $$ = TRUE; }
2238 | /*EMPTY*/ { $$ = FALSE; }
2241 OptTableElementList:
2242 TableElementList { $$ = $1; }
2243 | /*EMPTY*/ { $$ = NIL; }
2249 $$ = list_make1($1);
2251 | TableElementList ',' TableElement
2253 $$ = lappend($1, $3);
2258 columnDef { $$ = $1; }
2259 | TableLikeClause { $$ = $1; }
2260 | TableConstraint { $$ = $1; }
2263 columnDef: ColId Typename ColQualList
2265 ColumnDef *n = makeNode(ColumnDef);
2268 n->constraints = $3;
2275 ColQualList ColConstraint { $$ = lappend($1, $2); }
2276 | /*EMPTY*/ { $$ = NIL; }
2280 CONSTRAINT name ColConstraintElem
2282 Constraint *n = (Constraint *) $3;
2283 Assert(IsA(n, Constraint));
2288 | ColConstraintElem { $$ = $1; }
2289 | ConstraintAttr { $$ = $1; }
2292 /* DEFAULT NULL is already the default for Postgres.
2293 * But define it here and carry it forward into the system
2294 * to make it explicit.
2295 * - thomas 1998-09-13
2297 * WITH NULL and NULL are not SQL92-standard syntax elements,
2298 * so leave them out. Use DEFAULT NULL to explicitly indicate
2299 * that a column may have that value. WITH NULL leads to
2300 * shift/reduce conflicts with WITH TIME ZONE anyway.
2301 * - thomas 1999-01-08
2303 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
2304 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
2305 * or be part of a_expr NOT LIKE or similar constructs).
2310 Constraint *n = makeNode(Constraint);
2311 n->contype = CONSTR_NOTNULL;
2317 Constraint *n = makeNode(Constraint);
2318 n->contype = CONSTR_NULL;
2322 | UNIQUE opt_definition OptConsTableSpace
2324 Constraint *n = makeNode(Constraint);
2325 n->contype = CONSTR_UNIQUE;
2332 | PRIMARY KEY opt_definition OptConsTableSpace
2334 Constraint *n = makeNode(Constraint);
2335 n->contype = CONSTR_PRIMARY;
2342 | CHECK '(' a_expr ')'
2344 Constraint *n = makeNode(Constraint);
2345 n->contype = CONSTR_CHECK;
2348 n->cooked_expr = NULL;
2353 Constraint *n = makeNode(Constraint);
2354 n->contype = CONSTR_DEFAULT;
2357 n->cooked_expr = NULL;
2360 | REFERENCES qualified_name opt_column_list key_match key_actions
2362 Constraint *n = makeNode(Constraint);
2363 n->contype = CONSTR_FOREIGN;
2368 n->fk_matchtype = $4;
2369 n->fk_upd_action = (char) ($5 >> 8);
2370 n->fk_del_action = (char) ($5 & 0xFF);
2371 n->skip_validation = FALSE;
2377 * ConstraintAttr represents constraint attributes, which we parse as if
2378 * they were independent constraint clauses, in order to avoid shift/reduce
2379 * conflicts (since NOT might start either an independent NOT NULL clause
2380 * or an attribute). parse_utilcmd.c is responsible for attaching the
2381 * attribute information to the preceding "real" constraint node, and for
2382 * complaining if attribute clauses appear in the wrong place or wrong
2385 * See also ConstraintAttributeSpec, which can be used in places where
2386 * there is no parsing conflict.
2391 Constraint *n = makeNode(Constraint);
2392 n->contype = CONSTR_ATTR_DEFERRABLE;
2398 Constraint *n = makeNode(Constraint);
2399 n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
2403 | INITIALLY DEFERRED
2405 Constraint *n = makeNode(Constraint);
2406 n->contype = CONSTR_ATTR_DEFERRED;
2410 | INITIALLY IMMEDIATE
2412 Constraint *n = makeNode(Constraint);
2413 n->contype = CONSTR_ATTR_IMMEDIATE;
2421 * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2422 * This seems to be a poor man's inheritance capability, with the resulting
2423 * tables completely decoupled except for the original commonality in definitions.
2425 * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2426 * which is a part of SQL:2003.
2429 LIKE qualified_name TableLikeOptionList
2431 InhRelation *n = makeNode(InhRelation);
2438 TableLikeOptionList:
2439 TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
2440 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
2441 | /* EMPTY */ { $$ = 0; }
2445 DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
2446 | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
2447 | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
2448 | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
2449 | COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
2450 | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
2454 /* ConstraintElem specifies constraint syntax which is not embedded into
2455 * a column definition. ColConstraintElem specifies the embedded form.
2456 * - thomas 1997-12-03
2459 CONSTRAINT name ConstraintElem
2461 Constraint *n = (Constraint *) $3;
2462 Assert(IsA(n, Constraint));
2467 | ConstraintElem { $$ = $1; }
2471 CHECK '(' a_expr ')' ConstraintAttributeSpec
2473 Constraint *n = makeNode(Constraint);
2474 n->contype = CONSTR_CHECK;
2477 n->cooked_expr = NULL;
2480 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2481 errmsg("CHECK constraints cannot be deferred"),
2482 parser_errposition(@5)));
2485 | UNIQUE '(' columnList ')' opt_definition OptConsTableSpace
2486 ConstraintAttributeSpec
2488 Constraint *n = makeNode(Constraint);
2489 n->contype = CONSTR_UNIQUE;
2494 n->deferrable = ($7 & 1) != 0;
2495 n->initdeferred = ($7 & 2) != 0;
2498 | PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace
2499 ConstraintAttributeSpec
2501 Constraint *n = makeNode(Constraint);
2502 n->contype = CONSTR_PRIMARY;
2507 n->deferrable = ($8 & 1) != 0;
2508 n->initdeferred = ($8 & 2) != 0;
2511 | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
2512 opt_definition OptConsTableSpace ExclusionWhereClause
2513 ConstraintAttributeSpec
2515 Constraint *n = makeNode(Constraint);
2516 n->contype = CONSTR_EXCLUSION;
2518 n->access_method = $2;
2522 n->where_clause = $8;
2523 n->deferrable = ($9 & 1) != 0;
2524 n->initdeferred = ($9 & 2) != 0;
2527 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
2528 opt_column_list key_match key_actions ConstraintAttributeSpec
2530 Constraint *n = makeNode(Constraint);
2531 n->contype = CONSTR_FOREIGN;
2536 n->fk_matchtype = $9;
2537 n->fk_upd_action = (char) ($10 >> 8);
2538 n->fk_del_action = (char) ($10 & 0xFF);
2539 n->skip_validation = FALSE;
2540 n->deferrable = ($11 & 1) != 0;
2541 n->initdeferred = ($11 & 2) != 0;
2547 '(' columnList ')' { $$ = $2; }
2548 | /*EMPTY*/ { $$ = NIL; }
2552 columnElem { $$ = list_make1($1); }
2553 | columnList ',' columnElem { $$ = lappend($1, $3); }
2558 $$ = (Node *) makeString($1);
2562 key_match: MATCH FULL
2564 $$ = FKCONSTR_MATCH_FULL;
2569 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2570 errmsg("MATCH PARTIAL not yet implemented"),
2571 parser_errposition(@1)));
2572 $$ = FKCONSTR_MATCH_PARTIAL;
2576 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2580 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2584 ExclusionConstraintList:
2585 ExclusionConstraintElem { $$ = list_make1($1); }
2586 | ExclusionConstraintList ',' ExclusionConstraintElem
2587 { $$ = lappend($1, $3); }
2590 ExclusionConstraintElem: index_elem WITH any_operator
2592 $$ = list_make2($1, $3);
2594 /* allow OPERATOR() decoration for the benefit of ruleutils.c */
2595 | index_elem WITH OPERATOR '(' any_operator ')'
2597 $$ = list_make2($1, $5);
2601 ExclusionWhereClause:
2602 WHERE '(' a_expr ')' { $$ = $3; }
2603 | /*EMPTY*/ { $$ = NULL; }
2607 * We combine the update and delete actions into one value temporarily
2608 * for simplicity of parsing, and then break them down again in the
2609 * calling production. update is in the left 8 bits, delete in the right.
2610 * Note that NOACTION is the default.
2614 { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2616 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
2617 | key_update key_delete
2618 { $$ = ($1 << 8) | ($2 & 0xFF); }
2619 | key_delete key_update
2620 { $$ = ($2 << 8) | ($1 & 0xFF); }
2622 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2625 key_update: ON UPDATE key_action { $$ = $3; }
2628 key_delete: ON DELETE_P key_action { $$ = $3; }
2632 NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; }
2633 | RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; }
2634 | CASCADE { $$ = FKCONSTR_ACTION_CASCADE; }
2635 | SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; }
2636 | SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; }
2639 OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
2640 | /*EMPTY*/ { $$ = NIL; }
2643 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
2645 WITH reloptions { $$ = $2; }
2646 | WITH OIDS { $$ = list_make1(defWithOids(true)); }
2647 | WITHOUT OIDS { $$ = list_make1(defWithOids(false)); }
2648 | /*EMPTY*/ { $$ = NIL; }
2651 OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
2652 | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
2653 | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
2654 | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
2657 OptTableSpace: TABLESPACE name { $$ = $2; }
2658 | /*EMPTY*/ { $$ = NULL; }
2661 OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
2662 | /*EMPTY*/ { $$ = NULL; }
2667 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
2672 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
2675 * When the SelectStmt is a set-operation tree, we must
2676 * stuff the INTO information into the leftmost component
2677 * Select, because that's where analyze.c will expect
2678 * to find it. Similarly, the output column names must
2679 * be attached to that Select's target list.
2681 SelectStmt *n = findLeftmostSelect((SelectStmt *) $6);
2682 if (n->intoClause != NULL)
2684 (errcode(ERRCODE_SYNTAX_ERROR),
2685 errmsg("CREATE TABLE AS cannot specify INTO"),
2686 parser_errposition(exprLocation((Node *) n->intoClause))));
2687 $4->rel->istemp = $2;
2689 /* Implement WITH NO DATA by forcing top-level LIMIT 0 */
2691 ((SelectStmt *) $6)->limitCount = makeIntConst(0, -1);
2697 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
2699 $$ = makeNode(IntoClause);
2704 $$->tableSpaceName = $5;
2709 '(' CreateAsList ')' { $$ = $2; }
2710 | /*EMPTY*/ { $$ = NIL; }
2714 CreateAsElement { $$ = list_make1($1); }
2715 | CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); }
2721 ColumnDef *n = makeNode(ColumnDef);
2726 n->is_not_null = false;
2727 n->raw_default = NULL;
2728 n->cooked_default = NULL;
2729 n->constraints = NIL;
2735 WITH DATA_P { $$ = TRUE; }
2736 | WITH NO DATA_P { $$ = FALSE; }
2737 | /*EMPTY*/ { $$ = TRUE; }
2741 /*****************************************************************************
2744 * CREATE SEQUENCE seqname
2745 * ALTER SEQUENCE seqname
2747 *****************************************************************************/
2750 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
2752 CreateSeqStmt *n = makeNode(CreateSeqStmt);
2761 ALTER SEQUENCE qualified_name SeqOptList
2763 AlterSeqStmt *n = makeNode(AlterSeqStmt);
2770 OptSeqOptList: SeqOptList { $$ = $1; }
2771 | /*EMPTY*/ { $$ = NIL; }
2774 SeqOptList: SeqOptElem { $$ = list_make1($1); }
2775 | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
2778 SeqOptElem: CACHE NumericOnly
2780 $$ = makeDefElem("cache", (Node *)$2);
2784 $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE));
2788 $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE));
2790 | INCREMENT opt_by NumericOnly
2792 $$ = makeDefElem("increment", (Node *)$3);
2794 | MAXVALUE NumericOnly
2796 $$ = makeDefElem("maxvalue", (Node *)$2);
2798 | MINVALUE NumericOnly
2800 $$ = makeDefElem("minvalue", (Node *)$2);
2804 $$ = makeDefElem("maxvalue", NULL);
2808 $$ = makeDefElem("minvalue", NULL);
2812 $$ = makeDefElem("owned_by", (Node *)$3);
2814 | START opt_with NumericOnly
2816 $$ = makeDefElem("start", (Node *)$3);
2820 $$ = makeDefElem("restart", NULL);
2822 | RESTART opt_with NumericOnly
2824 $$ = makeDefElem("restart", (Node *)$3);
2833 FCONST { $$ = makeFloat($1); }
2839 | SignedIconst { $$ = makeInteger($1); }
2842 /*****************************************************************************
2845 * CREATE PROCEDURAL LANGUAGE ...
2846 * DROP PROCEDURAL LANGUAGE ...
2848 *****************************************************************************/
2851 CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2853 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2855 /* parameters are all to be supplied by system */
2858 n->plvalidator = NIL;
2859 n->pltrusted = false;
2862 | CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2863 HANDLER handler_name opt_inline_handler opt_validator
2865 CreatePLangStmt *n = makeNode(CreatePLangStmt);
2869 n->plvalidator = $9;
2876 TRUSTED { $$ = TRUE; }
2877 | /*EMPTY*/ { $$ = FALSE; }
2880 /* This ought to be just func_name, but that causes reduce/reduce conflicts
2881 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
2882 * Work around by using simple names, instead.
2885 name { $$ = list_make1(makeString($1)); }
2886 | name attrs { $$ = lcons(makeString($1), $2); }
2890 INLINE_P handler_name { $$ = $2; }
2891 | /*EMPTY*/ { $$ = NIL; }
2895 VALIDATOR handler_name { $$ = $2; }
2896 | NO VALIDATOR { $$ = NIL; }
2900 validator_clause { $$ = $1; }
2901 | /*EMPTY*/ { $$ = NIL; }
2905 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
2907 DropPLangStmt *n = makeNode(DropPLangStmt);
2910 n->missing_ok = false;
2913 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
2915 DropPLangStmt *n = makeNode(DropPLangStmt);
2918 n->missing_ok = true;
2928 /*****************************************************************************
2931 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
2933 *****************************************************************************/
2935 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
2937 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
2938 n->tablespacename = $3;
2945 OptTableSpaceOwner: OWNER name { $$ = $2; }
2946 | /*EMPTY */ { $$ = NULL; }
2949 /*****************************************************************************
2952 * DROP TABLESPACE <tablespace>
2954 * No need for drop behaviour as we cannot implement dependencies for
2955 * objects in other databases; we can only support RESTRICT.
2957 ****************************************************************************/
2959 DropTableSpaceStmt: DROP TABLESPACE name
2961 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2962 n->tablespacename = $3;
2963 n->missing_ok = false;
2966 | DROP TABLESPACE IF_P EXISTS name
2968 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2969 n->tablespacename = $5;
2970 n->missing_ok = true;
2975 /*****************************************************************************
2978 * CREATE FOREIGN DATA WRAPPER name [ VALIDATOR name ]
2980 *****************************************************************************/
2982 CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_validator create_generic_options
2984 CreateFdwStmt *n = makeNode(CreateFdwStmt);
2992 /*****************************************************************************
2995 * DROP FOREIGN DATA WRAPPER name
2997 ****************************************************************************/
2999 DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
3001 DropFdwStmt *n = makeNode(DropFdwStmt);
3003 n->missing_ok = false;
3007 | DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior
3009 DropFdwStmt *n = makeNode(DropFdwStmt);
3011 n->missing_ok = true;
3017 /*****************************************************************************
3020 * ALTER FOREIGN DATA WRAPPER name
3022 ****************************************************************************/
3024 AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name validator_clause alter_generic_options
3026 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3029 n->change_validator = true;
3033 | ALTER FOREIGN DATA_P WRAPPER name validator_clause
3035 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3038 n->change_validator = true;
3041 | ALTER FOREIGN DATA_P WRAPPER name alter_generic_options
3043 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3050 /* Options definition for CREATE FDW, SERVER and USER MAPPING */
3051 create_generic_options:
3052 OPTIONS '(' generic_option_list ')' { $$ = $3; }
3053 | /*EMPTY*/ { $$ = NIL; }
3056 generic_option_list:
3059 $$ = list_make1($1);
3061 | generic_option_list ',' generic_option_elem
3063 $$ = lappend($1, $3);
3067 /* Options definition for ALTER FDW, SERVER and USER MAPPING */
3068 alter_generic_options:
3069 OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
3072 alter_generic_option_list:
3073 alter_generic_option_elem
3075 $$ = list_make1($1);
3077 | alter_generic_option_list ',' alter_generic_option_elem
3079 $$ = lappend($1, $3);
3083 alter_generic_option_elem:
3088 | SET generic_option_elem
3091 $$->defaction = DEFELEM_SET;
3093 | ADD_P generic_option_elem
3096 $$->defaction = DEFELEM_ADD;
3098 | DROP generic_option_name
3100 $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP);
3104 generic_option_elem:
3105 generic_option_name generic_option_arg
3107 $$ = makeDefElem($1, $2);
3111 generic_option_name:
3112 ColLabel { $$ = $1; }
3115 /* We could use def_arg here, but the spec only requires string literals */
3117 Sconst { $$ = (Node *) makeString($1); }
3120 /*****************************************************************************
3123 * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
3125 *****************************************************************************/
3127 CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
3128 FOREIGN DATA_P WRAPPER name create_generic_options
3130 CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
3141 TYPE_P Sconst { $$ = $2; }
3142 | /*EMPTY*/ { $$ = NULL; }
3146 foreign_server_version:
3147 VERSION_P Sconst { $$ = $2; }
3148 | VERSION_P NULL_P { $$ = NULL; }
3151 opt_foreign_server_version:
3152 foreign_server_version { $$ = $1; }
3153 | /*EMPTY*/ { $$ = NULL; }
3156 /*****************************************************************************
3161 ****************************************************************************/
3163 DropForeignServerStmt: DROP SERVER name opt_drop_behavior
3165 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3167 n->missing_ok = false;
3171 | DROP SERVER IF_P EXISTS name opt_drop_behavior
3173 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3175 n->missing_ok = true;
3181 /*****************************************************************************
3184 * ALTER SERVER name [VERSION] [OPTIONS]
3186 ****************************************************************************/
3188 AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
3190 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3194 n->has_version = true;
3197 | ALTER SERVER name foreign_server_version
3199 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3202 n->has_version = true;
3205 | ALTER SERVER name alter_generic_options
3207 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3214 /*****************************************************************************
3217 * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
3219 *****************************************************************************/
3221 CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
3223 CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
3231 /* User mapping authorization identifier */
3233 CURRENT_USER { $$ = "current_user"; }
3234 | USER { $$ = "current_user"; }
3235 | RoleId { $$ = (strcmp($1, "public") == 0) ? NULL : $1; }
3238 /*****************************************************************************
3241 * DROP USER MAPPING FOR auth_ident SERVER name
3243 ****************************************************************************/
3245 DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
3247 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3250 n->missing_ok = false;
3253 | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
3255 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3258 n->missing_ok = true;
3263 /*****************************************************************************
3266 * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
3268 ****************************************************************************/
3270 AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
3272 AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
3280 /*****************************************************************************
3283 * CREATE TRIGGER ...
3286 *****************************************************************************/
3289 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
3290 qualified_name TriggerForSpec TriggerWhen
3291 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3293 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3300 n->events = intVal(linitial($5));
3301 n->columns = (List *) lsecond($5);
3303 n->isconstraint = FALSE;
3304 n->deferrable = FALSE;
3305 n->initdeferred = FALSE;
3306 n->constrrel = NULL;
3309 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
3310 qualified_name OptConstrFromTable ConstraintAttributeSpec
3311 FOR EACH ROW TriggerWhen
3312 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3314 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3321 n->events = intVal(linitial($6));
3322 n->columns = (List *) lsecond($6);
3323 n->whenClause = $14;
3324 n->isconstraint = TRUE;
3325 n->deferrable = ($10 & 1) != 0;
3326 n->initdeferred = ($10 & 2) != 0;
3333 BEFORE { $$ = TRUE; }
3334 | AFTER { $$ = FALSE; }
3340 | TriggerEvents OR TriggerOneEvent
3342 int events1 = intVal(linitial($1));
3343 int events2 = intVal(linitial($3));
3344 List *columns1 = (List *) lsecond($1);
3345 List *columns2 = (List *) lsecond($3);
3347 if (events1 & events2)
3348 parser_yyerror("duplicate trigger events specified");
3350 * concat'ing the columns lists loses information about
3351 * which columns went with which event, but so long as
3352 * only UPDATE carries columns and we disallow multiple
3353 * UPDATE items, it doesn't matter. Command execution
3354 * should just ignore the columns for non-UPDATE events.
3356 $$ = list_make2(makeInteger(events1 | events2),
3357 list_concat(columns1, columns2));
3363 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
3365 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
3367 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
3368 | UPDATE OF columnList
3369 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
3371 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
3375 FOR TriggerForOpt TriggerForType
3382 * If ROW/STATEMENT not specified, default to
3383 * STATEMENT, per SQL
3396 | STATEMENT { $$ = FALSE; }
3400 WHEN '(' a_expr ')' { $$ = $3; }
3401 | /*EMPTY*/ { $$ = NULL; }
3405 TriggerFuncArg { $$ = list_make1($1); }
3406 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
3407 | /*EMPTY*/ { $$ = NIL; }
3414 snprintf(buf, sizeof(buf), "%d", $1);
3415 $$ = makeString(pstrdup(buf));
3417 | FCONST { $$ = makeString($1); }
3418 | Sconst { $$ = makeString($1); }
3419 | BCONST { $$ = makeString($1); }
3420 | XCONST { $$ = makeString($1); }
3421 | ColId { $$ = makeString($1); }
3425 FROM qualified_name { $$ = $2; }
3426 | /*EMPTY*/ { $$ = NULL; }
3429 ConstraintAttributeSpec:
3430 ConstraintDeferrabilitySpec
3432 | ConstraintDeferrabilitySpec ConstraintTimeSpec
3434 if ($1 == 0 && $2 != 0)
3436 (errcode(ERRCODE_SYNTAX_ERROR),
3437 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3438 parser_errposition(@1)));
3441 | ConstraintTimeSpec
3448 | ConstraintTimeSpec ConstraintDeferrabilitySpec
3450 if ($2 == 0 && $1 != 0)
3452 (errcode(ERRCODE_SYNTAX_ERROR),
3453 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3454 parser_errposition(@1)));
3461 ConstraintDeferrabilitySpec:
3462 NOT DEFERRABLE { $$ = 0; }
3463 | DEFERRABLE { $$ = 1; }
3467 INITIALLY IMMEDIATE { $$ = 0; }
3468 | INITIALLY DEFERRED { $$ = 2; }
3473 DROP TRIGGER name ON qualified_name opt_drop_behavior
3475 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3479 n->removeType = OBJECT_TRIGGER;
3480 n->missing_ok = false;
3483 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
3485 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3489 n->removeType = OBJECT_TRIGGER;
3490 n->missing_ok = true;
3496 /*****************************************************************************
3499 * CREATE ASSERTION ...
3500 * DROP ASSERTION ...
3502 *****************************************************************************/
3505 CREATE ASSERTION name CHECK '(' a_expr ')'
3506 ConstraintAttributeSpec
3508 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3510 n->args = list_make1($6);
3511 n->isconstraint = TRUE;
3512 n->deferrable = ($8 & 1) != 0;
3513 n->initdeferred = ($8 & 2) != 0;
3516 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3517 errmsg("CREATE ASSERTION is not yet implemented")));
3524 DROP ASSERTION name opt_drop_behavior
3526 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3530 n->removeType = OBJECT_TRIGGER; /* XXX */
3532 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3533 errmsg("DROP ASSERTION is not yet implemented")));
3539 /*****************************************************************************
3542 * define (aggregate,operator,type)
3544 *****************************************************************************/
3547 CREATE AGGREGATE func_name aggr_args definition
3549 DefineStmt *n = makeNode(DefineStmt);
3550 n->kind = OBJECT_AGGREGATE;
3551 n->oldstyle = false;
3557 | CREATE AGGREGATE func_name old_aggr_definition
3559 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
3560 DefineStmt *n = makeNode(DefineStmt);
3561 n->kind = OBJECT_AGGREGATE;
3568 | CREATE OPERATOR any_operator definition
3570 DefineStmt *n = makeNode(DefineStmt);
3571 n->kind = OBJECT_OPERATOR;
3572 n->oldstyle = false;
3578 | CREATE TYPE_P any_name definition
3580 DefineStmt *n = makeNode(DefineStmt);
3581 n->kind = OBJECT_TYPE;
3582 n->oldstyle = false;
3588 | CREATE TYPE_P any_name
3590 /* Shell type (identified by lack of definition) */
3591 DefineStmt *n = makeNode(DefineStmt);
3592 n->kind = OBJECT_TYPE;
3593 n->oldstyle = false;
3596 n->definition = NIL;
3599 | CREATE TYPE_P any_name AS '(' TableFuncElementList ')'
3601 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
3602 RangeVar *r = makeNode(RangeVar);
3604 /* can't use qualified_name, sigh */
3605 switch (list_length($3))
3608 r->catalogname = NULL;
3609 r->schemaname = NULL;
3610 r->relname = strVal(linitial($3));
3613 r->catalogname = NULL;
3614 r->schemaname = strVal(linitial($3));
3615 r->relname = strVal(lsecond($3));
3618 r->catalogname = strVal(linitial($3));
3619 r->schemaname = strVal(lsecond($3));
3620 r->relname = strVal(lthird($3));
3624 (errcode(ERRCODE_SYNTAX_ERROR),
3625 errmsg("improper qualified name (too many dotted names): %s",
3626 NameListToString($3)),
3627 parser_errposition(@3)));
3635 | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
3637 CreateEnumStmt *n = makeNode(CreateEnumStmt);
3642 | CREATE TEXT_P SEARCH PARSER any_name definition
3644 DefineStmt *n = makeNode(DefineStmt);
3645 n->kind = OBJECT_TSPARSER;
3651 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
3653 DefineStmt *n = makeNode(DefineStmt);
3654 n->kind = OBJECT_TSDICTIONARY;
3660 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
3662 DefineStmt *n = makeNode(DefineStmt);
3663 n->kind = OBJECT_TSTEMPLATE;
3669 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
3671 DefineStmt *n = makeNode(DefineStmt);
3672 n->kind = OBJECT_TSCONFIGURATION;
3680 definition: '(' def_list ')' { $$ = $2; }
3683 def_list: def_elem { $$ = list_make1($1); }
3684 | def_list ',' def_elem { $$ = lappend($1, $3); }
3687 def_elem: ColLabel '=' def_arg
3689 $$ = makeDefElem($1, (Node *) $3);
3693 $$ = makeDefElem($1, NULL);
3697 /* Note: any simple identifier will be returned as a type name! */
3698 def_arg: func_type { $$ = (Node *)$1; }
3699 | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
3700 | qual_all_Op { $$ = (Node *)$1; }
3701 | NumericOnly { $$ = (Node *)$1; }
3702 | Sconst { $$ = (Node *)makeString($1); }
3705 aggr_args: '(' type_list ')' { $$ = $2; }
3706 | '(' '*' ')' { $$ = NIL; }
3709 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
3712 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
3713 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
3717 * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
3718 * the item names needed in old aggregate definitions are likely to become
3721 old_aggr_elem: IDENT '=' def_arg
3723 $$ = makeDefElem($1, (Node *)$3);
3728 enum_val_list { $$ = $1; }
3729 | /*EMPTY*/ { $$ = NIL; }
3732 enum_val_list: Sconst
3733 { $$ = list_make1(makeString($1)); }
3734 | enum_val_list ',' Sconst
3735 { $$ = lappend($1, makeString($3)); }
3739 /*****************************************************************************
3742 * CREATE OPERATOR CLASS ...
3743 * CREATE OPERATOR FAMILY ...
3744 * ALTER OPERATOR FAMILY ...
3745 * DROP OPERATOR CLASS ...
3746 * DROP OPERATOR FAMILY ...
3748 *****************************************************************************/
3751 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
3752 USING access_method opt_opfamily AS opclass_item_list
3754 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
3755 n->opclassname = $4;
3759 n->opfamilyname = $11;
3766 opclass_item { $$ = list_make1($1); }
3767 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
3771 OPERATOR Iconst any_operator opt_recheck
3773 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3774 n->itemtype = OPCLASS_ITEM_OPERATOR;
3780 | OPERATOR Iconst any_operator oper_argtypes opt_recheck
3782 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3783 n->itemtype = OPCLASS_ITEM_OPERATOR;
3789 | FUNCTION Iconst func_name func_args
3791 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3792 n->itemtype = OPCLASS_ITEM_FUNCTION;
3794 n->args = extractArgTypes($4);
3798 | FUNCTION Iconst '(' type_list ')' func_name func_args
3800 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3801 n->itemtype = OPCLASS_ITEM_FUNCTION;
3803 n->args = extractArgTypes($7);
3810 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3811 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
3817 opt_default: DEFAULT { $$ = TRUE; }
3818 | /*EMPTY*/ { $$ = FALSE; }
3821 opt_opfamily: FAMILY any_name { $$ = $2; }
3822 | /*EMPTY*/ { $$ = NIL; }
3825 opt_recheck: RECHECK
3828 * RECHECK no longer does anything in opclass definitions,
3829 * but we still accept it to ease porting of old database
3833 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3834 errmsg("RECHECK is no longer required"),
3835 errhint("Update your data type."),
3836 parser_errposition(@1)));
3839 | /*EMPTY*/ { $$ = FALSE; }
3844 CREATE OPERATOR FAMILY any_name USING access_method
3846 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
3847 n->opfamilyname = $4;
3854 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
3856 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3857 n->opfamilyname = $4;
3863 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
3865 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3866 n->opfamilyname = $4;
3875 opclass_drop { $$ = list_make1($1); }
3876 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
3880 OPERATOR Iconst '(' type_list ')'
3882 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3883 n->itemtype = OPCLASS_ITEM_OPERATOR;
3888 | FUNCTION Iconst '(' type_list ')'
3890 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3891 n->itemtype = OPCLASS_ITEM_FUNCTION;
3900 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
3902 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3903 n->opclassname = $4;
3906 n->missing_ok = false;
3909 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
3911 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
3912 n->opclassname = $6;
3915 n->missing_ok = true;
3921 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
3923 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3924 n->opfamilyname = $4;
3927 n->missing_ok = false;
3930 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
3932 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
3933 n->opfamilyname = $6;
3936 n->missing_ok = true;
3942 /*****************************************************************************
3946 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
3947 * REASSIGN OWNED BY username [, username ...] TO username
3949 *****************************************************************************/
3951 DROP OWNED BY name_list opt_drop_behavior
3953 DropOwnedStmt *n = makeNode(DropOwnedStmt);
3961 REASSIGN OWNED BY name_list TO name
3963 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
3970 /*****************************************************************************
3974 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
3975 * [ RESTRICT | CASCADE ]
3977 *****************************************************************************/
3979 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
3981 DropStmt *n = makeNode(DropStmt);
3983 n->missing_ok = TRUE;
3988 | DROP drop_type any_name_list opt_drop_behavior
3990 DropStmt *n = makeNode(DropStmt);
3992 n->missing_ok = FALSE;
4000 drop_type: TABLE { $$ = OBJECT_TABLE; }
4001 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4002 | VIEW { $$ = OBJECT_VIEW; }
4003 | INDEX { $$ = OBJECT_INDEX; }
4004 | TYPE_P { $$ = OBJECT_TYPE; }
4005 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
4006 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4007 | SCHEMA { $$ = OBJECT_SCHEMA; }
4008 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
4009 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
4010 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
4011 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
4015 any_name { $$ = list_make1($1); }
4016 | any_name_list ',' any_name { $$ = lappend($1, $3); }
4019 any_name: ColId { $$ = list_make1(makeString($1)); }
4020 | ColId attrs { $$ = lcons(makeString($1), $2); }
4023 attrs: '.' attr_name
4024 { $$ = list_make1(makeString($2)); }
4025 | attrs '.' attr_name
4026 { $$ = lappend($1, makeString($3)); }
4030 /*****************************************************************************
4033 * truncate table relname1, relname2, ...
4035 *****************************************************************************/
4038 TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
4040 TruncateStmt *n = makeNode(TruncateStmt);
4042 n->restart_seqs = $4;
4049 CONTINUE_P IDENTITY_P { $$ = false; }
4050 | RESTART IDENTITY_P { $$ = true; }
4051 | /* EMPTY */ { $$ = false; }
4054 /*****************************************************************************
4056 * The COMMENT ON statement can take different forms based upon the type of
4057 * the object associated with the comment. The form of the statement is:
4059 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
4060 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
4061 * CAST | COLUMN | SCHEMA | TABLESPACE | ROLE |
4062 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
4063 * TEXT SEARCH TEMPLATE |
4064 * TEXT SEARCH CONFIGURATION ] <objname> |
4065 * AGGREGATE <aggname> (arg1, ...) |
4066 * FUNCTION <funcname> (arg1, arg2, ...) |
4067 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
4068 * TRIGGER <triggername> ON <relname> |
4069 * CONSTRAINT <constraintname> ON <relname> |
4070 * RULE <rulename> ON <relname> ]
4073 *****************************************************************************/
4076 COMMENT ON comment_type any_name IS comment_text
4078 CommentStmt *n = makeNode(CommentStmt);
4085 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
4087 CommentStmt *n = makeNode(CommentStmt);
4088 n->objtype = OBJECT_AGGREGATE;
4094 | COMMENT ON FUNCTION func_name func_args IS comment_text
4096 CommentStmt *n = makeNode(CommentStmt);
4097 n->objtype = OBJECT_FUNCTION;
4099 n->objargs = extractArgTypes($5);
4103 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
4105 CommentStmt *n = makeNode(CommentStmt);
4106 n->objtype = OBJECT_OPERATOR;
4112 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
4114 CommentStmt *n = makeNode(CommentStmt);
4115 n->objtype = OBJECT_CONSTRAINT;
4116 n->objname = lappend($6, makeString($4));
4121 | COMMENT ON RULE name ON any_name IS comment_text
4123 CommentStmt *n = makeNode(CommentStmt);
4124 n->objtype = OBJECT_RULE;
4125 n->objname = lappend($6, makeString($4));
4130 | COMMENT ON RULE name IS comment_text
4132 /* Obsolete syntax supported for awhile for compatibility */
4133 CommentStmt *n = makeNode(CommentStmt);
4134 n->objtype = OBJECT_RULE;
4135 n->objname = list_make1(makeString($4));
4140 | COMMENT ON TRIGGER name ON any_name IS comment_text
4142 CommentStmt *n = makeNode(CommentStmt);
4143 n->objtype = OBJECT_TRIGGER;
4144 n->objname = lappend($6, makeString($4));
4149 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
4151 CommentStmt *n = makeNode(CommentStmt);
4152 n->objtype = OBJECT_OPCLASS;
4154 n->objargs = list_make1(makeString($7));
4158 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
4160 CommentStmt *n = makeNode(CommentStmt);
4161 n->objtype = OBJECT_OPFAMILY;
4163 n->objargs = list_make1(makeString($7));
4167 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
4169 CommentStmt *n = makeNode(CommentStmt);
4170 n->objtype = OBJECT_LARGEOBJECT;
4171 n->objname = list_make1($5);
4176 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
4178 CommentStmt *n = makeNode(CommentStmt);
4179 n->objtype = OBJECT_CAST;
4180 n->objname = list_make1($5);
4181 n->objargs = list_make1($7);
4185 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
4187 CommentStmt *n = makeNode(CommentStmt);
4188 n->objtype = OBJECT_LANGUAGE;
4194 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
4196 CommentStmt *n = makeNode(CommentStmt);
4197 n->objtype = OBJECT_TSPARSER;
4202 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
4204 CommentStmt *n = makeNode(CommentStmt);
4205 n->objtype = OBJECT_TSDICTIONARY;
4210 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
4212 CommentStmt *n = makeNode(CommentStmt);
4213 n->objtype = OBJECT_TSTEMPLATE;
4218 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
4220 CommentStmt *n = makeNode(CommentStmt);
4221 n->objtype = OBJECT_TSCONFIGURATION;
4229 COLUMN { $$ = OBJECT_COLUMN; }
4230 | DATABASE { $$ = OBJECT_DATABASE; }
4231 | SCHEMA { $$ = OBJECT_SCHEMA; }
4232 | INDEX { $$ = OBJECT_INDEX; }
4233 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4234 | TABLE { $$ = OBJECT_TABLE; }
4235 | DOMAIN_P { $$ = OBJECT_TYPE; }
4236 | TYPE_P { $$ = OBJECT_TYPE; }
4237 | VIEW { $$ = OBJECT_VIEW; }
4238 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4239 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
4240 | ROLE { $$ = OBJECT_ROLE; }
4245 | NULL_P { $$ = NULL; }
4248 /*****************************************************************************
4253 *****************************************************************************/
4255 FetchStmt: FETCH fetch_args
4257 FetchStmt *n = (FetchStmt *) $2;
4263 FetchStmt *n = (FetchStmt *) $2;
4269 fetch_args: cursor_name
4271 FetchStmt *n = makeNode(FetchStmt);
4273 n->direction = FETCH_FORWARD;
4277 | from_in cursor_name
4279 FetchStmt *n = makeNode(FetchStmt);
4281 n->direction = FETCH_FORWARD;
4285 | NEXT opt_from_in cursor_name
4287 FetchStmt *n = makeNode(FetchStmt);
4289 n->direction = FETCH_FORWARD;
4293 | PRIOR opt_from_in cursor_name
4295 FetchStmt *n = makeNode(FetchStmt);
4297 n->direction = FETCH_BACKWARD;
4301 | FIRST_P opt_from_in cursor_name
4303 FetchStmt *n = makeNode(FetchStmt);
4305 n->direction = FETCH_ABSOLUTE;
4309 | LAST_P opt_from_in cursor_name
4311 FetchStmt *n = makeNode(FetchStmt);
4313 n->direction = FETCH_ABSOLUTE;
4317 | ABSOLUTE_P SignedIconst opt_from_in cursor_name
4319 FetchStmt *n = makeNode(FetchStmt);
4321 n->direction = FETCH_ABSOLUTE;
4325 | RELATIVE_P SignedIconst opt_from_in cursor_name
4327 FetchStmt *n = makeNode(FetchStmt);
4329 n->direction = FETCH_RELATIVE;
4333 | SignedIconst opt_from_in cursor_name
4335 FetchStmt *n = makeNode(FetchStmt);
4337 n->direction = FETCH_FORWARD;
4341 | ALL opt_from_in cursor_name
4343 FetchStmt *n = makeNode(FetchStmt);
4345 n->direction = FETCH_FORWARD;
4346 n->howMany = FETCH_ALL;
4349 | FORWARD opt_from_in cursor_name
4351 FetchStmt *n = makeNode(FetchStmt);
4353 n->direction = FETCH_FORWARD;
4357 | FORWARD SignedIconst opt_from_in cursor_name
4359 FetchStmt *n = makeNode(FetchStmt);
4361 n->direction = FETCH_FORWARD;
4365 | FORWARD ALL opt_from_in cursor_name
4367 FetchStmt *n = makeNode(FetchStmt);
4369 n->direction = FETCH_FORWARD;
4370 n->howMany = FETCH_ALL;
4373 | BACKWARD opt_from_in cursor_name
4375 FetchStmt *n = makeNode(FetchStmt);
4377 n->direction = FETCH_BACKWARD;
4381 | BACKWARD SignedIconst opt_from_in cursor_name
4383 FetchStmt *n = makeNode(FetchStmt);
4385 n->direction = FETCH_BACKWARD;
4389 | BACKWARD ALL opt_from_in cursor_name
4391 FetchStmt *n = makeNode(FetchStmt);
4393 n->direction = FETCH_BACKWARD;
4394 n->howMany = FETCH_ALL;
4403 opt_from_in: from_in {}
4408 /*****************************************************************************
4410 * GRANT and REVOKE statements
4412 *****************************************************************************/
4414 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
4415 opt_grant_grant_option
4417 GrantStmt *n = makeNode(GrantStmt);
4420 n->targtype = ($4)->targtype;
4421 n->objtype = ($4)->objtype;
4422 n->objects = ($4)->objs;
4424 n->grant_option = $7;
4430 REVOKE privileges ON privilege_target
4431 FROM grantee_list opt_drop_behavior
4433 GrantStmt *n = makeNode(GrantStmt);
4434 n->is_grant = false;
4435 n->grant_option = false;
4437 n->targtype = ($4)->targtype;
4438 n->objtype = ($4)->objtype;
4439 n->objects = ($4)->objs;
4444 | REVOKE GRANT OPTION FOR privileges ON privilege_target
4445 FROM grantee_list opt_drop_behavior
4447 GrantStmt *n = makeNode(GrantStmt);
4448 n->is_grant = false;
4449 n->grant_option = true;
4451 n->targtype = ($7)->targtype;
4452 n->objtype = ($7)->objtype;
4453 n->objects = ($7)->objs;
4462 * Privilege names are represented as strings; the validity of the privilege
4463 * names gets checked at execution. This is a bit annoying but we have little
4464 * choice because of the syntactic conflict with lists of role names in
4465 * GRANT/REVOKE. What's more, we have to call out in the "privilege"
4466 * production any reserved keywords that need to be usable as privilege names.
4469 /* either ALL [PRIVILEGES] or a list of individual privileges */
4470 privileges: privilege_list
4476 | ALL '(' columnList ')'
4478 AccessPriv *n = makeNode(AccessPriv);
4479 n->priv_name = NULL;
4483 | ALL PRIVILEGES '(' columnList ')'
4485 AccessPriv *n = makeNode(AccessPriv);
4486 n->priv_name = NULL;
4492 privilege_list: privilege { $$ = list_make1($1); }
4493 | privilege_list ',' privilege { $$ = lappend($1, $3); }
4496 privilege: SELECT opt_column_list
4498 AccessPriv *n = makeNode(AccessPriv);
4499 n->priv_name = pstrdup($1);
4503 | REFERENCES opt_column_list
4505 AccessPriv *n = makeNode(AccessPriv);
4506 n->priv_name = pstrdup($1);
4510 | CREATE opt_column_list
4512 AccessPriv *n = makeNode(AccessPriv);
4513 n->priv_name = pstrdup($1);
4517 | ColId opt_column_list
4519 AccessPriv *n = makeNode(AccessPriv);
4527 /* Don't bother trying to fold the first two rules into one using
4528 * opt_table. You're going to get conflicts.
4533 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4534 n->targtype = ACL_TARGET_OBJECT;
4535 n->objtype = ACL_OBJECT_RELATION;
4539 | TABLE qualified_name_list
4541 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4542 n->targtype = ACL_TARGET_OBJECT;
4543 n->objtype = ACL_OBJECT_RELATION;
4547 | SEQUENCE qualified_name_list
4549 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4550 n->targtype = ACL_TARGET_OBJECT;
4551 n->objtype = ACL_OBJECT_SEQUENCE;
4555 | FOREIGN DATA_P WRAPPER name_list
4557 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4558 n->targtype = ACL_TARGET_OBJECT;
4559 n->objtype = ACL_OBJECT_FDW;
4563 | FOREIGN SERVER name_list
4565 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4566 n->targtype = ACL_TARGET_OBJECT;
4567 n->objtype = ACL_OBJECT_FOREIGN_SERVER;
4571 | FUNCTION function_with_argtypes_list
4573 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4574 n->targtype = ACL_TARGET_OBJECT;
4575 n->objtype = ACL_OBJECT_FUNCTION;
4579 | DATABASE name_list
4581 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4582 n->targtype = ACL_TARGET_OBJECT;
4583 n->objtype = ACL_OBJECT_DATABASE;
4587 | LANGUAGE name_list
4589 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4590 n->targtype = ACL_TARGET_OBJECT;
4591 n->objtype = ACL_OBJECT_LANGUAGE;
4595 | LARGE_P OBJECT_P Iconst_list
4597 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4598 n->targtype = ACL_TARGET_OBJECT;
4599 n->objtype = ACL_OBJECT_LARGEOBJECT;
4605 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4606 n->targtype = ACL_TARGET_OBJECT;
4607 n->objtype = ACL_OBJECT_NAMESPACE;
4611 | TABLESPACE name_list
4613 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4614 n->targtype = ACL_TARGET_OBJECT;
4615 n->objtype = ACL_OBJECT_TABLESPACE;
4619 | ALL TABLES IN_P SCHEMA name_list
4621 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4622 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4623 n->objtype = ACL_OBJECT_RELATION;
4627 | ALL SEQUENCES IN_P SCHEMA name_list
4629 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4630 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4631 n->objtype = ACL_OBJECT_SEQUENCE;
4635 | ALL FUNCTIONS IN_P SCHEMA name_list
4637 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4638 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4639 n->objtype = ACL_OBJECT_FUNCTION;
4647 grantee { $$ = list_make1($1); }
4648 | grantee_list ',' grantee { $$ = lappend($1, $3); }
4653 PrivGrantee *n = makeNode(PrivGrantee);
4654 /* This hack lets us avoid reserving PUBLIC as a keyword*/
4655 if (strcmp($1, "public") == 0)
4663 PrivGrantee *n = makeNode(PrivGrantee);
4664 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
4665 if (strcmp($2, "public") == 0)
4674 opt_grant_grant_option:
4675 WITH GRANT OPTION { $$ = TRUE; }
4676 | /*EMPTY*/ { $$ = FALSE; }
4679 function_with_argtypes_list:
4680 function_with_argtypes { $$ = list_make1($1); }
4681 | function_with_argtypes_list ',' function_with_argtypes
4682 { $$ = lappend($1, $3); }
4685 function_with_argtypes:
4688 FuncWithArgs *n = makeNode(FuncWithArgs);
4690 n->funcargs = extractArgTypes($2);
4695 /*****************************************************************************
4697 * GRANT and REVOKE ROLE statements
4699 *****************************************************************************/
4702 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4704 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4706 n->granted_roles = $2;
4707 n->grantee_roles = $4;
4715 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4717 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4718 n->is_grant = false;
4719 n->admin_opt = false;
4720 n->granted_roles = $2;
4721 n->grantee_roles = $4;
4725 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4727 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4728 n->is_grant = false;
4729 n->admin_opt = true;
4730 n->granted_roles = $5;
4731 n->grantee_roles = $7;
4737 opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
4738 | /*EMPTY*/ { $$ = FALSE; }
4741 opt_granted_by: GRANTED BY RoleId { $$ = $3; }
4742 | /*EMPTY*/ { $$ = NULL; }
4745 /*****************************************************************************
4747 * ALTER DEFAULT PRIVILEGES statement
4749 *****************************************************************************/
4751 AlterDefaultPrivilegesStmt:
4752 ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
4754 AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
4756 n->action = (GrantStmt *) $5;
4762 DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
4763 | /* EMPTY */ { $$ = NIL; }
4767 IN_P SCHEMA name_list
4769 $$ = makeDefElem("schemas", (Node *)$3);
4771 | FOR ROLE name_list
4773 $$ = makeDefElem("roles", (Node *)$3);
4775 | FOR USER name_list
4777 $$ = makeDefElem("roles", (Node *)$3);
4782 * This should match GRANT/REVOKE, except that individual target objects
4783 * are not mentioned and we only allow a subset of object types.
4786 GRANT privileges ON defacl_privilege_target TO grantee_list
4787 opt_grant_grant_option
4789 GrantStmt *n = makeNode(GrantStmt);
4792 n->targtype = ACL_TARGET_DEFAULTS;
4796 n->grant_option = $7;
4799 | REVOKE privileges ON defacl_privilege_target
4800 FROM grantee_list opt_drop_behavior
4802 GrantStmt *n = makeNode(GrantStmt);
4803 n->is_grant = false;
4804 n->grant_option = false;
4806 n->targtype = ACL_TARGET_DEFAULTS;
4813 | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
4814 FROM grantee_list opt_drop_behavior
4816 GrantStmt *n = makeNode(GrantStmt);
4817 n->is_grant = false;
4818 n->grant_option = true;
4820 n->targtype = ACL_TARGET_DEFAULTS;
4829 defacl_privilege_target:
4830 TABLES { $$ = ACL_OBJECT_RELATION; }
4831 | FUNCTIONS { $$ = ACL_OBJECT_FUNCTION; }
4832 | SEQUENCES { $$ = ACL_OBJECT_SEQUENCE; }
4836 /*****************************************************************************
4838 * QUERY: CREATE INDEX
4840 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
4841 * willing to make TABLESPACE a fully reserved word.
4842 *****************************************************************************/
4844 IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_index_name
4845 ON qualified_name access_method_clause '(' index_params ')'
4846 opt_reloptions OptTableSpace where_clause
4848 IndexStmt *n = makeNode(IndexStmt);
4853 n->accessMethod = $8;
4854 n->indexParams = $10;
4856 n->tableSpace = $13;
4857 n->whereClause = $14;
4863 UNIQUE { $$ = TRUE; }
4864 | /*EMPTY*/ { $$ = FALSE; }
4868 CONCURRENTLY { $$ = TRUE; }
4869 | /*EMPTY*/ { $$ = FALSE; }
4873 index_name { $$ = $1; }
4874 | /*EMPTY*/ { $$ = NULL; }
4877 access_method_clause:
4878 USING access_method { $$ = $2; }
4879 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
4882 index_params: index_elem { $$ = list_make1($1); }
4883 | index_params ',' index_elem { $$ = lappend($1, $3); }
4887 * Index attributes can be either simple column references, or arbitrary
4888 * expressions in parens. For backwards-compatibility reasons, we allow
4889 * an expression that's just a function call to be written without parens.
4891 index_elem: ColId opt_class opt_asc_desc opt_nulls_order
4893 $$ = makeNode(IndexElem);
4896 $$->indexcolname = NULL;
4899 $$->nulls_ordering = $4;
4901 | func_expr opt_class opt_asc_desc opt_nulls_order
4903 $$ = makeNode(IndexElem);
4906 $$->indexcolname = NULL;
4909 $$->nulls_ordering = $4;
4911 | '(' a_expr ')' opt_class opt_asc_desc opt_nulls_order
4913 $$ = makeNode(IndexElem);
4916 $$->indexcolname = NULL;
4919 $$->nulls_ordering = $6;
4923 opt_class: any_name { $$ = $1; }
4924 | USING any_name { $$ = $2; }
4925 | /*EMPTY*/ { $$ = NIL; }
4928 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
4929 | DESC { $$ = SORTBY_DESC; }
4930 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
4933 opt_nulls_order: NULLS_FIRST { $$ = SORTBY_NULLS_FIRST; }
4934 | NULLS_LAST { $$ = SORTBY_NULLS_LAST; }
4935 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
4939 /*****************************************************************************
4942 * create [or replace] function <fname>
4943 * [(<type-1> { , <type-n>})]
4945 * as <filename or code in language as appropriate>
4946 * language <lang> [with parameters]
4948 *****************************************************************************/
4951 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4952 RETURNS func_return createfunc_opt_list opt_definition
4954 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4963 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4964 RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
4966 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4969 n->parameters = mergeTableFuncParameters($5, $9);
4970 n->returnType = TableFuncTypeName($9);
4971 n->returnType->location = @7;
4973 n->withClause = $12;
4976 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4977 createfunc_opt_list opt_definition
4979 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
4983 n->returnType = NULL;
4991 OR REPLACE { $$ = TRUE; }
4992 | /*EMPTY*/ { $$ = FALSE; }
4995 func_args: '(' func_args_list ')' { $$ = $2; }
4996 | '(' ')' { $$ = NIL; }
5000 func_arg { $$ = list_make1($1); }
5001 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
5005 * func_args_with_defaults is separate because we only want to accept
5006 * defaults in CREATE FUNCTION, not in ALTER etc.
5008 func_args_with_defaults:
5009 '(' func_args_with_defaults_list ')' { $$ = $2; }
5010 | '(' ')' { $$ = NIL; }
5013 func_args_with_defaults_list:
5014 func_arg_with_default { $$ = list_make1($1); }
5015 | func_args_with_defaults_list ',' func_arg_with_default
5016 { $$ = lappend($1, $3); }
5020 * The style with arg_class first is SQL99 standard, but Oracle puts
5021 * param_name first; accept both since it's likely people will try both
5022 * anyway. Don't bother trying to save productions by letting arg_class
5023 * have an empty alternative ... you'll get shift/reduce conflicts.
5025 * We can catch over-specified arguments here if we want to,
5026 * but for now better to silently swallow typmod, etc.
5027 * - thomas 2000-03-22
5030 arg_class param_name func_type
5032 FunctionParameter *n = makeNode(FunctionParameter);
5039 | param_name arg_class func_type
5041 FunctionParameter *n = makeNode(FunctionParameter);
5048 | param_name func_type
5050 FunctionParameter *n = makeNode(FunctionParameter);
5053 n->mode = FUNC_PARAM_IN;
5057 | arg_class func_type
5059 FunctionParameter *n = makeNode(FunctionParameter);
5068 FunctionParameter *n = makeNode(FunctionParameter);
5071 n->mode = FUNC_PARAM_IN;
5077 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
5078 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
5079 | OUT_P { $$ = FUNC_PARAM_OUT; }
5080 | INOUT { $$ = FUNC_PARAM_INOUT; }
5081 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
5082 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
5086 * Ideally param_name should be ColId, but that causes too many conflicts.
5088 param_name: type_function_name
5094 /* We can catch over-specified results here if we want to,
5095 * but for now better to silently swallow typmod, etc.
5096 * - thomas 2000-03-22
5103 * We would like to make the %TYPE productions here be ColId attrs etc,
5104 * but that causes reduce/reduce conflicts. type_function_name
5105 * is next best choice.
5107 func_type: Typename { $$ = $1; }
5108 | type_function_name attrs '%' TYPE_P
5110 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
5111 $$->pct_type = true;
5114 | SETOF type_function_name attrs '%' TYPE_P
5116 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
5117 $$->pct_type = true;
5123 func_arg_with_default:
5128 | func_arg DEFAULT a_expr
5133 | func_arg '=' a_expr
5141 createfunc_opt_list:
5142 /* Must be at least one to prevent conflict */
5143 createfunc_opt_item { $$ = list_make1($1); }
5144 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
5148 * Options common to both CREATE FUNCTION and ALTER FUNCTION
5150 common_func_opt_item:
5151 CALLED ON NULL_P INPUT_P
5153 $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
5155 | RETURNS NULL_P ON NULL_P INPUT_P
5157 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5161 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5165 $$ = makeDefElem("volatility", (Node *)makeString("immutable"));
5169 $$ = makeDefElem("volatility", (Node *)makeString("stable"));
5173 $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
5175 | EXTERNAL SECURITY DEFINER
5177 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5179 | EXTERNAL SECURITY INVOKER
5181 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5185 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5189 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5193 $$ = makeDefElem("cost", (Node *)$2);
5197 $$ = makeDefElem("rows", (Node *)$2);
5201 /* we abuse the normal content of a DefElem here */
5202 $$ = makeDefElem("set", (Node *)$1);
5206 createfunc_opt_item:
5209 $$ = makeDefElem("as", (Node *)$2);
5211 | LANGUAGE ColId_or_Sconst
5213 $$ = makeDefElem("language", (Node *)makeString($2));
5217 $$ = makeDefElem("window", (Node *)makeInteger(TRUE));
5219 | common_func_opt_item
5225 func_as: Sconst { $$ = list_make1(makeString($1)); }
5228 $$ = list_make2(makeString($1), makeString($3));
5233 WITH definition { $$ = $2; }
5234 | /*EMPTY*/ { $$ = NIL; }
5237 table_func_column: param_name func_type
5239 FunctionParameter *n = makeNode(FunctionParameter);
5242 n->mode = FUNC_PARAM_TABLE;
5248 table_func_column_list:
5251 $$ = list_make1($1);
5253 | table_func_column_list ',' table_func_column
5255 $$ = lappend($1, $3);
5259 /*****************************************************************************
5262 * RENAME and OWNER subcommands are already provided by the generic
5263 * ALTER infrastructure, here we just specify alterations that can
5264 * only be applied to functions.
5266 *****************************************************************************/
5268 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
5270 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
5278 /* At least one option must be specified */
5279 common_func_opt_item { $$ = list_make1($1); }
5280 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
5283 /* Ignored, merely for SQL compliance */
5290 /*****************************************************************************
5294 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
5295 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
5296 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
5298 *****************************************************************************/
5301 DROP FUNCTION func_name func_args opt_drop_behavior
5303 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5304 n->kind = OBJECT_FUNCTION;
5306 n->args = extractArgTypes($4);
5308 n->missing_ok = false;
5311 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
5313 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5314 n->kind = OBJECT_FUNCTION;
5316 n->args = extractArgTypes($6);
5318 n->missing_ok = true;
5324 DROP AGGREGATE func_name aggr_args opt_drop_behavior
5326 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5327 n->kind = OBJECT_AGGREGATE;
5331 n->missing_ok = false;
5334 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
5336 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5337 n->kind = OBJECT_AGGREGATE;
5341 n->missing_ok = true;
5347 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
5349 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5350 n->kind = OBJECT_OPERATOR;
5354 n->missing_ok = false;
5357 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
5359 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5360 n->kind = OBJECT_OPERATOR;
5364 n->missing_ok = true;
5373 (errcode(ERRCODE_SYNTAX_ERROR),
5374 errmsg("missing argument"),
5375 errhint("Use NONE to denote the missing argument of a unary operator."),
5376 parser_errposition(@3)));
5378 | '(' Typename ',' Typename ')'
5379 { $$ = list_make2($2, $4); }
5380 | '(' NONE ',' Typename ')' /* left unary */
5381 { $$ = list_make2(NULL, $4); }
5382 | '(' Typename ',' NONE ')' /* right unary */
5383 { $$ = list_make2($2, NULL); }
5388 { $$ = list_make1(makeString($1)); }
5389 | ColId '.' any_operator
5390 { $$ = lcons(makeString($1), $3); }
5393 /*****************************************************************************
5395 * DO <anonymous code block> [ LANGUAGE language ]
5397 * We use a DefElem list for future extensibility, and to allow flexibility
5398 * in the clause order.
5400 *****************************************************************************/
5402 DoStmt: DO dostmt_opt_list
5404 DoStmt *n = makeNode(DoStmt);
5411 dostmt_opt_item { $$ = list_make1($1); }
5412 | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
5418 $$ = makeDefElem("as", (Node *)makeString($1));
5420 | LANGUAGE ColId_or_Sconst
5422 $$ = makeDefElem("language", (Node *)makeString($2));
5426 /*****************************************************************************
5428 * CREATE CAST / DROP CAST
5430 *****************************************************************************/
5432 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
5433 WITH FUNCTION function_with_argtypes cast_context
5435 CreateCastStmt *n = makeNode(CreateCastStmt);
5439 n->context = (CoercionContext) $11;
5443 | CREATE CAST '(' Typename AS Typename ')'
5444 WITHOUT FUNCTION cast_context
5446 CreateCastStmt *n = makeNode(CreateCastStmt);
5450 n->context = (CoercionContext) $10;
5454 | CREATE CAST '(' Typename AS Typename ')'
5455 WITH INOUT cast_context
5457 CreateCastStmt *n = makeNode(CreateCastStmt);
5461 n->context = (CoercionContext) $10;
5467 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
5468 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
5469 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
5473 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
5475 DropCastStmt *n = makeNode(DropCastStmt);
5484 opt_if_exists: IF_P EXISTS { $$ = TRUE; }
5485 | /*EMPTY*/ { $$ = FALSE; }
5489 /*****************************************************************************
5493 * REINDEX type <name> [FORCE]
5495 * FORCE no longer does anything, but we accept it for backwards compatibility
5496 *****************************************************************************/
5499 REINDEX reindex_type qualified_name opt_force
5501 ReindexStmt *n = makeNode(ReindexStmt);
5507 | REINDEX SYSTEM_P name opt_force
5509 ReindexStmt *n = makeNode(ReindexStmt);
5510 n->kind = OBJECT_DATABASE;
5513 n->do_system = true;
5517 | REINDEX DATABASE name opt_force
5519 ReindexStmt *n = makeNode(ReindexStmt);
5520 n->kind = OBJECT_DATABASE;
5523 n->do_system = true;
5530 INDEX { $$ = OBJECT_INDEX; }
5531 | TABLE { $$ = OBJECT_TABLE; }
5534 opt_force: FORCE { $$ = TRUE; }
5535 | /* EMPTY */ { $$ = FALSE; }
5539 /*****************************************************************************
5541 * ALTER THING name RENAME TO newname
5543 *****************************************************************************/
5545 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
5547 RenameStmt *n = makeNode(RenameStmt);
5548 n->renameType = OBJECT_AGGREGATE;
5554 | ALTER CONVERSION_P any_name RENAME TO name
5556 RenameStmt *n = makeNode(RenameStmt);
5557 n->renameType = OBJECT_CONVERSION;
5562 | ALTER DATABASE database_name RENAME TO database_name
5564 RenameStmt *n = makeNode(RenameStmt);
5565 n->renameType = OBJECT_DATABASE;
5570 | ALTER FUNCTION function_with_argtypes RENAME TO name
5572 RenameStmt *n = makeNode(RenameStmt);
5573 n->renameType = OBJECT_FUNCTION;
5574 n->object = $3->funcname;
5575 n->objarg = $3->funcargs;
5579 | ALTER GROUP_P RoleId RENAME TO RoleId
5581 RenameStmt *n = makeNode(RenameStmt);
5582 n->renameType = OBJECT_ROLE;
5587 | ALTER opt_procedural LANGUAGE name RENAME TO name
5589 RenameStmt *n = makeNode(RenameStmt);
5590 n->renameType = OBJECT_LANGUAGE;
5595 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
5597 RenameStmt *n = makeNode(RenameStmt);
5598 n->renameType = OBJECT_OPCLASS;
5604 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
5606 RenameStmt *n = makeNode(RenameStmt);
5607 n->renameType = OBJECT_OPFAMILY;
5613 | ALTER SCHEMA name RENAME TO name
5615 RenameStmt *n = makeNode(RenameStmt);
5616 n->renameType = OBJECT_SCHEMA;
5621 | ALTER TABLE relation_expr RENAME TO name
5623 RenameStmt *n = makeNode(RenameStmt);
5624 n->renameType = OBJECT_TABLE;
5630 | ALTER SEQUENCE qualified_name RENAME TO name
5632 RenameStmt *n = makeNode(RenameStmt);
5633 n->renameType = OBJECT_SEQUENCE;
5639 | ALTER VIEW qualified_name RENAME TO name
5641 RenameStmt *n = makeNode(RenameStmt);
5642 n->renameType = OBJECT_VIEW;
5648 | ALTER INDEX qualified_name RENAME TO name
5650 RenameStmt *n = makeNode(RenameStmt);
5651 n->renameType = OBJECT_INDEX;
5657 | ALTER TABLE relation_expr RENAME opt_column name TO name
5659 RenameStmt *n = makeNode(RenameStmt);
5660 n->renameType = OBJECT_COLUMN;
5666 | ALTER TRIGGER name ON qualified_name RENAME TO name
5668 RenameStmt *n = makeNode(RenameStmt);
5669 n->renameType = OBJECT_TRIGGER;
5675 | ALTER ROLE RoleId RENAME TO RoleId
5677 RenameStmt *n = makeNode(RenameStmt);
5678 n->renameType = OBJECT_ROLE;
5683 | ALTER USER RoleId RENAME TO RoleId
5685 RenameStmt *n = makeNode(RenameStmt);
5686 n->renameType = OBJECT_ROLE;
5691 | ALTER TABLESPACE name RENAME TO name
5693 RenameStmt *n = makeNode(RenameStmt);
5694 n->renameType = OBJECT_TABLESPACE;
5699 | ALTER TABLESPACE name SET reloptions
5701 AlterTableSpaceOptionsStmt *n =
5702 makeNode(AlterTableSpaceOptionsStmt);
5703 n->tablespacename = $3;
5708 | ALTER TABLESPACE name RESET reloptions
5710 AlterTableSpaceOptionsStmt *n =
5711 makeNode(AlterTableSpaceOptionsStmt);
5712 n->tablespacename = $3;
5717 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
5719 RenameStmt *n = makeNode(RenameStmt);
5720 n->renameType = OBJECT_TSPARSER;
5725 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
5727 RenameStmt *n = makeNode(RenameStmt);
5728 n->renameType = OBJECT_TSDICTIONARY;
5733 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
5735 RenameStmt *n = makeNode(RenameStmt);
5736 n->renameType = OBJECT_TSTEMPLATE;
5741 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
5743 RenameStmt *n = makeNode(RenameStmt);
5744 n->renameType = OBJECT_TSCONFIGURATION;
5749 | ALTER TYPE_P any_name RENAME TO name
5751 RenameStmt *n = makeNode(RenameStmt);
5752 n->renameType = OBJECT_TYPE;
5759 opt_column: COLUMN { $$ = COLUMN; }
5760 | /*EMPTY*/ { $$ = 0; }
5763 opt_set_data: SET DATA_P { $$ = 1; }
5764 | /*EMPTY*/ { $$ = 0; }
5767 /*****************************************************************************
5769 * ALTER THING name SET SCHEMA name
5771 *****************************************************************************/
5773 AlterObjectSchemaStmt:
5774 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
5776 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5777 n->objectType = OBJECT_AGGREGATE;
5783 | ALTER DOMAIN_P any_name SET SCHEMA name
5785 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5786 n->objectType = OBJECT_DOMAIN;
5791 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
5793 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5794 n->objectType = OBJECT_FUNCTION;
5795 n->object = $3->funcname;
5796 n->objarg = $3->funcargs;
5800 | ALTER TABLE relation_expr SET SCHEMA name
5802 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5803 n->objectType = OBJECT_TABLE;
5808 | ALTER SEQUENCE qualified_name SET SCHEMA name
5810 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5811 n->objectType = OBJECT_SEQUENCE;
5816 | ALTER VIEW qualified_name SET SCHEMA name
5818 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5819 n->objectType = OBJECT_VIEW;
5824 | ALTER TYPE_P any_name SET SCHEMA name
5826 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5827 n->objectType = OBJECT_TYPE;
5834 /*****************************************************************************
5836 * ALTER THING name OWNER TO newname
5838 *****************************************************************************/
5840 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
5842 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5843 n->objectType = OBJECT_AGGREGATE;
5849 | ALTER CONVERSION_P any_name OWNER TO RoleId
5851 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5852 n->objectType = OBJECT_CONVERSION;
5857 | ALTER DATABASE database_name OWNER TO RoleId
5859 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5860 n->objectType = OBJECT_DATABASE;
5861 n->object = list_make1(makeString($3));
5865 | ALTER DOMAIN_P any_name OWNER TO RoleId
5867 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5868 n->objectType = OBJECT_DOMAIN;
5873 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
5875 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5876 n->objectType = OBJECT_FUNCTION;
5877 n->object = $3->funcname;
5878 n->objarg = $3->funcargs;
5882 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
5884 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5885 n->objectType = OBJECT_LANGUAGE;
5886 n->object = list_make1(makeString($4));
5890 | ALTER LARGE_P OBJECT_P Iconst OWNER TO RoleId
5892 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5893 n->objectType = OBJECT_LARGEOBJECT;
5894 n->object = list_make1(makeInteger($4));
5898 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
5900 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5901 n->objectType = OBJECT_OPERATOR;
5907 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
5909 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5910 n->objectType = OBJECT_OPCLASS;
5916 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
5918 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5919 n->objectType = OBJECT_OPFAMILY;
5925 | ALTER SCHEMA name OWNER TO RoleId
5927 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5928 n->objectType = OBJECT_SCHEMA;
5929 n->object = list_make1(makeString($3));
5933 | ALTER TYPE_P any_name OWNER TO RoleId
5935 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5936 n->objectType = OBJECT_TYPE;
5941 | ALTER TABLESPACE name OWNER TO RoleId
5943 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5944 n->objectType = OBJECT_TABLESPACE;
5945 n->object = list_make1(makeString($3));
5949 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
5951 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5952 n->objectType = OBJECT_TSDICTIONARY;
5957 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
5959 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5960 n->objectType = OBJECT_TSCONFIGURATION;
5965 | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleId
5967 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5968 n->objectType = OBJECT_FDW;
5969 n->object = list_make1(makeString($5));
5973 | ALTER SERVER name OWNER TO RoleId
5975 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
5976 n->objectType = OBJECT_FOREIGN_SERVER;
5977 n->object = list_make1(makeString($3));
5984 /*****************************************************************************
5986 * QUERY: Define Rewrite Rule
5988 *****************************************************************************/
5990 RuleStmt: CREATE opt_or_replace RULE name AS
5991 ON event TO qualified_name where_clause
5992 DO opt_instead RuleActionList
5994 RuleStmt *n = makeNode(RuleStmt);
5998 n->whereClause = $10;
6007 NOTHING { $$ = NIL; }
6008 | RuleActionStmt { $$ = list_make1($1); }
6009 | '(' RuleActionMulti ')' { $$ = $2; }
6012 /* the thrashing around here is to discard "empty" statements... */
6014 RuleActionMulti ';' RuleActionStmtOrEmpty
6016 $$ = lappend($1, $3);
6020 | RuleActionStmtOrEmpty
6022 $$ = list_make1($1);
6036 RuleActionStmtOrEmpty:
6037 RuleActionStmt { $$ = $1; }
6038 | /*EMPTY*/ { $$ = NULL; }
6041 event: SELECT { $$ = CMD_SELECT; }
6042 | UPDATE { $$ = CMD_UPDATE; }
6043 | DELETE_P { $$ = CMD_DELETE; }
6044 | INSERT { $$ = CMD_INSERT; }
6048 INSTEAD { $$ = TRUE; }
6049 | ALSO { $$ = FALSE; }
6050 | /*EMPTY*/ { $$ = FALSE; }
6055 DROP RULE name ON qualified_name opt_drop_behavior
6057 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6061 n->removeType = OBJECT_RULE;
6062 n->missing_ok = false;
6065 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
6067 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6071 n->removeType = OBJECT_RULE;
6072 n->missing_ok = true;
6078 /*****************************************************************************
6081 * NOTIFY <identifier> can appear both in rule bodies and
6082 * as a query-level command
6084 *****************************************************************************/
6086 NotifyStmt: NOTIFY ColId
6088 NotifyStmt *n = makeNode(NotifyStmt);
6089 n->conditionname = $2;
6094 ListenStmt: LISTEN ColId
6096 ListenStmt *n = makeNode(ListenStmt);
6097 n->conditionname = $2;
6105 UnlistenStmt *n = makeNode(UnlistenStmt);
6106 n->conditionname = $2;
6111 UnlistenStmt *n = makeNode(UnlistenStmt);
6112 n->conditionname = NULL;
6118 /*****************************************************************************
6122 * BEGIN / COMMIT / ROLLBACK
6123 * (also older versions END / ABORT)
6125 *****************************************************************************/
6128 ABORT_P opt_transaction
6130 TransactionStmt *n = makeNode(TransactionStmt);
6131 n->kind = TRANS_STMT_ROLLBACK;
6135 | BEGIN_P opt_transaction transaction_mode_list_or_empty
6137 TransactionStmt *n = makeNode(TransactionStmt);
6138 n->kind = TRANS_STMT_BEGIN;
6142 | START TRANSACTION transaction_mode_list_or_empty
6144 TransactionStmt *n = makeNode(TransactionStmt);
6145 n->kind = TRANS_STMT_START;
6149 | COMMIT opt_transaction
6151 TransactionStmt *n = makeNode(TransactionStmt);
6152 n->kind = TRANS_STMT_COMMIT;
6156 | END_P opt_transaction
6158 TransactionStmt *n = makeNode(TransactionStmt);
6159 n->kind = TRANS_STMT_COMMIT;
6163 | ROLLBACK opt_transaction
6165 TransactionStmt *n = makeNode(TransactionStmt);
6166 n->kind = TRANS_STMT_ROLLBACK;
6172 TransactionStmt *n = makeNode(TransactionStmt);
6173 n->kind = TRANS_STMT_SAVEPOINT;
6174 n->options = list_make1(makeDefElem("savepoint_name",
6175 (Node *)makeString($2)));
6178 | RELEASE SAVEPOINT ColId
6180 TransactionStmt *n = makeNode(TransactionStmt);
6181 n->kind = TRANS_STMT_RELEASE;
6182 n->options = list_make1(makeDefElem("savepoint_name",
6183 (Node *)makeString($3)));
6188 TransactionStmt *n = makeNode(TransactionStmt);
6189 n->kind = TRANS_STMT_RELEASE;
6190 n->options = list_make1(makeDefElem("savepoint_name",
6191 (Node *)makeString($2)));
6194 | ROLLBACK opt_transaction TO SAVEPOINT ColId
6196 TransactionStmt *n = makeNode(TransactionStmt);
6197 n->kind = TRANS_STMT_ROLLBACK_TO;
6198 n->options = list_make1(makeDefElem("savepoint_name",
6199 (Node *)makeString($5)));
6202 | ROLLBACK opt_transaction TO ColId
6204 TransactionStmt *n = makeNode(TransactionStmt);
6205 n->kind = TRANS_STMT_ROLLBACK_TO;
6206 n->options = list_make1(makeDefElem("savepoint_name",
6207 (Node *)makeString($4)));
6210 | PREPARE TRANSACTION Sconst
6212 TransactionStmt *n = makeNode(TransactionStmt);
6213 n->kind = TRANS_STMT_PREPARE;
6217 | COMMIT PREPARED Sconst
6219 TransactionStmt *n = makeNode(TransactionStmt);
6220 n->kind = TRANS_STMT_COMMIT_PREPARED;
6224 | ROLLBACK PREPARED Sconst
6226 TransactionStmt *n = makeNode(TransactionStmt);
6227 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
6233 opt_transaction: WORK {}
6238 transaction_mode_item:
6239 ISOLATION LEVEL iso_level
6240 { $$ = makeDefElem("transaction_isolation",
6241 makeStringConst($3, @3)); }
6243 { $$ = makeDefElem("transaction_read_only",
6244 makeIntConst(TRUE, @1)); }
6246 { $$ = makeDefElem("transaction_read_only",
6247 makeIntConst(FALSE, @1)); }
6250 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
6251 transaction_mode_list:
6252 transaction_mode_item
6253 { $$ = list_make1($1); }
6254 | transaction_mode_list ',' transaction_mode_item
6255 { $$ = lappend($1, $3); }
6256 | transaction_mode_list transaction_mode_item
6257 { $$ = lappend($1, $2); }
6260 transaction_mode_list_or_empty:
6261 transaction_mode_list
6267 /*****************************************************************************
6270 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
6271 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
6273 *****************************************************************************/
6275 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
6276 AS SelectStmt opt_check_option
6278 ViewStmt *n = makeNode(ViewStmt);
6280 n->view->istemp = $2;
6286 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
6287 AS SelectStmt opt_check_option
6289 ViewStmt *n = makeNode(ViewStmt);
6291 n->view->istemp = $4;
6303 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6304 errmsg("WITH CHECK OPTION is not implemented")));
6306 | WITH CASCADED CHECK OPTION
6309 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6310 errmsg("WITH CHECK OPTION is not implemented")));
6312 | WITH LOCAL CHECK OPTION
6315 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6316 errmsg("WITH CHECK OPTION is not implemented")));
6318 | /* EMPTY */ { $$ = NIL; }
6321 /*****************************************************************************
6326 *****************************************************************************/
6328 LoadStmt: LOAD file_name
6330 LoadStmt *n = makeNode(LoadStmt);
6337 /*****************************************************************************
6341 *****************************************************************************/
6344 CREATE DATABASE database_name opt_with createdb_opt_list
6346 CreatedbStmt *n = makeNode(CreatedbStmt);
6354 createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
6355 | /* EMPTY */ { $$ = NIL; }
6359 TABLESPACE opt_equal name
6361 $$ = makeDefElem("tablespace", (Node *)makeString($3));
6363 | TABLESPACE opt_equal DEFAULT
6365 $$ = makeDefElem("tablespace", NULL);
6367 | LOCATION opt_equal Sconst
6369 $$ = makeDefElem("location", (Node *)makeString($3));
6371 | LOCATION opt_equal DEFAULT
6373 $$ = makeDefElem("location", NULL);
6375 | TEMPLATE opt_equal name
6377 $$ = makeDefElem("template", (Node *)makeString($3));
6379 | TEMPLATE opt_equal DEFAULT
6381 $$ = makeDefElem("template", NULL);
6383 | ENCODING opt_equal Sconst
6385 $$ = makeDefElem("encoding", (Node *)makeString($3));
6387 | ENCODING opt_equal Iconst
6389 $$ = makeDefElem("encoding", (Node *)makeInteger($3));
6391 | ENCODING opt_equal DEFAULT
6393 $$ = makeDefElem("encoding", NULL);
6395 | LC_COLLATE_P opt_equal Sconst
6397 $$ = makeDefElem("lc_collate", (Node *)makeString($3));
6399 | LC_COLLATE_P opt_equal DEFAULT
6401 $$ = makeDefElem("lc_collate", NULL);
6403 | LC_CTYPE_P opt_equal Sconst
6405 $$ = makeDefElem("lc_ctype", (Node *)makeString($3));
6407 | LC_CTYPE_P opt_equal DEFAULT
6409 $$ = makeDefElem("lc_ctype", NULL);
6411 | CONNECTION LIMIT opt_equal SignedIconst
6413 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6415 | OWNER opt_equal name
6417 $$ = makeDefElem("owner", (Node *)makeString($3));
6419 | OWNER opt_equal DEFAULT
6421 $$ = makeDefElem("owner", NULL);
6426 * Though the equals sign doesn't match other WITH options, pg_dump uses
6427 * equals for backward compatibility, and it doesn't seem worth removing it.
6434 /*****************************************************************************
6438 *****************************************************************************/
6441 ALTER DATABASE database_name opt_with alterdb_opt_list
6443 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6448 | ALTER DATABASE database_name SET TABLESPACE name
6450 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6452 n->options = list_make1(makeDefElem("tablespace",
6453 (Node *)makeString($6)));
6458 AlterDatabaseSetStmt:
6459 ALTER DATABASE database_name SetResetClause
6461 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
6470 alterdb_opt_list alterdb_opt_item { $$ = lappend($1, $2); }
6471 | /* EMPTY */ { $$ = NIL; }
6475 CONNECTION LIMIT opt_equal SignedIconst
6477 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6482 /*****************************************************************************
6484 * DROP DATABASE [ IF EXISTS ]
6486 * This is implicitly CASCADE, no need for drop behavior
6487 *****************************************************************************/
6489 DropdbStmt: DROP DATABASE database_name
6491 DropdbStmt *n = makeNode(DropdbStmt);
6493 n->missing_ok = FALSE;
6496 | DROP DATABASE IF_P EXISTS database_name
6498 DropdbStmt *n = makeNode(DropdbStmt);
6500 n->missing_ok = TRUE;
6506 /*****************************************************************************
6508 * Manipulate a domain
6510 *****************************************************************************/
6513 CREATE DOMAIN_P any_name opt_as Typename ColQualList
6515 CreateDomainStmt *n = makeNode(CreateDomainStmt);
6518 n->constraints = $6;
6524 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
6525 ALTER DOMAIN_P any_name alter_column_default
6527 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6533 /* ALTER DOMAIN <domain> DROP NOT NULL */
6534 | ALTER DOMAIN_P any_name DROP NOT NULL_P
6536 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6541 /* ALTER DOMAIN <domain> SET NOT NULL */
6542 | ALTER DOMAIN_P any_name SET NOT NULL_P
6544 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6549 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
6550 | ALTER DOMAIN_P any_name ADD_P TableConstraint
6552 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6558 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
6559 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
6561 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6575 /*****************************************************************************
6577 * Manipulate a text search dictionary or configuration
6579 *****************************************************************************/
6581 AlterTSDictionaryStmt:
6582 ALTER TEXT_P SEARCH DICTIONARY any_name definition
6584 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
6591 AlterTSConfigurationStmt:
6592 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
6594 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6598 n->override = false;
6602 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
6604 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6612 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
6614 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6617 n->dicts = list_make2($9,$11);
6618 n->override = false;
6622 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
6624 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6627 n->dicts = list_make2($11,$13);
6628 n->override = false;
6632 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
6634 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6637 n->missing_ok = false;
6640 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
6642 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6645 n->missing_ok = true;
6651 /*****************************************************************************
6653 * Manipulate a conversion
6655 * CREATE [DEFAULT] CONVERSION <conversion_name>
6656 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
6658 *****************************************************************************/
6660 CreateConversionStmt:
6661 CREATE opt_default CONVERSION_P any_name FOR Sconst
6662 TO Sconst FROM any_name
6664 CreateConversionStmt *n = makeNode(CreateConversionStmt);
6665 n->conversion_name = $4;
6666 n->for_encoding_name = $6;
6667 n->to_encoding_name = $8;
6674 /*****************************************************************************
6677 * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
6679 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
6681 *****************************************************************************/
6684 CLUSTER opt_verbose qualified_name cluster_index_specification
6686 ClusterStmt *n = makeNode(ClusterStmt);
6692 | CLUSTER opt_verbose
6694 ClusterStmt *n = makeNode(ClusterStmt);
6696 n->indexname = NULL;
6700 /* kept for pre-8.3 compatibility */
6701 | CLUSTER opt_verbose index_name ON qualified_name
6703 ClusterStmt *n = makeNode(ClusterStmt);
6711 cluster_index_specification:
6712 USING index_name { $$ = $2; }
6713 | /*EMPTY*/ { $$ = NULL; }
6717 /*****************************************************************************
6723 *****************************************************************************/
6725 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
6727 VacuumStmt *n = makeNode(VacuumStmt);
6728 n->options = VACOPT_VACUUM;
6730 n->options |= VACOPT_FULL;
6732 n->options |= VACOPT_VERBOSE;
6733 n->freeze_min_age = $3 ? 0 : -1;
6734 n->freeze_table_age = $3 ? 0 : -1;
6739 | VACUUM opt_full opt_freeze opt_verbose qualified_name
6741 VacuumStmt *n = makeNode(VacuumStmt);
6742 n->options = VACOPT_VACUUM;
6744 n->options |= VACOPT_FULL;
6746 n->options |= VACOPT_VERBOSE;
6747 n->freeze_min_age = $3 ? 0 : -1;
6748 n->freeze_table_age = $3 ? 0 : -1;
6753 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
6755 VacuumStmt *n = (VacuumStmt *) $5;
6756 n->options |= VACOPT_VACUUM;
6758 n->options |= VACOPT_FULL;
6760 n->options |= VACOPT_VERBOSE;
6761 n->freeze_min_age = $3 ? 0 : -1;
6762 n->freeze_table_age = $3 ? 0 : -1;
6765 | VACUUM '(' vacuum_option_list ')'
6767 VacuumStmt *n = makeNode(VacuumStmt);
6768 n->options = VACOPT_VACUUM | $3;
6769 if (n->options & VACOPT_FREEZE)
6770 n->freeze_min_age = n->freeze_table_age = 0;
6772 n->freeze_min_age = n->freeze_table_age = -1;
6777 | VACUUM '(' vacuum_option_list ')' qualified_name opt_name_list
6779 VacuumStmt *n = makeNode(VacuumStmt);
6780 n->options = VACOPT_VACUUM | $3;
6781 if (n->options & VACOPT_FREEZE)
6782 n->freeze_min_age = n->freeze_table_age = 0;
6784 n->freeze_min_age = n->freeze_table_age = -1;
6787 if (n->va_cols != NIL) /* implies analyze */
6788 n->options |= VACOPT_ANALYZE;
6794 vacuum_option_elem { $$ = $1; }
6795 | vacuum_option_list ',' vacuum_option_elem { $$ = $1 | $3; }
6799 analyze_keyword { $$ = VACOPT_ANALYZE; }
6800 | VERBOSE { $$ = VACOPT_VERBOSE; }
6801 | FREEZE { $$ = VACOPT_FREEZE; }
6802 | FULL { $$ = VACOPT_FULL; }
6803 | FULL INPLACE { $$ = VACOPT_FULL | VACOPT_INPLACE; }
6807 analyze_keyword opt_verbose
6809 VacuumStmt *n = makeNode(VacuumStmt);
6810 n->options = VACOPT_ANALYZE;
6812 n->options |= VACOPT_VERBOSE;
6813 n->freeze_min_age = -1;
6814 n->freeze_table_age = -1;
6819 | analyze_keyword opt_verbose qualified_name opt_name_list
6821 VacuumStmt *n = makeNode(VacuumStmt);
6822 n->options = VACOPT_ANALYZE;
6824 n->options |= VACOPT_VERBOSE;
6825 n->freeze_min_age = -1;
6826 n->freeze_table_age = -1;
6835 | ANALYSE /* British */ {}
6839 VERBOSE { $$ = TRUE; }
6840 | /*EMPTY*/ { $$ = FALSE; }
6843 opt_full: FULL { $$ = TRUE; }
6844 | /*EMPTY*/ { $$ = FALSE; }
6847 opt_freeze: FREEZE { $$ = TRUE; }
6848 | /*EMPTY*/ { $$ = FALSE; }
6852 '(' name_list ')' { $$ = $2; }
6853 | /*EMPTY*/ { $$ = NIL; }
6857 /*****************************************************************************
6860 * EXPLAIN [ANALYZE] [VERBOSE] query
6861 * EXPLAIN ( options ) query
6863 *****************************************************************************/
6866 EXPLAIN ExplainableStmt
6868 ExplainStmt *n = makeNode(ExplainStmt);
6873 | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
6875 ExplainStmt *n = makeNode(ExplainStmt);
6877 n->options = list_make1(makeDefElem("analyze", NULL));
6879 n->options = lappend(n->options,
6880 makeDefElem("verbose", NULL));
6883 | EXPLAIN VERBOSE ExplainableStmt
6885 ExplainStmt *n = makeNode(ExplainStmt);
6887 n->options = list_make1(makeDefElem("verbose", NULL));
6890 | EXPLAIN '(' explain_option_list ')' ExplainableStmt
6892 ExplainStmt *n = makeNode(ExplainStmt);
6906 | ExecuteStmt /* by default all are $$=$1 */
6909 explain_option_list:
6912 $$ = list_make1($1);
6914 | explain_option_list ',' explain_option_elem
6916 $$ = lappend($1, $3);
6920 explain_option_elem:
6921 explain_option_name explain_option_arg
6923 $$ = makeDefElem($1, $2);
6927 explain_option_name:
6929 | analyze_keyword { $$ = "analyze"; }
6930 | VERBOSE { $$ = "verbose"; }
6934 opt_boolean { $$ = (Node *) makeString($1); }
6935 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
6936 | NumericOnly { $$ = (Node *) $1; }
6937 | /* EMPTY */ { $$ = NULL; }
6940 /*****************************************************************************
6943 * PREPARE <plan_name> [(args, ...)] AS <query>
6945 *****************************************************************************/
6947 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
6949 PrepareStmt *n = makeNode(PrepareStmt);
6957 prep_type_clause: '(' type_list ')' { $$ = $2; }
6958 | /* EMPTY */ { $$ = NIL; }
6965 | DeleteStmt /* by default all are $$=$1 */
6968 /*****************************************************************************
6970 * EXECUTE <plan_name> [(params, ...)]
6971 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
6973 *****************************************************************************/
6975 ExecuteStmt: EXECUTE name execute_param_clause
6977 ExecuteStmt *n = makeNode(ExecuteStmt);
6983 | CREATE OptTemp TABLE create_as_target AS
6984 EXECUTE name execute_param_clause
6986 ExecuteStmt *n = makeNode(ExecuteStmt);
6989 $4->rel->istemp = $2;
6993 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6994 errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
6995 /* ... because it's not implemented, but it could be */
7000 execute_param_clause: '(' expr_list ')' { $$ = $2; }
7001 | /* EMPTY */ { $$ = NIL; }
7004 /*****************************************************************************
7007 * DEALLOCATE [PREPARE] <plan_name>
7009 *****************************************************************************/
7011 DeallocateStmt: DEALLOCATE name
7013 DeallocateStmt *n = makeNode(DeallocateStmt);
7017 | DEALLOCATE PREPARE name
7019 DeallocateStmt *n = makeNode(DeallocateStmt);
7025 DeallocateStmt *n = makeNode(DeallocateStmt);
7029 | DEALLOCATE PREPARE ALL
7031 DeallocateStmt *n = makeNode(DeallocateStmt);
7037 /*****************************************************************************
7042 *****************************************************************************/
7045 INSERT INTO qualified_name insert_rest returning_clause
7048 $4->returningList = $5;
7056 $$ = makeNode(InsertStmt);
7058 $$->selectStmt = $1;
7060 | '(' insert_column_list ')' SelectStmt
7062 $$ = makeNode(InsertStmt);
7064 $$->selectStmt = $4;
7068 $$ = makeNode(InsertStmt);
7070 $$->selectStmt = NULL;
7076 { $$ = list_make1($1); }
7077 | insert_column_list ',' insert_column_item
7078 { $$ = lappend($1, $3); }
7082 ColId opt_indirection
7084 $$ = makeNode(ResTarget);
7086 $$->indirection = check_indirection($2, yyscanner);
7093 RETURNING target_list { $$ = $2; }
7094 | /* EMPTY */ { $$ = NIL; }
7098 /*****************************************************************************
7103 *****************************************************************************/
7105 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
7106 using_clause where_or_current_clause returning_clause
7108 DeleteStmt *n = makeNode(DeleteStmt);
7110 n->usingClause = $4;
7111 n->whereClause = $5;
7112 n->returningList = $6;
7118 USING from_list { $$ = $2; }
7119 | /*EMPTY*/ { $$ = NIL; }
7123 /*****************************************************************************
7128 *****************************************************************************/
7130 LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
7132 LockStmt *n = makeNode(LockStmt);
7141 opt_lock: IN_P lock_type MODE { $$ = $2; }
7142 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
7145 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
7146 | ROW SHARE { $$ = RowShareLock; }
7147 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
7148 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
7149 | SHARE { $$ = ShareLock; }
7150 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
7151 | EXCLUSIVE { $$ = ExclusiveLock; }
7152 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
7155 opt_nowait: NOWAIT { $$ = TRUE; }
7156 | /*EMPTY*/ { $$ = FALSE; }
7160 /*****************************************************************************
7163 * UpdateStmt (UPDATE)
7165 *****************************************************************************/
7167 UpdateStmt: UPDATE relation_expr_opt_alias
7170 where_or_current_clause
7173 UpdateStmt *n = makeNode(UpdateStmt);
7177 n->whereClause = $6;
7178 n->returningList = $7;
7184 set_clause { $$ = $1; }
7185 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
7189 single_set_clause { $$ = list_make1($1); }
7190 | multiple_set_clause { $$ = $1; }
7194 set_target '=' ctext_expr
7197 $$->val = (Node *) $3;
7201 multiple_set_clause:
7202 '(' set_target_list ')' '=' ctext_row
7208 * Break the ctext_row apart, merge individual expressions
7209 * into the destination ResTargets. XXX this approach
7210 * cannot work for general row expressions as sources.
7212 if (list_length($2) != list_length($5))
7214 (errcode(ERRCODE_SYNTAX_ERROR),
7215 errmsg("number of columns does not match number of values"),
7216 parser_errposition(@1)));
7217 forboth(col_cell, $2, val_cell, $5)
7219 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
7220 Node *res_val = (Node *) lfirst(val_cell);
7222 res_col->val = res_val;
7230 ColId opt_indirection
7232 $$ = makeNode(ResTarget);
7234 $$->indirection = check_indirection($2, yyscanner);
7235 $$->val = NULL; /* upper production sets this */
7241 set_target { $$ = list_make1($1); }
7242 | set_target_list ',' set_target { $$ = lappend($1,$3); }
7246 /*****************************************************************************
7251 *****************************************************************************/
7252 DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
7254 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
7256 /* currently we always set FAST_PLAN option */
7257 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
7263 cursor_name: name { $$ = $1; }
7266 cursor_options: /*EMPTY*/ { $$ = 0; }
7267 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
7268 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
7269 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
7270 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
7273 opt_hold: /* EMPTY */ { $$ = 0; }
7274 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
7275 | WITHOUT HOLD { $$ = 0; }
7278 /*****************************************************************************
7283 *****************************************************************************/
7285 /* A complete SELECT statement looks like this.
7287 * The rule returns either a single SelectStmt node or a tree of them,
7288 * representing a set-operation tree.
7290 * There is an ambiguity when a sub-SELECT is within an a_expr and there
7291 * are excess parentheses: do the parentheses belong to the sub-SELECT or
7292 * to the surrounding a_expr? We don't really care, but bison wants to know.
7293 * To resolve the ambiguity, we are careful to define the grammar so that
7294 * the decision is staved off as long as possible: as long as we can keep
7295 * absorbing parentheses into the sub-SELECT, we will do so, and only when
7296 * it's no longer possible to do that will we decide that parens belong to
7297 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
7298 * parentheses are treated as part of the sub-select. The necessity of doing
7299 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
7300 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
7301 * SELECT viewpoint when we see the UNION.
7303 * This approach is implemented by defining a nonterminal select_with_parens,
7304 * which represents a SELECT with at least one outer layer of parentheses,
7305 * and being careful to use select_with_parens, never '(' SelectStmt ')',
7306 * in the expression grammar. We will then have shift-reduce conflicts
7307 * which we can resolve in favor of always treating '(' <select> ')' as
7308 * a select_with_parens. To resolve the conflicts, the productions that
7309 * conflict with the select_with_parens productions are manually given
7310 * precedences lower than the precedence of ')', thereby ensuring that we
7311 * shift ')' (and then reduce to select_with_parens) rather than trying to
7312 * reduce the inner <select> nonterminal to something else. We use UMINUS
7313 * precedence for this, which is a fairly arbitrary choice.
7315 * To be able to define select_with_parens itself without ambiguity, we need
7316 * a nonterminal select_no_parens that represents a SELECT structure with no
7317 * outermost parentheses. This is a little bit tedious, but it works.
7319 * In non-expression contexts, we use SelectStmt which can represent a SELECT
7320 * with or without outer parentheses.
7323 SelectStmt: select_no_parens %prec UMINUS
7324 | select_with_parens %prec UMINUS
7328 '(' select_no_parens ')' { $$ = $2; }
7329 | '(' select_with_parens ')' { $$ = $2; }
7333 * This rule parses the equivalent of the standard's <query expression>.
7334 * The duplicative productions are annoying, but hard to get rid of without
7335 * creating shift/reduce conflicts.
7337 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
7338 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
7339 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
7343 simple_select { $$ = $1; }
7344 | select_clause sort_clause
7346 insertSelectOptions((SelectStmt *) $1, $2, NIL,
7351 | select_clause opt_sort_clause for_locking_clause opt_select_limit
7353 insertSelectOptions((SelectStmt *) $1, $2, $3,
7354 list_nth($4, 0), list_nth($4, 1),
7359 | select_clause opt_sort_clause select_limit opt_for_locking_clause
7361 insertSelectOptions((SelectStmt *) $1, $2, $4,
7362 list_nth($3, 0), list_nth($3, 1),
7367 | with_clause select_clause
7369 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
7375 | with_clause select_clause sort_clause
7377 insertSelectOptions((SelectStmt *) $2, $3, NIL,
7383 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
7385 insertSelectOptions((SelectStmt *) $2, $3, $4,
7386 list_nth($5, 0), list_nth($5, 1),
7391 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
7393 insertSelectOptions((SelectStmt *) $2, $3, $5,
7394 list_nth($4, 0), list_nth($4, 1),
7402 simple_select { $$ = $1; }
7403 | select_with_parens { $$ = $1; }
7407 * This rule parses SELECT statements that can appear within set operations,
7408 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
7409 * the ordering of the set operations. Without '(' and ')' we want the
7410 * operations to be ordered per the precedence specs at the head of this file.
7412 * As with select_no_parens, simple_select cannot have outer parentheses,
7413 * but can have parenthesized subclauses.
7415 * Note that sort clauses cannot be included at this level --- SQL92 requires
7416 * SELECT foo UNION SELECT bar ORDER BY baz
7418 * (SELECT foo UNION SELECT bar) ORDER BY baz
7420 * SELECT foo UNION (SELECT bar ORDER BY baz)
7421 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
7422 * described as part of the select_no_parens production, not simple_select.
7423 * This does not limit functionality, because you can reintroduce these
7424 * clauses inside parentheses.
7426 * NOTE: only the leftmost component SelectStmt should have INTO.
7427 * However, this is not checked by the grammar; parse analysis must check it.
7430 SELECT opt_distinct target_list
7431 into_clause from_clause where_clause
7432 group_clause having_clause window_clause
7434 SelectStmt *n = makeNode(SelectStmt);
7435 n->distinctClause = $2;
7439 n->whereClause = $6;
7440 n->groupClause = $7;
7441 n->havingClause = $8;
7442 n->windowClause = $9;
7445 | values_clause { $$ = $1; }
7446 | TABLE relation_expr
7448 /* same as SELECT * FROM relation_expr */
7449 ColumnRef *cr = makeNode(ColumnRef);
7450 ResTarget *rt = makeNode(ResTarget);
7451 SelectStmt *n = makeNode(SelectStmt);
7453 cr->fields = list_make1(makeNode(A_Star));
7457 rt->indirection = NIL;
7458 rt->val = (Node *)cr;
7461 n->targetList = list_make1(rt);
7462 n->fromClause = list_make1($2);
7465 | select_clause UNION opt_all select_clause
7467 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
7469 | select_clause INTERSECT opt_all select_clause
7471 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
7473 | select_clause EXCEPT opt_all select_clause
7475 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
7480 * SQL standard WITH clause looks like:
7482 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
7483 * AS (query) [ SEARCH or CYCLE clause ]
7485 * We don't currently support the SEARCH or CYCLE clause.
7490 $$ = makeNode(WithClause);
7492 $$->recursive = false;
7495 | WITH RECURSIVE cte_list
7497 $$ = makeNode(WithClause);
7499 $$->recursive = true;
7505 common_table_expr { $$ = list_make1($1); }
7506 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
7509 common_table_expr: name opt_name_list AS select_with_parens
7511 CommonTableExpr *n = makeNode(CommonTableExpr);
7513 n->aliascolnames = $2;
7521 INTO OptTempTableName
7523 $$ = makeNode(IntoClause);
7527 $$->onCommit = ONCOMMIT_NOOP;
7528 $$->tableSpaceName = NULL;
7535 * Redundancy here is needed to avoid shift/reduce conflicts,
7536 * since TEMP is not a reserved word. See also OptTemp.
7539 TEMPORARY opt_table qualified_name
7544 | TEMP opt_table qualified_name
7549 | LOCAL TEMPORARY opt_table qualified_name
7554 | LOCAL TEMP opt_table qualified_name
7559 | GLOBAL TEMPORARY opt_table qualified_name
7564 | GLOBAL TEMP opt_table qualified_name
7569 | TABLE qualified_name
7585 opt_all: ALL { $$ = TRUE; }
7586 | DISTINCT { $$ = FALSE; }
7587 | /*EMPTY*/ { $$ = FALSE; }
7590 /* We use (NIL) as a placeholder to indicate that all target expressions
7591 * should be placed in the DISTINCT list during parsetree analysis.
7594 DISTINCT { $$ = list_make1(NIL); }
7595 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
7597 | /*EMPTY*/ { $$ = NIL; }
7601 sort_clause { $$ = $1;}
7602 | /*EMPTY*/ { $$ = NIL; }
7606 ORDER BY sortby_list { $$ = $3; }
7610 sortby { $$ = list_make1($1); }
7611 | sortby_list ',' sortby { $$ = lappend($1, $3); }
7614 sortby: a_expr USING qual_all_Op opt_nulls_order
7616 $$ = makeNode(SortBy);
7618 $$->sortby_dir = SORTBY_USING;
7619 $$->sortby_nulls = $4;
7623 | a_expr opt_asc_desc opt_nulls_order
7625 $$ = makeNode(SortBy);
7627 $$->sortby_dir = $2;
7628 $$->sortby_nulls = $3;
7630 $$->location = -1; /* no operator */
7636 limit_clause offset_clause { $$ = list_make2($2, $1); }
7637 | offset_clause limit_clause { $$ = list_make2($1, $2); }
7638 | limit_clause { $$ = list_make2(NULL, $1); }
7639 | offset_clause { $$ = list_make2($1, NULL); }
7643 select_limit { $$ = $1; }
7644 | /* EMPTY */ { $$ = list_make2(NULL,NULL); }
7648 LIMIT select_limit_value
7650 | LIMIT select_limit_value ',' select_offset_value
7652 /* Disabled because it was too confusing, bjm 2002-02-18 */
7654 (errcode(ERRCODE_SYNTAX_ERROR),
7655 errmsg("LIMIT #,# syntax is not supported"),
7656 errhint("Use separate LIMIT and OFFSET clauses."),
7657 parser_errposition(@1)));
7659 /* SQL:2008 syntax */
7660 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
7665 OFFSET select_offset_value
7667 /* SQL:2008 syntax */
7668 | OFFSET select_offset_value2 row_or_rows
7676 /* LIMIT ALL is represented as a NULL constant */
7677 $$ = makeNullAConst(@1);
7681 select_offset_value:
7686 * Allowing full expressions without parentheses causes various parsing
7687 * problems with the trailing ROW/ROWS key words. SQL only calls for
7688 * constants, so we allow the rest only with parentheses. If omitted,
7691 opt_select_fetch_first_value:
7692 SignedIconst { $$ = makeIntConst($1, @1); }
7693 | '(' a_expr ')' { $$ = $2; }
7694 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
7698 * Again, the trailing ROW/ROWS in this case prevent the full expression
7699 * syntax. c_expr is the best we can do.
7701 select_offset_value2:
7706 row_or_rows: ROW { $$ = 0; }
7710 first_or_next: FIRST_P { $$ = 0; }
7716 GROUP_P BY expr_list { $$ = $3; }
7717 | /*EMPTY*/ { $$ = NIL; }
7721 HAVING a_expr { $$ = $2; }
7722 | /*EMPTY*/ { $$ = NULL; }
7726 for_locking_items { $$ = $1; }
7727 | FOR READ ONLY { $$ = NIL; }
7730 opt_for_locking_clause:
7731 for_locking_clause { $$ = $1; }
7732 | /* EMPTY */ { $$ = NIL; }
7736 for_locking_item { $$ = list_make1($1); }
7737 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
7741 FOR UPDATE locked_rels_list opt_nowait
7743 LockingClause *n = makeNode(LockingClause);
7745 n->forUpdate = TRUE;
7749 | FOR SHARE locked_rels_list opt_nowait
7751 LockingClause *n = makeNode(LockingClause);
7753 n->forUpdate = FALSE;
7760 OF qualified_name_list { $$ = $2; }
7761 | /* EMPTY */ { $$ = NIL; }
7768 SelectStmt *n = makeNode(SelectStmt);
7769 n->valuesLists = list_make1($2);
7772 | values_clause ',' ctext_row
7774 SelectStmt *n = (SelectStmt *) $1;
7775 n->valuesLists = lappend(n->valuesLists, $3);
7781 /*****************************************************************************
7783 * clauses common to all Optimizable Stmts:
7784 * from_clause - allow list of both JOIN expressions and table names
7785 * where_clause - qualifications for joins or restrictions
7787 *****************************************************************************/
7790 FROM from_list { $$ = $2; }
7791 | /*EMPTY*/ { $$ = NIL; }
7795 table_ref { $$ = list_make1($1); }
7796 | from_list ',' table_ref { $$ = lappend($1, $3); }
7800 * table_ref is where an alias clause can be attached. Note we cannot make
7801 * alias_clause have an empty production because that causes parse conflicts
7802 * between table_ref := '(' joined_table ')' alias_clause
7803 * and joined_table := '(' joined_table ')'. So, we must have the
7804 * redundant-looking productions here instead.
7806 table_ref: relation_expr
7810 | relation_expr alias_clause
7817 RangeFunction *n = makeNode(RangeFunction);
7818 n->funccallnode = $1;
7819 n->coldeflist = NIL;
7822 | func_table alias_clause
7824 RangeFunction *n = makeNode(RangeFunction);
7825 n->funccallnode = $1;
7827 n->coldeflist = NIL;
7830 | func_table AS '(' TableFuncElementList ')'
7832 RangeFunction *n = makeNode(RangeFunction);
7833 n->funccallnode = $1;
7837 | func_table AS ColId '(' TableFuncElementList ')'
7839 RangeFunction *n = makeNode(RangeFunction);
7840 Alias *a = makeNode(Alias);
7841 n->funccallnode = $1;
7847 | func_table ColId '(' TableFuncElementList ')'
7849 RangeFunction *n = makeNode(RangeFunction);
7850 Alias *a = makeNode(Alias);
7851 n->funccallnode = $1;
7857 | select_with_parens
7860 * The SQL spec does not permit a subselect
7861 * (<derived_table>) without an alias clause,
7862 * so we don't either. This avoids the problem
7863 * of needing to invent a unique refname for it.
7864 * That could be surmounted if there's sufficient
7865 * popular demand, but for now let's just implement
7866 * the spec and see if anyone complains.
7867 * However, it does seem like a good idea to emit
7868 * an error message that's better than "syntax error".
7870 if (IsA($1, SelectStmt) &&
7871 ((SelectStmt *) $1)->valuesLists)
7873 (errcode(ERRCODE_SYNTAX_ERROR),
7874 errmsg("VALUES in FROM must have an alias"),
7875 errhint("For example, FROM (VALUES ...) [AS] foo."),
7876 parser_errposition(@1)));
7879 (errcode(ERRCODE_SYNTAX_ERROR),
7880 errmsg("subquery in FROM must have an alias"),
7881 errhint("For example, FROM (SELECT ...) [AS] foo."),
7882 parser_errposition(@1)));
7885 | select_with_parens alias_clause
7887 RangeSubselect *n = makeNode(RangeSubselect);
7896 | '(' joined_table ')' alias_clause
7905 * It may seem silly to separate joined_table from table_ref, but there is
7906 * method in SQL92's madness: if you don't do it this way you get reduce-
7907 * reduce conflicts, because it's not clear to the parser generator whether
7908 * to expect alias_clause after ')' or not. For the same reason we must
7909 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
7910 * join_type to expand to empty; if we try it, the parser generator can't
7911 * figure out when to reduce an empty join_type right after table_ref.
7913 * Note that a CROSS JOIN is the same as an unqualified
7914 * INNER JOIN, and an INNER JOIN/ON has the same shape
7915 * but a qualification expression to limit membership.
7916 * A NATURAL JOIN implicitly matches column names between
7917 * tables and the shape is determined by which columns are
7918 * in common. We'll collect columns during the later transformations.
7922 '(' joined_table ')'
7926 | table_ref CROSS JOIN table_ref
7928 /* CROSS JOIN is same as unqualified inner join */
7929 JoinExpr *n = makeNode(JoinExpr);
7930 n->jointype = JOIN_INNER;
7931 n->isNatural = FALSE;
7934 n->usingClause = NIL;
7938 | table_ref join_type JOIN table_ref join_qual
7940 JoinExpr *n = makeNode(JoinExpr);
7942 n->isNatural = FALSE;
7945 if ($5 != NULL && IsA($5, List))
7946 n->usingClause = (List *) $5; /* USING clause */
7948 n->quals = $5; /* ON clause */
7951 | table_ref JOIN table_ref join_qual
7953 /* letting join_type reduce to empty doesn't work */
7954 JoinExpr *n = makeNode(JoinExpr);
7955 n->jointype = JOIN_INNER;
7956 n->isNatural = FALSE;
7959 if ($4 != NULL && IsA($4, List))
7960 n->usingClause = (List *) $4; /* USING clause */
7962 n->quals = $4; /* ON clause */
7965 | table_ref NATURAL join_type JOIN table_ref
7967 JoinExpr *n = makeNode(JoinExpr);
7969 n->isNatural = TRUE;
7972 n->usingClause = NIL; /* figure out which columns later... */
7973 n->quals = NULL; /* fill later */
7976 | table_ref NATURAL JOIN table_ref
7978 /* letting join_type reduce to empty doesn't work */
7979 JoinExpr *n = makeNode(JoinExpr);
7980 n->jointype = JOIN_INNER;
7981 n->isNatural = TRUE;
7984 n->usingClause = NIL; /* figure out which columns later... */
7985 n->quals = NULL; /* fill later */
7991 AS ColId '(' name_list ')'
7993 $$ = makeNode(Alias);
7999 $$ = makeNode(Alias);
8002 | ColId '(' name_list ')'
8004 $$ = makeNode(Alias);
8010 $$ = makeNode(Alias);
8015 join_type: FULL join_outer { $$ = JOIN_FULL; }
8016 | LEFT join_outer { $$ = JOIN_LEFT; }
8017 | RIGHT join_outer { $$ = JOIN_RIGHT; }
8018 | INNER_P { $$ = JOIN_INNER; }
8021 /* OUTER is just noise... */
8022 join_outer: OUTER_P { $$ = NULL; }
8023 | /*EMPTY*/ { $$ = NULL; }
8026 /* JOIN qualification clauses
8027 * Possibilities are:
8028 * USING ( column list ) allows only unqualified column names,
8029 * which must match between tables.
8030 * ON expr allows more general qualifications.
8032 * We return USING as a List node, while an ON-expr will not be a List.
8035 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
8036 | ON a_expr { $$ = $2; }
8043 /* default inheritance */
8045 $$->inhOpt = INH_DEFAULT;
8048 | qualified_name '*'
8050 /* inheritance query */
8052 $$->inhOpt = INH_YES;
8055 | ONLY qualified_name
8057 /* no inheritance */
8059 $$->inhOpt = INH_NO;
8062 | ONLY '(' qualified_name ')'
8064 /* no inheritance, SQL99-style syntax */
8066 $$->inhOpt = INH_NO;
8073 relation_expr { $$ = list_make1($1); }
8074 | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
8079 * Given "UPDATE foo set set ...", we have to decide without looking any
8080 * further ahead whether the first "set" is an alias or the UPDATE's SET
8081 * keyword. Since "set" is allowed as a column name both interpretations
8082 * are feasible. We resolve the shift/reduce conflict by giving the first
8083 * relation_expr_opt_alias production a higher precedence than the SET token
8084 * has, causing the parser to prefer to reduce, in effect assuming that the
8085 * SET is not an alias.
8087 relation_expr_opt_alias: relation_expr %prec UMINUS
8091 | relation_expr ColId
8093 Alias *alias = makeNode(Alias);
8094 alias->aliasname = $2;
8098 | relation_expr AS ColId
8100 Alias *alias = makeNode(Alias);
8101 alias->aliasname = $3;
8108 func_table: func_expr { $$ = $1; }
8113 WHERE a_expr { $$ = $2; }
8114 | /*EMPTY*/ { $$ = NULL; }
8117 /* variant for UPDATE and DELETE */
8118 where_or_current_clause:
8119 WHERE a_expr { $$ = $2; }
8120 | WHERE CURRENT_P OF name
8122 CurrentOfExpr *n = makeNode(CurrentOfExpr);
8123 /* cvarno is filled in by parse analysis */
8124 n->cursor_name = $4;
8125 n->cursor_param = 0;
8128 | /*EMPTY*/ { $$ = NULL; }
8132 TableFuncElementList:
8135 $$ = list_make1($1);
8137 | TableFuncElementList ',' TableFuncElement
8139 $$ = lappend($1, $3);
8143 TableFuncElement: ColId Typename
8145 ColumnDef *n = makeNode(ColumnDef);
8148 n->constraints = NIL;
8154 /*****************************************************************************
8157 * SQL92 introduces a large amount of type-specific syntax.
8158 * Define individual clauses to handle these cases, and use
8159 * the generic case to handle regular type-extensible Postgres syntax.
8160 * - thomas 1997-10-10
8162 *****************************************************************************/
8164 Typename: SimpleTypename opt_array_bounds
8167 $$->arrayBounds = $2;
8169 | SETOF SimpleTypename opt_array_bounds
8172 $$->arrayBounds = $3;
8175 /* SQL standard syntax, currently only one-dimensional */
8176 | SimpleTypename ARRAY '[' Iconst ']'
8179 $$->arrayBounds = list_make1(makeInteger($4));
8181 | SETOF SimpleTypename ARRAY '[' Iconst ']'
8184 $$->arrayBounds = list_make1(makeInteger($5));
8187 | SimpleTypename ARRAY
8190 $$->arrayBounds = list_make1(makeInteger(-1));
8192 | SETOF SimpleTypename ARRAY
8195 $$->arrayBounds = list_make1(makeInteger(-1));
8201 opt_array_bounds '[' ']'
8202 { $$ = lappend($1, makeInteger(-1)); }
8203 | opt_array_bounds '[' Iconst ']'
8204 { $$ = lappend($1, makeInteger($3)); }
8210 GenericType { $$ = $1; }
8211 | Numeric { $$ = $1; }
8213 | Character { $$ = $1; }
8214 | ConstDatetime { $$ = $1; }
8215 | ConstInterval opt_interval
8220 | ConstInterval '(' Iconst ')' opt_interval
8225 if (list_length($5) != 1)
8227 (errcode(ERRCODE_SYNTAX_ERROR),
8228 errmsg("interval precision specified twice"),
8229 parser_errposition(@1)));
8230 $$->typmods = lappend($5, makeIntConst($3, @3));
8233 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
8234 makeIntConst($3, @3));
8238 /* We have a separate ConstTypename to allow defaulting fixed-length
8239 * types such as CHAR() and BIT() to an unspecified length.
8240 * SQL9x requires that these default to a length of one, but this
8241 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
8242 * where there is an obvious better choice to make.
8243 * Note that ConstInterval is not included here since it must
8244 * be pushed up higher in the rules to accomodate the postfix
8245 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
8246 * the generic-type-name case in AExprConst to avoid premature
8247 * reduce/reduce conflicts against function names.
8250 Numeric { $$ = $1; }
8251 | ConstBit { $$ = $1; }
8252 | ConstCharacter { $$ = $1; }
8253 | ConstDatetime { $$ = $1; }
8257 * GenericType covers all type names that don't have special syntax mandated
8258 * by the standard, including qualified names. We also allow type modifiers.
8259 * To avoid parsing conflicts against function invocations, the modifiers
8260 * have to be shown as expr_list here, but parse analysis will only accept
8261 * constants for them.
8264 type_function_name opt_type_modifiers
8266 $$ = makeTypeName($1);
8270 | type_function_name attrs opt_type_modifiers
8272 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8278 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
8279 | /* EMPTY */ { $$ = NIL; }
8283 * SQL92 numeric data types
8287 $$ = SystemTypeName("int4");
8292 $$ = SystemTypeName("int4");
8297 $$ = SystemTypeName("int2");
8302 $$ = SystemTypeName("int8");
8307 $$ = SystemTypeName("float4");
8315 | DOUBLE_P PRECISION
8317 $$ = SystemTypeName("float8");
8320 | DECIMAL_P opt_type_modifiers
8322 $$ = SystemTypeName("numeric");
8326 | DEC opt_type_modifiers
8328 $$ = SystemTypeName("numeric");
8332 | NUMERIC opt_type_modifiers
8334 $$ = SystemTypeName("numeric");
8340 $$ = SystemTypeName("bool");
8345 opt_float: '(' Iconst ')'
8348 * Check FLOAT() precision limits assuming IEEE floating
8349 * types - thomas 1997-09-18
8353 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8354 errmsg("precision for type float must be at least 1 bit"),
8355 parser_errposition(@2)));
8357 $$ = SystemTypeName("float4");
8359 $$ = SystemTypeName("float8");
8362 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8363 errmsg("precision for type float must be less than 54 bits"),
8364 parser_errposition(@2)));
8368 $$ = SystemTypeName("float8");
8373 * SQL92 bit-field data types
8374 * The following implements BIT() and BIT VARYING().
8386 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
8387 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
8388 ConstBit: BitWithLength
8400 BIT opt_varying '(' expr_list ')'
8404 typname = $2 ? "varbit" : "bit";
8405 $$ = SystemTypeName(typname);
8414 /* bit defaults to bit(1), varbit to no limit */
8417 $$ = SystemTypeName("varbit");
8421 $$ = SystemTypeName("bit");
8422 $$->typmods = list_make1(makeIntConst(1, -1));
8430 * SQL92 character data types
8431 * The following implements CHAR() and VARCHAR().
8433 Character: CharacterWithLength
8437 | CharacterWithoutLength
8443 ConstCharacter: CharacterWithLength
8447 | CharacterWithoutLength
8449 /* Length was not specified so allow to be unrestricted.
8450 * This handles problems with fixed-length (bpchar) strings
8451 * which in column definitions must default to a length
8452 * of one, but should not be constrained if the length
8453 * was not specified.
8460 CharacterWithLength: character '(' Iconst ')' opt_charset
8462 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
8466 type = palloc(strlen($1) + 1 + strlen($5) + 1);
8473 $$ = SystemTypeName($1);
8474 $$->typmods = list_make1(makeIntConst($3, @3));
8479 CharacterWithoutLength: character opt_charset
8481 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
8485 type = palloc(strlen($1) + 1 + strlen($2) + 1);
8492 $$ = SystemTypeName($1);
8494 /* char defaults to char(1), varchar to no limit */
8495 if (strcmp($1, "bpchar") == 0)
8496 $$->typmods = list_make1(makeIntConst(1, -1));
8502 character: CHARACTER opt_varying
8503 { $$ = $2 ? "varchar": "bpchar"; }
8504 | CHAR_P opt_varying
8505 { $$ = $2 ? "varchar": "bpchar"; }
8508 | NATIONAL CHARACTER opt_varying
8509 { $$ = $3 ? "varchar": "bpchar"; }
8510 | NATIONAL CHAR_P opt_varying
8511 { $$ = $3 ? "varchar": "bpchar"; }
8513 { $$ = $2 ? "varchar": "bpchar"; }
8517 VARYING { $$ = TRUE; }
8518 | /*EMPTY*/ { $$ = FALSE; }
8522 CHARACTER SET ColId { $$ = $3; }
8523 | /*EMPTY*/ { $$ = NULL; }
8527 * SQL92 date/time types
8530 TIMESTAMP '(' Iconst ')' opt_timezone
8533 $$ = SystemTypeName("timestamptz");
8535 $$ = SystemTypeName("timestamp");
8536 $$->typmods = list_make1(makeIntConst($3, @3));
8539 | TIMESTAMP opt_timezone
8542 $$ = SystemTypeName("timestamptz");
8544 $$ = SystemTypeName("timestamp");
8547 | TIME '(' Iconst ')' opt_timezone
8550 $$ = SystemTypeName("timetz");
8552 $$ = SystemTypeName("time");
8553 $$->typmods = list_make1(makeIntConst($3, @3));
8559 $$ = SystemTypeName("timetz");
8561 $$ = SystemTypeName("time");
8569 $$ = SystemTypeName("interval");
8575 WITH_TIME ZONE { $$ = TRUE; }
8576 | WITHOUT TIME ZONE { $$ = FALSE; }
8577 | /*EMPTY*/ { $$ = FALSE; }
8582 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
8584 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
8586 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
8588 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
8590 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
8595 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
8596 INTERVAL_MASK(MONTH), @1));
8600 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8601 INTERVAL_MASK(HOUR), @1));
8605 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8606 INTERVAL_MASK(HOUR) |
8607 INTERVAL_MASK(MINUTE), @1));
8609 | DAY_P TO interval_second
8612 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
8613 INTERVAL_MASK(HOUR) |
8614 INTERVAL_MASK(MINUTE) |
8615 INTERVAL_MASK(SECOND), @1);
8617 | HOUR_P TO MINUTE_P
8619 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
8620 INTERVAL_MASK(MINUTE), @1));
8622 | HOUR_P TO interval_second
8625 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
8626 INTERVAL_MASK(MINUTE) |
8627 INTERVAL_MASK(SECOND), @1);
8629 | MINUTE_P TO interval_second
8632 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
8633 INTERVAL_MASK(SECOND), @1);
8642 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
8644 | SECOND_P '(' Iconst ')'
8646 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
8647 makeIntConst($3, @3));
8652 /*****************************************************************************
8654 * expression grammar
8656 *****************************************************************************/
8659 * General expressions
8660 * This is the heart of the expression syntax.
8662 * We have two expression types: a_expr is the unrestricted kind, and
8663 * b_expr is a subset that must be used in some places to avoid shift/reduce
8664 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
8665 * because that use of AND conflicts with AND as a boolean operator. So,
8666 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
8668 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
8669 * always be used by surrounding it with parens.
8671 * c_expr is all the productions that are common to a_expr and b_expr;
8672 * it's factored out just to eliminate redundant coding.
8674 a_expr: c_expr { $$ = $1; }
8675 | a_expr TYPECAST Typename
8676 { $$ = makeTypeCast($1, $3, @2); }
8677 | a_expr AT TIME ZONE a_expr
8679 FuncCall *n = makeNode(FuncCall);
8680 n->funcname = SystemFuncName("timezone");
8681 n->args = list_make2($5, $1);
8683 n->agg_star = FALSE;
8684 n->agg_distinct = FALSE;
8685 n->func_variadic = FALSE;
8691 * These operators must be called out explicitly in order to make use
8692 * of bison's automatic operator-precedence handling. All other
8693 * operator names are handled by the generic productions using "Op",
8694 * below; and all those operators will have the same precedence.
8696 * If you add more explicitly-known operators, be sure to add them
8697 * also to b_expr and to the MathOp list above.
8699 | '+' a_expr %prec UMINUS
8700 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
8701 | '-' a_expr %prec UMINUS
8702 { $$ = doNegate($2, @1); }
8704 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
8706 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
8708 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
8710 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
8712 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
8714 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
8716 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
8718 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
8720 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
8722 | a_expr qual_Op a_expr %prec Op
8723 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
8724 | qual_Op a_expr %prec Op
8725 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
8726 | a_expr qual_Op %prec POSTFIXOP
8727 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
8730 { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
8732 { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
8734 { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
8736 | a_expr LIKE a_expr
8737 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
8738 | a_expr LIKE a_expr ESCAPE a_expr
8740 FuncCall *n = makeNode(FuncCall);
8741 n->funcname = SystemFuncName("like_escape");
8742 n->args = list_make2($3, $5);
8744 n->agg_star = FALSE;
8745 n->agg_distinct = FALSE;
8746 n->func_variadic = FALSE;
8749 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
8751 | a_expr NOT LIKE a_expr
8752 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
8753 | a_expr NOT LIKE a_expr ESCAPE a_expr
8755 FuncCall *n = makeNode(FuncCall);
8756 n->funcname = SystemFuncName("like_escape");
8757 n->args = list_make2($4, $6);
8759 n->agg_star = FALSE;
8760 n->agg_distinct = FALSE;
8761 n->func_variadic = FALSE;
8764 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
8766 | a_expr ILIKE a_expr
8767 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
8768 | a_expr ILIKE 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 ILIKE a_expr
8782 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
8783 | a_expr NOT ILIKE 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);
8797 | a_expr SIMILAR TO a_expr %prec SIMILAR
8799 FuncCall *n = makeNode(FuncCall);
8800 n->funcname = SystemFuncName("similar_escape");
8801 n->args = list_make2($4, makeNullAConst(-1));
8803 n->agg_star = FALSE;
8804 n->agg_distinct = FALSE;
8805 n->func_variadic = FALSE;
8808 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8810 | a_expr SIMILAR TO a_expr ESCAPE a_expr
8812 FuncCall *n = makeNode(FuncCall);
8813 n->funcname = SystemFuncName("similar_escape");
8814 n->args = list_make2($4, $6);
8816 n->agg_star = FALSE;
8817 n->agg_distinct = FALSE;
8818 n->func_variadic = FALSE;
8821 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
8823 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
8825 FuncCall *n = makeNode(FuncCall);
8826 n->funcname = SystemFuncName("similar_escape");
8827 n->args = list_make2($5, makeNullAConst(-1));
8829 n->agg_star = FALSE;
8830 n->agg_distinct = FALSE;
8831 n->func_variadic = FALSE;
8834 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8836 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
8838 FuncCall *n = makeNode(FuncCall);
8839 n->funcname = SystemFuncName("similar_escape");
8840 n->args = list_make2($5, $7);
8842 n->agg_star = FALSE;
8843 n->agg_distinct = FALSE;
8844 n->func_variadic = FALSE;
8847 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
8851 * Define SQL92-style Null test clause.
8852 * Allow two forms described in the standard:
8855 * Allow two SQL extensions
8861 NullTest *n = makeNode(NullTest);
8862 n->arg = (Expr *) $1;
8863 n->nulltesttype = IS_NULL;
8868 NullTest *n = makeNode(NullTest);
8869 n->arg = (Expr *) $1;
8870 n->nulltesttype = IS_NULL;
8873 | a_expr IS NOT NULL_P
8875 NullTest *n = makeNode(NullTest);
8876 n->arg = (Expr *) $1;
8877 n->nulltesttype = IS_NOT_NULL;
8882 NullTest *n = makeNode(NullTest);
8883 n->arg = (Expr *) $1;
8884 n->nulltesttype = IS_NOT_NULL;
8889 $$ = (Node *)makeOverlaps($1, $3, @2, yyscanner);
8893 BooleanTest *b = makeNode(BooleanTest);
8894 b->arg = (Expr *) $1;
8895 b->booltesttype = IS_TRUE;
8898 | a_expr IS NOT TRUE_P
8900 BooleanTest *b = makeNode(BooleanTest);
8901 b->arg = (Expr *) $1;
8902 b->booltesttype = IS_NOT_TRUE;
8907 BooleanTest *b = makeNode(BooleanTest);
8908 b->arg = (Expr *) $1;
8909 b->booltesttype = IS_FALSE;
8912 | a_expr IS NOT FALSE_P
8914 BooleanTest *b = makeNode(BooleanTest);
8915 b->arg = (Expr *) $1;
8916 b->booltesttype = IS_NOT_FALSE;
8921 BooleanTest *b = makeNode(BooleanTest);
8922 b->arg = (Expr *) $1;
8923 b->booltesttype = IS_UNKNOWN;
8926 | a_expr IS NOT UNKNOWN
8928 BooleanTest *b = makeNode(BooleanTest);
8929 b->arg = (Expr *) $1;
8930 b->booltesttype = IS_NOT_UNKNOWN;
8933 | a_expr IS DISTINCT FROM a_expr %prec IS
8935 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
8937 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
8939 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
8940 (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
8945 | a_expr IS OF '(' type_list ')' %prec IS
8947 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
8949 | a_expr IS NOT OF '(' type_list ')' %prec IS
8951 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
8954 * Ideally we would not use hard-wired operators below but
8955 * instead use opclasses. However, mixed data types and other
8956 * issues make this difficult:
8957 * http://archives.postgresql.org/pgsql-hackers/2008-08/msg01142.php
8959 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
8961 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
8962 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
8963 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
8966 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
8968 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
8969 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
8970 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
8973 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
8975 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
8976 (Node *) makeA_Expr(AEXPR_AND, NIL,
8977 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
8978 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
8980 (Node *) makeA_Expr(AEXPR_AND, NIL,
8981 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
8982 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
8986 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
8988 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
8989 (Node *) makeA_Expr(AEXPR_OR, NIL,
8990 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
8991 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
8993 (Node *) makeA_Expr(AEXPR_OR, NIL,
8994 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
8995 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
8999 | a_expr IN_P in_expr
9001 /* in_expr returns a SubLink or a list of a_exprs */
9002 if (IsA($3, SubLink))
9004 /* generate foo = ANY (subquery) */
9005 SubLink *n = (SubLink *) $3;
9006 n->subLinkType = ANY_SUBLINK;
9008 n->operName = list_make1(makeString("="));
9014 /* generate scalar IN expression */
9015 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
9018 | a_expr NOT IN_P in_expr
9020 /* in_expr returns a SubLink or a list of a_exprs */
9021 if (IsA($4, SubLink))
9023 /* generate NOT (foo = ANY (subquery)) */
9024 /* Make an = ANY node */
9025 SubLink *n = (SubLink *) $4;
9026 n->subLinkType = ANY_SUBLINK;
9028 n->operName = list_make1(makeString("="));
9030 /* Stick a NOT on top */
9031 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
9035 /* generate scalar NOT IN expression */
9036 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
9039 | a_expr subquery_Op sub_type select_with_parens %prec Op
9041 SubLink *n = makeNode(SubLink);
9042 n->subLinkType = $3;
9049 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
9051 if ($3 == ANY_SUBLINK)
9052 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
9054 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
9056 | UNIQUE select_with_parens
9058 /* Not sure how to get rid of the parentheses
9059 * but there are lots of shift/reduce errors without them.
9061 * Should be able to implement this by plopping the entire
9062 * select into a node, then transforming the target expressions
9063 * from whatever they are into count(*), and testing the
9064 * entire result equal to one.
9065 * But, will probably implement a separate node in the executor.
9068 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9069 errmsg("UNIQUE predicate is not yet implemented"),
9070 parser_errposition(@1)));
9072 | a_expr IS DOCUMENT_P %prec IS
9074 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9075 list_make1($1), @2);
9077 | a_expr IS NOT DOCUMENT_P %prec IS
9079 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9080 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9081 list_make1($1), @2),
9087 * Restricted expressions
9089 * b_expr is a subset of the complete expression syntax defined by a_expr.
9091 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
9092 * cause trouble in the places where b_expr is used. For simplicity, we
9093 * just eliminate all the boolean-keyword-operator productions from b_expr.
9097 | b_expr TYPECAST Typename
9098 { $$ = makeTypeCast($1, $3, @2); }
9099 | '+' b_expr %prec UMINUS
9100 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
9101 | '-' b_expr %prec UMINUS
9102 { $$ = doNegate($2, @1); }
9104 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
9106 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
9108 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
9110 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
9112 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
9114 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
9116 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
9118 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
9120 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
9121 | b_expr qual_Op b_expr %prec Op
9122 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
9123 | qual_Op b_expr %prec Op
9124 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
9125 | b_expr qual_Op %prec POSTFIXOP
9126 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
9127 | b_expr IS DISTINCT FROM b_expr %prec IS
9129 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
9131 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
9133 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
9134 NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
9136 | b_expr IS OF '(' type_list ')' %prec IS
9138 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
9140 | b_expr IS NOT OF '(' type_list ')' %prec IS
9142 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
9144 | b_expr IS DOCUMENT_P %prec IS
9146 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9147 list_make1($1), @2);
9149 | b_expr IS NOT DOCUMENT_P %prec IS
9151 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9152 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9153 list_make1($1), @2),
9159 * Productions that can be used in both a_expr and b_expr.
9161 * Note: productions that refer recursively to a_expr or b_expr mostly
9162 * cannot appear here. However, it's OK to refer to a_exprs that occur
9163 * inside parentheses, such as function arguments; that cannot introduce
9164 * ambiguity to the b_expr syntax.
9166 c_expr: columnref { $$ = $1; }
9167 | AexprConst { $$ = $1; }
9168 | PARAM opt_indirection
9170 ParamRef *p = makeNode(ParamRef);
9175 A_Indirection *n = makeNode(A_Indirection);
9176 n->arg = (Node *) p;
9177 n->indirection = check_indirection($2, yyscanner);
9183 | '(' a_expr ')' opt_indirection
9187 A_Indirection *n = makeNode(A_Indirection);
9189 n->indirection = check_indirection($4, yyscanner);
9199 | select_with_parens %prec UMINUS
9201 SubLink *n = makeNode(SubLink);
9202 n->subLinkType = EXPR_SUBLINK;
9209 | EXISTS select_with_parens
9211 SubLink *n = makeNode(SubLink);
9212 n->subLinkType = EXISTS_SUBLINK;
9219 | ARRAY select_with_parens
9221 SubLink *n = makeNode(SubLink);
9222 n->subLinkType = ARRAY_SUBLINK;
9231 A_ArrayExpr *n = (A_ArrayExpr *) $2;
9232 Assert(IsA(n, A_ArrayExpr));
9233 /* point outermost A_ArrayExpr to the ARRAY keyword */
9239 RowExpr *r = makeNode(RowExpr);
9241 r->row_typeid = InvalidOid; /* not analyzed yet */
9248 * func_expr is split out from c_expr just so that we have a classification
9249 * for "everything that is a function call or looks like one". This isn't
9250 * very important, but it saves us having to document which variants are
9251 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
9252 * (Note that many of the special SQL functions wouldn't actually make any
9253 * sense as functional index entries, but we ignore that consideration here.)
9255 func_expr: func_name '(' ')' over_clause
9257 FuncCall *n = makeNode(FuncCall);
9261 n->agg_star = FALSE;
9262 n->agg_distinct = FALSE;
9263 n->func_variadic = FALSE;
9268 | func_name '(' func_arg_list ')' over_clause
9270 FuncCall *n = makeNode(FuncCall);
9274 n->agg_star = FALSE;
9275 n->agg_distinct = FALSE;
9276 n->func_variadic = FALSE;
9281 | func_name '(' VARIADIC func_arg_expr ')' over_clause
9283 FuncCall *n = makeNode(FuncCall);
9285 n->args = list_make1($4);
9287 n->agg_star = FALSE;
9288 n->agg_distinct = FALSE;
9289 n->func_variadic = TRUE;
9294 | func_name '(' func_arg_list ',' VARIADIC func_arg_expr ')' over_clause
9296 FuncCall *n = makeNode(FuncCall);
9298 n->args = lappend($3, $6);
9300 n->agg_star = FALSE;
9301 n->agg_distinct = FALSE;
9302 n->func_variadic = TRUE;
9307 | func_name '(' func_arg_list sort_clause ')' over_clause
9309 FuncCall *n = makeNode(FuncCall);
9313 n->agg_star = FALSE;
9314 n->agg_distinct = FALSE;
9315 n->func_variadic = FALSE;
9320 | func_name '(' ALL func_arg_list opt_sort_clause ')' over_clause
9322 FuncCall *n = makeNode(FuncCall);
9326 n->agg_star = FALSE;
9327 n->agg_distinct = FALSE;
9328 /* Ideally we'd mark the FuncCall node to indicate
9329 * "must be an aggregate", but there's no provision
9330 * for that in FuncCall at the moment.
9332 n->func_variadic = FALSE;
9337 | func_name '(' DISTINCT func_arg_list opt_sort_clause ')' over_clause
9339 FuncCall *n = makeNode(FuncCall);
9343 n->agg_star = FALSE;
9344 n->agg_distinct = TRUE;
9345 n->func_variadic = FALSE;
9350 | func_name '(' '*' ')' over_clause
9353 * We consider AGGREGATE(*) to invoke a parameterless
9354 * aggregate. This does the right thing for COUNT(*),
9355 * and there are no other aggregates in SQL92 that accept
9358 * The FuncCall node is also marked agg_star = true,
9359 * so that later processing can detect what the argument
9362 FuncCall *n = makeNode(FuncCall);
9367 n->agg_distinct = FALSE;
9368 n->func_variadic = FALSE;
9376 * Translate as "'now'::text::date".
9378 * We cannot use "'now'::date" because coerce_type() will
9379 * immediately reduce that to a constant representing
9380 * today's date. We need to delay the conversion until
9381 * runtime, else the wrong things will happen when
9382 * CURRENT_DATE is used in a column default value or rule.
9384 * This could be simplified if we had a way to generate
9385 * an expression tree representing runtime application
9386 * of type-input conversion functions. (As of PG 7.3
9387 * that is actually possible, but not clear that we want
9391 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9392 $$ = makeTypeCast(n, SystemTypeName("date"), -1);
9397 * Translate as "'now'::text::timetz".
9398 * See comments for CURRENT_DATE.
9401 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9402 $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
9404 | CURRENT_TIME '(' Iconst ')'
9407 * Translate as "'now'::text::timetz(n)".
9408 * See comments for CURRENT_DATE.
9412 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9413 d = SystemTypeName("timetz");
9414 d->typmods = list_make1(makeIntConst($3, @3));
9415 $$ = makeTypeCast(n, d, -1);
9420 * Translate as "now()", since we have a function that
9421 * does exactly what is needed.
9423 FuncCall *n = makeNode(FuncCall);
9424 n->funcname = SystemFuncName("now");
9427 n->agg_star = FALSE;
9428 n->agg_distinct = FALSE;
9429 n->func_variadic = FALSE;
9434 | CURRENT_TIMESTAMP '(' Iconst ')'
9437 * Translate as "'now'::text::timestamptz(n)".
9438 * See comments for CURRENT_DATE.
9442 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9443 d = SystemTypeName("timestamptz");
9444 d->typmods = list_make1(makeIntConst($3, @3));
9445 $$ = makeTypeCast(n, d, -1);
9450 * Translate as "'now'::text::time".
9451 * See comments for CURRENT_DATE.
9454 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9455 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
9457 | LOCALTIME '(' Iconst ')'
9460 * Translate as "'now'::text::time(n)".
9461 * See comments for CURRENT_DATE.
9465 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9466 d = SystemTypeName("time");
9467 d->typmods = list_make1(makeIntConst($3, @3));
9468 $$ = makeTypeCast((Node *)n, d, -1);
9473 * Translate as "'now'::text::timestamp".
9474 * See comments for CURRENT_DATE.
9477 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9478 $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
9480 | LOCALTIMESTAMP '(' Iconst ')'
9483 * Translate as "'now'::text::timestamp(n)".
9484 * See comments for CURRENT_DATE.
9488 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9489 d = SystemTypeName("timestamp");
9490 d->typmods = list_make1(makeIntConst($3, @3));
9491 $$ = makeTypeCast(n, d, -1);
9495 FuncCall *n = makeNode(FuncCall);
9496 n->funcname = SystemFuncName("current_user");
9499 n->agg_star = FALSE;
9500 n->agg_distinct = FALSE;
9501 n->func_variadic = FALSE;
9508 FuncCall *n = makeNode(FuncCall);
9509 n->funcname = SystemFuncName("current_user");
9512 n->agg_star = FALSE;
9513 n->agg_distinct = FALSE;
9514 n->func_variadic = FALSE;
9521 FuncCall *n = makeNode(FuncCall);
9522 n->funcname = SystemFuncName("session_user");
9525 n->agg_star = FALSE;
9526 n->agg_distinct = FALSE;
9527 n->func_variadic = FALSE;
9534 FuncCall *n = makeNode(FuncCall);
9535 n->funcname = SystemFuncName("current_user");
9538 n->agg_star = FALSE;
9539 n->agg_distinct = FALSE;
9540 n->func_variadic = FALSE;
9547 FuncCall *n = makeNode(FuncCall);
9548 n->funcname = SystemFuncName("current_database");
9551 n->agg_star = FALSE;
9552 n->agg_distinct = FALSE;
9553 n->func_variadic = FALSE;
9560 FuncCall *n = makeNode(FuncCall);
9561 n->funcname = SystemFuncName("current_schema");
9564 n->agg_star = FALSE;
9565 n->agg_distinct = FALSE;
9566 n->func_variadic = FALSE;
9571 | CAST '(' a_expr AS Typename ')'
9572 { $$ = makeTypeCast($3, $5, @1); }
9573 | EXTRACT '(' extract_list ')'
9575 FuncCall *n = makeNode(FuncCall);
9576 n->funcname = SystemFuncName("date_part");
9579 n->agg_star = FALSE;
9580 n->agg_distinct = FALSE;
9581 n->func_variadic = FALSE;
9586 | OVERLAY '(' overlay_list ')'
9588 /* overlay(A PLACING B FROM C FOR D) is converted to
9589 * overlay(A, B, C, D)
9590 * overlay(A PLACING B FROM C) is converted to
9593 FuncCall *n = makeNode(FuncCall);
9594 n->funcname = SystemFuncName("overlay");
9597 n->agg_star = FALSE;
9598 n->agg_distinct = FALSE;
9599 n->func_variadic = FALSE;
9604 | POSITION '(' position_list ')'
9606 /* position(A in B) is converted to position(B, A) */
9607 FuncCall *n = makeNode(FuncCall);
9608 n->funcname = SystemFuncName("position");
9611 n->agg_star = FALSE;
9612 n->agg_distinct = FALSE;
9613 n->func_variadic = FALSE;
9618 | SUBSTRING '(' substr_list ')'
9620 /* substring(A from B for C) is converted to
9621 * substring(A, B, C) - thomas 2000-11-28
9623 FuncCall *n = makeNode(FuncCall);
9624 n->funcname = SystemFuncName("substring");
9627 n->agg_star = FALSE;
9628 n->agg_distinct = FALSE;
9629 n->func_variadic = FALSE;
9634 | TREAT '(' a_expr AS Typename ')'
9636 /* TREAT(expr AS target) converts expr of a particular type to target,
9637 * which is defined to be a subtype of the original expression.
9638 * In SQL99, this is intended for use with structured UDTs,
9639 * but let's make this a generally useful form allowing stronger
9640 * coercions than are handled by implicit casting.
9642 FuncCall *n = makeNode(FuncCall);
9643 /* Convert SystemTypeName() to SystemFuncName() even though
9644 * at the moment they result in the same thing.
9646 n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
9647 n->args = list_make1($3);
9649 n->agg_star = FALSE;
9650 n->agg_distinct = FALSE;
9651 n->func_variadic = FALSE;
9656 | TRIM '(' BOTH trim_list ')'
9658 /* various trim expressions are defined in SQL92
9659 * - thomas 1997-07-19
9661 FuncCall *n = makeNode(FuncCall);
9662 n->funcname = SystemFuncName("btrim");
9665 n->agg_star = FALSE;
9666 n->agg_distinct = FALSE;
9667 n->func_variadic = FALSE;
9672 | TRIM '(' LEADING trim_list ')'
9674 FuncCall *n = makeNode(FuncCall);
9675 n->funcname = SystemFuncName("ltrim");
9678 n->agg_star = FALSE;
9679 n->agg_distinct = FALSE;
9680 n->func_variadic = FALSE;
9685 | TRIM '(' TRAILING trim_list ')'
9687 FuncCall *n = makeNode(FuncCall);
9688 n->funcname = SystemFuncName("rtrim");
9691 n->agg_star = FALSE;
9692 n->agg_distinct = FALSE;
9693 n->func_variadic = FALSE;
9698 | TRIM '(' trim_list ')'
9700 FuncCall *n = makeNode(FuncCall);
9701 n->funcname = SystemFuncName("btrim");
9704 n->agg_star = FALSE;
9705 n->agg_distinct = FALSE;
9706 n->func_variadic = FALSE;
9711 | NULLIF '(' a_expr ',' a_expr ')'
9713 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
9715 | COALESCE '(' expr_list ')'
9717 CoalesceExpr *c = makeNode(CoalesceExpr);
9722 | GREATEST '(' expr_list ')'
9724 MinMaxExpr *v = makeNode(MinMaxExpr);
9726 v->op = IS_GREATEST;
9730 | LEAST '(' expr_list ')'
9732 MinMaxExpr *v = makeNode(MinMaxExpr);
9738 | XMLCONCAT '(' expr_list ')'
9740 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
9742 | XMLELEMENT '(' NAME_P ColLabel ')'
9744 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
9746 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
9748 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
9750 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
9752 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
9754 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
9756 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
9758 | XMLFOREST '(' xml_attribute_list ')'
9760 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
9762 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
9764 XmlExpr *x = (XmlExpr *)
9765 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
9766 list_make2($4, makeBoolAConst($5, -1)),
9771 | XMLPI '(' NAME_P ColLabel ')'
9773 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
9775 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
9777 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
9779 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
9781 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
9782 list_make3($3, $5, $6), @1);
9784 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
9786 XmlSerialize *n = makeNode(XmlSerialize);
9798 xml_root_version: VERSION_P a_expr
9800 | VERSION_P NO VALUE_P
9801 { $$ = makeNullAConst(-1); }
9804 opt_xml_root_standalone: ',' STANDALONE_P YES_P
9805 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
9806 | ',' STANDALONE_P NO
9807 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
9808 | ',' STANDALONE_P NO VALUE_P
9809 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
9811 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
9814 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
9817 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
9818 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
9821 xml_attribute_el: a_expr AS ColLabel
9823 $$ = makeNode(ResTarget);
9825 $$->indirection = NIL;
9826 $$->val = (Node *) $1;
9831 $$ = makeNode(ResTarget);
9833 $$->indirection = NIL;
9834 $$->val = (Node *) $1;
9839 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
9840 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
9843 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
9844 | STRIP_P WHITESPACE_P { $$ = FALSE; }
9845 | /*EMPTY*/ { $$ = FALSE; }
9849 * Window Definitions
9852 WINDOW window_definition_list { $$ = $2; }
9853 | /*EMPTY*/ { $$ = NIL; }
9856 window_definition_list:
9857 window_definition { $$ = list_make1($1); }
9858 | window_definition_list ',' window_definition
9859 { $$ = lappend($1, $3); }
9863 ColId AS window_specification
9871 over_clause: OVER window_specification
9875 WindowDef *n = makeNode(WindowDef);
9878 n->partitionClause = NIL;
9879 n->orderClause = NIL;
9880 n->frameOptions = FRAMEOPTION_DEFAULTS;
9888 window_specification: '(' opt_existing_window_name opt_partition_clause
9889 opt_sort_clause opt_frame_clause ')'
9891 WindowDef *n = makeNode(WindowDef);
9894 n->partitionClause = $3;
9895 n->orderClause = $4;
9896 n->frameOptions = $5;
9903 * If we see PARTITION, RANGE, or ROWS as the first token after the '('
9904 * of a window_specification, we want the assumption to be that there is
9905 * no existing_window_name; but those keywords are unreserved and so could
9906 * be ColIds. We fix this by making them have the same precedence as IDENT
9907 * and giving the empty production here a slightly higher precedence, so
9908 * that the shift/reduce conflict is resolved in favor of reducing the rule.
9909 * These keywords are thus precluded from being an existing_window_name but
9910 * are not reserved for any other purpose.
9912 opt_existing_window_name: ColId { $$ = $1; }
9913 | /*EMPTY*/ %prec Op { $$ = NULL; }
9916 opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
9917 | /*EMPTY*/ { $$ = NIL; }
9921 * This is only a subset of the full SQL:2008 frame_clause grammar.
9922 * We don't support <expression> PRECEDING, <expression> FOLLOWING,
9923 * nor <window frame exclusion> yet.
9928 $$ = FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE | $2;
9932 $$ = FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS | $2;
9935 { $$ = FRAMEOPTION_DEFAULTS; }
9938 frame_extent: frame_bound
9940 /* reject invalid cases */
9941 if ($1 & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
9943 (errcode(ERRCODE_WINDOWING_ERROR),
9944 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
9945 parser_errposition(@1)));
9946 if ($1 & FRAMEOPTION_START_CURRENT_ROW)
9948 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9949 errmsg("frame start at CURRENT ROW is not implemented"),
9950 parser_errposition(@1)));
9951 $$ = $1 | FRAMEOPTION_END_CURRENT_ROW;
9953 | BETWEEN frame_bound AND frame_bound
9955 /* reject invalid cases */
9956 if ($2 & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
9958 (errcode(ERRCODE_WINDOWING_ERROR),
9959 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
9960 parser_errposition(@2)));
9961 if ($2 & FRAMEOPTION_START_CURRENT_ROW)
9963 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9964 errmsg("frame start at CURRENT ROW is not implemented"),
9965 parser_errposition(@2)));
9966 if ($4 & FRAMEOPTION_START_UNBOUNDED_PRECEDING)
9968 (errcode(ERRCODE_WINDOWING_ERROR),
9969 errmsg("frame end cannot be UNBOUNDED PRECEDING"),
9970 parser_errposition(@4)));
9971 /* shift converts START_ options to END_ options */
9972 $$ = FRAMEOPTION_BETWEEN | $2 | ($4 << 1);
9977 * This is used for both frame start and frame end, with output set up on
9978 * the assumption it's frame start; the frame_extent productions must reject
9984 $$ = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
9986 | UNBOUNDED FOLLOWING
9988 $$ = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
9992 $$ = FRAMEOPTION_START_CURRENT_ROW;
9998 * Supporting nonterminals for expressions.
10001 /* Explicit row production.
10003 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
10004 * without conflicting with the parenthesized a_expr production. Without the
10005 * ROW keyword, there must be more than one a_expr inside the parens.
10007 row: ROW '(' expr_list ')' { $$ = $3; }
10008 | ROW '(' ')' { $$ = NIL; }
10009 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
10012 sub_type: ANY { $$ = ANY_SUBLINK; }
10013 | SOME { $$ = ANY_SUBLINK; }
10014 | ALL { $$ = ALL_SUBLINK; }
10017 all_Op: Op { $$ = $1; }
10018 | MathOp { $$ = $1; }
10021 MathOp: '+' { $$ = "+"; }
10022 | '-' { $$ = "-"; }
10023 | '*' { $$ = "*"; }
10024 | '/' { $$ = "/"; }
10025 | '%' { $$ = "%"; }
10026 | '^' { $$ = "^"; }
10027 | '<' { $$ = "<"; }
10028 | '>' { $$ = ">"; }
10029 | '=' { $$ = "="; }
10033 { $$ = list_make1(makeString($1)); }
10034 | OPERATOR '(' any_operator ')'
10040 { $$ = list_make1(makeString($1)); }
10041 | OPERATOR '(' any_operator ')'
10047 { $$ = list_make1(makeString($1)); }
10048 | OPERATOR '(' any_operator ')'
10051 { $$ = list_make1(makeString("~~")); }
10053 { $$ = list_make1(makeString("!~~")); }
10055 { $$ = list_make1(makeString("~~*")); }
10057 { $$ = list_make1(makeString("!~~*")); }
10058 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
10059 * the regular expression is preprocessed by a function (similar_escape),
10060 * and the ~ operator for posix regular expressions is used.
10061 * x SIMILAR TO y -> x ~ similar_escape(y)
10062 * this transformation is made on the fly by the parser upwards.
10063 * however the SubLink structure which handles any/some/all stuff
10064 * is not ready for such a thing.
10070 $$ = list_make1($1);
10072 | expr_list ',' a_expr
10074 $$ = lappend($1, $3);
10078 /* function arguments can have names */
10079 func_arg_list: func_arg_expr
10081 $$ = list_make1($1);
10083 | func_arg_list ',' func_arg_expr
10085 $$ = lappend($1, $3);
10089 func_arg_expr: a_expr
10093 | a_expr AS param_name
10095 NamedArgExpr *na = makeNode(NamedArgExpr);
10096 na->arg = (Expr *) $1;
10098 na->argnumber = -1; /* until determined */
10104 type_list: Typename { $$ = list_make1($1); }
10105 | type_list ',' Typename { $$ = lappend($1, $3); }
10108 array_expr: '[' expr_list ']'
10110 $$ = makeAArrayExpr($2, @1);
10112 | '[' array_expr_list ']'
10114 $$ = makeAArrayExpr($2, @1);
10118 $$ = makeAArrayExpr(NIL, @1);
10122 array_expr_list: array_expr { $$ = list_make1($1); }
10123 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
10128 extract_arg FROM a_expr
10130 $$ = list_make2(makeStringConst($1, @1), $3);
10132 | /*EMPTY*/ { $$ = NIL; }
10135 /* Allow delimited string Sconst in extract_arg as an SQL extension.
10136 * - thomas 2001-04-12
10140 | YEAR_P { $$ = "year"; }
10141 | MONTH_P { $$ = "month"; }
10142 | DAY_P { $$ = "day"; }
10143 | HOUR_P { $$ = "hour"; }
10144 | MINUTE_P { $$ = "minute"; }
10145 | SECOND_P { $$ = "second"; }
10146 | Sconst { $$ = $1; }
10149 /* OVERLAY() arguments
10150 * SQL99 defines the OVERLAY() function:
10151 * o overlay(text placing text from int for int)
10152 * o overlay(text placing text from int)
10153 * and similarly for binary strings
10156 a_expr overlay_placing substr_from substr_for
10158 $$ = list_make4($1, $2, $3, $4);
10160 | a_expr overlay_placing substr_from
10162 $$ = list_make3($1, $2, $3);
10171 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
10174 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
10175 | /*EMPTY*/ { $$ = NIL; }
10178 /* SUBSTRING() arguments
10179 * SQL9x defines a specific syntax for arguments to SUBSTRING():
10180 * o substring(text from int for int)
10181 * o substring(text from int) get entire string from starting point "int"
10182 * o substring(text for int) get first "int" characters of string
10183 * o substring(text from pattern) get entire string matching pattern
10184 * o substring(text from pattern for escape) same with specified escape char
10185 * We also want to support generic substring functions which accept
10186 * the usual generic list of arguments. So we will accept both styles
10187 * here, and convert the SQL9x style to the generic list for further
10188 * processing. - thomas 2000-11-28
10191 a_expr substr_from substr_for
10193 $$ = list_make3($1, $2, $3);
10195 | a_expr substr_for substr_from
10197 /* not legal per SQL99, but might as well allow it */
10198 $$ = list_make3($1, $3, $2);
10200 | a_expr substr_from
10202 $$ = list_make2($1, $2);
10204 | a_expr substr_for
10207 * Since there are no cases where this syntax allows
10208 * a textual FOR value, we forcibly cast the argument
10209 * to int4. The possible matches in pg_proc are
10210 * substring(text,int4) and substring(text,text),
10211 * and we don't want the parser to choose the latter,
10212 * which it is likely to do if the second argument
10213 * is unknown or doesn't have an implicit cast to int4.
10215 $$ = list_make3($1, makeIntConst(1, -1),
10217 SystemTypeName("int4"), -1));
10228 FROM a_expr { $$ = $2; }
10231 substr_for: FOR a_expr { $$ = $2; }
10234 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
10235 | FROM expr_list { $$ = $2; }
10236 | expr_list { $$ = $1; }
10239 in_expr: select_with_parens
10241 SubLink *n = makeNode(SubLink);
10243 /* other fields will be filled later */
10246 | '(' expr_list ')' { $$ = (Node *)$2; }
10250 * Define SQL92-style case clause.
10251 * - Full specification
10252 * CASE WHEN a = b THEN c ... ELSE d END
10253 * - Implicit argument
10254 * CASE a WHEN b THEN c ... ELSE d END
10256 case_expr: CASE case_arg when_clause_list case_default END_P
10258 CaseExpr *c = makeNode(CaseExpr);
10259 c->casetype = InvalidOid; /* not analyzed yet */
10260 c->arg = (Expr *) $2;
10262 c->defresult = (Expr *) $4;
10269 /* There must be at least one */
10270 when_clause { $$ = list_make1($1); }
10271 | when_clause_list when_clause { $$ = lappend($1, $2); }
10275 WHEN a_expr THEN a_expr
10277 CaseWhen *w = makeNode(CaseWhen);
10278 w->expr = (Expr *) $2;
10279 w->result = (Expr *) $4;
10286 ELSE a_expr { $$ = $2; }
10287 | /*EMPTY*/ { $$ = NULL; }
10290 case_arg: a_expr { $$ = $1; }
10291 | /*EMPTY*/ { $$ = NULL; }
10296 $$ = makeColumnRef($1, NIL, @1, yyscanner);
10298 | ColId indirection
10300 $$ = makeColumnRef($1, $2, @1, yyscanner);
10307 $$ = (Node *) makeString($2);
10311 $$ = (Node *) makeNode(A_Star);
10315 A_Indices *ai = makeNode(A_Indices);
10320 | '[' a_expr ':' a_expr ']'
10322 A_Indices *ai = makeNode(A_Indices);
10330 indirection_el { $$ = list_make1($1); }
10331 | indirection indirection_el { $$ = lappend($1, $2); }
10335 /*EMPTY*/ { $$ = NIL; }
10336 | opt_indirection indirection_el { $$ = lappend($1, $2); }
10339 opt_asymmetric: ASYMMETRIC
10344 * The SQL spec defines "contextually typed value expressions" and
10345 * "contextually typed row value constructors", which for our purposes
10346 * are the same as "a_expr" and "row" except that DEFAULT can appear at
10351 a_expr { $$ = (Node *) $1; }
10354 SetToDefault *n = makeNode(SetToDefault);
10361 ctext_expr { $$ = list_make1($1); }
10362 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
10366 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
10367 * making VALUES a fully reserved word, which will probably break more apps
10368 * than allowing the noise-word is worth.
10370 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
10374 /*****************************************************************************
10376 * target list for SELECT
10378 *****************************************************************************/
10381 target_el { $$ = list_make1($1); }
10382 | target_list ',' target_el { $$ = lappend($1, $3); }
10385 target_el: a_expr AS ColLabel
10387 $$ = makeNode(ResTarget);
10389 $$->indirection = NIL;
10390 $$->val = (Node *)$1;
10394 * We support omitting AS only for column labels that aren't
10395 * any known keyword. There is an ambiguity against postfix
10396 * operators: is "a ! b" an infix expression, or a postfix
10397 * expression and a column label? We prefer to resolve this
10398 * as an infix expression, which we accomplish by assigning
10399 * IDENT a precedence higher than POSTFIXOP.
10403 $$ = makeNode(ResTarget);
10405 $$->indirection = NIL;
10406 $$->val = (Node *)$1;
10411 $$ = makeNode(ResTarget);
10413 $$->indirection = NIL;
10414 $$->val = (Node *)$1;
10419 ColumnRef *n = makeNode(ColumnRef);
10420 n->fields = list_make1(makeNode(A_Star));
10423 $$ = makeNode(ResTarget);
10425 $$->indirection = NIL;
10426 $$->val = (Node *)n;
10432 /*****************************************************************************
10434 * Names and constants
10436 *****************************************************************************/
10438 qualified_name_list:
10439 qualified_name { $$ = list_make1($1); }
10440 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
10444 * The production for a qualified relation name has to exactly match the
10445 * production for a qualified func_name, because in a FROM clause we cannot
10446 * tell which we are parsing until we see what comes after it ('(' for a
10447 * func_name, something else for a relation). Therefore we allow 'indirection'
10448 * which may contain subscripts, and reject that case in the C code.
10453 $$ = makeNode(RangeVar);
10454 $$->catalogname = NULL;
10455 $$->schemaname = NULL;
10459 | ColId indirection
10461 check_qualified_name($2, yyscanner);
10462 $$ = makeNode(RangeVar);
10463 switch (list_length($2))
10466 $$->catalogname = NULL;
10467 $$->schemaname = $1;
10468 $$->relname = strVal(linitial($2));
10471 $$->catalogname = $1;
10472 $$->schemaname = strVal(linitial($2));
10473 $$->relname = strVal(lsecond($2));
10477 (errcode(ERRCODE_SYNTAX_ERROR),
10478 errmsg("improper qualified name (too many dotted names): %s",
10479 NameListToString(lcons(makeString($1), $2))),
10480 parser_errposition(@1)));
10488 { $$ = list_make1(makeString($1)); }
10489 | name_list ',' name
10490 { $$ = lappend($1, makeString($3)); }
10494 name: ColId { $$ = $1; };
10497 ColId { $$ = $1; };
10500 ColId { $$ = $1; };
10502 attr_name: ColLabel { $$ = $1; };
10504 index_name: ColId { $$ = $1; };
10506 file_name: Sconst { $$ = $1; };
10509 * The production for a qualified func_name has to exactly match the
10510 * production for a qualified columnref, because we cannot tell which we
10511 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
10512 * anything else for a columnref). Therefore we allow 'indirection' which
10513 * may contain subscripts, and reject that case in the C code. (If we
10514 * ever implement SQL99-like methods, such syntax may actually become legal!)
10516 func_name: type_function_name
10517 { $$ = list_make1(makeString($1)); }
10518 | ColId indirection
10520 $$ = check_func_name(lcons(makeString($1), $2),
10531 $$ = makeIntConst($1, @1);
10535 $$ = makeFloatConst($1, @1);
10539 $$ = makeStringConst($1, @1);
10543 $$ = makeBitStringConst($1, @1);
10547 /* This is a bit constant per SQL99:
10548 * Without Feature F511, "BIT data type",
10549 * a <general literal> shall not be a
10550 * <bit string literal> or a <hex string literal>.
10552 $$ = makeBitStringConst($1, @1);
10556 /* generic type 'literal' syntax */
10557 TypeName *t = makeTypeNameFromNameList($1);
10559 $$ = makeStringConstCast($2, @2, t);
10561 | func_name '(' func_arg_list ')' Sconst
10563 /* generic syntax with a type modifier */
10564 TypeName *t = makeTypeNameFromNameList($1);
10568 * We must use func_arg_list in the production to avoid
10569 * reduce/reduce conflicts, but we don't actually wish
10570 * to allow NamedArgExpr in this context.
10574 NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
10576 if (IsA(arg, NamedArgExpr))
10578 (errcode(ERRCODE_SYNTAX_ERROR),
10579 errmsg("type modifier cannot have AS name"),
10580 parser_errposition(arg->location)));
10584 $$ = makeStringConstCast($5, @5, t);
10586 | ConstTypename Sconst
10588 $$ = makeStringConstCast($2, @2, $1);
10590 | ConstInterval Sconst opt_interval
10594 $$ = makeStringConstCast($2, @2, t);
10596 | ConstInterval '(' Iconst ')' Sconst opt_interval
10601 if (list_length($6) != 1)
10603 (errcode(ERRCODE_SYNTAX_ERROR),
10604 errmsg("interval precision specified twice"),
10605 parser_errposition(@1)));
10606 t->typmods = lappend($6, makeIntConst($3, @3));
10609 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
10610 makeIntConst($3, @3));
10611 $$ = makeStringConstCast($5, @5, t);
10615 $$ = makeBoolAConst(TRUE, @1);
10619 $$ = makeBoolAConst(FALSE, @1);
10623 $$ = makeNullAConst(@1);
10627 Iconst: ICONST { $$ = $1; };
10628 Sconst: SCONST { $$ = $1; };
10629 RoleId: ColId { $$ = $1; };
10631 SignedIconst: Iconst { $$ = $1; }
10632 | '+' Iconst { $$ = + $2; }
10633 | '-' Iconst { $$ = - $2; }
10636 Iconst_list: Iconst { $$ = list_make1(makeInteger($1)); }
10637 | Iconst_list ',' Iconst { $$ = lappend($1, makeInteger($3)); }
10641 * Name classification hierarchy.
10643 * IDENT is the lexeme returned by the lexer for identifiers that match
10644 * no known keyword. In most cases, we can accept certain keywords as
10645 * names, not only IDENTs. We prefer to accept as many such keywords
10646 * as possible to minimize the impact of "reserved words" on programmers.
10647 * So, we divide names into several possible classes. The classification
10648 * is chosen in part to make keywords acceptable as names wherever possible.
10651 /* Column identifier --- names that can be column, table, etc names.
10653 ColId: IDENT { $$ = $1; }
10654 | unreserved_keyword { $$ = pstrdup($1); }
10655 | col_name_keyword { $$ = pstrdup($1); }
10658 /* Type/function identifier --- names that can be type or function names.
10660 type_function_name: IDENT { $$ = $1; }
10661 | unreserved_keyword { $$ = pstrdup($1); }
10662 | type_func_name_keyword { $$ = pstrdup($1); }
10665 /* Column label --- allowed labels in "AS" clauses.
10666 * This presently includes *all* Postgres keywords.
10668 ColLabel: IDENT { $$ = $1; }
10669 | unreserved_keyword { $$ = pstrdup($1); }
10670 | col_name_keyword { $$ = pstrdup($1); }
10671 | type_func_name_keyword { $$ = pstrdup($1); }
10672 | reserved_keyword { $$ = pstrdup($1); }
10677 * Keyword category lists. Generally, every keyword present in
10678 * the Postgres grammar should appear in exactly one of these lists.
10680 * Put a new keyword into the first list that it can go into without causing
10681 * shift or reduce conflicts. The earlier lists define "less reserved"
10682 * categories of keywords.
10684 * Make sure that each keyword's category in keywords.c matches where
10685 * it is listed here. (Someday we may be able to generate these lists and
10686 * keywords.c's table from a common master list.)
10689 /* "Unreserved" keywords --- available for use as any kind of name.
10691 unreserved_keyword:
10945 /* Column identifier --- keywords that can be column, table, etc names.
10947 * Many of these keywords will in fact be recognized as type or function
10948 * names too; but they have special productions for the purpose, and so
10949 * can't be treated as "generic" type or function names.
10951 * The type names appearing here are not usable as function names
10952 * because they can be followed by '(' in typename productions, which
10953 * looks too much like a function call for an LR(1) parser.
11003 /* Type/function identifier --- keywords that can be type or function names.
11005 * Most of these are keywords that are used as operators in expressions;
11006 * in general such keywords can't be column names because they would be
11007 * ambiguous with variables, but they are unambiguous as function identifiers.
11009 * Do not include POSITION, SUBSTRING, etc here since they have explicit
11010 * productions in a_expr to support the goofy SQL9x argument syntax.
11011 * - thomas 2000-11-28
11013 type_func_name_keyword:
11039 /* Reserved keyword --- these keywords are usable only as a ColLabel.
11041 * Keywords appear here if they could not be distinguished from variable,
11042 * type, or function names in some contexts. Don't put things here unless
11067 | CURRENT_TIMESTAMP
11128 * The signature of this function is required by bison. However, we
11129 * ignore the passed yylloc and instead use the last token position
11130 * available from the scanner.
11133 base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
11135 parser_yyerror(msg);
11139 makeColumnRef(char *colname, List *indirection,
11140 int location, core_yyscan_t yyscanner)
11143 * Generate a ColumnRef node, with an A_Indirection node added if there
11144 * is any subscripting in the specified indirection list. However,
11145 * any field selection at the start of the indirection list must be
11146 * transposed into the "fields" part of the ColumnRef node.
11148 ColumnRef *c = makeNode(ColumnRef);
11152 c->location = location;
11153 foreach(l, indirection)
11155 if (IsA(lfirst(l), A_Indices))
11157 A_Indirection *i = makeNode(A_Indirection);
11161 /* easy case - all indirection goes to A_Indirection */
11162 c->fields = list_make1(makeString(colname));
11163 i->indirection = check_indirection(indirection, yyscanner);
11167 /* got to split the list in two */
11168 i->indirection = check_indirection(list_copy_tail(indirection,
11171 indirection = list_truncate(indirection, nfields);
11172 c->fields = lcons(makeString(colname), indirection);
11174 i->arg = (Node *) c;
11177 else if (IsA(lfirst(l), A_Star))
11179 /* We only allow '*' at the end of a ColumnRef */
11180 if (lnext(l) != NULL)
11181 parser_yyerror("improper use of \"*\"");
11185 /* No subscripting, so all indirection gets added to field list */
11186 c->fields = lcons(makeString(colname), indirection);
11191 makeTypeCast(Node *arg, TypeName *typename, int location)
11193 TypeCast *n = makeNode(TypeCast);
11195 n->typeName = typename;
11196 n->location = location;
11201 makeStringConst(char *str, int location)
11203 A_Const *n = makeNode(A_Const);
11205 n->val.type = T_String;
11206 n->val.val.str = str;
11207 n->location = location;
11213 makeStringConstCast(char *str, int location, TypeName *typename)
11215 Node *s = makeStringConst(str, location);
11217 return makeTypeCast(s, typename, -1);
11221 makeIntConst(int val, int location)
11223 A_Const *n = makeNode(A_Const);
11225 n->val.type = T_Integer;
11226 n->val.val.ival = val;
11227 n->location = location;
11233 makeFloatConst(char *str, int location)
11235 A_Const *n = makeNode(A_Const);
11237 n->val.type = T_Float;
11238 n->val.val.str = str;
11239 n->location = location;
11245 makeBitStringConst(char *str, int location)
11247 A_Const *n = makeNode(A_Const);
11249 n->val.type = T_BitString;
11250 n->val.val.str = str;
11251 n->location = location;
11257 makeNullAConst(int location)
11259 A_Const *n = makeNode(A_Const);
11261 n->val.type = T_Null;
11262 n->location = location;
11268 makeAConst(Value *v, int location)
11275 n = makeFloatConst(v->val.str, location);
11279 n = makeIntConst(v->val.ival, location);
11284 n = makeStringConst(v->val.str, location);
11291 /* makeBoolAConst()
11292 * Create an A_Const string node and put it inside a boolean cast.
11295 makeBoolAConst(bool state, int location)
11297 A_Const *n = makeNode(A_Const);
11299 n->val.type = T_String;
11300 n->val.val.str = (state ? "t" : "f");
11301 n->location = location;
11303 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
11307 * Create and populate a FuncCall node to support the OVERLAPS operator.
11310 makeOverlaps(List *largs, List *rargs, int location, core_yyscan_t yyscanner)
11312 FuncCall *n = makeNode(FuncCall);
11314 n->funcname = SystemFuncName("overlaps");
11315 if (list_length(largs) == 1)
11316 largs = lappend(largs, largs);
11317 else if (list_length(largs) != 2)
11319 (errcode(ERRCODE_SYNTAX_ERROR),
11320 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
11321 parser_errposition(location)));
11322 if (list_length(rargs) == 1)
11323 rargs = lappend(rargs, rargs);
11324 else if (list_length(rargs) != 2)
11326 (errcode(ERRCODE_SYNTAX_ERROR),
11327 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
11328 parser_errposition(location)));
11329 n->args = list_concat(largs, rargs);
11330 n->agg_order = NIL;
11331 n->agg_star = FALSE;
11332 n->agg_distinct = FALSE;
11333 n->func_variadic = FALSE;
11335 n->location = location;
11339 /* check_qualified_name --- check the result of qualified_name production
11341 * It's easiest to let the grammar production for qualified_name allow
11342 * subscripts and '*', which we then must reject here.
11345 check_qualified_name(List *names, core_yyscan_t yyscanner)
11351 if (!IsA(lfirst(i), String))
11352 parser_yyerror("syntax error");
11356 /* check_func_name --- check the result of func_name production
11358 * It's easiest to let the grammar production for func_name allow subscripts
11359 * and '*', which we then must reject here.
11362 check_func_name(List *names, core_yyscan_t yyscanner)
11368 if (!IsA(lfirst(i), String))
11369 parser_yyerror("syntax error");
11374 /* check_indirection --- check the result of indirection production
11376 * We only allow '*' at the end of the list, but it's hard to enforce that
11377 * in the grammar, so do it here.
11380 check_indirection(List *indirection, core_yyscan_t yyscanner)
11384 foreach(l, indirection)
11386 if (IsA(lfirst(l), A_Star))
11388 if (lnext(l) != NULL)
11389 parser_yyerror("improper use of \"*\"");
11392 return indirection;
11395 /* extractArgTypes()
11396 * Given a list of FunctionParameter nodes, extract a list of just the
11397 * argument types (TypeNames) for input parameters only. This is what
11398 * is needed to look up an existing function, which is what is wanted by
11399 * the productions that use this call.
11402 extractArgTypes(List *parameters)
11404 List *result = NIL;
11407 foreach(i, parameters)
11409 FunctionParameter *p = (FunctionParameter *) lfirst(i);
11411 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
11412 result = lappend(result, p->argType);
11417 /* findLeftmostSelect()
11418 * Find the leftmost component SelectStmt in a set-operation parsetree.
11420 static SelectStmt *
11421 findLeftmostSelect(SelectStmt *node)
11423 while (node && node->op != SETOP_NONE)
11425 Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
11429 /* insertSelectOptions()
11430 * Insert ORDER BY, etc into an already-constructed SelectStmt.
11432 * This routine is just to avoid duplicating code in SelectStmt productions.
11435 insertSelectOptions(SelectStmt *stmt,
11436 List *sortClause, List *lockingClause,
11437 Node *limitOffset, Node *limitCount,
11438 WithClause *withClause,
11439 core_yyscan_t yyscanner)
11441 Assert(IsA(stmt, SelectStmt));
11444 * Tests here are to reject constructs like
11445 * (SELECT foo ORDER BY bar) ORDER BY baz
11449 if (stmt->sortClause)
11451 (errcode(ERRCODE_SYNTAX_ERROR),
11452 errmsg("multiple ORDER BY clauses not allowed"),
11453 parser_errposition(exprLocation((Node *) sortClause))));
11454 stmt->sortClause = sortClause;
11456 /* We can handle multiple locking clauses, though */
11457 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
11460 if (stmt->limitOffset)
11462 (errcode(ERRCODE_SYNTAX_ERROR),
11463 errmsg("multiple OFFSET clauses not allowed"),
11464 parser_errposition(exprLocation(limitOffset))));
11465 stmt->limitOffset = limitOffset;
11469 if (stmt->limitCount)
11471 (errcode(ERRCODE_SYNTAX_ERROR),
11472 errmsg("multiple LIMIT clauses not allowed"),
11473 parser_errposition(exprLocation(limitCount))));
11474 stmt->limitCount = limitCount;
11478 if (stmt->withClause)
11480 (errcode(ERRCODE_SYNTAX_ERROR),
11481 errmsg("multiple WITH clauses not allowed"),
11482 parser_errposition(exprLocation((Node *) withClause))));
11483 stmt->withClause = withClause;
11488 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
11490 SelectStmt *n = makeNode(SelectStmt);
11494 n->larg = (SelectStmt *) larg;
11495 n->rarg = (SelectStmt *) rarg;
11499 /* SystemFuncName()
11500 * Build a properly-qualified reference to a built-in function.
11503 SystemFuncName(char *name)
11505 return list_make2(makeString("pg_catalog"), makeString(name));
11508 /* SystemTypeName()
11509 * Build a properly-qualified reference to a built-in type.
11511 * typmod is defaulted, but may be changed afterwards by caller.
11512 * Likewise for the location.
11515 SystemTypeName(char *name)
11517 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
11518 makeString(name)));
11522 * Handle negation of a numeric constant.
11524 * Formerly, we did this here because the optimizer couldn't cope with
11525 * indexquals that looked like "var = -4" --- it wants "var = const"
11526 * and a unary minus operator applied to a constant didn't qualify.
11527 * As of Postgres 7.0, that problem doesn't exist anymore because there
11528 * is a constant-subexpression simplifier in the optimizer. However,
11529 * there's still a good reason for doing this here, which is that we can
11530 * postpone committing to a particular internal representation for simple
11531 * negative constants. It's better to leave "-123.456" in string form
11532 * until we know what the desired type is.
11535 doNegate(Node *n, int location)
11537 if (IsA(n, A_Const))
11539 A_Const *con = (A_Const *)n;
11541 /* report the constant's location as that of the '-' sign */
11542 con->location = location;
11544 if (con->val.type == T_Integer)
11546 con->val.val.ival = -con->val.val.ival;
11549 if (con->val.type == T_Float)
11551 doNegateFloat(&con->val);
11556 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
11560 doNegateFloat(Value *v)
11562 char *oldval = v->val.str;
11564 Assert(IsA(v, Float));
11565 if (*oldval == '+')
11567 if (*oldval == '-')
11568 v->val.str = oldval+1; /* just strip the '-' */
11571 char *newval = (char *) palloc(strlen(oldval) + 2);
11574 strcpy(newval+1, oldval);
11575 v->val.str = newval;
11580 makeAArrayExpr(List *elements, int location)
11582 A_ArrayExpr *n = makeNode(A_ArrayExpr);
11584 n->elements = elements;
11585 n->location = location;
11590 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
11593 XmlExpr *x = makeNode(XmlExpr);
11598 * named_args is a list of ResTarget; it'll be split apart into separate
11599 * expression and name lists in transformXmlExpr().
11601 x->named_args = named_args;
11602 x->arg_names = NIL;
11604 /* xmloption, if relevant, must be filled in by caller */
11605 /* type and typmod will be filled in during parse analysis */
11606 x->location = location;
11611 * Initialize to parse one query string
11614 parser_init(base_yy_extra_type *yyext)
11616 yyext->parsetree = NIL; /* in case grammar forgets to set it */
11620 * Merge the input and output parameters of a table function.
11623 mergeTableFuncParameters(List *func_args, List *columns)
11627 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
11628 foreach(lc, func_args)
11630 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
11632 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
11634 (errcode(ERRCODE_SYNTAX_ERROR),
11635 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
11638 return list_concat(func_args, columns);
11642 * Determine return type of a TABLE function. A single result column
11643 * returns setof that column's type; otherwise return setof record.
11646 TableFuncTypeName(List *columns)
11650 if (list_length(columns) == 1)
11652 FunctionParameter *p = (FunctionParameter *) linitial(columns);
11654 result = (TypeName *) copyObject(p->argType);
11657 result = SystemTypeName("record");
11659 result->setof = true;
11665 * Must undefine this stuff before including scan.c, since it has different
11666 * definitions for these macros.