4 /*-------------------------------------------------------------------------
7 * POSTGRESQL BISON rules/actions
9 * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
10 * Portions Copyright (c) 1994, Regents of the University of California
14 * src/backend/parser/gram.y
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);
134 static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
140 %name-prefix="base_yy"
143 %parse-param {core_yyscan_t yyscanner}
144 %lex-param {core_yyscan_t yyscanner}
148 core_YYSTYPE core_yystype;
149 /* these fields must match core_YYSTYPE: */
157 DropBehavior dbehavior;
158 OnCommitAction oncommit;
164 FunctionParameter *fun_param;
165 FunctionParameterMode fun_param_mode;
166 FuncWithArgs *funwithargs;
178 struct PrivTarget *privtarget;
179 AccessPriv *accesspriv;
181 VariableSetStmt *vsetstmt;
184 %type <node> stmt schema_stmt
185 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
186 AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
187 AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterTableStmt
188 AlterExtensionAddStmt AlterForeignTableStmt
189 AlterCompositeTypeStmt AlterUserStmt AlterUserMappingStmt AlterUserSetStmt
190 AlterRoleStmt AlterRoleSetStmt
191 AlterDefaultPrivilegesStmt DefACLAction
192 AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
193 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
194 CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
195 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
196 CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
197 CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
198 CreateAssertStmt CreateTrigStmt
199 CreateUserStmt CreateUserMappingStmt CreateRoleStmt
200 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
201 DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
202 DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
203 DropUserStmt DropdbStmt DropTableSpaceStmt DropFdwStmt
204 DropForeignServerStmt DropUserMappingStmt ExplainStmt FetchStmt
205 GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
206 LockStmt NotifyStmt ExplainableStmt PreparableStmt
207 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
208 RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
209 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
210 SecLabelStmt SelectStmt TransactionStmt TruncateStmt
211 UnlistenStmt UpdateStmt VacuumStmt
212 VariableResetStmt VariableSetStmt VariableShowStmt
213 ViewStmt CheckPointStmt CreateConversionStmt
214 DeallocateStmt PrepareStmt ExecuteStmt
215 DropOwnedStmt ReassignOwnedStmt
216 AlterTSConfigurationStmt AlterTSDictionaryStmt
218 %type <node> select_no_parens select_with_parens select_clause
219 simple_select values_clause
221 %type <node> alter_column_default opclass_item opclass_drop alter_using
222 %type <ival> add_drop opt_asc_desc opt_nulls_order
224 %type <node> alter_table_cmd alter_type_cmd
225 %type <list> alter_table_cmds alter_type_cmds
227 %type <dbehavior> opt_drop_behavior
229 %type <list> createdb_opt_list alterdb_opt_list copy_opt_list
230 transaction_mode_list create_extension_opt_list
231 %type <defelt> createdb_opt_item alterdb_opt_item copy_opt_item
232 transaction_mode_item create_extension_opt_item
234 %type <ival> opt_lock lock_type cast_context
235 %type <ival> vacuum_option_list vacuum_option_elem
236 %type <boolean> opt_force opt_or_replace
237 opt_grant_grant_option opt_grant_admin_option
238 opt_nowait opt_if_exists opt_with_data
240 %type <list> OptRoleList AlterOptRoleList
241 %type <defelt> CreateOptRoleElem AlterOptRoleElem
244 %type <str> foreign_server_version opt_foreign_server_version
245 %type <str> auth_ident
246 %type <str> opt_in_database
248 %type <str> OptSchemaName
249 %type <list> OptSchemaEltList
251 %type <boolean> TriggerForSpec TriggerForType
252 %type <ival> TriggerActionTime
253 %type <list> TriggerEvents TriggerOneEvent
254 %type <value> TriggerFuncArg
255 %type <node> TriggerWhen
257 %type <str> copy_file_name
258 database_name access_method_clause access_method attr_name
259 name cursor_name file_name
260 index_name opt_index_name cluster_index_specification
262 %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
263 opt_class opt_inline_handler opt_validator validator_clause
266 %type <range> qualified_name OptConstrFromTable
268 %type <str> all_Op MathOp
270 %type <str> iso_level opt_encoding
272 %type <list> grantee_list
273 %type <accesspriv> privilege
274 %type <list> privileges privilege_list
275 %type <privtarget> privilege_target
276 %type <funwithargs> function_with_argtypes
277 %type <list> function_with_argtypes_list
278 %type <ival> defacl_privilege_target
279 %type <defelt> DefACLOption
280 %type <list> DefACLOptionList
282 %type <list> stmtblock stmtmulti
283 OptTableElementList TableElementList OptInherit definition
284 OptTypedTableElementList TypedTableElementList
285 OptForeignTableElementList ForeignTableElementList
286 reloptions opt_reloptions
287 OptWith opt_distinct opt_definition func_args func_args_list
288 func_args_with_defaults func_args_with_defaults_list
289 func_as createfunc_opt_list alterfunc_opt_list
290 aggr_args old_aggr_definition old_aggr_list
291 oper_argtypes RuleActionList RuleActionMulti
292 opt_column_list columnList opt_name_list
293 sort_clause opt_sort_clause sortby_list index_params
294 name_list from_clause from_list opt_array_bounds
295 qualified_name_list any_name any_name_list
296 any_operator expr_list attrs
297 target_list insert_column_list set_target_list
298 set_clause_list set_clause multiple_set_clause
299 ctext_expr_list ctext_row def_list indirection opt_indirection
300 reloption_list group_clause TriggerFuncArgs select_limit
301 opt_select_limit opclass_item_list opclass_drop_list
302 opclass_purpose opt_opfamily transaction_mode_list_or_empty
303 OptTableFuncElementList TableFuncElementList opt_type_modifiers
305 execute_param_clause using_clause returning_clause
306 opt_enum_val_list enum_val_list table_func_column_list
307 create_generic_options alter_generic_options
308 relation_expr_list dostmt_opt_list
310 %type <range> OptTempTableName
311 %type <into> into_clause create_as_target
313 %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
314 %type <fun_param> func_arg func_arg_with_default table_func_column
315 %type <fun_param_mode> arg_class
316 %type <typnam> func_return func_type
318 %type <boolean> opt_trusted opt_restart_seqs
320 %type <oncommit> OnCommitOption
322 %type <node> for_locking_item
323 %type <list> for_locking_clause opt_for_locking_clause for_locking_items
324 %type <list> locked_rels_list
325 %type <boolean> opt_all
327 %type <node> join_outer join_qual
328 %type <jtype> join_type
330 %type <list> extract_list overlay_list position_list
331 %type <list> substr_list trim_list
332 %type <list> opt_interval interval_second
333 %type <node> overlay_placing substr_from substr_for
335 %type <boolean> opt_instead
336 %type <boolean> opt_unique opt_concurrently opt_verbose opt_full
337 %type <boolean> opt_freeze opt_default opt_recheck
338 %type <defelt> opt_binary opt_oids copy_delimiter
340 %type <boolean> copy_from
342 %type <ival> opt_column event cursor_options opt_hold opt_set_data
343 %type <objtype> reindex_type drop_type comment_type security_label_type
345 %type <node> fetch_args limit_clause select_limit_value
346 offset_clause select_offset_value
347 select_offset_value2 opt_select_fetch_first_value
348 %type <ival> row_or_rows first_or_next
350 %type <list> OptSeqOptList SeqOptList
351 %type <defelt> SeqOptElem
353 %type <istmt> insert_rest
355 %type <vsetstmt> set_rest SetResetClause
357 %type <node> TableElement TypedTableElement ConstraintElem TableFuncElement
359 %type <node> columnDef columnOptions
360 %type <defelt> def_elem reloption_elem old_aggr_elem
361 %type <node> def_arg columnElem where_clause where_or_current_clause
362 a_expr b_expr c_expr func_expr AexprConst indirection_el
363 columnref in_expr having_clause func_table array_expr
365 %type <list> ExclusionConstraintList ExclusionConstraintElem
366 %type <list> func_arg_list
367 %type <node> func_arg_expr
368 %type <list> row type_list array_expr_list
369 %type <node> case_expr case_arg when_clause case_default
370 %type <list> when_clause_list
371 %type <ival> sub_type
372 %type <list> OptCreateAs CreateAsList
373 %type <node> CreateAsElement ctext_expr
374 %type <value> NumericOnly
375 %type <list> NumericOnly_list
376 %type <alias> alias_clause
377 %type <sortby> sortby
378 %type <ielem> index_elem
379 %type <node> table_ref
380 %type <jexpr> joined_table
381 %type <range> relation_expr
382 %type <range> relation_expr_opt_alias
383 %type <target> target_el single_set_clause set_target insert_column_item
385 %type <str> generic_option_name
386 %type <node> generic_option_arg
387 %type <defelt> generic_option_elem alter_generic_option_elem
388 %type <list> generic_option_list alter_generic_option_list
389 %type <str> explain_option_name
390 %type <node> explain_option_arg
391 %type <defelt> explain_option_elem
392 %type <list> explain_option_list
393 %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
394 %type <defelt> copy_generic_opt_elem
395 %type <list> copy_generic_opt_list copy_generic_opt_arg_list
396 %type <list> copy_options
398 %type <typnam> Typename SimpleTypename SimpleTypenameWithoutCollation
400 GenericType Numeric opt_float
401 Character ConstCharacter
402 CharacterWithLength CharacterWithoutLength
403 ConstDatetime ConstInterval
404 Bit ConstBit BitWithLength BitWithoutLength
405 %type <str> character
406 %type <str> extract_arg
407 %type <str> opt_charset
408 %type <boolean> opt_varying opt_timezone
410 %type <ival> Iconst SignedIconst
411 %type <str> Sconst comment_text notify_payload
412 %type <str> RoleId opt_granted_by opt_boolean_or_string ColId_or_Sconst
413 %type <list> var_list
414 %type <str> ColId ColLabel var_name type_function_name param_name
415 %type <node> var_value zone_value
417 %type <keyword> unreserved_keyword type_func_name_keyword
418 %type <keyword> col_name_keyword reserved_keyword
420 %type <node> TableConstraint TableLikeClause
421 %type <ival> TableLikeOptionList TableLikeOption
422 %type <list> ColQualList
423 %type <node> ColConstraint ColConstraintElem ConstraintAttr
424 %type <ival> key_actions key_delete key_match key_update key_action
425 %type <ival> ConstraintAttributeSpec ConstraintDeferrabilitySpec
427 %type <str> ExistingIndex
429 %type <list> constraints_set_list
430 %type <boolean> constraints_set_mode
431 %type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
432 %type <list> opt_check_option
434 %type <str> opt_provider security_label
436 %type <target> xml_attribute_el
437 %type <list> xml_attribute_list xml_attributes
438 %type <node> xml_root_version opt_xml_root_standalone
439 %type <node> xmlexists_argument
440 %type <ival> document_or_content
441 %type <boolean> xml_whitespace_option
443 %type <node> common_table_expr
444 %type <with> with_clause opt_with_clause
445 %type <list> cte_list
447 %type <list> window_clause window_definition_list opt_partition_clause
448 %type <windef> window_definition over_clause window_specification
449 opt_frame_clause frame_extent frame_bound
450 %type <str> opt_existing_window_name
454 * Non-keyword token types. These are hard-wired into the "flex" lexer.
455 * They must be listed first so that their numeric codes do not depend on
456 * the set of keywords. PL/pgsql depends on this so that it can share the
457 * same lexer. If you add/change tokens here, fix PL/pgsql to match!
459 * DOT_DOT is unused in the core SQL grammar, and so will always provoke
460 * parse errors. It is needed by PL/pgsql.
462 %token <str> IDENT FCONST SCONST BCONST XCONST Op
463 %token <ival> ICONST PARAM
464 %token TYPECAST DOT_DOT COLON_EQUALS
467 * If you want to make any keyword changes, update the keyword table in
468 * src/include/parser/kwlist.h and add new keywords to the appropriate one
469 * of the reserved-or-not-so-reserved keyword lists, below; search
470 * this file for "Keyword category lists".
473 /* ordinary key words in alphabetical order */
474 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
475 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
476 ASSERTION ASSIGNMENT ASYMMETRIC AT ATTRIBUTE AUTHORIZATION
478 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
481 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
482 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
483 CLUSTER COALESCE COLLATE COLUMN COMMENT COMMENTS COMMIT
484 COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
485 CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
486 CREATEROLE CREATEUSER CROSS CSV CURRENT_P
487 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
488 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
490 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
491 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
492 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
494 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT
495 EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
496 EXTENSION EXTERNAL EXTRACT
498 FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOLLOWING FOR FORCE FOREIGN FORWARD
499 FREEZE FROM FULL FUNCTION FUNCTIONS
501 GLOBAL GRANT GRANTED GREATEST GROUP_P
503 HANDLER HAVING HEADER_P HOLD HOUR_P
505 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
506 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
507 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
508 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
514 LABEL LANGUAGE LARGE_P LAST_P LC_COLLATE_P LC_CTYPE_P LEADING
515 LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP
516 LOCATION LOCK_P LOGIN_P
518 MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
520 NAME_P NAMES NATIONAL NATURAL NCHAR NEXT NO NOCREATEDB
521 NOCREATEROLE NOCREATEUSER NOINHERIT NOLOGIN_P NONE NOREPLICATION_P
522 NOSUPERUSER NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
525 OBJECT_P OF OFF OFFSET OIDS ON ONLY OPERATOR OPTION OPTIONS OR
526 ORDER OUT_P OUTER_P OVER OVERLAPS OVERLAY OWNED OWNER
528 PARSER PARTIAL PARTITION PASSING PASSWORD PLACING PLANS POSITION
529 PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
530 PRIOR PRIVILEGES PROCEDURAL PROCEDURE
534 RANGE READ REAL REASSIGN RECHECK RECURSIVE REF REFERENCES REINDEX
535 RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA REPLICATION_P
536 RESET RESTART RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK
539 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE SEQUENCES
540 SERIALIZABLE SERVER SESSION SESSION_USER SET SETOF SHARE
541 SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT
542 STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING SUPERUSER_P
543 SYMMETRIC SYSID SYSTEM_P
545 TABLE TABLES TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
546 TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
547 TRUNCATE TRUSTED TYPE_P
549 UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNLOGGED
550 UNTIL UPDATE USER USING
552 VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
553 VERBOSE VERSION_P VIEW VOLATILE
555 WHEN WHERE WHITESPACE_P WINDOW WITH WITHOUT WORK WRAPPER WRITE
557 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLPARSE
558 XMLPI XMLROOT XMLSERIALIZE
565 * The grammar thinks these are keywords, but they are not in the kwlist.h
566 * list and so can never be entered directly. The filter in parser.c
567 * creates these tokens when required.
569 %token NULLS_FIRST NULLS_LAST WITH_TIME
572 /* Precedence: lowest to highest */
573 %nonassoc SET /* see relation_expr_opt_alias */
581 %nonassoc LIKE ILIKE SIMILAR
586 %left POSTFIXOP /* dummy for postfix Op rules */
588 * To support target_el without AS, we must give IDENT an explicit priority
589 * between POSTFIXOP and Op. We can safely assign the same priority to
590 * various unreserved keywords as needed to resolve ambiguities (this can't
591 * have any bad effects since obviously the keywords will still behave the
592 * same as if they weren't keywords). We need to do this for PARTITION,
593 * RANGE, ROWS to support opt_existing_window_name; and for RANGE, ROWS
594 * so that they can follow a_expr without creating
595 * postfix-operator problems.
597 * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
598 * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
599 * there is no principled way to distinguish these from the productions
600 * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
601 * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
602 * appear to cause UNBOUNDED to be treated differently from other unreserved
603 * keywords anywhere else in the grammar, but it's definitely risky. We can
604 * blame any funny behavior of UNBOUNDED on the SQL standard, though.
606 %nonassoc UNBOUNDED /* ideally should have same precedence as IDENT */
607 %nonassoc IDENT PARTITION RANGE ROWS PRECEDING FOLLOWING
608 %left Op OPERATOR /* multi-character ops and user-defined operators */
611 %nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN /* sets precedence for IS NULL, etc */
615 /* Unary Operators */
616 %left AT ZONE /* sets precedence for AT TIME ZONE */
623 * These might seem to be low-precedence, but actually they are not part
624 * of the arithmetic hierarchy at all in their use as JOIN operators.
625 * We make them high-precedence to support their use as function names.
626 * They wouldn't be given a precedence at all, were it not that we need
627 * left-associativity among the JOIN rules themselves.
629 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
630 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
631 %right PRESERVE STRIP_P
636 * The target production for the whole parse.
640 pg_yyget_extra(yyscanner)->parsetree = $1;
644 /* the thrashing around here is to discard "empty" statements... */
645 stmtmulti: stmtmulti ';' stmt
648 $$ = lappend($1, $3);
663 | AlterDatabaseSetStmt
664 | AlterDefaultPrivilegesStmt
667 | AlterExtensionAddStmt
669 | AlterForeignServerStmt
670 | AlterForeignTableStmt
673 | AlterObjectSchemaStmt
677 | AlterCompositeTypeStmt
680 | AlterTSConfigurationStmt
681 | AlterTSDictionaryStmt
682 | AlterUserMappingStmt
695 | CreateConversionStmt
697 | CreateExtensionStmt
699 | CreateForeignServerStmt
700 | CreateForeignTableStmt
710 | CreateTableSpaceStmt
714 | CreateUserMappingStmt
725 | DropForeignServerStmt
737 | DropUserMappingStmt
775 /*****************************************************************************
777 * Create a new Postgres DBMS role
779 *****************************************************************************/
782 CREATE ROLE RoleId opt_with OptRoleList
784 CreateRoleStmt *n = makeNode(CreateRoleStmt);
785 n->stmt_type = ROLESTMT_ROLE;
798 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
799 * for backwards compatibility). Note: the only option required by SQL99
800 * is "WITH ADMIN name".
803 OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
804 | /* EMPTY */ { $$ = NIL; }
808 AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
809 | /* EMPTY */ { $$ = NIL; }
815 $$ = makeDefElem("password",
816 (Node *)makeString($2));
820 $$ = makeDefElem("password", NULL);
822 | ENCRYPTED PASSWORD Sconst
824 $$ = makeDefElem("encryptedPassword",
825 (Node *)makeString($3));
827 | UNENCRYPTED PASSWORD Sconst
829 $$ = makeDefElem("unencryptedPassword",
830 (Node *)makeString($3));
834 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
838 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
842 $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE));
846 $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE));
850 $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
854 $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
858 $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE));
862 $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE));
866 /* For backwards compatibility, synonym for SUPERUSER */
867 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
871 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
875 $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE));
879 $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE));
883 $$ = makeDefElem("isreplication", (Node *)makeInteger(TRUE));
887 $$ = makeDefElem("isreplication", (Node *)makeInteger(FALSE));
889 | CONNECTION LIMIT SignedIconst
891 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3));
895 $$ = makeDefElem("validUntil", (Node *)makeString($3));
897 /* Supported but not documented for roles, for use by ALTER GROUP. */
900 $$ = makeDefElem("rolemembers", (Node *)$2);
905 AlterOptRoleElem { $$ = $1; }
906 /* The following are not supported by ALTER ROLE/USER/GROUP */
909 $$ = makeDefElem("sysid", (Node *)makeInteger($2));
913 $$ = makeDefElem("adminmembers", (Node *)$2);
917 $$ = makeDefElem("rolemembers", (Node *)$2);
919 | IN_P ROLE name_list
921 $$ = makeDefElem("addroleto", (Node *)$3);
923 | IN_P GROUP_P name_list
925 $$ = makeDefElem("addroleto", (Node *)$3);
930 /*****************************************************************************
932 * Create a new Postgres DBMS user (role with implied login ability)
934 *****************************************************************************/
937 CREATE USER RoleId opt_with OptRoleList
939 CreateRoleStmt *n = makeNode(CreateRoleStmt);
940 n->stmt_type = ROLESTMT_USER;
948 /*****************************************************************************
950 * Alter a postgresql DBMS role
952 *****************************************************************************/
955 ALTER ROLE RoleId opt_with AlterOptRoleList
957 AlterRoleStmt *n = makeNode(AlterRoleStmt);
959 n->action = +1; /* add, if there are members */
966 /* EMPTY */ { $$ = NULL; }
967 | IN_P DATABASE database_name { $$ = $3; }
971 ALTER ROLE RoleId opt_in_database SetResetClause
973 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
982 /*****************************************************************************
984 * Alter a postgresql DBMS user
986 *****************************************************************************/
989 ALTER USER RoleId opt_with AlterOptRoleList
991 AlterRoleStmt *n = makeNode(AlterRoleStmt);
993 n->action = +1; /* add, if there are members */
1001 ALTER USER RoleId SetResetClause
1003 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1012 /*****************************************************************************
1014 * Drop a postgresql DBMS role
1016 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
1017 * might own objects in multiple databases, there is presently no way to
1018 * implement either cascading or restricting. Caveat DBA.
1019 *****************************************************************************/
1024 DropRoleStmt *n = makeNode(DropRoleStmt);
1025 n->missing_ok = FALSE;
1029 | DROP ROLE IF_P EXISTS name_list
1031 DropRoleStmt *n = makeNode(DropRoleStmt);
1032 n->missing_ok = TRUE;
1038 /*****************************************************************************
1040 * Drop a postgresql DBMS user
1042 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
1043 * might own objects in multiple databases, there is presently no way to
1044 * implement either cascading or restricting. Caveat DBA.
1045 *****************************************************************************/
1050 DropRoleStmt *n = makeNode(DropRoleStmt);
1051 n->missing_ok = FALSE;
1055 | DROP USER IF_P EXISTS name_list
1057 DropRoleStmt *n = makeNode(DropRoleStmt);
1059 n->missing_ok = TRUE;
1065 /*****************************************************************************
1067 * Create a postgresql group (role without login ability)
1069 *****************************************************************************/
1072 CREATE GROUP_P RoleId opt_with OptRoleList
1074 CreateRoleStmt *n = makeNode(CreateRoleStmt);
1075 n->stmt_type = ROLESTMT_GROUP;
1083 /*****************************************************************************
1085 * Alter a postgresql group
1087 *****************************************************************************/
1090 ALTER GROUP_P RoleId add_drop USER name_list
1092 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1095 n->options = list_make1(makeDefElem("rolemembers",
1101 add_drop: ADD_P { $$ = +1; }
1106 /*****************************************************************************
1108 * Drop a postgresql group
1110 * XXX see above notes about cascading DROP USER; groups have same problem.
1111 *****************************************************************************/
1114 DROP GROUP_P name_list
1116 DropRoleStmt *n = makeNode(DropRoleStmt);
1117 n->missing_ok = FALSE;
1121 | DROP GROUP_P IF_P EXISTS name_list
1123 DropRoleStmt *n = makeNode(DropRoleStmt);
1124 n->missing_ok = TRUE;
1131 /*****************************************************************************
1133 * Manipulate a schema
1135 *****************************************************************************/
1138 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
1140 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1141 /* One can omit the schema name or the authorization id. */
1150 | CREATE SCHEMA ColId OptSchemaEltList
1152 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1153 /* ...but not both */
1163 | /* EMPTY */ { $$ = NULL; }
1167 OptSchemaEltList schema_stmt { $$ = lappend($1, $2); }
1168 | /* EMPTY */ { $$ = NIL; }
1172 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1173 * statement (in addition to by themselves).
1185 /*****************************************************************************
1187 * Set PG internal variable
1188 * SET name TO 'var_value'
1189 * Include SQL92 syntax (thomas 1997-10-22):
1190 * SET TIME ZONE 'var_value'
1192 *****************************************************************************/
1197 VariableSetStmt *n = $2;
1198 n->is_local = false;
1201 | SET LOCAL set_rest
1203 VariableSetStmt *n = $3;
1207 | SET SESSION set_rest
1209 VariableSetStmt *n = $3;
1210 n->is_local = false;
1215 set_rest: /* Generic SET syntaxes: */
1216 var_name TO var_list
1218 VariableSetStmt *n = makeNode(VariableSetStmt);
1219 n->kind = VAR_SET_VALUE;
1224 | var_name '=' var_list
1226 VariableSetStmt *n = makeNode(VariableSetStmt);
1227 n->kind = VAR_SET_VALUE;
1232 | var_name TO DEFAULT
1234 VariableSetStmt *n = makeNode(VariableSetStmt);
1235 n->kind = VAR_SET_DEFAULT;
1239 | var_name '=' DEFAULT
1241 VariableSetStmt *n = makeNode(VariableSetStmt);
1242 n->kind = VAR_SET_DEFAULT;
1246 | var_name FROM CURRENT_P
1248 VariableSetStmt *n = makeNode(VariableSetStmt);
1249 n->kind = VAR_SET_CURRENT;
1253 /* Special syntaxes mandated by SQL standard: */
1254 | TIME ZONE zone_value
1256 VariableSetStmt *n = makeNode(VariableSetStmt);
1257 n->kind = VAR_SET_VALUE;
1258 n->name = "timezone";
1260 n->args = list_make1($3);
1262 n->kind = VAR_SET_DEFAULT;
1265 | TRANSACTION transaction_mode_list
1267 VariableSetStmt *n = makeNode(VariableSetStmt);
1268 n->kind = VAR_SET_MULTI;
1269 n->name = "TRANSACTION";
1273 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1275 VariableSetStmt *n = makeNode(VariableSetStmt);
1276 n->kind = VAR_SET_MULTI;
1277 n->name = "SESSION CHARACTERISTICS";
1284 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1285 errmsg("current database cannot be changed"),
1286 parser_errposition(@2)));
1287 $$ = NULL; /*not reached*/
1291 VariableSetStmt *n = makeNode(VariableSetStmt);
1292 n->kind = VAR_SET_VALUE;
1293 n->name = "search_path";
1294 n->args = list_make1(makeStringConst($2, @2));
1297 | NAMES opt_encoding
1299 VariableSetStmt *n = makeNode(VariableSetStmt);
1300 n->kind = VAR_SET_VALUE;
1301 n->name = "client_encoding";
1303 n->args = list_make1(makeStringConst($2, @2));
1305 n->kind = VAR_SET_DEFAULT;
1308 | ROLE ColId_or_Sconst
1310 VariableSetStmt *n = makeNode(VariableSetStmt);
1311 n->kind = VAR_SET_VALUE;
1313 n->args = list_make1(makeStringConst($2, @2));
1316 | SESSION AUTHORIZATION ColId_or_Sconst
1318 VariableSetStmt *n = makeNode(VariableSetStmt);
1319 n->kind = VAR_SET_VALUE;
1320 n->name = "session_authorization";
1321 n->args = list_make1(makeStringConst($3, @3));
1324 | SESSION AUTHORIZATION DEFAULT
1326 VariableSetStmt *n = makeNode(VariableSetStmt);
1327 n->kind = VAR_SET_DEFAULT;
1328 n->name = "session_authorization";
1331 | XML_P OPTION document_or_content
1333 VariableSetStmt *n = makeNode(VariableSetStmt);
1334 n->kind = VAR_SET_VALUE;
1335 n->name = "xmloption";
1336 n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1341 var_name: ColId { $$ = $1; }
1342 | var_name '.' ColId
1344 $$ = palloc(strlen($1) + strlen($3) + 2);
1345 sprintf($$, "%s.%s", $1, $3);
1349 var_list: var_value { $$ = list_make1($1); }
1350 | var_list ',' var_value { $$ = lappend($1, $3); }
1353 var_value: opt_boolean_or_string
1354 { $$ = makeStringConst($1, @1); }
1356 { $$ = makeAConst($1, @1); }
1359 iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1360 | READ COMMITTED { $$ = "read committed"; }
1361 | REPEATABLE READ { $$ = "repeatable read"; }
1362 | SERIALIZABLE { $$ = "serializable"; }
1365 opt_boolean_or_string:
1366 TRUE_P { $$ = "true"; }
1367 | FALSE_P { $$ = "false"; }
1370 * OFF is also accepted as a boolean value, but is handled
1371 * by the ColId rule below. The action for booleans and strings
1372 * is the same, so we don't need to distinguish them here.
1374 | ColId_or_Sconst { $$ = $1; }
1377 /* Timezone values can be:
1378 * - a string such as 'pst8pdt'
1379 * - an identifier such as "pst8pdt"
1380 * - an integer or floating point number
1381 * - a time interval per SQL99
1382 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1383 * so use IDENT (meaning we reject anything that is a key word).
1388 $$ = makeStringConst($1, @1);
1392 $$ = makeStringConst($1, @1);
1394 | ConstInterval Sconst opt_interval
1399 A_Const *n = (A_Const *) linitial($3);
1400 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1402 (errcode(ERRCODE_SYNTAX_ERROR),
1403 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1404 parser_errposition(@3)));
1407 $$ = makeStringConstCast($2, @2, t);
1409 | ConstInterval '(' Iconst ')' Sconst opt_interval
1414 A_Const *n = (A_Const *) linitial($6);
1415 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1417 (errcode(ERRCODE_SYNTAX_ERROR),
1418 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1419 parser_errposition(@6)));
1420 if (list_length($6) != 1)
1422 (errcode(ERRCODE_SYNTAX_ERROR),
1423 errmsg("interval precision specified twice"),
1424 parser_errposition(@1)));
1425 t->typmods = lappend($6, makeIntConst($3, @3));
1428 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1429 makeIntConst($3, @3));
1430 $$ = makeStringConstCast($5, @5, t);
1432 | NumericOnly { $$ = makeAConst($1, @1); }
1433 | DEFAULT { $$ = NULL; }
1434 | LOCAL { $$ = NULL; }
1439 | DEFAULT { $$ = NULL; }
1440 | /*EMPTY*/ { $$ = NULL; }
1445 | Sconst { $$ = $1; }
1451 VariableSetStmt *n = makeNode(VariableSetStmt);
1452 n->kind = VAR_RESET;
1458 VariableSetStmt *n = makeNode(VariableSetStmt);
1459 n->kind = VAR_RESET;
1460 n->name = "timezone";
1463 | RESET TRANSACTION ISOLATION LEVEL
1465 VariableSetStmt *n = makeNode(VariableSetStmt);
1466 n->kind = VAR_RESET;
1467 n->name = "transaction_isolation";
1470 | RESET SESSION AUTHORIZATION
1472 VariableSetStmt *n = makeNode(VariableSetStmt);
1473 n->kind = VAR_RESET;
1474 n->name = "session_authorization";
1479 VariableSetStmt *n = makeNode(VariableSetStmt);
1480 n->kind = VAR_RESET_ALL;
1485 /* SetResetClause allows SET or RESET without LOCAL */
1487 SET set_rest { $$ = $2; }
1488 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1495 VariableShowStmt *n = makeNode(VariableShowStmt);
1501 VariableShowStmt *n = makeNode(VariableShowStmt);
1502 n->name = "timezone";
1505 | SHOW TRANSACTION ISOLATION LEVEL
1507 VariableShowStmt *n = makeNode(VariableShowStmt);
1508 n->name = "transaction_isolation";
1511 | SHOW SESSION AUTHORIZATION
1513 VariableShowStmt *n = makeNode(VariableShowStmt);
1514 n->name = "session_authorization";
1519 VariableShowStmt *n = makeNode(VariableShowStmt);
1527 SET CONSTRAINTS constraints_set_list constraints_set_mode
1529 ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
1530 n->constraints = $3;
1536 constraints_set_list:
1538 | qualified_name_list { $$ = $1; }
1541 constraints_set_mode:
1542 DEFERRED { $$ = TRUE; }
1543 | IMMEDIATE { $$ = FALSE; }
1548 * Checkpoint statement
1553 CheckPointStmt *n = makeNode(CheckPointStmt);
1559 /*****************************************************************************
1561 * DISCARD { ALL | TEMP | PLANS }
1563 *****************************************************************************/
1568 DiscardStmt *n = makeNode(DiscardStmt);
1569 n->target = DISCARD_ALL;
1574 DiscardStmt *n = makeNode(DiscardStmt);
1575 n->target = DISCARD_TEMP;
1580 DiscardStmt *n = makeNode(DiscardStmt);
1581 n->target = DISCARD_TEMP;
1586 DiscardStmt *n = makeNode(DiscardStmt);
1587 n->target = DISCARD_PLANS;
1593 /*****************************************************************************
1595 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations
1597 * Note: we accept all subcommands for each of the four variants, and sort
1598 * out what's really legal at execution time.
1599 *****************************************************************************/
1602 ALTER TABLE relation_expr alter_table_cmds
1604 AlterTableStmt *n = makeNode(AlterTableStmt);
1607 n->relkind = OBJECT_TABLE;
1610 | ALTER INDEX qualified_name alter_table_cmds
1612 AlterTableStmt *n = makeNode(AlterTableStmt);
1615 n->relkind = OBJECT_INDEX;
1618 | ALTER SEQUENCE qualified_name alter_table_cmds
1620 AlterTableStmt *n = makeNode(AlterTableStmt);
1623 n->relkind = OBJECT_SEQUENCE;
1626 | ALTER VIEW qualified_name alter_table_cmds
1628 AlterTableStmt *n = makeNode(AlterTableStmt);
1631 n->relkind = OBJECT_VIEW;
1637 alter_table_cmd { $$ = list_make1($1); }
1638 | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
1642 /* ALTER TABLE <name> ADD <coldef> */
1645 AlterTableCmd *n = makeNode(AlterTableCmd);
1646 n->subtype = AT_AddColumn;
1650 /* ALTER TABLE <name> ADD COLUMN <coldef> */
1651 | ADD_P COLUMN columnDef
1653 AlterTableCmd *n = makeNode(AlterTableCmd);
1654 n->subtype = AT_AddColumn;
1658 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1659 | ALTER opt_column ColId alter_column_default
1661 AlterTableCmd *n = makeNode(AlterTableCmd);
1662 n->subtype = AT_ColumnDefault;
1667 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1668 | ALTER opt_column ColId DROP NOT NULL_P
1670 AlterTableCmd *n = makeNode(AlterTableCmd);
1671 n->subtype = AT_DropNotNull;
1675 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1676 | ALTER opt_column ColId SET NOT NULL_P
1678 AlterTableCmd *n = makeNode(AlterTableCmd);
1679 n->subtype = AT_SetNotNull;
1683 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
1684 | ALTER opt_column ColId SET STATISTICS SignedIconst
1686 AlterTableCmd *n = makeNode(AlterTableCmd);
1687 n->subtype = AT_SetStatistics;
1689 n->def = (Node *) makeInteger($6);
1692 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
1693 | ALTER opt_column ColId SET reloptions
1695 AlterTableCmd *n = makeNode(AlterTableCmd);
1696 n->subtype = AT_SetOptions;
1698 n->def = (Node *) $5;
1701 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
1702 | ALTER opt_column ColId RESET reloptions
1704 AlterTableCmd *n = makeNode(AlterTableCmd);
1705 n->subtype = AT_ResetOptions;
1707 n->def = (Node *) $5;
1710 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1711 | ALTER opt_column ColId SET STORAGE ColId
1713 AlterTableCmd *n = makeNode(AlterTableCmd);
1714 n->subtype = AT_SetStorage;
1716 n->def = (Node *) makeString($6);
1719 /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
1720 | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
1722 AlterTableCmd *n = makeNode(AlterTableCmd);
1723 n->subtype = AT_DropColumn;
1726 n->missing_ok = TRUE;
1729 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1730 | DROP opt_column ColId opt_drop_behavior
1732 AlterTableCmd *n = makeNode(AlterTableCmd);
1733 n->subtype = AT_DropColumn;
1736 n->missing_ok = FALSE;
1740 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
1741 * [ USING <expression> ]
1743 | ALTER opt_column ColId opt_set_data TYPE_P Typename alter_using
1745 AlterTableCmd *n = makeNode(AlterTableCmd);
1746 n->subtype = AT_AlterColumnType;
1748 n->def = (Node *) $6;
1752 /* ALTER TABLE <name> ADD CONSTRAINT ... */
1753 | ADD_P TableConstraint
1755 AlterTableCmd *n = makeNode(AlterTableCmd);
1756 n->subtype = AT_AddConstraint;
1760 /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
1761 | VALIDATE CONSTRAINT name
1763 AlterTableCmd *n = makeNode(AlterTableCmd);
1764 n->subtype = AT_ValidateConstraint;
1768 /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
1769 | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
1771 AlterTableCmd *n = makeNode(AlterTableCmd);
1772 n->subtype = AT_DropConstraint;
1775 n->missing_ok = TRUE;
1778 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1779 | DROP CONSTRAINT name opt_drop_behavior
1781 AlterTableCmd *n = makeNode(AlterTableCmd);
1782 n->subtype = AT_DropConstraint;
1785 n->missing_ok = FALSE;
1788 /* ALTER TABLE <name> SET WITH OIDS */
1791 AlterTableCmd *n = makeNode(AlterTableCmd);
1792 n->subtype = AT_AddOids;
1795 /* ALTER TABLE <name> SET WITHOUT OIDS */
1798 AlterTableCmd *n = makeNode(AlterTableCmd);
1799 n->subtype = AT_DropOids;
1802 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1805 AlterTableCmd *n = makeNode(AlterTableCmd);
1806 n->subtype = AT_ClusterOn;
1810 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1811 | SET WITHOUT CLUSTER
1813 AlterTableCmd *n = makeNode(AlterTableCmd);
1814 n->subtype = AT_DropCluster;
1818 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
1819 | ENABLE_P TRIGGER name
1821 AlterTableCmd *n = makeNode(AlterTableCmd);
1822 n->subtype = AT_EnableTrig;
1826 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
1827 | ENABLE_P ALWAYS TRIGGER name
1829 AlterTableCmd *n = makeNode(AlterTableCmd);
1830 n->subtype = AT_EnableAlwaysTrig;
1834 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
1835 | ENABLE_P REPLICA TRIGGER name
1837 AlterTableCmd *n = makeNode(AlterTableCmd);
1838 n->subtype = AT_EnableReplicaTrig;
1842 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
1843 | ENABLE_P TRIGGER ALL
1845 AlterTableCmd *n = makeNode(AlterTableCmd);
1846 n->subtype = AT_EnableTrigAll;
1849 /* ALTER TABLE <name> ENABLE TRIGGER USER */
1850 | ENABLE_P TRIGGER USER
1852 AlterTableCmd *n = makeNode(AlterTableCmd);
1853 n->subtype = AT_EnableTrigUser;
1856 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
1857 | DISABLE_P TRIGGER name
1859 AlterTableCmd *n = makeNode(AlterTableCmd);
1860 n->subtype = AT_DisableTrig;
1864 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
1865 | DISABLE_P TRIGGER ALL
1867 AlterTableCmd *n = makeNode(AlterTableCmd);
1868 n->subtype = AT_DisableTrigAll;
1871 /* ALTER TABLE <name> DISABLE TRIGGER USER */
1872 | DISABLE_P TRIGGER USER
1874 AlterTableCmd *n = makeNode(AlterTableCmd);
1875 n->subtype = AT_DisableTrigUser;
1878 /* ALTER TABLE <name> ENABLE RULE <rule> */
1879 | ENABLE_P RULE name
1881 AlterTableCmd *n = makeNode(AlterTableCmd);
1882 n->subtype = AT_EnableRule;
1886 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
1887 | ENABLE_P ALWAYS RULE name
1889 AlterTableCmd *n = makeNode(AlterTableCmd);
1890 n->subtype = AT_EnableAlwaysRule;
1894 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
1895 | ENABLE_P REPLICA RULE name
1897 AlterTableCmd *n = makeNode(AlterTableCmd);
1898 n->subtype = AT_EnableReplicaRule;
1902 /* ALTER TABLE <name> DISABLE RULE <rule> */
1903 | DISABLE_P RULE name
1905 AlterTableCmd *n = makeNode(AlterTableCmd);
1906 n->subtype = AT_DisableRule;
1910 /* ALTER TABLE <name> INHERIT <parent> */
1911 | INHERIT qualified_name
1913 AlterTableCmd *n = makeNode(AlterTableCmd);
1914 n->subtype = AT_AddInherit;
1915 n->def = (Node *) $2;
1918 /* ALTER TABLE <name> NO INHERIT <parent> */
1919 | NO INHERIT qualified_name
1921 AlterTableCmd *n = makeNode(AlterTableCmd);
1922 n->subtype = AT_DropInherit;
1923 n->def = (Node *) $3;
1926 /* ALTER TABLE <name> OWNER TO RoleId */
1929 AlterTableCmd *n = makeNode(AlterTableCmd);
1930 n->subtype = AT_ChangeOwner;
1934 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1935 | SET TABLESPACE name
1937 AlterTableCmd *n = makeNode(AlterTableCmd);
1938 n->subtype = AT_SetTableSpace;
1942 /* ALTER TABLE <name> SET (...) */
1945 AlterTableCmd *n = makeNode(AlterTableCmd);
1946 n->subtype = AT_SetRelOptions;
1947 n->def = (Node *)$2;
1950 /* ALTER TABLE <name> RESET (...) */
1953 AlterTableCmd *n = makeNode(AlterTableCmd);
1954 n->subtype = AT_ResetRelOptions;
1955 n->def = (Node *)$2;
1958 | alter_generic_options
1960 AlterTableCmd *n = makeNode(AlterTableCmd);
1961 n->subtype = AT_GenericOptions;
1962 n->def = (Node *)$1;
1967 alter_column_default:
1968 SET DEFAULT a_expr { $$ = $3; }
1969 | DROP DEFAULT { $$ = NULL; }
1973 CASCADE { $$ = DROP_CASCADE; }
1974 | RESTRICT { $$ = DROP_RESTRICT; }
1975 | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1979 USING a_expr { $$ = $2; }
1980 | /* EMPTY */ { $$ = NULL; }
1984 '(' reloption_list ')' { $$ = $2; }
1987 opt_reloptions: WITH reloptions { $$ = $2; }
1988 | /* EMPTY */ { $$ = NIL; }
1992 reloption_elem { $$ = list_make1($1); }
1993 | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
1996 /* This should match def_elem and also allow qualified names */
1998 ColLabel '=' def_arg
2000 $$ = makeDefElem($1, (Node *) $3);
2004 $$ = makeDefElem($1, NULL);
2006 | ColLabel '.' ColLabel '=' def_arg
2008 $$ = makeDefElemExtended($1, $3, (Node *) $5,
2011 | ColLabel '.' ColLabel
2013 $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC);
2018 /*****************************************************************************
2022 * really variants of the ALTER TABLE subcommands with different spellings
2023 *****************************************************************************/
2025 AlterCompositeTypeStmt:
2026 ALTER TYPE_P any_name alter_type_cmds
2028 AlterTableStmt *n = makeNode(AlterTableStmt);
2030 /* can't use qualified_name, sigh */
2031 n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
2033 n->relkind = OBJECT_TYPE;
2039 alter_type_cmd { $$ = list_make1($1); }
2040 | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); }
2044 /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
2045 ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
2047 AlterTableCmd *n = makeNode(AlterTableCmd);
2048 n->subtype = AT_AddColumn;
2053 /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
2054 | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
2056 AlterTableCmd *n = makeNode(AlterTableCmd);
2057 n->subtype = AT_DropColumn;
2060 n->missing_ok = TRUE;
2063 /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
2064 | DROP ATTRIBUTE ColId opt_drop_behavior
2066 AlterTableCmd *n = makeNode(AlterTableCmd);
2067 n->subtype = AT_DropColumn;
2070 n->missing_ok = FALSE;
2073 /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
2074 | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_drop_behavior
2076 AlterTableCmd *n = makeNode(AlterTableCmd);
2077 n->subtype = AT_AlterColumnType;
2079 n->def = (Node *) $6;
2086 /*****************************************************************************
2089 * close <portalname>
2091 *****************************************************************************/
2096 ClosePortalStmt *n = makeNode(ClosePortalStmt);
2102 ClosePortalStmt *n = makeNode(ClosePortalStmt);
2103 n->portalname = NULL;
2109 /*****************************************************************************
2112 * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
2113 * COPY ( SELECT ... ) TO file [WITH] [(options)]
2115 * In the preferred syntax the options are comma-separated
2116 * and use generic identifiers instead of keywords. The pre-9.0
2117 * syntax had a hard-wired, space-separated set of options.
2119 * Really old syntax, from versions 7.2 and prior:
2120 * COPY [ BINARY ] table [ WITH OIDS ] FROM/TO file
2121 * [ [ USING ] DELIMITERS 'delimiter' ] ]
2122 * [ WITH NULL AS 'null string' ]
2123 * This option placement is not supported with COPY (SELECT...).
2125 *****************************************************************************/
2127 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
2128 copy_from copy_file_name copy_delimiter opt_with copy_options
2130 CopyStmt *n = makeNode(CopyStmt);
2138 /* Concatenate user-supplied flags */
2140 n->options = lappend(n->options, $2);
2142 n->options = lappend(n->options, $5);
2144 n->options = lappend(n->options, $8);
2146 n->options = list_concat(n->options, $10);
2149 | COPY select_with_parens TO copy_file_name opt_with copy_options
2151 CopyStmt *n = makeNode(CopyStmt);
2164 | TO { $$ = FALSE; }
2168 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
2169 * used depends on the direction. (It really doesn't make sense to copy from
2170 * stdout. We silently correct the "typo".) - AY 9/94
2174 | STDIN { $$ = NULL; }
2175 | STDOUT { $$ = NULL; }
2178 copy_options: copy_opt_list { $$ = $1; }
2179 | '(' copy_generic_opt_list ')' { $$ = $2; }
2182 /* old COPY option syntax */
2184 copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
2185 | /* EMPTY */ { $$ = NIL; }
2191 $$ = makeDefElem("format", (Node *)makeString("binary"));
2195 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2197 | DELIMITER opt_as Sconst
2199 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2201 | NULL_P opt_as Sconst
2203 $$ = makeDefElem("null", (Node *)makeString($3));
2207 $$ = makeDefElem("format", (Node *)makeString("csv"));
2211 $$ = makeDefElem("header", (Node *)makeInteger(TRUE));
2213 | QUOTE opt_as Sconst
2215 $$ = makeDefElem("quote", (Node *)makeString($3));
2217 | ESCAPE opt_as Sconst
2219 $$ = makeDefElem("escape", (Node *)makeString($3));
2221 | FORCE QUOTE columnList
2223 $$ = makeDefElem("force_quote", (Node *)$3);
2227 $$ = makeDefElem("force_quote", (Node *)makeNode(A_Star));
2229 | FORCE NOT NULL_P columnList
2231 $$ = makeDefElem("force_not_null", (Node *)$4);
2235 /* The following exist for backward compatibility with very old versions */
2240 $$ = makeDefElem("format", (Node *)makeString("binary"));
2242 | /*EMPTY*/ { $$ = NULL; }
2248 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2250 | /*EMPTY*/ { $$ = NULL; }
2254 opt_using DELIMITERS Sconst
2256 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2258 | /*EMPTY*/ { $$ = NULL; }
2266 /* new COPY option syntax */
2267 copy_generic_opt_list:
2268 copy_generic_opt_elem
2270 $$ = list_make1($1);
2272 | copy_generic_opt_list ',' copy_generic_opt_elem
2274 $$ = lappend($1, $3);
2278 copy_generic_opt_elem:
2279 ColLabel copy_generic_opt_arg
2281 $$ = makeDefElem($1, $2);
2285 copy_generic_opt_arg:
2286 opt_boolean_or_string { $$ = (Node *) makeString($1); }
2287 | NumericOnly { $$ = (Node *) $1; }
2288 | '*' { $$ = (Node *) makeNode(A_Star); }
2289 | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
2290 | /* EMPTY */ { $$ = NULL; }
2293 copy_generic_opt_arg_list:
2294 copy_generic_opt_arg_list_item
2296 $$ = list_make1($1);
2298 | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
2300 $$ = lappend($1, $3);
2304 /* beware of emitting non-string list elements here; see commands/define.c */
2305 copy_generic_opt_arg_list_item:
2306 opt_boolean_or_string { $$ = (Node *) makeString($1); }
2310 /*****************************************************************************
2313 * CREATE TABLE relname
2315 *****************************************************************************/
2317 CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
2318 OptInherit OptWith OnCommitOption OptTableSpace
2320 CreateStmt *n = makeNode(CreateStmt);
2321 $4->relpersistence = $2;
2324 n->inhRelations = $8;
2325 n->constraints = NIL;
2328 n->tablespacename = $11;
2329 n->if_not_exists = false;
2332 | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
2333 OptTableElementList ')' OptInherit OptWith OnCommitOption
2336 CreateStmt *n = makeNode(CreateStmt);
2337 $7->relpersistence = $2;
2340 n->inhRelations = $11;
2341 n->constraints = NIL;
2344 n->tablespacename = $14;
2345 n->if_not_exists = true;
2348 | CREATE OptTemp TABLE qualified_name OF any_name
2349 OptTypedTableElementList OptWith OnCommitOption OptTableSpace
2351 CreateStmt *n = makeNode(CreateStmt);
2352 $4->relpersistence = $2;
2355 n->ofTypename = makeTypeNameFromNameList($6);
2356 n->ofTypename->location = @6;
2357 n->constraints = NIL;
2360 n->tablespacename = $10;
2361 n->if_not_exists = false;
2364 | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
2365 OptTypedTableElementList OptWith OnCommitOption OptTableSpace
2367 CreateStmt *n = makeNode(CreateStmt);
2368 $7->relpersistence = $2;
2371 n->ofTypename = makeTypeNameFromNameList($9);
2372 n->ofTypename->location = @9;
2373 n->constraints = NIL;
2376 n->tablespacename = $13;
2377 n->if_not_exists = true;
2383 * Redundancy here is needed to avoid shift/reduce conflicts,
2384 * since TEMP is not a reserved word. See also OptTempTableName.
2386 * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
2387 * the LOCAL keyword is really meaningless.
2389 OptTemp: TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
2390 | TEMP { $$ = RELPERSISTENCE_TEMP; }
2391 | LOCAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
2392 | LOCAL TEMP { $$ = RELPERSISTENCE_TEMP; }
2393 | GLOBAL TEMPORARY { $$ = RELPERSISTENCE_TEMP; }
2394 | GLOBAL TEMP { $$ = RELPERSISTENCE_TEMP; }
2395 | UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
2396 | /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
2399 OptTableElementList:
2400 TableElementList { $$ = $1; }
2401 | /*EMPTY*/ { $$ = NIL; }
2404 OptTypedTableElementList:
2405 '(' TypedTableElementList ')' { $$ = $2; }
2406 | /*EMPTY*/ { $$ = NIL; }
2412 $$ = list_make1($1);
2414 | TableElementList ',' TableElement
2416 $$ = lappend($1, $3);
2420 TypedTableElementList:
2423 $$ = list_make1($1);
2425 | TypedTableElementList ',' TypedTableElement
2427 $$ = lappend($1, $3);
2432 columnDef { $$ = $1; }
2433 | TableLikeClause { $$ = $1; }
2434 | TableConstraint { $$ = $1; }
2438 columnOptions { $$ = $1; }
2439 | TableConstraint { $$ = $1; }
2442 columnDef: ColId Typename ColQualList
2444 ColumnDef *n = makeNode(ColumnDef);
2447 n->constraints = $3;
2453 columnOptions: ColId WITH OPTIONS ColQualList
2455 ColumnDef *n = makeNode(ColumnDef);
2457 n->constraints = $4;
2464 ColQualList ColConstraint { $$ = lappend($1, $2); }
2465 | /*EMPTY*/ { $$ = NIL; }
2469 CONSTRAINT name ColConstraintElem
2471 Constraint *n = (Constraint *) $3;
2472 Assert(IsA(n, Constraint));
2477 | ColConstraintElem { $$ = $1; }
2478 | ConstraintAttr { $$ = $1; }
2481 /* DEFAULT NULL is already the default for Postgres.
2482 * But define it here and carry it forward into the system
2483 * to make it explicit.
2484 * - thomas 1998-09-13
2486 * WITH NULL and NULL are not SQL92-standard syntax elements,
2487 * so leave them out. Use DEFAULT NULL to explicitly indicate
2488 * that a column may have that value. WITH NULL leads to
2489 * shift/reduce conflicts with WITH TIME ZONE anyway.
2490 * - thomas 1999-01-08
2492 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
2493 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
2494 * or be part of a_expr NOT LIKE or similar constructs).
2499 Constraint *n = makeNode(Constraint);
2500 n->contype = CONSTR_NOTNULL;
2506 Constraint *n = makeNode(Constraint);
2507 n->contype = CONSTR_NULL;
2511 | UNIQUE opt_definition OptConsTableSpace
2513 Constraint *n = makeNode(Constraint);
2514 n->contype = CONSTR_UNIQUE;
2518 n->indexname = NULL;
2522 | PRIMARY KEY opt_definition OptConsTableSpace
2524 Constraint *n = makeNode(Constraint);
2525 n->contype = CONSTR_PRIMARY;
2529 n->indexname = NULL;
2533 | CHECK '(' a_expr ')'
2535 Constraint *n = makeNode(Constraint);
2536 n->contype = CONSTR_CHECK;
2539 n->cooked_expr = NULL;
2544 Constraint *n = makeNode(Constraint);
2545 n->contype = CONSTR_DEFAULT;
2548 n->cooked_expr = NULL;
2551 | REFERENCES qualified_name opt_column_list key_match key_actions
2553 Constraint *n = makeNode(Constraint);
2554 n->contype = CONSTR_FOREIGN;
2559 n->fk_matchtype = $4;
2560 n->fk_upd_action = (char) ($5 >> 8);
2561 n->fk_del_action = (char) ($5 & 0xFF);
2562 n->skip_validation = FALSE;
2568 * ConstraintAttr represents constraint attributes, which we parse as if
2569 * they were independent constraint clauses, in order to avoid shift/reduce
2570 * conflicts (since NOT might start either an independent NOT NULL clause
2571 * or an attribute). parse_utilcmd.c is responsible for attaching the
2572 * attribute information to the preceding "real" constraint node, and for
2573 * complaining if attribute clauses appear in the wrong place or wrong
2576 * See also ConstraintAttributeSpec, which can be used in places where
2577 * there is no parsing conflict.
2582 Constraint *n = makeNode(Constraint);
2583 n->contype = CONSTR_ATTR_DEFERRABLE;
2589 Constraint *n = makeNode(Constraint);
2590 n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
2594 | INITIALLY DEFERRED
2596 Constraint *n = makeNode(Constraint);
2597 n->contype = CONSTR_ATTR_DEFERRED;
2601 | INITIALLY IMMEDIATE
2603 Constraint *n = makeNode(Constraint);
2604 n->contype = CONSTR_ATTR_IMMEDIATE;
2612 * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2613 * This seems to be a poor man's inheritance capability, with the resulting
2614 * tables completely decoupled except for the original commonality in definitions.
2616 * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2617 * which is a part of SQL:2003.
2620 LIKE qualified_name TableLikeOptionList
2622 InhRelation *n = makeNode(InhRelation);
2629 TableLikeOptionList:
2630 TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
2631 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
2632 | /* EMPTY */ { $$ = 0; }
2636 DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
2637 | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
2638 | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
2639 | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
2640 | COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
2641 | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
2645 /* ConstraintElem specifies constraint syntax which is not embedded into
2646 * a column definition. ColConstraintElem specifies the embedded form.
2647 * - thomas 1997-12-03
2650 CONSTRAINT name ConstraintElem
2652 Constraint *n = (Constraint *) $3;
2653 Assert(IsA(n, Constraint));
2658 | ConstraintElem { $$ = $1; }
2662 CHECK '(' a_expr ')' ConstraintAttributeSpec
2664 Constraint *n = makeNode(Constraint);
2665 n->contype = CONSTR_CHECK;
2668 n->cooked_expr = NULL;
2671 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2672 errmsg("CHECK constraints cannot be deferred"),
2673 parser_errposition(@5)));
2676 | UNIQUE '(' columnList ')' opt_definition OptConsTableSpace
2677 ConstraintAttributeSpec
2679 Constraint *n = makeNode(Constraint);
2680 n->contype = CONSTR_UNIQUE;
2684 n->indexname = NULL;
2686 n->deferrable = ($7 & 1) != 0;
2687 n->initdeferred = ($7 & 2) != 0;
2690 | UNIQUE ExistingIndex ConstraintAttributeSpec
2692 Constraint *n = makeNode(Constraint);
2693 n->contype = CONSTR_UNIQUE;
2698 n->indexspace = NULL;
2699 n->deferrable = ($3 & 1) != 0;
2700 n->initdeferred = ($3 & 2) != 0;
2703 | PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace
2704 ConstraintAttributeSpec
2706 Constraint *n = makeNode(Constraint);
2707 n->contype = CONSTR_PRIMARY;
2711 n->indexname = NULL;
2713 n->deferrable = ($8 & 1) != 0;
2714 n->initdeferred = ($8 & 2) != 0;
2717 | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
2719 Constraint *n = makeNode(Constraint);
2720 n->contype = CONSTR_PRIMARY;
2725 n->indexspace = NULL;
2726 n->deferrable = ($4 & 1) != 0;
2727 n->initdeferred = ($4 & 2) != 0;
2730 | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
2731 opt_definition OptConsTableSpace ExclusionWhereClause
2732 ConstraintAttributeSpec
2734 Constraint *n = makeNode(Constraint);
2735 n->contype = CONSTR_EXCLUSION;
2737 n->access_method = $2;
2740 n->indexname = NULL;
2742 n->where_clause = $8;
2743 n->deferrable = ($9 & 1) != 0;
2744 n->initdeferred = ($9 & 2) != 0;
2747 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
2748 opt_column_list key_match key_actions ConstraintAttributeSpec
2750 Constraint *n = makeNode(Constraint);
2751 n->contype = CONSTR_FOREIGN;
2756 n->fk_matchtype = $9;
2757 n->fk_upd_action = (char) ($10 >> 8);
2758 n->fk_del_action = (char) ($10 & 0xFF);
2759 n->deferrable = ($11 & 1) != 0;
2760 n->initdeferred = ($11 & 2) != 0;
2761 n->skip_validation = false;
2764 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
2765 opt_column_list key_match key_actions
2768 Constraint *n = makeNode(Constraint);
2769 n->contype = CONSTR_FOREIGN;
2774 n->fk_matchtype = $9;
2775 n->fk_upd_action = (char) ($10 >> 8);
2776 n->fk_del_action = (char) ($10 & 0xFF);
2777 n->skip_validation = true;
2783 '(' columnList ')' { $$ = $2; }
2784 | /*EMPTY*/ { $$ = NIL; }
2788 columnElem { $$ = list_make1($1); }
2789 | columnList ',' columnElem { $$ = lappend($1, $3); }
2794 $$ = (Node *) makeString($1);
2798 key_match: MATCH FULL
2800 $$ = FKCONSTR_MATCH_FULL;
2805 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2806 errmsg("MATCH PARTIAL not yet implemented"),
2807 parser_errposition(@1)));
2808 $$ = FKCONSTR_MATCH_PARTIAL;
2812 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2816 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2820 ExclusionConstraintList:
2821 ExclusionConstraintElem { $$ = list_make1($1); }
2822 | ExclusionConstraintList ',' ExclusionConstraintElem
2823 { $$ = lappend($1, $3); }
2826 ExclusionConstraintElem: index_elem WITH any_operator
2828 $$ = list_make2($1, $3);
2830 /* allow OPERATOR() decoration for the benefit of ruleutils.c */
2831 | index_elem WITH OPERATOR '(' any_operator ')'
2833 $$ = list_make2($1, $5);
2837 ExclusionWhereClause:
2838 WHERE '(' a_expr ')' { $$ = $3; }
2839 | /*EMPTY*/ { $$ = NULL; }
2843 * We combine the update and delete actions into one value temporarily
2844 * for simplicity of parsing, and then break them down again in the
2845 * calling production. update is in the left 8 bits, delete in the right.
2846 * Note that NOACTION is the default.
2850 { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2852 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
2853 | key_update key_delete
2854 { $$ = ($1 << 8) | ($2 & 0xFF); }
2855 | key_delete key_update
2856 { $$ = ($2 << 8) | ($1 & 0xFF); }
2858 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2861 key_update: ON UPDATE key_action { $$ = $3; }
2864 key_delete: ON DELETE_P key_action { $$ = $3; }
2868 NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; }
2869 | RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; }
2870 | CASCADE { $$ = FKCONSTR_ACTION_CASCADE; }
2871 | SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; }
2872 | SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; }
2875 OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
2876 | /*EMPTY*/ { $$ = NIL; }
2879 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
2881 WITH reloptions { $$ = $2; }
2882 | WITH OIDS { $$ = list_make1(defWithOids(true)); }
2883 | WITHOUT OIDS { $$ = list_make1(defWithOids(false)); }
2884 | /*EMPTY*/ { $$ = NIL; }
2887 OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
2888 | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
2889 | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
2890 | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
2893 OptTableSpace: TABLESPACE name { $$ = $2; }
2894 | /*EMPTY*/ { $$ = NULL; }
2897 OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
2898 | /*EMPTY*/ { $$ = NULL; }
2901 ExistingIndex: USING INDEX index_name { $$ = $3; }
2906 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
2911 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
2914 * When the SelectStmt is a set-operation tree, we must
2915 * stuff the INTO information into the leftmost component
2916 * Select, because that's where analyze.c will expect
2917 * to find it. Similarly, the output column names must
2918 * be attached to that Select's target list.
2920 SelectStmt *n = findLeftmostSelect((SelectStmt *) $6);
2921 if (n->intoClause != NULL)
2923 (errcode(ERRCODE_SYNTAX_ERROR),
2924 errmsg("CREATE TABLE AS cannot specify INTO"),
2925 parser_errposition(exprLocation((Node *) n->intoClause))));
2926 $4->rel->relpersistence = $2;
2928 /* Implement WITH NO DATA by forcing top-level LIMIT 0 */
2930 ((SelectStmt *) $6)->limitCount = makeIntConst(0, -1);
2936 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
2938 $$ = makeNode(IntoClause);
2943 $$->tableSpaceName = $5;
2948 '(' CreateAsList ')' { $$ = $2; }
2949 | /*EMPTY*/ { $$ = NIL; }
2953 CreateAsElement { $$ = list_make1($1); }
2954 | CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); }
2960 ColumnDef *n = makeNode(ColumnDef);
2965 n->is_not_null = false;
2966 n->raw_default = NULL;
2967 n->cooked_default = NULL;
2968 n->constraints = NIL;
2974 WITH DATA_P { $$ = TRUE; }
2975 | WITH NO DATA_P { $$ = FALSE; }
2976 | /*EMPTY*/ { $$ = TRUE; }
2980 /*****************************************************************************
2983 * CREATE SEQUENCE seqname
2984 * ALTER SEQUENCE seqname
2986 *****************************************************************************/
2989 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
2991 CreateSeqStmt *n = makeNode(CreateSeqStmt);
2992 $4->relpersistence = $2;
2995 n->ownerId = InvalidOid;
3001 ALTER SEQUENCE qualified_name SeqOptList
3003 AlterSeqStmt *n = makeNode(AlterSeqStmt);
3010 OptSeqOptList: SeqOptList { $$ = $1; }
3011 | /*EMPTY*/ { $$ = NIL; }
3014 SeqOptList: SeqOptElem { $$ = list_make1($1); }
3015 | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
3018 SeqOptElem: CACHE NumericOnly
3020 $$ = makeDefElem("cache", (Node *)$2);
3024 $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE));
3028 $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE));
3030 | INCREMENT opt_by NumericOnly
3032 $$ = makeDefElem("increment", (Node *)$3);
3034 | MAXVALUE NumericOnly
3036 $$ = makeDefElem("maxvalue", (Node *)$2);
3038 | MINVALUE NumericOnly
3040 $$ = makeDefElem("minvalue", (Node *)$2);
3044 $$ = makeDefElem("maxvalue", NULL);
3048 $$ = makeDefElem("minvalue", NULL);
3052 $$ = makeDefElem("owned_by", (Node *)$3);
3054 | START opt_with NumericOnly
3056 $$ = makeDefElem("start", (Node *)$3);
3060 $$ = makeDefElem("restart", NULL);
3062 | RESTART opt_with NumericOnly
3064 $$ = makeDefElem("restart", (Node *)$3);
3073 FCONST { $$ = makeFloat($1); }
3079 | SignedIconst { $$ = makeInteger($1); }
3082 NumericOnly_list: NumericOnly { $$ = list_make1($1); }
3083 | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); }
3086 /*****************************************************************************
3089 * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
3090 * DROP [PROCEDURAL] LANGUAGE ...
3092 *****************************************************************************/
3095 CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
3097 CreatePLangStmt *n = makeNode(CreatePLangStmt);
3100 /* parameters are all to be supplied by system */
3103 n->plvalidator = NIL;
3104 n->pltrusted = false;
3107 | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
3108 HANDLER handler_name opt_inline_handler opt_validator
3110 CreatePLangStmt *n = makeNode(CreatePLangStmt);
3115 n->plvalidator = $10;
3122 TRUSTED { $$ = TRUE; }
3123 | /*EMPTY*/ { $$ = FALSE; }
3126 /* This ought to be just func_name, but that causes reduce/reduce conflicts
3127 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
3128 * Work around by using simple names, instead.
3131 name { $$ = list_make1(makeString($1)); }
3132 | name attrs { $$ = lcons(makeString($1), $2); }
3136 INLINE_P handler_name { $$ = $2; }
3137 | /*EMPTY*/ { $$ = NIL; }
3141 VALIDATOR handler_name { $$ = $2; }
3142 | NO VALIDATOR { $$ = NIL; }
3146 validator_clause { $$ = $1; }
3147 | /*EMPTY*/ { $$ = NIL; }
3151 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
3153 DropPLangStmt *n = makeNode(DropPLangStmt);
3156 n->missing_ok = false;
3159 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
3161 DropPLangStmt *n = makeNode(DropPLangStmt);
3164 n->missing_ok = true;
3174 /*****************************************************************************
3177 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
3179 *****************************************************************************/
3181 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
3183 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
3184 n->tablespacename = $3;
3191 OptTableSpaceOwner: OWNER name { $$ = $2; }
3192 | /*EMPTY */ { $$ = NULL; }
3195 /*****************************************************************************
3198 * DROP TABLESPACE <tablespace>
3200 * No need for drop behaviour as we cannot implement dependencies for
3201 * objects in other databases; we can only support RESTRICT.
3203 ****************************************************************************/
3205 DropTableSpaceStmt: DROP TABLESPACE name
3207 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
3208 n->tablespacename = $3;
3209 n->missing_ok = false;
3212 | DROP TABLESPACE IF_P EXISTS name
3214 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
3215 n->tablespacename = $5;
3216 n->missing_ok = true;
3221 /*****************************************************************************
3224 * CREATE EXTENSION extension
3225 * [ WITH ] [ SCHEMA [=] schema ]
3227 *****************************************************************************/
3229 CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
3231 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
3238 create_extension_opt_list:
3239 create_extension_opt_list create_extension_opt_item
3240 { $$ = lappend($1, $2); }
3245 create_extension_opt_item:
3246 SCHEMA opt_equal name
3248 $$ = makeDefElem("schema", (Node *)makeString($3));
3252 /*****************************************************************************
3254 * ALTER EXTENSION name ADD object-identifier
3256 *****************************************************************************/
3258 AlterExtensionAddStmt:
3259 ALTER EXTENSION name ADD_P AGGREGATE func_name aggr_args
3261 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3263 n->objtype = OBJECT_AGGREGATE;
3268 | ALTER EXTENSION name ADD_P CAST '(' Typename AS Typename ')'
3270 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3272 n->objtype = OBJECT_CAST;
3273 n->objname = list_make1($7);
3274 n->objargs = list_make1($9);
3277 | ALTER EXTENSION name ADD_P CONVERSION_P any_name
3279 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3281 n->objtype = OBJECT_CONVERSION;
3285 | ALTER EXTENSION name ADD_P DOMAIN_P any_name
3287 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3289 n->objtype = OBJECT_DOMAIN;
3293 | ALTER EXTENSION name ADD_P FUNCTION function_with_argtypes
3295 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3297 n->objtype = OBJECT_FUNCTION;
3298 n->objname = $6->funcname;
3299 n->objargs = $6->funcargs;
3302 | ALTER EXTENSION name ADD_P opt_procedural LANGUAGE name
3304 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3306 n->objtype = OBJECT_LANGUAGE;
3307 n->objname = list_make1(makeString($7));
3310 | ALTER EXTENSION name ADD_P OPERATOR any_operator oper_argtypes
3312 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3314 n->objtype = OBJECT_OPERATOR;
3319 | ALTER EXTENSION name ADD_P OPERATOR CLASS any_name USING access_method
3321 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3323 n->objtype = OBJECT_OPCLASS;
3325 n->objargs = list_make1(makeString($9));
3328 | ALTER EXTENSION name ADD_P OPERATOR FAMILY any_name USING access_method
3330 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3332 n->objtype = OBJECT_OPFAMILY;
3334 n->objargs = list_make1(makeString($9));
3337 | ALTER EXTENSION name ADD_P SCHEMA name
3339 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3341 n->objtype = OBJECT_SCHEMA;
3342 n->objname = list_make1(makeString($6));
3345 | ALTER EXTENSION name ADD_P TABLE any_name
3347 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3349 n->objtype = OBJECT_TABLE;
3353 | ALTER EXTENSION name ADD_P TEXT_P SEARCH PARSER any_name
3355 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3357 n->objtype = OBJECT_TSPARSER;
3361 | ALTER EXTENSION name ADD_P TEXT_P SEARCH DICTIONARY any_name
3363 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3365 n->objtype = OBJECT_TSDICTIONARY;
3369 | ALTER EXTENSION name ADD_P TEXT_P SEARCH TEMPLATE any_name
3371 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3373 n->objtype = OBJECT_TSTEMPLATE;
3377 | ALTER EXTENSION name ADD_P TEXT_P SEARCH CONFIGURATION any_name
3379 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3381 n->objtype = OBJECT_TSCONFIGURATION;
3385 | ALTER EXTENSION name ADD_P SEQUENCE any_name
3387 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3389 n->objtype = OBJECT_SEQUENCE;
3393 | ALTER EXTENSION name ADD_P VIEW any_name
3395 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3397 n->objtype = OBJECT_VIEW;
3401 | ALTER EXTENSION name ADD_P FOREIGN TABLE any_name
3403 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3405 n->objtype = OBJECT_FOREIGN_TABLE;
3409 | ALTER EXTENSION name ADD_P FOREIGN DATA_P WRAPPER name
3411 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3413 n->objtype = OBJECT_FDW;
3414 n->objname = list_make1(makeString($8));
3417 | ALTER EXTENSION name ADD_P SERVER name
3419 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3421 n->objtype = OBJECT_FOREIGN_SERVER;
3422 n->objname = list_make1(makeString($6));
3425 | ALTER EXTENSION name ADD_P TYPE_P any_name
3427 AlterExtensionAddStmt *n = makeNode(AlterExtensionAddStmt);
3429 n->objtype = OBJECT_TYPE;
3435 /*****************************************************************************
3438 * CREATE FOREIGN DATA WRAPPER name [ VALIDATOR name ]
3440 *****************************************************************************/
3442 CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_validator create_generic_options
3444 CreateFdwStmt *n = makeNode(CreateFdwStmt);
3452 /*****************************************************************************
3455 * DROP FOREIGN DATA WRAPPER name
3457 ****************************************************************************/
3459 DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
3461 DropFdwStmt *n = makeNode(DropFdwStmt);
3463 n->missing_ok = false;
3467 | DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior
3469 DropFdwStmt *n = makeNode(DropFdwStmt);
3471 n->missing_ok = true;
3477 /*****************************************************************************
3480 * ALTER FOREIGN DATA WRAPPER name
3482 ****************************************************************************/
3484 AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name validator_clause alter_generic_options
3486 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3489 n->change_validator = true;
3493 | ALTER FOREIGN DATA_P WRAPPER name validator_clause
3495 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3498 n->change_validator = true;
3501 | ALTER FOREIGN DATA_P WRAPPER name alter_generic_options
3503 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3510 /* Options definition for CREATE FDW, SERVER and USER MAPPING */
3511 create_generic_options:
3512 OPTIONS '(' generic_option_list ')' { $$ = $3; }
3513 | /*EMPTY*/ { $$ = NIL; }
3516 generic_option_list:
3519 $$ = list_make1($1);
3521 | generic_option_list ',' generic_option_elem
3523 $$ = lappend($1, $3);
3527 /* Options definition for ALTER FDW, SERVER and USER MAPPING */
3528 alter_generic_options:
3529 OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
3532 alter_generic_option_list:
3533 alter_generic_option_elem
3535 $$ = list_make1($1);
3537 | alter_generic_option_list ',' alter_generic_option_elem
3539 $$ = lappend($1, $3);
3543 alter_generic_option_elem:
3548 | SET generic_option_elem
3551 $$->defaction = DEFELEM_SET;
3553 | ADD_P generic_option_elem
3556 $$->defaction = DEFELEM_ADD;
3558 | DROP generic_option_name
3560 $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP);
3564 generic_option_elem:
3565 generic_option_name generic_option_arg
3567 $$ = makeDefElem($1, $2);
3571 generic_option_name:
3572 ColLabel { $$ = $1; }
3575 /* We could use def_arg here, but the spec only requires string literals */
3577 Sconst { $$ = (Node *) makeString($1); }
3580 /*****************************************************************************
3583 * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
3585 *****************************************************************************/
3587 CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
3588 FOREIGN DATA_P WRAPPER name create_generic_options
3590 CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
3601 TYPE_P Sconst { $$ = $2; }
3602 | /*EMPTY*/ { $$ = NULL; }
3606 foreign_server_version:
3607 VERSION_P Sconst { $$ = $2; }
3608 | VERSION_P NULL_P { $$ = NULL; }
3611 opt_foreign_server_version:
3612 foreign_server_version { $$ = $1; }
3613 | /*EMPTY*/ { $$ = NULL; }
3616 /*****************************************************************************
3621 ****************************************************************************/
3623 DropForeignServerStmt: DROP SERVER name opt_drop_behavior
3625 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3627 n->missing_ok = false;
3631 | DROP SERVER IF_P EXISTS name opt_drop_behavior
3633 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3635 n->missing_ok = true;
3641 /*****************************************************************************
3644 * ALTER SERVER name [VERSION] [OPTIONS]
3646 ****************************************************************************/
3648 AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
3650 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3654 n->has_version = true;
3657 | ALTER SERVER name foreign_server_version
3659 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3662 n->has_version = true;
3665 | ALTER SERVER name alter_generic_options
3667 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3674 /*****************************************************************************
3677 * CREATE FOREIGN TABLE relname (...) SERVER name (...)
3679 *****************************************************************************/
3681 CreateForeignTableStmt:
3682 CREATE FOREIGN TABLE qualified_name
3683 OptForeignTableElementList
3684 SERVER name create_generic_options
3686 CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
3687 $4->relpersistence = RELPERSISTENCE_PERMANENT;
3688 n->base.relation = $4;
3689 n->base.tableElts = $5;
3690 n->base.inhRelations = NIL;
3691 n->base.if_not_exists = false;
3692 /* FDW-specific data */
3697 | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
3698 OptForeignTableElementList
3699 SERVER name create_generic_options
3701 CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
3702 $7->relpersistence = RELPERSISTENCE_PERMANENT;
3703 n->base.relation = $7;
3704 n->base.tableElts = $8;
3705 n->base.inhRelations = NIL;
3706 n->base.if_not_exists = true;
3707 /* FDW-specific data */
3708 n->servername = $10;
3714 OptForeignTableElementList:
3715 '(' ForeignTableElementList ')' { $$ = $2; }
3716 | '(' ')' { $$ = NIL; }
3719 ForeignTableElementList:
3722 $$ = list_make1($1);
3724 | ForeignTableElementList ',' ForeignTableElement
3726 $$ = lappend($1, $3);
3730 ForeignTableElement:
3731 columnDef { $$ = $1; }
3734 /*****************************************************************************
3737 * ALTER FOREIGN TABLE relname [...]
3739 *****************************************************************************/
3741 AlterForeignTableStmt:
3742 ALTER FOREIGN TABLE relation_expr alter_table_cmds
3744 AlterTableStmt *n = makeNode(AlterTableStmt);
3747 n->relkind = OBJECT_FOREIGN_TABLE;
3752 /*****************************************************************************
3755 * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
3757 *****************************************************************************/
3759 CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
3761 CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
3769 /* User mapping authorization identifier */
3771 CURRENT_USER { $$ = "current_user"; }
3772 | USER { $$ = "current_user"; }
3773 | RoleId { $$ = (strcmp($1, "public") == 0) ? NULL : $1; }
3776 /*****************************************************************************
3779 * DROP USER MAPPING FOR auth_ident SERVER name
3781 ****************************************************************************/
3783 DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
3785 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3788 n->missing_ok = false;
3791 | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
3793 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3796 n->missing_ok = true;
3801 /*****************************************************************************
3804 * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
3806 ****************************************************************************/
3808 AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
3810 AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
3818 /*****************************************************************************
3821 * CREATE TRIGGER ...
3824 *****************************************************************************/
3827 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
3828 qualified_name TriggerForSpec TriggerWhen
3829 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3831 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3838 n->events = intVal(linitial($5));
3839 n->columns = (List *) lsecond($5);
3841 n->isconstraint = FALSE;
3842 n->deferrable = FALSE;
3843 n->initdeferred = FALSE;
3844 n->constrrel = NULL;
3847 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
3848 qualified_name OptConstrFromTable ConstraintAttributeSpec
3849 FOR EACH ROW TriggerWhen
3850 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3852 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3858 n->timing = TRIGGER_TYPE_AFTER;
3859 n->events = intVal(linitial($6));
3860 n->columns = (List *) lsecond($6);
3861 n->whenClause = $14;
3862 n->isconstraint = TRUE;
3863 n->deferrable = ($10 & 1) != 0;
3864 n->initdeferred = ($10 & 2) != 0;
3871 BEFORE { $$ = TRIGGER_TYPE_BEFORE; }
3872 | AFTER { $$ = TRIGGER_TYPE_AFTER; }
3873 | INSTEAD OF { $$ = TRIGGER_TYPE_INSTEAD; }
3879 | TriggerEvents OR TriggerOneEvent
3881 int events1 = intVal(linitial($1));
3882 int events2 = intVal(linitial($3));
3883 List *columns1 = (List *) lsecond($1);
3884 List *columns2 = (List *) lsecond($3);
3886 if (events1 & events2)
3887 parser_yyerror("duplicate trigger events specified");
3889 * concat'ing the columns lists loses information about
3890 * which columns went with which event, but so long as
3891 * only UPDATE carries columns and we disallow multiple
3892 * UPDATE items, it doesn't matter. Command execution
3893 * should just ignore the columns for non-UPDATE events.
3895 $$ = list_make2(makeInteger(events1 | events2),
3896 list_concat(columns1, columns2));
3902 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
3904 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
3906 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
3907 | UPDATE OF columnList
3908 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
3910 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
3914 FOR TriggerForOptEach TriggerForType
3921 * If ROW/STATEMENT not specified, default to
3922 * STATEMENT, per SQL
3935 | STATEMENT { $$ = FALSE; }
3939 WHEN '(' a_expr ')' { $$ = $3; }
3940 | /*EMPTY*/ { $$ = NULL; }
3944 TriggerFuncArg { $$ = list_make1($1); }
3945 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
3946 | /*EMPTY*/ { $$ = NIL; }
3953 snprintf(buf, sizeof(buf), "%d", $1);
3954 $$ = makeString(pstrdup(buf));
3956 | FCONST { $$ = makeString($1); }
3957 | Sconst { $$ = makeString($1); }
3958 | BCONST { $$ = makeString($1); }
3959 | XCONST { $$ = makeString($1); }
3960 | ColId { $$ = makeString($1); }
3964 FROM qualified_name { $$ = $2; }
3965 | /*EMPTY*/ { $$ = NULL; }
3968 ConstraintAttributeSpec:
3969 ConstraintDeferrabilitySpec
3971 | ConstraintDeferrabilitySpec ConstraintTimeSpec
3973 if ($1 == 0 && $2 != 0)
3975 (errcode(ERRCODE_SYNTAX_ERROR),
3976 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3977 parser_errposition(@1)));
3980 | ConstraintTimeSpec
3987 | ConstraintTimeSpec ConstraintDeferrabilitySpec
3989 if ($2 == 0 && $1 != 0)
3991 (errcode(ERRCODE_SYNTAX_ERROR),
3992 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3993 parser_errposition(@1)));
4000 ConstraintDeferrabilitySpec:
4001 NOT DEFERRABLE { $$ = 0; }
4002 | DEFERRABLE { $$ = 1; }
4006 INITIALLY IMMEDIATE { $$ = 0; }
4007 | INITIALLY DEFERRED { $$ = 2; }
4012 DROP TRIGGER name ON qualified_name opt_drop_behavior
4014 DropPropertyStmt *n = makeNode(DropPropertyStmt);
4018 n->removeType = OBJECT_TRIGGER;
4019 n->missing_ok = false;
4022 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
4024 DropPropertyStmt *n = makeNode(DropPropertyStmt);
4028 n->removeType = OBJECT_TRIGGER;
4029 n->missing_ok = true;
4035 /*****************************************************************************
4038 * CREATE ASSERTION ...
4039 * DROP ASSERTION ...
4041 *****************************************************************************/
4044 CREATE ASSERTION name CHECK '(' a_expr ')'
4045 ConstraintAttributeSpec
4047 CreateTrigStmt *n = makeNode(CreateTrigStmt);
4049 n->args = list_make1($6);
4050 n->isconstraint = TRUE;
4051 n->deferrable = ($8 & 1) != 0;
4052 n->initdeferred = ($8 & 2) != 0;
4055 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4056 errmsg("CREATE ASSERTION is not yet implemented")));
4063 DROP ASSERTION name opt_drop_behavior
4065 DropPropertyStmt *n = makeNode(DropPropertyStmt);
4069 n->removeType = OBJECT_TRIGGER; /* XXX */
4071 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4072 errmsg("DROP ASSERTION is not yet implemented")));
4078 /*****************************************************************************
4081 * define (aggregate,operator,type)
4083 *****************************************************************************/
4086 CREATE AGGREGATE func_name aggr_args definition
4088 DefineStmt *n = makeNode(DefineStmt);
4089 n->kind = OBJECT_AGGREGATE;
4090 n->oldstyle = false;
4096 | CREATE AGGREGATE func_name old_aggr_definition
4098 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
4099 DefineStmt *n = makeNode(DefineStmt);
4100 n->kind = OBJECT_AGGREGATE;
4107 | CREATE OPERATOR any_operator definition
4109 DefineStmt *n = makeNode(DefineStmt);
4110 n->kind = OBJECT_OPERATOR;
4111 n->oldstyle = false;
4117 | CREATE TYPE_P any_name definition
4119 DefineStmt *n = makeNode(DefineStmt);
4120 n->kind = OBJECT_TYPE;
4121 n->oldstyle = false;
4127 | CREATE TYPE_P any_name
4129 /* Shell type (identified by lack of definition) */
4130 DefineStmt *n = makeNode(DefineStmt);
4131 n->kind = OBJECT_TYPE;
4132 n->oldstyle = false;
4135 n->definition = NIL;
4138 | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
4140 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
4142 /* can't use qualified_name, sigh */
4143 n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
4147 | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
4149 CreateEnumStmt *n = makeNode(CreateEnumStmt);
4154 | CREATE TEXT_P SEARCH PARSER any_name definition
4156 DefineStmt *n = makeNode(DefineStmt);
4157 n->kind = OBJECT_TSPARSER;
4163 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
4165 DefineStmt *n = makeNode(DefineStmt);
4166 n->kind = OBJECT_TSDICTIONARY;
4172 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
4174 DefineStmt *n = makeNode(DefineStmt);
4175 n->kind = OBJECT_TSTEMPLATE;
4181 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
4183 DefineStmt *n = makeNode(DefineStmt);
4184 n->kind = OBJECT_TSCONFIGURATION;
4192 definition: '(' def_list ')' { $$ = $2; }
4195 def_list: def_elem { $$ = list_make1($1); }
4196 | def_list ',' def_elem { $$ = lappend($1, $3); }
4199 def_elem: ColLabel '=' def_arg
4201 $$ = makeDefElem($1, (Node *) $3);
4205 $$ = makeDefElem($1, NULL);
4209 /* Note: any simple identifier will be returned as a type name! */
4210 def_arg: func_type { $$ = (Node *)$1; }
4211 | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
4212 | qual_all_Op { $$ = (Node *)$1; }
4213 | NumericOnly { $$ = (Node *)$1; }
4214 | Sconst { $$ = (Node *)makeString($1); }
4217 aggr_args: '(' type_list ')' { $$ = $2; }
4218 | '(' '*' ')' { $$ = NIL; }
4221 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
4224 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
4225 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
4229 * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
4230 * the item names needed in old aggregate definitions are likely to become
4233 old_aggr_elem: IDENT '=' def_arg
4235 $$ = makeDefElem($1, (Node *)$3);
4240 enum_val_list { $$ = $1; }
4241 | /*EMPTY*/ { $$ = NIL; }
4244 enum_val_list: Sconst
4245 { $$ = list_make1(makeString($1)); }
4246 | enum_val_list ',' Sconst
4247 { $$ = lappend($1, makeString($3)); }
4250 /*****************************************************************************
4252 * ALTER TYPE enumtype ADD ...
4254 *****************************************************************************/
4257 ALTER TYPE_P any_name ADD_P VALUE_P Sconst
4259 AlterEnumStmt *n = makeNode(AlterEnumStmt);
4262 n->newValNeighbor = NULL;
4263 n->newValIsAfter = true;
4266 | ALTER TYPE_P any_name ADD_P VALUE_P Sconst BEFORE Sconst
4268 AlterEnumStmt *n = makeNode(AlterEnumStmt);
4271 n->newValNeighbor = $8;
4272 n->newValIsAfter = false;
4275 | ALTER TYPE_P any_name ADD_P VALUE_P Sconst AFTER Sconst
4277 AlterEnumStmt *n = makeNode(AlterEnumStmt);
4280 n->newValNeighbor = $8;
4281 n->newValIsAfter = true;
4287 /*****************************************************************************
4290 * CREATE OPERATOR CLASS ...
4291 * CREATE OPERATOR FAMILY ...
4292 * ALTER OPERATOR FAMILY ...
4293 * DROP OPERATOR CLASS ...
4294 * DROP OPERATOR FAMILY ...
4296 *****************************************************************************/
4299 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
4300 USING access_method opt_opfamily AS opclass_item_list
4302 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
4303 n->opclassname = $4;
4307 n->opfamilyname = $11;
4314 opclass_item { $$ = list_make1($1); }
4315 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
4319 OPERATOR Iconst any_operator opclass_purpose opt_recheck
4321 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4322 n->itemtype = OPCLASS_ITEM_OPERATOR;
4326 n->order_family = $4;
4329 | OPERATOR Iconst any_operator oper_argtypes opclass_purpose
4332 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4333 n->itemtype = OPCLASS_ITEM_OPERATOR;
4337 n->order_family = $5;
4340 | FUNCTION Iconst func_name func_args
4342 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4343 n->itemtype = OPCLASS_ITEM_FUNCTION;
4345 n->args = extractArgTypes($4);
4349 | FUNCTION Iconst '(' type_list ')' func_name func_args
4351 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4352 n->itemtype = OPCLASS_ITEM_FUNCTION;
4354 n->args = extractArgTypes($7);
4361 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4362 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
4368 opt_default: DEFAULT { $$ = TRUE; }
4369 | /*EMPTY*/ { $$ = FALSE; }
4372 opt_opfamily: FAMILY any_name { $$ = $2; }
4373 | /*EMPTY*/ { $$ = NIL; }
4376 opclass_purpose: FOR SEARCH { $$ = NIL; }
4377 | FOR ORDER BY any_name { $$ = $4; }
4378 | /*EMPTY*/ { $$ = NIL; }
4381 opt_recheck: RECHECK
4384 * RECHECK no longer does anything in opclass definitions,
4385 * but we still accept it to ease porting of old database
4389 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4390 errmsg("RECHECK is no longer required"),
4391 errhint("Update your data type."),
4392 parser_errposition(@1)));
4395 | /*EMPTY*/ { $$ = FALSE; }
4400 CREATE OPERATOR FAMILY any_name USING access_method
4402 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
4403 n->opfamilyname = $4;
4410 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
4412 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
4413 n->opfamilyname = $4;
4419 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
4421 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
4422 n->opfamilyname = $4;
4431 opclass_drop { $$ = list_make1($1); }
4432 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
4436 OPERATOR Iconst '(' type_list ')'
4438 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4439 n->itemtype = OPCLASS_ITEM_OPERATOR;
4444 | FUNCTION Iconst '(' type_list ')'
4446 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4447 n->itemtype = OPCLASS_ITEM_FUNCTION;
4456 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
4458 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
4459 n->opclassname = $4;
4462 n->missing_ok = false;
4465 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
4467 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
4468 n->opclassname = $6;
4471 n->missing_ok = true;
4477 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
4479 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
4480 n->opfamilyname = $4;
4483 n->missing_ok = false;
4486 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
4488 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
4489 n->opfamilyname = $6;
4492 n->missing_ok = true;
4498 /*****************************************************************************
4502 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
4503 * REASSIGN OWNED BY username [, username ...] TO username
4505 *****************************************************************************/
4507 DROP OWNED BY name_list opt_drop_behavior
4509 DropOwnedStmt *n = makeNode(DropOwnedStmt);
4517 REASSIGN OWNED BY name_list TO name
4519 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
4526 /*****************************************************************************
4530 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
4531 * [ RESTRICT | CASCADE ]
4533 *****************************************************************************/
4535 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
4537 DropStmt *n = makeNode(DropStmt);
4539 n->missing_ok = TRUE;
4544 | DROP drop_type any_name_list opt_drop_behavior
4546 DropStmt *n = makeNode(DropStmt);
4548 n->missing_ok = FALSE;
4556 drop_type: TABLE { $$ = OBJECT_TABLE; }
4557 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4558 | VIEW { $$ = OBJECT_VIEW; }
4559 | INDEX { $$ = OBJECT_INDEX; }
4560 | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
4561 | TYPE_P { $$ = OBJECT_TYPE; }
4562 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
4563 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4564 | SCHEMA { $$ = OBJECT_SCHEMA; }
4565 | EXTENSION { $$ = OBJECT_EXTENSION; }
4566 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
4567 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
4568 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
4569 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
4573 any_name { $$ = list_make1($1); }
4574 | any_name_list ',' any_name { $$ = lappend($1, $3); }
4577 any_name: ColId { $$ = list_make1(makeString($1)); }
4578 | ColId attrs { $$ = lcons(makeString($1), $2); }
4581 attrs: '.' attr_name
4582 { $$ = list_make1(makeString($2)); }
4583 | attrs '.' attr_name
4584 { $$ = lappend($1, makeString($3)); }
4588 /*****************************************************************************
4591 * truncate table relname1, relname2, ...
4593 *****************************************************************************/
4596 TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
4598 TruncateStmt *n = makeNode(TruncateStmt);
4600 n->restart_seqs = $4;
4607 CONTINUE_P IDENTITY_P { $$ = false; }
4608 | RESTART IDENTITY_P { $$ = true; }
4609 | /* EMPTY */ { $$ = false; }
4612 /*****************************************************************************
4614 * The COMMENT ON statement can take different forms based upon the type of
4615 * the object associated with the comment. The form of the statement is:
4617 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
4618 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
4619 * CAST | COLUMN | SCHEMA | TABLESPACE | EXTENSION | ROLE |
4620 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
4621 * TEXT SEARCH TEMPLATE | TEXT SEARCH CONFIGURATION |
4622 * FOREIGN TABLE ] <objname> |
4623 * AGGREGATE <aggname> (arg1, ...) |
4624 * FUNCTION <funcname> (arg1, arg2, ...) |
4625 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
4626 * TRIGGER <triggername> ON <relname> |
4627 * CONSTRAINT <constraintname> ON <relname> |
4628 * RULE <rulename> ON <relname> ]
4631 *****************************************************************************/
4634 COMMENT ON comment_type any_name IS comment_text
4636 CommentStmt *n = makeNode(CommentStmt);
4643 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
4645 CommentStmt *n = makeNode(CommentStmt);
4646 n->objtype = OBJECT_AGGREGATE;
4652 | COMMENT ON FUNCTION func_name func_args IS comment_text
4654 CommentStmt *n = makeNode(CommentStmt);
4655 n->objtype = OBJECT_FUNCTION;
4657 n->objargs = extractArgTypes($5);
4661 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
4663 CommentStmt *n = makeNode(CommentStmt);
4664 n->objtype = OBJECT_OPERATOR;
4670 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
4672 CommentStmt *n = makeNode(CommentStmt);
4673 n->objtype = OBJECT_CONSTRAINT;
4674 n->objname = lappend($6, makeString($4));
4679 | COMMENT ON RULE name ON any_name IS comment_text
4681 CommentStmt *n = makeNode(CommentStmt);
4682 n->objtype = OBJECT_RULE;
4683 n->objname = lappend($6, makeString($4));
4688 | COMMENT ON RULE name IS comment_text
4690 /* Obsolete syntax supported for awhile for compatibility */
4691 CommentStmt *n = makeNode(CommentStmt);
4692 n->objtype = OBJECT_RULE;
4693 n->objname = list_make1(makeString($4));
4698 | COMMENT ON TRIGGER name ON any_name IS comment_text
4700 CommentStmt *n = makeNode(CommentStmt);
4701 n->objtype = OBJECT_TRIGGER;
4702 n->objname = lappend($6, makeString($4));
4707 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
4709 CommentStmt *n = makeNode(CommentStmt);
4710 n->objtype = OBJECT_OPCLASS;
4712 n->objargs = list_make1(makeString($7));
4716 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
4718 CommentStmt *n = makeNode(CommentStmt);
4719 n->objtype = OBJECT_OPFAMILY;
4721 n->objargs = list_make1(makeString($7));
4725 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
4727 CommentStmt *n = makeNode(CommentStmt);
4728 n->objtype = OBJECT_LARGEOBJECT;
4729 n->objname = list_make1($5);
4734 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
4736 CommentStmt *n = makeNode(CommentStmt);
4737 n->objtype = OBJECT_CAST;
4738 n->objname = list_make1($5);
4739 n->objargs = list_make1($7);
4743 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
4745 CommentStmt *n = makeNode(CommentStmt);
4746 n->objtype = OBJECT_LANGUAGE;
4752 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
4754 CommentStmt *n = makeNode(CommentStmt);
4755 n->objtype = OBJECT_TSPARSER;
4760 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
4762 CommentStmt *n = makeNode(CommentStmt);
4763 n->objtype = OBJECT_TSDICTIONARY;
4768 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
4770 CommentStmt *n = makeNode(CommentStmt);
4771 n->objtype = OBJECT_TSTEMPLATE;
4776 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
4778 CommentStmt *n = makeNode(CommentStmt);
4779 n->objtype = OBJECT_TSCONFIGURATION;
4787 COLUMN { $$ = OBJECT_COLUMN; }
4788 | DATABASE { $$ = OBJECT_DATABASE; }
4789 | SCHEMA { $$ = OBJECT_SCHEMA; }
4790 | INDEX { $$ = OBJECT_INDEX; }
4791 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4792 | TABLE { $$ = OBJECT_TABLE; }
4793 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
4794 | TYPE_P { $$ = OBJECT_TYPE; }
4795 | VIEW { $$ = OBJECT_VIEW; }
4796 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4797 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
4798 | EXTENSION { $$ = OBJECT_EXTENSION; }
4799 | ROLE { $$ = OBJECT_ROLE; }
4800 | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
4805 | NULL_P { $$ = NULL; }
4809 /*****************************************************************************
4811 * SECURITY LABEL [FOR <provider>] ON <object> IS <label>
4813 * As with COMMENT ON, <object> can refer to various types of database
4814 * objects (e.g. TABLE, COLUMN, etc.).
4816 *****************************************************************************/
4819 SECURITY LABEL opt_provider ON security_label_type any_name
4822 SecLabelStmt *n = makeNode(SecLabelStmt);
4830 | SECURITY LABEL opt_provider ON AGGREGATE func_name aggr_args
4833 SecLabelStmt *n = makeNode(SecLabelStmt);
4835 n->objtype = OBJECT_AGGREGATE;
4841 | SECURITY LABEL opt_provider ON FUNCTION func_name func_args
4844 SecLabelStmt *n = makeNode(SecLabelStmt);
4846 n->objtype = OBJECT_FUNCTION;
4848 n->objargs = extractArgTypes($7);
4852 | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
4855 SecLabelStmt *n = makeNode(SecLabelStmt);
4857 n->objtype = OBJECT_LARGEOBJECT;
4858 n->objname = list_make1($7);
4863 | SECURITY LABEL opt_provider ON opt_procedural LANGUAGE any_name
4866 SecLabelStmt *n = makeNode(SecLabelStmt);
4868 n->objtype = OBJECT_LANGUAGE;
4876 opt_provider: FOR ColId_or_Sconst { $$ = $2; }
4877 | /* empty */ { $$ = NULL; }
4880 security_label_type:
4881 COLUMN { $$ = OBJECT_COLUMN; }
4882 | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
4883 | SCHEMA { $$ = OBJECT_SCHEMA; }
4884 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4885 | TABLE { $$ = OBJECT_TABLE; }
4886 | DOMAIN_P { $$ = OBJECT_TYPE; }
4887 | TYPE_P { $$ = OBJECT_TYPE; }
4888 | VIEW { $$ = OBJECT_VIEW; }
4891 security_label: Sconst { $$ = $1; }
4892 | NULL_P { $$ = NULL; }
4895 /*****************************************************************************
4900 *****************************************************************************/
4902 FetchStmt: FETCH fetch_args
4904 FetchStmt *n = (FetchStmt *) $2;
4910 FetchStmt *n = (FetchStmt *) $2;
4916 fetch_args: cursor_name
4918 FetchStmt *n = makeNode(FetchStmt);
4920 n->direction = FETCH_FORWARD;
4924 | from_in cursor_name
4926 FetchStmt *n = makeNode(FetchStmt);
4928 n->direction = FETCH_FORWARD;
4932 | NEXT opt_from_in cursor_name
4934 FetchStmt *n = makeNode(FetchStmt);
4936 n->direction = FETCH_FORWARD;
4940 | PRIOR opt_from_in cursor_name
4942 FetchStmt *n = makeNode(FetchStmt);
4944 n->direction = FETCH_BACKWARD;
4948 | FIRST_P opt_from_in cursor_name
4950 FetchStmt *n = makeNode(FetchStmt);
4952 n->direction = FETCH_ABSOLUTE;
4956 | LAST_P opt_from_in cursor_name
4958 FetchStmt *n = makeNode(FetchStmt);
4960 n->direction = FETCH_ABSOLUTE;
4964 | ABSOLUTE_P SignedIconst opt_from_in cursor_name
4966 FetchStmt *n = makeNode(FetchStmt);
4968 n->direction = FETCH_ABSOLUTE;
4972 | RELATIVE_P SignedIconst opt_from_in cursor_name
4974 FetchStmt *n = makeNode(FetchStmt);
4976 n->direction = FETCH_RELATIVE;
4980 | SignedIconst opt_from_in cursor_name
4982 FetchStmt *n = makeNode(FetchStmt);
4984 n->direction = FETCH_FORWARD;
4988 | ALL opt_from_in cursor_name
4990 FetchStmt *n = makeNode(FetchStmt);
4992 n->direction = FETCH_FORWARD;
4993 n->howMany = FETCH_ALL;
4996 | FORWARD opt_from_in cursor_name
4998 FetchStmt *n = makeNode(FetchStmt);
5000 n->direction = FETCH_FORWARD;
5004 | FORWARD SignedIconst opt_from_in cursor_name
5006 FetchStmt *n = makeNode(FetchStmt);
5008 n->direction = FETCH_FORWARD;
5012 | FORWARD ALL opt_from_in cursor_name
5014 FetchStmt *n = makeNode(FetchStmt);
5016 n->direction = FETCH_FORWARD;
5017 n->howMany = FETCH_ALL;
5020 | BACKWARD opt_from_in cursor_name
5022 FetchStmt *n = makeNode(FetchStmt);
5024 n->direction = FETCH_BACKWARD;
5028 | BACKWARD SignedIconst opt_from_in cursor_name
5030 FetchStmt *n = makeNode(FetchStmt);
5032 n->direction = FETCH_BACKWARD;
5036 | BACKWARD ALL opt_from_in cursor_name
5038 FetchStmt *n = makeNode(FetchStmt);
5040 n->direction = FETCH_BACKWARD;
5041 n->howMany = FETCH_ALL;
5050 opt_from_in: from_in {}
5055 /*****************************************************************************
5057 * GRANT and REVOKE statements
5059 *****************************************************************************/
5061 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
5062 opt_grant_grant_option
5064 GrantStmt *n = makeNode(GrantStmt);
5067 n->targtype = ($4)->targtype;
5068 n->objtype = ($4)->objtype;
5069 n->objects = ($4)->objs;
5071 n->grant_option = $7;
5077 REVOKE privileges ON privilege_target
5078 FROM grantee_list opt_drop_behavior
5080 GrantStmt *n = makeNode(GrantStmt);
5081 n->is_grant = false;
5082 n->grant_option = false;
5084 n->targtype = ($4)->targtype;
5085 n->objtype = ($4)->objtype;
5086 n->objects = ($4)->objs;
5091 | REVOKE GRANT OPTION FOR privileges ON privilege_target
5092 FROM grantee_list opt_drop_behavior
5094 GrantStmt *n = makeNode(GrantStmt);
5095 n->is_grant = false;
5096 n->grant_option = true;
5098 n->targtype = ($7)->targtype;
5099 n->objtype = ($7)->objtype;
5100 n->objects = ($7)->objs;
5109 * Privilege names are represented as strings; the validity of the privilege
5110 * names gets checked at execution. This is a bit annoying but we have little
5111 * choice because of the syntactic conflict with lists of role names in
5112 * GRANT/REVOKE. What's more, we have to call out in the "privilege"
5113 * production any reserved keywords that need to be usable as privilege names.
5116 /* either ALL [PRIVILEGES] or a list of individual privileges */
5117 privileges: privilege_list
5123 | ALL '(' columnList ')'
5125 AccessPriv *n = makeNode(AccessPriv);
5126 n->priv_name = NULL;
5130 | ALL PRIVILEGES '(' columnList ')'
5132 AccessPriv *n = makeNode(AccessPriv);
5133 n->priv_name = NULL;
5139 privilege_list: privilege { $$ = list_make1($1); }
5140 | privilege_list ',' privilege { $$ = lappend($1, $3); }
5143 privilege: SELECT opt_column_list
5145 AccessPriv *n = makeNode(AccessPriv);
5146 n->priv_name = pstrdup($1);
5150 | REFERENCES opt_column_list
5152 AccessPriv *n = makeNode(AccessPriv);
5153 n->priv_name = pstrdup($1);
5157 | CREATE opt_column_list
5159 AccessPriv *n = makeNode(AccessPriv);
5160 n->priv_name = pstrdup($1);
5164 | ColId opt_column_list
5166 AccessPriv *n = makeNode(AccessPriv);
5174 /* Don't bother trying to fold the first two rules into one using
5175 * opt_table. You're going to get conflicts.
5180 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5181 n->targtype = ACL_TARGET_OBJECT;
5182 n->objtype = ACL_OBJECT_RELATION;
5186 | TABLE qualified_name_list
5188 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5189 n->targtype = ACL_TARGET_OBJECT;
5190 n->objtype = ACL_OBJECT_RELATION;
5194 | SEQUENCE qualified_name_list
5196 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5197 n->targtype = ACL_TARGET_OBJECT;
5198 n->objtype = ACL_OBJECT_SEQUENCE;
5202 | FOREIGN DATA_P WRAPPER name_list
5204 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5205 n->targtype = ACL_TARGET_OBJECT;
5206 n->objtype = ACL_OBJECT_FDW;
5210 | FOREIGN SERVER name_list
5212 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5213 n->targtype = ACL_TARGET_OBJECT;
5214 n->objtype = ACL_OBJECT_FOREIGN_SERVER;
5218 | FOREIGN TABLE qualified_name_list
5220 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5221 n->targtype = ACL_TARGET_OBJECT;
5222 n->objtype = ACL_OBJECT_FOREIGN_TABLE;
5226 | FUNCTION function_with_argtypes_list
5228 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5229 n->targtype = ACL_TARGET_OBJECT;
5230 n->objtype = ACL_OBJECT_FUNCTION;
5234 | DATABASE name_list
5236 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5237 n->targtype = ACL_TARGET_OBJECT;
5238 n->objtype = ACL_OBJECT_DATABASE;
5242 | LANGUAGE name_list
5244 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5245 n->targtype = ACL_TARGET_OBJECT;
5246 n->objtype = ACL_OBJECT_LANGUAGE;
5250 | LARGE_P OBJECT_P NumericOnly_list
5252 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5253 n->targtype = ACL_TARGET_OBJECT;
5254 n->objtype = ACL_OBJECT_LARGEOBJECT;
5260 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5261 n->targtype = ACL_TARGET_OBJECT;
5262 n->objtype = ACL_OBJECT_NAMESPACE;
5266 | TABLESPACE name_list
5268 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5269 n->targtype = ACL_TARGET_OBJECT;
5270 n->objtype = ACL_OBJECT_TABLESPACE;
5274 | ALL TABLES IN_P SCHEMA name_list
5276 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5277 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
5278 n->objtype = ACL_OBJECT_RELATION;
5282 | ALL SEQUENCES IN_P SCHEMA name_list
5284 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5285 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
5286 n->objtype = ACL_OBJECT_SEQUENCE;
5290 | ALL FUNCTIONS IN_P SCHEMA name_list
5292 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
5293 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
5294 n->objtype = ACL_OBJECT_FUNCTION;
5302 grantee { $$ = list_make1($1); }
5303 | grantee_list ',' grantee { $$ = lappend($1, $3); }
5308 PrivGrantee *n = makeNode(PrivGrantee);
5309 /* This hack lets us avoid reserving PUBLIC as a keyword*/
5310 if (strcmp($1, "public") == 0)
5318 PrivGrantee *n = makeNode(PrivGrantee);
5319 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
5320 if (strcmp($2, "public") == 0)
5329 opt_grant_grant_option:
5330 WITH GRANT OPTION { $$ = TRUE; }
5331 | /*EMPTY*/ { $$ = FALSE; }
5334 function_with_argtypes_list:
5335 function_with_argtypes { $$ = list_make1($1); }
5336 | function_with_argtypes_list ',' function_with_argtypes
5337 { $$ = lappend($1, $3); }
5340 function_with_argtypes:
5343 FuncWithArgs *n = makeNode(FuncWithArgs);
5345 n->funcargs = extractArgTypes($2);
5350 /*****************************************************************************
5352 * GRANT and REVOKE ROLE statements
5354 *****************************************************************************/
5357 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
5359 GrantRoleStmt *n = makeNode(GrantRoleStmt);
5361 n->granted_roles = $2;
5362 n->grantee_roles = $4;
5370 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
5372 GrantRoleStmt *n = makeNode(GrantRoleStmt);
5373 n->is_grant = false;
5374 n->admin_opt = false;
5375 n->granted_roles = $2;
5376 n->grantee_roles = $4;
5380 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
5382 GrantRoleStmt *n = makeNode(GrantRoleStmt);
5383 n->is_grant = false;
5384 n->admin_opt = true;
5385 n->granted_roles = $5;
5386 n->grantee_roles = $7;
5392 opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
5393 | /*EMPTY*/ { $$ = FALSE; }
5396 opt_granted_by: GRANTED BY RoleId { $$ = $3; }
5397 | /*EMPTY*/ { $$ = NULL; }
5400 /*****************************************************************************
5402 * ALTER DEFAULT PRIVILEGES statement
5404 *****************************************************************************/
5406 AlterDefaultPrivilegesStmt:
5407 ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
5409 AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
5411 n->action = (GrantStmt *) $5;
5417 DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
5418 | /* EMPTY */ { $$ = NIL; }
5422 IN_P SCHEMA name_list
5424 $$ = makeDefElem("schemas", (Node *)$3);
5426 | FOR ROLE name_list
5428 $$ = makeDefElem("roles", (Node *)$3);
5430 | FOR USER name_list
5432 $$ = makeDefElem("roles", (Node *)$3);
5437 * This should match GRANT/REVOKE, except that individual target objects
5438 * are not mentioned and we only allow a subset of object types.
5441 GRANT privileges ON defacl_privilege_target TO grantee_list
5442 opt_grant_grant_option
5444 GrantStmt *n = makeNode(GrantStmt);
5447 n->targtype = ACL_TARGET_DEFAULTS;
5451 n->grant_option = $7;
5454 | REVOKE privileges ON defacl_privilege_target
5455 FROM grantee_list opt_drop_behavior
5457 GrantStmt *n = makeNode(GrantStmt);
5458 n->is_grant = false;
5459 n->grant_option = false;
5461 n->targtype = ACL_TARGET_DEFAULTS;
5468 | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
5469 FROM grantee_list opt_drop_behavior
5471 GrantStmt *n = makeNode(GrantStmt);
5472 n->is_grant = false;
5473 n->grant_option = true;
5475 n->targtype = ACL_TARGET_DEFAULTS;
5484 defacl_privilege_target:
5485 TABLES { $$ = ACL_OBJECT_RELATION; }
5486 | FUNCTIONS { $$ = ACL_OBJECT_FUNCTION; }
5487 | SEQUENCES { $$ = ACL_OBJECT_SEQUENCE; }
5491 /*****************************************************************************
5493 * QUERY: CREATE INDEX
5495 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
5496 * willing to make TABLESPACE a fully reserved word.
5497 *****************************************************************************/
5499 IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_index_name
5500 ON qualified_name access_method_clause '(' index_params ')'
5501 opt_reloptions OptTableSpace where_clause
5503 IndexStmt *n = makeNode(IndexStmt);
5508 n->accessMethod = $8;
5509 n->indexParams = $10;
5511 n->tableSpace = $13;
5512 n->whereClause = $14;
5513 n->indexOid = InvalidOid;
5519 UNIQUE { $$ = TRUE; }
5520 | /*EMPTY*/ { $$ = FALSE; }
5524 CONCURRENTLY { $$ = TRUE; }
5525 | /*EMPTY*/ { $$ = FALSE; }
5529 index_name { $$ = $1; }
5530 | /*EMPTY*/ { $$ = NULL; }
5533 access_method_clause:
5534 USING access_method { $$ = $2; }
5535 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
5538 index_params: index_elem { $$ = list_make1($1); }
5539 | index_params ',' index_elem { $$ = lappend($1, $3); }
5543 * Index attributes can be either simple column references, or arbitrary
5544 * expressions in parens. For backwards-compatibility reasons, we allow
5545 * an expression that's just a function call to be written without parens.
5547 index_elem: ColId opt_collate opt_class opt_asc_desc opt_nulls_order
5549 $$ = makeNode(IndexElem);
5552 $$->indexcolname = NULL;
5556 $$->nulls_ordering = $5;
5558 | func_expr opt_collate opt_class opt_asc_desc opt_nulls_order
5560 $$ = makeNode(IndexElem);
5563 $$->indexcolname = NULL;
5567 $$->nulls_ordering = $5;
5569 | '(' a_expr ')' opt_collate opt_class opt_asc_desc opt_nulls_order
5571 $$ = makeNode(IndexElem);
5574 $$->indexcolname = NULL;
5578 $$->nulls_ordering = $7;
5582 opt_collate: COLLATE any_name { $$ = $2; }
5583 | /*EMPTY*/ { $$ = NIL; }
5586 opt_class: any_name { $$ = $1; }
5587 | USING any_name { $$ = $2; }
5588 | /*EMPTY*/ { $$ = NIL; }
5591 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
5592 | DESC { $$ = SORTBY_DESC; }
5593 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
5596 opt_nulls_order: NULLS_FIRST { $$ = SORTBY_NULLS_FIRST; }
5597 | NULLS_LAST { $$ = SORTBY_NULLS_LAST; }
5598 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
5602 /*****************************************************************************
5605 * create [or replace] function <fname>
5606 * [(<type-1> { , <type-n>})]
5608 * as <filename or code in language as appropriate>
5609 * language <lang> [with parameters]
5611 *****************************************************************************/
5614 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5615 RETURNS func_return createfunc_opt_list opt_definition
5617 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5626 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5627 RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
5629 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5632 n->parameters = mergeTableFuncParameters($5, $9);
5633 n->returnType = TableFuncTypeName($9);
5634 n->returnType->location = @7;
5636 n->withClause = $12;
5639 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5640 createfunc_opt_list opt_definition
5642 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5646 n->returnType = NULL;
5654 OR REPLACE { $$ = TRUE; }
5655 | /*EMPTY*/ { $$ = FALSE; }
5658 func_args: '(' func_args_list ')' { $$ = $2; }
5659 | '(' ')' { $$ = NIL; }
5663 func_arg { $$ = list_make1($1); }
5664 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
5668 * func_args_with_defaults is separate because we only want to accept
5669 * defaults in CREATE FUNCTION, not in ALTER etc.
5671 func_args_with_defaults:
5672 '(' func_args_with_defaults_list ')' { $$ = $2; }
5673 | '(' ')' { $$ = NIL; }
5676 func_args_with_defaults_list:
5677 func_arg_with_default { $$ = list_make1($1); }
5678 | func_args_with_defaults_list ',' func_arg_with_default
5679 { $$ = lappend($1, $3); }
5683 * The style with arg_class first is SQL99 standard, but Oracle puts
5684 * param_name first; accept both since it's likely people will try both
5685 * anyway. Don't bother trying to save productions by letting arg_class
5686 * have an empty alternative ... you'll get shift/reduce conflicts.
5688 * We can catch over-specified arguments here if we want to,
5689 * but for now better to silently swallow typmod, etc.
5690 * - thomas 2000-03-22
5693 arg_class param_name func_type
5695 FunctionParameter *n = makeNode(FunctionParameter);
5702 | param_name arg_class func_type
5704 FunctionParameter *n = makeNode(FunctionParameter);
5711 | param_name func_type
5713 FunctionParameter *n = makeNode(FunctionParameter);
5716 n->mode = FUNC_PARAM_IN;
5720 | arg_class func_type
5722 FunctionParameter *n = makeNode(FunctionParameter);
5731 FunctionParameter *n = makeNode(FunctionParameter);
5734 n->mode = FUNC_PARAM_IN;
5740 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
5741 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
5742 | OUT_P { $$ = FUNC_PARAM_OUT; }
5743 | INOUT { $$ = FUNC_PARAM_INOUT; }
5744 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
5745 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
5749 * Ideally param_name should be ColId, but that causes too many conflicts.
5751 param_name: type_function_name
5757 /* We can catch over-specified results here if we want to,
5758 * but for now better to silently swallow typmod, etc.
5759 * - thomas 2000-03-22
5766 * We would like to make the %TYPE productions here be ColId attrs etc,
5767 * but that causes reduce/reduce conflicts. type_function_name
5768 * is next best choice.
5770 func_type: Typename { $$ = $1; }
5771 | type_function_name attrs '%' TYPE_P
5773 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
5774 $$->pct_type = true;
5777 | SETOF type_function_name attrs '%' TYPE_P
5779 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
5780 $$->pct_type = true;
5786 func_arg_with_default:
5791 | func_arg DEFAULT a_expr
5796 | func_arg '=' a_expr
5804 createfunc_opt_list:
5805 /* Must be at least one to prevent conflict */
5806 createfunc_opt_item { $$ = list_make1($1); }
5807 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
5811 * Options common to both CREATE FUNCTION and ALTER FUNCTION
5813 common_func_opt_item:
5814 CALLED ON NULL_P INPUT_P
5816 $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
5818 | RETURNS NULL_P ON NULL_P INPUT_P
5820 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5824 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5828 $$ = makeDefElem("volatility", (Node *)makeString("immutable"));
5832 $$ = makeDefElem("volatility", (Node *)makeString("stable"));
5836 $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
5838 | EXTERNAL SECURITY DEFINER
5840 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5842 | EXTERNAL SECURITY INVOKER
5844 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5848 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5852 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5856 $$ = makeDefElem("cost", (Node *)$2);
5860 $$ = makeDefElem("rows", (Node *)$2);
5864 /* we abuse the normal content of a DefElem here */
5865 $$ = makeDefElem("set", (Node *)$1);
5869 createfunc_opt_item:
5872 $$ = makeDefElem("as", (Node *)$2);
5874 | LANGUAGE ColId_or_Sconst
5876 $$ = makeDefElem("language", (Node *)makeString($2));
5880 $$ = makeDefElem("window", (Node *)makeInteger(TRUE));
5882 | common_func_opt_item
5888 func_as: Sconst { $$ = list_make1(makeString($1)); }
5891 $$ = list_make2(makeString($1), makeString($3));
5896 WITH definition { $$ = $2; }
5897 | /*EMPTY*/ { $$ = NIL; }
5900 table_func_column: param_name func_type
5902 FunctionParameter *n = makeNode(FunctionParameter);
5905 n->mode = FUNC_PARAM_TABLE;
5911 table_func_column_list:
5914 $$ = list_make1($1);
5916 | table_func_column_list ',' table_func_column
5918 $$ = lappend($1, $3);
5922 /*****************************************************************************
5925 * RENAME and OWNER subcommands are already provided by the generic
5926 * ALTER infrastructure, here we just specify alterations that can
5927 * only be applied to functions.
5929 *****************************************************************************/
5931 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
5933 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
5941 /* At least one option must be specified */
5942 common_func_opt_item { $$ = list_make1($1); }
5943 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
5946 /* Ignored, merely for SQL compliance */
5953 /*****************************************************************************
5957 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
5958 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
5959 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
5961 *****************************************************************************/
5964 DROP FUNCTION func_name func_args opt_drop_behavior
5966 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5967 n->kind = OBJECT_FUNCTION;
5969 n->args = extractArgTypes($4);
5971 n->missing_ok = false;
5974 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
5976 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5977 n->kind = OBJECT_FUNCTION;
5979 n->args = extractArgTypes($6);
5981 n->missing_ok = true;
5987 DROP AGGREGATE func_name aggr_args opt_drop_behavior
5989 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5990 n->kind = OBJECT_AGGREGATE;
5994 n->missing_ok = false;
5997 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
5999 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
6000 n->kind = OBJECT_AGGREGATE;
6004 n->missing_ok = true;
6010 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
6012 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
6013 n->kind = OBJECT_OPERATOR;
6017 n->missing_ok = false;
6020 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
6022 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
6023 n->kind = OBJECT_OPERATOR;
6027 n->missing_ok = true;
6036 (errcode(ERRCODE_SYNTAX_ERROR),
6037 errmsg("missing argument"),
6038 errhint("Use NONE to denote the missing argument of a unary operator."),
6039 parser_errposition(@3)));
6041 | '(' Typename ',' Typename ')'
6042 { $$ = list_make2($2, $4); }
6043 | '(' NONE ',' Typename ')' /* left unary */
6044 { $$ = list_make2(NULL, $4); }
6045 | '(' Typename ',' NONE ')' /* right unary */
6046 { $$ = list_make2($2, NULL); }
6051 { $$ = list_make1(makeString($1)); }
6052 | ColId '.' any_operator
6053 { $$ = lcons(makeString($1), $3); }
6056 /*****************************************************************************
6058 * DO <anonymous code block> [ LANGUAGE language ]
6060 * We use a DefElem list for future extensibility, and to allow flexibility
6061 * in the clause order.
6063 *****************************************************************************/
6065 DoStmt: DO dostmt_opt_list
6067 DoStmt *n = makeNode(DoStmt);
6074 dostmt_opt_item { $$ = list_make1($1); }
6075 | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
6081 $$ = makeDefElem("as", (Node *)makeString($1));
6083 | LANGUAGE ColId_or_Sconst
6085 $$ = makeDefElem("language", (Node *)makeString($2));
6089 /*****************************************************************************
6091 * CREATE CAST / DROP CAST
6093 *****************************************************************************/
6095 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
6096 WITH FUNCTION function_with_argtypes cast_context
6098 CreateCastStmt *n = makeNode(CreateCastStmt);
6102 n->context = (CoercionContext) $11;
6106 | CREATE CAST '(' Typename AS Typename ')'
6107 WITHOUT FUNCTION cast_context
6109 CreateCastStmt *n = makeNode(CreateCastStmt);
6113 n->context = (CoercionContext) $10;
6117 | CREATE CAST '(' Typename AS Typename ')'
6118 WITH INOUT cast_context
6120 CreateCastStmt *n = makeNode(CreateCastStmt);
6124 n->context = (CoercionContext) $10;
6130 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
6131 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
6132 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
6136 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
6138 DropCastStmt *n = makeNode(DropCastStmt);
6147 opt_if_exists: IF_P EXISTS { $$ = TRUE; }
6148 | /*EMPTY*/ { $$ = FALSE; }
6152 /*****************************************************************************
6156 * REINDEX type <name> [FORCE]
6158 * FORCE no longer does anything, but we accept it for backwards compatibility
6159 *****************************************************************************/
6162 REINDEX reindex_type qualified_name opt_force
6164 ReindexStmt *n = makeNode(ReindexStmt);
6170 | REINDEX SYSTEM_P name opt_force
6172 ReindexStmt *n = makeNode(ReindexStmt);
6173 n->kind = OBJECT_DATABASE;
6176 n->do_system = true;
6180 | REINDEX DATABASE name opt_force
6182 ReindexStmt *n = makeNode(ReindexStmt);
6183 n->kind = OBJECT_DATABASE;
6186 n->do_system = true;
6193 INDEX { $$ = OBJECT_INDEX; }
6194 | TABLE { $$ = OBJECT_TABLE; }
6197 opt_force: FORCE { $$ = TRUE; }
6198 | /* EMPTY */ { $$ = FALSE; }
6202 /*****************************************************************************
6204 * ALTER THING name RENAME TO newname
6206 *****************************************************************************/
6208 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
6210 RenameStmt *n = makeNode(RenameStmt);
6211 n->renameType = OBJECT_AGGREGATE;
6217 | ALTER CONVERSION_P any_name RENAME TO name
6219 RenameStmt *n = makeNode(RenameStmt);
6220 n->renameType = OBJECT_CONVERSION;
6225 | ALTER DATABASE database_name RENAME TO database_name
6227 RenameStmt *n = makeNode(RenameStmt);
6228 n->renameType = OBJECT_DATABASE;
6233 | ALTER FUNCTION function_with_argtypes RENAME TO name
6235 RenameStmt *n = makeNode(RenameStmt);
6236 n->renameType = OBJECT_FUNCTION;
6237 n->object = $3->funcname;
6238 n->objarg = $3->funcargs;
6242 | ALTER GROUP_P RoleId RENAME TO RoleId
6244 RenameStmt *n = makeNode(RenameStmt);
6245 n->renameType = OBJECT_ROLE;
6250 | ALTER opt_procedural LANGUAGE name RENAME TO name
6252 RenameStmt *n = makeNode(RenameStmt);
6253 n->renameType = OBJECT_LANGUAGE;
6258 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
6260 RenameStmt *n = makeNode(RenameStmt);
6261 n->renameType = OBJECT_OPCLASS;
6267 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
6269 RenameStmt *n = makeNode(RenameStmt);
6270 n->renameType = OBJECT_OPFAMILY;
6276 | ALTER SCHEMA name RENAME TO name
6278 RenameStmt *n = makeNode(RenameStmt);
6279 n->renameType = OBJECT_SCHEMA;
6284 | ALTER TABLE relation_expr RENAME TO name
6286 RenameStmt *n = makeNode(RenameStmt);
6287 n->renameType = OBJECT_TABLE;
6293 | ALTER SEQUENCE qualified_name RENAME TO name
6295 RenameStmt *n = makeNode(RenameStmt);
6296 n->renameType = OBJECT_SEQUENCE;
6302 | ALTER VIEW qualified_name RENAME TO name
6304 RenameStmt *n = makeNode(RenameStmt);
6305 n->renameType = OBJECT_VIEW;
6311 | ALTER INDEX qualified_name RENAME TO name
6313 RenameStmt *n = makeNode(RenameStmt);
6314 n->renameType = OBJECT_INDEX;
6320 | ALTER FOREIGN TABLE relation_expr RENAME TO name
6322 RenameStmt *n = makeNode(RenameStmt);
6323 n->renameType = OBJECT_FOREIGN_TABLE;
6329 | ALTER TABLE relation_expr RENAME opt_column name TO name
6331 RenameStmt *n = makeNode(RenameStmt);
6332 n->renameType = OBJECT_COLUMN;
6333 n->relationType = OBJECT_TABLE;
6339 | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
6341 RenameStmt *n = makeNode(RenameStmt);
6342 n->renameType = OBJECT_COLUMN;
6343 n->relationType = OBJECT_FOREIGN_TABLE;
6349 | ALTER TRIGGER name ON qualified_name RENAME TO name
6351 RenameStmt *n = makeNode(RenameStmt);
6352 n->renameType = OBJECT_TRIGGER;
6358 | ALTER ROLE RoleId RENAME TO RoleId
6360 RenameStmt *n = makeNode(RenameStmt);
6361 n->renameType = OBJECT_ROLE;
6366 | ALTER USER RoleId RENAME TO RoleId
6368 RenameStmt *n = makeNode(RenameStmt);
6369 n->renameType = OBJECT_ROLE;
6374 | ALTER TABLESPACE name RENAME TO name
6376 RenameStmt *n = makeNode(RenameStmt);
6377 n->renameType = OBJECT_TABLESPACE;
6382 | ALTER TABLESPACE name SET reloptions
6384 AlterTableSpaceOptionsStmt *n =
6385 makeNode(AlterTableSpaceOptionsStmt);
6386 n->tablespacename = $3;
6391 | ALTER TABLESPACE name RESET reloptions
6393 AlterTableSpaceOptionsStmt *n =
6394 makeNode(AlterTableSpaceOptionsStmt);
6395 n->tablespacename = $3;
6400 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
6402 RenameStmt *n = makeNode(RenameStmt);
6403 n->renameType = OBJECT_TSPARSER;
6408 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
6410 RenameStmt *n = makeNode(RenameStmt);
6411 n->renameType = OBJECT_TSDICTIONARY;
6416 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
6418 RenameStmt *n = makeNode(RenameStmt);
6419 n->renameType = OBJECT_TSTEMPLATE;
6424 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
6426 RenameStmt *n = makeNode(RenameStmt);
6427 n->renameType = OBJECT_TSCONFIGURATION;
6432 | ALTER TYPE_P any_name RENAME TO name
6434 RenameStmt *n = makeNode(RenameStmt);
6435 n->renameType = OBJECT_TYPE;
6440 | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
6442 RenameStmt *n = makeNode(RenameStmt);
6443 n->renameType = OBJECT_ATTRIBUTE;
6444 n->relationType = OBJECT_TYPE;
6445 n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
6453 opt_column: COLUMN { $$ = COLUMN; }
6454 | /*EMPTY*/ { $$ = 0; }
6457 opt_set_data: SET DATA_P { $$ = 1; }
6458 | /*EMPTY*/ { $$ = 0; }
6461 /*****************************************************************************
6463 * ALTER THING name SET SCHEMA name
6465 *****************************************************************************/
6467 AlterObjectSchemaStmt:
6468 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
6470 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6471 n->objectType = OBJECT_AGGREGATE;
6477 | ALTER CONVERSION_P any_name SET SCHEMA name
6479 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6480 n->objectType = OBJECT_CONVERSION;
6485 | ALTER DOMAIN_P any_name SET SCHEMA name
6487 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6488 n->objectType = OBJECT_DOMAIN;
6493 | ALTER EXTENSION any_name SET SCHEMA name
6495 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6496 n->objectType = OBJECT_EXTENSION;
6501 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
6503 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6504 n->objectType = OBJECT_FUNCTION;
6505 n->object = $3->funcname;
6506 n->objarg = $3->funcargs;
6510 | ALTER OPERATOR any_operator oper_argtypes SET SCHEMA name
6512 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6513 n->objectType = OBJECT_OPERATOR;
6519 | ALTER OPERATOR CLASS any_name USING access_method SET SCHEMA name
6521 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6522 n->objectType = OBJECT_OPCLASS;
6528 | ALTER OPERATOR FAMILY any_name USING access_method SET SCHEMA name
6530 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6531 n->objectType = OBJECT_OPFAMILY;
6537 | ALTER TABLE relation_expr SET SCHEMA name
6539 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6540 n->objectType = OBJECT_TABLE;
6545 | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
6547 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6548 n->objectType = OBJECT_TSPARSER;
6553 | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
6555 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6556 n->objectType = OBJECT_TSDICTIONARY;
6561 | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
6563 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6564 n->objectType = OBJECT_TSTEMPLATE;
6569 | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
6571 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6572 n->objectType = OBJECT_TSCONFIGURATION;
6577 | ALTER SEQUENCE qualified_name SET SCHEMA name
6579 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6580 n->objectType = OBJECT_SEQUENCE;
6585 | ALTER VIEW qualified_name SET SCHEMA name
6587 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6588 n->objectType = OBJECT_VIEW;
6593 | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
6595 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6596 n->objectType = OBJECT_FOREIGN_TABLE;
6601 | ALTER TYPE_P any_name SET SCHEMA name
6603 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6604 n->objectType = OBJECT_TYPE;
6611 /*****************************************************************************
6613 * ALTER THING name OWNER TO newname
6615 *****************************************************************************/
6617 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
6619 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6620 n->objectType = OBJECT_AGGREGATE;
6626 | ALTER CONVERSION_P any_name OWNER TO RoleId
6628 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6629 n->objectType = OBJECT_CONVERSION;
6634 | ALTER DATABASE database_name OWNER TO RoleId
6636 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6637 n->objectType = OBJECT_DATABASE;
6638 n->object = list_make1(makeString($3));
6642 | ALTER DOMAIN_P any_name OWNER TO RoleId
6644 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6645 n->objectType = OBJECT_DOMAIN;
6650 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
6652 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6653 n->objectType = OBJECT_FUNCTION;
6654 n->object = $3->funcname;
6655 n->objarg = $3->funcargs;
6659 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
6661 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6662 n->objectType = OBJECT_LANGUAGE;
6663 n->object = list_make1(makeString($4));
6667 | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleId
6669 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6670 n->objectType = OBJECT_LARGEOBJECT;
6671 n->object = list_make1($4);
6675 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
6677 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6678 n->objectType = OBJECT_OPERATOR;
6684 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
6686 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6687 n->objectType = OBJECT_OPCLASS;
6693 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
6695 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6696 n->objectType = OBJECT_OPFAMILY;
6702 | ALTER SCHEMA name OWNER TO RoleId
6704 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6705 n->objectType = OBJECT_SCHEMA;
6706 n->object = list_make1(makeString($3));
6710 | ALTER TYPE_P any_name OWNER TO RoleId
6712 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6713 n->objectType = OBJECT_TYPE;
6718 | ALTER TABLESPACE name OWNER TO RoleId
6720 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6721 n->objectType = OBJECT_TABLESPACE;
6722 n->object = list_make1(makeString($3));
6726 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
6728 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6729 n->objectType = OBJECT_TSDICTIONARY;
6734 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
6736 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6737 n->objectType = OBJECT_TSCONFIGURATION;
6742 | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleId
6744 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6745 n->objectType = OBJECT_FDW;
6746 n->object = list_make1(makeString($5));
6750 | ALTER SERVER name OWNER TO RoleId
6752 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6753 n->objectType = OBJECT_FOREIGN_SERVER;
6754 n->object = list_make1(makeString($3));
6761 /*****************************************************************************
6763 * QUERY: Define Rewrite Rule
6765 *****************************************************************************/
6767 RuleStmt: CREATE opt_or_replace RULE name AS
6768 ON event TO qualified_name where_clause
6769 DO opt_instead RuleActionList
6771 RuleStmt *n = makeNode(RuleStmt);
6775 n->whereClause = $10;
6784 NOTHING { $$ = NIL; }
6785 | RuleActionStmt { $$ = list_make1($1); }
6786 | '(' RuleActionMulti ')' { $$ = $2; }
6789 /* the thrashing around here is to discard "empty" statements... */
6791 RuleActionMulti ';' RuleActionStmtOrEmpty
6793 $$ = lappend($1, $3);
6797 | RuleActionStmtOrEmpty
6799 $$ = list_make1($1);
6813 RuleActionStmtOrEmpty:
6814 RuleActionStmt { $$ = $1; }
6815 | /*EMPTY*/ { $$ = NULL; }
6818 event: SELECT { $$ = CMD_SELECT; }
6819 | UPDATE { $$ = CMD_UPDATE; }
6820 | DELETE_P { $$ = CMD_DELETE; }
6821 | INSERT { $$ = CMD_INSERT; }
6825 INSTEAD { $$ = TRUE; }
6826 | ALSO { $$ = FALSE; }
6827 | /*EMPTY*/ { $$ = FALSE; }
6832 DROP RULE name ON qualified_name opt_drop_behavior
6834 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6838 n->removeType = OBJECT_RULE;
6839 n->missing_ok = false;
6842 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
6844 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6848 n->removeType = OBJECT_RULE;
6849 n->missing_ok = true;
6855 /*****************************************************************************
6858 * NOTIFY <identifier> can appear both in rule bodies and
6859 * as a query-level command
6861 *****************************************************************************/
6863 NotifyStmt: NOTIFY ColId notify_payload
6865 NotifyStmt *n = makeNode(NotifyStmt);
6866 n->conditionname = $2;
6873 ',' Sconst { $$ = $2; }
6874 | /*EMPTY*/ { $$ = NULL; }
6877 ListenStmt: LISTEN ColId
6879 ListenStmt *n = makeNode(ListenStmt);
6880 n->conditionname = $2;
6888 UnlistenStmt *n = makeNode(UnlistenStmt);
6889 n->conditionname = $2;
6894 UnlistenStmt *n = makeNode(UnlistenStmt);
6895 n->conditionname = NULL;
6901 /*****************************************************************************
6905 * BEGIN / COMMIT / ROLLBACK
6906 * (also older versions END / ABORT)
6908 *****************************************************************************/
6911 ABORT_P opt_transaction
6913 TransactionStmt *n = makeNode(TransactionStmt);
6914 n->kind = TRANS_STMT_ROLLBACK;
6918 | BEGIN_P opt_transaction transaction_mode_list_or_empty
6920 TransactionStmt *n = makeNode(TransactionStmt);
6921 n->kind = TRANS_STMT_BEGIN;
6925 | START TRANSACTION transaction_mode_list_or_empty
6927 TransactionStmt *n = makeNode(TransactionStmt);
6928 n->kind = TRANS_STMT_START;
6932 | COMMIT opt_transaction
6934 TransactionStmt *n = makeNode(TransactionStmt);
6935 n->kind = TRANS_STMT_COMMIT;
6939 | END_P opt_transaction
6941 TransactionStmt *n = makeNode(TransactionStmt);
6942 n->kind = TRANS_STMT_COMMIT;
6946 | ROLLBACK opt_transaction
6948 TransactionStmt *n = makeNode(TransactionStmt);
6949 n->kind = TRANS_STMT_ROLLBACK;
6955 TransactionStmt *n = makeNode(TransactionStmt);
6956 n->kind = TRANS_STMT_SAVEPOINT;
6957 n->options = list_make1(makeDefElem("savepoint_name",
6958 (Node *)makeString($2)));
6961 | RELEASE SAVEPOINT ColId
6963 TransactionStmt *n = makeNode(TransactionStmt);
6964 n->kind = TRANS_STMT_RELEASE;
6965 n->options = list_make1(makeDefElem("savepoint_name",
6966 (Node *)makeString($3)));
6971 TransactionStmt *n = makeNode(TransactionStmt);
6972 n->kind = TRANS_STMT_RELEASE;
6973 n->options = list_make1(makeDefElem("savepoint_name",
6974 (Node *)makeString($2)));
6977 | ROLLBACK opt_transaction TO SAVEPOINT ColId
6979 TransactionStmt *n = makeNode(TransactionStmt);
6980 n->kind = TRANS_STMT_ROLLBACK_TO;
6981 n->options = list_make1(makeDefElem("savepoint_name",
6982 (Node *)makeString($5)));
6985 | ROLLBACK opt_transaction TO ColId
6987 TransactionStmt *n = makeNode(TransactionStmt);
6988 n->kind = TRANS_STMT_ROLLBACK_TO;
6989 n->options = list_make1(makeDefElem("savepoint_name",
6990 (Node *)makeString($4)));
6993 | PREPARE TRANSACTION Sconst
6995 TransactionStmt *n = makeNode(TransactionStmt);
6996 n->kind = TRANS_STMT_PREPARE;
7000 | COMMIT PREPARED Sconst
7002 TransactionStmt *n = makeNode(TransactionStmt);
7003 n->kind = TRANS_STMT_COMMIT_PREPARED;
7007 | ROLLBACK PREPARED Sconst
7009 TransactionStmt *n = makeNode(TransactionStmt);
7010 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
7016 opt_transaction: WORK {}
7021 transaction_mode_item:
7022 ISOLATION LEVEL iso_level
7023 { $$ = makeDefElem("transaction_isolation",
7024 makeStringConst($3, @3)); }
7026 { $$ = makeDefElem("transaction_read_only",
7027 makeIntConst(TRUE, @1)); }
7029 { $$ = makeDefElem("transaction_read_only",
7030 makeIntConst(FALSE, @1)); }
7032 { $$ = makeDefElem("transaction_deferrable",
7033 makeIntConst(TRUE, @1)); }
7035 { $$ = makeDefElem("transaction_deferrable",
7036 makeIntConst(FALSE, @1)); }
7039 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
7040 transaction_mode_list:
7041 transaction_mode_item
7042 { $$ = list_make1($1); }
7043 | transaction_mode_list ',' transaction_mode_item
7044 { $$ = lappend($1, $3); }
7045 | transaction_mode_list transaction_mode_item
7046 { $$ = lappend($1, $2); }
7049 transaction_mode_list_or_empty:
7050 transaction_mode_list
7056 /*****************************************************************************
7059 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
7060 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
7062 *****************************************************************************/
7064 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
7065 AS SelectStmt opt_check_option
7067 ViewStmt *n = makeNode(ViewStmt);
7069 n->view->relpersistence = $2;
7075 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
7076 AS SelectStmt opt_check_option
7078 ViewStmt *n = makeNode(ViewStmt);
7080 n->view->relpersistence = $4;
7092 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7093 errmsg("WITH CHECK OPTION is not implemented")));
7095 | WITH CASCADED CHECK OPTION
7098 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7099 errmsg("WITH CHECK OPTION is not implemented")));
7101 | WITH LOCAL CHECK OPTION
7104 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7105 errmsg("WITH CHECK OPTION is not implemented")));
7107 | /* EMPTY */ { $$ = NIL; }
7110 /*****************************************************************************
7115 *****************************************************************************/
7117 LoadStmt: LOAD file_name
7119 LoadStmt *n = makeNode(LoadStmt);
7126 /*****************************************************************************
7130 *****************************************************************************/
7133 CREATE DATABASE database_name opt_with createdb_opt_list
7135 CreatedbStmt *n = makeNode(CreatedbStmt);
7143 createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
7144 | /* EMPTY */ { $$ = NIL; }
7148 TABLESPACE opt_equal name
7150 $$ = makeDefElem("tablespace", (Node *)makeString($3));
7152 | TABLESPACE opt_equal DEFAULT
7154 $$ = makeDefElem("tablespace", NULL);
7156 | LOCATION opt_equal Sconst
7158 $$ = makeDefElem("location", (Node *)makeString($3));
7160 | LOCATION opt_equal DEFAULT
7162 $$ = makeDefElem("location", NULL);
7164 | TEMPLATE opt_equal name
7166 $$ = makeDefElem("template", (Node *)makeString($3));
7168 | TEMPLATE opt_equal DEFAULT
7170 $$ = makeDefElem("template", NULL);
7172 | ENCODING opt_equal Sconst
7174 $$ = makeDefElem("encoding", (Node *)makeString($3));
7176 | ENCODING opt_equal Iconst
7178 $$ = makeDefElem("encoding", (Node *)makeInteger($3));
7180 | ENCODING opt_equal DEFAULT
7182 $$ = makeDefElem("encoding", NULL);
7184 | LC_COLLATE_P opt_equal Sconst
7186 $$ = makeDefElem("lc_collate", (Node *)makeString($3));
7188 | LC_COLLATE_P opt_equal DEFAULT
7190 $$ = makeDefElem("lc_collate", NULL);
7192 | LC_CTYPE_P opt_equal Sconst
7194 $$ = makeDefElem("lc_ctype", (Node *)makeString($3));
7196 | LC_CTYPE_P opt_equal DEFAULT
7198 $$ = makeDefElem("lc_ctype", NULL);
7200 | CONNECTION LIMIT opt_equal SignedIconst
7202 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
7204 | OWNER opt_equal name
7206 $$ = makeDefElem("owner", (Node *)makeString($3));
7208 | OWNER opt_equal DEFAULT
7210 $$ = makeDefElem("owner", NULL);
7215 * Though the equals sign doesn't match other WITH options, pg_dump uses
7216 * equals for backward compatibility, and it doesn't seem worth removing it.
7223 /*****************************************************************************
7227 *****************************************************************************/
7230 ALTER DATABASE database_name opt_with alterdb_opt_list
7232 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
7237 | ALTER DATABASE database_name SET TABLESPACE name
7239 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
7241 n->options = list_make1(makeDefElem("tablespace",
7242 (Node *)makeString($6)));
7247 AlterDatabaseSetStmt:
7248 ALTER DATABASE database_name SetResetClause
7250 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
7259 alterdb_opt_list alterdb_opt_item { $$ = lappend($1, $2); }
7260 | /* EMPTY */ { $$ = NIL; }
7264 CONNECTION LIMIT opt_equal SignedIconst
7266 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
7271 /*****************************************************************************
7273 * DROP DATABASE [ IF EXISTS ]
7275 * This is implicitly CASCADE, no need for drop behavior
7276 *****************************************************************************/
7278 DropdbStmt: DROP DATABASE database_name
7280 DropdbStmt *n = makeNode(DropdbStmt);
7282 n->missing_ok = FALSE;
7285 | DROP DATABASE IF_P EXISTS database_name
7287 DropdbStmt *n = makeNode(DropdbStmt);
7289 n->missing_ok = TRUE;
7295 /*****************************************************************************
7297 * Manipulate a domain
7299 *****************************************************************************/
7302 CREATE DOMAIN_P any_name opt_as Typename ColQualList
7304 CreateDomainStmt *n = makeNode(CreateDomainStmt);
7307 n->constraints = $6;
7313 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
7314 ALTER DOMAIN_P any_name alter_column_default
7316 AlterDomainStmt *n = makeNode(AlterDomainStmt);
7322 /* ALTER DOMAIN <domain> DROP NOT NULL */
7323 | ALTER DOMAIN_P any_name DROP NOT NULL_P
7325 AlterDomainStmt *n = makeNode(AlterDomainStmt);
7330 /* ALTER DOMAIN <domain> SET NOT NULL */
7331 | ALTER DOMAIN_P any_name SET NOT NULL_P
7333 AlterDomainStmt *n = makeNode(AlterDomainStmt);
7338 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
7339 | ALTER DOMAIN_P any_name ADD_P TableConstraint
7341 AlterDomainStmt *n = makeNode(AlterDomainStmt);
7347 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
7348 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
7350 AlterDomainStmt *n = makeNode(AlterDomainStmt);
7364 /*****************************************************************************
7366 * Manipulate a text search dictionary or configuration
7368 *****************************************************************************/
7370 AlterTSDictionaryStmt:
7371 ALTER TEXT_P SEARCH DICTIONARY any_name definition
7373 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
7380 AlterTSConfigurationStmt:
7381 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
7383 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
7387 n->override = false;
7391 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
7393 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
7401 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
7403 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
7406 n->dicts = list_make2($9,$11);
7407 n->override = false;
7411 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
7413 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
7416 n->dicts = list_make2($11,$13);
7417 n->override = false;
7421 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
7423 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
7426 n->missing_ok = false;
7429 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
7431 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
7434 n->missing_ok = true;
7440 /*****************************************************************************
7442 * Manipulate a conversion
7444 * CREATE [DEFAULT] CONVERSION <conversion_name>
7445 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
7447 *****************************************************************************/
7449 CreateConversionStmt:
7450 CREATE opt_default CONVERSION_P any_name FOR Sconst
7451 TO Sconst FROM any_name
7453 CreateConversionStmt *n = makeNode(CreateConversionStmt);
7454 n->conversion_name = $4;
7455 n->for_encoding_name = $6;
7456 n->to_encoding_name = $8;
7463 /*****************************************************************************
7466 * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
7468 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
7470 *****************************************************************************/
7473 CLUSTER opt_verbose qualified_name cluster_index_specification
7475 ClusterStmt *n = makeNode(ClusterStmt);
7481 | CLUSTER opt_verbose
7483 ClusterStmt *n = makeNode(ClusterStmt);
7485 n->indexname = NULL;
7489 /* kept for pre-8.3 compatibility */
7490 | CLUSTER opt_verbose index_name ON qualified_name
7492 ClusterStmt *n = makeNode(ClusterStmt);
7500 cluster_index_specification:
7501 USING index_name { $$ = $2; }
7502 | /*EMPTY*/ { $$ = NULL; }
7506 /*****************************************************************************
7512 *****************************************************************************/
7514 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
7516 VacuumStmt *n = makeNode(VacuumStmt);
7517 n->options = VACOPT_VACUUM;
7519 n->options |= VACOPT_FULL;
7521 n->options |= VACOPT_VERBOSE;
7522 n->freeze_min_age = $3 ? 0 : -1;
7523 n->freeze_table_age = $3 ? 0 : -1;
7528 | VACUUM opt_full opt_freeze opt_verbose qualified_name
7530 VacuumStmt *n = makeNode(VacuumStmt);
7531 n->options = VACOPT_VACUUM;
7533 n->options |= VACOPT_FULL;
7535 n->options |= VACOPT_VERBOSE;
7536 n->freeze_min_age = $3 ? 0 : -1;
7537 n->freeze_table_age = $3 ? 0 : -1;
7542 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
7544 VacuumStmt *n = (VacuumStmt *) $5;
7545 n->options |= VACOPT_VACUUM;
7547 n->options |= VACOPT_FULL;
7549 n->options |= VACOPT_VERBOSE;
7550 n->freeze_min_age = $3 ? 0 : -1;
7551 n->freeze_table_age = $3 ? 0 : -1;
7554 | VACUUM '(' vacuum_option_list ')'
7556 VacuumStmt *n = makeNode(VacuumStmt);
7557 n->options = VACOPT_VACUUM | $3;
7558 if (n->options & VACOPT_FREEZE)
7559 n->freeze_min_age = n->freeze_table_age = 0;
7561 n->freeze_min_age = n->freeze_table_age = -1;
7566 | VACUUM '(' vacuum_option_list ')' qualified_name opt_name_list
7568 VacuumStmt *n = makeNode(VacuumStmt);
7569 n->options = VACOPT_VACUUM | $3;
7570 if (n->options & VACOPT_FREEZE)
7571 n->freeze_min_age = n->freeze_table_age = 0;
7573 n->freeze_min_age = n->freeze_table_age = -1;
7576 if (n->va_cols != NIL) /* implies analyze */
7577 n->options |= VACOPT_ANALYZE;
7583 vacuum_option_elem { $$ = $1; }
7584 | vacuum_option_list ',' vacuum_option_elem { $$ = $1 | $3; }
7588 analyze_keyword { $$ = VACOPT_ANALYZE; }
7589 | VERBOSE { $$ = VACOPT_VERBOSE; }
7590 | FREEZE { $$ = VACOPT_FREEZE; }
7591 | FULL { $$ = VACOPT_FULL; }
7595 analyze_keyword opt_verbose
7597 VacuumStmt *n = makeNode(VacuumStmt);
7598 n->options = VACOPT_ANALYZE;
7600 n->options |= VACOPT_VERBOSE;
7601 n->freeze_min_age = -1;
7602 n->freeze_table_age = -1;
7607 | analyze_keyword opt_verbose qualified_name opt_name_list
7609 VacuumStmt *n = makeNode(VacuumStmt);
7610 n->options = VACOPT_ANALYZE;
7612 n->options |= VACOPT_VERBOSE;
7613 n->freeze_min_age = -1;
7614 n->freeze_table_age = -1;
7623 | ANALYSE /* British */ {}
7627 VERBOSE { $$ = TRUE; }
7628 | /*EMPTY*/ { $$ = FALSE; }
7631 opt_full: FULL { $$ = TRUE; }
7632 | /*EMPTY*/ { $$ = FALSE; }
7635 opt_freeze: FREEZE { $$ = TRUE; }
7636 | /*EMPTY*/ { $$ = FALSE; }
7640 '(' name_list ')' { $$ = $2; }
7641 | /*EMPTY*/ { $$ = NIL; }
7645 /*****************************************************************************
7648 * EXPLAIN [ANALYZE] [VERBOSE] query
7649 * EXPLAIN ( options ) query
7651 *****************************************************************************/
7654 EXPLAIN ExplainableStmt
7656 ExplainStmt *n = makeNode(ExplainStmt);
7661 | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
7663 ExplainStmt *n = makeNode(ExplainStmt);
7665 n->options = list_make1(makeDefElem("analyze", NULL));
7667 n->options = lappend(n->options,
7668 makeDefElem("verbose", NULL));
7671 | EXPLAIN VERBOSE ExplainableStmt
7673 ExplainStmt *n = makeNode(ExplainStmt);
7675 n->options = list_make1(makeDefElem("verbose", NULL));
7678 | EXPLAIN '(' explain_option_list ')' ExplainableStmt
7680 ExplainStmt *n = makeNode(ExplainStmt);
7694 | ExecuteStmt /* by default all are $$=$1 */
7697 explain_option_list:
7700 $$ = list_make1($1);
7702 | explain_option_list ',' explain_option_elem
7704 $$ = lappend($1, $3);
7708 explain_option_elem:
7709 explain_option_name explain_option_arg
7711 $$ = makeDefElem($1, $2);
7715 explain_option_name:
7717 | analyze_keyword { $$ = "analyze"; }
7718 | VERBOSE { $$ = "verbose"; }
7722 opt_boolean_or_string { $$ = (Node *) makeString($1); }
7723 | NumericOnly { $$ = (Node *) $1; }
7724 | /* EMPTY */ { $$ = NULL; }
7727 /*****************************************************************************
7730 * PREPARE <plan_name> [(args, ...)] AS <query>
7732 *****************************************************************************/
7734 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
7736 PrepareStmt *n = makeNode(PrepareStmt);
7744 prep_type_clause: '(' type_list ')' { $$ = $2; }
7745 | /* EMPTY */ { $$ = NIL; }
7752 | DeleteStmt /* by default all are $$=$1 */
7755 /*****************************************************************************
7757 * EXECUTE <plan_name> [(params, ...)]
7758 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
7760 *****************************************************************************/
7762 ExecuteStmt: EXECUTE name execute_param_clause
7764 ExecuteStmt *n = makeNode(ExecuteStmt);
7770 | CREATE OptTemp TABLE create_as_target AS
7771 EXECUTE name execute_param_clause
7773 ExecuteStmt *n = makeNode(ExecuteStmt);
7776 $4->rel->relpersistence = $2;
7780 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7781 errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
7782 /* ... because it's not implemented, but it could be */
7787 execute_param_clause: '(' expr_list ')' { $$ = $2; }
7788 | /* EMPTY */ { $$ = NIL; }
7791 /*****************************************************************************
7794 * DEALLOCATE [PREPARE] <plan_name>
7796 *****************************************************************************/
7798 DeallocateStmt: DEALLOCATE name
7800 DeallocateStmt *n = makeNode(DeallocateStmt);
7804 | DEALLOCATE PREPARE name
7806 DeallocateStmt *n = makeNode(DeallocateStmt);
7812 DeallocateStmt *n = makeNode(DeallocateStmt);
7816 | DEALLOCATE PREPARE ALL
7818 DeallocateStmt *n = makeNode(DeallocateStmt);
7824 /*****************************************************************************
7829 *****************************************************************************/
7832 opt_with_clause INSERT INTO qualified_name insert_rest returning_clause
7835 $5->returningList = $6;
7836 $5->withClause = $1;
7844 $$ = makeNode(InsertStmt);
7846 $$->selectStmt = $1;
7848 | '(' insert_column_list ')' SelectStmt
7850 $$ = makeNode(InsertStmt);
7852 $$->selectStmt = $4;
7856 $$ = makeNode(InsertStmt);
7858 $$->selectStmt = NULL;
7864 { $$ = list_make1($1); }
7865 | insert_column_list ',' insert_column_item
7866 { $$ = lappend($1, $3); }
7870 ColId opt_indirection
7872 $$ = makeNode(ResTarget);
7874 $$->indirection = check_indirection($2, yyscanner);
7881 RETURNING target_list { $$ = $2; }
7882 | /* EMPTY */ { $$ = NIL; }
7886 /*****************************************************************************
7891 *****************************************************************************/
7893 DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
7894 using_clause where_or_current_clause returning_clause
7896 DeleteStmt *n = makeNode(DeleteStmt);
7898 n->usingClause = $5;
7899 n->whereClause = $6;
7900 n->returningList = $7;
7907 USING from_list { $$ = $2; }
7908 | /*EMPTY*/ { $$ = NIL; }
7912 /*****************************************************************************
7917 *****************************************************************************/
7919 LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
7921 LockStmt *n = makeNode(LockStmt);
7930 opt_lock: IN_P lock_type MODE { $$ = $2; }
7931 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
7934 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
7935 | ROW SHARE { $$ = RowShareLock; }
7936 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
7937 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
7938 | SHARE { $$ = ShareLock; }
7939 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
7940 | EXCLUSIVE { $$ = ExclusiveLock; }
7941 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
7944 opt_nowait: NOWAIT { $$ = TRUE; }
7945 | /*EMPTY*/ { $$ = FALSE; }
7949 /*****************************************************************************
7952 * UpdateStmt (UPDATE)
7954 *****************************************************************************/
7956 UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
7959 where_or_current_clause
7962 UpdateStmt *n = makeNode(UpdateStmt);
7966 n->whereClause = $7;
7967 n->returningList = $8;
7974 set_clause { $$ = $1; }
7975 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
7979 single_set_clause { $$ = list_make1($1); }
7980 | multiple_set_clause { $$ = $1; }
7984 set_target '=' ctext_expr
7987 $$->val = (Node *) $3;
7991 multiple_set_clause:
7992 '(' set_target_list ')' '=' ctext_row
7998 * Break the ctext_row apart, merge individual expressions
7999 * into the destination ResTargets. XXX this approach
8000 * cannot work for general row expressions as sources.
8002 if (list_length($2) != list_length($5))
8004 (errcode(ERRCODE_SYNTAX_ERROR),
8005 errmsg("number of columns does not match number of values"),
8006 parser_errposition(@1)));
8007 forboth(col_cell, $2, val_cell, $5)
8009 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
8010 Node *res_val = (Node *) lfirst(val_cell);
8012 res_col->val = res_val;
8020 ColId opt_indirection
8022 $$ = makeNode(ResTarget);
8024 $$->indirection = check_indirection($2, yyscanner);
8025 $$->val = NULL; /* upper production sets this */
8031 set_target { $$ = list_make1($1); }
8032 | set_target_list ',' set_target { $$ = lappend($1,$3); }
8036 /*****************************************************************************
8041 *****************************************************************************/
8042 DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
8044 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
8046 /* currently we always set FAST_PLAN option */
8047 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
8053 cursor_name: name { $$ = $1; }
8056 cursor_options: /*EMPTY*/ { $$ = 0; }
8057 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
8058 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
8059 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
8060 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
8063 opt_hold: /* EMPTY */ { $$ = 0; }
8064 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
8065 | WITHOUT HOLD { $$ = 0; }
8068 /*****************************************************************************
8073 *****************************************************************************/
8075 /* A complete SELECT statement looks like this.
8077 * The rule returns either a single SelectStmt node or a tree of them,
8078 * representing a set-operation tree.
8080 * There is an ambiguity when a sub-SELECT is within an a_expr and there
8081 * are excess parentheses: do the parentheses belong to the sub-SELECT or
8082 * to the surrounding a_expr? We don't really care, but bison wants to know.
8083 * To resolve the ambiguity, we are careful to define the grammar so that
8084 * the decision is staved off as long as possible: as long as we can keep
8085 * absorbing parentheses into the sub-SELECT, we will do so, and only when
8086 * it's no longer possible to do that will we decide that parens belong to
8087 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
8088 * parentheses are treated as part of the sub-select. The necessity of doing
8089 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
8090 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
8091 * SELECT viewpoint when we see the UNION.
8093 * This approach is implemented by defining a nonterminal select_with_parens,
8094 * which represents a SELECT with at least one outer layer of parentheses,
8095 * and being careful to use select_with_parens, never '(' SelectStmt ')',
8096 * in the expression grammar. We will then have shift-reduce conflicts
8097 * which we can resolve in favor of always treating '(' <select> ')' as
8098 * a select_with_parens. To resolve the conflicts, the productions that
8099 * conflict with the select_with_parens productions are manually given
8100 * precedences lower than the precedence of ')', thereby ensuring that we
8101 * shift ')' (and then reduce to select_with_parens) rather than trying to
8102 * reduce the inner <select> nonterminal to something else. We use UMINUS
8103 * precedence for this, which is a fairly arbitrary choice.
8105 * To be able to define select_with_parens itself without ambiguity, we need
8106 * a nonterminal select_no_parens that represents a SELECT structure with no
8107 * outermost parentheses. This is a little bit tedious, but it works.
8109 * In non-expression contexts, we use SelectStmt which can represent a SELECT
8110 * with or without outer parentheses.
8113 SelectStmt: select_no_parens %prec UMINUS
8114 | select_with_parens %prec UMINUS
8118 '(' select_no_parens ')' { $$ = $2; }
8119 | '(' select_with_parens ')' { $$ = $2; }
8123 * This rule parses the equivalent of the standard's <query expression>.
8124 * The duplicative productions are annoying, but hard to get rid of without
8125 * creating shift/reduce conflicts.
8127 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
8128 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
8129 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
8133 simple_select { $$ = $1; }
8134 | select_clause sort_clause
8136 insertSelectOptions((SelectStmt *) $1, $2, NIL,
8141 | select_clause opt_sort_clause for_locking_clause opt_select_limit
8143 insertSelectOptions((SelectStmt *) $1, $2, $3,
8144 list_nth($4, 0), list_nth($4, 1),
8149 | select_clause opt_sort_clause select_limit opt_for_locking_clause
8151 insertSelectOptions((SelectStmt *) $1, $2, $4,
8152 list_nth($3, 0), list_nth($3, 1),
8157 | with_clause select_clause
8159 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
8165 | with_clause select_clause sort_clause
8167 insertSelectOptions((SelectStmt *) $2, $3, NIL,
8173 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
8175 insertSelectOptions((SelectStmt *) $2, $3, $4,
8176 list_nth($5, 0), list_nth($5, 1),
8181 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
8183 insertSelectOptions((SelectStmt *) $2, $3, $5,
8184 list_nth($4, 0), list_nth($4, 1),
8192 simple_select { $$ = $1; }
8193 | select_with_parens { $$ = $1; }
8197 * This rule parses SELECT statements that can appear within set operations,
8198 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
8199 * the ordering of the set operations. Without '(' and ')' we want the
8200 * operations to be ordered per the precedence specs at the head of this file.
8202 * As with select_no_parens, simple_select cannot have outer parentheses,
8203 * but can have parenthesized subclauses.
8205 * Note that sort clauses cannot be included at this level --- SQL92 requires
8206 * SELECT foo UNION SELECT bar ORDER BY baz
8208 * (SELECT foo UNION SELECT bar) ORDER BY baz
8210 * SELECT foo UNION (SELECT bar ORDER BY baz)
8211 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
8212 * described as part of the select_no_parens production, not simple_select.
8213 * This does not limit functionality, because you can reintroduce these
8214 * clauses inside parentheses.
8216 * NOTE: only the leftmost component SelectStmt should have INTO.
8217 * However, this is not checked by the grammar; parse analysis must check it.
8220 SELECT opt_distinct target_list
8221 into_clause from_clause where_clause
8222 group_clause having_clause window_clause
8224 SelectStmt *n = makeNode(SelectStmt);
8225 n->distinctClause = $2;
8229 n->whereClause = $6;
8230 n->groupClause = $7;
8231 n->havingClause = $8;
8232 n->windowClause = $9;
8235 | values_clause { $$ = $1; }
8236 | TABLE relation_expr
8238 /* same as SELECT * FROM relation_expr */
8239 ColumnRef *cr = makeNode(ColumnRef);
8240 ResTarget *rt = makeNode(ResTarget);
8241 SelectStmt *n = makeNode(SelectStmt);
8243 cr->fields = list_make1(makeNode(A_Star));
8247 rt->indirection = NIL;
8248 rt->val = (Node *)cr;
8251 n->targetList = list_make1(rt);
8252 n->fromClause = list_make1($2);
8255 | select_clause UNION opt_all select_clause
8257 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
8259 | select_clause INTERSECT opt_all select_clause
8261 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
8263 | select_clause EXCEPT opt_all select_clause
8265 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
8270 * SQL standard WITH clause looks like:
8272 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
8273 * AS (query) [ SEARCH or CYCLE clause ]
8275 * We don't currently support the SEARCH or CYCLE clause.
8280 $$ = makeNode(WithClause);
8282 $$->recursive = false;
8285 | WITH RECURSIVE cte_list
8287 $$ = makeNode(WithClause);
8289 $$->recursive = true;
8295 common_table_expr { $$ = list_make1($1); }
8296 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
8299 common_table_expr: name opt_name_list AS select_with_parens
8301 CommonTableExpr *n = makeNode(CommonTableExpr);
8303 n->aliascolnames = $2;
8311 with_clause { $$ = $1; }
8312 | /*EMPTY*/ { $$ = NULL; }
8316 INTO OptTempTableName
8318 $$ = makeNode(IntoClause);
8322 $$->onCommit = ONCOMMIT_NOOP;
8323 $$->tableSpaceName = NULL;
8330 * Redundancy here is needed to avoid shift/reduce conflicts,
8331 * since TEMP is not a reserved word. See also OptTemp.
8334 TEMPORARY opt_table qualified_name
8337 $$->relpersistence = RELPERSISTENCE_TEMP;
8339 | TEMP opt_table qualified_name
8342 $$->relpersistence = RELPERSISTENCE_TEMP;
8344 | LOCAL TEMPORARY opt_table qualified_name
8347 $$->relpersistence = RELPERSISTENCE_TEMP;
8349 | LOCAL TEMP opt_table qualified_name
8352 $$->relpersistence = RELPERSISTENCE_TEMP;
8354 | GLOBAL TEMPORARY opt_table qualified_name
8357 $$->relpersistence = RELPERSISTENCE_TEMP;
8359 | GLOBAL TEMP opt_table qualified_name
8362 $$->relpersistence = RELPERSISTENCE_TEMP;
8364 | UNLOGGED opt_table qualified_name
8367 $$->relpersistence = RELPERSISTENCE_UNLOGGED;
8369 | TABLE qualified_name
8372 $$->relpersistence = RELPERSISTENCE_PERMANENT;
8377 $$->relpersistence = RELPERSISTENCE_PERMANENT;
8385 opt_all: ALL { $$ = TRUE; }
8386 | DISTINCT { $$ = FALSE; }
8387 | /*EMPTY*/ { $$ = FALSE; }
8390 /* We use (NIL) as a placeholder to indicate that all target expressions
8391 * should be placed in the DISTINCT list during parsetree analysis.
8394 DISTINCT { $$ = list_make1(NIL); }
8395 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
8397 | /*EMPTY*/ { $$ = NIL; }
8401 sort_clause { $$ = $1;}
8402 | /*EMPTY*/ { $$ = NIL; }
8406 ORDER BY sortby_list { $$ = $3; }
8410 sortby { $$ = list_make1($1); }
8411 | sortby_list ',' sortby { $$ = lappend($1, $3); }
8414 sortby: a_expr USING qual_all_Op opt_nulls_order
8416 $$ = makeNode(SortBy);
8418 $$->sortby_dir = SORTBY_USING;
8419 $$->sortby_nulls = $4;
8423 | a_expr opt_asc_desc opt_nulls_order
8425 $$ = makeNode(SortBy);
8427 $$->sortby_dir = $2;
8428 $$->sortby_nulls = $3;
8430 $$->location = -1; /* no operator */
8436 limit_clause offset_clause { $$ = list_make2($2, $1); }
8437 | offset_clause limit_clause { $$ = list_make2($1, $2); }
8438 | limit_clause { $$ = list_make2(NULL, $1); }
8439 | offset_clause { $$ = list_make2($1, NULL); }
8443 select_limit { $$ = $1; }
8444 | /* EMPTY */ { $$ = list_make2(NULL,NULL); }
8448 LIMIT select_limit_value
8450 | LIMIT select_limit_value ',' select_offset_value
8452 /* Disabled because it was too confusing, bjm 2002-02-18 */
8454 (errcode(ERRCODE_SYNTAX_ERROR),
8455 errmsg("LIMIT #,# syntax is not supported"),
8456 errhint("Use separate LIMIT and OFFSET clauses."),
8457 parser_errposition(@1)));
8459 /* SQL:2008 syntax */
8460 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
8465 OFFSET select_offset_value
8467 /* SQL:2008 syntax */
8468 | OFFSET select_offset_value2 row_or_rows
8476 /* LIMIT ALL is represented as a NULL constant */
8477 $$ = makeNullAConst(@1);
8481 select_offset_value:
8486 * Allowing full expressions without parentheses causes various parsing
8487 * problems with the trailing ROW/ROWS key words. SQL only calls for
8488 * constants, so we allow the rest only with parentheses. If omitted,
8491 opt_select_fetch_first_value:
8492 SignedIconst { $$ = makeIntConst($1, @1); }
8493 | '(' a_expr ')' { $$ = $2; }
8494 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
8498 * Again, the trailing ROW/ROWS in this case prevent the full expression
8499 * syntax. c_expr is the best we can do.
8501 select_offset_value2:
8506 row_or_rows: ROW { $$ = 0; }
8510 first_or_next: FIRST_P { $$ = 0; }
8516 GROUP_P BY expr_list { $$ = $3; }
8517 | /*EMPTY*/ { $$ = NIL; }
8521 HAVING a_expr { $$ = $2; }
8522 | /*EMPTY*/ { $$ = NULL; }
8526 for_locking_items { $$ = $1; }
8527 | FOR READ ONLY { $$ = NIL; }
8530 opt_for_locking_clause:
8531 for_locking_clause { $$ = $1; }
8532 | /* EMPTY */ { $$ = NIL; }
8536 for_locking_item { $$ = list_make1($1); }
8537 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
8541 FOR UPDATE locked_rels_list opt_nowait
8543 LockingClause *n = makeNode(LockingClause);
8545 n->forUpdate = TRUE;
8549 | FOR SHARE locked_rels_list opt_nowait
8551 LockingClause *n = makeNode(LockingClause);
8553 n->forUpdate = FALSE;
8560 OF qualified_name_list { $$ = $2; }
8561 | /* EMPTY */ { $$ = NIL; }
8568 SelectStmt *n = makeNode(SelectStmt);
8569 n->valuesLists = list_make1($2);
8572 | values_clause ',' ctext_row
8574 SelectStmt *n = (SelectStmt *) $1;
8575 n->valuesLists = lappend(n->valuesLists, $3);
8581 /*****************************************************************************
8583 * clauses common to all Optimizable Stmts:
8584 * from_clause - allow list of both JOIN expressions and table names
8585 * where_clause - qualifications for joins or restrictions
8587 *****************************************************************************/
8590 FROM from_list { $$ = $2; }
8591 | /*EMPTY*/ { $$ = NIL; }
8595 table_ref { $$ = list_make1($1); }
8596 | from_list ',' table_ref { $$ = lappend($1, $3); }
8600 * table_ref is where an alias clause can be attached. Note we cannot make
8601 * alias_clause have an empty production because that causes parse conflicts
8602 * between table_ref := '(' joined_table ')' alias_clause
8603 * and joined_table := '(' joined_table ')'. So, we must have the
8604 * redundant-looking productions here instead.
8606 table_ref: relation_expr
8610 | relation_expr alias_clause
8617 RangeFunction *n = makeNode(RangeFunction);
8618 n->funccallnode = $1;
8619 n->coldeflist = NIL;
8622 | func_table alias_clause
8624 RangeFunction *n = makeNode(RangeFunction);
8625 n->funccallnode = $1;
8627 n->coldeflist = NIL;
8630 | func_table AS '(' TableFuncElementList ')'
8632 RangeFunction *n = makeNode(RangeFunction);
8633 n->funccallnode = $1;
8637 | func_table AS ColId '(' TableFuncElementList ')'
8639 RangeFunction *n = makeNode(RangeFunction);
8640 Alias *a = makeNode(Alias);
8641 n->funccallnode = $1;
8647 | func_table ColId '(' TableFuncElementList ')'
8649 RangeFunction *n = makeNode(RangeFunction);
8650 Alias *a = makeNode(Alias);
8651 n->funccallnode = $1;
8657 | select_with_parens
8660 * The SQL spec does not permit a subselect
8661 * (<derived_table>) without an alias clause,
8662 * so we don't either. This avoids the problem
8663 * of needing to invent a unique refname for it.
8664 * That could be surmounted if there's sufficient
8665 * popular demand, but for now let's just implement
8666 * the spec and see if anyone complains.
8667 * However, it does seem like a good idea to emit
8668 * an error message that's better than "syntax error".
8670 if (IsA($1, SelectStmt) &&
8671 ((SelectStmt *) $1)->valuesLists)
8673 (errcode(ERRCODE_SYNTAX_ERROR),
8674 errmsg("VALUES in FROM must have an alias"),
8675 errhint("For example, FROM (VALUES ...) [AS] foo."),
8676 parser_errposition(@1)));
8679 (errcode(ERRCODE_SYNTAX_ERROR),
8680 errmsg("subquery in FROM must have an alias"),
8681 errhint("For example, FROM (SELECT ...) [AS] foo."),
8682 parser_errposition(@1)));
8685 | select_with_parens alias_clause
8687 RangeSubselect *n = makeNode(RangeSubselect);
8696 | '(' joined_table ')' alias_clause
8705 * It may seem silly to separate joined_table from table_ref, but there is
8706 * method in SQL92's madness: if you don't do it this way you get reduce-
8707 * reduce conflicts, because it's not clear to the parser generator whether
8708 * to expect alias_clause after ')' or not. For the same reason we must
8709 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
8710 * join_type to expand to empty; if we try it, the parser generator can't
8711 * figure out when to reduce an empty join_type right after table_ref.
8713 * Note that a CROSS JOIN is the same as an unqualified
8714 * INNER JOIN, and an INNER JOIN/ON has the same shape
8715 * but a qualification expression to limit membership.
8716 * A NATURAL JOIN implicitly matches column names between
8717 * tables and the shape is determined by which columns are
8718 * in common. We'll collect columns during the later transformations.
8722 '(' joined_table ')'
8726 | table_ref CROSS JOIN table_ref
8728 /* CROSS JOIN is same as unqualified inner join */
8729 JoinExpr *n = makeNode(JoinExpr);
8730 n->jointype = JOIN_INNER;
8731 n->isNatural = FALSE;
8734 n->usingClause = NIL;
8738 | table_ref join_type JOIN table_ref join_qual
8740 JoinExpr *n = makeNode(JoinExpr);
8742 n->isNatural = FALSE;
8745 if ($5 != NULL && IsA($5, List))
8746 n->usingClause = (List *) $5; /* USING clause */
8748 n->quals = $5; /* ON clause */
8751 | table_ref JOIN table_ref join_qual
8753 /* letting join_type reduce to empty doesn't work */
8754 JoinExpr *n = makeNode(JoinExpr);
8755 n->jointype = JOIN_INNER;
8756 n->isNatural = FALSE;
8759 if ($4 != NULL && IsA($4, List))
8760 n->usingClause = (List *) $4; /* USING clause */
8762 n->quals = $4; /* ON clause */
8765 | table_ref NATURAL join_type JOIN table_ref
8767 JoinExpr *n = makeNode(JoinExpr);
8769 n->isNatural = TRUE;
8772 n->usingClause = NIL; /* figure out which columns later... */
8773 n->quals = NULL; /* fill later */
8776 | table_ref NATURAL JOIN table_ref
8778 /* letting join_type reduce to empty doesn't work */
8779 JoinExpr *n = makeNode(JoinExpr);
8780 n->jointype = JOIN_INNER;
8781 n->isNatural = TRUE;
8784 n->usingClause = NIL; /* figure out which columns later... */
8785 n->quals = NULL; /* fill later */
8791 AS ColId '(' name_list ')'
8793 $$ = makeNode(Alias);
8799 $$ = makeNode(Alias);
8802 | ColId '(' name_list ')'
8804 $$ = makeNode(Alias);
8810 $$ = makeNode(Alias);
8815 join_type: FULL join_outer { $$ = JOIN_FULL; }
8816 | LEFT join_outer { $$ = JOIN_LEFT; }
8817 | RIGHT join_outer { $$ = JOIN_RIGHT; }
8818 | INNER_P { $$ = JOIN_INNER; }
8821 /* OUTER is just noise... */
8822 join_outer: OUTER_P { $$ = NULL; }
8823 | /*EMPTY*/ { $$ = NULL; }
8826 /* JOIN qualification clauses
8827 * Possibilities are:
8828 * USING ( column list ) allows only unqualified column names,
8829 * which must match between tables.
8830 * ON expr allows more general qualifications.
8832 * We return USING as a List node, while an ON-expr will not be a List.
8835 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
8836 | ON a_expr { $$ = $2; }
8843 /* default inheritance */
8845 $$->inhOpt = INH_DEFAULT;
8848 | qualified_name '*'
8850 /* inheritance query */
8852 $$->inhOpt = INH_YES;
8855 | ONLY qualified_name
8857 /* no inheritance */
8859 $$->inhOpt = INH_NO;
8862 | ONLY '(' qualified_name ')'
8864 /* no inheritance, SQL99-style syntax */
8866 $$->inhOpt = INH_NO;
8873 relation_expr { $$ = list_make1($1); }
8874 | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
8879 * Given "UPDATE foo set set ...", we have to decide without looking any
8880 * further ahead whether the first "set" is an alias or the UPDATE's SET
8881 * keyword. Since "set" is allowed as a column name both interpretations
8882 * are feasible. We resolve the shift/reduce conflict by giving the first
8883 * relation_expr_opt_alias production a higher precedence than the SET token
8884 * has, causing the parser to prefer to reduce, in effect assuming that the
8885 * SET is not an alias.
8887 relation_expr_opt_alias: relation_expr %prec UMINUS
8891 | relation_expr ColId
8893 Alias *alias = makeNode(Alias);
8894 alias->aliasname = $2;
8898 | relation_expr AS ColId
8900 Alias *alias = makeNode(Alias);
8901 alias->aliasname = $3;
8908 func_table: func_expr { $$ = $1; }
8913 WHERE a_expr { $$ = $2; }
8914 | /*EMPTY*/ { $$ = NULL; }
8917 /* variant for UPDATE and DELETE */
8918 where_or_current_clause:
8919 WHERE a_expr { $$ = $2; }
8920 | WHERE CURRENT_P OF name
8922 CurrentOfExpr *n = makeNode(CurrentOfExpr);
8923 /* cvarno is filled in by parse analysis */
8924 n->cursor_name = $4;
8925 n->cursor_param = 0;
8928 | /*EMPTY*/ { $$ = NULL; }
8932 OptTableFuncElementList:
8933 TableFuncElementList { $$ = $1; }
8934 | /*EMPTY*/ { $$ = NIL; }
8937 TableFuncElementList:
8940 $$ = list_make1($1);
8942 | TableFuncElementList ',' TableFuncElement
8944 $$ = lappend($1, $3);
8948 TableFuncElement: ColId Typename
8950 ColumnDef *n = makeNode(ColumnDef);
8953 n->constraints = NIL;
8959 /*****************************************************************************
8962 * SQL92 introduces a large amount of type-specific syntax.
8963 * Define individual clauses to handle these cases, and use
8964 * the generic case to handle regular type-extensible Postgres syntax.
8965 * - thomas 1997-10-10
8967 *****************************************************************************/
8969 Typename: SimpleTypename opt_array_bounds
8972 $$->arrayBounds = $2;
8974 | SETOF SimpleTypename opt_array_bounds
8977 $$->arrayBounds = $3;
8980 /* SQL standard syntax, currently only one-dimensional */
8981 | SimpleTypename ARRAY '[' Iconst ']'
8984 $$->arrayBounds = list_make1(makeInteger($4));
8986 | SETOF SimpleTypename ARRAY '[' Iconst ']'
8989 $$->arrayBounds = list_make1(makeInteger($5));
8992 | SimpleTypename ARRAY
8995 $$->arrayBounds = list_make1(makeInteger(-1));
8997 | SETOF SimpleTypename ARRAY
9000 $$->arrayBounds = list_make1(makeInteger(-1));
9006 opt_array_bounds '[' ']'
9007 { $$ = lappend($1, makeInteger(-1)); }
9008 | opt_array_bounds '[' Iconst ']'
9009 { $$ = lappend($1, makeInteger($3)); }
9015 SimpleTypenameWithoutCollation opt_collate
9021 SimpleTypenameWithoutCollation:
9022 GenericType { $$ = $1; }
9023 | Numeric { $$ = $1; }
9025 | Character { $$ = $1; }
9026 | ConstDatetime { $$ = $1; }
9027 | ConstInterval opt_interval
9032 | ConstInterval '(' Iconst ')' opt_interval
9037 if (list_length($5) != 1)
9039 (errcode(ERRCODE_SYNTAX_ERROR),
9040 errmsg("interval precision specified twice"),
9041 parser_errposition(@1)));
9042 $$->typmods = lappend($5, makeIntConst($3, @3));
9045 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
9046 makeIntConst($3, @3));
9050 /* We have a separate ConstTypename to allow defaulting fixed-length
9051 * types such as CHAR() and BIT() to an unspecified length.
9052 * SQL9x requires that these default to a length of one, but this
9053 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
9054 * where there is an obvious better choice to make.
9055 * Note that ConstInterval is not included here since it must
9056 * be pushed up higher in the rules to accomodate the postfix
9057 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
9058 * the generic-type-name case in AExprConst to avoid premature
9059 * reduce/reduce conflicts against function names.
9062 Numeric { $$ = $1; }
9063 | ConstBit { $$ = $1; }
9064 | ConstCharacter { $$ = $1; }
9065 | ConstDatetime { $$ = $1; }
9069 * GenericType covers all type names that don't have special syntax mandated
9070 * by the standard, including qualified names. We also allow type modifiers.
9071 * To avoid parsing conflicts against function invocations, the modifiers
9072 * have to be shown as expr_list here, but parse analysis will only accept
9073 * constants for them.
9076 type_function_name opt_type_modifiers
9078 $$ = makeTypeName($1);
9082 | type_function_name attrs opt_type_modifiers
9084 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
9090 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
9091 | /* EMPTY */ { $$ = NIL; }
9095 * SQL92 numeric data types
9099 $$ = SystemTypeName("int4");
9104 $$ = SystemTypeName("int4");
9109 $$ = SystemTypeName("int2");
9114 $$ = SystemTypeName("int8");
9119 $$ = SystemTypeName("float4");
9127 | DOUBLE_P PRECISION
9129 $$ = SystemTypeName("float8");
9132 | DECIMAL_P opt_type_modifiers
9134 $$ = SystemTypeName("numeric");
9138 | DEC opt_type_modifiers
9140 $$ = SystemTypeName("numeric");
9144 | NUMERIC opt_type_modifiers
9146 $$ = SystemTypeName("numeric");
9152 $$ = SystemTypeName("bool");
9157 opt_float: '(' Iconst ')'
9160 * Check FLOAT() precision limits assuming IEEE floating
9161 * types - thomas 1997-09-18
9165 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
9166 errmsg("precision for type float must be at least 1 bit"),
9167 parser_errposition(@2)));
9169 $$ = SystemTypeName("float4");
9171 $$ = SystemTypeName("float8");
9174 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
9175 errmsg("precision for type float must be less than 54 bits"),
9176 parser_errposition(@2)));
9180 $$ = SystemTypeName("float8");
9185 * SQL92 bit-field data types
9186 * The following implements BIT() and BIT VARYING().
9198 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
9199 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
9200 ConstBit: BitWithLength
9212 BIT opt_varying '(' expr_list ')'
9216 typname = $2 ? "varbit" : "bit";
9217 $$ = SystemTypeName(typname);
9226 /* bit defaults to bit(1), varbit to no limit */
9229 $$ = SystemTypeName("varbit");
9233 $$ = SystemTypeName("bit");
9234 $$->typmods = list_make1(makeIntConst(1, -1));
9242 * SQL92 character data types
9243 * The following implements CHAR() and VARCHAR().
9245 Character: CharacterWithLength
9249 | CharacterWithoutLength
9255 ConstCharacter: CharacterWithLength
9259 | CharacterWithoutLength
9261 /* Length was not specified so allow to be unrestricted.
9262 * This handles problems with fixed-length (bpchar) strings
9263 * which in column definitions must default to a length
9264 * of one, but should not be constrained if the length
9265 * was not specified.
9272 CharacterWithLength: character '(' Iconst ')' opt_charset
9274 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
9278 type = palloc(strlen($1) + 1 + strlen($5) + 1);
9285 $$ = SystemTypeName($1);
9286 $$->typmods = list_make1(makeIntConst($3, @3));
9291 CharacterWithoutLength: character opt_charset
9293 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
9297 type = palloc(strlen($1) + 1 + strlen($2) + 1);
9304 $$ = SystemTypeName($1);
9306 /* char defaults to char(1), varchar to no limit */
9307 if (strcmp($1, "bpchar") == 0)
9308 $$->typmods = list_make1(makeIntConst(1, -1));
9314 character: CHARACTER opt_varying
9315 { $$ = $2 ? "varchar": "bpchar"; }
9316 | CHAR_P opt_varying
9317 { $$ = $2 ? "varchar": "bpchar"; }
9320 | NATIONAL CHARACTER opt_varying
9321 { $$ = $3 ? "varchar": "bpchar"; }
9322 | NATIONAL CHAR_P opt_varying
9323 { $$ = $3 ? "varchar": "bpchar"; }
9325 { $$ = $2 ? "varchar": "bpchar"; }
9329 VARYING { $$ = TRUE; }
9330 | /*EMPTY*/ { $$ = FALSE; }
9334 CHARACTER SET ColId { $$ = $3; }
9335 | /*EMPTY*/ { $$ = NULL; }
9339 * SQL92 date/time types
9342 TIMESTAMP '(' Iconst ')' opt_timezone
9345 $$ = SystemTypeName("timestamptz");
9347 $$ = SystemTypeName("timestamp");
9348 $$->typmods = list_make1(makeIntConst($3, @3));
9351 | TIMESTAMP opt_timezone
9354 $$ = SystemTypeName("timestamptz");
9356 $$ = SystemTypeName("timestamp");
9359 | TIME '(' Iconst ')' opt_timezone
9362 $$ = SystemTypeName("timetz");
9364 $$ = SystemTypeName("time");
9365 $$->typmods = list_make1(makeIntConst($3, @3));
9371 $$ = SystemTypeName("timetz");
9373 $$ = SystemTypeName("time");
9381 $$ = SystemTypeName("interval");
9387 WITH_TIME ZONE { $$ = TRUE; }
9388 | WITHOUT TIME ZONE { $$ = FALSE; }
9389 | /*EMPTY*/ { $$ = FALSE; }
9394 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
9396 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
9398 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
9400 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
9402 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
9407 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
9408 INTERVAL_MASK(MONTH), @1));
9412 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
9413 INTERVAL_MASK(HOUR), @1));
9417 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
9418 INTERVAL_MASK(HOUR) |
9419 INTERVAL_MASK(MINUTE), @1));
9421 | DAY_P TO interval_second
9424 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
9425 INTERVAL_MASK(HOUR) |
9426 INTERVAL_MASK(MINUTE) |
9427 INTERVAL_MASK(SECOND), @1);
9429 | HOUR_P TO MINUTE_P
9431 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
9432 INTERVAL_MASK(MINUTE), @1));
9434 | HOUR_P TO interval_second
9437 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
9438 INTERVAL_MASK(MINUTE) |
9439 INTERVAL_MASK(SECOND), @1);
9441 | MINUTE_P TO interval_second
9444 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
9445 INTERVAL_MASK(SECOND), @1);
9454 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
9456 | SECOND_P '(' Iconst ')'
9458 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
9459 makeIntConst($3, @3));
9464 /*****************************************************************************
9466 * expression grammar
9468 *****************************************************************************/
9471 * General expressions
9472 * This is the heart of the expression syntax.
9474 * We have two expression types: a_expr is the unrestricted kind, and
9475 * b_expr is a subset that must be used in some places to avoid shift/reduce
9476 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
9477 * because that use of AND conflicts with AND as a boolean operator. So,
9478 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
9480 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
9481 * always be used by surrounding it with parens.
9483 * c_expr is all the productions that are common to a_expr and b_expr;
9484 * it's factored out just to eliminate redundant coding.
9486 a_expr: c_expr { $$ = $1; }
9487 | a_expr TYPECAST Typename
9488 { $$ = makeTypeCast($1, $3, @2); }
9489 | a_expr AT TIME ZONE a_expr
9491 FuncCall *n = makeNode(FuncCall);
9492 n->funcname = SystemFuncName("timezone");
9493 n->args = list_make2($5, $1);
9495 n->agg_star = FALSE;
9496 n->agg_distinct = FALSE;
9497 n->func_variadic = FALSE;
9503 * These operators must be called out explicitly in order to make use
9504 * of bison's automatic operator-precedence handling. All other
9505 * operator names are handled by the generic productions using "Op",
9506 * below; and all those operators will have the same precedence.
9508 * If you add more explicitly-known operators, be sure to add them
9509 * also to b_expr and to the MathOp list above.
9511 | '+' a_expr %prec UMINUS
9512 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
9513 | '-' a_expr %prec UMINUS
9514 { $$ = doNegate($2, @1); }
9516 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
9518 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
9520 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
9522 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
9524 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
9526 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
9528 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
9530 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
9532 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
9534 | a_expr qual_Op a_expr %prec Op
9535 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
9536 | qual_Op a_expr %prec Op
9537 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
9538 | a_expr qual_Op %prec POSTFIXOP
9539 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
9542 { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
9544 { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
9546 { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
9548 | a_expr LIKE a_expr
9549 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
9550 | a_expr LIKE a_expr ESCAPE a_expr
9552 FuncCall *n = makeNode(FuncCall);
9553 n->funcname = SystemFuncName("like_escape");
9554 n->args = list_make2($3, $5);
9556 n->agg_star = FALSE;
9557 n->agg_distinct = FALSE;
9558 n->func_variadic = FALSE;
9561 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
9563 | a_expr NOT LIKE a_expr
9564 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
9565 | a_expr NOT LIKE a_expr ESCAPE a_expr
9567 FuncCall *n = makeNode(FuncCall);
9568 n->funcname = SystemFuncName("like_escape");
9569 n->args = list_make2($4, $6);
9571 n->agg_star = FALSE;
9572 n->agg_distinct = FALSE;
9573 n->func_variadic = FALSE;
9576 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
9578 | a_expr ILIKE a_expr
9579 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
9580 | a_expr ILIKE a_expr ESCAPE a_expr
9582 FuncCall *n = makeNode(FuncCall);
9583 n->funcname = SystemFuncName("like_escape");
9584 n->args = list_make2($3, $5);
9586 n->agg_star = FALSE;
9587 n->agg_distinct = FALSE;
9588 n->func_variadic = FALSE;
9591 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n, @2);
9593 | a_expr NOT ILIKE a_expr
9594 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
9595 | a_expr NOT ILIKE a_expr ESCAPE a_expr
9597 FuncCall *n = makeNode(FuncCall);
9598 n->funcname = SystemFuncName("like_escape");
9599 n->args = list_make2($4, $6);
9601 n->agg_star = FALSE;
9602 n->agg_distinct = FALSE;
9603 n->func_variadic = FALSE;
9606 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n, @2);
9609 | a_expr SIMILAR TO a_expr %prec SIMILAR
9611 FuncCall *n = makeNode(FuncCall);
9612 n->funcname = SystemFuncName("similar_escape");
9613 n->args = list_make2($4, makeNullAConst(-1));
9615 n->agg_star = FALSE;
9616 n->agg_distinct = FALSE;
9617 n->func_variadic = FALSE;
9620 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
9622 | a_expr SIMILAR TO a_expr ESCAPE a_expr
9624 FuncCall *n = makeNode(FuncCall);
9625 n->funcname = SystemFuncName("similar_escape");
9626 n->args = list_make2($4, $6);
9628 n->agg_star = FALSE;
9629 n->agg_distinct = FALSE;
9630 n->func_variadic = FALSE;
9633 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
9635 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
9637 FuncCall *n = makeNode(FuncCall);
9638 n->funcname = SystemFuncName("similar_escape");
9639 n->args = list_make2($5, makeNullAConst(-1));
9641 n->agg_star = FALSE;
9642 n->agg_distinct = FALSE;
9643 n->func_variadic = FALSE;
9646 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
9648 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
9650 FuncCall *n = makeNode(FuncCall);
9651 n->funcname = SystemFuncName("similar_escape");
9652 n->args = list_make2($5, $7);
9654 n->agg_star = FALSE;
9655 n->agg_distinct = FALSE;
9656 n->func_variadic = FALSE;
9659 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
9663 * Define SQL92-style Null test clause.
9664 * Allow two forms described in the standard:
9667 * Allow two SQL extensions
9673 NullTest *n = makeNode(NullTest);
9674 n->arg = (Expr *) $1;
9675 n->nulltesttype = IS_NULL;
9680 NullTest *n = makeNode(NullTest);
9681 n->arg = (Expr *) $1;
9682 n->nulltesttype = IS_NULL;
9685 | a_expr IS NOT NULL_P
9687 NullTest *n = makeNode(NullTest);
9688 n->arg = (Expr *) $1;
9689 n->nulltesttype = IS_NOT_NULL;
9694 NullTest *n = makeNode(NullTest);
9695 n->arg = (Expr *) $1;
9696 n->nulltesttype = IS_NOT_NULL;
9701 $$ = (Node *)makeOverlaps($1, $3, @2, yyscanner);
9705 BooleanTest *b = makeNode(BooleanTest);
9706 b->arg = (Expr *) $1;
9707 b->booltesttype = IS_TRUE;
9710 | a_expr IS NOT TRUE_P
9712 BooleanTest *b = makeNode(BooleanTest);
9713 b->arg = (Expr *) $1;
9714 b->booltesttype = IS_NOT_TRUE;
9719 BooleanTest *b = makeNode(BooleanTest);
9720 b->arg = (Expr *) $1;
9721 b->booltesttype = IS_FALSE;
9724 | a_expr IS NOT FALSE_P
9726 BooleanTest *b = makeNode(BooleanTest);
9727 b->arg = (Expr *) $1;
9728 b->booltesttype = IS_NOT_FALSE;
9733 BooleanTest *b = makeNode(BooleanTest);
9734 b->arg = (Expr *) $1;
9735 b->booltesttype = IS_UNKNOWN;
9738 | a_expr IS NOT UNKNOWN
9740 BooleanTest *b = makeNode(BooleanTest);
9741 b->arg = (Expr *) $1;
9742 b->booltesttype = IS_NOT_UNKNOWN;
9745 | a_expr IS DISTINCT FROM a_expr %prec IS
9747 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
9749 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
9751 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9752 (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
9757 | a_expr IS OF '(' type_list ')' %prec IS
9759 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
9761 | a_expr IS NOT OF '(' type_list ')' %prec IS
9763 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
9766 * Ideally we would not use hard-wired operators below but
9767 * instead use opclasses. However, mixed data types and other
9768 * issues make this difficult:
9769 * http://archives.postgresql.org/pgsql-hackers/2008-08/msg01142.php
9771 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
9773 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
9774 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
9775 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
9778 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
9780 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
9781 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
9782 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
9785 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
9787 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
9788 (Node *) makeA_Expr(AEXPR_AND, NIL,
9789 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
9790 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
9792 (Node *) makeA_Expr(AEXPR_AND, NIL,
9793 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
9794 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
9798 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
9800 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
9801 (Node *) makeA_Expr(AEXPR_OR, NIL,
9802 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
9803 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
9805 (Node *) makeA_Expr(AEXPR_OR, NIL,
9806 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
9807 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
9811 | a_expr IN_P in_expr
9813 /* in_expr returns a SubLink or a list of a_exprs */
9814 if (IsA($3, SubLink))
9816 /* generate foo = ANY (subquery) */
9817 SubLink *n = (SubLink *) $3;
9818 n->subLinkType = ANY_SUBLINK;
9820 n->operName = list_make1(makeString("="));
9826 /* generate scalar IN expression */
9827 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
9830 | a_expr NOT IN_P in_expr
9832 /* in_expr returns a SubLink or a list of a_exprs */
9833 if (IsA($4, SubLink))
9835 /* generate NOT (foo = ANY (subquery)) */
9836 /* Make an = ANY node */
9837 SubLink *n = (SubLink *) $4;
9838 n->subLinkType = ANY_SUBLINK;
9840 n->operName = list_make1(makeString("="));
9842 /* Stick a NOT on top */
9843 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
9847 /* generate scalar NOT IN expression */
9848 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
9851 | a_expr subquery_Op sub_type select_with_parens %prec Op
9853 SubLink *n = makeNode(SubLink);
9854 n->subLinkType = $3;
9861 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
9863 if ($3 == ANY_SUBLINK)
9864 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
9866 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
9868 | UNIQUE select_with_parens
9870 /* Not sure how to get rid of the parentheses
9871 * but there are lots of shift/reduce errors without them.
9873 * Should be able to implement this by plopping the entire
9874 * select into a node, then transforming the target expressions
9875 * from whatever they are into count(*), and testing the
9876 * entire result equal to one.
9877 * But, will probably implement a separate node in the executor.
9880 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9881 errmsg("UNIQUE predicate is not yet implemented"),
9882 parser_errposition(@1)));
9884 | a_expr IS DOCUMENT_P %prec IS
9886 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9887 list_make1($1), @2);
9889 | a_expr IS NOT DOCUMENT_P %prec IS
9891 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9892 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9893 list_make1($1), @2),
9899 * Restricted expressions
9901 * b_expr is a subset of the complete expression syntax defined by a_expr.
9903 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
9904 * cause trouble in the places where b_expr is used. For simplicity, we
9905 * just eliminate all the boolean-keyword-operator productions from b_expr.
9909 | b_expr TYPECAST Typename
9910 { $$ = makeTypeCast($1, $3, @2); }
9911 | '+' b_expr %prec UMINUS
9912 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
9913 | '-' b_expr %prec UMINUS
9914 { $$ = doNegate($2, @1); }
9916 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
9918 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
9920 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
9922 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
9924 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
9926 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
9928 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
9930 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
9932 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
9933 | b_expr qual_Op b_expr %prec Op
9934 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
9935 | qual_Op b_expr %prec Op
9936 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
9937 | b_expr qual_Op %prec POSTFIXOP
9938 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
9939 | b_expr IS DISTINCT FROM b_expr %prec IS
9941 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
9943 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
9945 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
9946 NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
9948 | b_expr IS OF '(' type_list ')' %prec IS
9950 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
9952 | b_expr IS NOT OF '(' type_list ')' %prec IS
9954 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
9956 | b_expr IS DOCUMENT_P %prec IS
9958 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9959 list_make1($1), @2);
9961 | b_expr IS NOT DOCUMENT_P %prec IS
9963 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9964 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9965 list_make1($1), @2),
9971 * Productions that can be used in both a_expr and b_expr.
9973 * Note: productions that refer recursively to a_expr or b_expr mostly
9974 * cannot appear here. However, it's OK to refer to a_exprs that occur
9975 * inside parentheses, such as function arguments; that cannot introduce
9976 * ambiguity to the b_expr syntax.
9978 c_expr: columnref { $$ = $1; }
9979 | AexprConst { $$ = $1; }
9980 | PARAM opt_indirection
9982 ParamRef *p = makeNode(ParamRef);
9987 A_Indirection *n = makeNode(A_Indirection);
9988 n->arg = (Node *) p;
9989 n->indirection = check_indirection($2, yyscanner);
9995 | '(' a_expr ')' opt_indirection
9999 A_Indirection *n = makeNode(A_Indirection);
10001 n->indirection = check_indirection($4, yyscanner);
10011 | select_with_parens %prec UMINUS
10013 SubLink *n = makeNode(SubLink);
10014 n->subLinkType = EXPR_SUBLINK;
10015 n->testexpr = NULL;
10021 | EXISTS select_with_parens
10023 SubLink *n = makeNode(SubLink);
10024 n->subLinkType = EXISTS_SUBLINK;
10025 n->testexpr = NULL;
10031 | ARRAY select_with_parens
10033 SubLink *n = makeNode(SubLink);
10034 n->subLinkType = ARRAY_SUBLINK;
10035 n->testexpr = NULL;
10043 A_ArrayExpr *n = (A_ArrayExpr *) $2;
10044 Assert(IsA(n, A_ArrayExpr));
10045 /* point outermost A_ArrayExpr to the ARRAY keyword */
10051 RowExpr *r = makeNode(RowExpr);
10053 r->row_typeid = InvalidOid; /* not analyzed yet */
10057 | c_expr COLLATE any_name
10059 CollateClause *n = makeNode(CollateClause);
10060 n->arg = (Expr *) $1;
10068 * func_expr is split out from c_expr just so that we have a classification
10069 * for "everything that is a function call or looks like one". This isn't
10070 * very important, but it saves us having to document which variants are
10071 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
10072 * (Note that many of the special SQL functions wouldn't actually make any
10073 * sense as functional index entries, but we ignore that consideration here.)
10075 func_expr: func_name '(' ')' over_clause
10077 FuncCall *n = makeNode(FuncCall);
10080 n->agg_order = NIL;
10081 n->agg_star = FALSE;
10082 n->agg_distinct = FALSE;
10083 n->func_variadic = FALSE;
10088 | func_name '(' func_arg_list ')' over_clause
10090 FuncCall *n = makeNode(FuncCall);
10093 n->agg_order = NIL;
10094 n->agg_star = FALSE;
10095 n->agg_distinct = FALSE;
10096 n->func_variadic = FALSE;
10101 | func_name '(' VARIADIC func_arg_expr ')' over_clause
10103 FuncCall *n = makeNode(FuncCall);
10105 n->args = list_make1($4);
10106 n->agg_order = NIL;
10107 n->agg_star = FALSE;
10108 n->agg_distinct = FALSE;
10109 n->func_variadic = TRUE;
10114 | func_name '(' func_arg_list ',' VARIADIC func_arg_expr ')' over_clause
10116 FuncCall *n = makeNode(FuncCall);
10118 n->args = lappend($3, $6);
10119 n->agg_order = NIL;
10120 n->agg_star = FALSE;
10121 n->agg_distinct = FALSE;
10122 n->func_variadic = TRUE;
10127 | func_name '(' func_arg_list sort_clause ')' over_clause
10129 FuncCall *n = makeNode(FuncCall);
10133 n->agg_star = FALSE;
10134 n->agg_distinct = FALSE;
10135 n->func_variadic = FALSE;
10140 | func_name '(' ALL func_arg_list opt_sort_clause ')' over_clause
10142 FuncCall *n = makeNode(FuncCall);
10146 n->agg_star = FALSE;
10147 n->agg_distinct = FALSE;
10148 /* Ideally we'd mark the FuncCall node to indicate
10149 * "must be an aggregate", but there's no provision
10150 * for that in FuncCall at the moment.
10152 n->func_variadic = FALSE;
10157 | func_name '(' DISTINCT func_arg_list opt_sort_clause ')' over_clause
10159 FuncCall *n = makeNode(FuncCall);
10163 n->agg_star = FALSE;
10164 n->agg_distinct = TRUE;
10165 n->func_variadic = FALSE;
10170 | func_name '(' '*' ')' over_clause
10173 * We consider AGGREGATE(*) to invoke a parameterless
10174 * aggregate. This does the right thing for COUNT(*),
10175 * and there are no other aggregates in SQL92 that accept
10176 * '*' as parameter.
10178 * The FuncCall node is also marked agg_star = true,
10179 * so that later processing can detect what the argument
10182 FuncCall *n = makeNode(FuncCall);
10185 n->agg_order = NIL;
10186 n->agg_star = TRUE;
10187 n->agg_distinct = FALSE;
10188 n->func_variadic = FALSE;
10196 * Translate as "'now'::text::date".
10198 * We cannot use "'now'::date" because coerce_type() will
10199 * immediately reduce that to a constant representing
10200 * today's date. We need to delay the conversion until
10201 * runtime, else the wrong things will happen when
10202 * CURRENT_DATE is used in a column default value or rule.
10204 * This could be simplified if we had a way to generate
10205 * an expression tree representing runtime application
10206 * of type-input conversion functions. (As of PG 7.3
10207 * that is actually possible, but not clear that we want
10211 n = makeStringConstCast("now", @1, SystemTypeName("text"));
10212 $$ = makeTypeCast(n, SystemTypeName("date"), -1);
10217 * Translate as "'now'::text::timetz".
10218 * See comments for CURRENT_DATE.
10221 n = makeStringConstCast("now", @1, SystemTypeName("text"));
10222 $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
10224 | CURRENT_TIME '(' Iconst ')'
10227 * Translate as "'now'::text::timetz(n)".
10228 * See comments for CURRENT_DATE.
10232 n = makeStringConstCast("now", @1, SystemTypeName("text"));
10233 d = SystemTypeName("timetz");
10234 d->typmods = list_make1(makeIntConst($3, @3));
10235 $$ = makeTypeCast(n, d, -1);
10237 | CURRENT_TIMESTAMP
10240 * Translate as "now()", since we have a function that
10241 * does exactly what is needed.
10243 FuncCall *n = makeNode(FuncCall);
10244 n->funcname = SystemFuncName("now");
10246 n->agg_order = NIL;
10247 n->agg_star = FALSE;
10248 n->agg_distinct = FALSE;
10249 n->func_variadic = FALSE;
10254 | CURRENT_TIMESTAMP '(' Iconst ')'
10257 * Translate as "'now'::text::timestamptz(n)".
10258 * See comments for CURRENT_DATE.
10262 n = makeStringConstCast("now", @1, SystemTypeName("text"));
10263 d = SystemTypeName("timestamptz");
10264 d->typmods = list_make1(makeIntConst($3, @3));
10265 $$ = makeTypeCast(n, d, -1);
10270 * Translate as "'now'::text::time".
10271 * See comments for CURRENT_DATE.
10274 n = makeStringConstCast("now", @1, SystemTypeName("text"));
10275 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
10277 | LOCALTIME '(' Iconst ')'
10280 * Translate as "'now'::text::time(n)".
10281 * See comments for CURRENT_DATE.
10285 n = makeStringConstCast("now", @1, SystemTypeName("text"));
10286 d = SystemTypeName("time");
10287 d->typmods = list_make1(makeIntConst($3, @3));
10288 $$ = makeTypeCast((Node *)n, d, -1);
10293 * Translate as "'now'::text::timestamp".
10294 * See comments for CURRENT_DATE.
10297 n = makeStringConstCast("now", @1, SystemTypeName("text"));
10298 $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
10300 | LOCALTIMESTAMP '(' Iconst ')'
10303 * Translate as "'now'::text::timestamp(n)".
10304 * See comments for CURRENT_DATE.
10308 n = makeStringConstCast("now", @1, SystemTypeName("text"));
10309 d = SystemTypeName("timestamp");
10310 d->typmods = list_make1(makeIntConst($3, @3));
10311 $$ = makeTypeCast(n, d, -1);
10315 FuncCall *n = makeNode(FuncCall);
10316 n->funcname = SystemFuncName("current_user");
10318 n->agg_order = NIL;
10319 n->agg_star = FALSE;
10320 n->agg_distinct = FALSE;
10321 n->func_variadic = FALSE;
10328 FuncCall *n = makeNode(FuncCall);
10329 n->funcname = SystemFuncName("current_user");
10331 n->agg_order = NIL;
10332 n->agg_star = FALSE;
10333 n->agg_distinct = FALSE;
10334 n->func_variadic = FALSE;
10341 FuncCall *n = makeNode(FuncCall);
10342 n->funcname = SystemFuncName("session_user");
10344 n->agg_order = NIL;
10345 n->agg_star = FALSE;
10346 n->agg_distinct = FALSE;
10347 n->func_variadic = FALSE;
10354 FuncCall *n = makeNode(FuncCall);
10355 n->funcname = SystemFuncName("current_user");
10357 n->agg_order = NIL;
10358 n->agg_star = FALSE;
10359 n->agg_distinct = FALSE;
10360 n->func_variadic = FALSE;
10367 FuncCall *n = makeNode(FuncCall);
10368 n->funcname = SystemFuncName("current_database");
10370 n->agg_order = NIL;
10371 n->agg_star = FALSE;
10372 n->agg_distinct = FALSE;
10373 n->func_variadic = FALSE;
10380 FuncCall *n = makeNode(FuncCall);
10381 n->funcname = SystemFuncName("current_schema");
10383 n->agg_order = NIL;
10384 n->agg_star = FALSE;
10385 n->agg_distinct = FALSE;
10386 n->func_variadic = FALSE;
10391 | CAST '(' a_expr AS Typename ')'
10392 { $$ = makeTypeCast($3, $5, @1); }
10393 | EXTRACT '(' extract_list ')'
10395 FuncCall *n = makeNode(FuncCall);
10396 n->funcname = SystemFuncName("date_part");
10398 n->agg_order = NIL;
10399 n->agg_star = FALSE;
10400 n->agg_distinct = FALSE;
10401 n->func_variadic = FALSE;
10406 | OVERLAY '(' overlay_list ')'
10408 /* overlay(A PLACING B FROM C FOR D) is converted to
10409 * overlay(A, B, C, D)
10410 * overlay(A PLACING B FROM C) is converted to
10413 FuncCall *n = makeNode(FuncCall);
10414 n->funcname = SystemFuncName("overlay");
10416 n->agg_order = NIL;
10417 n->agg_star = FALSE;
10418 n->agg_distinct = FALSE;
10419 n->func_variadic = FALSE;
10424 | POSITION '(' position_list ')'
10426 /* position(A in B) is converted to position(B, A) */
10427 FuncCall *n = makeNode(FuncCall);
10428 n->funcname = SystemFuncName("position");
10430 n->agg_order = NIL;
10431 n->agg_star = FALSE;
10432 n->agg_distinct = FALSE;
10433 n->func_variadic = FALSE;
10438 | SUBSTRING '(' substr_list ')'
10440 /* substring(A from B for C) is converted to
10441 * substring(A, B, C) - thomas 2000-11-28
10443 FuncCall *n = makeNode(FuncCall);
10444 n->funcname = SystemFuncName("substring");
10446 n->agg_order = NIL;
10447 n->agg_star = FALSE;
10448 n->agg_distinct = FALSE;
10449 n->func_variadic = FALSE;
10454 | TREAT '(' a_expr AS Typename ')'
10456 /* TREAT(expr AS target) converts expr of a particular type to target,
10457 * which is defined to be a subtype of the original expression.
10458 * In SQL99, this is intended for use with structured UDTs,
10459 * but let's make this a generally useful form allowing stronger
10460 * coercions than are handled by implicit casting.
10462 FuncCall *n = makeNode(FuncCall);
10463 /* Convert SystemTypeName() to SystemFuncName() even though
10464 * at the moment they result in the same thing.
10466 n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
10467 n->args = list_make1($3);
10468 n->agg_order = NIL;
10469 n->agg_star = FALSE;
10470 n->agg_distinct = FALSE;
10471 n->func_variadic = FALSE;
10476 | TRIM '(' BOTH trim_list ')'
10478 /* various trim expressions are defined in SQL92
10479 * - thomas 1997-07-19
10481 FuncCall *n = makeNode(FuncCall);
10482 n->funcname = SystemFuncName("btrim");
10484 n->agg_order = NIL;
10485 n->agg_star = FALSE;
10486 n->agg_distinct = FALSE;
10487 n->func_variadic = FALSE;
10492 | TRIM '(' LEADING trim_list ')'
10494 FuncCall *n = makeNode(FuncCall);
10495 n->funcname = SystemFuncName("ltrim");
10497 n->agg_order = NIL;
10498 n->agg_star = FALSE;
10499 n->agg_distinct = FALSE;
10500 n->func_variadic = FALSE;
10505 | TRIM '(' TRAILING trim_list ')'
10507 FuncCall *n = makeNode(FuncCall);
10508 n->funcname = SystemFuncName("rtrim");
10510 n->agg_order = NIL;
10511 n->agg_star = FALSE;
10512 n->agg_distinct = FALSE;
10513 n->func_variadic = FALSE;
10518 | TRIM '(' trim_list ')'
10520 FuncCall *n = makeNode(FuncCall);
10521 n->funcname = SystemFuncName("btrim");
10523 n->agg_order = NIL;
10524 n->agg_star = FALSE;
10525 n->agg_distinct = FALSE;
10526 n->func_variadic = FALSE;
10531 | NULLIF '(' a_expr ',' a_expr ')'
10533 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
10535 | COALESCE '(' expr_list ')'
10537 CoalesceExpr *c = makeNode(CoalesceExpr);
10542 | GREATEST '(' expr_list ')'
10544 MinMaxExpr *v = makeNode(MinMaxExpr);
10546 v->op = IS_GREATEST;
10550 | LEAST '(' expr_list ')'
10552 MinMaxExpr *v = makeNode(MinMaxExpr);
10558 | XMLCONCAT '(' expr_list ')'
10560 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
10562 | XMLELEMENT '(' NAME_P ColLabel ')'
10564 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
10566 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
10568 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
10570 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
10572 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
10574 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
10576 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
10578 | XMLEXISTS '(' c_expr xmlexists_argument ')'
10580 /* xmlexists(A PASSING [BY REF] B [BY REF]) is
10581 * converted to xmlexists(A, B)*/
10582 FuncCall *n = makeNode(FuncCall);
10583 n->funcname = SystemFuncName("xmlexists");
10584 n->args = list_make2($3, $4);
10585 n->agg_order = NIL;
10586 n->agg_star = FALSE;
10587 n->agg_distinct = FALSE;
10588 n->func_variadic = FALSE;
10593 | XMLFOREST '(' xml_attribute_list ')'
10595 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
10597 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
10599 XmlExpr *x = (XmlExpr *)
10600 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
10601 list_make2($4, makeBoolAConst($5, -1)),
10606 | XMLPI '(' NAME_P ColLabel ')'
10608 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
10610 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
10612 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
10614 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
10616 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
10617 list_make3($3, $5, $6), @1);
10619 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
10621 XmlSerialize *n = makeNode(XmlSerialize);
10633 xml_root_version: VERSION_P a_expr
10635 | VERSION_P NO VALUE_P
10636 { $$ = makeNullAConst(-1); }
10639 opt_xml_root_standalone: ',' STANDALONE_P YES_P
10640 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
10641 | ',' STANDALONE_P NO
10642 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
10643 | ',' STANDALONE_P NO VALUE_P
10644 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
10646 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
10649 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
10652 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
10653 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
10656 xml_attribute_el: a_expr AS ColLabel
10658 $$ = makeNode(ResTarget);
10660 $$->indirection = NIL;
10661 $$->val = (Node *) $1;
10666 $$ = makeNode(ResTarget);
10668 $$->indirection = NIL;
10669 $$->val = (Node *) $1;
10674 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
10675 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
10678 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
10679 | STRIP_P WHITESPACE_P { $$ = FALSE; }
10680 | /*EMPTY*/ { $$ = FALSE; }
10683 /* We allow several variants for SQL and other compatibility. */
10684 xmlexists_argument:
10689 | PASSING c_expr BY REF
10693 | PASSING BY REF c_expr
10697 | PASSING BY REF c_expr BY REF
10705 * Window Definitions
10708 WINDOW window_definition_list { $$ = $2; }
10709 | /*EMPTY*/ { $$ = NIL; }
10712 window_definition_list:
10713 window_definition { $$ = list_make1($1); }
10714 | window_definition_list ',' window_definition
10715 { $$ = lappend($1, $3); }
10719 ColId AS window_specification
10727 over_clause: OVER window_specification
10731 WindowDef *n = makeNode(WindowDef);
10734 n->partitionClause = NIL;
10735 n->orderClause = NIL;
10736 n->frameOptions = FRAMEOPTION_DEFAULTS;
10737 n->startOffset = NULL;
10738 n->endOffset = NULL;
10746 window_specification: '(' opt_existing_window_name opt_partition_clause
10747 opt_sort_clause opt_frame_clause ')'
10749 WindowDef *n = makeNode(WindowDef);
10752 n->partitionClause = $3;
10753 n->orderClause = $4;
10754 /* copy relevant fields of opt_frame_clause */
10755 n->frameOptions = $5->frameOptions;
10756 n->startOffset = $5->startOffset;
10757 n->endOffset = $5->endOffset;
10764 * If we see PARTITION, RANGE, or ROWS as the first token after the '('
10765 * of a window_specification, we want the assumption to be that there is
10766 * no existing_window_name; but those keywords are unreserved and so could
10767 * be ColIds. We fix this by making them have the same precedence as IDENT
10768 * and giving the empty production here a slightly higher precedence, so
10769 * that the shift/reduce conflict is resolved in favor of reducing the rule.
10770 * These keywords are thus precluded from being an existing_window_name but
10771 * are not reserved for any other purpose.
10773 opt_existing_window_name: ColId { $$ = $1; }
10774 | /*EMPTY*/ %prec Op { $$ = NULL; }
10777 opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
10778 | /*EMPTY*/ { $$ = NIL; }
10782 * For frame clauses, we return a WindowDef, but only some fields are used:
10783 * frameOptions, startOffset, and endOffset.
10785 * This is only a subset of the full SQL:2008 frame_clause grammar.
10786 * We don't support <window frame exclusion> yet.
10792 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
10793 if (n->frameOptions & (FRAMEOPTION_START_VALUE_PRECEDING |
10794 FRAMEOPTION_END_VALUE_PRECEDING))
10796 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10797 errmsg("RANGE PRECEDING is only supported with UNBOUNDED"),
10798 parser_errposition(@1)));
10799 if (n->frameOptions & (FRAMEOPTION_START_VALUE_FOLLOWING |
10800 FRAMEOPTION_END_VALUE_FOLLOWING))
10802 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10803 errmsg("RANGE FOLLOWING is only supported with UNBOUNDED"),
10804 parser_errposition(@1)));
10807 | ROWS frame_extent
10810 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
10815 WindowDef *n = makeNode(WindowDef);
10816 n->frameOptions = FRAMEOPTION_DEFAULTS;
10817 n->startOffset = NULL;
10818 n->endOffset = NULL;
10823 frame_extent: frame_bound
10826 /* reject invalid cases */
10827 if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
10829 (errcode(ERRCODE_WINDOWING_ERROR),
10830 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
10831 parser_errposition(@1)));
10832 if (n->frameOptions & FRAMEOPTION_START_VALUE_FOLLOWING)
10834 (errcode(ERRCODE_WINDOWING_ERROR),
10835 errmsg("frame starting from following row cannot end with current row"),
10836 parser_errposition(@1)));
10837 n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
10840 | BETWEEN frame_bound AND frame_bound
10842 WindowDef *n1 = $2;
10843 WindowDef *n2 = $4;
10844 /* form merged options */
10845 int frameOptions = n1->frameOptions;
10846 /* shift converts START_ options to END_ options */
10847 frameOptions |= n2->frameOptions << 1;
10848 frameOptions |= FRAMEOPTION_BETWEEN;
10849 /* reject invalid cases */
10850 if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
10852 (errcode(ERRCODE_WINDOWING_ERROR),
10853 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
10854 parser_errposition(@2)));
10855 if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
10857 (errcode(ERRCODE_WINDOWING_ERROR),
10858 errmsg("frame end cannot be UNBOUNDED PRECEDING"),
10859 parser_errposition(@4)));
10860 if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
10861 (frameOptions & FRAMEOPTION_END_VALUE_PRECEDING))
10863 (errcode(ERRCODE_WINDOWING_ERROR),
10864 errmsg("frame starting from current row cannot have preceding rows"),
10865 parser_errposition(@4)));
10866 if ((frameOptions & FRAMEOPTION_START_VALUE_FOLLOWING) &&
10867 (frameOptions & (FRAMEOPTION_END_VALUE_PRECEDING |
10868 FRAMEOPTION_END_CURRENT_ROW)))
10870 (errcode(ERRCODE_WINDOWING_ERROR),
10871 errmsg("frame starting from following row cannot have preceding rows"),
10872 parser_errposition(@4)));
10873 n1->frameOptions = frameOptions;
10874 n1->endOffset = n2->startOffset;
10880 * This is used for both frame start and frame end, with output set up on
10881 * the assumption it's frame start; the frame_extent productions must reject
10885 UNBOUNDED PRECEDING
10887 WindowDef *n = makeNode(WindowDef);
10888 n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
10889 n->startOffset = NULL;
10890 n->endOffset = NULL;
10893 | UNBOUNDED FOLLOWING
10895 WindowDef *n = makeNode(WindowDef);
10896 n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
10897 n->startOffset = NULL;
10898 n->endOffset = NULL;
10903 WindowDef *n = makeNode(WindowDef);
10904 n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
10905 n->startOffset = NULL;
10906 n->endOffset = NULL;
10911 WindowDef *n = makeNode(WindowDef);
10912 n->frameOptions = FRAMEOPTION_START_VALUE_PRECEDING;
10913 n->startOffset = $1;
10914 n->endOffset = NULL;
10919 WindowDef *n = makeNode(WindowDef);
10920 n->frameOptions = FRAMEOPTION_START_VALUE_FOLLOWING;
10921 n->startOffset = $1;
10922 n->endOffset = NULL;
10929 * Supporting nonterminals for expressions.
10932 /* Explicit row production.
10934 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
10935 * without conflicting with the parenthesized a_expr production. Without the
10936 * ROW keyword, there must be more than one a_expr inside the parens.
10938 row: ROW '(' expr_list ')' { $$ = $3; }
10939 | ROW '(' ')' { $$ = NIL; }
10940 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
10943 sub_type: ANY { $$ = ANY_SUBLINK; }
10944 | SOME { $$ = ANY_SUBLINK; }
10945 | ALL { $$ = ALL_SUBLINK; }
10948 all_Op: Op { $$ = $1; }
10949 | MathOp { $$ = $1; }
10952 MathOp: '+' { $$ = "+"; }
10953 | '-' { $$ = "-"; }
10954 | '*' { $$ = "*"; }
10955 | '/' { $$ = "/"; }
10956 | '%' { $$ = "%"; }
10957 | '^' { $$ = "^"; }
10958 | '<' { $$ = "<"; }
10959 | '>' { $$ = ">"; }
10960 | '=' { $$ = "="; }
10964 { $$ = list_make1(makeString($1)); }
10965 | OPERATOR '(' any_operator ')'
10971 { $$ = list_make1(makeString($1)); }
10972 | OPERATOR '(' any_operator ')'
10978 { $$ = list_make1(makeString($1)); }
10979 | OPERATOR '(' any_operator ')'
10982 { $$ = list_make1(makeString("~~")); }
10984 { $$ = list_make1(makeString("!~~")); }
10986 { $$ = list_make1(makeString("~~*")); }
10988 { $$ = list_make1(makeString("!~~*")); }
10989 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
10990 * the regular expression is preprocessed by a function (similar_escape),
10991 * and the ~ operator for posix regular expressions is used.
10992 * x SIMILAR TO y -> x ~ similar_escape(y)
10993 * this transformation is made on the fly by the parser upwards.
10994 * however the SubLink structure which handles any/some/all stuff
10995 * is not ready for such a thing.
11001 $$ = list_make1($1);
11003 | expr_list ',' a_expr
11005 $$ = lappend($1, $3);
11009 /* function arguments can have names */
11010 func_arg_list: func_arg_expr
11012 $$ = list_make1($1);
11014 | func_arg_list ',' func_arg_expr
11016 $$ = lappend($1, $3);
11020 func_arg_expr: a_expr
11024 | param_name COLON_EQUALS a_expr
11026 NamedArgExpr *na = makeNode(NamedArgExpr);
11028 na->arg = (Expr *) $3;
11029 na->argnumber = -1; /* until determined */
11035 type_list: Typename { $$ = list_make1($1); }
11036 | type_list ',' Typename { $$ = lappend($1, $3); }
11039 array_expr: '[' expr_list ']'
11041 $$ = makeAArrayExpr($2, @1);
11043 | '[' array_expr_list ']'
11045 $$ = makeAArrayExpr($2, @1);
11049 $$ = makeAArrayExpr(NIL, @1);
11053 array_expr_list: array_expr { $$ = list_make1($1); }
11054 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
11059 extract_arg FROM a_expr
11061 $$ = list_make2(makeStringConst($1, @1), $3);
11063 | /*EMPTY*/ { $$ = NIL; }
11066 /* Allow delimited string Sconst in extract_arg as an SQL extension.
11067 * - thomas 2001-04-12
11071 | YEAR_P { $$ = "year"; }
11072 | MONTH_P { $$ = "month"; }
11073 | DAY_P { $$ = "day"; }
11074 | HOUR_P { $$ = "hour"; }
11075 | MINUTE_P { $$ = "minute"; }
11076 | SECOND_P { $$ = "second"; }
11077 | Sconst { $$ = $1; }
11080 /* OVERLAY() arguments
11081 * SQL99 defines the OVERLAY() function:
11082 * o overlay(text placing text from int for int)
11083 * o overlay(text placing text from int)
11084 * and similarly for binary strings
11087 a_expr overlay_placing substr_from substr_for
11089 $$ = list_make4($1, $2, $3, $4);
11091 | a_expr overlay_placing substr_from
11093 $$ = list_make3($1, $2, $3);
11102 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
11105 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
11106 | /*EMPTY*/ { $$ = NIL; }
11109 /* SUBSTRING() arguments
11110 * SQL9x defines a specific syntax for arguments to SUBSTRING():
11111 * o substring(text from int for int)
11112 * o substring(text from int) get entire string from starting point "int"
11113 * o substring(text for int) get first "int" characters of string
11114 * o substring(text from pattern) get entire string matching pattern
11115 * o substring(text from pattern for escape) same with specified escape char
11116 * We also want to support generic substring functions which accept
11117 * the usual generic list of arguments. So we will accept both styles
11118 * here, and convert the SQL9x style to the generic list for further
11119 * processing. - thomas 2000-11-28
11122 a_expr substr_from substr_for
11124 $$ = list_make3($1, $2, $3);
11126 | a_expr substr_for substr_from
11128 /* not legal per SQL99, but might as well allow it */
11129 $$ = list_make3($1, $3, $2);
11131 | a_expr substr_from
11133 $$ = list_make2($1, $2);
11135 | a_expr substr_for
11138 * Since there are no cases where this syntax allows
11139 * a textual FOR value, we forcibly cast the argument
11140 * to int4. The possible matches in pg_proc are
11141 * substring(text,int4) and substring(text,text),
11142 * and we don't want the parser to choose the latter,
11143 * which it is likely to do if the second argument
11144 * is unknown or doesn't have an implicit cast to int4.
11146 $$ = list_make3($1, makeIntConst(1, -1),
11148 SystemTypeName("int4"), -1));
11159 FROM a_expr { $$ = $2; }
11162 substr_for: FOR a_expr { $$ = $2; }
11165 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
11166 | FROM expr_list { $$ = $2; }
11167 | expr_list { $$ = $1; }
11170 in_expr: select_with_parens
11172 SubLink *n = makeNode(SubLink);
11174 /* other fields will be filled later */
11177 | '(' expr_list ')' { $$ = (Node *)$2; }
11181 * Define SQL92-style case clause.
11182 * - Full specification
11183 * CASE WHEN a = b THEN c ... ELSE d END
11184 * - Implicit argument
11185 * CASE a WHEN b THEN c ... ELSE d END
11187 case_expr: CASE case_arg when_clause_list case_default END_P
11189 CaseExpr *c = makeNode(CaseExpr);
11190 c->casetype = InvalidOid; /* not analyzed yet */
11191 c->arg = (Expr *) $2;
11193 c->defresult = (Expr *) $4;
11200 /* There must be at least one */
11201 when_clause { $$ = list_make1($1); }
11202 | when_clause_list when_clause { $$ = lappend($1, $2); }
11206 WHEN a_expr THEN a_expr
11208 CaseWhen *w = makeNode(CaseWhen);
11209 w->expr = (Expr *) $2;
11210 w->result = (Expr *) $4;
11217 ELSE a_expr { $$ = $2; }
11218 | /*EMPTY*/ { $$ = NULL; }
11221 case_arg: a_expr { $$ = $1; }
11222 | /*EMPTY*/ { $$ = NULL; }
11227 $$ = makeColumnRef($1, NIL, @1, yyscanner);
11229 | ColId indirection
11231 $$ = makeColumnRef($1, $2, @1, yyscanner);
11238 $$ = (Node *) makeString($2);
11242 $$ = (Node *) makeNode(A_Star);
11246 A_Indices *ai = makeNode(A_Indices);
11251 | '[' a_expr ':' a_expr ']'
11253 A_Indices *ai = makeNode(A_Indices);
11261 indirection_el { $$ = list_make1($1); }
11262 | indirection indirection_el { $$ = lappend($1, $2); }
11266 /*EMPTY*/ { $$ = NIL; }
11267 | opt_indirection indirection_el { $$ = lappend($1, $2); }
11270 opt_asymmetric: ASYMMETRIC
11275 * The SQL spec defines "contextually typed value expressions" and
11276 * "contextually typed row value constructors", which for our purposes
11277 * are the same as "a_expr" and "row" except that DEFAULT can appear at
11282 a_expr { $$ = (Node *) $1; }
11285 SetToDefault *n = makeNode(SetToDefault);
11292 ctext_expr { $$ = list_make1($1); }
11293 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
11297 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
11298 * making VALUES a fully reserved word, which will probably break more apps
11299 * than allowing the noise-word is worth.
11301 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
11305 /*****************************************************************************
11307 * target list for SELECT
11309 *****************************************************************************/
11312 target_el { $$ = list_make1($1); }
11313 | target_list ',' target_el { $$ = lappend($1, $3); }
11316 target_el: a_expr AS ColLabel
11318 $$ = makeNode(ResTarget);
11320 $$->indirection = NIL;
11321 $$->val = (Node *)$1;
11325 * We support omitting AS only for column labels that aren't
11326 * any known keyword. There is an ambiguity against postfix
11327 * operators: is "a ! b" an infix expression, or a postfix
11328 * expression and a column label? We prefer to resolve this
11329 * as an infix expression, which we accomplish by assigning
11330 * IDENT a precedence higher than POSTFIXOP.
11334 $$ = makeNode(ResTarget);
11336 $$->indirection = NIL;
11337 $$->val = (Node *)$1;
11342 $$ = makeNode(ResTarget);
11344 $$->indirection = NIL;
11345 $$->val = (Node *)$1;
11350 ColumnRef *n = makeNode(ColumnRef);
11351 n->fields = list_make1(makeNode(A_Star));
11354 $$ = makeNode(ResTarget);
11356 $$->indirection = NIL;
11357 $$->val = (Node *)n;
11363 /*****************************************************************************
11365 * Names and constants
11367 *****************************************************************************/
11369 qualified_name_list:
11370 qualified_name { $$ = list_make1($1); }
11371 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
11375 * The production for a qualified relation name has to exactly match the
11376 * production for a qualified func_name, because in a FROM clause we cannot
11377 * tell which we are parsing until we see what comes after it ('(' for a
11378 * func_name, something else for a relation). Therefore we allow 'indirection'
11379 * which may contain subscripts, and reject that case in the C code.
11384 $$ = makeRangeVar(NULL, $1, @1);
11386 | ColId indirection
11388 check_qualified_name($2, yyscanner);
11389 $$ = makeRangeVar(NULL, NULL, @1);
11390 switch (list_length($2))
11393 $$->catalogname = NULL;
11394 $$->schemaname = $1;
11395 $$->relname = strVal(linitial($2));
11398 $$->catalogname = $1;
11399 $$->schemaname = strVal(linitial($2));
11400 $$->relname = strVal(lsecond($2));
11404 (errcode(ERRCODE_SYNTAX_ERROR),
11405 errmsg("improper qualified name (too many dotted names): %s",
11406 NameListToString(lcons(makeString($1), $2))),
11407 parser_errposition(@1)));
11414 { $$ = list_make1(makeString($1)); }
11415 | name_list ',' name
11416 { $$ = lappend($1, makeString($3)); }
11420 name: ColId { $$ = $1; };
11423 ColId { $$ = $1; };
11426 ColId { $$ = $1; };
11428 attr_name: ColLabel { $$ = $1; };
11430 index_name: ColId { $$ = $1; };
11432 file_name: Sconst { $$ = $1; };
11435 * The production for a qualified func_name has to exactly match the
11436 * production for a qualified columnref, because we cannot tell which we
11437 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
11438 * anything else for a columnref). Therefore we allow 'indirection' which
11439 * may contain subscripts, and reject that case in the C code. (If we
11440 * ever implement SQL99-like methods, such syntax may actually become legal!)
11442 func_name: type_function_name
11443 { $$ = list_make1(makeString($1)); }
11444 | ColId indirection
11446 $$ = check_func_name(lcons(makeString($1), $2),
11457 $$ = makeIntConst($1, @1);
11461 $$ = makeFloatConst($1, @1);
11465 $$ = makeStringConst($1, @1);
11469 $$ = makeBitStringConst($1, @1);
11473 /* This is a bit constant per SQL99:
11474 * Without Feature F511, "BIT data type",
11475 * a <general literal> shall not be a
11476 * <bit string literal> or a <hex string literal>.
11478 $$ = makeBitStringConst($1, @1);
11482 /* generic type 'literal' syntax */
11483 TypeName *t = makeTypeNameFromNameList($1);
11485 $$ = makeStringConstCast($2, @2, t);
11487 | func_name '(' func_arg_list ')' Sconst
11489 /* generic syntax with a type modifier */
11490 TypeName *t = makeTypeNameFromNameList($1);
11494 * We must use func_arg_list in the production to avoid
11495 * reduce/reduce conflicts, but we don't actually wish
11496 * to allow NamedArgExpr in this context.
11500 NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
11502 if (IsA(arg, NamedArgExpr))
11504 (errcode(ERRCODE_SYNTAX_ERROR),
11505 errmsg("type modifier cannot have parameter name"),
11506 parser_errposition(arg->location)));
11510 $$ = makeStringConstCast($5, @5, t);
11512 | ConstTypename Sconst
11514 $$ = makeStringConstCast($2, @2, $1);
11516 | ConstInterval Sconst opt_interval
11520 $$ = makeStringConstCast($2, @2, t);
11522 | ConstInterval '(' Iconst ')' Sconst opt_interval
11527 if (list_length($6) != 1)
11529 (errcode(ERRCODE_SYNTAX_ERROR),
11530 errmsg("interval precision specified twice"),
11531 parser_errposition(@1)));
11532 t->typmods = lappend($6, makeIntConst($3, @3));
11535 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
11536 makeIntConst($3, @3));
11537 $$ = makeStringConstCast($5, @5, t);
11541 $$ = makeBoolAConst(TRUE, @1);
11545 $$ = makeBoolAConst(FALSE, @1);
11549 $$ = makeNullAConst(@1);
11553 Iconst: ICONST { $$ = $1; };
11554 Sconst: SCONST { $$ = $1; };
11555 RoleId: ColId { $$ = $1; };
11557 SignedIconst: Iconst { $$ = $1; }
11558 | '+' Iconst { $$ = + $2; }
11559 | '-' Iconst { $$ = - $2; }
11563 * Name classification hierarchy.
11565 * IDENT is the lexeme returned by the lexer for identifiers that match
11566 * no known keyword. In most cases, we can accept certain keywords as
11567 * names, not only IDENTs. We prefer to accept as many such keywords
11568 * as possible to minimize the impact of "reserved words" on programmers.
11569 * So, we divide names into several possible classes. The classification
11570 * is chosen in part to make keywords acceptable as names wherever possible.
11573 /* Column identifier --- names that can be column, table, etc names.
11575 ColId: IDENT { $$ = $1; }
11576 | unreserved_keyword { $$ = pstrdup($1); }
11577 | col_name_keyword { $$ = pstrdup($1); }
11580 /* Type/function identifier --- names that can be type or function names.
11582 type_function_name: IDENT { $$ = $1; }
11583 | unreserved_keyword { $$ = pstrdup($1); }
11584 | type_func_name_keyword { $$ = pstrdup($1); }
11587 /* Column label --- allowed labels in "AS" clauses.
11588 * This presently includes *all* Postgres keywords.
11590 ColLabel: IDENT { $$ = $1; }
11591 | unreserved_keyword { $$ = pstrdup($1); }
11592 | col_name_keyword { $$ = pstrdup($1); }
11593 | type_func_name_keyword { $$ = pstrdup($1); }
11594 | reserved_keyword { $$ = pstrdup($1); }
11599 * Keyword category lists. Generally, every keyword present in
11600 * the Postgres grammar should appear in exactly one of these lists.
11602 * Put a new keyword into the first list that it can go into without causing
11603 * shift or reduce conflicts. The earlier lists define "less reserved"
11604 * categories of keywords.
11606 * Make sure that each keyword's category in kwlist.h matches where
11607 * it is listed here. (Someday we may be able to generate these lists and
11608 * kwlist.h's table from a common master list.)
11611 /* "Unreserved" keywords --- available for use as any kind of name.
11613 unreserved_keyword:
11875 /* Column identifier --- keywords that can be column, table, etc names.
11877 * Many of these keywords will in fact be recognized as type or function
11878 * names too; but they have special productions for the purpose, and so
11879 * can't be treated as "generic" type or function names.
11881 * The type names appearing here are not usable as function names
11882 * because they can be followed by '(' in typename productions, which
11883 * looks too much like a function call for an LR(1) parser.
11935 /* Type/function identifier --- keywords that can be type or function names.
11937 * Most of these are keywords that are used as operators in expressions;
11938 * in general such keywords can't be column names because they would be
11939 * ambiguous with variables, but they are unambiguous as function identifiers.
11941 * Do not include POSITION, SUBSTRING, etc here since they have explicit
11942 * productions in a_expr to support the goofy SQL9x argument syntax.
11943 * - thomas 2000-11-28
11945 type_func_name_keyword:
11970 /* Reserved keyword --- these keywords are usable only as a ColLabel.
11972 * Keywords appear here if they could not be distinguished from variable,
11973 * type, or function names in some contexts. Don't put things here unless
11998 | CURRENT_TIMESTAMP
12058 * The signature of this function is required by bison. However, we
12059 * ignore the passed yylloc and instead use the last token position
12060 * available from the scanner.
12063 base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
12065 parser_yyerror(msg);
12069 makeColumnRef(char *colname, List *indirection,
12070 int location, core_yyscan_t yyscanner)
12073 * Generate a ColumnRef node, with an A_Indirection node added if there
12074 * is any subscripting in the specified indirection list. However,
12075 * any field selection at the start of the indirection list must be
12076 * transposed into the "fields" part of the ColumnRef node.
12078 ColumnRef *c = makeNode(ColumnRef);
12082 c->location = location;
12083 foreach(l, indirection)
12085 if (IsA(lfirst(l), A_Indices))
12087 A_Indirection *i = makeNode(A_Indirection);
12091 /* easy case - all indirection goes to A_Indirection */
12092 c->fields = list_make1(makeString(colname));
12093 i->indirection = check_indirection(indirection, yyscanner);
12097 /* got to split the list in two */
12098 i->indirection = check_indirection(list_copy_tail(indirection,
12101 indirection = list_truncate(indirection, nfields);
12102 c->fields = lcons(makeString(colname), indirection);
12104 i->arg = (Node *) c;
12107 else if (IsA(lfirst(l), A_Star))
12109 /* We only allow '*' at the end of a ColumnRef */
12110 if (lnext(l) != NULL)
12111 parser_yyerror("improper use of \"*\"");
12115 /* No subscripting, so all indirection gets added to field list */
12116 c->fields = lcons(makeString(colname), indirection);
12121 makeTypeCast(Node *arg, TypeName *typename, int location)
12123 TypeCast *n = makeNode(TypeCast);
12125 n->typeName = typename;
12126 n->location = location;
12131 makeStringConst(char *str, int location)
12133 A_Const *n = makeNode(A_Const);
12135 n->val.type = T_String;
12136 n->val.val.str = str;
12137 n->location = location;
12143 makeStringConstCast(char *str, int location, TypeName *typename)
12145 Node *s = makeStringConst(str, location);
12147 return makeTypeCast(s, typename, -1);
12151 makeIntConst(int val, int location)
12153 A_Const *n = makeNode(A_Const);
12155 n->val.type = T_Integer;
12156 n->val.val.ival = val;
12157 n->location = location;
12163 makeFloatConst(char *str, int location)
12165 A_Const *n = makeNode(A_Const);
12167 n->val.type = T_Float;
12168 n->val.val.str = str;
12169 n->location = location;
12175 makeBitStringConst(char *str, int location)
12177 A_Const *n = makeNode(A_Const);
12179 n->val.type = T_BitString;
12180 n->val.val.str = str;
12181 n->location = location;
12187 makeNullAConst(int location)
12189 A_Const *n = makeNode(A_Const);
12191 n->val.type = T_Null;
12192 n->location = location;
12198 makeAConst(Value *v, int location)
12205 n = makeFloatConst(v->val.str, location);
12209 n = makeIntConst(v->val.ival, location);
12214 n = makeStringConst(v->val.str, location);
12221 /* makeBoolAConst()
12222 * Create an A_Const string node and put it inside a boolean cast.
12225 makeBoolAConst(bool state, int location)
12227 A_Const *n = makeNode(A_Const);
12229 n->val.type = T_String;
12230 n->val.val.str = (state ? "t" : "f");
12231 n->location = location;
12233 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
12237 * Create and populate a FuncCall node to support the OVERLAPS operator.
12240 makeOverlaps(List *largs, List *rargs, int location, core_yyscan_t yyscanner)
12242 FuncCall *n = makeNode(FuncCall);
12244 n->funcname = SystemFuncName("overlaps");
12245 if (list_length(largs) == 1)
12246 largs = lappend(largs, largs);
12247 else if (list_length(largs) != 2)
12249 (errcode(ERRCODE_SYNTAX_ERROR),
12250 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
12251 parser_errposition(location)));
12252 if (list_length(rargs) == 1)
12253 rargs = lappend(rargs, rargs);
12254 else if (list_length(rargs) != 2)
12256 (errcode(ERRCODE_SYNTAX_ERROR),
12257 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
12258 parser_errposition(location)));
12259 n->args = list_concat(largs, rargs);
12260 n->agg_order = NIL;
12261 n->agg_star = FALSE;
12262 n->agg_distinct = FALSE;
12263 n->func_variadic = FALSE;
12265 n->location = location;
12269 /* check_qualified_name --- check the result of qualified_name production
12271 * It's easiest to let the grammar production for qualified_name allow
12272 * subscripts and '*', which we then must reject here.
12275 check_qualified_name(List *names, core_yyscan_t yyscanner)
12281 if (!IsA(lfirst(i), String))
12282 parser_yyerror("syntax error");
12286 /* check_func_name --- check the result of func_name production
12288 * It's easiest to let the grammar production for func_name allow subscripts
12289 * and '*', which we then must reject here.
12292 check_func_name(List *names, core_yyscan_t yyscanner)
12298 if (!IsA(lfirst(i), String))
12299 parser_yyerror("syntax error");
12304 /* check_indirection --- check the result of indirection production
12306 * We only allow '*' at the end of the list, but it's hard to enforce that
12307 * in the grammar, so do it here.
12310 check_indirection(List *indirection, core_yyscan_t yyscanner)
12314 foreach(l, indirection)
12316 if (IsA(lfirst(l), A_Star))
12318 if (lnext(l) != NULL)
12319 parser_yyerror("improper use of \"*\"");
12322 return indirection;
12325 /* extractArgTypes()
12326 * Given a list of FunctionParameter nodes, extract a list of just the
12327 * argument types (TypeNames) for input parameters only. This is what
12328 * is needed to look up an existing function, which is what is wanted by
12329 * the productions that use this call.
12332 extractArgTypes(List *parameters)
12334 List *result = NIL;
12337 foreach(i, parameters)
12339 FunctionParameter *p = (FunctionParameter *) lfirst(i);
12341 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
12342 result = lappend(result, p->argType);
12347 /* findLeftmostSelect()
12348 * Find the leftmost component SelectStmt in a set-operation parsetree.
12350 static SelectStmt *
12351 findLeftmostSelect(SelectStmt *node)
12353 while (node && node->op != SETOP_NONE)
12355 Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
12359 /* insertSelectOptions()
12360 * Insert ORDER BY, etc into an already-constructed SelectStmt.
12362 * This routine is just to avoid duplicating code in SelectStmt productions.
12365 insertSelectOptions(SelectStmt *stmt,
12366 List *sortClause, List *lockingClause,
12367 Node *limitOffset, Node *limitCount,
12368 WithClause *withClause,
12369 core_yyscan_t yyscanner)
12371 Assert(IsA(stmt, SelectStmt));
12374 * Tests here are to reject constructs like
12375 * (SELECT foo ORDER BY bar) ORDER BY baz
12379 if (stmt->sortClause)
12381 (errcode(ERRCODE_SYNTAX_ERROR),
12382 errmsg("multiple ORDER BY clauses not allowed"),
12383 parser_errposition(exprLocation((Node *) sortClause))));
12384 stmt->sortClause = sortClause;
12386 /* We can handle multiple locking clauses, though */
12387 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
12390 if (stmt->limitOffset)
12392 (errcode(ERRCODE_SYNTAX_ERROR),
12393 errmsg("multiple OFFSET clauses not allowed"),
12394 parser_errposition(exprLocation(limitOffset))));
12395 stmt->limitOffset = limitOffset;
12399 if (stmt->limitCount)
12401 (errcode(ERRCODE_SYNTAX_ERROR),
12402 errmsg("multiple LIMIT clauses not allowed"),
12403 parser_errposition(exprLocation(limitCount))));
12404 stmt->limitCount = limitCount;
12408 if (stmt->withClause)
12410 (errcode(ERRCODE_SYNTAX_ERROR),
12411 errmsg("multiple WITH clauses not allowed"),
12412 parser_errposition(exprLocation((Node *) withClause))));
12413 stmt->withClause = withClause;
12418 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
12420 SelectStmt *n = makeNode(SelectStmt);
12424 n->larg = (SelectStmt *) larg;
12425 n->rarg = (SelectStmt *) rarg;
12429 /* SystemFuncName()
12430 * Build a properly-qualified reference to a built-in function.
12433 SystemFuncName(char *name)
12435 return list_make2(makeString("pg_catalog"), makeString(name));
12438 /* SystemTypeName()
12439 * Build a properly-qualified reference to a built-in type.
12441 * typmod is defaulted, but may be changed afterwards by caller.
12442 * Likewise for the location.
12445 SystemTypeName(char *name)
12447 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
12448 makeString(name)));
12452 * Handle negation of a numeric constant.
12454 * Formerly, we did this here because the optimizer couldn't cope with
12455 * indexquals that looked like "var = -4" --- it wants "var = const"
12456 * and a unary minus operator applied to a constant didn't qualify.
12457 * As of Postgres 7.0, that problem doesn't exist anymore because there
12458 * is a constant-subexpression simplifier in the optimizer. However,
12459 * there's still a good reason for doing this here, which is that we can
12460 * postpone committing to a particular internal representation for simple
12461 * negative constants. It's better to leave "-123.456" in string form
12462 * until we know what the desired type is.
12465 doNegate(Node *n, int location)
12467 if (IsA(n, A_Const))
12469 A_Const *con = (A_Const *)n;
12471 /* report the constant's location as that of the '-' sign */
12472 con->location = location;
12474 if (con->val.type == T_Integer)
12476 con->val.val.ival = -con->val.val.ival;
12479 if (con->val.type == T_Float)
12481 doNegateFloat(&con->val);
12486 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
12490 doNegateFloat(Value *v)
12492 char *oldval = v->val.str;
12494 Assert(IsA(v, Float));
12495 if (*oldval == '+')
12497 if (*oldval == '-')
12498 v->val.str = oldval+1; /* just strip the '-' */
12501 char *newval = (char *) palloc(strlen(oldval) + 2);
12504 strcpy(newval+1, oldval);
12505 v->val.str = newval;
12510 makeAArrayExpr(List *elements, int location)
12512 A_ArrayExpr *n = makeNode(A_ArrayExpr);
12514 n->elements = elements;
12515 n->location = location;
12520 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
12523 XmlExpr *x = makeNode(XmlExpr);
12528 * named_args is a list of ResTarget; it'll be split apart into separate
12529 * expression and name lists in transformXmlExpr().
12531 x->named_args = named_args;
12532 x->arg_names = NIL;
12534 /* xmloption, if relevant, must be filled in by caller */
12535 /* type and typmod will be filled in during parse analysis */
12536 x->location = location;
12541 * Initialize to parse one query string
12544 parser_init(base_yy_extra_type *yyext)
12546 yyext->parsetree = NIL; /* in case grammar forgets to set it */
12550 * Merge the input and output parameters of a table function.
12553 mergeTableFuncParameters(List *func_args, List *columns)
12557 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
12558 foreach(lc, func_args)
12560 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
12562 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
12564 (errcode(ERRCODE_SYNTAX_ERROR),
12565 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
12568 return list_concat(func_args, columns);
12572 * Determine return type of a TABLE function. A single result column
12573 * returns setof that column's type; otherwise return setof record.
12576 TableFuncTypeName(List *columns)
12580 if (list_length(columns) == 1)
12582 FunctionParameter *p = (FunctionParameter *) linitial(columns);
12584 result = (TypeName *) copyObject(p->argType);
12587 result = SystemTypeName("record");
12589 result->setof = true;
12595 * Convert a list of (dotted) names to a RangeVar (like
12596 * makeRangeVarFromNameList, but with position support). The
12597 * "AnyName" refers to the any_name production in the grammar.
12600 makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
12602 RangeVar *r = makeNode(RangeVar);
12604 switch (list_length(names))
12607 r->catalogname = NULL;
12608 r->schemaname = NULL;
12609 r->relname = strVal(linitial(names));
12612 r->catalogname = NULL;
12613 r->schemaname = strVal(linitial(names));
12614 r->relname = strVal(lsecond(names));
12617 r->catalogname = strVal(linitial(names));;
12618 r->schemaname = strVal(lsecond(names));
12619 r->relname = strVal(lthird(names));
12623 (errcode(ERRCODE_SYNTAX_ERROR),
12624 errmsg("improper qualified name (too many dotted names): %s",
12625 NameListToString(names)),
12626 parser_errposition(position)));
12630 r->relpersistence = RELPERSISTENCE_PERMANENT;
12631 r->location = position;
12637 * Must undefine this stuff before including scan.c, since it has different
12638 * definitions for these macros.