4 /*-------------------------------------------------------------------------
7 * POSTGRESQL BISON rules/actions
9 * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
10 * Portions Copyright (c) 1994, Regents of the University of California
14 * 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 AlterFdwStmt
186 AlterForeignServerStmt AlterGroupStmt
187 AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterTableStmt
188 AlterCompositeTypeStmt AlterUserStmt AlterUserMappingStmt AlterUserSetStmt
189 AlterRoleStmt AlterRoleSetStmt
190 AlterDefaultPrivilegesStmt DefACLAction
191 AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
192 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
193 CreateDomainStmt CreateGroupStmt CreateOpClassStmt
194 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
195 CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
196 CreateFdwStmt CreateForeignServerStmt CreateAssertStmt CreateTrigStmt
197 CreateUserStmt CreateUserMappingStmt CreateRoleStmt
198 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
199 DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
200 DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
201 DropUserStmt DropdbStmt DropTableSpaceStmt DropFdwStmt
202 DropForeignServerStmt DropUserMappingStmt ExplainStmt FetchStmt
203 GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
204 LockStmt NotifyStmt ExplainableStmt PreparableStmt
205 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
206 RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
207 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
208 SecLabelStmt SelectStmt TransactionStmt TruncateStmt
209 UnlistenStmt UpdateStmt VacuumStmt
210 VariableResetStmt VariableSetStmt VariableShowStmt
211 ViewStmt CheckPointStmt CreateConversionStmt
212 DeallocateStmt PrepareStmt ExecuteStmt
213 DropOwnedStmt ReassignOwnedStmt
214 AlterTSConfigurationStmt AlterTSDictionaryStmt
216 %type <node> select_no_parens select_with_parens select_clause
217 simple_select values_clause
219 %type <node> alter_column_default opclass_item opclass_drop alter_using
220 %type <ival> add_drop opt_asc_desc opt_nulls_order
222 %type <node> alter_table_cmd alter_type_cmd
223 %type <list> alter_table_cmds alter_type_cmds
225 %type <dbehavior> opt_drop_behavior
227 %type <list> createdb_opt_list alterdb_opt_list copy_opt_list
228 transaction_mode_list
229 %type <defelt> createdb_opt_item alterdb_opt_item copy_opt_item
230 transaction_mode_item
232 %type <ival> opt_lock lock_type cast_context
233 %type <ival> vacuum_option_list vacuum_option_elem
234 %type <boolean> opt_force opt_or_replace
235 opt_grant_grant_option opt_grant_admin_option
236 opt_nowait opt_if_exists opt_with_data
238 %type <list> OptRoleList AlterOptRoleList
239 %type <defelt> CreateOptRoleElem AlterOptRoleElem
242 %type <str> foreign_server_version opt_foreign_server_version
243 %type <str> auth_ident
244 %type <str> opt_in_database
246 %type <str> OptSchemaName
247 %type <list> OptSchemaEltList
249 %type <boolean> TriggerForSpec TriggerForType
250 %type <ival> TriggerActionTime
251 %type <list> TriggerEvents TriggerOneEvent
252 %type <value> TriggerFuncArg
253 %type <node> TriggerWhen
255 %type <str> copy_file_name
256 database_name access_method_clause access_method attr_name
257 name cursor_name file_name
258 index_name opt_index_name cluster_index_specification
260 %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
261 opt_class opt_inline_handler opt_validator validator_clause
263 %type <range> qualified_name OptConstrFromTable
265 %type <str> all_Op MathOp
267 %type <str> iso_level opt_encoding
269 %type <list> grantee_list
270 %type <accesspriv> privilege
271 %type <list> privileges privilege_list
272 %type <privtarget> privilege_target
273 %type <funwithargs> function_with_argtypes
274 %type <list> function_with_argtypes_list
275 %type <ival> defacl_privilege_target
276 %type <defelt> DefACLOption
277 %type <list> DefACLOptionList
279 %type <list> stmtblock stmtmulti
280 OptTableElementList TableElementList OptInherit definition
281 OptTypedTableElementList TypedTableElementList
282 reloptions opt_reloptions
283 OptWith opt_distinct opt_definition func_args func_args_list
284 func_args_with_defaults func_args_with_defaults_list
285 func_as createfunc_opt_list alterfunc_opt_list
286 aggr_args old_aggr_definition old_aggr_list
287 oper_argtypes RuleActionList RuleActionMulti
288 opt_column_list columnList opt_name_list
289 sort_clause opt_sort_clause sortby_list index_params
290 name_list from_clause from_list opt_array_bounds
291 qualified_name_list any_name any_name_list
292 any_operator expr_list attrs
293 target_list insert_column_list set_target_list
294 set_clause_list set_clause multiple_set_clause
295 ctext_expr_list ctext_row def_list indirection opt_indirection
296 reloption_list group_clause TriggerFuncArgs select_limit
297 opt_select_limit opclass_item_list opclass_drop_list
298 opt_opfamily transaction_mode_list_or_empty
299 OptTableFuncElementList TableFuncElementList opt_type_modifiers
301 execute_param_clause using_clause returning_clause
302 opt_enum_val_list enum_val_list table_func_column_list
303 create_generic_options alter_generic_options
304 relation_expr_list dostmt_opt_list
306 %type <range> OptTempTableName
307 %type <into> into_clause create_as_target
309 %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
310 %type <fun_param> func_arg func_arg_with_default table_func_column
311 %type <fun_param_mode> arg_class
312 %type <typnam> func_return func_type
314 %type <boolean> OptTemp opt_trusted opt_restart_seqs
315 %type <oncommit> OnCommitOption
317 %type <node> for_locking_item
318 %type <list> for_locking_clause opt_for_locking_clause for_locking_items
319 %type <list> locked_rels_list
320 %type <boolean> opt_all
322 %type <node> join_outer join_qual
323 %type <jtype> join_type
325 %type <list> extract_list overlay_list position_list
326 %type <list> substr_list trim_list
327 %type <list> opt_interval interval_second
328 %type <node> overlay_placing substr_from substr_for
330 %type <boolean> opt_instead
331 %type <boolean> opt_unique opt_concurrently opt_verbose opt_full
332 %type <boolean> opt_freeze opt_default opt_recheck
333 %type <defelt> opt_binary opt_oids copy_delimiter
335 %type <boolean> copy_from
337 %type <ival> opt_column event cursor_options opt_hold opt_set_data
338 %type <objtype> reindex_type drop_type comment_type security_label_type
340 %type <node> fetch_args limit_clause select_limit_value
341 offset_clause select_offset_value
342 select_offset_value2 opt_select_fetch_first_value
343 %type <ival> row_or_rows first_or_next
345 %type <list> OptSeqOptList SeqOptList
346 %type <defelt> SeqOptElem
348 %type <istmt> insert_rest
350 %type <vsetstmt> set_rest SetResetClause
352 %type <node> TableElement TypedTableElement ConstraintElem TableFuncElement
353 %type <node> columnDef columnOptions
354 %type <defelt> def_elem reloption_elem old_aggr_elem
355 %type <node> def_arg columnElem where_clause where_or_current_clause
356 a_expr b_expr c_expr func_expr AexprConst indirection_el
357 columnref in_expr having_clause func_table array_expr
359 %type <list> ExclusionConstraintList ExclusionConstraintElem
360 %type <list> func_arg_list
361 %type <node> func_arg_expr
362 %type <list> row type_list array_expr_list
363 %type <node> case_expr case_arg when_clause case_default
364 %type <list> when_clause_list
365 %type <ival> sub_type
366 %type <list> OptCreateAs CreateAsList
367 %type <node> CreateAsElement ctext_expr
368 %type <value> NumericOnly
369 %type <list> NumericOnly_list
370 %type <alias> alias_clause
371 %type <sortby> sortby
372 %type <ielem> index_elem
373 %type <node> table_ref
374 %type <jexpr> joined_table
375 %type <range> relation_expr
376 %type <range> relation_expr_opt_alias
377 %type <target> target_el single_set_clause set_target insert_column_item
379 %type <str> generic_option_name
380 %type <node> generic_option_arg
381 %type <defelt> generic_option_elem alter_generic_option_elem
382 %type <list> generic_option_list alter_generic_option_list
383 %type <str> explain_option_name
384 %type <node> explain_option_arg
385 %type <defelt> explain_option_elem
386 %type <list> explain_option_list
387 %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
388 %type <defelt> copy_generic_opt_elem
389 %type <list> copy_generic_opt_list copy_generic_opt_arg_list
390 %type <list> copy_options
392 %type <typnam> Typename SimpleTypename ConstTypename
393 GenericType Numeric opt_float
394 Character ConstCharacter
395 CharacterWithLength CharacterWithoutLength
396 ConstDatetime ConstInterval
397 Bit ConstBit BitWithLength BitWithoutLength
398 %type <str> character
399 %type <str> extract_arg
400 %type <str> opt_charset
401 %type <boolean> opt_varying opt_timezone
403 %type <ival> Iconst SignedIconst
404 %type <str> Sconst comment_text notify_payload
405 %type <str> RoleId opt_granted_by opt_boolean ColId_or_Sconst
406 %type <list> var_list
407 %type <str> ColId ColLabel var_name type_function_name param_name
408 %type <node> var_value zone_value
410 %type <keyword> unreserved_keyword type_func_name_keyword
411 %type <keyword> col_name_keyword reserved_keyword
413 %type <node> TableConstraint TableLikeClause
414 %type <ival> TableLikeOptionList TableLikeOption
415 %type <list> ColQualList
416 %type <node> ColConstraint ColConstraintElem ConstraintAttr
417 %type <ival> key_actions key_delete key_match key_update key_action
418 %type <ival> ConstraintAttributeSpec ConstraintDeferrabilitySpec
421 %type <list> constraints_set_list
422 %type <boolean> constraints_set_mode
423 %type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
424 %type <list> opt_check_option
426 %type <str> opt_provider security_label
428 %type <target> xml_attribute_el
429 %type <list> xml_attribute_list xml_attributes
430 %type <node> xml_root_version opt_xml_root_standalone
431 %type <node> xmlexists_argument
432 %type <ival> document_or_content
433 %type <boolean> xml_whitespace_option
435 %type <node> common_table_expr
436 %type <with> with_clause
437 %type <list> cte_list
439 %type <list> window_clause window_definition_list opt_partition_clause
440 %type <windef> window_definition over_clause window_specification
441 opt_frame_clause frame_extent frame_bound
442 %type <str> opt_existing_window_name
446 * Non-keyword token types. These are hard-wired into the "flex" lexer.
447 * They must be listed first so that their numeric codes do not depend on
448 * the set of keywords. PL/pgsql depends on this so that it can share the
449 * same lexer. If you add/change tokens here, fix PL/pgsql to match!
451 * DOT_DOT is unused in the core SQL grammar, and so will always provoke
452 * parse errors. It is needed by PL/pgsql.
454 %token <str> IDENT FCONST SCONST BCONST XCONST Op
455 %token <ival> ICONST PARAM
456 %token TYPECAST DOT_DOT COLON_EQUALS
459 * If you want to make any keyword changes, update the keyword table in
460 * src/include/parser/kwlist.h and add new keywords to the appropriate one
461 * of the reserved-or-not-so-reserved keyword lists, below; search
462 * this file for "Keyword category lists".
465 /* ordinary key words in alphabetical order */
466 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
467 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
468 ASSERTION ASSIGNMENT ASYMMETRIC AT ATTRIBUTE AUTHORIZATION
470 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
473 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
474 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
475 CLUSTER COALESCE COLLATE COLUMN COMMENT COMMENTS COMMIT
476 COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
477 CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
478 CREATEROLE CREATEUSER CROSS CSV CURRENT_P
479 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
480 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
482 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
483 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
484 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
486 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT
487 EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
489 FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOLLOWING FOR FORCE FOREIGN FORWARD
490 FREEZE FROM FULL FUNCTION FUNCTIONS
492 GLOBAL GRANT GRANTED GREATEST GROUP_P
494 HANDLER HAVING HEADER_P HOLD HOUR_P
496 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
497 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
498 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
499 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
505 LABEL LANGUAGE LARGE_P LAST_P LC_COLLATE_P LC_CTYPE_P LEADING
506 LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP
507 LOCATION LOCK_P LOGIN_P
509 MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
511 NAME_P NAMES NATIONAL NATURAL NCHAR NEXT NO NOCREATEDB
512 NOCREATEROLE NOCREATEUSER NOINHERIT NOLOGIN_P NONE NOSUPERUSER
513 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NULLS_P NUMERIC
515 OBJECT_P OF OFF OFFSET OIDS ON ONLY OPERATOR OPTION OPTIONS OR
516 ORDER OUT_P OUTER_P OVER OVERLAPS OVERLAY OWNED OWNER
518 PARSER PARTIAL PARTITION PASSING PASSWORD PLACING PLANS POSITION
519 PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
520 PRIOR PRIVILEGES PROCEDURAL PROCEDURE
524 RANGE READ REAL REASSIGN RECHECK RECURSIVE REF REFERENCES REINDEX
525 RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA RESET RESTART
526 RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROW ROWS RULE
528 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE SEQUENCES
529 SERIALIZABLE SERVER SESSION SESSION_USER SET SETOF SHARE
530 SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT
531 STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING SUPERUSER_P
532 SYMMETRIC SYSID SYSTEM_P
534 TABLE TABLES TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
535 TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
536 TRUNCATE TRUSTED TYPE_P
538 UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
541 VACUUM VALID VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
542 VERBOSE VERSION_P VIEW VOLATILE
544 WHEN WHERE WHITESPACE_P WINDOW WITH WITHOUT WORK WRAPPER WRITE
546 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLPARSE
547 XMLPI XMLROOT XMLSERIALIZE
554 * The grammar thinks these are keywords, but they are not in the kwlist.h
555 * list and so can never be entered directly. The filter in parser.c
556 * creates these tokens when required.
558 %token NULLS_FIRST NULLS_LAST WITH_TIME
561 /* Precedence: lowest to highest */
562 %nonassoc SET /* see relation_expr_opt_alias */
570 %nonassoc LIKE ILIKE SIMILAR
575 %left POSTFIXOP /* dummy for postfix Op rules */
577 * To support target_el without AS, we must give IDENT an explicit priority
578 * between POSTFIXOP and Op. We can safely assign the same priority to
579 * various unreserved keywords as needed to resolve ambiguities (this can't
580 * have any bad effects since obviously the keywords will still behave the
581 * same as if they weren't keywords). We need to do this for PARTITION,
582 * RANGE, ROWS to support opt_existing_window_name; and for RANGE, ROWS
583 * so that they can follow a_expr without creating
584 * postfix-operator problems.
586 * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
587 * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
588 * there is no principled way to distinguish these from the productions
589 * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
590 * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
591 * appear to cause UNBOUNDED to be treated differently from other unreserved
592 * keywords anywhere else in the grammar, but it's definitely risky. We can
593 * blame any funny behavior of UNBOUNDED on the SQL standard, though.
595 %nonassoc UNBOUNDED /* ideally should have same precedence as IDENT */
596 %nonassoc IDENT PARTITION RANGE ROWS PRECEDING FOLLOWING
597 %left Op OPERATOR /* multi-character ops and user-defined operators */
600 %nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN /* sets precedence for IS NULL, etc */
604 /* Unary Operators */
605 %left AT ZONE /* sets precedence for AT TIME ZONE */
612 * These might seem to be low-precedence, but actually they are not part
613 * of the arithmetic hierarchy at all in their use as JOIN operators.
614 * We make them high-precedence to support their use as function names.
615 * They wouldn't be given a precedence at all, were it not that we need
616 * left-associativity among the JOIN rules themselves.
618 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
619 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
620 %right PRESERVE STRIP_P
625 * The target production for the whole parse.
629 pg_yyget_extra(yyscanner)->parsetree = $1;
633 /* the thrashing around here is to discard "empty" statements... */
634 stmtmulti: stmtmulti ';' stmt
637 $$ = lappend($1, $3);
652 | AlterDatabaseSetStmt
653 | AlterDefaultPrivilegesStmt
656 | AlterForeignServerStmt
659 | AlterObjectSchemaStmt
663 | AlterCompositeTypeStmt
666 | AlterTSConfigurationStmt
667 | AlterTSDictionaryStmt
668 | AlterUserMappingStmt
681 | CreateConversionStmt
684 | CreateForeignServerStmt
694 | CreateTableSpaceStmt
698 | CreateUserMappingStmt
709 | DropForeignServerStmt
721 | DropUserMappingStmt
759 /*****************************************************************************
761 * Create a new Postgres DBMS role
763 *****************************************************************************/
766 CREATE ROLE RoleId opt_with OptRoleList
768 CreateRoleStmt *n = makeNode(CreateRoleStmt);
769 n->stmt_type = ROLESTMT_ROLE;
782 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
783 * for backwards compatibility). Note: the only option required by SQL99
784 * is "WITH ADMIN name".
787 OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
788 | /* EMPTY */ { $$ = NIL; }
792 AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
793 | /* EMPTY */ { $$ = NIL; }
799 $$ = makeDefElem("password",
800 (Node *)makeString($2));
804 $$ = makeDefElem("password", NULL);
806 | ENCRYPTED PASSWORD Sconst
808 $$ = makeDefElem("encryptedPassword",
809 (Node *)makeString($3));
811 | UNENCRYPTED PASSWORD Sconst
813 $$ = makeDefElem("unencryptedPassword",
814 (Node *)makeString($3));
818 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
822 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
826 $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE));
830 $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE));
834 $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
838 $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
842 $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE));
846 $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE));
850 /* For backwards compatibility, synonym for SUPERUSER */
851 $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
855 $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
859 $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE));
863 $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE));
865 | CONNECTION LIMIT SignedIconst
867 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3));
871 $$ = makeDefElem("validUntil", (Node *)makeString($3));
873 /* Supported but not documented for roles, for use by ALTER GROUP. */
876 $$ = makeDefElem("rolemembers", (Node *)$2);
881 AlterOptRoleElem { $$ = $1; }
882 /* The following are not supported by ALTER ROLE/USER/GROUP */
885 $$ = makeDefElem("sysid", (Node *)makeInteger($2));
889 $$ = makeDefElem("adminmembers", (Node *)$2);
893 $$ = makeDefElem("rolemembers", (Node *)$2);
895 | IN_P ROLE name_list
897 $$ = makeDefElem("addroleto", (Node *)$3);
899 | IN_P GROUP_P name_list
901 $$ = makeDefElem("addroleto", (Node *)$3);
906 /*****************************************************************************
908 * Create a new Postgres DBMS user (role with implied login ability)
910 *****************************************************************************/
913 CREATE USER RoleId opt_with OptRoleList
915 CreateRoleStmt *n = makeNode(CreateRoleStmt);
916 n->stmt_type = ROLESTMT_USER;
924 /*****************************************************************************
926 * Alter a postgresql DBMS role
928 *****************************************************************************/
931 ALTER ROLE RoleId opt_with AlterOptRoleList
933 AlterRoleStmt *n = makeNode(AlterRoleStmt);
935 n->action = +1; /* add, if there are members */
942 /* EMPTY */ { $$ = NULL; }
943 | IN_P DATABASE database_name { $$ = $3; }
947 ALTER ROLE RoleId opt_in_database SetResetClause
949 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
958 /*****************************************************************************
960 * Alter a postgresql DBMS user
962 *****************************************************************************/
965 ALTER USER RoleId opt_with AlterOptRoleList
967 AlterRoleStmt *n = makeNode(AlterRoleStmt);
969 n->action = +1; /* add, if there are members */
977 ALTER USER RoleId SetResetClause
979 AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
988 /*****************************************************************************
990 * Drop a postgresql DBMS role
992 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
993 * might own objects in multiple databases, there is presently no way to
994 * implement either cascading or restricting. Caveat DBA.
995 *****************************************************************************/
1000 DropRoleStmt *n = makeNode(DropRoleStmt);
1001 n->missing_ok = FALSE;
1005 | DROP ROLE IF_P EXISTS name_list
1007 DropRoleStmt *n = makeNode(DropRoleStmt);
1008 n->missing_ok = TRUE;
1014 /*****************************************************************************
1016 * Drop a postgresql DBMS user
1018 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
1019 * might own objects in multiple databases, there is presently no way to
1020 * implement either cascading or restricting. Caveat DBA.
1021 *****************************************************************************/
1026 DropRoleStmt *n = makeNode(DropRoleStmt);
1027 n->missing_ok = FALSE;
1031 | DROP USER IF_P EXISTS name_list
1033 DropRoleStmt *n = makeNode(DropRoleStmt);
1035 n->missing_ok = TRUE;
1041 /*****************************************************************************
1043 * Create a postgresql group (role without login ability)
1045 *****************************************************************************/
1048 CREATE GROUP_P RoleId opt_with OptRoleList
1050 CreateRoleStmt *n = makeNode(CreateRoleStmt);
1051 n->stmt_type = ROLESTMT_GROUP;
1059 /*****************************************************************************
1061 * Alter a postgresql group
1063 *****************************************************************************/
1066 ALTER GROUP_P RoleId add_drop USER name_list
1068 AlterRoleStmt *n = makeNode(AlterRoleStmt);
1071 n->options = list_make1(makeDefElem("rolemembers",
1077 add_drop: ADD_P { $$ = +1; }
1082 /*****************************************************************************
1084 * Drop a postgresql group
1086 * XXX see above notes about cascading DROP USER; groups have same problem.
1087 *****************************************************************************/
1090 DROP GROUP_P name_list
1092 DropRoleStmt *n = makeNode(DropRoleStmt);
1093 n->missing_ok = FALSE;
1097 | DROP GROUP_P IF_P EXISTS name_list
1099 DropRoleStmt *n = makeNode(DropRoleStmt);
1100 n->missing_ok = TRUE;
1107 /*****************************************************************************
1109 * Manipulate a schema
1111 *****************************************************************************/
1114 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
1116 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1117 /* One can omit the schema name or the authorization id. */
1126 | CREATE SCHEMA ColId OptSchemaEltList
1128 CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
1129 /* ...but not both */
1139 | /* EMPTY */ { $$ = NULL; }
1143 OptSchemaEltList schema_stmt { $$ = lappend($1, $2); }
1144 | /* EMPTY */ { $$ = NIL; }
1148 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1149 * statement (in addition to by themselves).
1161 /*****************************************************************************
1163 * Set PG internal variable
1164 * SET name TO 'var_value'
1165 * Include SQL92 syntax (thomas 1997-10-22):
1166 * SET TIME ZONE 'var_value'
1168 *****************************************************************************/
1173 VariableSetStmt *n = $2;
1174 n->is_local = false;
1177 | SET LOCAL set_rest
1179 VariableSetStmt *n = $3;
1183 | SET SESSION set_rest
1185 VariableSetStmt *n = $3;
1186 n->is_local = false;
1191 set_rest: /* Generic SET syntaxes: */
1192 var_name TO var_list
1194 VariableSetStmt *n = makeNode(VariableSetStmt);
1195 n->kind = VAR_SET_VALUE;
1200 | var_name '=' var_list
1202 VariableSetStmt *n = makeNode(VariableSetStmt);
1203 n->kind = VAR_SET_VALUE;
1208 | var_name TO DEFAULT
1210 VariableSetStmt *n = makeNode(VariableSetStmt);
1211 n->kind = VAR_SET_DEFAULT;
1215 | var_name '=' DEFAULT
1217 VariableSetStmt *n = makeNode(VariableSetStmt);
1218 n->kind = VAR_SET_DEFAULT;
1222 | var_name FROM CURRENT_P
1224 VariableSetStmt *n = makeNode(VariableSetStmt);
1225 n->kind = VAR_SET_CURRENT;
1229 /* Special syntaxes mandated by SQL standard: */
1230 | TIME ZONE zone_value
1232 VariableSetStmt *n = makeNode(VariableSetStmt);
1233 n->kind = VAR_SET_VALUE;
1234 n->name = "timezone";
1236 n->args = list_make1($3);
1238 n->kind = VAR_SET_DEFAULT;
1241 | TRANSACTION transaction_mode_list
1243 VariableSetStmt *n = makeNode(VariableSetStmt);
1244 n->kind = VAR_SET_MULTI;
1245 n->name = "TRANSACTION";
1249 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1251 VariableSetStmt *n = makeNode(VariableSetStmt);
1252 n->kind = VAR_SET_MULTI;
1253 n->name = "SESSION CHARACTERISTICS";
1260 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1261 errmsg("current database cannot be changed"),
1262 parser_errposition(@2)));
1263 $$ = NULL; /*not reached*/
1267 VariableSetStmt *n = makeNode(VariableSetStmt);
1268 n->kind = VAR_SET_VALUE;
1269 n->name = "search_path";
1270 n->args = list_make1(makeStringConst($2, @2));
1273 | NAMES opt_encoding
1275 VariableSetStmt *n = makeNode(VariableSetStmt);
1276 n->kind = VAR_SET_VALUE;
1277 n->name = "client_encoding";
1279 n->args = list_make1(makeStringConst($2, @2));
1281 n->kind = VAR_SET_DEFAULT;
1284 | ROLE ColId_or_Sconst
1286 VariableSetStmt *n = makeNode(VariableSetStmt);
1287 n->kind = VAR_SET_VALUE;
1289 n->args = list_make1(makeStringConst($2, @2));
1292 | SESSION AUTHORIZATION ColId_or_Sconst
1294 VariableSetStmt *n = makeNode(VariableSetStmt);
1295 n->kind = VAR_SET_VALUE;
1296 n->name = "session_authorization";
1297 n->args = list_make1(makeStringConst($3, @3));
1300 | SESSION AUTHORIZATION DEFAULT
1302 VariableSetStmt *n = makeNode(VariableSetStmt);
1303 n->kind = VAR_SET_DEFAULT;
1304 n->name = "session_authorization";
1307 | XML_P OPTION document_or_content
1309 VariableSetStmt *n = makeNode(VariableSetStmt);
1310 n->kind = VAR_SET_VALUE;
1311 n->name = "xmloption";
1312 n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
1317 var_name: ColId { $$ = $1; }
1318 | var_name '.' ColId
1320 $$ = palloc(strlen($1) + strlen($3) + 2);
1321 sprintf($$, "%s.%s", $1, $3);
1325 var_list: var_value { $$ = list_make1($1); }
1326 | var_list ',' var_value { $$ = lappend($1, $3); }
1329 var_value: opt_boolean
1330 { $$ = makeStringConst($1, @1); }
1332 { $$ = makeStringConst($1, @1); }
1334 { $$ = makeAConst($1, @1); }
1337 iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
1338 | READ COMMITTED { $$ = "read committed"; }
1339 | REPEATABLE READ { $$ = "repeatable read"; }
1340 | SERIALIZABLE { $$ = "serializable"; }
1344 TRUE_P { $$ = "true"; }
1345 | FALSE_P { $$ = "false"; }
1347 | OFF { $$ = "off"; }
1350 /* Timezone values can be:
1351 * - a string such as 'pst8pdt'
1352 * - an identifier such as "pst8pdt"
1353 * - an integer or floating point number
1354 * - a time interval per SQL99
1355 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1356 * so use IDENT (meaning we reject anything that is a key word).
1361 $$ = makeStringConst($1, @1);
1365 $$ = makeStringConst($1, @1);
1367 | ConstInterval Sconst opt_interval
1372 A_Const *n = (A_Const *) linitial($3);
1373 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1375 (errcode(ERRCODE_SYNTAX_ERROR),
1376 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1377 parser_errposition(@3)));
1380 $$ = makeStringConstCast($2, @2, t);
1382 | ConstInterval '(' Iconst ')' Sconst opt_interval
1387 A_Const *n = (A_Const *) linitial($6);
1388 if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1390 (errcode(ERRCODE_SYNTAX_ERROR),
1391 errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1392 parser_errposition(@6)));
1393 if (list_length($6) != 1)
1395 (errcode(ERRCODE_SYNTAX_ERROR),
1396 errmsg("interval precision specified twice"),
1397 parser_errposition(@1)));
1398 t->typmods = lappend($6, makeIntConst($3, @3));
1401 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1402 makeIntConst($3, @3));
1403 $$ = makeStringConstCast($5, @5, t);
1405 | NumericOnly { $$ = makeAConst($1, @1); }
1406 | DEFAULT { $$ = NULL; }
1407 | LOCAL { $$ = NULL; }
1412 | DEFAULT { $$ = NULL; }
1413 | /*EMPTY*/ { $$ = NULL; }
1418 | Sconst { $$ = $1; }
1424 VariableSetStmt *n = makeNode(VariableSetStmt);
1425 n->kind = VAR_RESET;
1431 VariableSetStmt *n = makeNode(VariableSetStmt);
1432 n->kind = VAR_RESET;
1433 n->name = "timezone";
1436 | RESET TRANSACTION ISOLATION LEVEL
1438 VariableSetStmt *n = makeNode(VariableSetStmt);
1439 n->kind = VAR_RESET;
1440 n->name = "transaction_isolation";
1443 | RESET SESSION AUTHORIZATION
1445 VariableSetStmt *n = makeNode(VariableSetStmt);
1446 n->kind = VAR_RESET;
1447 n->name = "session_authorization";
1452 VariableSetStmt *n = makeNode(VariableSetStmt);
1453 n->kind = VAR_RESET_ALL;
1458 /* SetResetClause allows SET or RESET without LOCAL */
1460 SET set_rest { $$ = $2; }
1461 | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
1468 VariableShowStmt *n = makeNode(VariableShowStmt);
1474 VariableShowStmt *n = makeNode(VariableShowStmt);
1475 n->name = "timezone";
1478 | SHOW TRANSACTION ISOLATION LEVEL
1480 VariableShowStmt *n = makeNode(VariableShowStmt);
1481 n->name = "transaction_isolation";
1484 | SHOW SESSION AUTHORIZATION
1486 VariableShowStmt *n = makeNode(VariableShowStmt);
1487 n->name = "session_authorization";
1492 VariableShowStmt *n = makeNode(VariableShowStmt);
1500 SET CONSTRAINTS constraints_set_list constraints_set_mode
1502 ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
1503 n->constraints = $3;
1509 constraints_set_list:
1511 | qualified_name_list { $$ = $1; }
1514 constraints_set_mode:
1515 DEFERRED { $$ = TRUE; }
1516 | IMMEDIATE { $$ = FALSE; }
1521 * Checkpoint statement
1526 CheckPointStmt *n = makeNode(CheckPointStmt);
1532 /*****************************************************************************
1534 * DISCARD { ALL | TEMP | PLANS }
1536 *****************************************************************************/
1541 DiscardStmt *n = makeNode(DiscardStmt);
1542 n->target = DISCARD_ALL;
1547 DiscardStmt *n = makeNode(DiscardStmt);
1548 n->target = DISCARD_TEMP;
1553 DiscardStmt *n = makeNode(DiscardStmt);
1554 n->target = DISCARD_TEMP;
1559 DiscardStmt *n = makeNode(DiscardStmt);
1560 n->target = DISCARD_PLANS;
1566 /*****************************************************************************
1568 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations
1570 * Note: we accept all subcommands for each of the four variants, and sort
1571 * out what's really legal at execution time.
1572 *****************************************************************************/
1575 ALTER TABLE relation_expr alter_table_cmds
1577 AlterTableStmt *n = makeNode(AlterTableStmt);
1580 n->relkind = OBJECT_TABLE;
1583 | ALTER INDEX qualified_name alter_table_cmds
1585 AlterTableStmt *n = makeNode(AlterTableStmt);
1588 n->relkind = OBJECT_INDEX;
1591 | ALTER SEQUENCE qualified_name alter_table_cmds
1593 AlterTableStmt *n = makeNode(AlterTableStmt);
1596 n->relkind = OBJECT_SEQUENCE;
1599 | ALTER VIEW qualified_name alter_table_cmds
1601 AlterTableStmt *n = makeNode(AlterTableStmt);
1604 n->relkind = OBJECT_VIEW;
1610 alter_table_cmd { $$ = list_make1($1); }
1611 | alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
1615 /* ALTER TABLE <name> ADD <coldef> */
1618 AlterTableCmd *n = makeNode(AlterTableCmd);
1619 n->subtype = AT_AddColumn;
1623 /* ALTER TABLE <name> ADD COLUMN <coldef> */
1624 | ADD_P COLUMN columnDef
1626 AlterTableCmd *n = makeNode(AlterTableCmd);
1627 n->subtype = AT_AddColumn;
1631 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1632 | ALTER opt_column ColId alter_column_default
1634 AlterTableCmd *n = makeNode(AlterTableCmd);
1635 n->subtype = AT_ColumnDefault;
1640 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1641 | ALTER opt_column ColId DROP NOT NULL_P
1643 AlterTableCmd *n = makeNode(AlterTableCmd);
1644 n->subtype = AT_DropNotNull;
1648 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1649 | ALTER opt_column ColId SET NOT NULL_P
1651 AlterTableCmd *n = makeNode(AlterTableCmd);
1652 n->subtype = AT_SetNotNull;
1656 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
1657 | ALTER opt_column ColId SET STATISTICS SignedIconst
1659 AlterTableCmd *n = makeNode(AlterTableCmd);
1660 n->subtype = AT_SetStatistics;
1662 n->def = (Node *) makeInteger($6);
1665 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
1666 | ALTER opt_column ColId SET reloptions
1668 AlterTableCmd *n = makeNode(AlterTableCmd);
1669 n->subtype = AT_SetOptions;
1671 n->def = (Node *) $5;
1674 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
1675 | ALTER opt_column ColId RESET reloptions
1677 AlterTableCmd *n = makeNode(AlterTableCmd);
1678 n->subtype = AT_ResetOptions;
1680 n->def = (Node *) $5;
1683 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1684 | ALTER opt_column ColId SET STORAGE ColId
1686 AlterTableCmd *n = makeNode(AlterTableCmd);
1687 n->subtype = AT_SetStorage;
1689 n->def = (Node *) makeString($6);
1692 /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
1693 | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
1695 AlterTableCmd *n = makeNode(AlterTableCmd);
1696 n->subtype = AT_DropColumn;
1699 n->missing_ok = TRUE;
1702 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1703 | DROP opt_column ColId opt_drop_behavior
1705 AlterTableCmd *n = makeNode(AlterTableCmd);
1706 n->subtype = AT_DropColumn;
1709 n->missing_ok = FALSE;
1713 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
1714 * [ USING <expression> ]
1716 | ALTER opt_column ColId opt_set_data TYPE_P Typename alter_using
1718 AlterTableCmd *n = makeNode(AlterTableCmd);
1719 n->subtype = AT_AlterColumnType;
1721 n->def = (Node *) $6;
1725 /* ALTER TABLE <name> ADD CONSTRAINT ... */
1726 | ADD_P TableConstraint
1728 AlterTableCmd *n = makeNode(AlterTableCmd);
1729 n->subtype = AT_AddConstraint;
1733 /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
1734 | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
1736 AlterTableCmd *n = makeNode(AlterTableCmd);
1737 n->subtype = AT_DropConstraint;
1740 n->missing_ok = TRUE;
1743 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1744 | DROP CONSTRAINT name opt_drop_behavior
1746 AlterTableCmd *n = makeNode(AlterTableCmd);
1747 n->subtype = AT_DropConstraint;
1750 n->missing_ok = FALSE;
1753 /* ALTER TABLE <name> SET WITH OIDS */
1756 AlterTableCmd *n = makeNode(AlterTableCmd);
1757 n->subtype = AT_AddOids;
1760 /* ALTER TABLE <name> SET WITHOUT OIDS */
1763 AlterTableCmd *n = makeNode(AlterTableCmd);
1764 n->subtype = AT_DropOids;
1767 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1770 AlterTableCmd *n = makeNode(AlterTableCmd);
1771 n->subtype = AT_ClusterOn;
1775 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1776 | SET WITHOUT CLUSTER
1778 AlterTableCmd *n = makeNode(AlterTableCmd);
1779 n->subtype = AT_DropCluster;
1783 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
1784 | ENABLE_P TRIGGER name
1786 AlterTableCmd *n = makeNode(AlterTableCmd);
1787 n->subtype = AT_EnableTrig;
1791 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
1792 | ENABLE_P ALWAYS TRIGGER name
1794 AlterTableCmd *n = makeNode(AlterTableCmd);
1795 n->subtype = AT_EnableAlwaysTrig;
1799 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
1800 | ENABLE_P REPLICA TRIGGER name
1802 AlterTableCmd *n = makeNode(AlterTableCmd);
1803 n->subtype = AT_EnableReplicaTrig;
1807 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
1808 | ENABLE_P TRIGGER ALL
1810 AlterTableCmd *n = makeNode(AlterTableCmd);
1811 n->subtype = AT_EnableTrigAll;
1814 /* ALTER TABLE <name> ENABLE TRIGGER USER */
1815 | ENABLE_P TRIGGER USER
1817 AlterTableCmd *n = makeNode(AlterTableCmd);
1818 n->subtype = AT_EnableTrigUser;
1821 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
1822 | DISABLE_P TRIGGER name
1824 AlterTableCmd *n = makeNode(AlterTableCmd);
1825 n->subtype = AT_DisableTrig;
1829 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
1830 | DISABLE_P TRIGGER ALL
1832 AlterTableCmd *n = makeNode(AlterTableCmd);
1833 n->subtype = AT_DisableTrigAll;
1836 /* ALTER TABLE <name> DISABLE TRIGGER USER */
1837 | DISABLE_P TRIGGER USER
1839 AlterTableCmd *n = makeNode(AlterTableCmd);
1840 n->subtype = AT_DisableTrigUser;
1843 /* ALTER TABLE <name> ENABLE RULE <rule> */
1844 | ENABLE_P RULE name
1846 AlterTableCmd *n = makeNode(AlterTableCmd);
1847 n->subtype = AT_EnableRule;
1851 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
1852 | ENABLE_P ALWAYS RULE name
1854 AlterTableCmd *n = makeNode(AlterTableCmd);
1855 n->subtype = AT_EnableAlwaysRule;
1859 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
1860 | ENABLE_P REPLICA RULE name
1862 AlterTableCmd *n = makeNode(AlterTableCmd);
1863 n->subtype = AT_EnableReplicaRule;
1867 /* ALTER TABLE <name> DISABLE RULE <rule> */
1868 | DISABLE_P RULE name
1870 AlterTableCmd *n = makeNode(AlterTableCmd);
1871 n->subtype = AT_DisableRule;
1875 /* ALTER TABLE <name> INHERIT <parent> */
1876 | INHERIT qualified_name
1878 AlterTableCmd *n = makeNode(AlterTableCmd);
1879 n->subtype = AT_AddInherit;
1880 n->def = (Node *) $2;
1883 /* ALTER TABLE <name> NO INHERIT <parent> */
1884 | NO INHERIT qualified_name
1886 AlterTableCmd *n = makeNode(AlterTableCmd);
1887 n->subtype = AT_DropInherit;
1888 n->def = (Node *) $3;
1891 /* ALTER TABLE <name> OWNER TO RoleId */
1894 AlterTableCmd *n = makeNode(AlterTableCmd);
1895 n->subtype = AT_ChangeOwner;
1899 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1900 | SET TABLESPACE name
1902 AlterTableCmd *n = makeNode(AlterTableCmd);
1903 n->subtype = AT_SetTableSpace;
1907 /* ALTER TABLE <name> SET (...) */
1910 AlterTableCmd *n = makeNode(AlterTableCmd);
1911 n->subtype = AT_SetRelOptions;
1912 n->def = (Node *)$2;
1915 /* ALTER TABLE <name> RESET (...) */
1918 AlterTableCmd *n = makeNode(AlterTableCmd);
1919 n->subtype = AT_ResetRelOptions;
1920 n->def = (Node *)$2;
1925 alter_column_default:
1926 SET DEFAULT a_expr { $$ = $3; }
1927 | DROP DEFAULT { $$ = NULL; }
1931 CASCADE { $$ = DROP_CASCADE; }
1932 | RESTRICT { $$ = DROP_RESTRICT; }
1933 | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1937 USING a_expr { $$ = $2; }
1938 | /* EMPTY */ { $$ = NULL; }
1942 '(' reloption_list ')' { $$ = $2; }
1945 opt_reloptions: WITH reloptions { $$ = $2; }
1946 | /* EMPTY */ { $$ = NIL; }
1950 reloption_elem { $$ = list_make1($1); }
1951 | reloption_list ',' reloption_elem { $$ = lappend($1, $3); }
1954 /* This should match def_elem and also allow qualified names */
1956 ColLabel '=' def_arg
1958 $$ = makeDefElem($1, (Node *) $3);
1962 $$ = makeDefElem($1, NULL);
1964 | ColLabel '.' ColLabel '=' def_arg
1966 $$ = makeDefElemExtended($1, $3, (Node *) $5,
1969 | ColLabel '.' ColLabel
1971 $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC);
1976 /*****************************************************************************
1980 * really variants of the ALTER TABLE subcommands with different spellings
1981 *****************************************************************************/
1983 AlterCompositeTypeStmt:
1984 ALTER TYPE_P any_name alter_type_cmds
1986 AlterTableStmt *n = makeNode(AlterTableStmt);
1988 /* can't use qualified_name, sigh */
1989 n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
1991 n->relkind = OBJECT_TYPE;
1997 alter_type_cmd { $$ = list_make1($1); }
1998 | alter_type_cmds ',' alter_type_cmd { $$ = lappend($1, $3); }
2002 /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> */
2003 ADD_P ATTRIBUTE TableFuncElement
2005 AlterTableCmd *n = makeNode(AlterTableCmd);
2006 n->subtype = AT_AddColumn;
2010 /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> */
2011 | DROP ATTRIBUTE IF_P EXISTS ColId
2013 AlterTableCmd *n = makeNode(AlterTableCmd);
2014 n->subtype = AT_DropColumn;
2016 n->behavior = DROP_RESTRICT; /* currently no effect */
2017 n->missing_ok = TRUE;
2020 /* ALTER TYPE <name> DROP ATTRIBUTE <attname> */
2021 | DROP ATTRIBUTE ColId opt_drop_behavior
2023 AlterTableCmd *n = makeNode(AlterTableCmd);
2024 n->subtype = AT_DropColumn;
2026 n->behavior = DROP_RESTRICT; /* currently no effect */
2027 n->missing_ok = FALSE;
2030 /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> */
2031 | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename
2033 AlterTableCmd *n = makeNode(AlterTableCmd);
2034 n->subtype = AT_AlterColumnType;
2036 n->def = (Node *) $6;
2042 /*****************************************************************************
2045 * close <portalname>
2047 *****************************************************************************/
2052 ClosePortalStmt *n = makeNode(ClosePortalStmt);
2058 ClosePortalStmt *n = makeNode(ClosePortalStmt);
2059 n->portalname = NULL;
2065 /*****************************************************************************
2068 * COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
2069 * COPY ( SELECT ... ) TO file [WITH] [(options)]
2071 * In the preferred syntax the options are comma-separated
2072 * and use generic identifiers instead of keywords. The pre-9.0
2073 * syntax had a hard-wired, space-separated set of options.
2075 * Really old syntax, from versions 7.2 and prior:
2076 * COPY [ BINARY ] table [ WITH OIDS ] FROM/TO file
2077 * [ [ USING ] DELIMITERS 'delimiter' ] ]
2078 * [ WITH NULL AS 'null string' ]
2079 * This option placement is not supported with COPY (SELECT...).
2081 *****************************************************************************/
2083 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
2084 copy_from copy_file_name copy_delimiter opt_with copy_options
2086 CopyStmt *n = makeNode(CopyStmt);
2094 /* Concatenate user-supplied flags */
2096 n->options = lappend(n->options, $2);
2098 n->options = lappend(n->options, $5);
2100 n->options = lappend(n->options, $8);
2102 n->options = list_concat(n->options, $10);
2105 | COPY select_with_parens TO copy_file_name opt_with copy_options
2107 CopyStmt *n = makeNode(CopyStmt);
2120 | TO { $$ = FALSE; }
2124 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
2125 * used depends on the direction. (It really doesn't make sense to copy from
2126 * stdout. We silently correct the "typo".) - AY 9/94
2130 | STDIN { $$ = NULL; }
2131 | STDOUT { $$ = NULL; }
2134 copy_options: copy_opt_list { $$ = $1; }
2135 | '(' copy_generic_opt_list ')' { $$ = $2; }
2138 /* old COPY option syntax */
2140 copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
2141 | /* EMPTY */ { $$ = NIL; }
2147 $$ = makeDefElem("format", (Node *)makeString("binary"));
2151 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2153 | DELIMITER opt_as Sconst
2155 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2157 | NULL_P opt_as Sconst
2159 $$ = makeDefElem("null", (Node *)makeString($3));
2163 $$ = makeDefElem("format", (Node *)makeString("csv"));
2167 $$ = makeDefElem("header", (Node *)makeInteger(TRUE));
2169 | QUOTE opt_as Sconst
2171 $$ = makeDefElem("quote", (Node *)makeString($3));
2173 | ESCAPE opt_as Sconst
2175 $$ = makeDefElem("escape", (Node *)makeString($3));
2177 | FORCE QUOTE columnList
2179 $$ = makeDefElem("force_quote", (Node *)$3);
2183 $$ = makeDefElem("force_quote", (Node *)makeNode(A_Star));
2185 | FORCE NOT NULL_P columnList
2187 $$ = makeDefElem("force_not_null", (Node *)$4);
2191 /* The following exist for backward compatibility with very old versions */
2196 $$ = makeDefElem("format", (Node *)makeString("binary"));
2198 | /*EMPTY*/ { $$ = NULL; }
2204 $$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
2206 | /*EMPTY*/ { $$ = NULL; }
2210 opt_using DELIMITERS Sconst
2212 $$ = makeDefElem("delimiter", (Node *)makeString($3));
2214 | /*EMPTY*/ { $$ = NULL; }
2222 /* new COPY option syntax */
2223 copy_generic_opt_list:
2224 copy_generic_opt_elem
2226 $$ = list_make1($1);
2228 | copy_generic_opt_list ',' copy_generic_opt_elem
2230 $$ = lappend($1, $3);
2234 copy_generic_opt_elem:
2235 ColLabel copy_generic_opt_arg
2237 $$ = makeDefElem($1, $2);
2241 copy_generic_opt_arg:
2242 opt_boolean { $$ = (Node *) makeString($1); }
2243 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
2244 | NumericOnly { $$ = (Node *) $1; }
2245 | '*' { $$ = (Node *) makeNode(A_Star); }
2246 | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
2247 | /* EMPTY */ { $$ = NULL; }
2250 copy_generic_opt_arg_list:
2251 copy_generic_opt_arg_list_item
2253 $$ = list_make1($1);
2255 | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
2257 $$ = lappend($1, $3);
2261 /* beware of emitting non-string list elements here; see commands/define.c */
2262 copy_generic_opt_arg_list_item:
2263 opt_boolean { $$ = (Node *) makeString($1); }
2264 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
2268 /*****************************************************************************
2271 * CREATE TABLE relname
2273 *****************************************************************************/
2275 CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
2276 OptInherit OptWith OnCommitOption OptTableSpace
2278 CreateStmt *n = makeNode(CreateStmt);
2282 n->inhRelations = $8;
2283 n->constraints = NIL;
2286 n->tablespacename = $11;
2287 n->if_not_exists = false;
2290 | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
2291 OptTableElementList ')' OptInherit OptWith OnCommitOption
2294 CreateStmt *n = makeNode(CreateStmt);
2298 n->inhRelations = $11;
2299 n->constraints = NIL;
2302 n->tablespacename = $14;
2303 n->if_not_exists = true;
2306 | CREATE OptTemp TABLE qualified_name OF any_name
2307 OptTypedTableElementList OptWith OnCommitOption OptTableSpace
2309 CreateStmt *n = makeNode(CreateStmt);
2313 n->ofTypename = makeTypeNameFromNameList($6);
2314 n->ofTypename->location = @6;
2315 n->constraints = NIL;
2318 n->tablespacename = $10;
2319 n->if_not_exists = false;
2322 | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
2323 OptTypedTableElementList OptWith OnCommitOption OptTableSpace
2325 CreateStmt *n = makeNode(CreateStmt);
2329 n->ofTypename = makeTypeNameFromNameList($9);
2330 n->ofTypename->location = @9;
2331 n->constraints = NIL;
2334 n->tablespacename = $13;
2335 n->if_not_exists = true;
2341 * Redundancy here is needed to avoid shift/reduce conflicts,
2342 * since TEMP is not a reserved word. See also OptTempTableName.
2344 * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
2345 * the LOCAL keyword is really meaningless.
2347 OptTemp: TEMPORARY { $$ = TRUE; }
2348 | TEMP { $$ = TRUE; }
2349 | LOCAL TEMPORARY { $$ = TRUE; }
2350 | LOCAL TEMP { $$ = TRUE; }
2351 | GLOBAL TEMPORARY { $$ = TRUE; }
2352 | GLOBAL TEMP { $$ = TRUE; }
2353 | /*EMPTY*/ { $$ = FALSE; }
2356 OptTableElementList:
2357 TableElementList { $$ = $1; }
2358 | /*EMPTY*/ { $$ = NIL; }
2361 OptTypedTableElementList:
2362 '(' TypedTableElementList ')' { $$ = $2; }
2363 | /*EMPTY*/ { $$ = NIL; }
2369 $$ = list_make1($1);
2371 | TableElementList ',' TableElement
2373 $$ = lappend($1, $3);
2377 TypedTableElementList:
2380 $$ = list_make1($1);
2382 | TypedTableElementList ',' TypedTableElement
2384 $$ = lappend($1, $3);
2389 columnDef { $$ = $1; }
2390 | TableLikeClause { $$ = $1; }
2391 | TableConstraint { $$ = $1; }
2395 columnOptions { $$ = $1; }
2396 | TableConstraint { $$ = $1; }
2399 columnDef: ColId Typename ColQualList
2401 ColumnDef *n = makeNode(ColumnDef);
2404 n->constraints = $3;
2410 columnOptions: ColId WITH OPTIONS ColQualList
2412 ColumnDef *n = makeNode(ColumnDef);
2414 n->constraints = $4;
2421 ColQualList ColConstraint { $$ = lappend($1, $2); }
2422 | /*EMPTY*/ { $$ = NIL; }
2426 CONSTRAINT name ColConstraintElem
2428 Constraint *n = (Constraint *) $3;
2429 Assert(IsA(n, Constraint));
2434 | ColConstraintElem { $$ = $1; }
2435 | ConstraintAttr { $$ = $1; }
2438 /* DEFAULT NULL is already the default for Postgres.
2439 * But define it here and carry it forward into the system
2440 * to make it explicit.
2441 * - thomas 1998-09-13
2443 * WITH NULL and NULL are not SQL92-standard syntax elements,
2444 * so leave them out. Use DEFAULT NULL to explicitly indicate
2445 * that a column may have that value. WITH NULL leads to
2446 * shift/reduce conflicts with WITH TIME ZONE anyway.
2447 * - thomas 1999-01-08
2449 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
2450 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
2451 * or be part of a_expr NOT LIKE or similar constructs).
2456 Constraint *n = makeNode(Constraint);
2457 n->contype = CONSTR_NOTNULL;
2463 Constraint *n = makeNode(Constraint);
2464 n->contype = CONSTR_NULL;
2468 | UNIQUE opt_definition OptConsTableSpace
2470 Constraint *n = makeNode(Constraint);
2471 n->contype = CONSTR_UNIQUE;
2478 | PRIMARY KEY opt_definition OptConsTableSpace
2480 Constraint *n = makeNode(Constraint);
2481 n->contype = CONSTR_PRIMARY;
2488 | CHECK '(' a_expr ')'
2490 Constraint *n = makeNode(Constraint);
2491 n->contype = CONSTR_CHECK;
2494 n->cooked_expr = NULL;
2499 Constraint *n = makeNode(Constraint);
2500 n->contype = CONSTR_DEFAULT;
2503 n->cooked_expr = NULL;
2506 | REFERENCES qualified_name opt_column_list key_match key_actions
2508 Constraint *n = makeNode(Constraint);
2509 n->contype = CONSTR_FOREIGN;
2514 n->fk_matchtype = $4;
2515 n->fk_upd_action = (char) ($5 >> 8);
2516 n->fk_del_action = (char) ($5 & 0xFF);
2517 n->skip_validation = FALSE;
2523 * ConstraintAttr represents constraint attributes, which we parse as if
2524 * they were independent constraint clauses, in order to avoid shift/reduce
2525 * conflicts (since NOT might start either an independent NOT NULL clause
2526 * or an attribute). parse_utilcmd.c is responsible for attaching the
2527 * attribute information to the preceding "real" constraint node, and for
2528 * complaining if attribute clauses appear in the wrong place or wrong
2531 * See also ConstraintAttributeSpec, which can be used in places where
2532 * there is no parsing conflict.
2537 Constraint *n = makeNode(Constraint);
2538 n->contype = CONSTR_ATTR_DEFERRABLE;
2544 Constraint *n = makeNode(Constraint);
2545 n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
2549 | INITIALLY DEFERRED
2551 Constraint *n = makeNode(Constraint);
2552 n->contype = CONSTR_ATTR_DEFERRED;
2556 | INITIALLY IMMEDIATE
2558 Constraint *n = makeNode(Constraint);
2559 n->contype = CONSTR_ATTR_IMMEDIATE;
2567 * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2568 * This seems to be a poor man's inheritance capability, with the resulting
2569 * tables completely decoupled except for the original commonality in definitions.
2571 * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2572 * which is a part of SQL:2003.
2575 LIKE qualified_name TableLikeOptionList
2577 InhRelation *n = makeNode(InhRelation);
2584 TableLikeOptionList:
2585 TableLikeOptionList INCLUDING TableLikeOption { $$ = $1 | $3; }
2586 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
2587 | /* EMPTY */ { $$ = 0; }
2591 DEFAULTS { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
2592 | CONSTRAINTS { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
2593 | INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
2594 | STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
2595 | COMMENTS { $$ = CREATE_TABLE_LIKE_COMMENTS; }
2596 | ALL { $$ = CREATE_TABLE_LIKE_ALL; }
2600 /* ConstraintElem specifies constraint syntax which is not embedded into
2601 * a column definition. ColConstraintElem specifies the embedded form.
2602 * - thomas 1997-12-03
2605 CONSTRAINT name ConstraintElem
2607 Constraint *n = (Constraint *) $3;
2608 Assert(IsA(n, Constraint));
2613 | ConstraintElem { $$ = $1; }
2617 CHECK '(' a_expr ')' ConstraintAttributeSpec
2619 Constraint *n = makeNode(Constraint);
2620 n->contype = CONSTR_CHECK;
2623 n->cooked_expr = NULL;
2626 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2627 errmsg("CHECK constraints cannot be deferred"),
2628 parser_errposition(@5)));
2631 | UNIQUE '(' columnList ')' opt_definition OptConsTableSpace
2632 ConstraintAttributeSpec
2634 Constraint *n = makeNode(Constraint);
2635 n->contype = CONSTR_UNIQUE;
2640 n->deferrable = ($7 & 1) != 0;
2641 n->initdeferred = ($7 & 2) != 0;
2644 | PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace
2645 ConstraintAttributeSpec
2647 Constraint *n = makeNode(Constraint);
2648 n->contype = CONSTR_PRIMARY;
2653 n->deferrable = ($8 & 1) != 0;
2654 n->initdeferred = ($8 & 2) != 0;
2657 | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
2658 opt_definition OptConsTableSpace ExclusionWhereClause
2659 ConstraintAttributeSpec
2661 Constraint *n = makeNode(Constraint);
2662 n->contype = CONSTR_EXCLUSION;
2664 n->access_method = $2;
2668 n->where_clause = $8;
2669 n->deferrable = ($9 & 1) != 0;
2670 n->initdeferred = ($9 & 2) != 0;
2673 | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
2674 opt_column_list key_match key_actions ConstraintAttributeSpec
2676 Constraint *n = makeNode(Constraint);
2677 n->contype = CONSTR_FOREIGN;
2682 n->fk_matchtype = $9;
2683 n->fk_upd_action = (char) ($10 >> 8);
2684 n->fk_del_action = (char) ($10 & 0xFF);
2685 n->skip_validation = FALSE;
2686 n->deferrable = ($11 & 1) != 0;
2687 n->initdeferred = ($11 & 2) != 0;
2693 '(' columnList ')' { $$ = $2; }
2694 | /*EMPTY*/ { $$ = NIL; }
2698 columnElem { $$ = list_make1($1); }
2699 | columnList ',' columnElem { $$ = lappend($1, $3); }
2704 $$ = (Node *) makeString($1);
2708 key_match: MATCH FULL
2710 $$ = FKCONSTR_MATCH_FULL;
2715 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2716 errmsg("MATCH PARTIAL not yet implemented"),
2717 parser_errposition(@1)));
2718 $$ = FKCONSTR_MATCH_PARTIAL;
2722 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2726 $$ = FKCONSTR_MATCH_UNSPECIFIED;
2730 ExclusionConstraintList:
2731 ExclusionConstraintElem { $$ = list_make1($1); }
2732 | ExclusionConstraintList ',' ExclusionConstraintElem
2733 { $$ = lappend($1, $3); }
2736 ExclusionConstraintElem: index_elem WITH any_operator
2738 $$ = list_make2($1, $3);
2740 /* allow OPERATOR() decoration for the benefit of ruleutils.c */
2741 | index_elem WITH OPERATOR '(' any_operator ')'
2743 $$ = list_make2($1, $5);
2747 ExclusionWhereClause:
2748 WHERE '(' a_expr ')' { $$ = $3; }
2749 | /*EMPTY*/ { $$ = NULL; }
2753 * We combine the update and delete actions into one value temporarily
2754 * for simplicity of parsing, and then break them down again in the
2755 * calling production. update is in the left 8 bits, delete in the right.
2756 * Note that NOACTION is the default.
2760 { $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2762 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
2763 | key_update key_delete
2764 { $$ = ($1 << 8) | ($2 & 0xFF); }
2765 | key_delete key_update
2766 { $$ = ($2 << 8) | ($1 & 0xFF); }
2768 { $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
2771 key_update: ON UPDATE key_action { $$ = $3; }
2774 key_delete: ON DELETE_P key_action { $$ = $3; }
2778 NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; }
2779 | RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; }
2780 | CASCADE { $$ = FKCONSTR_ACTION_CASCADE; }
2781 | SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; }
2782 | SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; }
2785 OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
2786 | /*EMPTY*/ { $$ = NIL; }
2789 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
2791 WITH reloptions { $$ = $2; }
2792 | WITH OIDS { $$ = list_make1(defWithOids(true)); }
2793 | WITHOUT OIDS { $$ = list_make1(defWithOids(false)); }
2794 | /*EMPTY*/ { $$ = NIL; }
2797 OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
2798 | ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
2799 | ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
2800 | /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
2803 OptTableSpace: TABLESPACE name { $$ = $2; }
2804 | /*EMPTY*/ { $$ = NULL; }
2807 OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
2808 | /*EMPTY*/ { $$ = NULL; }
2813 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
2818 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
2821 * When the SelectStmt is a set-operation tree, we must
2822 * stuff the INTO information into the leftmost component
2823 * Select, because that's where analyze.c will expect
2824 * to find it. Similarly, the output column names must
2825 * be attached to that Select's target list.
2827 SelectStmt *n = findLeftmostSelect((SelectStmt *) $6);
2828 if (n->intoClause != NULL)
2830 (errcode(ERRCODE_SYNTAX_ERROR),
2831 errmsg("CREATE TABLE AS cannot specify INTO"),
2832 parser_errposition(exprLocation((Node *) n->intoClause))));
2833 $4->rel->istemp = $2;
2835 /* Implement WITH NO DATA by forcing top-level LIMIT 0 */
2837 ((SelectStmt *) $6)->limitCount = makeIntConst(0, -1);
2843 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
2845 $$ = makeNode(IntoClause);
2850 $$->tableSpaceName = $5;
2855 '(' CreateAsList ')' { $$ = $2; }
2856 | /*EMPTY*/ { $$ = NIL; }
2860 CreateAsElement { $$ = list_make1($1); }
2861 | CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); }
2867 ColumnDef *n = makeNode(ColumnDef);
2872 n->is_not_null = false;
2873 n->raw_default = NULL;
2874 n->cooked_default = NULL;
2875 n->constraints = NIL;
2881 WITH DATA_P { $$ = TRUE; }
2882 | WITH NO DATA_P { $$ = FALSE; }
2883 | /*EMPTY*/ { $$ = TRUE; }
2887 /*****************************************************************************
2890 * CREATE SEQUENCE seqname
2891 * ALTER SEQUENCE seqname
2893 *****************************************************************************/
2896 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
2898 CreateSeqStmt *n = makeNode(CreateSeqStmt);
2902 n->ownerId = InvalidOid;
2908 ALTER SEQUENCE qualified_name SeqOptList
2910 AlterSeqStmt *n = makeNode(AlterSeqStmt);
2917 OptSeqOptList: SeqOptList { $$ = $1; }
2918 | /*EMPTY*/ { $$ = NIL; }
2921 SeqOptList: SeqOptElem { $$ = list_make1($1); }
2922 | SeqOptList SeqOptElem { $$ = lappend($1, $2); }
2925 SeqOptElem: CACHE NumericOnly
2927 $$ = makeDefElem("cache", (Node *)$2);
2931 $$ = makeDefElem("cycle", (Node *)makeInteger(TRUE));
2935 $$ = makeDefElem("cycle", (Node *)makeInteger(FALSE));
2937 | INCREMENT opt_by NumericOnly
2939 $$ = makeDefElem("increment", (Node *)$3);
2941 | MAXVALUE NumericOnly
2943 $$ = makeDefElem("maxvalue", (Node *)$2);
2945 | MINVALUE NumericOnly
2947 $$ = makeDefElem("minvalue", (Node *)$2);
2951 $$ = makeDefElem("maxvalue", NULL);
2955 $$ = makeDefElem("minvalue", NULL);
2959 $$ = makeDefElem("owned_by", (Node *)$3);
2961 | START opt_with NumericOnly
2963 $$ = makeDefElem("start", (Node *)$3);
2967 $$ = makeDefElem("restart", NULL);
2969 | RESTART opt_with NumericOnly
2971 $$ = makeDefElem("restart", (Node *)$3);
2980 FCONST { $$ = makeFloat($1); }
2986 | SignedIconst { $$ = makeInteger($1); }
2989 NumericOnly_list: NumericOnly { $$ = list_make1($1); }
2990 | NumericOnly_list ',' NumericOnly { $$ = lappend($1, $3); }
2993 /*****************************************************************************
2996 * CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
2997 * DROP [PROCEDURAL] LANGUAGE ...
2999 *****************************************************************************/
3002 CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
3004 CreatePLangStmt *n = makeNode(CreatePLangStmt);
3007 /* parameters are all to be supplied by system */
3010 n->plvalidator = NIL;
3011 n->pltrusted = false;
3014 | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
3015 HANDLER handler_name opt_inline_handler opt_validator
3017 CreatePLangStmt *n = makeNode(CreatePLangStmt);
3022 n->plvalidator = $10;
3029 TRUSTED { $$ = TRUE; }
3030 | /*EMPTY*/ { $$ = FALSE; }
3033 /* This ought to be just func_name, but that causes reduce/reduce conflicts
3034 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
3035 * Work around by using simple names, instead.
3038 name { $$ = list_make1(makeString($1)); }
3039 | name attrs { $$ = lcons(makeString($1), $2); }
3043 INLINE_P handler_name { $$ = $2; }
3044 | /*EMPTY*/ { $$ = NIL; }
3048 VALIDATOR handler_name { $$ = $2; }
3049 | NO VALIDATOR { $$ = NIL; }
3053 validator_clause { $$ = $1; }
3054 | /*EMPTY*/ { $$ = NIL; }
3058 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
3060 DropPLangStmt *n = makeNode(DropPLangStmt);
3063 n->missing_ok = false;
3066 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
3068 DropPLangStmt *n = makeNode(DropPLangStmt);
3071 n->missing_ok = true;
3081 /*****************************************************************************
3084 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
3086 *****************************************************************************/
3088 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
3090 CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
3091 n->tablespacename = $3;
3098 OptTableSpaceOwner: OWNER name { $$ = $2; }
3099 | /*EMPTY */ { $$ = NULL; }
3102 /*****************************************************************************
3105 * DROP TABLESPACE <tablespace>
3107 * No need for drop behaviour as we cannot implement dependencies for
3108 * objects in other databases; we can only support RESTRICT.
3110 ****************************************************************************/
3112 DropTableSpaceStmt: DROP TABLESPACE name
3114 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
3115 n->tablespacename = $3;
3116 n->missing_ok = false;
3119 | DROP TABLESPACE IF_P EXISTS name
3121 DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
3122 n->tablespacename = $5;
3123 n->missing_ok = true;
3128 /*****************************************************************************
3131 * CREATE FOREIGN DATA WRAPPER name [ VALIDATOR name ]
3133 *****************************************************************************/
3135 CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_validator create_generic_options
3137 CreateFdwStmt *n = makeNode(CreateFdwStmt);
3145 /*****************************************************************************
3148 * DROP FOREIGN DATA WRAPPER name
3150 ****************************************************************************/
3152 DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
3154 DropFdwStmt *n = makeNode(DropFdwStmt);
3156 n->missing_ok = false;
3160 | DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior
3162 DropFdwStmt *n = makeNode(DropFdwStmt);
3164 n->missing_ok = true;
3170 /*****************************************************************************
3173 * ALTER FOREIGN DATA WRAPPER name
3175 ****************************************************************************/
3177 AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name validator_clause alter_generic_options
3179 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3182 n->change_validator = true;
3186 | ALTER FOREIGN DATA_P WRAPPER name validator_clause
3188 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3191 n->change_validator = true;
3194 | ALTER FOREIGN DATA_P WRAPPER name alter_generic_options
3196 AlterFdwStmt *n = makeNode(AlterFdwStmt);
3203 /* Options definition for CREATE FDW, SERVER and USER MAPPING */
3204 create_generic_options:
3205 OPTIONS '(' generic_option_list ')' { $$ = $3; }
3206 | /*EMPTY*/ { $$ = NIL; }
3209 generic_option_list:
3212 $$ = list_make1($1);
3214 | generic_option_list ',' generic_option_elem
3216 $$ = lappend($1, $3);
3220 /* Options definition for ALTER FDW, SERVER and USER MAPPING */
3221 alter_generic_options:
3222 OPTIONS '(' alter_generic_option_list ')' { $$ = $3; }
3225 alter_generic_option_list:
3226 alter_generic_option_elem
3228 $$ = list_make1($1);
3230 | alter_generic_option_list ',' alter_generic_option_elem
3232 $$ = lappend($1, $3);
3236 alter_generic_option_elem:
3241 | SET generic_option_elem
3244 $$->defaction = DEFELEM_SET;
3246 | ADD_P generic_option_elem
3249 $$->defaction = DEFELEM_ADD;
3251 | DROP generic_option_name
3253 $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP);
3257 generic_option_elem:
3258 generic_option_name generic_option_arg
3260 $$ = makeDefElem($1, $2);
3264 generic_option_name:
3265 ColLabel { $$ = $1; }
3268 /* We could use def_arg here, but the spec only requires string literals */
3270 Sconst { $$ = (Node *) makeString($1); }
3273 /*****************************************************************************
3276 * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
3278 *****************************************************************************/
3280 CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
3281 FOREIGN DATA_P WRAPPER name create_generic_options
3283 CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
3294 TYPE_P Sconst { $$ = $2; }
3295 | /*EMPTY*/ { $$ = NULL; }
3299 foreign_server_version:
3300 VERSION_P Sconst { $$ = $2; }
3301 | VERSION_P NULL_P { $$ = NULL; }
3304 opt_foreign_server_version:
3305 foreign_server_version { $$ = $1; }
3306 | /*EMPTY*/ { $$ = NULL; }
3309 /*****************************************************************************
3314 ****************************************************************************/
3316 DropForeignServerStmt: DROP SERVER name opt_drop_behavior
3318 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3320 n->missing_ok = false;
3324 | DROP SERVER IF_P EXISTS name opt_drop_behavior
3326 DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
3328 n->missing_ok = true;
3334 /*****************************************************************************
3337 * ALTER SERVER name [VERSION] [OPTIONS]
3339 ****************************************************************************/
3341 AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
3343 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3347 n->has_version = true;
3350 | ALTER SERVER name foreign_server_version
3352 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3355 n->has_version = true;
3358 | ALTER SERVER name alter_generic_options
3360 AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
3367 /*****************************************************************************
3370 * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
3372 *****************************************************************************/
3374 CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
3376 CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
3384 /* User mapping authorization identifier */
3386 CURRENT_USER { $$ = "current_user"; }
3387 | USER { $$ = "current_user"; }
3388 | RoleId { $$ = (strcmp($1, "public") == 0) ? NULL : $1; }
3391 /*****************************************************************************
3394 * DROP USER MAPPING FOR auth_ident SERVER name
3396 ****************************************************************************/
3398 DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
3400 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3403 n->missing_ok = false;
3406 | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
3408 DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
3411 n->missing_ok = true;
3416 /*****************************************************************************
3419 * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
3421 ****************************************************************************/
3423 AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
3425 AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
3433 /*****************************************************************************
3436 * CREATE TRIGGER ...
3439 *****************************************************************************/
3442 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
3443 qualified_name TriggerForSpec TriggerWhen
3444 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3446 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3453 n->events = intVal(linitial($5));
3454 n->columns = (List *) lsecond($5);
3456 n->isconstraint = FALSE;
3457 n->deferrable = FALSE;
3458 n->initdeferred = FALSE;
3459 n->constrrel = NULL;
3462 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
3463 qualified_name OptConstrFromTable ConstraintAttributeSpec
3464 FOR EACH ROW TriggerWhen
3465 EXECUTE PROCEDURE func_name '(' TriggerFuncArgs ')'
3467 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3473 n->timing = TRIGGER_TYPE_AFTER;
3474 n->events = intVal(linitial($6));
3475 n->columns = (List *) lsecond($6);
3476 n->whenClause = $14;
3477 n->isconstraint = TRUE;
3478 n->deferrable = ($10 & 1) != 0;
3479 n->initdeferred = ($10 & 2) != 0;
3486 BEFORE { $$ = TRIGGER_TYPE_BEFORE; }
3487 | AFTER { $$ = TRIGGER_TYPE_AFTER; }
3488 | INSTEAD OF { $$ = TRIGGER_TYPE_INSTEAD; }
3494 | TriggerEvents OR TriggerOneEvent
3496 int events1 = intVal(linitial($1));
3497 int events2 = intVal(linitial($3));
3498 List *columns1 = (List *) lsecond($1);
3499 List *columns2 = (List *) lsecond($3);
3501 if (events1 & events2)
3502 parser_yyerror("duplicate trigger events specified");
3504 * concat'ing the columns lists loses information about
3505 * which columns went with which event, but so long as
3506 * only UPDATE carries columns and we disallow multiple
3507 * UPDATE items, it doesn't matter. Command execution
3508 * should just ignore the columns for non-UPDATE events.
3510 $$ = list_make2(makeInteger(events1 | events2),
3511 list_concat(columns1, columns2));
3517 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
3519 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
3521 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
3522 | UPDATE OF columnList
3523 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
3525 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
3529 FOR TriggerForOptEach TriggerForType
3536 * If ROW/STATEMENT not specified, default to
3537 * STATEMENT, per SQL
3550 | STATEMENT { $$ = FALSE; }
3554 WHEN '(' a_expr ')' { $$ = $3; }
3555 | /*EMPTY*/ { $$ = NULL; }
3559 TriggerFuncArg { $$ = list_make1($1); }
3560 | TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
3561 | /*EMPTY*/ { $$ = NIL; }
3568 snprintf(buf, sizeof(buf), "%d", $1);
3569 $$ = makeString(pstrdup(buf));
3571 | FCONST { $$ = makeString($1); }
3572 | Sconst { $$ = makeString($1); }
3573 | BCONST { $$ = makeString($1); }
3574 | XCONST { $$ = makeString($1); }
3575 | ColId { $$ = makeString($1); }
3579 FROM qualified_name { $$ = $2; }
3580 | /*EMPTY*/ { $$ = NULL; }
3583 ConstraintAttributeSpec:
3584 ConstraintDeferrabilitySpec
3586 | ConstraintDeferrabilitySpec ConstraintTimeSpec
3588 if ($1 == 0 && $2 != 0)
3590 (errcode(ERRCODE_SYNTAX_ERROR),
3591 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3592 parser_errposition(@1)));
3595 | ConstraintTimeSpec
3602 | ConstraintTimeSpec ConstraintDeferrabilitySpec
3604 if ($2 == 0 && $1 != 0)
3606 (errcode(ERRCODE_SYNTAX_ERROR),
3607 errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3608 parser_errposition(@1)));
3615 ConstraintDeferrabilitySpec:
3616 NOT DEFERRABLE { $$ = 0; }
3617 | DEFERRABLE { $$ = 1; }
3621 INITIALLY IMMEDIATE { $$ = 0; }
3622 | INITIALLY DEFERRED { $$ = 2; }
3627 DROP TRIGGER name ON qualified_name opt_drop_behavior
3629 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3633 n->removeType = OBJECT_TRIGGER;
3634 n->missing_ok = false;
3637 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
3639 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3643 n->removeType = OBJECT_TRIGGER;
3644 n->missing_ok = true;
3650 /*****************************************************************************
3653 * CREATE ASSERTION ...
3654 * DROP ASSERTION ...
3656 *****************************************************************************/
3659 CREATE ASSERTION name CHECK '(' a_expr ')'
3660 ConstraintAttributeSpec
3662 CreateTrigStmt *n = makeNode(CreateTrigStmt);
3664 n->args = list_make1($6);
3665 n->isconstraint = TRUE;
3666 n->deferrable = ($8 & 1) != 0;
3667 n->initdeferred = ($8 & 2) != 0;
3670 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3671 errmsg("CREATE ASSERTION is not yet implemented")));
3678 DROP ASSERTION name opt_drop_behavior
3680 DropPropertyStmt *n = makeNode(DropPropertyStmt);
3684 n->removeType = OBJECT_TRIGGER; /* XXX */
3686 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3687 errmsg("DROP ASSERTION is not yet implemented")));
3693 /*****************************************************************************
3696 * define (aggregate,operator,type)
3698 *****************************************************************************/
3701 CREATE AGGREGATE func_name aggr_args definition
3703 DefineStmt *n = makeNode(DefineStmt);
3704 n->kind = OBJECT_AGGREGATE;
3705 n->oldstyle = false;
3711 | CREATE AGGREGATE func_name old_aggr_definition
3713 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
3714 DefineStmt *n = makeNode(DefineStmt);
3715 n->kind = OBJECT_AGGREGATE;
3722 | CREATE OPERATOR any_operator definition
3724 DefineStmt *n = makeNode(DefineStmt);
3725 n->kind = OBJECT_OPERATOR;
3726 n->oldstyle = false;
3732 | CREATE TYPE_P any_name definition
3734 DefineStmt *n = makeNode(DefineStmt);
3735 n->kind = OBJECT_TYPE;
3736 n->oldstyle = false;
3742 | CREATE TYPE_P any_name
3744 /* Shell type (identified by lack of definition) */
3745 DefineStmt *n = makeNode(DefineStmt);
3746 n->kind = OBJECT_TYPE;
3747 n->oldstyle = false;
3750 n->definition = NIL;
3753 | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
3755 CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
3757 /* can't use qualified_name, sigh */
3758 n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
3762 | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
3764 CreateEnumStmt *n = makeNode(CreateEnumStmt);
3769 | CREATE TEXT_P SEARCH PARSER any_name definition
3771 DefineStmt *n = makeNode(DefineStmt);
3772 n->kind = OBJECT_TSPARSER;
3778 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
3780 DefineStmt *n = makeNode(DefineStmt);
3781 n->kind = OBJECT_TSDICTIONARY;
3787 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
3789 DefineStmt *n = makeNode(DefineStmt);
3790 n->kind = OBJECT_TSTEMPLATE;
3796 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
3798 DefineStmt *n = makeNode(DefineStmt);
3799 n->kind = OBJECT_TSCONFIGURATION;
3807 definition: '(' def_list ')' { $$ = $2; }
3810 def_list: def_elem { $$ = list_make1($1); }
3811 | def_list ',' def_elem { $$ = lappend($1, $3); }
3814 def_elem: ColLabel '=' def_arg
3816 $$ = makeDefElem($1, (Node *) $3);
3820 $$ = makeDefElem($1, NULL);
3824 /* Note: any simple identifier will be returned as a type name! */
3825 def_arg: func_type { $$ = (Node *)$1; }
3826 | reserved_keyword { $$ = (Node *)makeString(pstrdup($1)); }
3827 | qual_all_Op { $$ = (Node *)$1; }
3828 | NumericOnly { $$ = (Node *)$1; }
3829 | Sconst { $$ = (Node *)makeString($1); }
3832 aggr_args: '(' type_list ')' { $$ = $2; }
3833 | '(' '*' ')' { $$ = NIL; }
3836 old_aggr_definition: '(' old_aggr_list ')' { $$ = $2; }
3839 old_aggr_list: old_aggr_elem { $$ = list_make1($1); }
3840 | old_aggr_list ',' old_aggr_elem { $$ = lappend($1, $3); }
3844 * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
3845 * the item names needed in old aggregate definitions are likely to become
3848 old_aggr_elem: IDENT '=' def_arg
3850 $$ = makeDefElem($1, (Node *)$3);
3855 enum_val_list { $$ = $1; }
3856 | /*EMPTY*/ { $$ = NIL; }
3859 enum_val_list: Sconst
3860 { $$ = list_make1(makeString($1)); }
3861 | enum_val_list ',' Sconst
3862 { $$ = lappend($1, makeString($3)); }
3866 /*****************************************************************************
3869 * CREATE OPERATOR CLASS ...
3870 * CREATE OPERATOR FAMILY ...
3871 * ALTER OPERATOR FAMILY ...
3872 * DROP OPERATOR CLASS ...
3873 * DROP OPERATOR FAMILY ...
3875 *****************************************************************************/
3878 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
3879 USING access_method opt_opfamily AS opclass_item_list
3881 CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
3882 n->opclassname = $4;
3886 n->opfamilyname = $11;
3893 opclass_item { $$ = list_make1($1); }
3894 | opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
3898 OPERATOR Iconst any_operator opt_recheck
3900 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3901 n->itemtype = OPCLASS_ITEM_OPERATOR;
3907 | OPERATOR Iconst any_operator oper_argtypes opt_recheck
3909 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3910 n->itemtype = OPCLASS_ITEM_OPERATOR;
3916 | FUNCTION Iconst func_name func_args
3918 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3919 n->itemtype = OPCLASS_ITEM_FUNCTION;
3921 n->args = extractArgTypes($4);
3925 | FUNCTION Iconst '(' type_list ')' func_name func_args
3927 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3928 n->itemtype = OPCLASS_ITEM_FUNCTION;
3930 n->args = extractArgTypes($7);
3937 CreateOpClassItem *n = makeNode(CreateOpClassItem);
3938 n->itemtype = OPCLASS_ITEM_STORAGETYPE;
3944 opt_default: DEFAULT { $$ = TRUE; }
3945 | /*EMPTY*/ { $$ = FALSE; }
3948 opt_opfamily: FAMILY any_name { $$ = $2; }
3949 | /*EMPTY*/ { $$ = NIL; }
3952 opt_recheck: RECHECK
3955 * RECHECK no longer does anything in opclass definitions,
3956 * but we still accept it to ease porting of old database
3960 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3961 errmsg("RECHECK is no longer required"),
3962 errhint("Update your data type."),
3963 parser_errposition(@1)));
3966 | /*EMPTY*/ { $$ = FALSE; }
3971 CREATE OPERATOR FAMILY any_name USING access_method
3973 CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
3974 n->opfamilyname = $4;
3981 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
3983 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3984 n->opfamilyname = $4;
3990 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
3992 AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
3993 n->opfamilyname = $4;
4002 opclass_drop { $$ = list_make1($1); }
4003 | opclass_drop_list ',' opclass_drop { $$ = lappend($1, $3); }
4007 OPERATOR Iconst '(' type_list ')'
4009 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4010 n->itemtype = OPCLASS_ITEM_OPERATOR;
4015 | FUNCTION Iconst '(' type_list ')'
4017 CreateOpClassItem *n = makeNode(CreateOpClassItem);
4018 n->itemtype = OPCLASS_ITEM_FUNCTION;
4027 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
4029 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
4030 n->opclassname = $4;
4033 n->missing_ok = false;
4036 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
4038 RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
4039 n->opclassname = $6;
4042 n->missing_ok = true;
4048 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
4050 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
4051 n->opfamilyname = $4;
4054 n->missing_ok = false;
4057 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
4059 RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
4060 n->opfamilyname = $6;
4063 n->missing_ok = true;
4069 /*****************************************************************************
4073 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
4074 * REASSIGN OWNED BY username [, username ...] TO username
4076 *****************************************************************************/
4078 DROP OWNED BY name_list opt_drop_behavior
4080 DropOwnedStmt *n = makeNode(DropOwnedStmt);
4088 REASSIGN OWNED BY name_list TO name
4090 ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
4097 /*****************************************************************************
4101 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
4102 * [ RESTRICT | CASCADE ]
4104 *****************************************************************************/
4106 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
4108 DropStmt *n = makeNode(DropStmt);
4110 n->missing_ok = TRUE;
4115 | DROP drop_type any_name_list opt_drop_behavior
4117 DropStmt *n = makeNode(DropStmt);
4119 n->missing_ok = FALSE;
4127 drop_type: TABLE { $$ = OBJECT_TABLE; }
4128 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4129 | VIEW { $$ = OBJECT_VIEW; }
4130 | INDEX { $$ = OBJECT_INDEX; }
4131 | TYPE_P { $$ = OBJECT_TYPE; }
4132 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
4133 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4134 | SCHEMA { $$ = OBJECT_SCHEMA; }
4135 | TEXT_P SEARCH PARSER { $$ = OBJECT_TSPARSER; }
4136 | TEXT_P SEARCH DICTIONARY { $$ = OBJECT_TSDICTIONARY; }
4137 | TEXT_P SEARCH TEMPLATE { $$ = OBJECT_TSTEMPLATE; }
4138 | TEXT_P SEARCH CONFIGURATION { $$ = OBJECT_TSCONFIGURATION; }
4142 any_name { $$ = list_make1($1); }
4143 | any_name_list ',' any_name { $$ = lappend($1, $3); }
4146 any_name: ColId { $$ = list_make1(makeString($1)); }
4147 | ColId attrs { $$ = lcons(makeString($1), $2); }
4150 attrs: '.' attr_name
4151 { $$ = list_make1(makeString($2)); }
4152 | attrs '.' attr_name
4153 { $$ = lappend($1, makeString($3)); }
4157 /*****************************************************************************
4160 * truncate table relname1, relname2, ...
4162 *****************************************************************************/
4165 TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
4167 TruncateStmt *n = makeNode(TruncateStmt);
4169 n->restart_seqs = $4;
4176 CONTINUE_P IDENTITY_P { $$ = false; }
4177 | RESTART IDENTITY_P { $$ = true; }
4178 | /* EMPTY */ { $$ = false; }
4181 /*****************************************************************************
4183 * The COMMENT ON statement can take different forms based upon the type of
4184 * the object associated with the comment. The form of the statement is:
4186 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
4187 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
4188 * CAST | COLUMN | SCHEMA | TABLESPACE | ROLE |
4189 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
4190 * TEXT SEARCH TEMPLATE |
4191 * TEXT SEARCH CONFIGURATION ] <objname> |
4192 * AGGREGATE <aggname> (arg1, ...) |
4193 * FUNCTION <funcname> (arg1, arg2, ...) |
4194 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
4195 * TRIGGER <triggername> ON <relname> |
4196 * CONSTRAINT <constraintname> ON <relname> |
4197 * RULE <rulename> ON <relname> ]
4200 *****************************************************************************/
4203 COMMENT ON comment_type any_name IS comment_text
4205 CommentStmt *n = makeNode(CommentStmt);
4212 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
4214 CommentStmt *n = makeNode(CommentStmt);
4215 n->objtype = OBJECT_AGGREGATE;
4221 | COMMENT ON FUNCTION func_name func_args IS comment_text
4223 CommentStmt *n = makeNode(CommentStmt);
4224 n->objtype = OBJECT_FUNCTION;
4226 n->objargs = extractArgTypes($5);
4230 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
4232 CommentStmt *n = makeNode(CommentStmt);
4233 n->objtype = OBJECT_OPERATOR;
4239 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
4241 CommentStmt *n = makeNode(CommentStmt);
4242 n->objtype = OBJECT_CONSTRAINT;
4243 n->objname = lappend($6, makeString($4));
4248 | COMMENT ON RULE name ON any_name IS comment_text
4250 CommentStmt *n = makeNode(CommentStmt);
4251 n->objtype = OBJECT_RULE;
4252 n->objname = lappend($6, makeString($4));
4257 | COMMENT ON RULE name IS comment_text
4259 /* Obsolete syntax supported for awhile for compatibility */
4260 CommentStmt *n = makeNode(CommentStmt);
4261 n->objtype = OBJECT_RULE;
4262 n->objname = list_make1(makeString($4));
4267 | COMMENT ON TRIGGER name ON any_name IS comment_text
4269 CommentStmt *n = makeNode(CommentStmt);
4270 n->objtype = OBJECT_TRIGGER;
4271 n->objname = lappend($6, makeString($4));
4276 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
4278 CommentStmt *n = makeNode(CommentStmt);
4279 n->objtype = OBJECT_OPCLASS;
4281 n->objargs = list_make1(makeString($7));
4285 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
4287 CommentStmt *n = makeNode(CommentStmt);
4288 n->objtype = OBJECT_OPFAMILY;
4290 n->objargs = list_make1(makeString($7));
4294 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
4296 CommentStmt *n = makeNode(CommentStmt);
4297 n->objtype = OBJECT_LARGEOBJECT;
4298 n->objname = list_make1($5);
4303 | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
4305 CommentStmt *n = makeNode(CommentStmt);
4306 n->objtype = OBJECT_CAST;
4307 n->objname = list_make1($5);
4308 n->objargs = list_make1($7);
4312 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
4314 CommentStmt *n = makeNode(CommentStmt);
4315 n->objtype = OBJECT_LANGUAGE;
4321 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
4323 CommentStmt *n = makeNode(CommentStmt);
4324 n->objtype = OBJECT_TSPARSER;
4329 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
4331 CommentStmt *n = makeNode(CommentStmt);
4332 n->objtype = OBJECT_TSDICTIONARY;
4337 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
4339 CommentStmt *n = makeNode(CommentStmt);
4340 n->objtype = OBJECT_TSTEMPLATE;
4345 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
4347 CommentStmt *n = makeNode(CommentStmt);
4348 n->objtype = OBJECT_TSCONFIGURATION;
4356 COLUMN { $$ = OBJECT_COLUMN; }
4357 | DATABASE { $$ = OBJECT_DATABASE; }
4358 | SCHEMA { $$ = OBJECT_SCHEMA; }
4359 | INDEX { $$ = OBJECT_INDEX; }
4360 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4361 | TABLE { $$ = OBJECT_TABLE; }
4362 | DOMAIN_P { $$ = OBJECT_TYPE; }
4363 | TYPE_P { $$ = OBJECT_TYPE; }
4364 | VIEW { $$ = OBJECT_VIEW; }
4365 | CONVERSION_P { $$ = OBJECT_CONVERSION; }
4366 | TABLESPACE { $$ = OBJECT_TABLESPACE; }
4367 | ROLE { $$ = OBJECT_ROLE; }
4372 | NULL_P { $$ = NULL; }
4376 /*****************************************************************************
4378 * SECURITY LABEL [FOR <provider>] ON <object> IS <label>
4380 * As with COMMENT ON, <object> can refer to various types of database
4381 * objects (e.g. TABLE, COLUMN, etc.).
4383 *****************************************************************************/
4386 SECURITY LABEL opt_provider ON security_label_type any_name
4389 SecLabelStmt *n = makeNode(SecLabelStmt);
4397 | SECURITY LABEL opt_provider ON AGGREGATE func_name aggr_args
4400 SecLabelStmt *n = makeNode(SecLabelStmt);
4402 n->objtype = OBJECT_AGGREGATE;
4408 | SECURITY LABEL opt_provider ON FUNCTION func_name func_args
4411 SecLabelStmt *n = makeNode(SecLabelStmt);
4413 n->objtype = OBJECT_FUNCTION;
4415 n->objargs = extractArgTypes($7);
4419 | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
4422 SecLabelStmt *n = makeNode(SecLabelStmt);
4424 n->objtype = OBJECT_LARGEOBJECT;
4425 n->objname = list_make1($7);
4430 | SECURITY LABEL opt_provider ON opt_procedural LANGUAGE any_name
4433 SecLabelStmt *n = makeNode(SecLabelStmt);
4435 n->objtype = OBJECT_LANGUAGE;
4443 opt_provider: FOR ColId_or_Sconst { $$ = $2; }
4444 | /* empty */ { $$ = NULL; }
4447 security_label_type:
4448 COLUMN { $$ = OBJECT_COLUMN; }
4449 | SCHEMA { $$ = OBJECT_SCHEMA; }
4450 | SEQUENCE { $$ = OBJECT_SEQUENCE; }
4451 | TABLE { $$ = OBJECT_TABLE; }
4452 | DOMAIN_P { $$ = OBJECT_TYPE; }
4453 | TYPE_P { $$ = OBJECT_TYPE; }
4454 | VIEW { $$ = OBJECT_VIEW; }
4457 security_label: Sconst { $$ = $1; }
4458 | NULL_P { $$ = NULL; }
4461 /*****************************************************************************
4466 *****************************************************************************/
4468 FetchStmt: FETCH fetch_args
4470 FetchStmt *n = (FetchStmt *) $2;
4476 FetchStmt *n = (FetchStmt *) $2;
4482 fetch_args: cursor_name
4484 FetchStmt *n = makeNode(FetchStmt);
4486 n->direction = FETCH_FORWARD;
4490 | from_in cursor_name
4492 FetchStmt *n = makeNode(FetchStmt);
4494 n->direction = FETCH_FORWARD;
4498 | NEXT opt_from_in cursor_name
4500 FetchStmt *n = makeNode(FetchStmt);
4502 n->direction = FETCH_FORWARD;
4506 | PRIOR opt_from_in cursor_name
4508 FetchStmt *n = makeNode(FetchStmt);
4510 n->direction = FETCH_BACKWARD;
4514 | FIRST_P opt_from_in cursor_name
4516 FetchStmt *n = makeNode(FetchStmt);
4518 n->direction = FETCH_ABSOLUTE;
4522 | LAST_P opt_from_in cursor_name
4524 FetchStmt *n = makeNode(FetchStmt);
4526 n->direction = FETCH_ABSOLUTE;
4530 | ABSOLUTE_P SignedIconst opt_from_in cursor_name
4532 FetchStmt *n = makeNode(FetchStmt);
4534 n->direction = FETCH_ABSOLUTE;
4538 | RELATIVE_P SignedIconst opt_from_in cursor_name
4540 FetchStmt *n = makeNode(FetchStmt);
4542 n->direction = FETCH_RELATIVE;
4546 | SignedIconst opt_from_in cursor_name
4548 FetchStmt *n = makeNode(FetchStmt);
4550 n->direction = FETCH_FORWARD;
4554 | ALL opt_from_in cursor_name
4556 FetchStmt *n = makeNode(FetchStmt);
4558 n->direction = FETCH_FORWARD;
4559 n->howMany = FETCH_ALL;
4562 | FORWARD opt_from_in cursor_name
4564 FetchStmt *n = makeNode(FetchStmt);
4566 n->direction = FETCH_FORWARD;
4570 | FORWARD SignedIconst opt_from_in cursor_name
4572 FetchStmt *n = makeNode(FetchStmt);
4574 n->direction = FETCH_FORWARD;
4578 | FORWARD ALL opt_from_in cursor_name
4580 FetchStmt *n = makeNode(FetchStmt);
4582 n->direction = FETCH_FORWARD;
4583 n->howMany = FETCH_ALL;
4586 | BACKWARD opt_from_in cursor_name
4588 FetchStmt *n = makeNode(FetchStmt);
4590 n->direction = FETCH_BACKWARD;
4594 | BACKWARD SignedIconst opt_from_in cursor_name
4596 FetchStmt *n = makeNode(FetchStmt);
4598 n->direction = FETCH_BACKWARD;
4602 | BACKWARD ALL opt_from_in cursor_name
4604 FetchStmt *n = makeNode(FetchStmt);
4606 n->direction = FETCH_BACKWARD;
4607 n->howMany = FETCH_ALL;
4616 opt_from_in: from_in {}
4621 /*****************************************************************************
4623 * GRANT and REVOKE statements
4625 *****************************************************************************/
4627 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
4628 opt_grant_grant_option
4630 GrantStmt *n = makeNode(GrantStmt);
4633 n->targtype = ($4)->targtype;
4634 n->objtype = ($4)->objtype;
4635 n->objects = ($4)->objs;
4637 n->grant_option = $7;
4643 REVOKE privileges ON privilege_target
4644 FROM grantee_list opt_drop_behavior
4646 GrantStmt *n = makeNode(GrantStmt);
4647 n->is_grant = false;
4648 n->grant_option = false;
4650 n->targtype = ($4)->targtype;
4651 n->objtype = ($4)->objtype;
4652 n->objects = ($4)->objs;
4657 | REVOKE GRANT OPTION FOR privileges ON privilege_target
4658 FROM grantee_list opt_drop_behavior
4660 GrantStmt *n = makeNode(GrantStmt);
4661 n->is_grant = false;
4662 n->grant_option = true;
4664 n->targtype = ($7)->targtype;
4665 n->objtype = ($7)->objtype;
4666 n->objects = ($7)->objs;
4675 * Privilege names are represented as strings; the validity of the privilege
4676 * names gets checked at execution. This is a bit annoying but we have little
4677 * choice because of the syntactic conflict with lists of role names in
4678 * GRANT/REVOKE. What's more, we have to call out in the "privilege"
4679 * production any reserved keywords that need to be usable as privilege names.
4682 /* either ALL [PRIVILEGES] or a list of individual privileges */
4683 privileges: privilege_list
4689 | ALL '(' columnList ')'
4691 AccessPriv *n = makeNode(AccessPriv);
4692 n->priv_name = NULL;
4696 | ALL PRIVILEGES '(' columnList ')'
4698 AccessPriv *n = makeNode(AccessPriv);
4699 n->priv_name = NULL;
4705 privilege_list: privilege { $$ = list_make1($1); }
4706 | privilege_list ',' privilege { $$ = lappend($1, $3); }
4709 privilege: SELECT opt_column_list
4711 AccessPriv *n = makeNode(AccessPriv);
4712 n->priv_name = pstrdup($1);
4716 | REFERENCES opt_column_list
4718 AccessPriv *n = makeNode(AccessPriv);
4719 n->priv_name = pstrdup($1);
4723 | CREATE opt_column_list
4725 AccessPriv *n = makeNode(AccessPriv);
4726 n->priv_name = pstrdup($1);
4730 | ColId opt_column_list
4732 AccessPriv *n = makeNode(AccessPriv);
4740 /* Don't bother trying to fold the first two rules into one using
4741 * opt_table. You're going to get conflicts.
4746 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4747 n->targtype = ACL_TARGET_OBJECT;
4748 n->objtype = ACL_OBJECT_RELATION;
4752 | TABLE qualified_name_list
4754 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4755 n->targtype = ACL_TARGET_OBJECT;
4756 n->objtype = ACL_OBJECT_RELATION;
4760 | SEQUENCE qualified_name_list
4762 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4763 n->targtype = ACL_TARGET_OBJECT;
4764 n->objtype = ACL_OBJECT_SEQUENCE;
4768 | FOREIGN DATA_P WRAPPER name_list
4770 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4771 n->targtype = ACL_TARGET_OBJECT;
4772 n->objtype = ACL_OBJECT_FDW;
4776 | FOREIGN SERVER name_list
4778 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4779 n->targtype = ACL_TARGET_OBJECT;
4780 n->objtype = ACL_OBJECT_FOREIGN_SERVER;
4784 | FUNCTION function_with_argtypes_list
4786 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4787 n->targtype = ACL_TARGET_OBJECT;
4788 n->objtype = ACL_OBJECT_FUNCTION;
4792 | DATABASE name_list
4794 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4795 n->targtype = ACL_TARGET_OBJECT;
4796 n->objtype = ACL_OBJECT_DATABASE;
4800 | LANGUAGE name_list
4802 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4803 n->targtype = ACL_TARGET_OBJECT;
4804 n->objtype = ACL_OBJECT_LANGUAGE;
4808 | LARGE_P OBJECT_P NumericOnly_list
4810 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4811 n->targtype = ACL_TARGET_OBJECT;
4812 n->objtype = ACL_OBJECT_LARGEOBJECT;
4818 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4819 n->targtype = ACL_TARGET_OBJECT;
4820 n->objtype = ACL_OBJECT_NAMESPACE;
4824 | TABLESPACE name_list
4826 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4827 n->targtype = ACL_TARGET_OBJECT;
4828 n->objtype = ACL_OBJECT_TABLESPACE;
4832 | ALL TABLES IN_P SCHEMA name_list
4834 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4835 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4836 n->objtype = ACL_OBJECT_RELATION;
4840 | ALL SEQUENCES IN_P SCHEMA name_list
4842 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4843 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4844 n->objtype = ACL_OBJECT_SEQUENCE;
4848 | ALL FUNCTIONS IN_P SCHEMA name_list
4850 PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
4851 n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
4852 n->objtype = ACL_OBJECT_FUNCTION;
4860 grantee { $$ = list_make1($1); }
4861 | grantee_list ',' grantee { $$ = lappend($1, $3); }
4866 PrivGrantee *n = makeNode(PrivGrantee);
4867 /* This hack lets us avoid reserving PUBLIC as a keyword*/
4868 if (strcmp($1, "public") == 0)
4876 PrivGrantee *n = makeNode(PrivGrantee);
4877 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
4878 if (strcmp($2, "public") == 0)
4887 opt_grant_grant_option:
4888 WITH GRANT OPTION { $$ = TRUE; }
4889 | /*EMPTY*/ { $$ = FALSE; }
4892 function_with_argtypes_list:
4893 function_with_argtypes { $$ = list_make1($1); }
4894 | function_with_argtypes_list ',' function_with_argtypes
4895 { $$ = lappend($1, $3); }
4898 function_with_argtypes:
4901 FuncWithArgs *n = makeNode(FuncWithArgs);
4903 n->funcargs = extractArgTypes($2);
4908 /*****************************************************************************
4910 * GRANT and REVOKE ROLE statements
4912 *****************************************************************************/
4915 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4917 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4919 n->granted_roles = $2;
4920 n->grantee_roles = $4;
4928 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4930 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4931 n->is_grant = false;
4932 n->admin_opt = false;
4933 n->granted_roles = $2;
4934 n->grantee_roles = $4;
4938 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4940 GrantRoleStmt *n = makeNode(GrantRoleStmt);
4941 n->is_grant = false;
4942 n->admin_opt = true;
4943 n->granted_roles = $5;
4944 n->grantee_roles = $7;
4950 opt_grant_admin_option: WITH ADMIN OPTION { $$ = TRUE; }
4951 | /*EMPTY*/ { $$ = FALSE; }
4954 opt_granted_by: GRANTED BY RoleId { $$ = $3; }
4955 | /*EMPTY*/ { $$ = NULL; }
4958 /*****************************************************************************
4960 * ALTER DEFAULT PRIVILEGES statement
4962 *****************************************************************************/
4964 AlterDefaultPrivilegesStmt:
4965 ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
4967 AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
4969 n->action = (GrantStmt *) $5;
4975 DefACLOptionList DefACLOption { $$ = lappend($1, $2); }
4976 | /* EMPTY */ { $$ = NIL; }
4980 IN_P SCHEMA name_list
4982 $$ = makeDefElem("schemas", (Node *)$3);
4984 | FOR ROLE name_list
4986 $$ = makeDefElem("roles", (Node *)$3);
4988 | FOR USER name_list
4990 $$ = makeDefElem("roles", (Node *)$3);
4995 * This should match GRANT/REVOKE, except that individual target objects
4996 * are not mentioned and we only allow a subset of object types.
4999 GRANT privileges ON defacl_privilege_target TO grantee_list
5000 opt_grant_grant_option
5002 GrantStmt *n = makeNode(GrantStmt);
5005 n->targtype = ACL_TARGET_DEFAULTS;
5009 n->grant_option = $7;
5012 | REVOKE privileges ON defacl_privilege_target
5013 FROM grantee_list opt_drop_behavior
5015 GrantStmt *n = makeNode(GrantStmt);
5016 n->is_grant = false;
5017 n->grant_option = false;
5019 n->targtype = ACL_TARGET_DEFAULTS;
5026 | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
5027 FROM grantee_list opt_drop_behavior
5029 GrantStmt *n = makeNode(GrantStmt);
5030 n->is_grant = false;
5031 n->grant_option = true;
5033 n->targtype = ACL_TARGET_DEFAULTS;
5042 defacl_privilege_target:
5043 TABLES { $$ = ACL_OBJECT_RELATION; }
5044 | FUNCTIONS { $$ = ACL_OBJECT_FUNCTION; }
5045 | SEQUENCES { $$ = ACL_OBJECT_SEQUENCE; }
5049 /*****************************************************************************
5051 * QUERY: CREATE INDEX
5053 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
5054 * willing to make TABLESPACE a fully reserved word.
5055 *****************************************************************************/
5057 IndexStmt: CREATE opt_unique INDEX opt_concurrently opt_index_name
5058 ON qualified_name access_method_clause '(' index_params ')'
5059 opt_reloptions OptTableSpace where_clause
5061 IndexStmt *n = makeNode(IndexStmt);
5066 n->accessMethod = $8;
5067 n->indexParams = $10;
5069 n->tableSpace = $13;
5070 n->whereClause = $14;
5076 UNIQUE { $$ = TRUE; }
5077 | /*EMPTY*/ { $$ = FALSE; }
5081 CONCURRENTLY { $$ = TRUE; }
5082 | /*EMPTY*/ { $$ = FALSE; }
5086 index_name { $$ = $1; }
5087 | /*EMPTY*/ { $$ = NULL; }
5090 access_method_clause:
5091 USING access_method { $$ = $2; }
5092 | /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
5095 index_params: index_elem { $$ = list_make1($1); }
5096 | index_params ',' index_elem { $$ = lappend($1, $3); }
5100 * Index attributes can be either simple column references, or arbitrary
5101 * expressions in parens. For backwards-compatibility reasons, we allow
5102 * an expression that's just a function call to be written without parens.
5104 index_elem: ColId opt_class opt_asc_desc opt_nulls_order
5106 $$ = makeNode(IndexElem);
5109 $$->indexcolname = NULL;
5112 $$->nulls_ordering = $4;
5114 | func_expr opt_class opt_asc_desc opt_nulls_order
5116 $$ = makeNode(IndexElem);
5119 $$->indexcolname = NULL;
5122 $$->nulls_ordering = $4;
5124 | '(' a_expr ')' opt_class opt_asc_desc opt_nulls_order
5126 $$ = makeNode(IndexElem);
5129 $$->indexcolname = NULL;
5132 $$->nulls_ordering = $6;
5136 opt_class: any_name { $$ = $1; }
5137 | USING any_name { $$ = $2; }
5138 | /*EMPTY*/ { $$ = NIL; }
5141 opt_asc_desc: ASC { $$ = SORTBY_ASC; }
5142 | DESC { $$ = SORTBY_DESC; }
5143 | /*EMPTY*/ { $$ = SORTBY_DEFAULT; }
5146 opt_nulls_order: NULLS_FIRST { $$ = SORTBY_NULLS_FIRST; }
5147 | NULLS_LAST { $$ = SORTBY_NULLS_LAST; }
5148 | /*EMPTY*/ { $$ = SORTBY_NULLS_DEFAULT; }
5152 /*****************************************************************************
5155 * create [or replace] function <fname>
5156 * [(<type-1> { , <type-n>})]
5158 * as <filename or code in language as appropriate>
5159 * language <lang> [with parameters]
5161 *****************************************************************************/
5164 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5165 RETURNS func_return createfunc_opt_list opt_definition
5167 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5176 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5177 RETURNS TABLE '(' table_func_column_list ')' createfunc_opt_list opt_definition
5179 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5182 n->parameters = mergeTableFuncParameters($5, $9);
5183 n->returnType = TableFuncTypeName($9);
5184 n->returnType->location = @7;
5186 n->withClause = $12;
5189 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
5190 createfunc_opt_list opt_definition
5192 CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
5196 n->returnType = NULL;
5204 OR REPLACE { $$ = TRUE; }
5205 | /*EMPTY*/ { $$ = FALSE; }
5208 func_args: '(' func_args_list ')' { $$ = $2; }
5209 | '(' ')' { $$ = NIL; }
5213 func_arg { $$ = list_make1($1); }
5214 | func_args_list ',' func_arg { $$ = lappend($1, $3); }
5218 * func_args_with_defaults is separate because we only want to accept
5219 * defaults in CREATE FUNCTION, not in ALTER etc.
5221 func_args_with_defaults:
5222 '(' func_args_with_defaults_list ')' { $$ = $2; }
5223 | '(' ')' { $$ = NIL; }
5226 func_args_with_defaults_list:
5227 func_arg_with_default { $$ = list_make1($1); }
5228 | func_args_with_defaults_list ',' func_arg_with_default
5229 { $$ = lappend($1, $3); }
5233 * The style with arg_class first is SQL99 standard, but Oracle puts
5234 * param_name first; accept both since it's likely people will try both
5235 * anyway. Don't bother trying to save productions by letting arg_class
5236 * have an empty alternative ... you'll get shift/reduce conflicts.
5238 * We can catch over-specified arguments here if we want to,
5239 * but for now better to silently swallow typmod, etc.
5240 * - thomas 2000-03-22
5243 arg_class param_name func_type
5245 FunctionParameter *n = makeNode(FunctionParameter);
5252 | param_name arg_class func_type
5254 FunctionParameter *n = makeNode(FunctionParameter);
5261 | param_name func_type
5263 FunctionParameter *n = makeNode(FunctionParameter);
5266 n->mode = FUNC_PARAM_IN;
5270 | arg_class func_type
5272 FunctionParameter *n = makeNode(FunctionParameter);
5281 FunctionParameter *n = makeNode(FunctionParameter);
5284 n->mode = FUNC_PARAM_IN;
5290 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
5291 arg_class: IN_P { $$ = FUNC_PARAM_IN; }
5292 | OUT_P { $$ = FUNC_PARAM_OUT; }
5293 | INOUT { $$ = FUNC_PARAM_INOUT; }
5294 | IN_P OUT_P { $$ = FUNC_PARAM_INOUT; }
5295 | VARIADIC { $$ = FUNC_PARAM_VARIADIC; }
5299 * Ideally param_name should be ColId, but that causes too many conflicts.
5301 param_name: type_function_name
5307 /* We can catch over-specified results here if we want to,
5308 * but for now better to silently swallow typmod, etc.
5309 * - thomas 2000-03-22
5316 * We would like to make the %TYPE productions here be ColId attrs etc,
5317 * but that causes reduce/reduce conflicts. type_function_name
5318 * is next best choice.
5320 func_type: Typename { $$ = $1; }
5321 | type_function_name attrs '%' TYPE_P
5323 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
5324 $$->pct_type = true;
5327 | SETOF type_function_name attrs '%' TYPE_P
5329 $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
5330 $$->pct_type = true;
5336 func_arg_with_default:
5341 | func_arg DEFAULT a_expr
5346 | func_arg '=' a_expr
5354 createfunc_opt_list:
5355 /* Must be at least one to prevent conflict */
5356 createfunc_opt_item { $$ = list_make1($1); }
5357 | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
5361 * Options common to both CREATE FUNCTION and ALTER FUNCTION
5363 common_func_opt_item:
5364 CALLED ON NULL_P INPUT_P
5366 $$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
5368 | RETURNS NULL_P ON NULL_P INPUT_P
5370 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5374 $$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
5378 $$ = makeDefElem("volatility", (Node *)makeString("immutable"));
5382 $$ = makeDefElem("volatility", (Node *)makeString("stable"));
5386 $$ = makeDefElem("volatility", (Node *)makeString("volatile"));
5388 | EXTERNAL SECURITY DEFINER
5390 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5392 | EXTERNAL SECURITY INVOKER
5394 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5398 $$ = makeDefElem("security", (Node *)makeInteger(TRUE));
5402 $$ = makeDefElem("security", (Node *)makeInteger(FALSE));
5406 $$ = makeDefElem("cost", (Node *)$2);
5410 $$ = makeDefElem("rows", (Node *)$2);
5414 /* we abuse the normal content of a DefElem here */
5415 $$ = makeDefElem("set", (Node *)$1);
5419 createfunc_opt_item:
5422 $$ = makeDefElem("as", (Node *)$2);
5424 | LANGUAGE ColId_or_Sconst
5426 $$ = makeDefElem("language", (Node *)makeString($2));
5430 $$ = makeDefElem("window", (Node *)makeInteger(TRUE));
5432 | common_func_opt_item
5438 func_as: Sconst { $$ = list_make1(makeString($1)); }
5441 $$ = list_make2(makeString($1), makeString($3));
5446 WITH definition { $$ = $2; }
5447 | /*EMPTY*/ { $$ = NIL; }
5450 table_func_column: param_name func_type
5452 FunctionParameter *n = makeNode(FunctionParameter);
5455 n->mode = FUNC_PARAM_TABLE;
5461 table_func_column_list:
5464 $$ = list_make1($1);
5466 | table_func_column_list ',' table_func_column
5468 $$ = lappend($1, $3);
5472 /*****************************************************************************
5475 * RENAME and OWNER subcommands are already provided by the generic
5476 * ALTER infrastructure, here we just specify alterations that can
5477 * only be applied to functions.
5479 *****************************************************************************/
5481 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
5483 AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
5491 /* At least one option must be specified */
5492 common_func_opt_item { $$ = list_make1($1); }
5493 | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
5496 /* Ignored, merely for SQL compliance */
5503 /*****************************************************************************
5507 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
5508 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
5509 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
5511 *****************************************************************************/
5514 DROP FUNCTION func_name func_args opt_drop_behavior
5516 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5517 n->kind = OBJECT_FUNCTION;
5519 n->args = extractArgTypes($4);
5521 n->missing_ok = false;
5524 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
5526 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5527 n->kind = OBJECT_FUNCTION;
5529 n->args = extractArgTypes($6);
5531 n->missing_ok = true;
5537 DROP AGGREGATE func_name aggr_args opt_drop_behavior
5539 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5540 n->kind = OBJECT_AGGREGATE;
5544 n->missing_ok = false;
5547 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
5549 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5550 n->kind = OBJECT_AGGREGATE;
5554 n->missing_ok = true;
5560 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
5562 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5563 n->kind = OBJECT_OPERATOR;
5567 n->missing_ok = false;
5570 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
5572 RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
5573 n->kind = OBJECT_OPERATOR;
5577 n->missing_ok = true;
5586 (errcode(ERRCODE_SYNTAX_ERROR),
5587 errmsg("missing argument"),
5588 errhint("Use NONE to denote the missing argument of a unary operator."),
5589 parser_errposition(@3)));
5591 | '(' Typename ',' Typename ')'
5592 { $$ = list_make2($2, $4); }
5593 | '(' NONE ',' Typename ')' /* left unary */
5594 { $$ = list_make2(NULL, $4); }
5595 | '(' Typename ',' NONE ')' /* right unary */
5596 { $$ = list_make2($2, NULL); }
5601 { $$ = list_make1(makeString($1)); }
5602 | ColId '.' any_operator
5603 { $$ = lcons(makeString($1), $3); }
5606 /*****************************************************************************
5608 * DO <anonymous code block> [ LANGUAGE language ]
5610 * We use a DefElem list for future extensibility, and to allow flexibility
5611 * in the clause order.
5613 *****************************************************************************/
5615 DoStmt: DO dostmt_opt_list
5617 DoStmt *n = makeNode(DoStmt);
5624 dostmt_opt_item { $$ = list_make1($1); }
5625 | dostmt_opt_list dostmt_opt_item { $$ = lappend($1, $2); }
5631 $$ = makeDefElem("as", (Node *)makeString($1));
5633 | LANGUAGE ColId_or_Sconst
5635 $$ = makeDefElem("language", (Node *)makeString($2));
5639 /*****************************************************************************
5641 * CREATE CAST / DROP CAST
5643 *****************************************************************************/
5645 CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
5646 WITH FUNCTION function_with_argtypes cast_context
5648 CreateCastStmt *n = makeNode(CreateCastStmt);
5652 n->context = (CoercionContext) $11;
5656 | CREATE CAST '(' Typename AS Typename ')'
5657 WITHOUT FUNCTION cast_context
5659 CreateCastStmt *n = makeNode(CreateCastStmt);
5663 n->context = (CoercionContext) $10;
5667 | CREATE CAST '(' Typename AS Typename ')'
5668 WITH INOUT cast_context
5670 CreateCastStmt *n = makeNode(CreateCastStmt);
5674 n->context = (CoercionContext) $10;
5680 cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
5681 | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
5682 | /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
5686 DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
5688 DropCastStmt *n = makeNode(DropCastStmt);
5697 opt_if_exists: IF_P EXISTS { $$ = TRUE; }
5698 | /*EMPTY*/ { $$ = FALSE; }
5702 /*****************************************************************************
5706 * REINDEX type <name> [FORCE]
5708 * FORCE no longer does anything, but we accept it for backwards compatibility
5709 *****************************************************************************/
5712 REINDEX reindex_type qualified_name opt_force
5714 ReindexStmt *n = makeNode(ReindexStmt);
5720 | REINDEX SYSTEM_P name opt_force
5722 ReindexStmt *n = makeNode(ReindexStmt);
5723 n->kind = OBJECT_DATABASE;
5726 n->do_system = true;
5730 | REINDEX DATABASE name opt_force
5732 ReindexStmt *n = makeNode(ReindexStmt);
5733 n->kind = OBJECT_DATABASE;
5736 n->do_system = true;
5743 INDEX { $$ = OBJECT_INDEX; }
5744 | TABLE { $$ = OBJECT_TABLE; }
5747 opt_force: FORCE { $$ = TRUE; }
5748 | /* EMPTY */ { $$ = FALSE; }
5752 /*****************************************************************************
5754 * ALTER THING name RENAME TO newname
5756 *****************************************************************************/
5758 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
5760 RenameStmt *n = makeNode(RenameStmt);
5761 n->renameType = OBJECT_AGGREGATE;
5767 | ALTER CONVERSION_P any_name RENAME TO name
5769 RenameStmt *n = makeNode(RenameStmt);
5770 n->renameType = OBJECT_CONVERSION;
5775 | ALTER DATABASE database_name RENAME TO database_name
5777 RenameStmt *n = makeNode(RenameStmt);
5778 n->renameType = OBJECT_DATABASE;
5783 | ALTER FUNCTION function_with_argtypes RENAME TO name
5785 RenameStmt *n = makeNode(RenameStmt);
5786 n->renameType = OBJECT_FUNCTION;
5787 n->object = $3->funcname;
5788 n->objarg = $3->funcargs;
5792 | ALTER GROUP_P RoleId RENAME TO RoleId
5794 RenameStmt *n = makeNode(RenameStmt);
5795 n->renameType = OBJECT_ROLE;
5800 | ALTER opt_procedural LANGUAGE name RENAME TO name
5802 RenameStmt *n = makeNode(RenameStmt);
5803 n->renameType = OBJECT_LANGUAGE;
5808 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
5810 RenameStmt *n = makeNode(RenameStmt);
5811 n->renameType = OBJECT_OPCLASS;
5817 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
5819 RenameStmt *n = makeNode(RenameStmt);
5820 n->renameType = OBJECT_OPFAMILY;
5826 | ALTER SCHEMA name RENAME TO name
5828 RenameStmt *n = makeNode(RenameStmt);
5829 n->renameType = OBJECT_SCHEMA;
5834 | ALTER TABLE relation_expr RENAME TO name
5836 RenameStmt *n = makeNode(RenameStmt);
5837 n->renameType = OBJECT_TABLE;
5843 | ALTER SEQUENCE qualified_name RENAME TO name
5845 RenameStmt *n = makeNode(RenameStmt);
5846 n->renameType = OBJECT_SEQUENCE;
5852 | ALTER VIEW qualified_name RENAME TO name
5854 RenameStmt *n = makeNode(RenameStmt);
5855 n->renameType = OBJECT_VIEW;
5861 | ALTER INDEX qualified_name RENAME TO name
5863 RenameStmt *n = makeNode(RenameStmt);
5864 n->renameType = OBJECT_INDEX;
5870 | ALTER TABLE relation_expr RENAME opt_column name TO name
5872 RenameStmt *n = makeNode(RenameStmt);
5873 n->renameType = OBJECT_COLUMN;
5879 | ALTER TRIGGER name ON qualified_name RENAME TO name
5881 RenameStmt *n = makeNode(RenameStmt);
5882 n->renameType = OBJECT_TRIGGER;
5888 | ALTER ROLE RoleId RENAME TO RoleId
5890 RenameStmt *n = makeNode(RenameStmt);
5891 n->renameType = OBJECT_ROLE;
5896 | ALTER USER RoleId RENAME TO RoleId
5898 RenameStmt *n = makeNode(RenameStmt);
5899 n->renameType = OBJECT_ROLE;
5904 | ALTER TABLESPACE name RENAME TO name
5906 RenameStmt *n = makeNode(RenameStmt);
5907 n->renameType = OBJECT_TABLESPACE;
5912 | ALTER TABLESPACE name SET reloptions
5914 AlterTableSpaceOptionsStmt *n =
5915 makeNode(AlterTableSpaceOptionsStmt);
5916 n->tablespacename = $3;
5921 | ALTER TABLESPACE name RESET reloptions
5923 AlterTableSpaceOptionsStmt *n =
5924 makeNode(AlterTableSpaceOptionsStmt);
5925 n->tablespacename = $3;
5930 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
5932 RenameStmt *n = makeNode(RenameStmt);
5933 n->renameType = OBJECT_TSPARSER;
5938 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
5940 RenameStmt *n = makeNode(RenameStmt);
5941 n->renameType = OBJECT_TSDICTIONARY;
5946 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
5948 RenameStmt *n = makeNode(RenameStmt);
5949 n->renameType = OBJECT_TSTEMPLATE;
5954 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
5956 RenameStmt *n = makeNode(RenameStmt);
5957 n->renameType = OBJECT_TSCONFIGURATION;
5962 | ALTER TYPE_P any_name RENAME TO name
5964 RenameStmt *n = makeNode(RenameStmt);
5965 n->renameType = OBJECT_TYPE;
5970 | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name
5972 RenameStmt *n = makeNode(RenameStmt);
5973 n->renameType = OBJECT_ATTRIBUTE;
5974 n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
5981 opt_column: COLUMN { $$ = COLUMN; }
5982 | /*EMPTY*/ { $$ = 0; }
5985 opt_set_data: SET DATA_P { $$ = 1; }
5986 | /*EMPTY*/ { $$ = 0; }
5989 /*****************************************************************************
5991 * ALTER THING name SET SCHEMA name
5993 *****************************************************************************/
5995 AlterObjectSchemaStmt:
5996 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
5998 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
5999 n->objectType = OBJECT_AGGREGATE;
6005 | ALTER DOMAIN_P any_name SET SCHEMA name
6007 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6008 n->objectType = OBJECT_DOMAIN;
6013 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
6015 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6016 n->objectType = OBJECT_FUNCTION;
6017 n->object = $3->funcname;
6018 n->objarg = $3->funcargs;
6022 | ALTER TABLE relation_expr SET SCHEMA name
6024 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6025 n->objectType = OBJECT_TABLE;
6030 | ALTER SEQUENCE qualified_name SET SCHEMA name
6032 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6033 n->objectType = OBJECT_SEQUENCE;
6038 | ALTER VIEW qualified_name SET SCHEMA name
6040 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6041 n->objectType = OBJECT_VIEW;
6046 | ALTER TYPE_P any_name SET SCHEMA name
6048 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
6049 n->objectType = OBJECT_TYPE;
6056 /*****************************************************************************
6058 * ALTER THING name OWNER TO newname
6060 *****************************************************************************/
6062 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
6064 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6065 n->objectType = OBJECT_AGGREGATE;
6071 | ALTER CONVERSION_P any_name OWNER TO RoleId
6073 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6074 n->objectType = OBJECT_CONVERSION;
6079 | ALTER DATABASE database_name OWNER TO RoleId
6081 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6082 n->objectType = OBJECT_DATABASE;
6083 n->object = list_make1(makeString($3));
6087 | ALTER DOMAIN_P any_name OWNER TO RoleId
6089 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6090 n->objectType = OBJECT_DOMAIN;
6095 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
6097 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6098 n->objectType = OBJECT_FUNCTION;
6099 n->object = $3->funcname;
6100 n->objarg = $3->funcargs;
6104 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
6106 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6107 n->objectType = OBJECT_LANGUAGE;
6108 n->object = list_make1(makeString($4));
6112 | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleId
6114 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6115 n->objectType = OBJECT_LARGEOBJECT;
6116 n->object = list_make1($4);
6120 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
6122 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6123 n->objectType = OBJECT_OPERATOR;
6129 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
6131 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6132 n->objectType = OBJECT_OPCLASS;
6138 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
6140 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6141 n->objectType = OBJECT_OPFAMILY;
6147 | ALTER SCHEMA name OWNER TO RoleId
6149 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6150 n->objectType = OBJECT_SCHEMA;
6151 n->object = list_make1(makeString($3));
6155 | ALTER TYPE_P any_name OWNER TO RoleId
6157 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6158 n->objectType = OBJECT_TYPE;
6163 | ALTER TABLESPACE name OWNER TO RoleId
6165 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6166 n->objectType = OBJECT_TABLESPACE;
6167 n->object = list_make1(makeString($3));
6171 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
6173 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6174 n->objectType = OBJECT_TSDICTIONARY;
6179 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
6181 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6182 n->objectType = OBJECT_TSCONFIGURATION;
6187 | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleId
6189 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6190 n->objectType = OBJECT_FDW;
6191 n->object = list_make1(makeString($5));
6195 | ALTER SERVER name OWNER TO RoleId
6197 AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
6198 n->objectType = OBJECT_FOREIGN_SERVER;
6199 n->object = list_make1(makeString($3));
6206 /*****************************************************************************
6208 * QUERY: Define Rewrite Rule
6210 *****************************************************************************/
6212 RuleStmt: CREATE opt_or_replace RULE name AS
6213 ON event TO qualified_name where_clause
6214 DO opt_instead RuleActionList
6216 RuleStmt *n = makeNode(RuleStmt);
6220 n->whereClause = $10;
6229 NOTHING { $$ = NIL; }
6230 | RuleActionStmt { $$ = list_make1($1); }
6231 | '(' RuleActionMulti ')' { $$ = $2; }
6234 /* the thrashing around here is to discard "empty" statements... */
6236 RuleActionMulti ';' RuleActionStmtOrEmpty
6238 $$ = lappend($1, $3);
6242 | RuleActionStmtOrEmpty
6244 $$ = list_make1($1);
6258 RuleActionStmtOrEmpty:
6259 RuleActionStmt { $$ = $1; }
6260 | /*EMPTY*/ { $$ = NULL; }
6263 event: SELECT { $$ = CMD_SELECT; }
6264 | UPDATE { $$ = CMD_UPDATE; }
6265 | DELETE_P { $$ = CMD_DELETE; }
6266 | INSERT { $$ = CMD_INSERT; }
6270 INSTEAD { $$ = TRUE; }
6271 | ALSO { $$ = FALSE; }
6272 | /*EMPTY*/ { $$ = FALSE; }
6277 DROP RULE name ON qualified_name opt_drop_behavior
6279 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6283 n->removeType = OBJECT_RULE;
6284 n->missing_ok = false;
6287 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
6289 DropPropertyStmt *n = makeNode(DropPropertyStmt);
6293 n->removeType = OBJECT_RULE;
6294 n->missing_ok = true;
6300 /*****************************************************************************
6303 * NOTIFY <identifier> can appear both in rule bodies and
6304 * as a query-level command
6306 *****************************************************************************/
6308 NotifyStmt: NOTIFY ColId notify_payload
6310 NotifyStmt *n = makeNode(NotifyStmt);
6311 n->conditionname = $2;
6318 ',' Sconst { $$ = $2; }
6319 | /*EMPTY*/ { $$ = NULL; }
6322 ListenStmt: LISTEN ColId
6324 ListenStmt *n = makeNode(ListenStmt);
6325 n->conditionname = $2;
6333 UnlistenStmt *n = makeNode(UnlistenStmt);
6334 n->conditionname = $2;
6339 UnlistenStmt *n = makeNode(UnlistenStmt);
6340 n->conditionname = NULL;
6346 /*****************************************************************************
6350 * BEGIN / COMMIT / ROLLBACK
6351 * (also older versions END / ABORT)
6353 *****************************************************************************/
6356 ABORT_P opt_transaction
6358 TransactionStmt *n = makeNode(TransactionStmt);
6359 n->kind = TRANS_STMT_ROLLBACK;
6363 | BEGIN_P opt_transaction transaction_mode_list_or_empty
6365 TransactionStmt *n = makeNode(TransactionStmt);
6366 n->kind = TRANS_STMT_BEGIN;
6370 | START TRANSACTION transaction_mode_list_or_empty
6372 TransactionStmt *n = makeNode(TransactionStmt);
6373 n->kind = TRANS_STMT_START;
6377 | COMMIT opt_transaction
6379 TransactionStmt *n = makeNode(TransactionStmt);
6380 n->kind = TRANS_STMT_COMMIT;
6384 | END_P opt_transaction
6386 TransactionStmt *n = makeNode(TransactionStmt);
6387 n->kind = TRANS_STMT_COMMIT;
6391 | ROLLBACK opt_transaction
6393 TransactionStmt *n = makeNode(TransactionStmt);
6394 n->kind = TRANS_STMT_ROLLBACK;
6400 TransactionStmt *n = makeNode(TransactionStmt);
6401 n->kind = TRANS_STMT_SAVEPOINT;
6402 n->options = list_make1(makeDefElem("savepoint_name",
6403 (Node *)makeString($2)));
6406 | RELEASE SAVEPOINT ColId
6408 TransactionStmt *n = makeNode(TransactionStmt);
6409 n->kind = TRANS_STMT_RELEASE;
6410 n->options = list_make1(makeDefElem("savepoint_name",
6411 (Node *)makeString($3)));
6416 TransactionStmt *n = makeNode(TransactionStmt);
6417 n->kind = TRANS_STMT_RELEASE;
6418 n->options = list_make1(makeDefElem("savepoint_name",
6419 (Node *)makeString($2)));
6422 | ROLLBACK opt_transaction TO SAVEPOINT ColId
6424 TransactionStmt *n = makeNode(TransactionStmt);
6425 n->kind = TRANS_STMT_ROLLBACK_TO;
6426 n->options = list_make1(makeDefElem("savepoint_name",
6427 (Node *)makeString($5)));
6430 | ROLLBACK opt_transaction TO ColId
6432 TransactionStmt *n = makeNode(TransactionStmt);
6433 n->kind = TRANS_STMT_ROLLBACK_TO;
6434 n->options = list_make1(makeDefElem("savepoint_name",
6435 (Node *)makeString($4)));
6438 | PREPARE TRANSACTION Sconst
6440 TransactionStmt *n = makeNode(TransactionStmt);
6441 n->kind = TRANS_STMT_PREPARE;
6445 | COMMIT PREPARED Sconst
6447 TransactionStmt *n = makeNode(TransactionStmt);
6448 n->kind = TRANS_STMT_COMMIT_PREPARED;
6452 | ROLLBACK PREPARED Sconst
6454 TransactionStmt *n = makeNode(TransactionStmt);
6455 n->kind = TRANS_STMT_ROLLBACK_PREPARED;
6461 opt_transaction: WORK {}
6466 transaction_mode_item:
6467 ISOLATION LEVEL iso_level
6468 { $$ = makeDefElem("transaction_isolation",
6469 makeStringConst($3, @3)); }
6471 { $$ = makeDefElem("transaction_read_only",
6472 makeIntConst(TRUE, @1)); }
6474 { $$ = makeDefElem("transaction_read_only",
6475 makeIntConst(FALSE, @1)); }
6478 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
6479 transaction_mode_list:
6480 transaction_mode_item
6481 { $$ = list_make1($1); }
6482 | transaction_mode_list ',' transaction_mode_item
6483 { $$ = lappend($1, $3); }
6484 | transaction_mode_list transaction_mode_item
6485 { $$ = lappend($1, $2); }
6488 transaction_mode_list_or_empty:
6489 transaction_mode_list
6495 /*****************************************************************************
6498 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
6499 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
6501 *****************************************************************************/
6503 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
6504 AS SelectStmt opt_check_option
6506 ViewStmt *n = makeNode(ViewStmt);
6508 n->view->istemp = $2;
6514 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
6515 AS SelectStmt opt_check_option
6517 ViewStmt *n = makeNode(ViewStmt);
6519 n->view->istemp = $4;
6531 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6532 errmsg("WITH CHECK OPTION is not implemented")));
6534 | WITH CASCADED CHECK OPTION
6537 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6538 errmsg("WITH CHECK OPTION is not implemented")));
6540 | WITH LOCAL CHECK OPTION
6543 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6544 errmsg("WITH CHECK OPTION is not implemented")));
6546 | /* EMPTY */ { $$ = NIL; }
6549 /*****************************************************************************
6554 *****************************************************************************/
6556 LoadStmt: LOAD file_name
6558 LoadStmt *n = makeNode(LoadStmt);
6565 /*****************************************************************************
6569 *****************************************************************************/
6572 CREATE DATABASE database_name opt_with createdb_opt_list
6574 CreatedbStmt *n = makeNode(CreatedbStmt);
6582 createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
6583 | /* EMPTY */ { $$ = NIL; }
6587 TABLESPACE opt_equal name
6589 $$ = makeDefElem("tablespace", (Node *)makeString($3));
6591 | TABLESPACE opt_equal DEFAULT
6593 $$ = makeDefElem("tablespace", NULL);
6595 | LOCATION opt_equal Sconst
6597 $$ = makeDefElem("location", (Node *)makeString($3));
6599 | LOCATION opt_equal DEFAULT
6601 $$ = makeDefElem("location", NULL);
6603 | TEMPLATE opt_equal name
6605 $$ = makeDefElem("template", (Node *)makeString($3));
6607 | TEMPLATE opt_equal DEFAULT
6609 $$ = makeDefElem("template", NULL);
6611 | ENCODING opt_equal Sconst
6613 $$ = makeDefElem("encoding", (Node *)makeString($3));
6615 | ENCODING opt_equal Iconst
6617 $$ = makeDefElem("encoding", (Node *)makeInteger($3));
6619 | ENCODING opt_equal DEFAULT
6621 $$ = makeDefElem("encoding", NULL);
6623 | LC_COLLATE_P opt_equal Sconst
6625 $$ = makeDefElem("lc_collate", (Node *)makeString($3));
6627 | LC_COLLATE_P opt_equal DEFAULT
6629 $$ = makeDefElem("lc_collate", NULL);
6631 | LC_CTYPE_P opt_equal Sconst
6633 $$ = makeDefElem("lc_ctype", (Node *)makeString($3));
6635 | LC_CTYPE_P opt_equal DEFAULT
6637 $$ = makeDefElem("lc_ctype", NULL);
6639 | CONNECTION LIMIT opt_equal SignedIconst
6641 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6643 | OWNER opt_equal name
6645 $$ = makeDefElem("owner", (Node *)makeString($3));
6647 | OWNER opt_equal DEFAULT
6649 $$ = makeDefElem("owner", NULL);
6654 * Though the equals sign doesn't match other WITH options, pg_dump uses
6655 * equals for backward compatibility, and it doesn't seem worth removing it.
6662 /*****************************************************************************
6666 *****************************************************************************/
6669 ALTER DATABASE database_name opt_with alterdb_opt_list
6671 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6676 | ALTER DATABASE database_name SET TABLESPACE name
6678 AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
6680 n->options = list_make1(makeDefElem("tablespace",
6681 (Node *)makeString($6)));
6686 AlterDatabaseSetStmt:
6687 ALTER DATABASE database_name SetResetClause
6689 AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
6698 alterdb_opt_list alterdb_opt_item { $$ = lappend($1, $2); }
6699 | /* EMPTY */ { $$ = NIL; }
6703 CONNECTION LIMIT opt_equal SignedIconst
6705 $$ = makeDefElem("connectionlimit", (Node *)makeInteger($4));
6710 /*****************************************************************************
6712 * DROP DATABASE [ IF EXISTS ]
6714 * This is implicitly CASCADE, no need for drop behavior
6715 *****************************************************************************/
6717 DropdbStmt: DROP DATABASE database_name
6719 DropdbStmt *n = makeNode(DropdbStmt);
6721 n->missing_ok = FALSE;
6724 | DROP DATABASE IF_P EXISTS database_name
6726 DropdbStmt *n = makeNode(DropdbStmt);
6728 n->missing_ok = TRUE;
6734 /*****************************************************************************
6736 * Manipulate a domain
6738 *****************************************************************************/
6741 CREATE DOMAIN_P any_name opt_as Typename ColQualList
6743 CreateDomainStmt *n = makeNode(CreateDomainStmt);
6746 n->constraints = $6;
6752 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
6753 ALTER DOMAIN_P any_name alter_column_default
6755 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6761 /* ALTER DOMAIN <domain> DROP NOT NULL */
6762 | ALTER DOMAIN_P any_name DROP NOT NULL_P
6764 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6769 /* ALTER DOMAIN <domain> SET NOT NULL */
6770 | ALTER DOMAIN_P any_name SET NOT NULL_P
6772 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6777 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
6778 | ALTER DOMAIN_P any_name ADD_P TableConstraint
6780 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6786 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
6787 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
6789 AlterDomainStmt *n = makeNode(AlterDomainStmt);
6803 /*****************************************************************************
6805 * Manipulate a text search dictionary or configuration
6807 *****************************************************************************/
6809 AlterTSDictionaryStmt:
6810 ALTER TEXT_P SEARCH DICTIONARY any_name definition
6812 AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
6819 AlterTSConfigurationStmt:
6820 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
6822 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6826 n->override = false;
6830 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
6832 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6840 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
6842 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6845 n->dicts = list_make2($9,$11);
6846 n->override = false;
6850 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
6852 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6855 n->dicts = list_make2($11,$13);
6856 n->override = false;
6860 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
6862 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6865 n->missing_ok = false;
6868 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
6870 AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
6873 n->missing_ok = true;
6879 /*****************************************************************************
6881 * Manipulate a conversion
6883 * CREATE [DEFAULT] CONVERSION <conversion_name>
6884 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
6886 *****************************************************************************/
6888 CreateConversionStmt:
6889 CREATE opt_default CONVERSION_P any_name FOR Sconst
6890 TO Sconst FROM any_name
6892 CreateConversionStmt *n = makeNode(CreateConversionStmt);
6893 n->conversion_name = $4;
6894 n->for_encoding_name = $6;
6895 n->to_encoding_name = $8;
6902 /*****************************************************************************
6905 * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
6907 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
6909 *****************************************************************************/
6912 CLUSTER opt_verbose qualified_name cluster_index_specification
6914 ClusterStmt *n = makeNode(ClusterStmt);
6920 | CLUSTER opt_verbose
6922 ClusterStmt *n = makeNode(ClusterStmt);
6924 n->indexname = NULL;
6928 /* kept for pre-8.3 compatibility */
6929 | CLUSTER opt_verbose index_name ON qualified_name
6931 ClusterStmt *n = makeNode(ClusterStmt);
6939 cluster_index_specification:
6940 USING index_name { $$ = $2; }
6941 | /*EMPTY*/ { $$ = NULL; }
6945 /*****************************************************************************
6951 *****************************************************************************/
6953 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
6955 VacuumStmt *n = makeNode(VacuumStmt);
6956 n->options = VACOPT_VACUUM;
6958 n->options |= VACOPT_FULL;
6960 n->options |= VACOPT_VERBOSE;
6961 n->freeze_min_age = $3 ? 0 : -1;
6962 n->freeze_table_age = $3 ? 0 : -1;
6967 | VACUUM opt_full opt_freeze opt_verbose qualified_name
6969 VacuumStmt *n = makeNode(VacuumStmt);
6970 n->options = VACOPT_VACUUM;
6972 n->options |= VACOPT_FULL;
6974 n->options |= VACOPT_VERBOSE;
6975 n->freeze_min_age = $3 ? 0 : -1;
6976 n->freeze_table_age = $3 ? 0 : -1;
6981 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
6983 VacuumStmt *n = (VacuumStmt *) $5;
6984 n->options |= VACOPT_VACUUM;
6986 n->options |= VACOPT_FULL;
6988 n->options |= VACOPT_VERBOSE;
6989 n->freeze_min_age = $3 ? 0 : -1;
6990 n->freeze_table_age = $3 ? 0 : -1;
6993 | VACUUM '(' vacuum_option_list ')'
6995 VacuumStmt *n = makeNode(VacuumStmt);
6996 n->options = VACOPT_VACUUM | $3;
6997 if (n->options & VACOPT_FREEZE)
6998 n->freeze_min_age = n->freeze_table_age = 0;
7000 n->freeze_min_age = n->freeze_table_age = -1;
7005 | VACUUM '(' vacuum_option_list ')' qualified_name opt_name_list
7007 VacuumStmt *n = makeNode(VacuumStmt);
7008 n->options = VACOPT_VACUUM | $3;
7009 if (n->options & VACOPT_FREEZE)
7010 n->freeze_min_age = n->freeze_table_age = 0;
7012 n->freeze_min_age = n->freeze_table_age = -1;
7015 if (n->va_cols != NIL) /* implies analyze */
7016 n->options |= VACOPT_ANALYZE;
7022 vacuum_option_elem { $$ = $1; }
7023 | vacuum_option_list ',' vacuum_option_elem { $$ = $1 | $3; }
7027 analyze_keyword { $$ = VACOPT_ANALYZE; }
7028 | VERBOSE { $$ = VACOPT_VERBOSE; }
7029 | FREEZE { $$ = VACOPT_FREEZE; }
7030 | FULL { $$ = VACOPT_FULL; }
7034 analyze_keyword opt_verbose
7036 VacuumStmt *n = makeNode(VacuumStmt);
7037 n->options = VACOPT_ANALYZE;
7039 n->options |= VACOPT_VERBOSE;
7040 n->freeze_min_age = -1;
7041 n->freeze_table_age = -1;
7046 | analyze_keyword opt_verbose qualified_name opt_name_list
7048 VacuumStmt *n = makeNode(VacuumStmt);
7049 n->options = VACOPT_ANALYZE;
7051 n->options |= VACOPT_VERBOSE;
7052 n->freeze_min_age = -1;
7053 n->freeze_table_age = -1;
7062 | ANALYSE /* British */ {}
7066 VERBOSE { $$ = TRUE; }
7067 | /*EMPTY*/ { $$ = FALSE; }
7070 opt_full: FULL { $$ = TRUE; }
7071 | /*EMPTY*/ { $$ = FALSE; }
7074 opt_freeze: FREEZE { $$ = TRUE; }
7075 | /*EMPTY*/ { $$ = FALSE; }
7079 '(' name_list ')' { $$ = $2; }
7080 | /*EMPTY*/ { $$ = NIL; }
7084 /*****************************************************************************
7087 * EXPLAIN [ANALYZE] [VERBOSE] query
7088 * EXPLAIN ( options ) query
7090 *****************************************************************************/
7093 EXPLAIN ExplainableStmt
7095 ExplainStmt *n = makeNode(ExplainStmt);
7100 | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
7102 ExplainStmt *n = makeNode(ExplainStmt);
7104 n->options = list_make1(makeDefElem("analyze", NULL));
7106 n->options = lappend(n->options,
7107 makeDefElem("verbose", NULL));
7110 | EXPLAIN VERBOSE ExplainableStmt
7112 ExplainStmt *n = makeNode(ExplainStmt);
7114 n->options = list_make1(makeDefElem("verbose", NULL));
7117 | EXPLAIN '(' explain_option_list ')' ExplainableStmt
7119 ExplainStmt *n = makeNode(ExplainStmt);
7133 | ExecuteStmt /* by default all are $$=$1 */
7136 explain_option_list:
7139 $$ = list_make1($1);
7141 | explain_option_list ',' explain_option_elem
7143 $$ = lappend($1, $3);
7147 explain_option_elem:
7148 explain_option_name explain_option_arg
7150 $$ = makeDefElem($1, $2);
7154 explain_option_name:
7156 | analyze_keyword { $$ = "analyze"; }
7157 | VERBOSE { $$ = "verbose"; }
7161 opt_boolean { $$ = (Node *) makeString($1); }
7162 | ColId_or_Sconst { $$ = (Node *) makeString($1); }
7163 | NumericOnly { $$ = (Node *) $1; }
7164 | /* EMPTY */ { $$ = NULL; }
7167 /*****************************************************************************
7170 * PREPARE <plan_name> [(args, ...)] AS <query>
7172 *****************************************************************************/
7174 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
7176 PrepareStmt *n = makeNode(PrepareStmt);
7184 prep_type_clause: '(' type_list ')' { $$ = $2; }
7185 | /* EMPTY */ { $$ = NIL; }
7192 | DeleteStmt /* by default all are $$=$1 */
7195 /*****************************************************************************
7197 * EXECUTE <plan_name> [(params, ...)]
7198 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
7200 *****************************************************************************/
7202 ExecuteStmt: EXECUTE name execute_param_clause
7204 ExecuteStmt *n = makeNode(ExecuteStmt);
7210 | CREATE OptTemp TABLE create_as_target AS
7211 EXECUTE name execute_param_clause
7213 ExecuteStmt *n = makeNode(ExecuteStmt);
7216 $4->rel->istemp = $2;
7220 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7221 errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
7222 /* ... because it's not implemented, but it could be */
7227 execute_param_clause: '(' expr_list ')' { $$ = $2; }
7228 | /* EMPTY */ { $$ = NIL; }
7231 /*****************************************************************************
7234 * DEALLOCATE [PREPARE] <plan_name>
7236 *****************************************************************************/
7238 DeallocateStmt: DEALLOCATE name
7240 DeallocateStmt *n = makeNode(DeallocateStmt);
7244 | DEALLOCATE PREPARE name
7246 DeallocateStmt *n = makeNode(DeallocateStmt);
7252 DeallocateStmt *n = makeNode(DeallocateStmt);
7256 | DEALLOCATE PREPARE ALL
7258 DeallocateStmt *n = makeNode(DeallocateStmt);
7264 /*****************************************************************************
7269 *****************************************************************************/
7272 INSERT INTO qualified_name insert_rest returning_clause
7275 $4->returningList = $5;
7283 $$ = makeNode(InsertStmt);
7285 $$->selectStmt = $1;
7287 | '(' insert_column_list ')' SelectStmt
7289 $$ = makeNode(InsertStmt);
7291 $$->selectStmt = $4;
7295 $$ = makeNode(InsertStmt);
7297 $$->selectStmt = NULL;
7303 { $$ = list_make1($1); }
7304 | insert_column_list ',' insert_column_item
7305 { $$ = lappend($1, $3); }
7309 ColId opt_indirection
7311 $$ = makeNode(ResTarget);
7313 $$->indirection = check_indirection($2, yyscanner);
7320 RETURNING target_list { $$ = $2; }
7321 | /* EMPTY */ { $$ = NIL; }
7325 /*****************************************************************************
7330 *****************************************************************************/
7332 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
7333 using_clause where_or_current_clause returning_clause
7335 DeleteStmt *n = makeNode(DeleteStmt);
7337 n->usingClause = $4;
7338 n->whereClause = $5;
7339 n->returningList = $6;
7345 USING from_list { $$ = $2; }
7346 | /*EMPTY*/ { $$ = NIL; }
7350 /*****************************************************************************
7355 *****************************************************************************/
7357 LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
7359 LockStmt *n = makeNode(LockStmt);
7368 opt_lock: IN_P lock_type MODE { $$ = $2; }
7369 | /*EMPTY*/ { $$ = AccessExclusiveLock; }
7372 lock_type: ACCESS SHARE { $$ = AccessShareLock; }
7373 | ROW SHARE { $$ = RowShareLock; }
7374 | ROW EXCLUSIVE { $$ = RowExclusiveLock; }
7375 | SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
7376 | SHARE { $$ = ShareLock; }
7377 | SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
7378 | EXCLUSIVE { $$ = ExclusiveLock; }
7379 | ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
7382 opt_nowait: NOWAIT { $$ = TRUE; }
7383 | /*EMPTY*/ { $$ = FALSE; }
7387 /*****************************************************************************
7390 * UpdateStmt (UPDATE)
7392 *****************************************************************************/
7394 UpdateStmt: UPDATE relation_expr_opt_alias
7397 where_or_current_clause
7400 UpdateStmt *n = makeNode(UpdateStmt);
7404 n->whereClause = $6;
7405 n->returningList = $7;
7411 set_clause { $$ = $1; }
7412 | set_clause_list ',' set_clause { $$ = list_concat($1,$3); }
7416 single_set_clause { $$ = list_make1($1); }
7417 | multiple_set_clause { $$ = $1; }
7421 set_target '=' ctext_expr
7424 $$->val = (Node *) $3;
7428 multiple_set_clause:
7429 '(' set_target_list ')' '=' ctext_row
7435 * Break the ctext_row apart, merge individual expressions
7436 * into the destination ResTargets. XXX this approach
7437 * cannot work for general row expressions as sources.
7439 if (list_length($2) != list_length($5))
7441 (errcode(ERRCODE_SYNTAX_ERROR),
7442 errmsg("number of columns does not match number of values"),
7443 parser_errposition(@1)));
7444 forboth(col_cell, $2, val_cell, $5)
7446 ResTarget *res_col = (ResTarget *) lfirst(col_cell);
7447 Node *res_val = (Node *) lfirst(val_cell);
7449 res_col->val = res_val;
7457 ColId opt_indirection
7459 $$ = makeNode(ResTarget);
7461 $$->indirection = check_indirection($2, yyscanner);
7462 $$->val = NULL; /* upper production sets this */
7468 set_target { $$ = list_make1($1); }
7469 | set_target_list ',' set_target { $$ = lappend($1,$3); }
7473 /*****************************************************************************
7478 *****************************************************************************/
7479 DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
7481 DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
7483 /* currently we always set FAST_PLAN option */
7484 n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
7490 cursor_name: name { $$ = $1; }
7493 cursor_options: /*EMPTY*/ { $$ = 0; }
7494 | cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
7495 | cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
7496 | cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
7497 | cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
7500 opt_hold: /* EMPTY */ { $$ = 0; }
7501 | WITH HOLD { $$ = CURSOR_OPT_HOLD; }
7502 | WITHOUT HOLD { $$ = 0; }
7505 /*****************************************************************************
7510 *****************************************************************************/
7512 /* A complete SELECT statement looks like this.
7514 * The rule returns either a single SelectStmt node or a tree of them,
7515 * representing a set-operation tree.
7517 * There is an ambiguity when a sub-SELECT is within an a_expr and there
7518 * are excess parentheses: do the parentheses belong to the sub-SELECT or
7519 * to the surrounding a_expr? We don't really care, but bison wants to know.
7520 * To resolve the ambiguity, we are careful to define the grammar so that
7521 * the decision is staved off as long as possible: as long as we can keep
7522 * absorbing parentheses into the sub-SELECT, we will do so, and only when
7523 * it's no longer possible to do that will we decide that parens belong to
7524 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
7525 * parentheses are treated as part of the sub-select. The necessity of doing
7526 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
7527 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
7528 * SELECT viewpoint when we see the UNION.
7530 * This approach is implemented by defining a nonterminal select_with_parens,
7531 * which represents a SELECT with at least one outer layer of parentheses,
7532 * and being careful to use select_with_parens, never '(' SelectStmt ')',
7533 * in the expression grammar. We will then have shift-reduce conflicts
7534 * which we can resolve in favor of always treating '(' <select> ')' as
7535 * a select_with_parens. To resolve the conflicts, the productions that
7536 * conflict with the select_with_parens productions are manually given
7537 * precedences lower than the precedence of ')', thereby ensuring that we
7538 * shift ')' (and then reduce to select_with_parens) rather than trying to
7539 * reduce the inner <select> nonterminal to something else. We use UMINUS
7540 * precedence for this, which is a fairly arbitrary choice.
7542 * To be able to define select_with_parens itself without ambiguity, we need
7543 * a nonterminal select_no_parens that represents a SELECT structure with no
7544 * outermost parentheses. This is a little bit tedious, but it works.
7546 * In non-expression contexts, we use SelectStmt which can represent a SELECT
7547 * with or without outer parentheses.
7550 SelectStmt: select_no_parens %prec UMINUS
7551 | select_with_parens %prec UMINUS
7555 '(' select_no_parens ')' { $$ = $2; }
7556 | '(' select_with_parens ')' { $$ = $2; }
7560 * This rule parses the equivalent of the standard's <query expression>.
7561 * The duplicative productions are annoying, but hard to get rid of without
7562 * creating shift/reduce conflicts.
7564 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
7565 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
7566 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
7570 simple_select { $$ = $1; }
7571 | select_clause sort_clause
7573 insertSelectOptions((SelectStmt *) $1, $2, NIL,
7578 | select_clause opt_sort_clause for_locking_clause opt_select_limit
7580 insertSelectOptions((SelectStmt *) $1, $2, $3,
7581 list_nth($4, 0), list_nth($4, 1),
7586 | select_clause opt_sort_clause select_limit opt_for_locking_clause
7588 insertSelectOptions((SelectStmt *) $1, $2, $4,
7589 list_nth($3, 0), list_nth($3, 1),
7594 | with_clause select_clause
7596 insertSelectOptions((SelectStmt *) $2, NULL, NIL,
7602 | with_clause select_clause sort_clause
7604 insertSelectOptions((SelectStmt *) $2, $3, NIL,
7610 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
7612 insertSelectOptions((SelectStmt *) $2, $3, $4,
7613 list_nth($5, 0), list_nth($5, 1),
7618 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
7620 insertSelectOptions((SelectStmt *) $2, $3, $5,
7621 list_nth($4, 0), list_nth($4, 1),
7629 simple_select { $$ = $1; }
7630 | select_with_parens { $$ = $1; }
7634 * This rule parses SELECT statements that can appear within set operations,
7635 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
7636 * the ordering of the set operations. Without '(' and ')' we want the
7637 * operations to be ordered per the precedence specs at the head of this file.
7639 * As with select_no_parens, simple_select cannot have outer parentheses,
7640 * but can have parenthesized subclauses.
7642 * Note that sort clauses cannot be included at this level --- SQL92 requires
7643 * SELECT foo UNION SELECT bar ORDER BY baz
7645 * (SELECT foo UNION SELECT bar) ORDER BY baz
7647 * SELECT foo UNION (SELECT bar ORDER BY baz)
7648 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
7649 * described as part of the select_no_parens production, not simple_select.
7650 * This does not limit functionality, because you can reintroduce these
7651 * clauses inside parentheses.
7653 * NOTE: only the leftmost component SelectStmt should have INTO.
7654 * However, this is not checked by the grammar; parse analysis must check it.
7657 SELECT opt_distinct target_list
7658 into_clause from_clause where_clause
7659 group_clause having_clause window_clause
7661 SelectStmt *n = makeNode(SelectStmt);
7662 n->distinctClause = $2;
7666 n->whereClause = $6;
7667 n->groupClause = $7;
7668 n->havingClause = $8;
7669 n->windowClause = $9;
7672 | values_clause { $$ = $1; }
7673 | TABLE relation_expr
7675 /* same as SELECT * FROM relation_expr */
7676 ColumnRef *cr = makeNode(ColumnRef);
7677 ResTarget *rt = makeNode(ResTarget);
7678 SelectStmt *n = makeNode(SelectStmt);
7680 cr->fields = list_make1(makeNode(A_Star));
7684 rt->indirection = NIL;
7685 rt->val = (Node *)cr;
7688 n->targetList = list_make1(rt);
7689 n->fromClause = list_make1($2);
7692 | select_clause UNION opt_all select_clause
7694 $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
7696 | select_clause INTERSECT opt_all select_clause
7698 $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
7700 | select_clause EXCEPT opt_all select_clause
7702 $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
7707 * SQL standard WITH clause looks like:
7709 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
7710 * AS (query) [ SEARCH or CYCLE clause ]
7712 * We don't currently support the SEARCH or CYCLE clause.
7717 $$ = makeNode(WithClause);
7719 $$->recursive = false;
7722 | WITH RECURSIVE cte_list
7724 $$ = makeNode(WithClause);
7726 $$->recursive = true;
7732 common_table_expr { $$ = list_make1($1); }
7733 | cte_list ',' common_table_expr { $$ = lappend($1, $3); }
7736 common_table_expr: name opt_name_list AS select_with_parens
7738 CommonTableExpr *n = makeNode(CommonTableExpr);
7740 n->aliascolnames = $2;
7748 INTO OptTempTableName
7750 $$ = makeNode(IntoClause);
7754 $$->onCommit = ONCOMMIT_NOOP;
7755 $$->tableSpaceName = NULL;
7762 * Redundancy here is needed to avoid shift/reduce conflicts,
7763 * since TEMP is not a reserved word. See also OptTemp.
7766 TEMPORARY opt_table qualified_name
7771 | TEMP opt_table qualified_name
7776 | LOCAL TEMPORARY opt_table qualified_name
7781 | LOCAL TEMP opt_table qualified_name
7786 | GLOBAL TEMPORARY opt_table qualified_name
7791 | GLOBAL TEMP opt_table qualified_name
7796 | TABLE qualified_name
7812 opt_all: ALL { $$ = TRUE; }
7813 | DISTINCT { $$ = FALSE; }
7814 | /*EMPTY*/ { $$ = FALSE; }
7817 /* We use (NIL) as a placeholder to indicate that all target expressions
7818 * should be placed in the DISTINCT list during parsetree analysis.
7821 DISTINCT { $$ = list_make1(NIL); }
7822 | DISTINCT ON '(' expr_list ')' { $$ = $4; }
7824 | /*EMPTY*/ { $$ = NIL; }
7828 sort_clause { $$ = $1;}
7829 | /*EMPTY*/ { $$ = NIL; }
7833 ORDER BY sortby_list { $$ = $3; }
7837 sortby { $$ = list_make1($1); }
7838 | sortby_list ',' sortby { $$ = lappend($1, $3); }
7841 sortby: a_expr USING qual_all_Op opt_nulls_order
7843 $$ = makeNode(SortBy);
7845 $$->sortby_dir = SORTBY_USING;
7846 $$->sortby_nulls = $4;
7850 | a_expr opt_asc_desc opt_nulls_order
7852 $$ = makeNode(SortBy);
7854 $$->sortby_dir = $2;
7855 $$->sortby_nulls = $3;
7857 $$->location = -1; /* no operator */
7863 limit_clause offset_clause { $$ = list_make2($2, $1); }
7864 | offset_clause limit_clause { $$ = list_make2($1, $2); }
7865 | limit_clause { $$ = list_make2(NULL, $1); }
7866 | offset_clause { $$ = list_make2($1, NULL); }
7870 select_limit { $$ = $1; }
7871 | /* EMPTY */ { $$ = list_make2(NULL,NULL); }
7875 LIMIT select_limit_value
7877 | LIMIT select_limit_value ',' select_offset_value
7879 /* Disabled because it was too confusing, bjm 2002-02-18 */
7881 (errcode(ERRCODE_SYNTAX_ERROR),
7882 errmsg("LIMIT #,# syntax is not supported"),
7883 errhint("Use separate LIMIT and OFFSET clauses."),
7884 parser_errposition(@1)));
7886 /* SQL:2008 syntax */
7887 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
7892 OFFSET select_offset_value
7894 /* SQL:2008 syntax */
7895 | OFFSET select_offset_value2 row_or_rows
7903 /* LIMIT ALL is represented as a NULL constant */
7904 $$ = makeNullAConst(@1);
7908 select_offset_value:
7913 * Allowing full expressions without parentheses causes various parsing
7914 * problems with the trailing ROW/ROWS key words. SQL only calls for
7915 * constants, so we allow the rest only with parentheses. If omitted,
7918 opt_select_fetch_first_value:
7919 SignedIconst { $$ = makeIntConst($1, @1); }
7920 | '(' a_expr ')' { $$ = $2; }
7921 | /*EMPTY*/ { $$ = makeIntConst(1, -1); }
7925 * Again, the trailing ROW/ROWS in this case prevent the full expression
7926 * syntax. c_expr is the best we can do.
7928 select_offset_value2:
7933 row_or_rows: ROW { $$ = 0; }
7937 first_or_next: FIRST_P { $$ = 0; }
7943 GROUP_P BY expr_list { $$ = $3; }
7944 | /*EMPTY*/ { $$ = NIL; }
7948 HAVING a_expr { $$ = $2; }
7949 | /*EMPTY*/ { $$ = NULL; }
7953 for_locking_items { $$ = $1; }
7954 | FOR READ ONLY { $$ = NIL; }
7957 opt_for_locking_clause:
7958 for_locking_clause { $$ = $1; }
7959 | /* EMPTY */ { $$ = NIL; }
7963 for_locking_item { $$ = list_make1($1); }
7964 | for_locking_items for_locking_item { $$ = lappend($1, $2); }
7968 FOR UPDATE locked_rels_list opt_nowait
7970 LockingClause *n = makeNode(LockingClause);
7972 n->forUpdate = TRUE;
7976 | FOR SHARE locked_rels_list opt_nowait
7978 LockingClause *n = makeNode(LockingClause);
7980 n->forUpdate = FALSE;
7987 OF qualified_name_list { $$ = $2; }
7988 | /* EMPTY */ { $$ = NIL; }
7995 SelectStmt *n = makeNode(SelectStmt);
7996 n->valuesLists = list_make1($2);
7999 | values_clause ',' ctext_row
8001 SelectStmt *n = (SelectStmt *) $1;
8002 n->valuesLists = lappend(n->valuesLists, $3);
8008 /*****************************************************************************
8010 * clauses common to all Optimizable Stmts:
8011 * from_clause - allow list of both JOIN expressions and table names
8012 * where_clause - qualifications for joins or restrictions
8014 *****************************************************************************/
8017 FROM from_list { $$ = $2; }
8018 | /*EMPTY*/ { $$ = NIL; }
8022 table_ref { $$ = list_make1($1); }
8023 | from_list ',' table_ref { $$ = lappend($1, $3); }
8027 * table_ref is where an alias clause can be attached. Note we cannot make
8028 * alias_clause have an empty production because that causes parse conflicts
8029 * between table_ref := '(' joined_table ')' alias_clause
8030 * and joined_table := '(' joined_table ')'. So, we must have the
8031 * redundant-looking productions here instead.
8033 table_ref: relation_expr
8037 | relation_expr alias_clause
8044 RangeFunction *n = makeNode(RangeFunction);
8045 n->funccallnode = $1;
8046 n->coldeflist = NIL;
8049 | func_table alias_clause
8051 RangeFunction *n = makeNode(RangeFunction);
8052 n->funccallnode = $1;
8054 n->coldeflist = NIL;
8057 | func_table AS '(' TableFuncElementList ')'
8059 RangeFunction *n = makeNode(RangeFunction);
8060 n->funccallnode = $1;
8064 | func_table AS ColId '(' TableFuncElementList ')'
8066 RangeFunction *n = makeNode(RangeFunction);
8067 Alias *a = makeNode(Alias);
8068 n->funccallnode = $1;
8074 | func_table ColId '(' TableFuncElementList ')'
8076 RangeFunction *n = makeNode(RangeFunction);
8077 Alias *a = makeNode(Alias);
8078 n->funccallnode = $1;
8084 | select_with_parens
8087 * The SQL spec does not permit a subselect
8088 * (<derived_table>) without an alias clause,
8089 * so we don't either. This avoids the problem
8090 * of needing to invent a unique refname for it.
8091 * That could be surmounted if there's sufficient
8092 * popular demand, but for now let's just implement
8093 * the spec and see if anyone complains.
8094 * However, it does seem like a good idea to emit
8095 * an error message that's better than "syntax error".
8097 if (IsA($1, SelectStmt) &&
8098 ((SelectStmt *) $1)->valuesLists)
8100 (errcode(ERRCODE_SYNTAX_ERROR),
8101 errmsg("VALUES in FROM must have an alias"),
8102 errhint("For example, FROM (VALUES ...) [AS] foo."),
8103 parser_errposition(@1)));
8106 (errcode(ERRCODE_SYNTAX_ERROR),
8107 errmsg("subquery in FROM must have an alias"),
8108 errhint("For example, FROM (SELECT ...) [AS] foo."),
8109 parser_errposition(@1)));
8112 | select_with_parens alias_clause
8114 RangeSubselect *n = makeNode(RangeSubselect);
8123 | '(' joined_table ')' alias_clause
8132 * It may seem silly to separate joined_table from table_ref, but there is
8133 * method in SQL92's madness: if you don't do it this way you get reduce-
8134 * reduce conflicts, because it's not clear to the parser generator whether
8135 * to expect alias_clause after ')' or not. For the same reason we must
8136 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
8137 * join_type to expand to empty; if we try it, the parser generator can't
8138 * figure out when to reduce an empty join_type right after table_ref.
8140 * Note that a CROSS JOIN is the same as an unqualified
8141 * INNER JOIN, and an INNER JOIN/ON has the same shape
8142 * but a qualification expression to limit membership.
8143 * A NATURAL JOIN implicitly matches column names between
8144 * tables and the shape is determined by which columns are
8145 * in common. We'll collect columns during the later transformations.
8149 '(' joined_table ')'
8153 | table_ref CROSS JOIN table_ref
8155 /* CROSS JOIN is same as unqualified inner join */
8156 JoinExpr *n = makeNode(JoinExpr);
8157 n->jointype = JOIN_INNER;
8158 n->isNatural = FALSE;
8161 n->usingClause = NIL;
8165 | table_ref join_type JOIN table_ref join_qual
8167 JoinExpr *n = makeNode(JoinExpr);
8169 n->isNatural = FALSE;
8172 if ($5 != NULL && IsA($5, List))
8173 n->usingClause = (List *) $5; /* USING clause */
8175 n->quals = $5; /* ON clause */
8178 | table_ref JOIN table_ref join_qual
8180 /* letting join_type reduce to empty doesn't work */
8181 JoinExpr *n = makeNode(JoinExpr);
8182 n->jointype = JOIN_INNER;
8183 n->isNatural = FALSE;
8186 if ($4 != NULL && IsA($4, List))
8187 n->usingClause = (List *) $4; /* USING clause */
8189 n->quals = $4; /* ON clause */
8192 | table_ref NATURAL join_type JOIN table_ref
8194 JoinExpr *n = makeNode(JoinExpr);
8196 n->isNatural = TRUE;
8199 n->usingClause = NIL; /* figure out which columns later... */
8200 n->quals = NULL; /* fill later */
8203 | table_ref NATURAL JOIN table_ref
8205 /* letting join_type reduce to empty doesn't work */
8206 JoinExpr *n = makeNode(JoinExpr);
8207 n->jointype = JOIN_INNER;
8208 n->isNatural = TRUE;
8211 n->usingClause = NIL; /* figure out which columns later... */
8212 n->quals = NULL; /* fill later */
8218 AS ColId '(' name_list ')'
8220 $$ = makeNode(Alias);
8226 $$ = makeNode(Alias);
8229 | ColId '(' name_list ')'
8231 $$ = makeNode(Alias);
8237 $$ = makeNode(Alias);
8242 join_type: FULL join_outer { $$ = JOIN_FULL; }
8243 | LEFT join_outer { $$ = JOIN_LEFT; }
8244 | RIGHT join_outer { $$ = JOIN_RIGHT; }
8245 | INNER_P { $$ = JOIN_INNER; }
8248 /* OUTER is just noise... */
8249 join_outer: OUTER_P { $$ = NULL; }
8250 | /*EMPTY*/ { $$ = NULL; }
8253 /* JOIN qualification clauses
8254 * Possibilities are:
8255 * USING ( column list ) allows only unqualified column names,
8256 * which must match between tables.
8257 * ON expr allows more general qualifications.
8259 * We return USING as a List node, while an ON-expr will not be a List.
8262 join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
8263 | ON a_expr { $$ = $2; }
8270 /* default inheritance */
8272 $$->inhOpt = INH_DEFAULT;
8275 | qualified_name '*'
8277 /* inheritance query */
8279 $$->inhOpt = INH_YES;
8282 | ONLY qualified_name
8284 /* no inheritance */
8286 $$->inhOpt = INH_NO;
8289 | ONLY '(' qualified_name ')'
8291 /* no inheritance, SQL99-style syntax */
8293 $$->inhOpt = INH_NO;
8300 relation_expr { $$ = list_make1($1); }
8301 | relation_expr_list ',' relation_expr { $$ = lappend($1, $3); }
8306 * Given "UPDATE foo set set ...", we have to decide without looking any
8307 * further ahead whether the first "set" is an alias or the UPDATE's SET
8308 * keyword. Since "set" is allowed as a column name both interpretations
8309 * are feasible. We resolve the shift/reduce conflict by giving the first
8310 * relation_expr_opt_alias production a higher precedence than the SET token
8311 * has, causing the parser to prefer to reduce, in effect assuming that the
8312 * SET is not an alias.
8314 relation_expr_opt_alias: relation_expr %prec UMINUS
8318 | relation_expr ColId
8320 Alias *alias = makeNode(Alias);
8321 alias->aliasname = $2;
8325 | relation_expr AS ColId
8327 Alias *alias = makeNode(Alias);
8328 alias->aliasname = $3;
8335 func_table: func_expr { $$ = $1; }
8340 WHERE a_expr { $$ = $2; }
8341 | /*EMPTY*/ { $$ = NULL; }
8344 /* variant for UPDATE and DELETE */
8345 where_or_current_clause:
8346 WHERE a_expr { $$ = $2; }
8347 | WHERE CURRENT_P OF name
8349 CurrentOfExpr *n = makeNode(CurrentOfExpr);
8350 /* cvarno is filled in by parse analysis */
8351 n->cursor_name = $4;
8352 n->cursor_param = 0;
8355 | /*EMPTY*/ { $$ = NULL; }
8359 OptTableFuncElementList:
8360 TableFuncElementList { $$ = $1; }
8361 | /*EMPTY*/ { $$ = NIL; }
8364 TableFuncElementList:
8367 $$ = list_make1($1);
8369 | TableFuncElementList ',' TableFuncElement
8371 $$ = lappend($1, $3);
8375 TableFuncElement: ColId Typename
8377 ColumnDef *n = makeNode(ColumnDef);
8380 n->constraints = NIL;
8386 /*****************************************************************************
8389 * SQL92 introduces a large amount of type-specific syntax.
8390 * Define individual clauses to handle these cases, and use
8391 * the generic case to handle regular type-extensible Postgres syntax.
8392 * - thomas 1997-10-10
8394 *****************************************************************************/
8396 Typename: SimpleTypename opt_array_bounds
8399 $$->arrayBounds = $2;
8401 | SETOF SimpleTypename opt_array_bounds
8404 $$->arrayBounds = $3;
8407 /* SQL standard syntax, currently only one-dimensional */
8408 | SimpleTypename ARRAY '[' Iconst ']'
8411 $$->arrayBounds = list_make1(makeInteger($4));
8413 | SETOF SimpleTypename ARRAY '[' Iconst ']'
8416 $$->arrayBounds = list_make1(makeInteger($5));
8419 | SimpleTypename ARRAY
8422 $$->arrayBounds = list_make1(makeInteger(-1));
8424 | SETOF SimpleTypename ARRAY
8427 $$->arrayBounds = list_make1(makeInteger(-1));
8433 opt_array_bounds '[' ']'
8434 { $$ = lappend($1, makeInteger(-1)); }
8435 | opt_array_bounds '[' Iconst ']'
8436 { $$ = lappend($1, makeInteger($3)); }
8442 GenericType { $$ = $1; }
8443 | Numeric { $$ = $1; }
8445 | Character { $$ = $1; }
8446 | ConstDatetime { $$ = $1; }
8447 | ConstInterval opt_interval
8452 | ConstInterval '(' Iconst ')' opt_interval
8457 if (list_length($5) != 1)
8459 (errcode(ERRCODE_SYNTAX_ERROR),
8460 errmsg("interval precision specified twice"),
8461 parser_errposition(@1)));
8462 $$->typmods = lappend($5, makeIntConst($3, @3));
8465 $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
8466 makeIntConst($3, @3));
8470 /* We have a separate ConstTypename to allow defaulting fixed-length
8471 * types such as CHAR() and BIT() to an unspecified length.
8472 * SQL9x requires that these default to a length of one, but this
8473 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
8474 * where there is an obvious better choice to make.
8475 * Note that ConstInterval is not included here since it must
8476 * be pushed up higher in the rules to accomodate the postfix
8477 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
8478 * the generic-type-name case in AExprConst to avoid premature
8479 * reduce/reduce conflicts against function names.
8482 Numeric { $$ = $1; }
8483 | ConstBit { $$ = $1; }
8484 | ConstCharacter { $$ = $1; }
8485 | ConstDatetime { $$ = $1; }
8489 * GenericType covers all type names that don't have special syntax mandated
8490 * by the standard, including qualified names. We also allow type modifiers.
8491 * To avoid parsing conflicts against function invocations, the modifiers
8492 * have to be shown as expr_list here, but parse analysis will only accept
8493 * constants for them.
8496 type_function_name opt_type_modifiers
8498 $$ = makeTypeName($1);
8502 | type_function_name attrs opt_type_modifiers
8504 $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
8510 opt_type_modifiers: '(' expr_list ')' { $$ = $2; }
8511 | /* EMPTY */ { $$ = NIL; }
8515 * SQL92 numeric data types
8519 $$ = SystemTypeName("int4");
8524 $$ = SystemTypeName("int4");
8529 $$ = SystemTypeName("int2");
8534 $$ = SystemTypeName("int8");
8539 $$ = SystemTypeName("float4");
8547 | DOUBLE_P PRECISION
8549 $$ = SystemTypeName("float8");
8552 | DECIMAL_P opt_type_modifiers
8554 $$ = SystemTypeName("numeric");
8558 | DEC opt_type_modifiers
8560 $$ = SystemTypeName("numeric");
8564 | NUMERIC opt_type_modifiers
8566 $$ = SystemTypeName("numeric");
8572 $$ = SystemTypeName("bool");
8577 opt_float: '(' Iconst ')'
8580 * Check FLOAT() precision limits assuming IEEE floating
8581 * types - thomas 1997-09-18
8585 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8586 errmsg("precision for type float must be at least 1 bit"),
8587 parser_errposition(@2)));
8589 $$ = SystemTypeName("float4");
8591 $$ = SystemTypeName("float8");
8594 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8595 errmsg("precision for type float must be less than 54 bits"),
8596 parser_errposition(@2)));
8600 $$ = SystemTypeName("float8");
8605 * SQL92 bit-field data types
8606 * The following implements BIT() and BIT VARYING().
8618 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
8619 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
8620 ConstBit: BitWithLength
8632 BIT opt_varying '(' expr_list ')'
8636 typname = $2 ? "varbit" : "bit";
8637 $$ = SystemTypeName(typname);
8646 /* bit defaults to bit(1), varbit to no limit */
8649 $$ = SystemTypeName("varbit");
8653 $$ = SystemTypeName("bit");
8654 $$->typmods = list_make1(makeIntConst(1, -1));
8662 * SQL92 character data types
8663 * The following implements CHAR() and VARCHAR().
8665 Character: CharacterWithLength
8669 | CharacterWithoutLength
8675 ConstCharacter: CharacterWithLength
8679 | CharacterWithoutLength
8681 /* Length was not specified so allow to be unrestricted.
8682 * This handles problems with fixed-length (bpchar) strings
8683 * which in column definitions must default to a length
8684 * of one, but should not be constrained if the length
8685 * was not specified.
8692 CharacterWithLength: character '(' Iconst ')' opt_charset
8694 if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
8698 type = palloc(strlen($1) + 1 + strlen($5) + 1);
8705 $$ = SystemTypeName($1);
8706 $$->typmods = list_make1(makeIntConst($3, @3));
8711 CharacterWithoutLength: character opt_charset
8713 if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
8717 type = palloc(strlen($1) + 1 + strlen($2) + 1);
8724 $$ = SystemTypeName($1);
8726 /* char defaults to char(1), varchar to no limit */
8727 if (strcmp($1, "bpchar") == 0)
8728 $$->typmods = list_make1(makeIntConst(1, -1));
8734 character: CHARACTER opt_varying
8735 { $$ = $2 ? "varchar": "bpchar"; }
8736 | CHAR_P opt_varying
8737 { $$ = $2 ? "varchar": "bpchar"; }
8740 | NATIONAL CHARACTER opt_varying
8741 { $$ = $3 ? "varchar": "bpchar"; }
8742 | NATIONAL CHAR_P opt_varying
8743 { $$ = $3 ? "varchar": "bpchar"; }
8745 { $$ = $2 ? "varchar": "bpchar"; }
8749 VARYING { $$ = TRUE; }
8750 | /*EMPTY*/ { $$ = FALSE; }
8754 CHARACTER SET ColId { $$ = $3; }
8755 | /*EMPTY*/ { $$ = NULL; }
8759 * SQL92 date/time types
8762 TIMESTAMP '(' Iconst ')' opt_timezone
8765 $$ = SystemTypeName("timestamptz");
8767 $$ = SystemTypeName("timestamp");
8768 $$->typmods = list_make1(makeIntConst($3, @3));
8771 | TIMESTAMP opt_timezone
8774 $$ = SystemTypeName("timestamptz");
8776 $$ = SystemTypeName("timestamp");
8779 | TIME '(' Iconst ')' opt_timezone
8782 $$ = SystemTypeName("timetz");
8784 $$ = SystemTypeName("time");
8785 $$->typmods = list_make1(makeIntConst($3, @3));
8791 $$ = SystemTypeName("timetz");
8793 $$ = SystemTypeName("time");
8801 $$ = SystemTypeName("interval");
8807 WITH_TIME ZONE { $$ = TRUE; }
8808 | WITHOUT TIME ZONE { $$ = FALSE; }
8809 | /*EMPTY*/ { $$ = FALSE; }
8814 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
8816 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
8818 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
8820 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
8822 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
8827 $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
8828 INTERVAL_MASK(MONTH), @1));
8832 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8833 INTERVAL_MASK(HOUR), @1));
8837 $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
8838 INTERVAL_MASK(HOUR) |
8839 INTERVAL_MASK(MINUTE), @1));
8841 | DAY_P TO interval_second
8844 linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
8845 INTERVAL_MASK(HOUR) |
8846 INTERVAL_MASK(MINUTE) |
8847 INTERVAL_MASK(SECOND), @1);
8849 | HOUR_P TO MINUTE_P
8851 $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
8852 INTERVAL_MASK(MINUTE), @1));
8854 | HOUR_P TO interval_second
8857 linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
8858 INTERVAL_MASK(MINUTE) |
8859 INTERVAL_MASK(SECOND), @1);
8861 | MINUTE_P TO interval_second
8864 linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
8865 INTERVAL_MASK(SECOND), @1);
8874 $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
8876 | SECOND_P '(' Iconst ')'
8878 $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
8879 makeIntConst($3, @3));
8884 /*****************************************************************************
8886 * expression grammar
8888 *****************************************************************************/
8891 * General expressions
8892 * This is the heart of the expression syntax.
8894 * We have two expression types: a_expr is the unrestricted kind, and
8895 * b_expr is a subset that must be used in some places to avoid shift/reduce
8896 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
8897 * because that use of AND conflicts with AND as a boolean operator. So,
8898 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
8900 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
8901 * always be used by surrounding it with parens.
8903 * c_expr is all the productions that are common to a_expr and b_expr;
8904 * it's factored out just to eliminate redundant coding.
8906 a_expr: c_expr { $$ = $1; }
8907 | a_expr TYPECAST Typename
8908 { $$ = makeTypeCast($1, $3, @2); }
8909 | a_expr AT TIME ZONE a_expr
8911 FuncCall *n = makeNode(FuncCall);
8912 n->funcname = SystemFuncName("timezone");
8913 n->args = list_make2($5, $1);
8915 n->agg_star = FALSE;
8916 n->agg_distinct = FALSE;
8917 n->func_variadic = FALSE;
8923 * These operators must be called out explicitly in order to make use
8924 * of bison's automatic operator-precedence handling. All other
8925 * operator names are handled by the generic productions using "Op",
8926 * below; and all those operators will have the same precedence.
8928 * If you add more explicitly-known operators, be sure to add them
8929 * also to b_expr and to the MathOp list above.
8931 | '+' a_expr %prec UMINUS
8932 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
8933 | '-' a_expr %prec UMINUS
8934 { $$ = doNegate($2, @1); }
8936 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
8938 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
8940 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
8942 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
8944 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
8946 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
8948 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
8950 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
8952 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
8954 | a_expr qual_Op a_expr %prec Op
8955 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
8956 | qual_Op a_expr %prec Op
8957 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
8958 | a_expr qual_Op %prec POSTFIXOP
8959 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
8962 { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
8964 { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
8966 { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
8968 | a_expr LIKE a_expr
8969 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
8970 | a_expr LIKE a_expr ESCAPE a_expr
8972 FuncCall *n = makeNode(FuncCall);
8973 n->funcname = SystemFuncName("like_escape");
8974 n->args = list_make2($3, $5);
8976 n->agg_star = FALSE;
8977 n->agg_distinct = FALSE;
8978 n->func_variadic = FALSE;
8981 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
8983 | a_expr NOT LIKE a_expr
8984 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
8985 | a_expr NOT LIKE a_expr ESCAPE a_expr
8987 FuncCall *n = makeNode(FuncCall);
8988 n->funcname = SystemFuncName("like_escape");
8989 n->args = list_make2($4, $6);
8991 n->agg_star = FALSE;
8992 n->agg_distinct = FALSE;
8993 n->func_variadic = FALSE;
8996 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
8998 | a_expr ILIKE a_expr
8999 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
9000 | a_expr ILIKE a_expr ESCAPE a_expr
9002 FuncCall *n = makeNode(FuncCall);
9003 n->funcname = SystemFuncName("like_escape");
9004 n->args = list_make2($3, $5);
9006 n->agg_star = FALSE;
9007 n->agg_distinct = FALSE;
9008 n->func_variadic = FALSE;
9011 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n, @2);
9013 | a_expr NOT ILIKE a_expr
9014 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
9015 | a_expr NOT ILIKE a_expr ESCAPE a_expr
9017 FuncCall *n = makeNode(FuncCall);
9018 n->funcname = SystemFuncName("like_escape");
9019 n->args = list_make2($4, $6);
9021 n->agg_star = FALSE;
9022 n->agg_distinct = FALSE;
9023 n->func_variadic = FALSE;
9026 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n, @2);
9029 | a_expr SIMILAR TO a_expr %prec SIMILAR
9031 FuncCall *n = makeNode(FuncCall);
9032 n->funcname = SystemFuncName("similar_escape");
9033 n->args = list_make2($4, makeNullAConst(-1));
9035 n->agg_star = FALSE;
9036 n->agg_distinct = FALSE;
9037 n->func_variadic = FALSE;
9040 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
9042 | a_expr SIMILAR TO a_expr ESCAPE a_expr
9044 FuncCall *n = makeNode(FuncCall);
9045 n->funcname = SystemFuncName("similar_escape");
9046 n->args = list_make2($4, $6);
9048 n->agg_star = FALSE;
9049 n->agg_distinct = FALSE;
9050 n->func_variadic = FALSE;
9053 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
9055 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
9057 FuncCall *n = makeNode(FuncCall);
9058 n->funcname = SystemFuncName("similar_escape");
9059 n->args = list_make2($5, makeNullAConst(-1));
9061 n->agg_star = FALSE;
9062 n->agg_distinct = FALSE;
9063 n->func_variadic = FALSE;
9066 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
9068 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
9070 FuncCall *n = makeNode(FuncCall);
9071 n->funcname = SystemFuncName("similar_escape");
9072 n->args = list_make2($5, $7);
9074 n->agg_star = FALSE;
9075 n->agg_distinct = FALSE;
9076 n->func_variadic = FALSE;
9079 $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
9083 * Define SQL92-style Null test clause.
9084 * Allow two forms described in the standard:
9087 * Allow two SQL extensions
9093 NullTest *n = makeNode(NullTest);
9094 n->arg = (Expr *) $1;
9095 n->nulltesttype = IS_NULL;
9100 NullTest *n = makeNode(NullTest);
9101 n->arg = (Expr *) $1;
9102 n->nulltesttype = IS_NULL;
9105 | a_expr IS NOT NULL_P
9107 NullTest *n = makeNode(NullTest);
9108 n->arg = (Expr *) $1;
9109 n->nulltesttype = IS_NOT_NULL;
9114 NullTest *n = makeNode(NullTest);
9115 n->arg = (Expr *) $1;
9116 n->nulltesttype = IS_NOT_NULL;
9121 $$ = (Node *)makeOverlaps($1, $3, @2, yyscanner);
9125 BooleanTest *b = makeNode(BooleanTest);
9126 b->arg = (Expr *) $1;
9127 b->booltesttype = IS_TRUE;
9130 | a_expr IS NOT TRUE_P
9132 BooleanTest *b = makeNode(BooleanTest);
9133 b->arg = (Expr *) $1;
9134 b->booltesttype = IS_NOT_TRUE;
9139 BooleanTest *b = makeNode(BooleanTest);
9140 b->arg = (Expr *) $1;
9141 b->booltesttype = IS_FALSE;
9144 | a_expr IS NOT FALSE_P
9146 BooleanTest *b = makeNode(BooleanTest);
9147 b->arg = (Expr *) $1;
9148 b->booltesttype = IS_NOT_FALSE;
9153 BooleanTest *b = makeNode(BooleanTest);
9154 b->arg = (Expr *) $1;
9155 b->booltesttype = IS_UNKNOWN;
9158 | a_expr IS NOT UNKNOWN
9160 BooleanTest *b = makeNode(BooleanTest);
9161 b->arg = (Expr *) $1;
9162 b->booltesttype = IS_NOT_UNKNOWN;
9165 | a_expr IS DISTINCT FROM a_expr %prec IS
9167 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
9169 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
9171 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9172 (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
9177 | a_expr IS OF '(' type_list ')' %prec IS
9179 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
9181 | a_expr IS NOT OF '(' type_list ')' %prec IS
9183 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
9186 * Ideally we would not use hard-wired operators below but
9187 * instead use opclasses. However, mixed data types and other
9188 * issues make this difficult:
9189 * http://archives.postgresql.org/pgsql-hackers/2008-08/msg01142.php
9191 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
9193 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
9194 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
9195 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
9198 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
9200 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
9201 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
9202 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
9205 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
9207 $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
9208 (Node *) makeA_Expr(AEXPR_AND, NIL,
9209 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
9210 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
9212 (Node *) makeA_Expr(AEXPR_AND, NIL,
9213 (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
9214 (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
9218 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
9220 $$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
9221 (Node *) makeA_Expr(AEXPR_OR, NIL,
9222 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
9223 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
9225 (Node *) makeA_Expr(AEXPR_OR, NIL,
9226 (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
9227 (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
9231 | a_expr IN_P in_expr
9233 /* in_expr returns a SubLink or a list of a_exprs */
9234 if (IsA($3, SubLink))
9236 /* generate foo = ANY (subquery) */
9237 SubLink *n = (SubLink *) $3;
9238 n->subLinkType = ANY_SUBLINK;
9240 n->operName = list_make1(makeString("="));
9246 /* generate scalar IN expression */
9247 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
9250 | a_expr NOT IN_P in_expr
9252 /* in_expr returns a SubLink or a list of a_exprs */
9253 if (IsA($4, SubLink))
9255 /* generate NOT (foo = ANY (subquery)) */
9256 /* Make an = ANY node */
9257 SubLink *n = (SubLink *) $4;
9258 n->subLinkType = ANY_SUBLINK;
9260 n->operName = list_make1(makeString("="));
9262 /* Stick a NOT on top */
9263 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
9267 /* generate scalar NOT IN expression */
9268 $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
9271 | a_expr subquery_Op sub_type select_with_parens %prec Op
9273 SubLink *n = makeNode(SubLink);
9274 n->subLinkType = $3;
9281 | a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
9283 if ($3 == ANY_SUBLINK)
9284 $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
9286 $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
9288 | UNIQUE select_with_parens
9290 /* Not sure how to get rid of the parentheses
9291 * but there are lots of shift/reduce errors without them.
9293 * Should be able to implement this by plopping the entire
9294 * select into a node, then transforming the target expressions
9295 * from whatever they are into count(*), and testing the
9296 * entire result equal to one.
9297 * But, will probably implement a separate node in the executor.
9300 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9301 errmsg("UNIQUE predicate is not yet implemented"),
9302 parser_errposition(@1)));
9304 | a_expr IS DOCUMENT_P %prec IS
9306 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9307 list_make1($1), @2);
9309 | a_expr IS NOT DOCUMENT_P %prec IS
9311 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9312 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9313 list_make1($1), @2),
9319 * Restricted expressions
9321 * b_expr is a subset of the complete expression syntax defined by a_expr.
9323 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
9324 * cause trouble in the places where b_expr is used. For simplicity, we
9325 * just eliminate all the boolean-keyword-operator productions from b_expr.
9329 | b_expr TYPECAST Typename
9330 { $$ = makeTypeCast($1, $3, @2); }
9331 | '+' b_expr %prec UMINUS
9332 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
9333 | '-' b_expr %prec UMINUS
9334 { $$ = doNegate($2, @1); }
9336 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
9338 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
9340 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
9342 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
9344 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
9346 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
9348 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
9350 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
9352 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
9353 | b_expr qual_Op b_expr %prec Op
9354 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
9355 | qual_Op b_expr %prec Op
9356 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
9357 | b_expr qual_Op %prec POSTFIXOP
9358 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
9359 | b_expr IS DISTINCT FROM b_expr %prec IS
9361 $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
9363 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
9365 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
9366 NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
9368 | b_expr IS OF '(' type_list ')' %prec IS
9370 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
9372 | b_expr IS NOT OF '(' type_list ')' %prec IS
9374 $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
9376 | b_expr IS DOCUMENT_P %prec IS
9378 $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9379 list_make1($1), @2);
9381 | b_expr IS NOT DOCUMENT_P %prec IS
9383 $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
9384 makeXmlExpr(IS_DOCUMENT, NULL, NIL,
9385 list_make1($1), @2),
9391 * Productions that can be used in both a_expr and b_expr.
9393 * Note: productions that refer recursively to a_expr or b_expr mostly
9394 * cannot appear here. However, it's OK to refer to a_exprs that occur
9395 * inside parentheses, such as function arguments; that cannot introduce
9396 * ambiguity to the b_expr syntax.
9398 c_expr: columnref { $$ = $1; }
9399 | AexprConst { $$ = $1; }
9400 | PARAM opt_indirection
9402 ParamRef *p = makeNode(ParamRef);
9407 A_Indirection *n = makeNode(A_Indirection);
9408 n->arg = (Node *) p;
9409 n->indirection = check_indirection($2, yyscanner);
9415 | '(' a_expr ')' opt_indirection
9419 A_Indirection *n = makeNode(A_Indirection);
9421 n->indirection = check_indirection($4, yyscanner);
9431 | select_with_parens %prec UMINUS
9433 SubLink *n = makeNode(SubLink);
9434 n->subLinkType = EXPR_SUBLINK;
9441 | EXISTS select_with_parens
9443 SubLink *n = makeNode(SubLink);
9444 n->subLinkType = EXISTS_SUBLINK;
9451 | ARRAY select_with_parens
9453 SubLink *n = makeNode(SubLink);
9454 n->subLinkType = ARRAY_SUBLINK;
9463 A_ArrayExpr *n = (A_ArrayExpr *) $2;
9464 Assert(IsA(n, A_ArrayExpr));
9465 /* point outermost A_ArrayExpr to the ARRAY keyword */
9471 RowExpr *r = makeNode(RowExpr);
9473 r->row_typeid = InvalidOid; /* not analyzed yet */
9480 * func_expr is split out from c_expr just so that we have a classification
9481 * for "everything that is a function call or looks like one". This isn't
9482 * very important, but it saves us having to document which variants are
9483 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
9484 * (Note that many of the special SQL functions wouldn't actually make any
9485 * sense as functional index entries, but we ignore that consideration here.)
9487 func_expr: func_name '(' ')' over_clause
9489 FuncCall *n = makeNode(FuncCall);
9493 n->agg_star = FALSE;
9494 n->agg_distinct = FALSE;
9495 n->func_variadic = FALSE;
9500 | func_name '(' func_arg_list ')' over_clause
9502 FuncCall *n = makeNode(FuncCall);
9506 n->agg_star = FALSE;
9507 n->agg_distinct = FALSE;
9508 n->func_variadic = FALSE;
9513 | func_name '(' VARIADIC func_arg_expr ')' over_clause
9515 FuncCall *n = makeNode(FuncCall);
9517 n->args = list_make1($4);
9519 n->agg_star = FALSE;
9520 n->agg_distinct = FALSE;
9521 n->func_variadic = TRUE;
9526 | func_name '(' func_arg_list ',' VARIADIC func_arg_expr ')' over_clause
9528 FuncCall *n = makeNode(FuncCall);
9530 n->args = lappend($3, $6);
9532 n->agg_star = FALSE;
9533 n->agg_distinct = FALSE;
9534 n->func_variadic = TRUE;
9539 | func_name '(' func_arg_list sort_clause ')' over_clause
9541 FuncCall *n = makeNode(FuncCall);
9545 n->agg_star = FALSE;
9546 n->agg_distinct = FALSE;
9547 n->func_variadic = FALSE;
9552 | func_name '(' ALL func_arg_list opt_sort_clause ')' over_clause
9554 FuncCall *n = makeNode(FuncCall);
9558 n->agg_star = FALSE;
9559 n->agg_distinct = FALSE;
9560 /* Ideally we'd mark the FuncCall node to indicate
9561 * "must be an aggregate", but there's no provision
9562 * for that in FuncCall at the moment.
9564 n->func_variadic = FALSE;
9569 | func_name '(' DISTINCT func_arg_list opt_sort_clause ')' over_clause
9571 FuncCall *n = makeNode(FuncCall);
9575 n->agg_star = FALSE;
9576 n->agg_distinct = TRUE;
9577 n->func_variadic = FALSE;
9582 | func_name '(' '*' ')' over_clause
9585 * We consider AGGREGATE(*) to invoke a parameterless
9586 * aggregate. This does the right thing for COUNT(*),
9587 * and there are no other aggregates in SQL92 that accept
9590 * The FuncCall node is also marked agg_star = true,
9591 * so that later processing can detect what the argument
9594 FuncCall *n = makeNode(FuncCall);
9599 n->agg_distinct = FALSE;
9600 n->func_variadic = FALSE;
9608 * Translate as "'now'::text::date".
9610 * We cannot use "'now'::date" because coerce_type() will
9611 * immediately reduce that to a constant representing
9612 * today's date. We need to delay the conversion until
9613 * runtime, else the wrong things will happen when
9614 * CURRENT_DATE is used in a column default value or rule.
9616 * This could be simplified if we had a way to generate
9617 * an expression tree representing runtime application
9618 * of type-input conversion functions. (As of PG 7.3
9619 * that is actually possible, but not clear that we want
9623 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9624 $$ = makeTypeCast(n, SystemTypeName("date"), -1);
9629 * Translate as "'now'::text::timetz".
9630 * See comments for CURRENT_DATE.
9633 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9634 $$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
9636 | CURRENT_TIME '(' Iconst ')'
9639 * Translate as "'now'::text::timetz(n)".
9640 * See comments for CURRENT_DATE.
9644 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9645 d = SystemTypeName("timetz");
9646 d->typmods = list_make1(makeIntConst($3, @3));
9647 $$ = makeTypeCast(n, d, -1);
9652 * Translate as "now()", since we have a function that
9653 * does exactly what is needed.
9655 FuncCall *n = makeNode(FuncCall);
9656 n->funcname = SystemFuncName("now");
9659 n->agg_star = FALSE;
9660 n->agg_distinct = FALSE;
9661 n->func_variadic = FALSE;
9666 | CURRENT_TIMESTAMP '(' Iconst ')'
9669 * Translate as "'now'::text::timestamptz(n)".
9670 * See comments for CURRENT_DATE.
9674 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9675 d = SystemTypeName("timestamptz");
9676 d->typmods = list_make1(makeIntConst($3, @3));
9677 $$ = makeTypeCast(n, d, -1);
9682 * Translate as "'now'::text::time".
9683 * See comments for CURRENT_DATE.
9686 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9687 $$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
9689 | LOCALTIME '(' Iconst ')'
9692 * Translate as "'now'::text::time(n)".
9693 * See comments for CURRENT_DATE.
9697 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9698 d = SystemTypeName("time");
9699 d->typmods = list_make1(makeIntConst($3, @3));
9700 $$ = makeTypeCast((Node *)n, d, -1);
9705 * Translate as "'now'::text::timestamp".
9706 * See comments for CURRENT_DATE.
9709 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9710 $$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
9712 | LOCALTIMESTAMP '(' Iconst ')'
9715 * Translate as "'now'::text::timestamp(n)".
9716 * See comments for CURRENT_DATE.
9720 n = makeStringConstCast("now", @1, SystemTypeName("text"));
9721 d = SystemTypeName("timestamp");
9722 d->typmods = list_make1(makeIntConst($3, @3));
9723 $$ = makeTypeCast(n, d, -1);
9727 FuncCall *n = makeNode(FuncCall);
9728 n->funcname = SystemFuncName("current_user");
9731 n->agg_star = FALSE;
9732 n->agg_distinct = FALSE;
9733 n->func_variadic = FALSE;
9740 FuncCall *n = makeNode(FuncCall);
9741 n->funcname = SystemFuncName("current_user");
9744 n->agg_star = FALSE;
9745 n->agg_distinct = FALSE;
9746 n->func_variadic = FALSE;
9753 FuncCall *n = makeNode(FuncCall);
9754 n->funcname = SystemFuncName("session_user");
9757 n->agg_star = FALSE;
9758 n->agg_distinct = FALSE;
9759 n->func_variadic = FALSE;
9766 FuncCall *n = makeNode(FuncCall);
9767 n->funcname = SystemFuncName("current_user");
9770 n->agg_star = FALSE;
9771 n->agg_distinct = FALSE;
9772 n->func_variadic = FALSE;
9779 FuncCall *n = makeNode(FuncCall);
9780 n->funcname = SystemFuncName("current_database");
9783 n->agg_star = FALSE;
9784 n->agg_distinct = FALSE;
9785 n->func_variadic = FALSE;
9792 FuncCall *n = makeNode(FuncCall);
9793 n->funcname = SystemFuncName("current_schema");
9796 n->agg_star = FALSE;
9797 n->agg_distinct = FALSE;
9798 n->func_variadic = FALSE;
9803 | CAST '(' a_expr AS Typename ')'
9804 { $$ = makeTypeCast($3, $5, @1); }
9805 | EXTRACT '(' extract_list ')'
9807 FuncCall *n = makeNode(FuncCall);
9808 n->funcname = SystemFuncName("date_part");
9811 n->agg_star = FALSE;
9812 n->agg_distinct = FALSE;
9813 n->func_variadic = FALSE;
9818 | OVERLAY '(' overlay_list ')'
9820 /* overlay(A PLACING B FROM C FOR D) is converted to
9821 * overlay(A, B, C, D)
9822 * overlay(A PLACING B FROM C) is converted to
9825 FuncCall *n = makeNode(FuncCall);
9826 n->funcname = SystemFuncName("overlay");
9829 n->agg_star = FALSE;
9830 n->agg_distinct = FALSE;
9831 n->func_variadic = FALSE;
9836 | POSITION '(' position_list ')'
9838 /* position(A in B) is converted to position(B, A) */
9839 FuncCall *n = makeNode(FuncCall);
9840 n->funcname = SystemFuncName("position");
9843 n->agg_star = FALSE;
9844 n->agg_distinct = FALSE;
9845 n->func_variadic = FALSE;
9850 | SUBSTRING '(' substr_list ')'
9852 /* substring(A from B for C) is converted to
9853 * substring(A, B, C) - thomas 2000-11-28
9855 FuncCall *n = makeNode(FuncCall);
9856 n->funcname = SystemFuncName("substring");
9859 n->agg_star = FALSE;
9860 n->agg_distinct = FALSE;
9861 n->func_variadic = FALSE;
9866 | TREAT '(' a_expr AS Typename ')'
9868 /* TREAT(expr AS target) converts expr of a particular type to target,
9869 * which is defined to be a subtype of the original expression.
9870 * In SQL99, this is intended for use with structured UDTs,
9871 * but let's make this a generally useful form allowing stronger
9872 * coercions than are handled by implicit casting.
9874 FuncCall *n = makeNode(FuncCall);
9875 /* Convert SystemTypeName() to SystemFuncName() even though
9876 * at the moment they result in the same thing.
9878 n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
9879 n->args = list_make1($3);
9881 n->agg_star = FALSE;
9882 n->agg_distinct = FALSE;
9883 n->func_variadic = FALSE;
9888 | TRIM '(' BOTH trim_list ')'
9890 /* various trim expressions are defined in SQL92
9891 * - thomas 1997-07-19
9893 FuncCall *n = makeNode(FuncCall);
9894 n->funcname = SystemFuncName("btrim");
9897 n->agg_star = FALSE;
9898 n->agg_distinct = FALSE;
9899 n->func_variadic = FALSE;
9904 | TRIM '(' LEADING trim_list ')'
9906 FuncCall *n = makeNode(FuncCall);
9907 n->funcname = SystemFuncName("ltrim");
9910 n->agg_star = FALSE;
9911 n->agg_distinct = FALSE;
9912 n->func_variadic = FALSE;
9917 | TRIM '(' TRAILING trim_list ')'
9919 FuncCall *n = makeNode(FuncCall);
9920 n->funcname = SystemFuncName("rtrim");
9923 n->agg_star = FALSE;
9924 n->agg_distinct = FALSE;
9925 n->func_variadic = FALSE;
9930 | TRIM '(' trim_list ')'
9932 FuncCall *n = makeNode(FuncCall);
9933 n->funcname = SystemFuncName("btrim");
9936 n->agg_star = FALSE;
9937 n->agg_distinct = FALSE;
9938 n->func_variadic = FALSE;
9943 | NULLIF '(' a_expr ',' a_expr ')'
9945 $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
9947 | COALESCE '(' expr_list ')'
9949 CoalesceExpr *c = makeNode(CoalesceExpr);
9954 | GREATEST '(' expr_list ')'
9956 MinMaxExpr *v = makeNode(MinMaxExpr);
9958 v->op = IS_GREATEST;
9962 | LEAST '(' expr_list ')'
9964 MinMaxExpr *v = makeNode(MinMaxExpr);
9970 | XMLCONCAT '(' expr_list ')'
9972 $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
9974 | XMLELEMENT '(' NAME_P ColLabel ')'
9976 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
9978 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
9980 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
9982 | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
9984 $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
9986 | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
9988 $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
9990 | XMLEXISTS '(' c_expr xmlexists_argument ')'
9992 /* xmlexists(A PASSING [BY REF] B [BY REF]) is
9993 * converted to xmlexists(A, B)*/
9994 FuncCall *n = makeNode(FuncCall);
9995 n->funcname = SystemFuncName("xmlexists");
9996 n->args = list_make2($3, $4);
9998 n->agg_star = FALSE;
9999 n->agg_distinct = FALSE;
10000 n->func_variadic = FALSE;
10005 | XMLFOREST '(' xml_attribute_list ')'
10007 $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
10009 | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
10011 XmlExpr *x = (XmlExpr *)
10012 makeXmlExpr(IS_XMLPARSE, NULL, NIL,
10013 list_make2($4, makeBoolAConst($5, -1)),
10018 | XMLPI '(' NAME_P ColLabel ')'
10020 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
10022 | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
10024 $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
10026 | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
10028 $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
10029 list_make3($3, $5, $6), @1);
10031 | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename ')'
10033 XmlSerialize *n = makeNode(XmlSerialize);
10045 xml_root_version: VERSION_P a_expr
10047 | VERSION_P NO VALUE_P
10048 { $$ = makeNullAConst(-1); }
10051 opt_xml_root_standalone: ',' STANDALONE_P YES_P
10052 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
10053 | ',' STANDALONE_P NO
10054 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
10055 | ',' STANDALONE_P NO VALUE_P
10056 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
10058 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
10061 xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')' { $$ = $3; }
10064 xml_attribute_list: xml_attribute_el { $$ = list_make1($1); }
10065 | xml_attribute_list ',' xml_attribute_el { $$ = lappend($1, $3); }
10068 xml_attribute_el: a_expr AS ColLabel
10070 $$ = makeNode(ResTarget);
10072 $$->indirection = NIL;
10073 $$->val = (Node *) $1;
10078 $$ = makeNode(ResTarget);
10080 $$->indirection = NIL;
10081 $$->val = (Node *) $1;
10086 document_or_content: DOCUMENT_P { $$ = XMLOPTION_DOCUMENT; }
10087 | CONTENT_P { $$ = XMLOPTION_CONTENT; }
10090 xml_whitespace_option: PRESERVE WHITESPACE_P { $$ = TRUE; }
10091 | STRIP_P WHITESPACE_P { $$ = FALSE; }
10092 | /*EMPTY*/ { $$ = FALSE; }
10095 /* We allow several variants for SQL and other compatibility. */
10096 xmlexists_argument:
10101 | PASSING c_expr BY REF
10105 | PASSING BY REF c_expr
10109 | PASSING BY REF c_expr BY REF
10117 * Window Definitions
10120 WINDOW window_definition_list { $$ = $2; }
10121 | /*EMPTY*/ { $$ = NIL; }
10124 window_definition_list:
10125 window_definition { $$ = list_make1($1); }
10126 | window_definition_list ',' window_definition
10127 { $$ = lappend($1, $3); }
10131 ColId AS window_specification
10139 over_clause: OVER window_specification
10143 WindowDef *n = makeNode(WindowDef);
10146 n->partitionClause = NIL;
10147 n->orderClause = NIL;
10148 n->frameOptions = FRAMEOPTION_DEFAULTS;
10149 n->startOffset = NULL;
10150 n->endOffset = NULL;
10158 window_specification: '(' opt_existing_window_name opt_partition_clause
10159 opt_sort_clause opt_frame_clause ')'
10161 WindowDef *n = makeNode(WindowDef);
10164 n->partitionClause = $3;
10165 n->orderClause = $4;
10166 /* copy relevant fields of opt_frame_clause */
10167 n->frameOptions = $5->frameOptions;
10168 n->startOffset = $5->startOffset;
10169 n->endOffset = $5->endOffset;
10176 * If we see PARTITION, RANGE, or ROWS as the first token after the '('
10177 * of a window_specification, we want the assumption to be that there is
10178 * no existing_window_name; but those keywords are unreserved and so could
10179 * be ColIds. We fix this by making them have the same precedence as IDENT
10180 * and giving the empty production here a slightly higher precedence, so
10181 * that the shift/reduce conflict is resolved in favor of reducing the rule.
10182 * These keywords are thus precluded from being an existing_window_name but
10183 * are not reserved for any other purpose.
10185 opt_existing_window_name: ColId { $$ = $1; }
10186 | /*EMPTY*/ %prec Op { $$ = NULL; }
10189 opt_partition_clause: PARTITION BY expr_list { $$ = $3; }
10190 | /*EMPTY*/ { $$ = NIL; }
10194 * For frame clauses, we return a WindowDef, but only some fields are used:
10195 * frameOptions, startOffset, and endOffset.
10197 * This is only a subset of the full SQL:2008 frame_clause grammar.
10198 * We don't support <window frame exclusion> yet.
10204 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
10205 if (n->frameOptions & (FRAMEOPTION_START_VALUE_PRECEDING |
10206 FRAMEOPTION_END_VALUE_PRECEDING))
10208 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10209 errmsg("RANGE PRECEDING is only supported with UNBOUNDED"),
10210 parser_errposition(@1)));
10211 if (n->frameOptions & (FRAMEOPTION_START_VALUE_FOLLOWING |
10212 FRAMEOPTION_END_VALUE_FOLLOWING))
10214 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10215 errmsg("RANGE FOLLOWING is only supported with UNBOUNDED"),
10216 parser_errposition(@1)));
10219 | ROWS frame_extent
10222 n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
10227 WindowDef *n = makeNode(WindowDef);
10228 n->frameOptions = FRAMEOPTION_DEFAULTS;
10229 n->startOffset = NULL;
10230 n->endOffset = NULL;
10235 frame_extent: frame_bound
10238 /* reject invalid cases */
10239 if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
10241 (errcode(ERRCODE_WINDOWING_ERROR),
10242 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
10243 parser_errposition(@1)));
10244 if (n->frameOptions & FRAMEOPTION_START_VALUE_FOLLOWING)
10246 (errcode(ERRCODE_WINDOWING_ERROR),
10247 errmsg("frame starting from following row cannot end with current row"),
10248 parser_errposition(@1)));
10249 n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
10252 | BETWEEN frame_bound AND frame_bound
10254 WindowDef *n1 = $2;
10255 WindowDef *n2 = $4;
10256 /* form merged options */
10257 int frameOptions = n1->frameOptions;
10258 /* shift converts START_ options to END_ options */
10259 frameOptions |= n2->frameOptions << 1;
10260 frameOptions |= FRAMEOPTION_BETWEEN;
10261 /* reject invalid cases */
10262 if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
10264 (errcode(ERRCODE_WINDOWING_ERROR),
10265 errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
10266 parser_errposition(@2)));
10267 if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
10269 (errcode(ERRCODE_WINDOWING_ERROR),
10270 errmsg("frame end cannot be UNBOUNDED PRECEDING"),
10271 parser_errposition(@4)));
10272 if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
10273 (frameOptions & FRAMEOPTION_END_VALUE_PRECEDING))
10275 (errcode(ERRCODE_WINDOWING_ERROR),
10276 errmsg("frame starting from current row cannot have preceding rows"),
10277 parser_errposition(@4)));
10278 if ((frameOptions & FRAMEOPTION_START_VALUE_FOLLOWING) &&
10279 (frameOptions & (FRAMEOPTION_END_VALUE_PRECEDING |
10280 FRAMEOPTION_END_CURRENT_ROW)))
10282 (errcode(ERRCODE_WINDOWING_ERROR),
10283 errmsg("frame starting from following row cannot have preceding rows"),
10284 parser_errposition(@4)));
10285 n1->frameOptions = frameOptions;
10286 n1->endOffset = n2->startOffset;
10292 * This is used for both frame start and frame end, with output set up on
10293 * the assumption it's frame start; the frame_extent productions must reject
10297 UNBOUNDED PRECEDING
10299 WindowDef *n = makeNode(WindowDef);
10300 n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
10301 n->startOffset = NULL;
10302 n->endOffset = NULL;
10305 | UNBOUNDED FOLLOWING
10307 WindowDef *n = makeNode(WindowDef);
10308 n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
10309 n->startOffset = NULL;
10310 n->endOffset = NULL;
10315 WindowDef *n = makeNode(WindowDef);
10316 n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
10317 n->startOffset = NULL;
10318 n->endOffset = NULL;
10323 WindowDef *n = makeNode(WindowDef);
10324 n->frameOptions = FRAMEOPTION_START_VALUE_PRECEDING;
10325 n->startOffset = $1;
10326 n->endOffset = NULL;
10331 WindowDef *n = makeNode(WindowDef);
10332 n->frameOptions = FRAMEOPTION_START_VALUE_FOLLOWING;
10333 n->startOffset = $1;
10334 n->endOffset = NULL;
10341 * Supporting nonterminals for expressions.
10344 /* Explicit row production.
10346 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
10347 * without conflicting with the parenthesized a_expr production. Without the
10348 * ROW keyword, there must be more than one a_expr inside the parens.
10350 row: ROW '(' expr_list ')' { $$ = $3; }
10351 | ROW '(' ')' { $$ = NIL; }
10352 | '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
10355 sub_type: ANY { $$ = ANY_SUBLINK; }
10356 | SOME { $$ = ANY_SUBLINK; }
10357 | ALL { $$ = ALL_SUBLINK; }
10360 all_Op: Op { $$ = $1; }
10361 | MathOp { $$ = $1; }
10364 MathOp: '+' { $$ = "+"; }
10365 | '-' { $$ = "-"; }
10366 | '*' { $$ = "*"; }
10367 | '/' { $$ = "/"; }
10368 | '%' { $$ = "%"; }
10369 | '^' { $$ = "^"; }
10370 | '<' { $$ = "<"; }
10371 | '>' { $$ = ">"; }
10372 | '=' { $$ = "="; }
10376 { $$ = list_make1(makeString($1)); }
10377 | OPERATOR '(' any_operator ')'
10383 { $$ = list_make1(makeString($1)); }
10384 | OPERATOR '(' any_operator ')'
10390 { $$ = list_make1(makeString($1)); }
10391 | OPERATOR '(' any_operator ')'
10394 { $$ = list_make1(makeString("~~")); }
10396 { $$ = list_make1(makeString("!~~")); }
10398 { $$ = list_make1(makeString("~~*")); }
10400 { $$ = list_make1(makeString("!~~*")); }
10401 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
10402 * the regular expression is preprocessed by a function (similar_escape),
10403 * and the ~ operator for posix regular expressions is used.
10404 * x SIMILAR TO y -> x ~ similar_escape(y)
10405 * this transformation is made on the fly by the parser upwards.
10406 * however the SubLink structure which handles any/some/all stuff
10407 * is not ready for such a thing.
10413 $$ = list_make1($1);
10415 | expr_list ',' a_expr
10417 $$ = lappend($1, $3);
10421 /* function arguments can have names */
10422 func_arg_list: func_arg_expr
10424 $$ = list_make1($1);
10426 | func_arg_list ',' func_arg_expr
10428 $$ = lappend($1, $3);
10432 func_arg_expr: a_expr
10436 | param_name COLON_EQUALS a_expr
10438 NamedArgExpr *na = makeNode(NamedArgExpr);
10440 na->arg = (Expr *) $3;
10441 na->argnumber = -1; /* until determined */
10447 type_list: Typename { $$ = list_make1($1); }
10448 | type_list ',' Typename { $$ = lappend($1, $3); }
10451 array_expr: '[' expr_list ']'
10453 $$ = makeAArrayExpr($2, @1);
10455 | '[' array_expr_list ']'
10457 $$ = makeAArrayExpr($2, @1);
10461 $$ = makeAArrayExpr(NIL, @1);
10465 array_expr_list: array_expr { $$ = list_make1($1); }
10466 | array_expr_list ',' array_expr { $$ = lappend($1, $3); }
10471 extract_arg FROM a_expr
10473 $$ = list_make2(makeStringConst($1, @1), $3);
10475 | /*EMPTY*/ { $$ = NIL; }
10478 /* Allow delimited string Sconst in extract_arg as an SQL extension.
10479 * - thomas 2001-04-12
10483 | YEAR_P { $$ = "year"; }
10484 | MONTH_P { $$ = "month"; }
10485 | DAY_P { $$ = "day"; }
10486 | HOUR_P { $$ = "hour"; }
10487 | MINUTE_P { $$ = "minute"; }
10488 | SECOND_P { $$ = "second"; }
10489 | Sconst { $$ = $1; }
10492 /* OVERLAY() arguments
10493 * SQL99 defines the OVERLAY() function:
10494 * o overlay(text placing text from int for int)
10495 * o overlay(text placing text from int)
10496 * and similarly for binary strings
10499 a_expr overlay_placing substr_from substr_for
10501 $$ = list_make4($1, $2, $3, $4);
10503 | a_expr overlay_placing substr_from
10505 $$ = list_make3($1, $2, $3);
10514 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
10517 b_expr IN_P b_expr { $$ = list_make2($3, $1); }
10518 | /*EMPTY*/ { $$ = NIL; }
10521 /* SUBSTRING() arguments
10522 * SQL9x defines a specific syntax for arguments to SUBSTRING():
10523 * o substring(text from int for int)
10524 * o substring(text from int) get entire string from starting point "int"
10525 * o substring(text for int) get first "int" characters of string
10526 * o substring(text from pattern) get entire string matching pattern
10527 * o substring(text from pattern for escape) same with specified escape char
10528 * We also want to support generic substring functions which accept
10529 * the usual generic list of arguments. So we will accept both styles
10530 * here, and convert the SQL9x style to the generic list for further
10531 * processing. - thomas 2000-11-28
10534 a_expr substr_from substr_for
10536 $$ = list_make3($1, $2, $3);
10538 | a_expr substr_for substr_from
10540 /* not legal per SQL99, but might as well allow it */
10541 $$ = list_make3($1, $3, $2);
10543 | a_expr substr_from
10545 $$ = list_make2($1, $2);
10547 | a_expr substr_for
10550 * Since there are no cases where this syntax allows
10551 * a textual FOR value, we forcibly cast the argument
10552 * to int4. The possible matches in pg_proc are
10553 * substring(text,int4) and substring(text,text),
10554 * and we don't want the parser to choose the latter,
10555 * which it is likely to do if the second argument
10556 * is unknown or doesn't have an implicit cast to int4.
10558 $$ = list_make3($1, makeIntConst(1, -1),
10560 SystemTypeName("int4"), -1));
10571 FROM a_expr { $$ = $2; }
10574 substr_for: FOR a_expr { $$ = $2; }
10577 trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
10578 | FROM expr_list { $$ = $2; }
10579 | expr_list { $$ = $1; }
10582 in_expr: select_with_parens
10584 SubLink *n = makeNode(SubLink);
10586 /* other fields will be filled later */
10589 | '(' expr_list ')' { $$ = (Node *)$2; }
10593 * Define SQL92-style case clause.
10594 * - Full specification
10595 * CASE WHEN a = b THEN c ... ELSE d END
10596 * - Implicit argument
10597 * CASE a WHEN b THEN c ... ELSE d END
10599 case_expr: CASE case_arg when_clause_list case_default END_P
10601 CaseExpr *c = makeNode(CaseExpr);
10602 c->casetype = InvalidOid; /* not analyzed yet */
10603 c->arg = (Expr *) $2;
10605 c->defresult = (Expr *) $4;
10612 /* There must be at least one */
10613 when_clause { $$ = list_make1($1); }
10614 | when_clause_list when_clause { $$ = lappend($1, $2); }
10618 WHEN a_expr THEN a_expr
10620 CaseWhen *w = makeNode(CaseWhen);
10621 w->expr = (Expr *) $2;
10622 w->result = (Expr *) $4;
10629 ELSE a_expr { $$ = $2; }
10630 | /*EMPTY*/ { $$ = NULL; }
10633 case_arg: a_expr { $$ = $1; }
10634 | /*EMPTY*/ { $$ = NULL; }
10639 $$ = makeColumnRef($1, NIL, @1, yyscanner);
10641 | ColId indirection
10643 $$ = makeColumnRef($1, $2, @1, yyscanner);
10650 $$ = (Node *) makeString($2);
10654 $$ = (Node *) makeNode(A_Star);
10658 A_Indices *ai = makeNode(A_Indices);
10663 | '[' a_expr ':' a_expr ']'
10665 A_Indices *ai = makeNode(A_Indices);
10673 indirection_el { $$ = list_make1($1); }
10674 | indirection indirection_el { $$ = lappend($1, $2); }
10678 /*EMPTY*/ { $$ = NIL; }
10679 | opt_indirection indirection_el { $$ = lappend($1, $2); }
10682 opt_asymmetric: ASYMMETRIC
10687 * The SQL spec defines "contextually typed value expressions" and
10688 * "contextually typed row value constructors", which for our purposes
10689 * are the same as "a_expr" and "row" except that DEFAULT can appear at
10694 a_expr { $$ = (Node *) $1; }
10697 SetToDefault *n = makeNode(SetToDefault);
10704 ctext_expr { $$ = list_make1($1); }
10705 | ctext_expr_list ',' ctext_expr { $$ = lappend($1, $3); }
10709 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
10710 * making VALUES a fully reserved word, which will probably break more apps
10711 * than allowing the noise-word is worth.
10713 ctext_row: '(' ctext_expr_list ')' { $$ = $2; }
10717 /*****************************************************************************
10719 * target list for SELECT
10721 *****************************************************************************/
10724 target_el { $$ = list_make1($1); }
10725 | target_list ',' target_el { $$ = lappend($1, $3); }
10728 target_el: a_expr AS ColLabel
10730 $$ = makeNode(ResTarget);
10732 $$->indirection = NIL;
10733 $$->val = (Node *)$1;
10737 * We support omitting AS only for column labels that aren't
10738 * any known keyword. There is an ambiguity against postfix
10739 * operators: is "a ! b" an infix expression, or a postfix
10740 * expression and a column label? We prefer to resolve this
10741 * as an infix expression, which we accomplish by assigning
10742 * IDENT a precedence higher than POSTFIXOP.
10746 $$ = makeNode(ResTarget);
10748 $$->indirection = NIL;
10749 $$->val = (Node *)$1;
10754 $$ = makeNode(ResTarget);
10756 $$->indirection = NIL;
10757 $$->val = (Node *)$1;
10762 ColumnRef *n = makeNode(ColumnRef);
10763 n->fields = list_make1(makeNode(A_Star));
10766 $$ = makeNode(ResTarget);
10768 $$->indirection = NIL;
10769 $$->val = (Node *)n;
10775 /*****************************************************************************
10777 * Names and constants
10779 *****************************************************************************/
10781 qualified_name_list:
10782 qualified_name { $$ = list_make1($1); }
10783 | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
10787 * The production for a qualified relation name has to exactly match the
10788 * production for a qualified func_name, because in a FROM clause we cannot
10789 * tell which we are parsing until we see what comes after it ('(' for a
10790 * func_name, something else for a relation). Therefore we allow 'indirection'
10791 * which may contain subscripts, and reject that case in the C code.
10796 $$ = makeNode(RangeVar);
10797 $$->catalogname = NULL;
10798 $$->schemaname = NULL;
10802 | ColId indirection
10804 check_qualified_name($2, yyscanner);
10805 $$ = makeNode(RangeVar);
10806 switch (list_length($2))
10809 $$->catalogname = NULL;
10810 $$->schemaname = $1;
10811 $$->relname = strVal(linitial($2));
10814 $$->catalogname = $1;
10815 $$->schemaname = strVal(linitial($2));
10816 $$->relname = strVal(lsecond($2));
10820 (errcode(ERRCODE_SYNTAX_ERROR),
10821 errmsg("improper qualified name (too many dotted names): %s",
10822 NameListToString(lcons(makeString($1), $2))),
10823 parser_errposition(@1)));
10831 { $$ = list_make1(makeString($1)); }
10832 | name_list ',' name
10833 { $$ = lappend($1, makeString($3)); }
10837 name: ColId { $$ = $1; };
10840 ColId { $$ = $1; };
10843 ColId { $$ = $1; };
10845 attr_name: ColLabel { $$ = $1; };
10847 index_name: ColId { $$ = $1; };
10849 file_name: Sconst { $$ = $1; };
10852 * The production for a qualified func_name has to exactly match the
10853 * production for a qualified columnref, because we cannot tell which we
10854 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
10855 * anything else for a columnref). Therefore we allow 'indirection' which
10856 * may contain subscripts, and reject that case in the C code. (If we
10857 * ever implement SQL99-like methods, such syntax may actually become legal!)
10859 func_name: type_function_name
10860 { $$ = list_make1(makeString($1)); }
10861 | ColId indirection
10863 $$ = check_func_name(lcons(makeString($1), $2),
10874 $$ = makeIntConst($1, @1);
10878 $$ = makeFloatConst($1, @1);
10882 $$ = makeStringConst($1, @1);
10886 $$ = makeBitStringConst($1, @1);
10890 /* This is a bit constant per SQL99:
10891 * Without Feature F511, "BIT data type",
10892 * a <general literal> shall not be a
10893 * <bit string literal> or a <hex string literal>.
10895 $$ = makeBitStringConst($1, @1);
10899 /* generic type 'literal' syntax */
10900 TypeName *t = makeTypeNameFromNameList($1);
10902 $$ = makeStringConstCast($2, @2, t);
10904 | func_name '(' func_arg_list ')' Sconst
10906 /* generic syntax with a type modifier */
10907 TypeName *t = makeTypeNameFromNameList($1);
10911 * We must use func_arg_list in the production to avoid
10912 * reduce/reduce conflicts, but we don't actually wish
10913 * to allow NamedArgExpr in this context.
10917 NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
10919 if (IsA(arg, NamedArgExpr))
10921 (errcode(ERRCODE_SYNTAX_ERROR),
10922 errmsg("type modifier cannot have parameter name"),
10923 parser_errposition(arg->location)));
10927 $$ = makeStringConstCast($5, @5, t);
10929 | ConstTypename Sconst
10931 $$ = makeStringConstCast($2, @2, $1);
10933 | ConstInterval Sconst opt_interval
10937 $$ = makeStringConstCast($2, @2, t);
10939 | ConstInterval '(' Iconst ')' Sconst opt_interval
10944 if (list_length($6) != 1)
10946 (errcode(ERRCODE_SYNTAX_ERROR),
10947 errmsg("interval precision specified twice"),
10948 parser_errposition(@1)));
10949 t->typmods = lappend($6, makeIntConst($3, @3));
10952 t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
10953 makeIntConst($3, @3));
10954 $$ = makeStringConstCast($5, @5, t);
10958 $$ = makeBoolAConst(TRUE, @1);
10962 $$ = makeBoolAConst(FALSE, @1);
10966 $$ = makeNullAConst(@1);
10970 Iconst: ICONST { $$ = $1; };
10971 Sconst: SCONST { $$ = $1; };
10972 RoleId: ColId { $$ = $1; };
10974 SignedIconst: Iconst { $$ = $1; }
10975 | '+' Iconst { $$ = + $2; }
10976 | '-' Iconst { $$ = - $2; }
10980 * Name classification hierarchy.
10982 * IDENT is the lexeme returned by the lexer for identifiers that match
10983 * no known keyword. In most cases, we can accept certain keywords as
10984 * names, not only IDENTs. We prefer to accept as many such keywords
10985 * as possible to minimize the impact of "reserved words" on programmers.
10986 * So, we divide names into several possible classes. The classification
10987 * is chosen in part to make keywords acceptable as names wherever possible.
10990 /* Column identifier --- names that can be column, table, etc names.
10992 ColId: IDENT { $$ = $1; }
10993 | unreserved_keyword { $$ = pstrdup($1); }
10994 | col_name_keyword { $$ = pstrdup($1); }
10997 /* Type/function identifier --- names that can be type or function names.
10999 type_function_name: IDENT { $$ = $1; }
11000 | unreserved_keyword { $$ = pstrdup($1); }
11001 | type_func_name_keyword { $$ = pstrdup($1); }
11004 /* Column label --- allowed labels in "AS" clauses.
11005 * This presently includes *all* Postgres keywords.
11007 ColLabel: IDENT { $$ = $1; }
11008 | unreserved_keyword { $$ = pstrdup($1); }
11009 | col_name_keyword { $$ = pstrdup($1); }
11010 | type_func_name_keyword { $$ = pstrdup($1); }
11011 | reserved_keyword { $$ = pstrdup($1); }
11016 * Keyword category lists. Generally, every keyword present in
11017 * the Postgres grammar should appear in exactly one of these lists.
11019 * Put a new keyword into the first list that it can go into without causing
11020 * shift or reduce conflicts. The earlier lists define "less reserved"
11021 * categories of keywords.
11023 * Make sure that each keyword's category in keywords.c matches where
11024 * it is listed here. (Someday we may be able to generate these lists and
11025 * keywords.c's table from a common master list.)
11028 /* "Unreserved" keywords --- available for use as any kind of name.
11030 unreserved_keyword:
11287 /* Column identifier --- keywords that can be column, table, etc names.
11289 * Many of these keywords will in fact be recognized as type or function
11290 * names too; but they have special productions for the purpose, and so
11291 * can't be treated as "generic" type or function names.
11293 * The type names appearing here are not usable as function names
11294 * because they can be followed by '(' in typename productions, which
11295 * looks too much like a function call for an LR(1) parser.
11347 /* Type/function identifier --- keywords that can be type or function names.
11349 * Most of these are keywords that are used as operators in expressions;
11350 * in general such keywords can't be column names because they would be
11351 * ambiguous with variables, but they are unambiguous as function identifiers.
11353 * Do not include POSITION, SUBSTRING, etc here since they have explicit
11354 * productions in a_expr to support the goofy SQL9x argument syntax.
11355 * - thomas 2000-11-28
11357 type_func_name_keyword:
11382 /* Reserved keyword --- these keywords are usable only as a ColLabel.
11384 * Keywords appear here if they could not be distinguished from variable,
11385 * type, or function names in some contexts. Don't put things here unless
11410 | CURRENT_TIMESTAMP
11471 * The signature of this function is required by bison. However, we
11472 * ignore the passed yylloc and instead use the last token position
11473 * available from the scanner.
11476 base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
11478 parser_yyerror(msg);
11482 makeColumnRef(char *colname, List *indirection,
11483 int location, core_yyscan_t yyscanner)
11486 * Generate a ColumnRef node, with an A_Indirection node added if there
11487 * is any subscripting in the specified indirection list. However,
11488 * any field selection at the start of the indirection list must be
11489 * transposed into the "fields" part of the ColumnRef node.
11491 ColumnRef *c = makeNode(ColumnRef);
11495 c->location = location;
11496 foreach(l, indirection)
11498 if (IsA(lfirst(l), A_Indices))
11500 A_Indirection *i = makeNode(A_Indirection);
11504 /* easy case - all indirection goes to A_Indirection */
11505 c->fields = list_make1(makeString(colname));
11506 i->indirection = check_indirection(indirection, yyscanner);
11510 /* got to split the list in two */
11511 i->indirection = check_indirection(list_copy_tail(indirection,
11514 indirection = list_truncate(indirection, nfields);
11515 c->fields = lcons(makeString(colname), indirection);
11517 i->arg = (Node *) c;
11520 else if (IsA(lfirst(l), A_Star))
11522 /* We only allow '*' at the end of a ColumnRef */
11523 if (lnext(l) != NULL)
11524 parser_yyerror("improper use of \"*\"");
11528 /* No subscripting, so all indirection gets added to field list */
11529 c->fields = lcons(makeString(colname), indirection);
11534 makeTypeCast(Node *arg, TypeName *typename, int location)
11536 TypeCast *n = makeNode(TypeCast);
11538 n->typeName = typename;
11539 n->location = location;
11544 makeStringConst(char *str, int location)
11546 A_Const *n = makeNode(A_Const);
11548 n->val.type = T_String;
11549 n->val.val.str = str;
11550 n->location = location;
11556 makeStringConstCast(char *str, int location, TypeName *typename)
11558 Node *s = makeStringConst(str, location);
11560 return makeTypeCast(s, typename, -1);
11564 makeIntConst(int val, int location)
11566 A_Const *n = makeNode(A_Const);
11568 n->val.type = T_Integer;
11569 n->val.val.ival = val;
11570 n->location = location;
11576 makeFloatConst(char *str, int location)
11578 A_Const *n = makeNode(A_Const);
11580 n->val.type = T_Float;
11581 n->val.val.str = str;
11582 n->location = location;
11588 makeBitStringConst(char *str, int location)
11590 A_Const *n = makeNode(A_Const);
11592 n->val.type = T_BitString;
11593 n->val.val.str = str;
11594 n->location = location;
11600 makeNullAConst(int location)
11602 A_Const *n = makeNode(A_Const);
11604 n->val.type = T_Null;
11605 n->location = location;
11611 makeAConst(Value *v, int location)
11618 n = makeFloatConst(v->val.str, location);
11622 n = makeIntConst(v->val.ival, location);
11627 n = makeStringConst(v->val.str, location);
11634 /* makeBoolAConst()
11635 * Create an A_Const string node and put it inside a boolean cast.
11638 makeBoolAConst(bool state, int location)
11640 A_Const *n = makeNode(A_Const);
11642 n->val.type = T_String;
11643 n->val.val.str = (state ? "t" : "f");
11644 n->location = location;
11646 return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
11650 * Create and populate a FuncCall node to support the OVERLAPS operator.
11653 makeOverlaps(List *largs, List *rargs, int location, core_yyscan_t yyscanner)
11655 FuncCall *n = makeNode(FuncCall);
11657 n->funcname = SystemFuncName("overlaps");
11658 if (list_length(largs) == 1)
11659 largs = lappend(largs, largs);
11660 else if (list_length(largs) != 2)
11662 (errcode(ERRCODE_SYNTAX_ERROR),
11663 errmsg("wrong number of parameters on left side of OVERLAPS expression"),
11664 parser_errposition(location)));
11665 if (list_length(rargs) == 1)
11666 rargs = lappend(rargs, rargs);
11667 else if (list_length(rargs) != 2)
11669 (errcode(ERRCODE_SYNTAX_ERROR),
11670 errmsg("wrong number of parameters on right side of OVERLAPS expression"),
11671 parser_errposition(location)));
11672 n->args = list_concat(largs, rargs);
11673 n->agg_order = NIL;
11674 n->agg_star = FALSE;
11675 n->agg_distinct = FALSE;
11676 n->func_variadic = FALSE;
11678 n->location = location;
11682 /* check_qualified_name --- check the result of qualified_name production
11684 * It's easiest to let the grammar production for qualified_name allow
11685 * subscripts and '*', which we then must reject here.
11688 check_qualified_name(List *names, core_yyscan_t yyscanner)
11694 if (!IsA(lfirst(i), String))
11695 parser_yyerror("syntax error");
11699 /* check_func_name --- check the result of func_name production
11701 * It's easiest to let the grammar production for func_name allow subscripts
11702 * and '*', which we then must reject here.
11705 check_func_name(List *names, core_yyscan_t yyscanner)
11711 if (!IsA(lfirst(i), String))
11712 parser_yyerror("syntax error");
11717 /* check_indirection --- check the result of indirection production
11719 * We only allow '*' at the end of the list, but it's hard to enforce that
11720 * in the grammar, so do it here.
11723 check_indirection(List *indirection, core_yyscan_t yyscanner)
11727 foreach(l, indirection)
11729 if (IsA(lfirst(l), A_Star))
11731 if (lnext(l) != NULL)
11732 parser_yyerror("improper use of \"*\"");
11735 return indirection;
11738 /* extractArgTypes()
11739 * Given a list of FunctionParameter nodes, extract a list of just the
11740 * argument types (TypeNames) for input parameters only. This is what
11741 * is needed to look up an existing function, which is what is wanted by
11742 * the productions that use this call.
11745 extractArgTypes(List *parameters)
11747 List *result = NIL;
11750 foreach(i, parameters)
11752 FunctionParameter *p = (FunctionParameter *) lfirst(i);
11754 if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
11755 result = lappend(result, p->argType);
11760 /* findLeftmostSelect()
11761 * Find the leftmost component SelectStmt in a set-operation parsetree.
11763 static SelectStmt *
11764 findLeftmostSelect(SelectStmt *node)
11766 while (node && node->op != SETOP_NONE)
11768 Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
11772 /* insertSelectOptions()
11773 * Insert ORDER BY, etc into an already-constructed SelectStmt.
11775 * This routine is just to avoid duplicating code in SelectStmt productions.
11778 insertSelectOptions(SelectStmt *stmt,
11779 List *sortClause, List *lockingClause,
11780 Node *limitOffset, Node *limitCount,
11781 WithClause *withClause,
11782 core_yyscan_t yyscanner)
11784 Assert(IsA(stmt, SelectStmt));
11787 * Tests here are to reject constructs like
11788 * (SELECT foo ORDER BY bar) ORDER BY baz
11792 if (stmt->sortClause)
11794 (errcode(ERRCODE_SYNTAX_ERROR),
11795 errmsg("multiple ORDER BY clauses not allowed"),
11796 parser_errposition(exprLocation((Node *) sortClause))));
11797 stmt->sortClause = sortClause;
11799 /* We can handle multiple locking clauses, though */
11800 stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
11803 if (stmt->limitOffset)
11805 (errcode(ERRCODE_SYNTAX_ERROR),
11806 errmsg("multiple OFFSET clauses not allowed"),
11807 parser_errposition(exprLocation(limitOffset))));
11808 stmt->limitOffset = limitOffset;
11812 if (stmt->limitCount)
11814 (errcode(ERRCODE_SYNTAX_ERROR),
11815 errmsg("multiple LIMIT clauses not allowed"),
11816 parser_errposition(exprLocation(limitCount))));
11817 stmt->limitCount = limitCount;
11821 if (stmt->withClause)
11823 (errcode(ERRCODE_SYNTAX_ERROR),
11824 errmsg("multiple WITH clauses not allowed"),
11825 parser_errposition(exprLocation((Node *) withClause))));
11826 stmt->withClause = withClause;
11831 makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
11833 SelectStmt *n = makeNode(SelectStmt);
11837 n->larg = (SelectStmt *) larg;
11838 n->rarg = (SelectStmt *) rarg;
11842 /* SystemFuncName()
11843 * Build a properly-qualified reference to a built-in function.
11846 SystemFuncName(char *name)
11848 return list_make2(makeString("pg_catalog"), makeString(name));
11851 /* SystemTypeName()
11852 * Build a properly-qualified reference to a built-in type.
11854 * typmod is defaulted, but may be changed afterwards by caller.
11855 * Likewise for the location.
11858 SystemTypeName(char *name)
11860 return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
11861 makeString(name)));
11865 * Handle negation of a numeric constant.
11867 * Formerly, we did this here because the optimizer couldn't cope with
11868 * indexquals that looked like "var = -4" --- it wants "var = const"
11869 * and a unary minus operator applied to a constant didn't qualify.
11870 * As of Postgres 7.0, that problem doesn't exist anymore because there
11871 * is a constant-subexpression simplifier in the optimizer. However,
11872 * there's still a good reason for doing this here, which is that we can
11873 * postpone committing to a particular internal representation for simple
11874 * negative constants. It's better to leave "-123.456" in string form
11875 * until we know what the desired type is.
11878 doNegate(Node *n, int location)
11880 if (IsA(n, A_Const))
11882 A_Const *con = (A_Const *)n;
11884 /* report the constant's location as that of the '-' sign */
11885 con->location = location;
11887 if (con->val.type == T_Integer)
11889 con->val.val.ival = -con->val.val.ival;
11892 if (con->val.type == T_Float)
11894 doNegateFloat(&con->val);
11899 return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
11903 doNegateFloat(Value *v)
11905 char *oldval = v->val.str;
11907 Assert(IsA(v, Float));
11908 if (*oldval == '+')
11910 if (*oldval == '-')
11911 v->val.str = oldval+1; /* just strip the '-' */
11914 char *newval = (char *) palloc(strlen(oldval) + 2);
11917 strcpy(newval+1, oldval);
11918 v->val.str = newval;
11923 makeAArrayExpr(List *elements, int location)
11925 A_ArrayExpr *n = makeNode(A_ArrayExpr);
11927 n->elements = elements;
11928 n->location = location;
11933 makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
11936 XmlExpr *x = makeNode(XmlExpr);
11941 * named_args is a list of ResTarget; it'll be split apart into separate
11942 * expression and name lists in transformXmlExpr().
11944 x->named_args = named_args;
11945 x->arg_names = NIL;
11947 /* xmloption, if relevant, must be filled in by caller */
11948 /* type and typmod will be filled in during parse analysis */
11949 x->location = location;
11954 * Initialize to parse one query string
11957 parser_init(base_yy_extra_type *yyext)
11959 yyext->parsetree = NIL; /* in case grammar forgets to set it */
11963 * Merge the input and output parameters of a table function.
11966 mergeTableFuncParameters(List *func_args, List *columns)
11970 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
11971 foreach(lc, func_args)
11973 FunctionParameter *p = (FunctionParameter *) lfirst(lc);
11975 if (p->mode != FUNC_PARAM_IN && p->mode != FUNC_PARAM_VARIADIC)
11977 (errcode(ERRCODE_SYNTAX_ERROR),
11978 errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
11981 return list_concat(func_args, columns);
11985 * Determine return type of a TABLE function. A single result column
11986 * returns setof that column's type; otherwise return setof record.
11989 TableFuncTypeName(List *columns)
11993 if (list_length(columns) == 1)
11995 FunctionParameter *p = (FunctionParameter *) linitial(columns);
11997 result = (TypeName *) copyObject(p->argType);
12000 result = SystemTypeName("record");
12002 result->setof = true;
12008 * Convert a list of (dotted) names to a RangeVar (like
12009 * makeRangeVarFromNameList, but with position support). The
12010 * "AnyName" refers to the any_name production in the grammar.
12013 makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
12015 RangeVar *r = makeNode(RangeVar);
12017 switch (list_length(names))
12020 r->catalogname = NULL;
12021 r->schemaname = NULL;
12022 r->relname = strVal(linitial(names));
12025 r->catalogname = NULL;
12026 r->schemaname = strVal(linitial(names));
12027 r->relname = strVal(lsecond(names));
12030 r->catalogname = strVal(linitial(names));;
12031 r->schemaname = strVal(lsecond(names));
12032 r->relname = strVal(lthird(names));
12036 (errcode(ERRCODE_SYNTAX_ERROR),
12037 errmsg("improper qualified name (too many dotted names): %s",
12038 NameListToString(names)),
12039 parser_errposition(position)));
12043 r->location = position;
12049 * Must undefine this stuff before including scan.c, since it has different
12050 * definitions for these macros.