4 /*-------------------------------------------------------------------------
7 * POSTGRES SQL YACC rules/actions
9 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
10 * Portions Copyright (c) 1994, Regents of the University of California
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 "commands/defrem.h"
57 #include "nodes/makefuncs.h"
58 #include "nodes/nodeFuncs.h"
59 #include "parser/gramparse.h"
60 #include "storage/lmgr.h"
61 #include "utils/date.h"
62 #include "utils/datetime.h"
63 #include "utils/numeric.h"
64 #include "utils/xml.h"
67 /* Location tracking support --- simpler than bison's default */
68 #define YYLLOC_DEFAULT(Current, Rhs, N) \
71 (Current
) = (Rhs
)[1]; \
73 (Current
) = (Rhs
)[0]; \
77 * The %name-prefix option below will make bison call base_yylex, but we
78 * really want it to call filtered_base_yylex (see parser.c).
80 #define base_yylex filtered_base_yylex
83 * Bison doesn't allocate anything that needs to live across parser calls,
84 * so we can easily have it use palloc instead of malloc. This prevents
85 * memory leaks if we error out during parsing. Note this only works with
86 * bison >= 2.0. However, in bison 1.875 the default is to use alloca()
87 * if possible, so there's not really much problem anyhow, at least if
88 * you're building with gcc.
90 #define YYMALLOC palloc
93 extern List
*parsetree
; /* final parse result is delivered here */
95 static bool QueryIsRule
= FALSE
;
98 * If you need access to certain yacc-generated variables and find that
99 * they're static by default, uncomment the next line. (this is not a
102 /*#define __YYSCLASS*/
104 static Node
*makeColumnRef
(char *colname
, List
*indirection
, int location
);
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
, int location
);
115 static void check_qualified_name
(List
*names
);
116 static List
*check_func_name
(List
*names
);
117 static List
*check_indirection
(List
*indirection
);
118 static List
*extractArgTypes
(List
*parameters
);
119 static SelectStmt
*findLeftmostSelect
(SelectStmt
*node
);
120 static void insertSelectOptions
(SelectStmt
*stmt
,
121 List
*sortClause
, List
*lockingClause
,
122 Node
*limitOffset
, Node
*limitCount
,
123 WithClause
*withClause
);
124 static Node
*makeSetOp
(SetOperation op
, bool all
, Node
*larg
, Node
*rarg
);
125 static Node
*doNegate
(Node
*n
, int location
);
126 static void doNegateFloat
(Value
*v
);
127 static Node
*makeAArrayExpr
(List
*elements
, int location
);
128 static Node
*makeXmlExpr
(XmlExprOp op
, char *name
, List
*named_args
,
129 List
*args
, int location
);
130 static List
*mergeTableFuncParameters
(List
*func_args
, List
*columns
);
131 static TypeName
*TableFuncTypeName
(List
*columns
);
136 %name
-prefix
="base_yy"
147 DropBehavior dbehavior
;
148 OnCommitAction oncommit
;
155 FunctionParameter
*fun_param
;
156 FunctionParameterMode fun_param_mode
;
157 FuncWithArgs
*funwithargs
;
168 PrivTarget
*privtarget
;
171 VariableSetStmt
*vsetstmt
;
174 %type
<node
> stmt schema_stmt
175 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterGroupStmt
176 AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterTableStmt
177 AlterUserStmt AlterUserSetStmt AlterRoleStmt AlterRoleSetStmt
178 AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
179 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
180 CreateDomainStmt CreateGroupStmt CreateOpClassStmt
181 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
182 CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
183 CreateAssertStmt CreateTrigStmt CreateUserStmt CreateRoleStmt
184 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt
185 DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
186 DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
187 DropUserStmt DropdbStmt DropTableSpaceStmt ExplainStmt FetchStmt
188 GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
189 LockStmt NotifyStmt ExplainableStmt PreparableStmt
190 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
191 RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
192 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
193 SelectStmt TransactionStmt TruncateStmt
194 UnlistenStmt UpdateStmt VacuumStmt
195 VariableResetStmt VariableSetStmt VariableShowStmt
196 ViewStmt CheckPointStmt CreateConversionStmt
197 DeallocateStmt PrepareStmt ExecuteStmt
198 DropOwnedStmt ReassignOwnedStmt
199 AlterTSConfigurationStmt AlterTSDictionaryStmt
201 %type
<node
> select_no_parens select_with_parens select_clause
202 simple_select values_clause
204 %type
<node
> alter_column_default opclass_item opclass_drop alter_using
205 %type
<ival
> add_drop opt_asc_desc opt_nulls_order
207 %type
<node
> alter_table_cmd
208 %type
<list
> alter_table_cmds
210 %type
<dbehavior
> opt_drop_behavior
212 %type
<list
> createdb_opt_list alterdb_opt_list copy_opt_list
213 transaction_mode_list
214 %type
<defelt
> createdb_opt_item alterdb_opt_item copy_opt_item
215 transaction_mode_item
217 %type
<ival
> opt_lock lock_type cast_context
218 %type
<boolean
> opt_force opt_or_replace
219 opt_grant_grant_option opt_grant_admin_option
220 opt_nowait opt_if_exists opt_with_data
222 %type
<list
> OptRoleList
223 %type
<defelt
> OptRoleElem
225 %type
<str
> OptSchemaName
226 %type
<list
> OptSchemaEltList
228 %type
<boolean
> TriggerActionTime TriggerForSpec opt_trusted opt_restart_seqs
229 %type
<str
> opt_lancompiler
231 %type
<str
> TriggerEvents
232 %type
<value
> TriggerFuncArg
234 %type
<str
> relation_name copy_file_name
235 database_name access_method_clause access_method attr_name
236 index_name name file_name cluster_index_specification
238 %type
<list
> func_name handler_name qual_Op qual_all_Op subquery_Op
239 opt_class opt_validator
241 %type
<range
> qualified_name OptConstrFromTable
243 %type
<str
> all_Op MathOp SpecialRuleRelation
245 %type
<str
> iso_level opt_encoding
247 %type
<list
> grantee_list
248 %type
<str
> privilege
249 %type
<list
> privileges privilege_list
250 %type
<privtarget
> privilege_target
251 %type
<funwithargs
> function_with_argtypes
252 %type
<list
> function_with_argtypes_list
253 %type
<chr
> TriggerOneEvent
255 %type
<list
> stmtblock stmtmulti
256 OptTableElementList TableElementList OptInherit definition
257 OptWith opt_distinct opt_definition func_args func_args_list
258 func_args_with_defaults func_args_with_defaults_list
259 func_as createfunc_opt_list alterfunc_opt_list
260 aggr_args old_aggr_definition old_aggr_list
261 oper_argtypes RuleActionList RuleActionMulti
262 opt_column_list columnList opt_name_list
263 sort_clause opt_sort_clause sortby_list index_params
264 name_list from_clause from_list opt_array_bounds
265 qualified_name_list any_name any_name_list
266 any_operator expr_list attrs
267 target_list insert_column_list set_target_list
268 set_clause_list set_clause multiple_set_clause
269 ctext_expr_list ctext_row def_list indirection opt_indirection
270 group_clause TriggerFuncArgs select_limit
271 opt_select_limit opclass_item_list opclass_drop_list
272 opt_opfamily transaction_mode_list_or_empty
273 TableFuncElementList opt_type_modifiers
275 execute_param_clause using_clause returning_clause
276 enum_val_list table_func_column_list
278 %type
<range
> OptTempTableName
279 %type
<into
> into_clause create_as_target
281 %type
<defelt
> createfunc_opt_item common_func_opt_item
282 %type
<fun_param
> func_arg func_arg_with_default table_func_column
283 %type
<fun_param_mode
> arg_class
284 %type
<typnam
> func_return func_type
286 %type
<boolean
> TriggerForType OptTemp
287 %type
<oncommit
> OnCommitOption
289 %type
<node
> for_locking_item
290 %type
<list
> for_locking_clause opt_for_locking_clause for_locking_items
291 %type
<list
> locked_rels_list
292 %type
<boolean
> opt_all
294 %type
<node
> join_outer join_qual
295 %type
<jtype
> join_type
297 %type
<list
> extract_list overlay_list position_list
298 %type
<list
> substr_list trim_list
299 %type
<list
> opt_interval interval_second
300 %type
<node
> overlay_placing substr_from substr_for
302 %type
<boolean
> opt_instead opt_analyze
303 %type
<boolean
> index_opt_unique opt_verbose opt_full
304 %type
<boolean
> opt_freeze opt_default opt_recheck
305 %type
<defelt
> opt_binary opt_oids copy_delimiter
307 %type
<boolean
> copy_from
309 %type
<ival
> opt_column event cursor_options opt_hold opt_set_data
310 %type
<objtype
> reindex_type drop_type comment_type
312 %type
<node
> fetch_direction select_limit_value select_offset_value
313 select_offset_value2 opt_select_fetch_first_value
314 %type
<ival
> row_or_rows first_or_next
316 %type
<list
> OptSeqOptList SeqOptList
317 %type
<defelt
> SeqOptElem
319 %type
<istmt
> insert_rest
321 %type
<vsetstmt
> set_rest SetResetClause
323 %type
<node
> TableElement ConstraintElem TableFuncElement
324 %type
<node
> columnDef
325 %type
<defelt
> def_elem old_aggr_elem
326 %type
<node
> def_arg columnElem where_clause where_or_current_clause
327 a_expr b_expr c_expr func_expr AexprConst indirection_el
328 columnref in_expr having_clause func_table array_expr
329 %type
<list
> row type_list array_expr_list
330 %type
<node
> case_expr case_arg when_clause case_default
331 %type
<list
> when_clause_list
332 %type
<ival
> sub_type
333 %type
<list
> OptCreateAs CreateAsList
334 %type
<node
> CreateAsElement ctext_expr
335 %type
<value
> NumericOnly
336 %type
<alias
> alias_clause
337 %type
<sortby
> sortby
338 %type
<ielem
> index_elem
339 %type
<node
> table_ref
340 %type
<jexpr
> joined_table
341 %type
<range
> relation_expr
342 %type
<range
> relation_expr_opt_alias
343 %type
<target
> target_el single_set_clause set_target insert_column_item
345 %type
<typnam
> Typename SimpleTypename ConstTypename
346 GenericType Numeric opt_float
347 Character ConstCharacter
348 CharacterWithLength CharacterWithoutLength
349 ConstDatetime ConstInterval
350 Bit ConstBit BitWithLength BitWithoutLength
351 %type
<str
> character
352 %type
<str
> extract_arg
353 %type
<str
> opt_charset
354 %type
<boolean
> opt_varying opt_timezone
356 %type
<ival
> Iconst SignedIconst
357 %type
<str
> Sconst comment_text
358 %type
<str
> RoleId opt_granted_by opt_boolean ColId_or_Sconst
359 %type
<list
> var_list
360 %type
<str
> ColId ColLabel var_name type_function_name param_name
361 %type
<node
> var_value zone_value
363 %type
<keyword
> unreserved_keyword type_func_name_keyword
364 %type
<keyword
> col_name_keyword reserved_keyword
366 %type
<node
> TableConstraint TableLikeClause
367 %type
<list
> TableLikeOptionList
368 %type
<ival
> TableLikeOption
369 %type
<list
> ColQualList
370 %type
<node
> ColConstraint ColConstraintElem ConstraintAttr
371 %type
<ival
> key_actions key_delete key_match key_update key_action
372 %type
<ival
> ConstraintAttributeSpec ConstraintDeferrabilitySpec
375 %type
<list
> constraints_set_list
376 %type
<boolean
> constraints_set_mode
377 %type
<str
> OptTableSpace OptConsTableSpace OptTableSpaceOwner
378 %type
<list
> opt_check_option
380 %type
<target
> xml_attribute_el
381 %type
<list
> xml_attribute_list xml_attributes
382 %type
<node
> xml_root_version opt_xml_root_standalone
383 %type
<ival
> document_or_content
384 %type
<boolean
> xml_whitespace_option
386 %type
<node
> common_table_expr
387 %type
<with
> with_clause
388 %type
<list
> cte_list
392 * If you make any token changes, update the keyword table in
393 * parser/keywords.c and add new keywords to the appropriate one of
394 * the reserved-or-not-so-reserved keyword lists, below; search
395 * this file for "Name classification hierarchy".
398 /* ordinary key words in alphabetical order */
399 %token
<keyword
> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
400 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
401 ASSERTION ASSIGNMENT ASYMMETRIC AT AUTHORIZATION
403 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
406 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
407 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
408 CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT
409 COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
410 CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
411 CREATEROLE CREATEUSER CROSS CSV CTYPE CURRENT_P
412 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
413 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
415 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
416 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
417 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
419 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT EXCLUDING
420 EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
422 FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOR FORCE FOREIGN FORWARD
423 FREEZE FROM FULL FUNCTION
425 GLOBAL GRANT GRANTED GREATEST GROUP_P
427 HANDLER HAVING HEADER_P HOLD HOUR_P
429 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
430 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY
431 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
432 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
438 LANCOMPILER LANGUAGE LARGE_P LAST_P LEADING LEAST LEFT LEVEL
439 LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP LOCATION
442 MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
444 NAME_P NAMES NATIONAL NATURAL NCHAR NEW NEXT NO NOCREATEDB
445 NOCREATEROLE NOCREATEUSER NOINHERIT NOLOGIN_P NONE NOSUPERUSER
446 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NULLS_P NUMERIC
448 OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OR
449 ORDER OUT_P OUTER_P OVERLAPS OVERLAY OWNED OWNER
451 PARSER PARTIAL PASSWORD PLACING PLANS POSITION
452 PRECISION PRESERVE PREPARE PREPARED PRIMARY
453 PRIOR PRIVILEGES PROCEDURAL PROCEDURE
457 READ REAL REASSIGN RECHECK RECURSIVE REFERENCES REINDEX RELATIVE_P RELEASE
458 RENAME REPEATABLE REPLACE REPLICA RESET RESTART RESTRICT RETURNING RETURNS
459 REVOKE RIGHT ROLE ROLLBACK ROW ROWS RULE
461 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE
462 SERIALIZABLE SESSION SESSION_USER SET SETOF SHARE
463 SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT
464 STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING SUPERUSER_P
465 SYMMETRIC SYSID SYSTEM_P
467 TABLE TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
468 TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
469 TRUNCATE TRUSTED TYPE_P
471 UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
474 VACUUM VALID VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
475 VERBOSE VERSION_P VIEW VOLATILE
477 WHEN WHERE WHITESPACE_P WITH WITHOUT WORK WRITE
479 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLFOREST XMLPARSE
480 XMLPI XMLROOT XMLSERIALIZE
486 /* The grammar thinks these are keywords, but they are not in the keywords.c
487 * list and so can never be entered directly. The filter in parser.c
488 * creates these tokens when required.
490 %token NULLS_FIRST NULLS_LAST WITH_TIME
492 /* Special token types, not actually keywords - see the "lex" file */
493 %token
<str
> IDENT FCONST SCONST BCONST XCONST Op
494 %token
<ival
> ICONST PARAM
496 /* precedence: lowest to highest */
497 %nonassoc SET
/* see relation_expr_opt_alias */
505 %nonassoc LIKE ILIKE SIMILAR
510 %left POSTFIXOP
/* dummy for postfix Op rules */
511 %nonassoc IDENT
/* to support target_el without AS */
512 %left Op OPERATOR
/* multi-character ops and user-defined operators */
515 %nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN
/* sets precedence for IS NULL, etc */
519 /* Unary Operators */
520 %left AT ZONE
/* sets precedence for AT TIME ZONE */
527 * These might seem to be low-precedence, but actually they are not part
528 * of the arithmetic hierarchy at all in their use as JOIN operators.
529 * We make them high-precedence to support their use as function names.
530 * They wouldn't be given a precedence at all, were it not that we need
531 * left-associativity among the JOIN rules themselves.
533 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
534 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
535 %right PRESERVE STRIP_P
539 * Handle comment-only lines, and ;; SELECT * FROM pg_class ;;;
540 * psql already handles such cases, but other interfaces don't.
543 stmtblock: stmtmulti
{ parsetree
= $1; }
546 /* the thrashing around here is to discard "empty" statements... */
547 stmtmulti: stmtmulti
';' stmt
549 $$
= lappend
($1, $3);
563 | AlterDatabaseSetStmt
567 | AlterObjectSchemaStmt
573 | AlterTSConfigurationStmt
574 | AlterTSDictionaryStmt
587 | CreateConversionStmt
598 | CreateTableSpaceStmt
657 /*****************************************************************************
659 * Create a new Postgres DBMS role
661 *****************************************************************************/
664 CREATE ROLE RoleId opt_with OptRoleList
666 CreateRoleStmt
*n
= makeNode
(CreateRoleStmt
);
667 n
->stmt_type
= ROLESTMT_ROLE
;
680 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
681 * for backwards compatibility). Note: the only option required by SQL99
682 * is "WITH ADMIN name".
685 OptRoleList OptRoleElem
{ $$
= lappend
($1, $2); }
686 |
/* EMPTY */ { $$
= NIL
; }
692 $$
= makeDefElem
("password",
693 (Node
*)makeString
($2));
697 $$
= makeDefElem
("password", NULL
);
699 | ENCRYPTED PASSWORD Sconst
701 $$
= makeDefElem
("encryptedPassword",
702 (Node
*)makeString
($3));
704 | UNENCRYPTED PASSWORD Sconst
706 $$
= makeDefElem
("unencryptedPassword",
707 (Node
*)makeString
($3));
711 $$
= makeDefElem
("superuser", (Node
*)makeInteger
(TRUE
));
715 $$
= makeDefElem
("superuser", (Node
*)makeInteger
(FALSE
));
719 $$
= makeDefElem
("inherit", (Node
*)makeInteger
(TRUE
));
723 $$
= makeDefElem
("inherit", (Node
*)makeInteger
(FALSE
));
727 $$
= makeDefElem
("createdb", (Node
*)makeInteger
(TRUE
));
731 $$
= makeDefElem
("createdb", (Node
*)makeInteger
(FALSE
));
735 $$
= makeDefElem
("createrole", (Node
*)makeInteger
(TRUE
));
739 $$
= makeDefElem
("createrole", (Node
*)makeInteger
(FALSE
));
743 /* For backwards compatibility, synonym for SUPERUSER */
744 $$
= makeDefElem
("superuser", (Node
*)makeInteger
(TRUE
));
748 $$
= makeDefElem
("superuser", (Node
*)makeInteger
(FALSE
));
752 $$
= makeDefElem
("canlogin", (Node
*)makeInteger
(TRUE
));
756 $$
= makeDefElem
("canlogin", (Node
*)makeInteger
(FALSE
));
758 | CONNECTION LIMIT SignedIconst
760 $$
= makeDefElem
("connectionlimit", (Node
*)makeInteger
($3));
764 $$
= makeDefElem
("validUntil", (Node
*)makeString
($3));
766 /* Supported but not documented for roles, for use by ALTER GROUP. */
769 $$
= makeDefElem
("rolemembers", (Node
*)$2);
771 /* The following are not supported by ALTER ROLE/USER/GROUP */
774 $$
= makeDefElem
("sysid", (Node
*)makeInteger
($2));
778 $$
= makeDefElem
("adminmembers", (Node
*)$2);
782 $$
= makeDefElem
("rolemembers", (Node
*)$2);
784 | IN_P ROLE name_list
786 $$
= makeDefElem
("addroleto", (Node
*)$3);
788 | IN_P GROUP_P name_list
790 $$
= makeDefElem
("addroleto", (Node
*)$3);
795 /*****************************************************************************
797 * Create a new Postgres DBMS user (role with implied login ability)
799 *****************************************************************************/
802 CREATE USER RoleId opt_with OptRoleList
804 CreateRoleStmt
*n
= makeNode
(CreateRoleStmt
);
805 n
->stmt_type
= ROLESTMT_USER
;
813 /*****************************************************************************
815 * Alter a postgresql DBMS role
817 *****************************************************************************/
820 ALTER ROLE RoleId opt_with OptRoleList
822 AlterRoleStmt
*n
= makeNode
(AlterRoleStmt
);
824 n
->action
= +1; /* add, if there are members */
831 ALTER ROLE RoleId SetResetClause
833 AlterRoleSetStmt
*n
= makeNode
(AlterRoleSetStmt
);
841 /*****************************************************************************
843 * Alter a postgresql DBMS user
845 *****************************************************************************/
848 ALTER USER RoleId opt_with OptRoleList
850 AlterRoleStmt
*n
= makeNode
(AlterRoleStmt
);
852 n
->action
= +1; /* add, if there are members */
860 ALTER USER RoleId SetResetClause
862 AlterRoleSetStmt
*n
= makeNode
(AlterRoleSetStmt
);
870 /*****************************************************************************
872 * Drop a postgresql DBMS role
874 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
875 * might own objects in multiple databases, there is presently no way to
876 * implement either cascading or restricting. Caveat DBA.
877 *****************************************************************************/
882 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
883 n
->missing_ok
= FALSE
;
887 | DROP ROLE IF_P EXISTS name_list
889 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
890 n
->missing_ok
= TRUE
;
896 /*****************************************************************************
898 * Drop a postgresql DBMS user
900 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
901 * might own objects in multiple databases, there is presently no way to
902 * implement either cascading or restricting. Caveat DBA.
903 *****************************************************************************/
908 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
909 n
->missing_ok
= FALSE
;
913 | DROP USER IF_P EXISTS name_list
915 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
917 n
->missing_ok
= TRUE
;
923 /*****************************************************************************
925 * Create a postgresql group (role without login ability)
927 *****************************************************************************/
930 CREATE GROUP_P RoleId opt_with OptRoleList
932 CreateRoleStmt
*n
= makeNode
(CreateRoleStmt
);
933 n
->stmt_type
= ROLESTMT_GROUP
;
941 /*****************************************************************************
943 * Alter a postgresql group
945 *****************************************************************************/
948 ALTER GROUP_P RoleId add_drop USER name_list
950 AlterRoleStmt
*n
= makeNode
(AlterRoleStmt
);
953 n
->options
= list_make1
(makeDefElem
("rolemembers",
959 add_drop: ADD_P
{ $$
= +1; }
964 /*****************************************************************************
966 * Drop a postgresql group
968 * XXX see above notes about cascading DROP USER; groups have same problem.
969 *****************************************************************************/
972 DROP GROUP_P name_list
974 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
975 n
->missing_ok
= FALSE
;
979 | DROP GROUP_P IF_P EXISTS name_list
981 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
982 n
->missing_ok
= TRUE
;
989 /*****************************************************************************
991 * Manipulate a schema
993 *****************************************************************************/
996 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
998 CreateSchemaStmt
*n
= makeNode
(CreateSchemaStmt
);
999 /* One can omit the schema name or the authorization id. */
1008 | CREATE SCHEMA ColId OptSchemaEltList
1010 CreateSchemaStmt
*n
= makeNode
(CreateSchemaStmt
);
1011 /* ...but not both */
1021 |
/* EMPTY */ { $$
= NULL
; }
1025 OptSchemaEltList schema_stmt
{ $$
= lappend
($1, $2); }
1026 |
/* EMPTY */ { $$
= NIL
; }
1030 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1031 * statement (in addition to by themselves).
1043 /*****************************************************************************
1045 * Set PG internal variable
1046 * SET name TO 'var_value'
1047 * Include SQL92 syntax (thomas 1997-10-22):
1048 * SET TIME ZONE 'var_value'
1050 *****************************************************************************/
1055 VariableSetStmt
*n
= $2;
1056 n
->is_local
= false
;
1059 | SET LOCAL set_rest
1061 VariableSetStmt
*n
= $3;
1065 | SET SESSION set_rest
1067 VariableSetStmt
*n
= $3;
1068 n
->is_local
= false
;
1073 set_rest: /* Generic SET syntaxes: */
1074 var_name TO var_list
1076 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1077 n
->kind
= VAR_SET_VALUE
;
1082 | var_name
'=' var_list
1084 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1085 n
->kind
= VAR_SET_VALUE
;
1090 | var_name TO DEFAULT
1092 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1093 n
->kind
= VAR_SET_DEFAULT
;
1097 | var_name
'=' DEFAULT
1099 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1100 n
->kind
= VAR_SET_DEFAULT
;
1104 | var_name FROM CURRENT_P
1106 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1107 n
->kind
= VAR_SET_CURRENT
;
1111 /* Special syntaxes mandated by SQL standard: */
1112 | TIME ZONE zone_value
1114 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1115 n
->kind
= VAR_SET_VALUE
;
1116 n
->name
= "timezone";
1118 n
->args
= list_make1
($3);
1120 n
->kind
= VAR_SET_DEFAULT
;
1123 | TRANSACTION transaction_mode_list
1125 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1126 n
->kind
= VAR_SET_MULTI
;
1127 n
->name
= "TRANSACTION";
1131 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1133 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1134 n
->kind
= VAR_SET_MULTI
;
1135 n
->name
= "SESSION CHARACTERISTICS";
1142 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
1143 errmsg
("current database cannot be changed"),
1144 scanner_errposition
(@
2)));
1145 $$
= NULL
; /*not reached*/
1149 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1150 n
->kind
= VAR_SET_VALUE
;
1151 n
->name
= "search_path";
1152 n
->args
= list_make1
(makeStringConst
($2, @
2));
1155 | NAMES opt_encoding
1157 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1158 n
->kind
= VAR_SET_VALUE
;
1159 n
->name
= "client_encoding";
1161 n
->args
= list_make1
(makeStringConst
($2, @
2));
1163 n
->kind
= VAR_SET_DEFAULT
;
1166 | ROLE ColId_or_Sconst
1168 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1169 n
->kind
= VAR_SET_VALUE
;
1171 n
->args
= list_make1
(makeStringConst
($2, @
2));
1174 | SESSION AUTHORIZATION ColId_or_Sconst
1176 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1177 n
->kind
= VAR_SET_VALUE
;
1178 n
->name
= "session_authorization";
1179 n
->args
= list_make1
(makeStringConst
($3, @
3));
1182 | SESSION AUTHORIZATION DEFAULT
1184 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1185 n
->kind
= VAR_SET_DEFAULT
;
1186 n
->name
= "session_authorization";
1189 | XML_P OPTION document_or_content
1191 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1192 n
->kind
= VAR_SET_VALUE
;
1193 n
->name
= "xmloption";
1194 n
->args
= list_make1
(makeStringConst
($3 == XMLOPTION_DOCUMENT ?
"DOCUMENT" : "CONTENT", @
3));
1199 var_name: ColId
{ $$
= $1; }
1200 | var_name
'.' ColId
1202 $$
= palloc
(strlen
($1) + strlen
($3) + 2);
1203 sprintf
($$
, "%s.%s", $1, $3);
1207 var_list: var_value
{ $$
= list_make1
($1); }
1208 | var_list
',' var_value
{ $$
= lappend
($1, $3); }
1211 var_value: opt_boolean
1212 { $$
= makeStringConst
($1, @
1); }
1214 { $$
= makeStringConst
($1, @
1); }
1216 { $$
= makeAConst
($1, @
1); }
1219 iso_level: READ UNCOMMITTED
{ $$
= "read uncommitted"; }
1220 | READ COMMITTED
{ $$
= "read committed"; }
1221 | REPEATABLE READ
{ $$
= "repeatable read"; }
1222 | SERIALIZABLE
{ $$
= "serializable"; }
1226 TRUE_P
{ $$
= "true"; }
1227 | FALSE_P
{ $$
= "false"; }
1229 | OFF
{ $$
= "off"; }
1232 /* Timezone values can be:
1233 * - a string such as 'pst8pdt'
1234 * - an identifier such as "pst8pdt"
1235 * - an integer or floating point number
1236 * - a time interval per SQL99
1237 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1238 * so use IDENT and reject anything which is a reserved word.
1243 $$
= makeStringConst
($1, @
1);
1247 $$
= makeStringConst
($1, @
1);
1249 | ConstInterval Sconst opt_interval
1254 A_Const
*n
= (A_Const
*) linitial
($3);
1255 if
((n
->val.val.ival
& ~
(INTERVAL_MASK
(HOUR
) | INTERVAL_MASK
(MINUTE
))) != 0)
1257 (errcode
(ERRCODE_SYNTAX_ERROR
),
1258 errmsg
("time zone interval must be HOUR or HOUR TO MINUTE"),
1259 scanner_errposition
(@
3)));
1262 $$
= makeStringConstCast
($2, @
2, t
);
1264 | ConstInterval
'(' Iconst
')' Sconst opt_interval
1269 A_Const
*n
= (A_Const
*) linitial
($6);
1270 if
((n
->val.val.ival
& ~
(INTERVAL_MASK
(HOUR
) | INTERVAL_MASK
(MINUTE
))) != 0)
1272 (errcode
(ERRCODE_SYNTAX_ERROR
),
1273 errmsg
("time zone interval must be HOUR or HOUR TO MINUTE"),
1274 scanner_errposition
(@
6)));
1275 if
(list_length
($6) != 1)
1277 (errcode
(ERRCODE_SYNTAX_ERROR
),
1278 errmsg
("interval precision specified twice"),
1279 scanner_errposition
(@
1)));
1280 t
->typmods
= lappend
($6, makeIntConst
($3, @
3));
1283 t
->typmods
= list_make2
(makeIntConst
(INTERVAL_FULL_RANGE
, -1),
1284 makeIntConst
($3, @
3));
1285 $$
= makeStringConstCast
($5, @
5, t
);
1287 | NumericOnly
{ $$
= makeAConst
($1, @
1); }
1288 | DEFAULT
{ $$
= NULL
; }
1289 | LOCAL
{ $$
= NULL
; }
1294 | DEFAULT
{ $$
= NULL
; }
1295 |
/*EMPTY*/ { $$
= NULL
; }
1300 | Sconst
{ $$
= $1; }
1306 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1307 n
->kind
= VAR_RESET
;
1313 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1314 n
->kind
= VAR_RESET
;
1315 n
->name
= "timezone";
1318 | RESET TRANSACTION ISOLATION LEVEL
1320 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1321 n
->kind
= VAR_RESET
;
1322 n
->name
= "transaction_isolation";
1325 | RESET SESSION AUTHORIZATION
1327 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1328 n
->kind
= VAR_RESET
;
1329 n
->name
= "session_authorization";
1334 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1335 n
->kind
= VAR_RESET_ALL
;
1340 /* SetResetClause allows SET or RESET without LOCAL */
1342 SET set_rest
{ $$
= $2; }
1343 | VariableResetStmt
{ $$
= (VariableSetStmt
*) $1; }
1350 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1356 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1357 n
->name
= "timezone";
1360 | SHOW TRANSACTION ISOLATION LEVEL
1362 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1363 n
->name
= "transaction_isolation";
1366 | SHOW SESSION AUTHORIZATION
1368 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1369 n
->name
= "session_authorization";
1374 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1382 SET CONSTRAINTS constraints_set_list constraints_set_mode
1384 ConstraintsSetStmt
*n
= makeNode
(ConstraintsSetStmt
);
1385 n
->constraints
= $3;
1391 constraints_set_list:
1393 | qualified_name_list
{ $$
= $1; }
1396 constraints_set_mode:
1397 DEFERRED
{ $$
= TRUE
; }
1398 | IMMEDIATE
{ $$
= FALSE
; }
1403 * Checkpoint statement
1408 CheckPointStmt
*n
= makeNode
(CheckPointStmt
);
1414 /*****************************************************************************
1416 * DISCARD { ALL | TEMP | PLANS }
1418 *****************************************************************************/
1423 DiscardStmt
*n
= makeNode
(DiscardStmt
);
1424 n
->target
= DISCARD_ALL
;
1429 DiscardStmt
*n
= makeNode
(DiscardStmt
);
1430 n
->target
= DISCARD_TEMP
;
1435 DiscardStmt
*n
= makeNode
(DiscardStmt
);
1436 n
->target
= DISCARD_TEMP
;
1441 DiscardStmt
*n
= makeNode
(DiscardStmt
);
1442 n
->target
= DISCARD_PLANS
;
1448 /*****************************************************************************
1450 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations
1452 * Note: we accept all subcommands for each of the four variants, and sort
1453 * out what's really legal at execution time.
1454 *****************************************************************************/
1457 ALTER TABLE relation_expr alter_table_cmds
1459 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
1462 n
->relkind
= OBJECT_TABLE
;
1465 | ALTER INDEX relation_expr alter_table_cmds
1467 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
1470 n
->relkind
= OBJECT_INDEX
;
1473 | ALTER SEQUENCE relation_expr alter_table_cmds
1475 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
1478 n
->relkind
= OBJECT_SEQUENCE
;
1481 | ALTER VIEW relation_expr alter_table_cmds
1483 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
1486 n
->relkind
= OBJECT_VIEW
;
1492 alter_table_cmd
{ $$
= list_make1
($1); }
1493 | alter_table_cmds
',' alter_table_cmd
{ $$
= lappend
($1, $3); }
1497 /* ALTER TABLE <name> ADD [COLUMN] <coldef> */
1498 ADD_P opt_column columnDef
1500 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1501 n
->subtype
= AT_AddColumn
;
1505 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1506 | ALTER opt_column ColId alter_column_default
1508 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1509 n
->subtype
= AT_ColumnDefault
;
1514 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1515 | ALTER opt_column ColId DROP NOT NULL_P
1517 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1518 n
->subtype
= AT_DropNotNull
;
1522 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1523 | ALTER opt_column ColId SET NOT NULL_P
1525 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1526 n
->subtype
= AT_SetNotNull
;
1530 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
1531 | ALTER opt_column ColId SET STATISTICS SignedIconst
1533 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1534 n
->subtype
= AT_SetStatistics
;
1536 n
->def
= (Node
*) makeInteger
($6);
1539 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1540 | ALTER opt_column ColId SET STORAGE ColId
1542 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1543 n
->subtype
= AT_SetStorage
;
1545 n
->def
= (Node
*) makeString
($6);
1548 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1549 | DROP opt_column ColId opt_drop_behavior
1551 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1552 n
->subtype
= AT_DropColumn
;
1558 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
1559 * [ USING <expression> ]
1561 | ALTER opt_column ColId opt_set_data TYPE_P Typename alter_using
1563 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1564 n
->subtype
= AT_AlterColumnType
;
1566 n
->def
= (Node
*) $6;
1570 /* ALTER TABLE <name> ADD CONSTRAINT ... */
1571 | ADD_P TableConstraint
1573 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1574 n
->subtype
= AT_AddConstraint
;
1578 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1579 | DROP CONSTRAINT name opt_drop_behavior
1581 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1582 n
->subtype
= AT_DropConstraint
;
1587 /* ALTER TABLE <name> SET WITHOUT OIDS */
1590 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1591 n
->subtype
= AT_DropOids
;
1594 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1597 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1598 n
->subtype
= AT_ClusterOn
;
1602 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1603 | SET WITHOUT CLUSTER
1605 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1606 n
->subtype
= AT_DropCluster
;
1610 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
1611 | ENABLE_P TRIGGER name
1613 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1614 n
->subtype
= AT_EnableTrig
;
1618 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
1619 | ENABLE_P ALWAYS TRIGGER name
1621 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1622 n
->subtype
= AT_EnableAlwaysTrig
;
1626 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
1627 | ENABLE_P REPLICA TRIGGER name
1629 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1630 n
->subtype
= AT_EnableReplicaTrig
;
1634 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
1635 | ENABLE_P TRIGGER ALL
1637 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1638 n
->subtype
= AT_EnableTrigAll
;
1641 /* ALTER TABLE <name> ENABLE TRIGGER USER */
1642 | ENABLE_P TRIGGER USER
1644 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1645 n
->subtype
= AT_EnableTrigUser
;
1648 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
1649 | DISABLE_P TRIGGER name
1651 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1652 n
->subtype
= AT_DisableTrig
;
1656 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
1657 | DISABLE_P TRIGGER ALL
1659 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1660 n
->subtype
= AT_DisableTrigAll
;
1663 /* ALTER TABLE <name> DISABLE TRIGGER USER */
1664 | DISABLE_P TRIGGER USER
1666 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1667 n
->subtype
= AT_DisableTrigUser
;
1670 /* ALTER TABLE <name> ENABLE RULE <rule> */
1671 | ENABLE_P RULE name
1673 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1674 n
->subtype
= AT_EnableRule
;
1678 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
1679 | ENABLE_P ALWAYS RULE name
1681 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1682 n
->subtype
= AT_EnableAlwaysRule
;
1686 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
1687 | ENABLE_P REPLICA RULE name
1689 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1690 n
->subtype
= AT_EnableReplicaRule
;
1694 /* ALTER TABLE <name> DISABLE RULE <rule> */
1695 | DISABLE_P RULE name
1697 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1698 n
->subtype
= AT_DisableRule
;
1702 /* ALTER TABLE <name> INHERIT <parent> */
1703 | INHERIT qualified_name
1705 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1706 n
->subtype
= AT_AddInherit
;
1707 n
->def
= (Node
*) $2;
1710 /* ALTER TABLE <name> NO INHERIT <parent> */
1711 | NO INHERIT qualified_name
1713 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1714 n
->subtype
= AT_DropInherit
;
1715 n
->def
= (Node
*) $3;
1718 /* ALTER TABLE <name> OWNER TO RoleId */
1721 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1722 n
->subtype
= AT_ChangeOwner
;
1726 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1727 | SET TABLESPACE name
1729 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1730 n
->subtype
= AT_SetTableSpace
;
1734 /* ALTER TABLE <name> SET (...) */
1737 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1738 n
->subtype
= AT_SetRelOptions
;
1739 n
->def
= (Node
*)$2;
1742 /* ALTER TABLE <name> RESET (...) */
1745 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1746 n
->subtype
= AT_ResetRelOptions
;
1747 n
->def
= (Node
*)$2;
1752 alter_column_default:
1753 SET DEFAULT a_expr
{ $$
= $3; }
1754 | DROP DEFAULT
{ $$
= NULL
; }
1758 CASCADE
{ $$
= DROP_CASCADE
; }
1759 | RESTRICT
{ $$
= DROP_RESTRICT
; }
1760 |
/* EMPTY */ { $$
= DROP_RESTRICT
; /* default */ }
1764 USING a_expr
{ $$
= $2; }
1765 |
/* EMPTY */ { $$
= NULL
; }
1770 /*****************************************************************************
1773 * close <portalname>
1775 *****************************************************************************/
1780 ClosePortalStmt
*n
= makeNode
(ClosePortalStmt
);
1786 ClosePortalStmt
*n
= makeNode
(ClosePortalStmt
);
1787 n
->portalname
= NULL
;
1793 /*****************************************************************************
1796 * COPY relname ['(' columnList ')'] FROM/TO file [WITH options]
1798 * BINARY, OIDS, and DELIMITERS kept in old locations
1799 * for backward compatibility. 2002-06-18
1801 * COPY ( SELECT ... ) TO file [WITH options]
1802 * This form doesn't have the backwards-compatible option
1805 *****************************************************************************/
1807 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
1808 copy_from copy_file_name copy_delimiter opt_with copy_opt_list
1810 CopyStmt
*n
= makeNode
(CopyStmt
);
1818 /* Concatenate user-supplied flags */
1820 n
->options
= lappend
(n
->options
, $2);
1822 n
->options
= lappend
(n
->options
, $5);
1824 n
->options
= lappend
(n
->options
, $8);
1826 n
->options
= list_concat
(n
->options
, $10);
1829 | COPY select_with_parens TO copy_file_name opt_with
1832 CopyStmt
*n
= makeNode
(CopyStmt
);
1845 | TO
{ $$
= FALSE
; }
1849 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
1850 * used depends on the direction. (It really doesn't make sense to copy from
1851 * stdout. We silently correct the "typo".) - AY 9/94
1855 | STDIN
{ $$
= NULL
; }
1856 | STDOUT
{ $$
= NULL
; }
1862 copy_opt_list copy_opt_item
{ $$
= lappend
($1, $2); }
1863 |
/* EMPTY */ { $$
= NIL
; }
1870 $$
= makeDefElem
("binary", (Node
*)makeInteger
(TRUE
));
1874 $$
= makeDefElem
("oids", (Node
*)makeInteger
(TRUE
));
1876 | DELIMITER opt_as Sconst
1878 $$
= makeDefElem
("delimiter", (Node
*)makeString
($3));
1880 | NULL_P opt_as Sconst
1882 $$
= makeDefElem
("null", (Node
*)makeString
($3));
1886 $$
= makeDefElem
("csv", (Node
*)makeInteger
(TRUE
));
1890 $$
= makeDefElem
("header", (Node
*)makeInteger
(TRUE
));
1892 | QUOTE opt_as Sconst
1894 $$
= makeDefElem
("quote", (Node
*)makeString
($3));
1896 | ESCAPE opt_as Sconst
1898 $$
= makeDefElem
("escape", (Node
*)makeString
($3));
1900 | FORCE QUOTE columnList
1902 $$
= makeDefElem
("force_quote", (Node
*)$3);
1904 | FORCE NOT NULL_P columnList
1906 $$
= makeDefElem
("force_notnull", (Node
*)$4);
1910 /* The following exist for backward compatibility */
1915 $$
= makeDefElem
("binary", (Node
*)makeInteger
(TRUE
));
1917 |
/*EMPTY*/ { $$
= NULL
; }
1923 $$
= makeDefElem
("oids", (Node
*)makeInteger
(TRUE
));
1925 |
/*EMPTY*/ { $$
= NULL
; }
1929 /* USING DELIMITERS kept for backward compatibility. 2002-06-15 */
1930 opt_using DELIMITERS Sconst
1932 $$
= makeDefElem
("delimiter", (Node
*)makeString
($3));
1934 |
/*EMPTY*/ { $$
= NULL
; }
1943 /*****************************************************************************
1946 * CREATE TABLE relname
1948 *****************************************************************************/
1950 CreateStmt: CREATE OptTemp TABLE qualified_name
'(' OptTableElementList
')'
1951 OptInherit OptWith OnCommitOption OptTableSpace
1953 CreateStmt
*n
= makeNode
(CreateStmt
);
1957 n
->inhRelations
= $8;
1958 n
->constraints
= NIL
;
1961 n
->tablespacename
= $11;
1964 | CREATE OptTemp TABLE qualified_name OF qualified_name
1965 '(' OptTableElementList
')' OptWith OnCommitOption OptTableSpace
1967 /* SQL99 CREATE TABLE OF <UDT> (cols) seems to be satisfied
1968 * by our inheritance capabilities. Let's try it...
1970 CreateStmt
*n
= makeNode
(CreateStmt
);
1974 n
->inhRelations
= list_make1
($6);
1975 n
->constraints
= NIL
;
1978 n
->tablespacename
= $12;
1984 * Redundancy here is needed to avoid shift/reduce conflicts,
1985 * since TEMP is not a reserved word. See also OptTempTableName.
1987 * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
1988 * the LOCAL keyword is really meaningless.
1990 OptTemp: TEMPORARY
{ $$
= TRUE
; }
1991 | TEMP
{ $$
= TRUE
; }
1992 | LOCAL TEMPORARY
{ $$
= TRUE
; }
1993 | LOCAL TEMP
{ $$
= TRUE
; }
1994 | GLOBAL TEMPORARY
{ $$
= TRUE
; }
1995 | GLOBAL TEMP
{ $$
= TRUE
; }
1996 |
/*EMPTY*/ { $$
= FALSE
; }
1999 OptTableElementList:
2000 TableElementList
{ $$
= $1; }
2001 |
/*EMPTY*/ { $$
= NIL
; }
2007 $$
= list_make1
($1);
2009 | TableElementList
',' TableElement
2011 $$
= lappend
($1, $3);
2016 columnDef
{ $$
= $1; }
2017 | TableLikeClause
{ $$
= $1; }
2018 | TableConstraint
{ $$
= $1; }
2021 columnDef: ColId Typename ColQualList
2023 ColumnDef
*n
= makeNode
(ColumnDef
);
2026 n
->constraints
= $3;
2033 ColQualList ColConstraint
{ $$
= lappend
($1, $2); }
2034 |
/*EMPTY*/ { $$
= NIL
; }
2038 CONSTRAINT name ColConstraintElem
2040 switch
(nodeTag
($3))
2044 Constraint
*n
= (Constraint
*)$3;
2048 case T_FkConstraint
:
2050 FkConstraint
*n
= (FkConstraint
*)$3;
2051 n
->constr_name
= $2;
2059 | ColConstraintElem
{ $$
= $1; }
2060 | ConstraintAttr
{ $$
= $1; }
2063 /* DEFAULT NULL is already the default for Postgres.
2064 * But define it here and carry it forward into the system
2065 * to make it explicit.
2066 * - thomas 1998-09-13
2068 * WITH NULL and NULL are not SQL92-standard syntax elements,
2069 * so leave them out. Use DEFAULT NULL to explicitly indicate
2070 * that a column may have that value. WITH NULL leads to
2071 * shift/reduce conflicts with WITH TIME ZONE anyway.
2072 * - thomas 1999-01-08
2074 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
2075 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
2076 * or be part of a_expr NOT LIKE or similar constructs).
2081 Constraint
*n
= makeNode
(Constraint
);
2082 n
->contype
= CONSTR_NOTNULL
;
2085 n
->cooked_expr
= NULL
;
2087 n
->indexspace
= NULL
;
2092 Constraint
*n
= makeNode
(Constraint
);
2093 n
->contype
= CONSTR_NULL
;
2096 n
->cooked_expr
= NULL
;
2098 n
->indexspace
= NULL
;
2101 | UNIQUE opt_definition OptConsTableSpace
2103 Constraint
*n
= makeNode
(Constraint
);
2104 n
->contype
= CONSTR_UNIQUE
;
2107 n
->cooked_expr
= NULL
;
2113 | PRIMARY KEY opt_definition OptConsTableSpace
2115 Constraint
*n
= makeNode
(Constraint
);
2116 n
->contype
= CONSTR_PRIMARY
;
2119 n
->cooked_expr
= NULL
;
2125 | CHECK
'(' a_expr
')'
2127 Constraint
*n
= makeNode
(Constraint
);
2128 n
->contype
= CONSTR_CHECK
;
2131 n
->cooked_expr
= NULL
;
2133 n
->indexspace
= NULL
;
2138 Constraint
*n
= makeNode
(Constraint
);
2139 n
->contype
= CONSTR_DEFAULT
;
2142 n
->cooked_expr
= NULL
;
2144 n
->indexspace
= NULL
;
2147 | REFERENCES qualified_name opt_column_list key_match key_actions
2149 FkConstraint
*n
= makeNode
(FkConstraint
);
2150 n
->constr_name
= NULL
;
2154 n
->fk_matchtype
= $4;
2155 n
->fk_upd_action
= (char) ($5 >> 8);
2156 n
->fk_del_action
= (char) ($5 & 0xFF);
2157 n
->deferrable
= FALSE
;
2158 n
->initdeferred
= FALSE
;
2164 * ConstraintAttr represents constraint attributes, which we parse as if
2165 * they were independent constraint clauses, in order to avoid shift/reduce
2166 * conflicts (since NOT might start either an independent NOT NULL clause
2167 * or an attribute). parse_utilcmd.c is responsible for attaching the
2168 * attribute information to the preceding "real" constraint node, and for
2169 * complaining if attribute clauses appear in the wrong place or wrong
2172 * See also ConstraintAttributeSpec, which can be used in places where
2173 * there is no parsing conflict.
2178 Constraint
*n
= makeNode
(Constraint
);
2179 n
->contype
= CONSTR_ATTR_DEFERRABLE
;
2184 Constraint
*n
= makeNode
(Constraint
);
2185 n
->contype
= CONSTR_ATTR_NOT_DEFERRABLE
;
2188 | INITIALLY DEFERRED
2190 Constraint
*n
= makeNode
(Constraint
);
2191 n
->contype
= CONSTR_ATTR_DEFERRED
;
2194 | INITIALLY IMMEDIATE
2196 Constraint
*n
= makeNode
(Constraint
);
2197 n
->contype
= CONSTR_ATTR_IMMEDIATE
;
2204 * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2205 * This seems to be a poor man's inheritance capability, with the resulting
2206 * tables completely decoupled except for the original commonality in definitions.
2208 * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2209 * which is a part of SQL:2003.
2212 LIKE qualified_name TableLikeOptionList
2214 InhRelation
*n
= makeNode
(InhRelation
);
2221 TableLikeOptionList:
2222 TableLikeOptionList TableLikeOption
{ $$
= lappend_int
($1, $2); }
2223 |
/* EMPTY */ { $$
= NIL
; }
2227 INCLUDING DEFAULTS
{ $$
= CREATE_TABLE_LIKE_INCLUDING_DEFAULTS
; }
2228 | EXCLUDING DEFAULTS
{ $$
= CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS
; }
2229 | INCLUDING CONSTRAINTS
{ $$
= CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS
; }
2230 | EXCLUDING CONSTRAINTS
{ $$
= CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS
; }
2231 | INCLUDING INDEXES
{ $$
= CREATE_TABLE_LIKE_INCLUDING_INDEXES
; }
2232 | EXCLUDING INDEXES
{ $$
= CREATE_TABLE_LIKE_EXCLUDING_INDEXES
; }
2236 /* ConstraintElem specifies constraint syntax which is not embedded into
2237 * a column definition. ColConstraintElem specifies the embedded form.
2238 * - thomas 1997-12-03
2241 CONSTRAINT name ConstraintElem
2243 switch
(nodeTag
($3))
2247 Constraint
*n
= (Constraint
*)$3;
2251 case T_FkConstraint
:
2253 FkConstraint
*n
= (FkConstraint
*)$3;
2254 n
->constr_name
= $2;
2262 | ConstraintElem
{ $$
= $1; }
2266 CHECK
'(' a_expr
')'
2268 Constraint
*n
= makeNode
(Constraint
);
2269 n
->contype
= CONSTR_CHECK
;
2272 n
->cooked_expr
= NULL
;
2273 n
->indexspace
= NULL
;
2276 | UNIQUE
'(' columnList
')' opt_definition OptConsTableSpace
2278 Constraint
*n
= makeNode
(Constraint
);
2279 n
->contype
= CONSTR_UNIQUE
;
2282 n
->cooked_expr
= NULL
;
2288 | PRIMARY KEY
'(' columnList
')' opt_definition OptConsTableSpace
2290 Constraint
*n
= makeNode
(Constraint
);
2291 n
->contype
= CONSTR_PRIMARY
;
2294 n
->cooked_expr
= NULL
;
2300 | FOREIGN KEY
'(' columnList
')' REFERENCES qualified_name
2301 opt_column_list key_match key_actions ConstraintAttributeSpec
2303 FkConstraint
*n
= makeNode
(FkConstraint
);
2304 n
->constr_name
= NULL
;
2308 n
->fk_matchtype
= $9;
2309 n
->fk_upd_action
= (char) ($10 >> 8);
2310 n
->fk_del_action
= (char) ($10 & 0xFF);
2311 n
->deferrable
= ($11 & 1) != 0;
2312 n
->initdeferred
= ($11 & 2) != 0;
2318 '(' columnList
')' { $$
= $2; }
2319 |
/*EMPTY*/ { $$
= NIL
; }
2323 columnElem
{ $$
= list_make1
($1); }
2324 | columnList
',' columnElem
{ $$
= lappend
($1, $3); }
2329 $$
= (Node
*) makeString
($1);
2333 key_match: MATCH FULL
2335 $$
= FKCONSTR_MATCH_FULL
;
2340 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
2341 errmsg
("MATCH PARTIAL not yet implemented"),
2342 scanner_errposition
(@
1)));
2343 $$
= FKCONSTR_MATCH_PARTIAL
;
2347 $$
= FKCONSTR_MATCH_UNSPECIFIED
;
2351 $$
= FKCONSTR_MATCH_UNSPECIFIED
;
2356 * We combine the update and delete actions into one value temporarily
2357 * for simplicity of parsing, and then break them down again in the
2358 * calling production. update is in the left 8 bits, delete in the right.
2359 * Note that NOACTION is the default.
2363 { $$
= ($1 << 8) |
(FKCONSTR_ACTION_NOACTION
& 0xFF); }
2365 { $$
= (FKCONSTR_ACTION_NOACTION
<< 8) |
($1 & 0xFF); }
2366 | key_update key_delete
2367 { $$
= ($1 << 8) |
($2 & 0xFF); }
2368 | key_delete key_update
2369 { $$
= ($2 << 8) |
($1 & 0xFF); }
2371 { $$
= (FKCONSTR_ACTION_NOACTION
<< 8) |
(FKCONSTR_ACTION_NOACTION
& 0xFF); }
2374 key_update: ON UPDATE key_action
{ $$
= $3; }
2377 key_delete: ON DELETE_P key_action
{ $$
= $3; }
2381 NO ACTION
{ $$
= FKCONSTR_ACTION_NOACTION
; }
2382 | RESTRICT
{ $$
= FKCONSTR_ACTION_RESTRICT
; }
2383 | CASCADE
{ $$
= FKCONSTR_ACTION_CASCADE
; }
2384 | SET NULL_P
{ $$
= FKCONSTR_ACTION_SETNULL
; }
2385 | SET DEFAULT
{ $$
= FKCONSTR_ACTION_SETDEFAULT
; }
2388 OptInherit: INHERITS
'(' qualified_name_list
')' { $$
= $3; }
2389 |
/*EMPTY*/ { $$
= NIL
; }
2392 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
2394 WITH definition
{ $$
= $2; }
2395 | WITH OIDS
{ $$
= list_make1
(defWithOids
(true
)); }
2396 | WITHOUT OIDS
{ $$
= list_make1
(defWithOids
(false
)); }
2397 |
/*EMPTY*/ { $$
= NIL
; }
2400 OnCommitOption: ON COMMIT DROP
{ $$
= ONCOMMIT_DROP
; }
2401 | ON COMMIT DELETE_P ROWS
{ $$
= ONCOMMIT_DELETE_ROWS
; }
2402 | ON COMMIT PRESERVE ROWS
{ $$
= ONCOMMIT_PRESERVE_ROWS
; }
2403 |
/*EMPTY*/ { $$
= ONCOMMIT_NOOP
; }
2406 OptTableSpace: TABLESPACE name
{ $$
= $2; }
2407 |
/*EMPTY*/ { $$
= NULL
; }
2410 OptConsTableSpace: USING INDEX TABLESPACE name
{ $$
= $4; }
2411 |
/*EMPTY*/ { $$
= NULL
; }
2416 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
2421 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
2424 * When the SelectStmt is a set-operation tree, we must
2425 * stuff the INTO information into the leftmost component
2426 * Select, because that's where analyze.c will expect
2427 * to find it. Similarly, the output column names must
2428 * be attached to that Select's target list.
2430 SelectStmt
*n
= findLeftmostSelect
((SelectStmt
*) $6);
2431 if
(n
->intoClause
!= NULL
)
2433 (errcode
(ERRCODE_SYNTAX_ERROR
),
2434 errmsg
("CREATE TABLE AS cannot specify INTO"),
2435 scanner_errposition
(exprLocation
((Node
*) n
->intoClause
))));
2436 $4->rel
->istemp
= $2;
2438 /* Implement WITH NO DATA by forcing top-level LIMIT 0 */
2440 ((SelectStmt
*) $6)->limitCount
= makeIntConst
(0, -1);
2446 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
2448 $$
= makeNode
(IntoClause
);
2453 $$
->tableSpaceName
= $5;
2458 '(' CreateAsList
')' { $$
= $2; }
2459 |
/*EMPTY*/ { $$
= NIL
; }
2463 CreateAsElement
{ $$
= list_make1
($1); }
2464 | CreateAsList
',' CreateAsElement
{ $$
= lappend
($1, $3); }
2470 ColumnDef
*n
= makeNode
(ColumnDef
);
2475 n
->is_not_null
= false
;
2476 n
->raw_default
= NULL
;
2477 n
->cooked_default
= NULL
;
2478 n
->constraints
= NIL
;
2484 WITH DATA_P
{ $$
= TRUE
; }
2485 | WITH NO DATA_P
{ $$
= FALSE
; }
2486 |
/*EMPTY*/ { $$
= TRUE
; }
2490 /*****************************************************************************
2493 * CREATE SEQUENCE seqname
2494 * ALTER SEQUENCE seqname
2496 *****************************************************************************/
2499 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
2501 CreateSeqStmt
*n
= makeNode
(CreateSeqStmt
);
2510 ALTER SEQUENCE relation_expr SeqOptList
2512 AlterSeqStmt
*n
= makeNode
(AlterSeqStmt
);
2519 OptSeqOptList: SeqOptList
{ $$
= $1; }
2520 |
/*EMPTY*/ { $$
= NIL
; }
2523 SeqOptList: SeqOptElem
{ $$
= list_make1
($1); }
2524 | SeqOptList SeqOptElem
{ $$
= lappend
($1, $2); }
2527 SeqOptElem: CACHE NumericOnly
2529 $$
= makeDefElem
("cache", (Node
*)$2);
2533 $$
= makeDefElem
("cycle", (Node
*)makeInteger
(TRUE
));
2537 $$
= makeDefElem
("cycle", (Node
*)makeInteger
(FALSE
));
2539 | INCREMENT opt_by NumericOnly
2541 $$
= makeDefElem
("increment", (Node
*)$3);
2543 | MAXVALUE NumericOnly
2545 $$
= makeDefElem
("maxvalue", (Node
*)$2);
2547 | MINVALUE NumericOnly
2549 $$
= makeDefElem
("minvalue", (Node
*)$2);
2553 $$
= makeDefElem
("maxvalue", NULL
);
2557 $$
= makeDefElem
("minvalue", NULL
);
2561 $$
= makeDefElem
("owned_by", (Node
*)$3);
2563 | START opt_with NumericOnly
2565 $$
= makeDefElem
("start", (Node
*)$3);
2569 $$
= makeDefElem
("restart", NULL
);
2571 | RESTART opt_with NumericOnly
2573 $$
= makeDefElem
("restart", (Node
*)$3);
2582 FCONST
{ $$
= makeFloat
($1); }
2588 | SignedIconst
{ $$
= makeInteger
($1); };
2591 /*****************************************************************************
2594 * CREATE PROCEDURAL LANGUAGE ...
2595 * DROP PROCEDURAL LANGUAGE ...
2597 *****************************************************************************/
2600 CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2602 CreatePLangStmt
*n
= makeNode
(CreatePLangStmt
);
2604 /* parameters are all to be supplied by system */
2606 n
->plvalidator
= NIL
;
2607 n
->pltrusted
= false
;
2610 | CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2611 HANDLER handler_name opt_validator opt_lancompiler
2613 CreatePLangStmt
*n
= makeNode
(CreatePLangStmt
);
2616 n
->plvalidator
= $8;
2618 /* LANCOMPILER is now ignored entirely */
2624 TRUSTED
{ $$
= TRUE
; }
2625 |
/*EMPTY*/ { $$
= FALSE
; }
2628 /* This ought to be just func_name, but that causes reduce/reduce conflicts
2629 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
2630 * Work around by using simple names, instead.
2633 name
{ $$
= list_make1
(makeString
($1)); }
2634 | name attrs
{ $$
= lcons
(makeString
($1), $2); }
2638 VALIDATOR handler_name
{ $$
= $2; }
2639 |
/*EMPTY*/ { $$
= NIL
; }
2643 LANCOMPILER Sconst
{ $$
= $2; }
2644 |
/*EMPTY*/ { $$
= NULL
; }
2648 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
2650 DropPLangStmt
*n
= makeNode
(DropPLangStmt
);
2653 n
->missing_ok
= false
;
2656 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
2658 DropPLangStmt
*n
= makeNode
(DropPLangStmt
);
2661 n
->missing_ok
= true
;
2671 /*****************************************************************************
2674 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
2676 *****************************************************************************/
2678 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
2680 CreateTableSpaceStmt
*n
= makeNode
(CreateTableSpaceStmt
);
2681 n
->tablespacename
= $3;
2688 OptTableSpaceOwner: OWNER name
{ $$
= $2; }
2689 |
/*EMPTY */ { $$
= NULL
; }
2692 /*****************************************************************************
2695 * DROP TABLESPACE <tablespace>
2697 * No need for drop behaviour as we cannot implement dependencies for
2698 * objects in other databases; we can only support RESTRICT.
2700 ****************************************************************************/
2702 DropTableSpaceStmt: DROP TABLESPACE name
2704 DropTableSpaceStmt
*n
= makeNode
(DropTableSpaceStmt
);
2705 n
->tablespacename
= $3;
2706 n
->missing_ok
= false
;
2709 | DROP TABLESPACE IF_P EXISTS name
2711 DropTableSpaceStmt
*n
= makeNode
(DropTableSpaceStmt
);
2712 n
->tablespacename
= $5;
2713 n
->missing_ok
= true
;
2718 /*****************************************************************************
2721 * CREATE TRIGGER ...
2724 *****************************************************************************/
2727 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
2728 qualified_name TriggerForSpec EXECUTE PROCEDURE
2729 func_name
'(' TriggerFuncArgs
')'
2731 CreateTrigStmt
*n
= makeNode
(CreateTrigStmt
);
2738 memcpy
(n
->actions
, $5, 4);
2739 n
->isconstraint
= FALSE
;
2740 n
->deferrable
= FALSE
;
2741 n
->initdeferred
= FALSE
;
2742 n
->constrrel
= NULL
;
2745 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
2746 qualified_name OptConstrFromTable
2747 ConstraintAttributeSpec
2748 FOR EACH ROW EXECUTE PROCEDURE
2749 func_name
'(' TriggerFuncArgs
')'
2751 CreateTrigStmt
*n
= makeNode
(CreateTrigStmt
);
2758 memcpy
(n
->actions
, $6, 4);
2759 n
->isconstraint
= TRUE
;
2760 n
->deferrable
= ($10 & 1) != 0;
2761 n
->initdeferred
= ($10 & 2) != 0;
2769 BEFORE
{ $$
= TRUE
; }
2770 | AFTER
{ $$
= FALSE
; }
2776 char *e
= palloc
(4);
2777 e
[0] = $1; e
[1] = '\0';
2780 | TriggerOneEvent OR TriggerOneEvent
2782 char *e
= palloc
(4);
2783 e
[0] = $1; e
[1] = $3; e
[2] = '\0';
2786 | TriggerOneEvent OR TriggerOneEvent OR TriggerOneEvent
2788 char *e
= palloc
(4);
2789 e
[0] = $1; e
[1] = $3; e
[2] = $5; e
[3] = '\0';
2795 INSERT
{ $$
= 'i'; }
2796 | DELETE_P
{ $$
= 'd'; }
2797 | UPDATE
{ $$
= 'u'; }
2798 | TRUNCATE
{ $$
= 't'; }
2802 FOR TriggerForOpt TriggerForType
2809 * If ROW/STATEMENT not specified, default to
2810 * STATEMENT, per SQL
2823 | STATEMENT
{ $$
= FALSE
; }
2827 TriggerFuncArg
{ $$
= list_make1
($1); }
2828 | TriggerFuncArgs
',' TriggerFuncArg
{ $$
= lappend
($1, $3); }
2829 |
/*EMPTY*/ { $$
= NIL
; }
2836 snprintf
(buf
, sizeof
(buf
), "%d", $1);
2837 $$
= makeString
(pstrdup
(buf
));
2839 | FCONST
{ $$
= makeString
($1); }
2840 | Sconst
{ $$
= makeString
($1); }
2841 | BCONST
{ $$
= makeString
($1); }
2842 | XCONST
{ $$
= makeString
($1); }
2843 | ColId
{ $$
= makeString
($1); }
2847 FROM qualified_name
{ $$
= $2; }
2848 |
/*EMPTY*/ { $$
= NULL
; }
2851 ConstraintAttributeSpec:
2852 ConstraintDeferrabilitySpec
2854 | ConstraintDeferrabilitySpec ConstraintTimeSpec
2856 if
($1 == 0 && $2 != 0)
2858 (errcode
(ERRCODE_SYNTAX_ERROR
),
2859 errmsg
("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
2860 scanner_errposition
(@
1)));
2863 | ConstraintTimeSpec
2870 | ConstraintTimeSpec ConstraintDeferrabilitySpec
2872 if
($2 == 0 && $1 != 0)
2874 (errcode
(ERRCODE_SYNTAX_ERROR
),
2875 errmsg
("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
2876 scanner_errposition
(@
1)));
2883 ConstraintDeferrabilitySpec:
2884 NOT DEFERRABLE
{ $$
= 0; }
2885 | DEFERRABLE
{ $$
= 1; }
2889 INITIALLY IMMEDIATE
{ $$
= 0; }
2890 | INITIALLY DEFERRED
{ $$
= 2; }
2895 DROP TRIGGER name ON qualified_name opt_drop_behavior
2897 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
2901 n
->removeType
= OBJECT_TRIGGER
;
2902 n
->missing_ok
= false
;
2905 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
2907 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
2911 n
->removeType
= OBJECT_TRIGGER
;
2912 n
->missing_ok
= true
;
2918 /*****************************************************************************
2921 * CREATE ASSERTION ...
2922 * DROP ASSERTION ...
2924 *****************************************************************************/
2927 CREATE ASSERTION name CHECK
'(' a_expr
')'
2928 ConstraintAttributeSpec
2930 CreateTrigStmt
*n
= makeNode
(CreateTrigStmt
);
2932 n
->args
= list_make1
($6);
2933 n
->isconstraint
= TRUE
;
2934 n
->deferrable
= ($8 & 1) != 0;
2935 n
->initdeferred
= ($8 & 2) != 0;
2938 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
2939 errmsg
("CREATE ASSERTION is not yet implemented")));
2946 DROP ASSERTION name opt_drop_behavior
2948 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
2952 n
->removeType
= OBJECT_TRIGGER
; /* XXX */
2954 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
2955 errmsg
("DROP ASSERTION is not yet implemented")));
2961 /*****************************************************************************
2964 * define (aggregate,operator,type)
2966 *****************************************************************************/
2969 CREATE AGGREGATE func_name aggr_args definition
2971 DefineStmt
*n
= makeNode
(DefineStmt
);
2972 n
->kind
= OBJECT_AGGREGATE
;
2973 n
->oldstyle
= false
;
2979 | CREATE AGGREGATE func_name old_aggr_definition
2981 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
2982 DefineStmt
*n
= makeNode
(DefineStmt
);
2983 n
->kind
= OBJECT_AGGREGATE
;
2990 | CREATE OPERATOR any_operator definition
2992 DefineStmt
*n
= makeNode
(DefineStmt
);
2993 n
->kind
= OBJECT_OPERATOR
;
2994 n
->oldstyle
= false
;
3000 | CREATE TYPE_P any_name definition
3002 DefineStmt
*n
= makeNode
(DefineStmt
);
3003 n
->kind
= OBJECT_TYPE
;
3004 n
->oldstyle
= false
;
3010 | CREATE TYPE_P any_name
3012 /* Shell type (identified by lack of definition) */
3013 DefineStmt
*n
= makeNode
(DefineStmt
);
3014 n
->kind
= OBJECT_TYPE
;
3015 n
->oldstyle
= false
;
3018 n
->definition
= NIL
;
3021 | CREATE TYPE_P any_name AS
'(' TableFuncElementList
')'
3023 CompositeTypeStmt
*n
= makeNode
(CompositeTypeStmt
);
3024 RangeVar
*r
= makeNode
(RangeVar
);
3026 /* can't use qualified_name, sigh */
3027 switch
(list_length
($3))
3030 r
->catalogname
= NULL
;
3031 r
->schemaname
= NULL
;
3032 r
->relname
= strVal
(linitial
($3));
3035 r
->catalogname
= NULL
;
3036 r
->schemaname
= strVal
(linitial
($3));
3037 r
->relname
= strVal
(lsecond
($3));
3040 r
->catalogname
= strVal
(linitial
($3));
3041 r
->schemaname
= strVal
(lsecond
($3));
3042 r
->relname
= strVal
(lthird
($3));
3046 (errcode
(ERRCODE_SYNTAX_ERROR
),
3047 errmsg
("improper qualified name (too many dotted names): %s",
3048 NameListToString
($3)),
3049 scanner_errposition
(@
3)));
3057 | CREATE TYPE_P any_name AS ENUM_P
'(' enum_val_list
')'
3059 CreateEnumStmt
*n
= makeNode
(CreateEnumStmt
);
3064 | CREATE TEXT_P SEARCH PARSER any_name definition
3066 DefineStmt
*n
= makeNode
(DefineStmt
);
3067 n
->kind
= OBJECT_TSPARSER
;
3073 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
3075 DefineStmt
*n
= makeNode
(DefineStmt
);
3076 n
->kind
= OBJECT_TSDICTIONARY
;
3082 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
3084 DefineStmt
*n
= makeNode
(DefineStmt
);
3085 n
->kind
= OBJECT_TSTEMPLATE
;
3091 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
3093 DefineStmt
*n
= makeNode
(DefineStmt
);
3094 n
->kind
= OBJECT_TSCONFIGURATION
;
3102 definition: '(' def_list
')' { $$
= $2; }
3105 def_list: def_elem
{ $$
= list_make1
($1); }
3106 | def_list
',' def_elem
{ $$
= lappend
($1, $3); }
3109 def_elem: ColLabel
'=' def_arg
3111 $$
= makeDefElem
($1, (Node
*)$3);
3115 $$
= makeDefElem
($1, NULL
);
3119 /* Note: any simple identifier will be returned as a type name! */
3120 def_arg: func_type
{ $$
= (Node
*)$1; }
3121 | reserved_keyword
{ $$
= (Node
*)makeString
(pstrdup
($1)); }
3122 | qual_all_Op
{ $$
= (Node
*)$1; }
3123 | NumericOnly
{ $$
= (Node
*)$1; }
3124 | Sconst
{ $$
= (Node
*)makeString
($1); }
3127 aggr_args: '(' type_list
')' { $$
= $2; }
3128 |
'(' '*' ')' { $$
= NIL
; }
3131 old_aggr_definition: '(' old_aggr_list
')' { $$
= $2; }
3134 old_aggr_list: old_aggr_elem
{ $$
= list_make1
($1); }
3135 | old_aggr_list
',' old_aggr_elem
{ $$
= lappend
($1, $3); }
3138 old_aggr_elem: IDENT
'=' def_arg
3140 $$
= makeDefElem
($1, (Node
*)$3);
3144 enum_val_list: Sconst
3145 { $$
= list_make1
(makeString
($1)); }
3146 | enum_val_list
',' Sconst
3147 { $$
= lappend
($1, makeString
($3)); }
3151 /*****************************************************************************
3154 * CREATE OPERATOR CLASS ...
3155 * CREATE OPERATOR FAMILY ...
3156 * ALTER OPERATOR FAMILY ...
3157 * DROP OPERATOR CLASS ...
3158 * DROP OPERATOR FAMILY ...
3160 *****************************************************************************/
3163 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
3164 USING access_method opt_opfamily AS opclass_item_list
3166 CreateOpClassStmt
*n
= makeNode
(CreateOpClassStmt
);
3167 n
->opclassname
= $4;
3171 n
->opfamilyname
= $11;
3178 opclass_item
{ $$
= list_make1
($1); }
3179 | opclass_item_list
',' opclass_item
{ $$
= lappend
($1, $3); }
3183 OPERATOR Iconst any_operator opt_recheck
3185 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3186 n
->itemtype
= OPCLASS_ITEM_OPERATOR
;
3192 | OPERATOR Iconst any_operator oper_argtypes opt_recheck
3194 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3195 n
->itemtype
= OPCLASS_ITEM_OPERATOR
;
3201 | FUNCTION Iconst func_name func_args
3203 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3204 n
->itemtype
= OPCLASS_ITEM_FUNCTION
;
3206 n
->args
= extractArgTypes
($4);
3210 | FUNCTION Iconst
'(' type_list
')' func_name func_args
3212 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3213 n
->itemtype
= OPCLASS_ITEM_FUNCTION
;
3215 n
->args
= extractArgTypes
($7);
3222 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3223 n
->itemtype
= OPCLASS_ITEM_STORAGETYPE
;
3229 opt_default: DEFAULT
{ $$
= TRUE
; }
3230 |
/*EMPTY*/ { $$
= FALSE
; }
3233 opt_opfamily: FAMILY any_name
{ $$
= $2; }
3234 |
/*EMPTY*/ { $$
= NIL
; }
3237 opt_recheck: RECHECK
3240 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
3241 errmsg
("RECHECK is no longer supported"),
3242 errhint
("Update your data type."),
3243 scanner_errposition
(@
1)));
3246 |
/*EMPTY*/ { $$
= FALSE
; }
3251 CREATE OPERATOR FAMILY any_name USING access_method
3253 CreateOpFamilyStmt
*n
= makeNode
(CreateOpFamilyStmt
);
3254 n
->opfamilyname
= $4;
3261 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
3263 AlterOpFamilyStmt
*n
= makeNode
(AlterOpFamilyStmt
);
3264 n
->opfamilyname
= $4;
3270 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
3272 AlterOpFamilyStmt
*n
= makeNode
(AlterOpFamilyStmt
);
3273 n
->opfamilyname
= $4;
3282 opclass_drop
{ $$
= list_make1
($1); }
3283 | opclass_drop_list
',' opclass_drop
{ $$
= lappend
($1, $3); }
3287 OPERATOR Iconst
'(' type_list
')'
3289 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3290 n
->itemtype
= OPCLASS_ITEM_OPERATOR
;
3295 | FUNCTION Iconst
'(' type_list
')'
3297 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3298 n
->itemtype
= OPCLASS_ITEM_FUNCTION
;
3307 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
3309 RemoveOpClassStmt
*n
= makeNode
(RemoveOpClassStmt
);
3310 n
->opclassname
= $4;
3313 n
->missing_ok
= false
;
3316 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
3318 RemoveOpClassStmt
*n
= makeNode
(RemoveOpClassStmt
);
3319 n
->opclassname
= $6;
3322 n
->missing_ok
= true
;
3328 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
3330 RemoveOpFamilyStmt
*n
= makeNode
(RemoveOpFamilyStmt
);
3331 n
->opfamilyname
= $4;
3334 n
->missing_ok
= false
;
3337 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
3339 RemoveOpFamilyStmt
*n
= makeNode
(RemoveOpFamilyStmt
);
3340 n
->opfamilyname
= $6;
3343 n
->missing_ok
= true
;
3349 /*****************************************************************************
3353 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
3354 * REASSIGN OWNED BY username [, username ...] TO username
3356 *****************************************************************************/
3358 DROP OWNED BY name_list opt_drop_behavior
3360 DropOwnedStmt
*n
= makeNode
(DropOwnedStmt
);
3368 REASSIGN OWNED BY name_list TO name
3370 ReassignOwnedStmt
*n
= makeNode
(ReassignOwnedStmt
);
3377 /*****************************************************************************
3381 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
3382 * [ RESTRICT | CASCADE ]
3384 *****************************************************************************/
3386 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
3388 DropStmt
*n
= makeNode
(DropStmt
);
3390 n
->missing_ok
= TRUE
;
3395 | DROP drop_type any_name_list opt_drop_behavior
3397 DropStmt
*n
= makeNode
(DropStmt
);
3399 n
->missing_ok
= FALSE
;
3407 drop_type: TABLE
{ $$
= OBJECT_TABLE
; }
3408 | SEQUENCE
{ $$
= OBJECT_SEQUENCE
; }
3409 | VIEW
{ $$
= OBJECT_VIEW
; }
3410 | INDEX
{ $$
= OBJECT_INDEX
; }
3411 | TYPE_P
{ $$
= OBJECT_TYPE
; }
3412 | DOMAIN_P
{ $$
= OBJECT_DOMAIN
; }
3413 | CONVERSION_P
{ $$
= OBJECT_CONVERSION
; }
3414 | SCHEMA
{ $$
= OBJECT_SCHEMA
; }
3415 | TEXT_P SEARCH PARSER
{ $$
= OBJECT_TSPARSER
; }
3416 | TEXT_P SEARCH DICTIONARY
{ $$
= OBJECT_TSDICTIONARY
; }
3417 | TEXT_P SEARCH TEMPLATE
{ $$
= OBJECT_TSTEMPLATE
; }
3418 | TEXT_P SEARCH CONFIGURATION
{ $$
= OBJECT_TSCONFIGURATION
; }
3422 any_name
{ $$
= list_make1
($1); }
3423 | any_name_list
',' any_name
{ $$
= lappend
($1, $3); }
3426 any_name: ColId
{ $$
= list_make1
(makeString
($1)); }
3427 | ColId attrs
{ $$
= lcons
(makeString
($1), $2); }
3430 attrs: '.' attr_name
3431 { $$
= list_make1
(makeString
($2)); }
3432 | attrs
'.' attr_name
3433 { $$
= lappend
($1, makeString
($3)); }
3437 /*****************************************************************************
3440 * truncate table relname1, relname2, ...
3442 *****************************************************************************/
3445 TRUNCATE opt_table qualified_name_list opt_restart_seqs opt_drop_behavior
3447 TruncateStmt
*n
= makeNode
(TruncateStmt
);
3449 n
->restart_seqs
= $4;
3456 CONTINUE_P IDENTITY_P
{ $$
= false
; }
3457 | RESTART IDENTITY_P
{ $$
= true
; }
3458 |
/* EMPTY */ { $$
= false
; }
3461 /*****************************************************************************
3463 * The COMMENT ON statement can take different forms based upon the type of
3464 * the object associated with the comment. The form of the statement is:
3466 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
3467 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
3468 * CAST | COLUMN | SCHEMA | TABLESPACE | ROLE |
3469 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
3470 * TEXT SEARCH TEMPLATE |
3471 * TEXT SEARCH CONFIGURATION ] <objname> |
3472 * AGGREGATE <aggname> (arg1, ...) |
3473 * FUNCTION <funcname> (arg1, arg2, ...) |
3474 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
3475 * TRIGGER <triggername> ON <relname> |
3476 * CONSTRAINT <constraintname> ON <relname> |
3477 * RULE <rulename> ON <relname> ]
3480 *****************************************************************************/
3483 COMMENT ON comment_type any_name IS comment_text
3485 CommentStmt
*n
= makeNode
(CommentStmt
);
3492 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
3494 CommentStmt
*n
= makeNode
(CommentStmt
);
3495 n
->objtype
= OBJECT_AGGREGATE
;
3501 | COMMENT ON FUNCTION func_name func_args IS comment_text
3503 CommentStmt
*n
= makeNode
(CommentStmt
);
3504 n
->objtype
= OBJECT_FUNCTION
;
3506 n
->objargs
= extractArgTypes
($5);
3510 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
3512 CommentStmt
*n
= makeNode
(CommentStmt
);
3513 n
->objtype
= OBJECT_OPERATOR
;
3519 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
3521 CommentStmt
*n
= makeNode
(CommentStmt
);
3522 n
->objtype
= OBJECT_CONSTRAINT
;
3523 n
->objname
= lappend
($6, makeString
($4));
3528 | COMMENT ON RULE name ON any_name IS comment_text
3530 CommentStmt
*n
= makeNode
(CommentStmt
);
3531 n
->objtype
= OBJECT_RULE
;
3532 n
->objname
= lappend
($6, makeString
($4));
3537 | COMMENT ON RULE name IS comment_text
3539 /* Obsolete syntax supported for awhile for compatibility */
3540 CommentStmt
*n
= makeNode
(CommentStmt
);
3541 n
->objtype
= OBJECT_RULE
;
3542 n
->objname
= list_make1
(makeString
($4));
3547 | COMMENT ON TRIGGER name ON any_name IS comment_text
3549 CommentStmt
*n
= makeNode
(CommentStmt
);
3550 n
->objtype
= OBJECT_TRIGGER
;
3551 n
->objname
= lappend
($6, makeString
($4));
3556 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
3558 CommentStmt
*n
= makeNode
(CommentStmt
);
3559 n
->objtype
= OBJECT_OPCLASS
;
3561 n
->objargs
= list_make1
(makeString
($7));
3565 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
3567 CommentStmt
*n
= makeNode
(CommentStmt
);
3568 n
->objtype
= OBJECT_OPFAMILY
;
3570 n
->objargs
= list_make1
(makeString
($7));
3574 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
3576 CommentStmt
*n
= makeNode
(CommentStmt
);
3577 n
->objtype
= OBJECT_LARGEOBJECT
;
3578 n
->objname
= list_make1
($5);
3583 | COMMENT ON CAST
'(' Typename AS Typename
')' IS comment_text
3585 CommentStmt
*n
= makeNode
(CommentStmt
);
3586 n
->objtype
= OBJECT_CAST
;
3587 n
->objname
= list_make1
($5);
3588 n
->objargs
= list_make1
($7);
3592 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
3594 CommentStmt
*n
= makeNode
(CommentStmt
);
3595 n
->objtype
= OBJECT_LANGUAGE
;
3601 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
3603 CommentStmt
*n
= makeNode
(CommentStmt
);
3604 n
->objtype
= OBJECT_TSPARSER
;
3609 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
3611 CommentStmt
*n
= makeNode
(CommentStmt
);
3612 n
->objtype
= OBJECT_TSDICTIONARY
;
3617 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
3619 CommentStmt
*n
= makeNode
(CommentStmt
);
3620 n
->objtype
= OBJECT_TSTEMPLATE
;
3625 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
3627 CommentStmt
*n
= makeNode
(CommentStmt
);
3628 n
->objtype
= OBJECT_TSCONFIGURATION
;
3636 COLUMN
{ $$
= OBJECT_COLUMN
; }
3637 | DATABASE
{ $$
= OBJECT_DATABASE
; }
3638 | SCHEMA
{ $$
= OBJECT_SCHEMA
; }
3639 | INDEX
{ $$
= OBJECT_INDEX
; }
3640 | SEQUENCE
{ $$
= OBJECT_SEQUENCE
; }
3641 | TABLE
{ $$
= OBJECT_TABLE
; }
3642 | DOMAIN_P
{ $$
= OBJECT_TYPE
; }
3643 | TYPE_P
{ $$
= OBJECT_TYPE
; }
3644 | VIEW
{ $$
= OBJECT_VIEW
; }
3645 | CONVERSION_P
{ $$
= OBJECT_CONVERSION
; }
3646 | TABLESPACE
{ $$
= OBJECT_TABLESPACE
; }
3647 | ROLE
{ $$
= OBJECT_ROLE
; }
3652 | NULL_P
{ $$
= NULL
; }
3655 /*****************************************************************************
3660 *****************************************************************************/
3662 FetchStmt: FETCH fetch_direction from_in name
3664 FetchStmt
*n
= (FetchStmt
*) $2;
3671 FetchStmt
*n
= makeNode
(FetchStmt
);
3672 n
->direction
= FETCH_FORWARD
;
3678 | MOVE fetch_direction from_in name
3680 FetchStmt
*n
= (FetchStmt
*) $2;
3687 FetchStmt
*n
= makeNode
(FetchStmt
);
3688 n
->direction
= FETCH_FORWARD
;
3699 FetchStmt
*n
= makeNode
(FetchStmt
);
3700 n
->direction
= FETCH_FORWARD
;
3706 FetchStmt
*n
= makeNode
(FetchStmt
);
3707 n
->direction
= FETCH_FORWARD
;
3713 FetchStmt
*n
= makeNode
(FetchStmt
);
3714 n
->direction
= FETCH_BACKWARD
;
3720 FetchStmt
*n
= makeNode
(FetchStmt
);
3721 n
->direction
= FETCH_ABSOLUTE
;
3727 FetchStmt
*n
= makeNode
(FetchStmt
);
3728 n
->direction
= FETCH_ABSOLUTE
;
3732 | ABSOLUTE_P SignedIconst
3734 FetchStmt
*n
= makeNode
(FetchStmt
);
3735 n
->direction
= FETCH_ABSOLUTE
;
3739 | RELATIVE_P SignedIconst
3741 FetchStmt
*n
= makeNode
(FetchStmt
);
3742 n
->direction
= FETCH_RELATIVE
;
3748 FetchStmt
*n
= makeNode
(FetchStmt
);
3749 n
->direction
= FETCH_FORWARD
;
3755 FetchStmt
*n
= makeNode
(FetchStmt
);
3756 n
->direction
= FETCH_FORWARD
;
3757 n
->howMany
= FETCH_ALL
;
3762 FetchStmt
*n
= makeNode
(FetchStmt
);
3763 n
->direction
= FETCH_FORWARD
;
3767 | FORWARD SignedIconst
3769 FetchStmt
*n
= makeNode
(FetchStmt
);
3770 n
->direction
= FETCH_FORWARD
;
3776 FetchStmt
*n
= makeNode
(FetchStmt
);
3777 n
->direction
= FETCH_FORWARD
;
3778 n
->howMany
= FETCH_ALL
;
3783 FetchStmt
*n
= makeNode
(FetchStmt
);
3784 n
->direction
= FETCH_BACKWARD
;
3788 | BACKWARD SignedIconst
3790 FetchStmt
*n
= makeNode
(FetchStmt
);
3791 n
->direction
= FETCH_BACKWARD
;
3797 FetchStmt
*n
= makeNode
(FetchStmt
);
3798 n
->direction
= FETCH_BACKWARD
;
3799 n
->howMany
= FETCH_ALL
;
3809 /*****************************************************************************
3811 * GRANT and REVOKE statements
3813 *****************************************************************************/
3815 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
3816 opt_grant_grant_option
3818 GrantStmt
*n
= makeNode
(GrantStmt
);
3821 n
->objtype
= ($4)->objtype
;
3822 n
->objects
= ($4)->objs
;
3824 n
->grant_option
= $7;
3830 REVOKE privileges ON privilege_target
3831 FROM grantee_list opt_drop_behavior
3833 GrantStmt
*n
= makeNode
(GrantStmt
);
3834 n
->is_grant
= false
;
3835 n
->grant_option
= false
;
3837 n
->objtype
= ($4)->objtype
;
3838 n
->objects
= ($4)->objs
;
3843 | REVOKE GRANT OPTION FOR privileges ON privilege_target
3844 FROM grantee_list opt_drop_behavior
3846 GrantStmt
*n
= makeNode
(GrantStmt
);
3847 n
->is_grant
= false
;
3848 n
->grant_option
= true
;
3850 n
->objtype
= ($7)->objtype
;
3851 n
->objects
= ($7)->objs
;
3860 * A privilege list is represented as a list of strings; the validity of
3861 * the privilege names gets checked at execution. This is a bit annoying
3862 * but we have little choice because of the syntactic conflict with lists
3863 * of role names in GRANT/REVOKE. What's more, we have to call out in
3864 * the "privilege" production any reserved keywords that need to be usable
3865 * as privilege names.
3868 /* either ALL [PRIVILEGES] or a list of individual privileges */
3869 privileges: privilege_list
3877 privilege_list: privilege
3878 { $$
= list_make1
(makeString
($1)); }
3879 | privilege_list
',' privilege
3880 { $$
= lappend
($1, makeString
($3)); }
3883 privilege: SELECT
{ $$
= pstrdup
($1); }
3884 | REFERENCES
{ $$
= pstrdup
($1); }
3885 | CREATE
{ $$
= pstrdup
($1); }
3886 | ColId
{ $$
= $1; }
3890 /* Don't bother trying to fold the first two rules into one using
3891 * opt_table. You're going to get conflicts.
3896 PrivTarget
*n
= makeNode
(PrivTarget
);
3897 n
->objtype
= ACL_OBJECT_RELATION
;
3901 | TABLE qualified_name_list
3903 PrivTarget
*n
= makeNode
(PrivTarget
);
3904 n
->objtype
= ACL_OBJECT_RELATION
;
3908 | SEQUENCE qualified_name_list
3910 PrivTarget
*n
= makeNode
(PrivTarget
);
3911 n
->objtype
= ACL_OBJECT_SEQUENCE
;
3915 | FUNCTION function_with_argtypes_list
3917 PrivTarget
*n
= makeNode
(PrivTarget
);
3918 n
->objtype
= ACL_OBJECT_FUNCTION
;
3922 | DATABASE name_list
3924 PrivTarget
*n
= makeNode
(PrivTarget
);
3925 n
->objtype
= ACL_OBJECT_DATABASE
;
3929 | LANGUAGE name_list
3931 PrivTarget
*n
= makeNode
(PrivTarget
);
3932 n
->objtype
= ACL_OBJECT_LANGUAGE
;
3938 PrivTarget
*n
= makeNode
(PrivTarget
);
3939 n
->objtype
= ACL_OBJECT_NAMESPACE
;
3943 | TABLESPACE name_list
3945 PrivTarget
*n
= makeNode
(PrivTarget
);
3946 n
->objtype
= ACL_OBJECT_TABLESPACE
;
3954 grantee
{ $$
= list_make1
($1); }
3955 | grantee_list
',' grantee
{ $$
= lappend
($1, $3); }
3960 PrivGrantee
*n
= makeNode
(PrivGrantee
);
3961 /* This hack lets us avoid reserving PUBLIC as a keyword*/
3962 if
(strcmp
($1, "public") == 0)
3970 PrivGrantee
*n
= makeNode
(PrivGrantee
);
3971 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
3972 if
(strcmp
($2, "public") == 0)
3981 opt_grant_grant_option:
3982 WITH GRANT OPTION
{ $$
= TRUE
; }
3983 |
/*EMPTY*/ { $$
= FALSE
; }
3986 function_with_argtypes_list:
3987 function_with_argtypes
{ $$
= list_make1
($1); }
3988 | function_with_argtypes_list
',' function_with_argtypes
3989 { $$
= lappend
($1, $3); }
3992 function_with_argtypes:
3995 FuncWithArgs
*n
= makeNode
(FuncWithArgs
);
3997 n
->funcargs
= extractArgTypes
($2);
4002 /*****************************************************************************
4004 * GRANT and REVOKE ROLE statements
4006 *****************************************************************************/
4009 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4011 GrantRoleStmt
*n
= makeNode
(GrantRoleStmt
);
4013 n
->granted_roles
= $2;
4014 n
->grantee_roles
= $4;
4022 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4024 GrantRoleStmt
*n
= makeNode
(GrantRoleStmt
);
4025 n
->is_grant
= false
;
4026 n
->admin_opt
= false
;
4027 n
->granted_roles
= $2;
4028 n
->grantee_roles
= $4;
4032 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4034 GrantRoleStmt
*n
= makeNode
(GrantRoleStmt
);
4035 n
->is_grant
= false
;
4036 n
->admin_opt
= true
;
4037 n
->granted_roles
= $5;
4038 n
->grantee_roles
= $7;
4044 opt_grant_admin_option: WITH ADMIN OPTION
{ $$
= TRUE
; }
4045 |
/*EMPTY*/ { $$
= FALSE
; }
4048 opt_granted_by: GRANTED BY RoleId
{ $$
= $3; }
4049 |
/*EMPTY*/ { $$
= NULL
; }
4053 /*****************************************************************************
4055 * QUERY: CREATE INDEX
4057 * Note: we can't factor CONCURRENTLY into a separate production without
4058 * making it a reserved word.
4060 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
4061 * willing to make TABLESPACE a fully reserved word.
4062 *****************************************************************************/
4064 IndexStmt: CREATE index_opt_unique INDEX index_name
4065 ON qualified_name access_method_clause
'(' index_params
')'
4066 opt_definition OptTableSpace where_clause
4068 IndexStmt
*n
= makeNode
(IndexStmt
);
4070 n
->concurrent
= false
;
4073 n
->accessMethod
= $7;
4074 n
->indexParams
= $9;
4076 n
->tableSpace
= $12;
4077 n
->whereClause
= $13;
4080 | CREATE index_opt_unique INDEX CONCURRENTLY index_name
4081 ON qualified_name access_method_clause
'(' index_params
')'
4082 opt_definition OptTableSpace where_clause
4084 IndexStmt
*n
= makeNode
(IndexStmt
);
4086 n
->concurrent
= true
;
4089 n
->accessMethod
= $8;
4090 n
->indexParams
= $10;
4092 n
->tableSpace
= $13;
4093 n
->whereClause
= $14;
4099 UNIQUE
{ $$
= TRUE
; }
4100 |
/*EMPTY*/ { $$
= FALSE
; }
4103 access_method_clause:
4104 USING access_method
{ $$
= $2; }
4105 |
/*EMPTY*/ { $$
= DEFAULT_INDEX_TYPE
; }
4108 index_params: index_elem
{ $$
= list_make1
($1); }
4109 | index_params
',' index_elem
{ $$
= lappend
($1, $3); }
4113 * Index attributes can be either simple column references, or arbitrary
4114 * expressions in parens. For backwards-compatibility reasons, we allow
4115 * an expression that's just a function call to be written without parens.
4117 index_elem: ColId opt_class opt_asc_desc opt_nulls_order
4119 $$
= makeNode
(IndexElem
);
4124 $$
->nulls_ordering
= $4;
4126 | func_expr opt_class opt_asc_desc opt_nulls_order
4128 $$
= makeNode
(IndexElem
);
4133 $$
->nulls_ordering
= $4;
4135 |
'(' a_expr
')' opt_class opt_asc_desc opt_nulls_order
4137 $$
= makeNode
(IndexElem
);
4142 $$
->nulls_ordering
= $6;
4146 opt_class: any_name
{ $$
= $1; }
4147 | USING any_name
{ $$
= $2; }
4148 |
/*EMPTY*/ { $$
= NIL
; }
4151 opt_asc_desc: ASC
{ $$
= SORTBY_ASC
; }
4152 | DESC
{ $$
= SORTBY_DESC
; }
4153 |
/*EMPTY*/ { $$
= SORTBY_DEFAULT
; }
4156 opt_nulls_order: NULLS_FIRST
{ $$
= SORTBY_NULLS_FIRST
; }
4157 | NULLS_LAST
{ $$
= SORTBY_NULLS_LAST
; }
4158 |
/*EMPTY*/ { $$
= SORTBY_NULLS_DEFAULT
; }
4162 /*****************************************************************************
4165 * create [or replace] function <fname>
4166 * [(<type-1> { , <type-n>})]
4168 * as <filename or code in language as appropriate>
4169 * language <lang> [with parameters]
4171 *****************************************************************************/
4174 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4175 RETURNS func_return createfunc_opt_list opt_definition
4177 CreateFunctionStmt
*n
= makeNode
(CreateFunctionStmt
);
4186 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4187 RETURNS TABLE
'(' table_func_column_list
')' createfunc_opt_list opt_definition
4189 CreateFunctionStmt
*n
= makeNode
(CreateFunctionStmt
);
4192 n
->parameters
= mergeTableFuncParameters
($5, $9);
4193 n
->returnType
= TableFuncTypeName
($9);
4194 n
->returnType
->location
= @
7;
4196 n
->withClause
= $12;
4199 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4200 createfunc_opt_list opt_definition
4202 CreateFunctionStmt
*n
= makeNode
(CreateFunctionStmt
);
4206 n
->returnType
= NULL
;
4214 OR REPLACE
{ $$
= TRUE
; }
4215 |
/*EMPTY*/ { $$
= FALSE
; }
4218 func_args: '(' func_args_list
')' { $$
= $2; }
4219 |
'(' ')' { $$
= NIL
; }
4223 func_arg
{ $$
= list_make1
($1); }
4224 | func_args_list
',' func_arg
{ $$
= lappend
($1, $3); }
4228 * func_args_with_defaults is separate because we only want to accept
4229 * defaults in CREATE FUNCTION, not in ALTER etc.
4231 func_args_with_defaults:
4232 '(' func_args_with_defaults_list
')' { $$
= $2; }
4233 |
'(' ')' { $$
= NIL
; }
4236 func_args_with_defaults_list:
4237 func_arg_with_default
{ $$
= list_make1
( $1); }
4238 | func_args_with_defaults_list
',' func_arg_with_default
{ $$
= lappend
($1, $3); }
4243 * The style with arg_class first is SQL99 standard, but Oracle puts
4244 * param_name first; accept both since it's likely people will try both
4245 * anyway. Don't bother trying to save productions by letting arg_class
4246 * have an empty alternative ... you'll get shift/reduce conflicts.
4248 * We can catch over-specified arguments here if we want to,
4249 * but for now better to silently swallow typmod, etc.
4250 * - thomas 2000-03-22
4253 arg_class param_name func_type
4255 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4262 | param_name arg_class func_type
4264 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4271 | param_name func_type
4273 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4276 n
->mode
= FUNC_PARAM_IN
;
4280 | arg_class func_type
4282 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4291 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4294 n
->mode
= FUNC_PARAM_IN
;
4300 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
4301 arg_class: IN_P
{ $$
= FUNC_PARAM_IN
; }
4302 | OUT_P
{ $$
= FUNC_PARAM_OUT
; }
4303 | INOUT
{ $$
= FUNC_PARAM_INOUT
; }
4304 | IN_P OUT_P
{ $$
= FUNC_PARAM_INOUT
; }
4305 | VARIADIC
{ $$
= FUNC_PARAM_VARIADIC
; }
4309 * Ideally param_name should be ColId, but that causes too many conflicts.
4311 param_name: type_function_name
4317 /* We can catch over-specified results here if we want to,
4318 * but for now better to silently swallow typmod, etc.
4319 * - thomas 2000-03-22
4326 * We would like to make the %TYPE productions here be ColId attrs etc,
4327 * but that causes reduce/reduce conflicts. type_function_name
4328 * is next best choice.
4330 func_type: Typename
{ $$
= $1; }
4331 | type_function_name attrs
'%' TYPE_P
4333 $$
= makeTypeNameFromNameList
(lcons
(makeString
($1), $2));
4334 $$
->pct_type
= true
;
4337 | SETOF type_function_name attrs
'%' TYPE_P
4339 $$
= makeTypeNameFromNameList
(lcons
(makeString
($2), $3));
4340 $$
->pct_type
= true
;
4346 func_arg_with_default:
4351 | func_arg DEFAULT a_expr
4356 | func_arg
'=' a_expr
4364 createfunc_opt_list:
4365 /* Must be at least one to prevent conflict */
4366 createfunc_opt_item
{ $$
= list_make1
($1); }
4367 | createfunc_opt_list createfunc_opt_item
{ $$
= lappend
($1, $2); }
4371 * Options common to both CREATE FUNCTION and ALTER FUNCTION
4373 common_func_opt_item:
4374 CALLED ON NULL_P INPUT_P
4376 $$
= makeDefElem
("strict", (Node
*)makeInteger
(FALSE
));
4378 | RETURNS NULL_P ON NULL_P INPUT_P
4380 $$
= makeDefElem
("strict", (Node
*)makeInteger
(TRUE
));
4384 $$
= makeDefElem
("strict", (Node
*)makeInteger
(TRUE
));
4388 $$
= makeDefElem
("volatility", (Node
*)makeString
("immutable"));
4392 $$
= makeDefElem
("volatility", (Node
*)makeString
("stable"));
4396 $$
= makeDefElem
("volatility", (Node
*)makeString
("volatile"));
4398 | EXTERNAL SECURITY DEFINER
4400 $$
= makeDefElem
("security", (Node
*)makeInteger
(TRUE
));
4402 | EXTERNAL SECURITY INVOKER
4404 $$
= makeDefElem
("security", (Node
*)makeInteger
(FALSE
));
4408 $$
= makeDefElem
("security", (Node
*)makeInteger
(TRUE
));
4412 $$
= makeDefElem
("security", (Node
*)makeInteger
(FALSE
));
4416 $$
= makeDefElem
("cost", (Node
*)$2);
4420 $$
= makeDefElem
("rows", (Node
*)$2);
4424 /* we abuse the normal content of a DefElem here */
4425 $$
= makeDefElem
("set", (Node
*)$1);
4429 createfunc_opt_item:
4432 $$
= makeDefElem
("as", (Node
*)$2);
4434 | LANGUAGE ColId_or_Sconst
4436 $$
= makeDefElem
("language", (Node
*)makeString
($2));
4438 | common_func_opt_item
4444 func_as: Sconst
{ $$
= list_make1
(makeString
($1)); }
4447 $$
= list_make2
(makeString
($1), makeString
($3));
4452 WITH definition
{ $$
= $2; }
4453 |
/*EMPTY*/ { $$
= NIL
; }
4456 table_func_column: param_name func_type
4458 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4461 n
->mode
= FUNC_PARAM_TABLE
;
4466 table_func_column_list:
4469 $$
= list_make1
($1);
4471 | table_func_column_list
',' table_func_column
4473 $$
= lappend
($1, $3);
4477 /*****************************************************************************
4480 * RENAME and OWNER subcommands are already provided by the generic
4481 * ALTER infrastructure, here we just specify alterations that can
4482 * only be applied to functions.
4484 *****************************************************************************/
4486 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
4488 AlterFunctionStmt
*n
= makeNode
(AlterFunctionStmt
);
4496 /* At least one option must be specified */
4497 common_func_opt_item
{ $$
= list_make1
($1); }
4498 | alterfunc_opt_list common_func_opt_item
{ $$
= lappend
($1, $2); }
4501 /* Ignored, merely for SQL compliance */
4508 /*****************************************************************************
4512 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
4513 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
4514 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
4516 *****************************************************************************/
4519 DROP FUNCTION func_name func_args opt_drop_behavior
4521 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4522 n
->kind
= OBJECT_FUNCTION
;
4524 n
->args
= extractArgTypes
($4);
4526 n
->missing_ok
= false
;
4529 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
4531 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4532 n
->kind
= OBJECT_FUNCTION
;
4534 n
->args
= extractArgTypes
($6);
4536 n
->missing_ok
= true
;
4542 DROP AGGREGATE func_name aggr_args opt_drop_behavior
4544 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4545 n
->kind
= OBJECT_AGGREGATE
;
4549 n
->missing_ok
= false
;
4552 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
4554 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4555 n
->kind
= OBJECT_AGGREGATE
;
4559 n
->missing_ok
= true
;
4565 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
4567 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4568 n
->kind
= OBJECT_OPERATOR
;
4572 n
->missing_ok
= false
;
4575 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
4577 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4578 n
->kind
= OBJECT_OPERATOR
;
4582 n
->missing_ok
= true
;
4591 (errcode
(ERRCODE_SYNTAX_ERROR
),
4592 errmsg
("missing argument"),
4593 errhint
("Use NONE to denote the missing argument of a unary operator."),
4594 scanner_errposition
(@
3)));
4596 |
'(' Typename
',' Typename
')'
4597 { $$
= list_make2
($2, $4); }
4598 |
'(' NONE
',' Typename
')' /* left unary */
4599 { $$
= list_make2
(NULL
, $4); }
4600 |
'(' Typename
',' NONE
')' /* right unary */
4601 { $$
= list_make2
($2, NULL
); }
4606 { $$
= list_make1
(makeString
($1)); }
4607 | ColId
'.' any_operator
4608 { $$
= lcons
(makeString
($1), $3); }
4612 /*****************************************************************************
4614 * CREATE CAST / DROP CAST
4616 *****************************************************************************/
4618 CreateCastStmt: CREATE CAST
'(' Typename AS Typename
')'
4619 WITH FUNCTION function_with_argtypes cast_context
4621 CreateCastStmt
*n
= makeNode
(CreateCastStmt
);
4625 n
->context
= (CoercionContext
) $11;
4629 | CREATE CAST
'(' Typename AS Typename
')'
4630 WITHOUT FUNCTION cast_context
4632 CreateCastStmt
*n
= makeNode
(CreateCastStmt
);
4636 n
->context
= (CoercionContext
) $10;
4640 | CREATE CAST
'(' Typename AS Typename
')'
4641 WITH INOUT cast_context
4643 CreateCastStmt
*n
= makeNode
(CreateCastStmt
);
4647 n
->context
= (CoercionContext
) $10;
4653 cast_context: AS IMPLICIT_P
{ $$
= COERCION_IMPLICIT
; }
4654 | AS ASSIGNMENT
{ $$
= COERCION_ASSIGNMENT
; }
4655 |
/*EMPTY*/ { $$
= COERCION_EXPLICIT
; }
4659 DropCastStmt: DROP CAST opt_if_exists
'(' Typename AS Typename
')' opt_drop_behavior
4661 DropCastStmt
*n
= makeNode
(DropCastStmt
);
4670 opt_if_exists: IF_P EXISTS
{ $$
= TRUE
; }
4671 |
/*EMPTY*/ { $$
= FALSE
; }
4675 /*****************************************************************************
4679 * REINDEX type <name> [FORCE]
4681 * FORCE no longer does anything, but we accept it for backwards compatibility
4682 *****************************************************************************/
4685 REINDEX reindex_type qualified_name opt_force
4687 ReindexStmt
*n
= makeNode
(ReindexStmt
);
4693 | REINDEX SYSTEM_P name opt_force
4695 ReindexStmt
*n
= makeNode
(ReindexStmt
);
4696 n
->kind
= OBJECT_DATABASE
;
4699 n
->do_system
= true
;
4703 | REINDEX DATABASE name opt_force
4705 ReindexStmt
*n
= makeNode
(ReindexStmt
);
4706 n
->kind
= OBJECT_DATABASE
;
4709 n
->do_system
= true
;
4716 INDEX
{ $$
= OBJECT_INDEX
; }
4717 | TABLE
{ $$
= OBJECT_TABLE
; }
4720 opt_force: FORCE
{ $$
= TRUE
; }
4721 |
/* EMPTY */ { $$
= FALSE
; }
4725 /*****************************************************************************
4727 * ALTER THING name RENAME TO newname
4729 *****************************************************************************/
4731 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
4733 RenameStmt
*n
= makeNode
(RenameStmt
);
4734 n
->renameType
= OBJECT_AGGREGATE
;
4740 | ALTER CONVERSION_P any_name RENAME TO name
4742 RenameStmt
*n
= makeNode
(RenameStmt
);
4743 n
->renameType
= OBJECT_CONVERSION
;
4748 | ALTER DATABASE database_name RENAME TO database_name
4750 RenameStmt
*n
= makeNode
(RenameStmt
);
4751 n
->renameType
= OBJECT_DATABASE
;
4756 | ALTER FUNCTION function_with_argtypes RENAME TO name
4758 RenameStmt
*n
= makeNode
(RenameStmt
);
4759 n
->renameType
= OBJECT_FUNCTION
;
4760 n
->object
= $3->funcname
;
4761 n
->objarg
= $3->funcargs
;
4765 | ALTER GROUP_P RoleId RENAME TO RoleId
4767 RenameStmt
*n
= makeNode
(RenameStmt
);
4768 n
->renameType
= OBJECT_ROLE
;
4773 | ALTER opt_procedural LANGUAGE name RENAME TO name
4775 RenameStmt
*n
= makeNode
(RenameStmt
);
4776 n
->renameType
= OBJECT_LANGUAGE
;
4781 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
4783 RenameStmt
*n
= makeNode
(RenameStmt
);
4784 n
->renameType
= OBJECT_OPCLASS
;
4790 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
4792 RenameStmt
*n
= makeNode
(RenameStmt
);
4793 n
->renameType
= OBJECT_OPFAMILY
;
4799 | ALTER SCHEMA name RENAME TO name
4801 RenameStmt
*n
= makeNode
(RenameStmt
);
4802 n
->renameType
= OBJECT_SCHEMA
;
4807 | ALTER TABLE relation_expr RENAME TO name
4809 RenameStmt
*n
= makeNode
(RenameStmt
);
4810 n
->renameType
= OBJECT_TABLE
;
4816 | ALTER SEQUENCE relation_expr RENAME TO name
4818 RenameStmt
*n
= makeNode
(RenameStmt
);
4819 n
->renameType
= OBJECT_SEQUENCE
;
4825 | ALTER VIEW relation_expr RENAME TO name
4827 RenameStmt
*n
= makeNode
(RenameStmt
);
4828 n
->renameType
= OBJECT_VIEW
;
4834 | ALTER INDEX relation_expr RENAME TO name
4836 RenameStmt
*n
= makeNode
(RenameStmt
);
4837 n
->renameType
= OBJECT_INDEX
;
4843 | ALTER TABLE relation_expr RENAME opt_column name TO name
4845 RenameStmt
*n
= makeNode
(RenameStmt
);
4846 n
->renameType
= OBJECT_COLUMN
;
4852 | ALTER TRIGGER name ON relation_expr RENAME TO name
4854 RenameStmt
*n
= makeNode
(RenameStmt
);
4855 n
->renameType
= OBJECT_TRIGGER
;
4861 | ALTER ROLE RoleId RENAME TO RoleId
4863 RenameStmt
*n
= makeNode
(RenameStmt
);
4864 n
->renameType
= OBJECT_ROLE
;
4869 | ALTER USER RoleId RENAME TO RoleId
4871 RenameStmt
*n
= makeNode
(RenameStmt
);
4872 n
->renameType
= OBJECT_ROLE
;
4877 | ALTER TABLESPACE name RENAME TO name
4879 RenameStmt
*n
= makeNode
(RenameStmt
);
4880 n
->renameType
= OBJECT_TABLESPACE
;
4885 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
4887 RenameStmt
*n
= makeNode
(RenameStmt
);
4888 n
->renameType
= OBJECT_TSPARSER
;
4893 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
4895 RenameStmt
*n
= makeNode
(RenameStmt
);
4896 n
->renameType
= OBJECT_TSDICTIONARY
;
4901 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
4903 RenameStmt
*n
= makeNode
(RenameStmt
);
4904 n
->renameType
= OBJECT_TSTEMPLATE
;
4909 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
4911 RenameStmt
*n
= makeNode
(RenameStmt
);
4912 n
->renameType
= OBJECT_TSCONFIGURATION
;
4917 | ALTER TYPE_P any_name RENAME TO name
4919 RenameStmt
*n
= makeNode
(RenameStmt
);
4920 n
->renameType
= OBJECT_TYPE
;
4927 opt_column: COLUMN
{ $$
= COLUMN
; }
4928 |
/*EMPTY*/ { $$
= 0; }
4931 opt_set_data: SET DATA_P
{ $$
= 1; }
4932 |
/*EMPTY*/ { $$
= 0; }
4935 /*****************************************************************************
4937 * ALTER THING name SET SCHEMA name
4939 *****************************************************************************/
4941 AlterObjectSchemaStmt:
4942 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
4944 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4945 n
->objectType
= OBJECT_AGGREGATE
;
4951 | ALTER DOMAIN_P any_name SET SCHEMA name
4953 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4954 n
->objectType
= OBJECT_DOMAIN
;
4959 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
4961 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4962 n
->objectType
= OBJECT_FUNCTION
;
4963 n
->object
= $3->funcname
;
4964 n
->objarg
= $3->funcargs
;
4968 | ALTER TABLE relation_expr SET SCHEMA name
4970 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4971 n
->objectType
= OBJECT_TABLE
;
4976 | ALTER SEQUENCE relation_expr SET SCHEMA name
4978 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4979 n
->objectType
= OBJECT_SEQUENCE
;
4984 | ALTER VIEW relation_expr SET SCHEMA name
4986 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4987 n
->objectType
= OBJECT_VIEW
;
4992 | ALTER TYPE_P any_name SET SCHEMA name
4994 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4995 n
->objectType
= OBJECT_TYPE
;
5002 /*****************************************************************************
5004 * ALTER THING name OWNER TO newname
5006 *****************************************************************************/
5008 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
5010 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5011 n
->objectType
= OBJECT_AGGREGATE
;
5017 | ALTER CONVERSION_P any_name OWNER TO RoleId
5019 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5020 n
->objectType
= OBJECT_CONVERSION
;
5025 | ALTER DATABASE database_name OWNER TO RoleId
5027 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5028 n
->objectType
= OBJECT_DATABASE
;
5029 n
->object
= list_make1
(makeString
($3));
5033 | ALTER DOMAIN_P any_name OWNER TO RoleId
5035 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5036 n
->objectType
= OBJECT_DOMAIN
;
5041 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
5043 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5044 n
->objectType
= OBJECT_FUNCTION
;
5045 n
->object
= $3->funcname
;
5046 n
->objarg
= $3->funcargs
;
5050 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
5052 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5053 n
->objectType
= OBJECT_LANGUAGE
;
5054 n
->object
= list_make1
(makeString
($4));
5058 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
5060 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5061 n
->objectType
= OBJECT_OPERATOR
;
5067 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
5069 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5070 n
->objectType
= OBJECT_OPCLASS
;
5076 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
5078 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5079 n
->objectType
= OBJECT_OPFAMILY
;
5085 | ALTER SCHEMA name OWNER TO RoleId
5087 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5088 n
->objectType
= OBJECT_SCHEMA
;
5089 n
->object
= list_make1
(makeString
($3));
5093 | ALTER TYPE_P any_name OWNER TO RoleId
5095 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5096 n
->objectType
= OBJECT_TYPE
;
5101 | ALTER TABLESPACE name OWNER TO RoleId
5103 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5104 n
->objectType
= OBJECT_TABLESPACE
;
5105 n
->object
= list_make1
(makeString
($3));
5109 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
5111 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5112 n
->objectType
= OBJECT_TSDICTIONARY
;
5117 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
5119 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5120 n
->objectType
= OBJECT_TSCONFIGURATION
;
5128 /*****************************************************************************
5130 * QUERY: Define Rewrite Rule
5132 *****************************************************************************/
5134 RuleStmt: CREATE opt_or_replace RULE name AS
5135 { QueryIsRule
=TRUE
; }
5136 ON event TO qualified_name where_clause
5137 DO opt_instead RuleActionList
5139 RuleStmt
*n
= makeNode
(RuleStmt
);
5143 n
->whereClause
= $11;
5153 NOTHING
{ $$
= NIL
; }
5154 | RuleActionStmt
{ $$
= list_make1
($1); }
5155 |
'(' RuleActionMulti
')' { $$
= $2; }
5158 /* the thrashing around here is to discard "empty" statements... */
5160 RuleActionMulti
';' RuleActionStmtOrEmpty
5162 $$
= lappend
($1, $3);
5166 | RuleActionStmtOrEmpty
5168 $$
= list_make1
($1);
5182 RuleActionStmtOrEmpty:
5183 RuleActionStmt
{ $$
= $1; }
5184 |
/*EMPTY*/ { $$
= NULL
; }
5187 event: SELECT
{ $$
= CMD_SELECT
; }
5188 | UPDATE
{ $$
= CMD_UPDATE
; }
5189 | DELETE_P
{ $$
= CMD_DELETE
; }
5190 | INSERT
{ $$
= CMD_INSERT
; }
5194 INSTEAD
{ $$
= TRUE
; }
5195 | ALSO
{ $$
= FALSE
; }
5196 |
/*EMPTY*/ { $$
= FALSE
; }
5201 DROP RULE name ON qualified_name opt_drop_behavior
5203 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
5207 n
->removeType
= OBJECT_RULE
;
5208 n
->missing_ok
= false
;
5211 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
5213 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
5217 n
->removeType
= OBJECT_RULE
;
5218 n
->missing_ok
= true
;
5224 /*****************************************************************************
5227 * NOTIFY <identifier> can appear both in rule bodies and
5228 * as a query-level command
5230 *****************************************************************************/
5232 NotifyStmt: NOTIFY ColId
5234 NotifyStmt
*n
= makeNode
(NotifyStmt
);
5235 n
->conditionname
= $2;
5240 ListenStmt: LISTEN ColId
5242 ListenStmt
*n
= makeNode
(ListenStmt
);
5243 n
->conditionname
= $2;
5251 UnlistenStmt
*n
= makeNode
(UnlistenStmt
);
5252 n
->conditionname
= $2;
5257 UnlistenStmt
*n
= makeNode
(UnlistenStmt
);
5258 n
->conditionname
= NULL
;
5264 /*****************************************************************************
5268 * BEGIN / COMMIT / ROLLBACK
5269 * (also older versions END / ABORT)
5271 *****************************************************************************/
5274 ABORT_P opt_transaction
5276 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5277 n
->kind
= TRANS_STMT_ROLLBACK
;
5281 | BEGIN_P opt_transaction transaction_mode_list_or_empty
5283 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5284 n
->kind
= TRANS_STMT_BEGIN
;
5288 | START TRANSACTION transaction_mode_list_or_empty
5290 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5291 n
->kind
= TRANS_STMT_START
;
5295 | COMMIT opt_transaction
5297 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5298 n
->kind
= TRANS_STMT_COMMIT
;
5302 | END_P opt_transaction
5304 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5305 n
->kind
= TRANS_STMT_COMMIT
;
5309 | ROLLBACK opt_transaction
5311 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5312 n
->kind
= TRANS_STMT_ROLLBACK
;
5318 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5319 n
->kind
= TRANS_STMT_SAVEPOINT
;
5320 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5321 (Node
*)makeString
($2)));
5324 | RELEASE SAVEPOINT ColId
5326 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5327 n
->kind
= TRANS_STMT_RELEASE
;
5328 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5329 (Node
*)makeString
($3)));
5334 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5335 n
->kind
= TRANS_STMT_RELEASE
;
5336 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5337 (Node
*)makeString
($2)));
5340 | ROLLBACK opt_transaction TO SAVEPOINT ColId
5342 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5343 n
->kind
= TRANS_STMT_ROLLBACK_TO
;
5344 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5345 (Node
*)makeString
($5)));
5348 | ROLLBACK opt_transaction TO ColId
5350 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5351 n
->kind
= TRANS_STMT_ROLLBACK_TO
;
5352 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5353 (Node
*)makeString
($4)));
5356 | PREPARE TRANSACTION Sconst
5358 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5359 n
->kind
= TRANS_STMT_PREPARE
;
5363 | COMMIT PREPARED Sconst
5365 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5366 n
->kind
= TRANS_STMT_COMMIT_PREPARED
;
5370 | ROLLBACK PREPARED Sconst
5372 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5373 n
->kind
= TRANS_STMT_ROLLBACK_PREPARED
;
5379 opt_transaction: WORK
{}
5384 transaction_mode_item:
5385 ISOLATION LEVEL iso_level
5386 { $$
= makeDefElem
("transaction_isolation",
5387 makeStringConst
($3, @
3)); }
5389 { $$
= makeDefElem
("transaction_read_only",
5390 makeIntConst
(TRUE
, @
1)); }
5392 { $$
= makeDefElem
("transaction_read_only",
5393 makeIntConst
(FALSE
, @
1)); }
5396 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
5397 transaction_mode_list:
5398 transaction_mode_item
5399 { $$
= list_make1
($1); }
5400 | transaction_mode_list
',' transaction_mode_item
5401 { $$
= lappend
($1, $3); }
5402 | transaction_mode_list transaction_mode_item
5403 { $$
= lappend
($1, $2); }
5406 transaction_mode_list_or_empty:
5407 transaction_mode_list
5413 /*****************************************************************************
5416 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
5417 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
5419 *****************************************************************************/
5421 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
5422 AS SelectStmt opt_check_option
5424 ViewStmt
*n
= makeNode
(ViewStmt
);
5426 n
->view
->istemp
= $2;
5432 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
5433 AS SelectStmt opt_check_option
5435 ViewStmt
*n
= makeNode
(ViewStmt
);
5437 n
->view
->istemp
= $4;
5449 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
5450 errmsg
("WITH CHECK OPTION is not implemented")));
5452 | WITH CASCADED CHECK OPTION
5455 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
5456 errmsg
("WITH CHECK OPTION is not implemented")));
5458 | WITH LOCAL CHECK OPTION
5461 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
5462 errmsg
("WITH CHECK OPTION is not implemented")));
5464 |
/* EMPTY */ { $$
= NIL
; }
5467 /*****************************************************************************
5472 *****************************************************************************/
5474 LoadStmt: LOAD file_name
5476 LoadStmt
*n
= makeNode
(LoadStmt
);
5483 /*****************************************************************************
5487 *****************************************************************************/
5490 CREATE DATABASE database_name opt_with createdb_opt_list
5492 CreatedbStmt
*n
= makeNode
(CreatedbStmt
);
5500 createdb_opt_list createdb_opt_item
{ $$
= lappend
($1, $2); }
5501 |
/* EMPTY */ { $$
= NIL
; }
5505 TABLESPACE opt_equal name
5507 $$
= makeDefElem
("tablespace", (Node
*)makeString
($3));
5509 | TABLESPACE opt_equal DEFAULT
5511 $$
= makeDefElem
("tablespace", NULL
);
5513 | LOCATION opt_equal Sconst
5515 $$
= makeDefElem
("location", (Node
*)makeString
($3));
5517 | LOCATION opt_equal DEFAULT
5519 $$
= makeDefElem
("location", NULL
);
5521 | TEMPLATE opt_equal name
5523 $$
= makeDefElem
("template", (Node
*)makeString
($3));
5525 | TEMPLATE opt_equal DEFAULT
5527 $$
= makeDefElem
("template", NULL
);
5529 | ENCODING opt_equal Sconst
5531 $$
= makeDefElem
("encoding", (Node
*)makeString
($3));
5533 | ENCODING opt_equal Iconst
5535 $$
= makeDefElem
("encoding", (Node
*)makeInteger
($3));
5537 | ENCODING opt_equal DEFAULT
5539 $$
= makeDefElem
("encoding", NULL
);
5541 | COLLATE opt_equal Sconst
5543 $$
= makeDefElem
("collate", (Node
*)makeString
($3));
5545 | COLLATE opt_equal DEFAULT
5547 $$
= makeDefElem
("collate", NULL
);
5549 | CTYPE opt_equal Sconst
5551 $$
= makeDefElem
("ctype", (Node
*)makeString
($3));
5553 | CTYPE opt_equal DEFAULT
5555 $$
= makeDefElem
("ctype", NULL
);
5557 | CONNECTION LIMIT opt_equal SignedIconst
5559 $$
= makeDefElem
("connectionlimit", (Node
*)makeInteger
($4));
5561 | OWNER opt_equal name
5563 $$
= makeDefElem
("owner", (Node
*)makeString
($3));
5565 | OWNER opt_equal DEFAULT
5567 $$
= makeDefElem
("owner", NULL
);
5572 * Though the equals sign doesn't match other WITH options, pg_dump uses
5573 * equals for backward compatibility, and it doesn't seem worth removing it.
5580 /*****************************************************************************
5584 *****************************************************************************/
5587 ALTER DATABASE database_name opt_with alterdb_opt_list
5589 AlterDatabaseStmt
*n
= makeNode
(AlterDatabaseStmt
);
5594 | ALTER DATABASE database_name SET TABLESPACE name
5596 AlterDatabaseStmt
*n
= makeNode
(AlterDatabaseStmt
);
5598 n
->options
= list_make1
(makeDefElem
("tablespace",
5599 (Node
*)makeString
($6)));
5604 AlterDatabaseSetStmt:
5605 ALTER DATABASE database_name SetResetClause
5607 AlterDatabaseSetStmt
*n
= makeNode
(AlterDatabaseSetStmt
);
5616 alterdb_opt_list alterdb_opt_item
{ $$
= lappend
($1, $2); }
5617 |
/* EMPTY */ { $$
= NIL
; }
5621 CONNECTION LIMIT opt_equal SignedIconst
5623 $$
= makeDefElem
("connectionlimit", (Node
*)makeInteger
($4));
5628 /*****************************************************************************
5630 * DROP DATABASE [ IF EXISTS ]
5632 * This is implicitly CASCADE, no need for drop behavior
5633 *****************************************************************************/
5635 DropdbStmt: DROP DATABASE database_name
5637 DropdbStmt
*n
= makeNode
(DropdbStmt
);
5639 n
->missing_ok
= FALSE
;
5642 | DROP DATABASE IF_P EXISTS database_name
5644 DropdbStmt
*n
= makeNode
(DropdbStmt
);
5646 n
->missing_ok
= TRUE
;
5652 /*****************************************************************************
5654 * Manipulate a domain
5656 *****************************************************************************/
5659 CREATE DOMAIN_P any_name opt_as Typename ColQualList
5661 CreateDomainStmt
*n
= makeNode
(CreateDomainStmt
);
5664 n
->constraints
= $6;
5670 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
5671 ALTER DOMAIN_P any_name alter_column_default
5673 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
5679 /* ALTER DOMAIN <domain> DROP NOT NULL */
5680 | ALTER DOMAIN_P any_name DROP NOT NULL_P
5682 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
5687 /* ALTER DOMAIN <domain> SET NOT NULL */
5688 | ALTER DOMAIN_P any_name SET NOT NULL_P
5690 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
5695 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
5696 | ALTER DOMAIN_P any_name ADD_P TableConstraint
5698 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
5704 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
5705 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
5707 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
5721 /*****************************************************************************
5723 * Manipulate a text search dictionary or configuration
5725 *****************************************************************************/
5727 AlterTSDictionaryStmt:
5728 ALTER TEXT_P SEARCH DICTIONARY any_name definition
5730 AlterTSDictionaryStmt
*n
= makeNode
(AlterTSDictionaryStmt
);
5737 AlterTSConfigurationStmt:
5738 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
5740 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5744 n
->override
= false
;
5748 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
5750 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5758 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
5760 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5763 n
->dicts
= list_make2
($9,$11);
5764 n
->override
= false
;
5768 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
5770 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5773 n
->dicts
= list_make2
($11,$13);
5774 n
->override
= false
;
5778 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
5780 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5783 n
->missing_ok
= false
;
5786 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
5788 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5791 n
->missing_ok
= true
;
5797 /*****************************************************************************
5799 * Manipulate a conversion
5801 * CREATE [DEFAULT] CONVERSION <conversion_name>
5802 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
5804 *****************************************************************************/
5806 CreateConversionStmt:
5807 CREATE opt_default CONVERSION_P any_name FOR Sconst
5808 TO Sconst FROM any_name
5810 CreateConversionStmt
*n
= makeNode
(CreateConversionStmt
);
5811 n
->conversion_name
= $4;
5812 n
->for_encoding_name
= $6;
5813 n
->to_encoding_name
= $8;
5820 /*****************************************************************************
5823 * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
5825 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
5827 *****************************************************************************/
5830 CLUSTER opt_verbose qualified_name cluster_index_specification
5832 ClusterStmt
*n
= makeNode
(ClusterStmt
);
5838 | CLUSTER opt_verbose
5840 ClusterStmt
*n
= makeNode
(ClusterStmt
);
5842 n
->indexname
= NULL
;
5846 /* kept for pre-8.3 compatibility */
5847 | CLUSTER opt_verbose index_name ON qualified_name
5849 ClusterStmt
*n
= makeNode
(ClusterStmt
);
5857 cluster_index_specification:
5858 USING index_name
{ $$
= $2; }
5859 |
/*EMPTY*/ { $$
= NULL
; }
5863 /*****************************************************************************
5869 *****************************************************************************/
5871 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
5873 VacuumStmt
*n
= makeNode
(VacuumStmt
);
5877 n
->freeze_min_age
= $3 ?
0 : -1;
5878 n
->scan_all
= $2 ||
$3;
5884 | VACUUM opt_full opt_freeze opt_verbose qualified_name
5886 VacuumStmt
*n
= makeNode
(VacuumStmt
);
5890 n
->freeze_min_age
= $3 ?
0 : -1;
5891 n
->scan_all
= $2 ||
$3;
5897 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
5899 VacuumStmt
*n
= (VacuumStmt
*) $5;
5902 n
->freeze_min_age
= $3 ?
0 : -1;
5903 n
->scan_all
= $2 ||
$3;
5910 analyze_keyword opt_verbose
5912 VacuumStmt
*n
= makeNode
(VacuumStmt
);
5916 n
->freeze_min_age
= -1;
5922 | analyze_keyword opt_verbose qualified_name opt_name_list
5924 VacuumStmt
*n
= makeNode
(VacuumStmt
);
5928 n
->freeze_min_age
= -1;
5938 | ANALYSE
/* British */ {}
5942 VERBOSE
{ $$
= TRUE
; }
5943 |
/*EMPTY*/ { $$
= FALSE
; }
5946 opt_full: FULL
{ $$
= TRUE
; }
5947 |
/*EMPTY*/ { $$
= FALSE
; }
5950 opt_freeze: FREEZE
{ $$
= TRUE
; }
5951 |
/*EMPTY*/ { $$
= FALSE
; }
5955 '(' name_list
')' { $$
= $2; }
5956 |
/*EMPTY*/ { $$
= NIL
; }
5960 /*****************************************************************************
5963 * EXPLAIN [ANALYZE] [VERBOSE] query
5965 *****************************************************************************/
5967 ExplainStmt: EXPLAIN opt_analyze opt_verbose ExplainableStmt
5969 ExplainStmt
*n
= makeNode
(ExplainStmt
);
5984 | ExecuteStmt
/* by default all are $$=$1 */
5988 analyze_keyword
{ $$
= TRUE
; }
5989 |
/* EMPTY */ { $$
= FALSE
; }
5992 /*****************************************************************************
5995 * PREPARE <plan_name> [(args, ...)] AS <query>
5997 *****************************************************************************/
5999 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
6001 PrepareStmt
*n
= makeNode
(PrepareStmt
);
6009 prep_type_clause: '(' type_list
')' { $$
= $2; }
6010 |
/* EMPTY */ { $$
= NIL
; }
6017 | DeleteStmt
/* by default all are $$=$1 */
6020 /*****************************************************************************
6022 * EXECUTE <plan_name> [(params, ...)]
6023 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
6025 *****************************************************************************/
6027 ExecuteStmt: EXECUTE name execute_param_clause
6029 ExecuteStmt
*n
= makeNode
(ExecuteStmt
);
6035 | CREATE OptTemp TABLE create_as_target AS
6036 EXECUTE name execute_param_clause
6038 ExecuteStmt
*n
= makeNode
(ExecuteStmt
);
6041 $4->rel
->istemp
= $2;
6045 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
6046 errmsg
("column name list not allowed in CREATE TABLE / AS EXECUTE")));
6047 /* ... because it's not implemented, but it could be */
6052 execute_param_clause: '(' expr_list
')' { $$
= $2; }
6053 |
/* EMPTY */ { $$
= NIL
; }
6056 /*****************************************************************************
6059 * DEALLOCATE [PREPARE] <plan_name>
6061 *****************************************************************************/
6063 DeallocateStmt: DEALLOCATE name
6065 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
6069 | DEALLOCATE PREPARE name
6071 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
6077 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
6081 | DEALLOCATE PREPARE ALL
6083 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
6089 /*****************************************************************************
6094 *****************************************************************************/
6097 INSERT INTO qualified_name insert_rest returning_clause
6100 $4->returningList
= $5;
6108 $$
= makeNode
(InsertStmt
);
6110 $$
->selectStmt
= $1;
6112 |
'(' insert_column_list
')' SelectStmt
6114 $$
= makeNode
(InsertStmt
);
6116 $$
->selectStmt
= $4;
6120 $$
= makeNode
(InsertStmt
);
6122 $$
->selectStmt
= NULL
;
6128 { $$
= list_make1
($1); }
6129 | insert_column_list
',' insert_column_item
6130 { $$
= lappend
($1, $3); }
6134 ColId opt_indirection
6136 $$
= makeNode
(ResTarget
);
6138 $$
->indirection
= check_indirection
($2);
6145 RETURNING target_list
{ $$
= $2; }
6146 |
/* EMPTY */ { $$
= NIL
; }
6150 /*****************************************************************************
6155 *****************************************************************************/
6157 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
6158 using_clause where_or_current_clause returning_clause
6160 DeleteStmt
*n
= makeNode
(DeleteStmt
);
6162 n
->usingClause
= $4;
6163 n
->whereClause
= $5;
6164 n
->returningList
= $6;
6170 USING from_list
{ $$
= $2; }
6171 |
/*EMPTY*/ { $$
= NIL
; }
6174 LockStmt: LOCK_P opt_table qualified_name_list opt_lock opt_nowait
6176 LockStmt
*n
= makeNode
(LockStmt
);
6185 opt_lock: IN_P lock_type MODE
{ $$
= $2; }
6186 |
/*EMPTY*/ { $$
= AccessExclusiveLock
; }
6189 lock_type: ACCESS SHARE
{ $$
= AccessShareLock
; }
6190 | ROW SHARE
{ $$
= RowShareLock
; }
6191 | ROW EXCLUSIVE
{ $$
= RowExclusiveLock
; }
6192 | SHARE UPDATE EXCLUSIVE
{ $$
= ShareUpdateExclusiveLock
; }
6193 | SHARE
{ $$
= ShareLock
; }
6194 | SHARE ROW EXCLUSIVE
{ $$
= ShareRowExclusiveLock
; }
6195 | EXCLUSIVE
{ $$
= ExclusiveLock
; }
6196 | ACCESS EXCLUSIVE
{ $$
= AccessExclusiveLock
; }
6199 opt_nowait: NOWAIT
{ $$
= TRUE
; }
6200 |
/*EMPTY*/ { $$
= FALSE
; }
6204 /*****************************************************************************
6207 * UpdateStmt (UPDATE)
6209 *****************************************************************************/
6211 UpdateStmt: UPDATE relation_expr_opt_alias
6214 where_or_current_clause
6217 UpdateStmt
*n
= makeNode
(UpdateStmt
);
6221 n
->whereClause
= $6;
6222 n
->returningList
= $7;
6228 set_clause
{ $$
= $1; }
6229 | set_clause_list
',' set_clause
{ $$
= list_concat
($1,$3); }
6233 single_set_clause
{ $$
= list_make1
($1); }
6234 | multiple_set_clause
{ $$
= $1; }
6238 set_target
'=' ctext_expr
6241 $$
->val
= (Node
*) $3;
6245 multiple_set_clause:
6246 '(' set_target_list
')' '=' ctext_row
6252 * Break the ctext_row apart, merge individual expressions
6253 * into the destination ResTargets. XXX this approach
6254 * cannot work for general row expressions as sources.
6256 if
(list_length
($2) != list_length
($5))
6258 (errcode
(ERRCODE_SYNTAX_ERROR
),
6259 errmsg
("number of columns does not match number of values"),
6260 scanner_errposition
(@
1)));
6261 forboth
(col_cell
, $2, val_cell
, $5)
6263 ResTarget
*res_col
= (ResTarget
*) lfirst
(col_cell
);
6264 Node
*res_val
= (Node
*) lfirst
(val_cell
);
6266 res_col
->val
= res_val
;
6274 ColId opt_indirection
6276 $$
= makeNode
(ResTarget
);
6278 $$
->indirection
= check_indirection
($2);
6279 $$
->val
= NULL
; /* upper production sets this */
6285 set_target
{ $$
= list_make1
($1); }
6286 | set_target_list
',' set_target
{ $$
= lappend
($1,$3); }
6290 /*****************************************************************************
6295 *****************************************************************************/
6296 DeclareCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR SelectStmt
6298 DeclareCursorStmt
*n
= makeNode
(DeclareCursorStmt
);
6300 /* currently we always set FAST_PLAN option */
6301 n
->options
= $3 |
$5 | CURSOR_OPT_FAST_PLAN
;
6307 cursor_options: /*EMPTY*/ { $$
= 0; }
6308 | cursor_options NO SCROLL
{ $$
= $1 | CURSOR_OPT_NO_SCROLL
; }
6309 | cursor_options SCROLL
{ $$
= $1 | CURSOR_OPT_SCROLL
; }
6310 | cursor_options BINARY
{ $$
= $1 | CURSOR_OPT_BINARY
; }
6311 | cursor_options INSENSITIVE
{ $$
= $1 | CURSOR_OPT_INSENSITIVE
; }
6314 opt_hold: /* EMPTY */ { $$
= 0; }
6315 | WITH HOLD
{ $$
= CURSOR_OPT_HOLD
; }
6316 | WITHOUT HOLD
{ $$
= 0; }
6319 /*****************************************************************************
6324 *****************************************************************************/
6326 /* A complete SELECT statement looks like this.
6328 * The rule returns either a single SelectStmt node or a tree of them,
6329 * representing a set-operation tree.
6331 * There is an ambiguity when a sub-SELECT is within an a_expr and there
6332 * are excess parentheses: do the parentheses belong to the sub-SELECT or
6333 * to the surrounding a_expr? We don't really care, but yacc wants to know.
6334 * To resolve the ambiguity, we are careful to define the grammar so that
6335 * the decision is staved off as long as possible: as long as we can keep
6336 * absorbing parentheses into the sub-SELECT, we will do so, and only when
6337 * it's no longer possible to do that will we decide that parens belong to
6338 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
6339 * parentheses are treated as part of the sub-select. The necessity of doing
6340 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
6341 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
6342 * SELECT viewpoint when we see the UNION.
6344 * This approach is implemented by defining a nonterminal select_with_parens,
6345 * which represents a SELECT with at least one outer layer of parentheses,
6346 * and being careful to use select_with_parens, never '(' SelectStmt ')',
6347 * in the expression grammar. We will then have shift-reduce conflicts
6348 * which we can resolve in favor of always treating '(' <select> ')' as
6349 * a select_with_parens. To resolve the conflicts, the productions that
6350 * conflict with the select_with_parens productions are manually given
6351 * precedences lower than the precedence of ')', thereby ensuring that we
6352 * shift ')' (and then reduce to select_with_parens) rather than trying to
6353 * reduce the inner <select> nonterminal to something else. We use UMINUS
6354 * precedence for this, which is a fairly arbitrary choice.
6356 * To be able to define select_with_parens itself without ambiguity, we need
6357 * a nonterminal select_no_parens that represents a SELECT structure with no
6358 * outermost parentheses. This is a little bit tedious, but it works.
6360 * In non-expression contexts, we use SelectStmt which can represent a SELECT
6361 * with or without outer parentheses.
6364 SelectStmt: select_no_parens %prec UMINUS
6365 | select_with_parens %prec UMINUS
6369 '(' select_no_parens
')' { $$
= $2; }
6370 |
'(' select_with_parens
')' { $$
= $2; }
6374 * This rule parses the equivalent of the standard's <query expression>.
6375 * The duplicative productions are annoying, but hard to get rid of without
6376 * creating shift/reduce conflicts.
6378 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
6379 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
6380 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
6384 simple_select
{ $$
= $1; }
6385 | select_clause sort_clause
6387 insertSelectOptions
((SelectStmt
*) $1, $2, NIL
,
6391 | select_clause opt_sort_clause for_locking_clause opt_select_limit
6393 insertSelectOptions
((SelectStmt
*) $1, $2, $3,
6394 list_nth
($4, 0), list_nth
($4, 1),
6398 | select_clause opt_sort_clause select_limit opt_for_locking_clause
6400 insertSelectOptions
((SelectStmt
*) $1, $2, $4,
6401 list_nth
($3, 0), list_nth
($3, 1),
6405 | with_clause simple_select
6407 insertSelectOptions
((SelectStmt
*) $2, NULL
, NIL
,
6412 | with_clause select_clause sort_clause
6414 insertSelectOptions
((SelectStmt
*) $2, $3, NIL
,
6419 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
6421 insertSelectOptions
((SelectStmt
*) $2, $3, $4,
6422 list_nth
($5, 0), list_nth
($5, 1),
6426 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
6428 insertSelectOptions
((SelectStmt
*) $2, $3, $5,
6429 list_nth
($4, 0), list_nth
($4, 1),
6436 simple_select
{ $$
= $1; }
6437 | select_with_parens
{ $$
= $1; }
6441 * This rule parses SELECT statements that can appear within set operations,
6442 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
6443 * the ordering of the set operations. Without '(' and ')' we want the
6444 * operations to be ordered per the precedence specs at the head of this file.
6446 * As with select_no_parens, simple_select cannot have outer parentheses,
6447 * but can have parenthesized subclauses.
6449 * Note that sort clauses cannot be included at this level --- SQL92 requires
6450 * SELECT foo UNION SELECT bar ORDER BY baz
6452 * (SELECT foo UNION SELECT bar) ORDER BY baz
6454 * SELECT foo UNION (SELECT bar ORDER BY baz)
6455 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
6456 * described as part of the select_no_parens production, not simple_select.
6457 * This does not limit functionality, because you can reintroduce these
6458 * clauses inside parentheses.
6460 * NOTE: only the leftmost component SelectStmt should have INTO.
6461 * However, this is not checked by the grammar; parse analysis must check it.
6464 SELECT opt_distinct target_list
6465 into_clause from_clause where_clause
6466 group_clause having_clause
6468 SelectStmt
*n
= makeNode
(SelectStmt
);
6469 n
->distinctClause
= $2;
6473 n
->whereClause
= $6;
6474 n
->groupClause
= $7;
6475 n
->havingClause
= $8;
6478 | values_clause
{ $$
= $1; }
6479 | TABLE relation_expr
6481 /* same as SELECT * FROM relation_expr */
6482 ColumnRef
*cr
= makeNode
(ColumnRef
);
6483 ResTarget
*rt
= makeNode
(ResTarget
);
6484 SelectStmt
*n
= makeNode
(SelectStmt
);
6486 cr
->fields
= list_make1
(makeNode
(A_Star
));
6490 rt
->indirection
= NIL
;
6491 rt
->val
= (Node
*)cr
;
6494 n
->targetList
= list_make1
(rt
);
6495 n
->fromClause
= list_make1
($2);
6498 | select_clause UNION opt_all select_clause
6500 $$
= makeSetOp
(SETOP_UNION
, $3, $1, $4);
6502 | select_clause INTERSECT opt_all select_clause
6504 $$
= makeSetOp
(SETOP_INTERSECT
, $3, $1, $4);
6506 | select_clause EXCEPT opt_all select_clause
6508 $$
= makeSetOp
(SETOP_EXCEPT
, $3, $1, $4);
6513 * SQL standard WITH clause looks like:
6515 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
6516 * AS (query) [ SEARCH or CYCLE clause ]
6518 * We don't currently support the SEARCH or CYCLE clause.
6523 $$
= makeNode
(WithClause
);
6525 $$
->recursive
= false
;
6528 | WITH RECURSIVE cte_list
6530 $$
= makeNode
(WithClause
);
6532 $$
->recursive
= true
;
6538 common_table_expr
{ $$
= list_make1
($1); }
6539 | cte_list
',' common_table_expr
{ $$
= lappend
($1, $3); }
6542 common_table_expr: name opt_name_list AS select_with_parens
6544 CommonTableExpr
*n
= makeNode
(CommonTableExpr
);
6546 n
->aliascolnames
= $2;
6554 INTO OptTempTableName
6556 $$
= makeNode
(IntoClause
);
6560 $$
->onCommit
= ONCOMMIT_NOOP
;
6561 $$
->tableSpaceName
= NULL
;
6568 * Redundancy here is needed to avoid shift/reduce conflicts,
6569 * since TEMP is not a reserved word. See also OptTemp.
6572 TEMPORARY opt_table qualified_name
6577 | TEMP opt_table qualified_name
6582 | LOCAL TEMPORARY opt_table qualified_name
6587 | LOCAL TEMP opt_table qualified_name
6592 | GLOBAL TEMPORARY opt_table qualified_name
6597 | GLOBAL TEMP opt_table qualified_name
6602 | TABLE qualified_name
6618 opt_all: ALL
{ $$
= TRUE
; }
6619 | DISTINCT
{ $$
= FALSE
; }
6620 |
/*EMPTY*/ { $$
= FALSE
; }
6623 /* We use (NIL) as a placeholder to indicate that all target expressions
6624 * should be placed in the DISTINCT list during parsetree analysis.
6627 DISTINCT
{ $$
= list_make1
(NIL
); }
6628 | DISTINCT ON
'(' expr_list
')' { $$
= $4; }
6630 |
/*EMPTY*/ { $$
= NIL
; }
6634 sort_clause
{ $$
= $1;}
6635 |
/*EMPTY*/ { $$
= NIL
; }
6639 ORDER BY sortby_list
{ $$
= $3; }
6643 sortby
{ $$
= list_make1
($1); }
6644 | sortby_list
',' sortby
{ $$
= lappend
($1, $3); }
6647 sortby: a_expr USING qual_all_Op opt_nulls_order
6649 $$
= makeNode
(SortBy
);
6651 $$
->sortby_dir
= SORTBY_USING
;
6652 $$
->sortby_nulls
= $4;
6656 | a_expr opt_asc_desc opt_nulls_order
6658 $$
= makeNode
(SortBy
);
6660 $$
->sortby_dir
= $2;
6661 $$
->sortby_nulls
= $3;
6663 $$
->location
= -1; /* no operator */
6669 LIMIT select_limit_value OFFSET select_offset_value
6670 { $$
= list_make2
($4, $2); }
6671 | OFFSET select_offset_value LIMIT select_limit_value
6672 { $$
= list_make2
($2, $4); }
6673 | LIMIT select_limit_value
6674 { $$
= list_make2
(NULL
, $2); }
6675 | OFFSET select_offset_value
6676 { $$
= list_make2
($2, NULL
); }
6677 | LIMIT select_limit_value
',' select_offset_value
6679 /* Disabled because it was too confusing, bjm 2002-02-18 */
6681 (errcode
(ERRCODE_SYNTAX_ERROR
),
6682 errmsg
("LIMIT #,# syntax is not supported"),
6683 errhint
("Use separate LIMIT and OFFSET clauses."),
6684 scanner_errposition
(@
1)));
6686 /* SQL:2008 syntax variants */
6687 | OFFSET select_offset_value2 row_or_rows
6688 { $$
= list_make2
($2, NULL
); }
6689 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
6690 { $$
= list_make2
(NULL
, $3); }
6691 | OFFSET select_offset_value2 row_or_rows FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
6692 { $$
= list_make2
($2, $6); }
6696 select_limit
{ $$
= $1; }
6698 { $$
= list_make2
(NULL
,NULL
); }
6705 /* LIMIT ALL is represented as a NULL constant */
6706 $$
= makeNullAConst
(@
1);
6711 * Allowing full expressions without parentheses causes various parsing
6712 * problems with the trailing ROW/ROWS key words. SQL only calls for
6713 * constants, so we allow the rest only with parentheses.
6715 opt_select_fetch_first_value:
6716 SignedIconst
{ $$
= makeIntConst
($1, @
1); }
6717 |
'(' a_expr
')' { $$
= $2; }
6718 |
/*EMPTY*/ { $$
= makeIntConst
(1, -1); }
6721 select_offset_value:
6726 * Again, the trailing ROW/ROWS in this case prevent the full expression
6727 * syntax. c_expr is the best we can do.
6729 select_offset_value2:
6746 GROUP_P BY expr_list
{ $$
= $3; }
6747 |
/*EMPTY*/ { $$
= NIL
; }
6751 HAVING a_expr
{ $$
= $2; }
6752 |
/*EMPTY*/ { $$
= NULL
; }
6756 for_locking_items
{ $$
= $1; }
6757 | FOR READ ONLY
{ $$
= NIL
; }
6760 opt_for_locking_clause:
6761 for_locking_clause
{ $$
= $1; }
6762 |
/* EMPTY */ { $$
= NIL
; }
6766 for_locking_item
{ $$
= list_make1
($1); }
6767 | for_locking_items for_locking_item
{ $$
= lappend
($1, $2); }
6771 FOR UPDATE locked_rels_list opt_nowait
6773 LockingClause
*n
= makeNode
(LockingClause
);
6775 n
->forUpdate
= TRUE
;
6779 | FOR SHARE locked_rels_list opt_nowait
6781 LockingClause
*n
= makeNode
(LockingClause
);
6783 n
->forUpdate
= FALSE
;
6790 OF qualified_name_list
{ $$
= $2; }
6791 |
/* EMPTY */ { $$
= NIL
; }
6798 SelectStmt
*n
= makeNode
(SelectStmt
);
6799 n
->valuesLists
= list_make1
($2);
6802 | values_clause
',' ctext_row
6804 SelectStmt
*n
= (SelectStmt
*) $1;
6805 n
->valuesLists
= lappend
(n
->valuesLists
, $3);
6811 /*****************************************************************************
6813 * clauses common to all Optimizable Stmts:
6814 * from_clause - allow list of both JOIN expressions and table names
6815 * where_clause - qualifications for joins or restrictions
6817 *****************************************************************************/
6820 FROM from_list
{ $$
= $2; }
6821 |
/*EMPTY*/ { $$
= NIL
; }
6825 table_ref
{ $$
= list_make1
($1); }
6826 | from_list
',' table_ref
{ $$
= lappend
($1, $3); }
6830 * table_ref is where an alias clause can be attached. Note we cannot make
6831 * alias_clause have an empty production because that causes parse conflicts
6832 * between table_ref := '(' joined_table ')' alias_clause
6833 * and joined_table := '(' joined_table ')'. So, we must have the
6834 * redundant-looking productions here instead.
6836 table_ref: relation_expr
6840 | relation_expr alias_clause
6847 RangeFunction
*n
= makeNode
(RangeFunction
);
6848 n
->funccallnode
= $1;
6849 n
->coldeflist
= NIL
;
6852 | func_table alias_clause
6854 RangeFunction
*n
= makeNode
(RangeFunction
);
6855 n
->funccallnode
= $1;
6857 n
->coldeflist
= NIL
;
6860 | func_table AS
'(' TableFuncElementList
')'
6862 RangeFunction
*n
= makeNode
(RangeFunction
);
6863 n
->funccallnode
= $1;
6867 | func_table AS ColId
'(' TableFuncElementList
')'
6869 RangeFunction
*n
= makeNode
(RangeFunction
);
6870 Alias
*a
= makeNode
(Alias
);
6871 n
->funccallnode
= $1;
6877 | func_table ColId
'(' TableFuncElementList
')'
6879 RangeFunction
*n
= makeNode
(RangeFunction
);
6880 Alias
*a
= makeNode
(Alias
);
6881 n
->funccallnode
= $1;
6887 | select_with_parens
6890 * The SQL spec does not permit a subselect
6891 * (<derived_table>) without an alias clause,
6892 * so we don't either. This avoids the problem
6893 * of needing to invent a unique refname for it.
6894 * That could be surmounted if there's sufficient
6895 * popular demand, but for now let's just implement
6896 * the spec and see if anyone complains.
6897 * However, it does seem like a good idea to emit
6898 * an error message that's better than "syntax error".
6900 if
(IsA
($1, SelectStmt
) &&
6901 ((SelectStmt
*) $1)->valuesLists
)
6903 (errcode
(ERRCODE_SYNTAX_ERROR
),
6904 errmsg
("VALUES in FROM must have an alias"),
6905 errhint
("For example, FROM (VALUES ...) [AS] foo."),
6906 scanner_errposition
(@
1)));
6909 (errcode
(ERRCODE_SYNTAX_ERROR
),
6910 errmsg
("subquery in FROM must have an alias"),
6911 errhint
("For example, FROM (SELECT ...) [AS] foo."),
6912 scanner_errposition
(@
1)));
6915 | select_with_parens alias_clause
6917 RangeSubselect
*n
= makeNode
(RangeSubselect
);
6926 |
'(' joined_table
')' alias_clause
6935 * It may seem silly to separate joined_table from table_ref, but there is
6936 * method in SQL92's madness: if you don't do it this way you get reduce-
6937 * reduce conflicts, because it's not clear to the parser generator whether
6938 * to expect alias_clause after ')' or not. For the same reason we must
6939 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
6940 * join_type to expand to empty; if we try it, the parser generator can't
6941 * figure out when to reduce an empty join_type right after table_ref.
6943 * Note that a CROSS JOIN is the same as an unqualified
6944 * INNER JOIN, and an INNER JOIN/ON has the same shape
6945 * but a qualification expression to limit membership.
6946 * A NATURAL JOIN implicitly matches column names between
6947 * tables and the shape is determined by which columns are
6948 * in common. We'll collect columns during the later transformations.
6952 '(' joined_table
')'
6956 | table_ref CROSS JOIN table_ref
6958 /* CROSS JOIN is same as unqualified inner join */
6959 JoinExpr
*n
= makeNode
(JoinExpr
);
6960 n
->jointype
= JOIN_INNER
;
6961 n
->isNatural
= FALSE
;
6968 | table_ref join_type JOIN table_ref join_qual
6970 JoinExpr
*n
= makeNode
(JoinExpr
);
6972 n
->isNatural
= FALSE
;
6975 if
($5 != NULL
&& IsA
($5, List
))
6976 n
->using
= (List
*) $5; /* USING clause */
6978 n
->quals
= $5; /* ON clause */
6981 | table_ref JOIN table_ref join_qual
6983 /* letting join_type reduce to empty doesn't work */
6984 JoinExpr
*n
= makeNode
(JoinExpr
);
6985 n
->jointype
= JOIN_INNER
;
6986 n
->isNatural
= FALSE
;
6989 if
($4 != NULL
&& IsA
($4, List
))
6990 n
->using
= (List
*) $4; /* USING clause */
6992 n
->quals
= $4; /* ON clause */
6995 | table_ref NATURAL join_type JOIN table_ref
6997 JoinExpr
*n
= makeNode
(JoinExpr
);
6999 n
->isNatural
= TRUE
;
7002 n
->using
= NIL
; /* figure out which columns later... */
7003 n
->quals
= NULL
; /* fill later */
7006 | table_ref NATURAL JOIN table_ref
7008 /* letting join_type reduce to empty doesn't work */
7009 JoinExpr
*n
= makeNode
(JoinExpr
);
7010 n
->jointype
= JOIN_INNER
;
7011 n
->isNatural
= TRUE
;
7014 n
->using
= NIL
; /* figure out which columns later... */
7015 n
->quals
= NULL
; /* fill later */
7021 AS ColId
'(' name_list
')'
7023 $$
= makeNode
(Alias
);
7029 $$
= makeNode
(Alias
);
7032 | ColId
'(' name_list
')'
7034 $$
= makeNode
(Alias
);
7040 $$
= makeNode
(Alias
);
7045 join_type: FULL join_outer
{ $$
= JOIN_FULL
; }
7046 | LEFT join_outer
{ $$
= JOIN_LEFT
; }
7047 | RIGHT join_outer
{ $$
= JOIN_RIGHT
; }
7048 | INNER_P
{ $$
= JOIN_INNER
; }
7051 /* OUTER is just noise... */
7052 join_outer: OUTER_P
{ $$
= NULL
; }
7053 |
/*EMPTY*/ { $$
= NULL
; }
7056 /* JOIN qualification clauses
7057 * Possibilities are:
7058 * USING ( column list ) allows only unqualified column names,
7059 * which must match between tables.
7060 * ON expr allows more general qualifications.
7062 * We return USING as a List node, while an ON-expr will not be a List.
7065 join_qual: USING
'(' name_list
')' { $$
= (Node
*) $3; }
7066 | ON a_expr
{ $$
= $2; }
7073 /* default inheritance */
7075 $$
->inhOpt
= INH_DEFAULT
;
7078 | qualified_name
'*'
7080 /* inheritance query */
7082 $$
->inhOpt
= INH_YES
;
7085 | ONLY qualified_name
7087 /* no inheritance */
7089 $$
->inhOpt
= INH_NO
;
7092 | ONLY
'(' qualified_name
')'
7094 /* no inheritance, SQL99-style syntax */
7096 $$
->inhOpt
= INH_NO
;
7103 * Given "UPDATE foo set set ...", we have to decide without looking any
7104 * further ahead whether the first "set" is an alias or the UPDATE's SET
7105 * keyword. Since "set" is allowed as a column name both interpretations
7106 * are feasible. We resolve the shift/reduce conflict by giving the first
7107 * relation_expr_opt_alias production a higher precedence than the SET token
7108 * has, causing the parser to prefer to reduce, in effect assuming that the
7109 * SET is not an alias.
7111 relation_expr_opt_alias: relation_expr %prec UMINUS
7115 | relation_expr ColId
7117 Alias
*alias
= makeNode
(Alias
);
7118 alias
->aliasname
= $2;
7122 | relation_expr AS ColId
7124 Alias
*alias
= makeNode
(Alias
);
7125 alias
->aliasname
= $3;
7132 func_table: func_expr
{ $$
= $1; }
7137 WHERE a_expr
{ $$
= $2; }
7138 |
/*EMPTY*/ { $$
= NULL
; }
7141 /* variant for UPDATE and DELETE */
7142 where_or_current_clause:
7143 WHERE a_expr
{ $$
= $2; }
7144 | WHERE CURRENT_P OF name
7146 CurrentOfExpr
*n
= makeNode
(CurrentOfExpr
);
7147 /* cvarno is filled in by parse analysis */
7148 n
->cursor_name
= $4;
7149 n
->cursor_param
= 0;
7152 | WHERE CURRENT_P OF PARAM
7154 CurrentOfExpr
*n
= makeNode
(CurrentOfExpr
);
7155 /* cvarno is filled in by parse analysis */
7156 n
->cursor_name
= NULL
;
7157 n
->cursor_param
= $4;
7160 |
/*EMPTY*/ { $$
= NULL
; }
7164 TableFuncElementList:
7167 $$
= list_make1
($1);
7169 | TableFuncElementList
',' TableFuncElement
7171 $$
= lappend
($1, $3);
7175 TableFuncElement: ColId Typename
7177 ColumnDef
*n
= makeNode
(ColumnDef
);
7180 n
->constraints
= NIL
;
7186 /*****************************************************************************
7189 * SQL92 introduces a large amount of type-specific syntax.
7190 * Define individual clauses to handle these cases, and use
7191 * the generic case to handle regular type-extensible Postgres syntax.
7192 * - thomas 1997-10-10
7194 *****************************************************************************/
7196 Typename: SimpleTypename opt_array_bounds
7199 $$
->arrayBounds
= $2;
7201 | SETOF SimpleTypename opt_array_bounds
7204 $$
->arrayBounds
= $3;
7207 /* SQL standard syntax, currently only one-dimensional */
7208 | SimpleTypename ARRAY
'[' Iconst
']'
7211 $$
->arrayBounds
= list_make1
(makeInteger
($4));
7213 | SETOF SimpleTypename ARRAY
'[' Iconst
']'
7216 $$
->arrayBounds
= list_make1
(makeInteger
($5));
7219 | SimpleTypename ARRAY
7222 $$
->arrayBounds
= list_make1
(makeInteger
(-1));
7224 | SETOF SimpleTypename ARRAY
7227 $$
->arrayBounds
= list_make1
(makeInteger
(-1));
7233 opt_array_bounds
'[' ']'
7234 { $$
= lappend
($1, makeInteger
(-1)); }
7235 | opt_array_bounds
'[' Iconst
']'
7236 { $$
= lappend
($1, makeInteger
($3)); }
7242 GenericType
{ $$
= $1; }
7243 | Numeric
{ $$
= $1; }
7245 | Character
{ $$
= $1; }
7246 | ConstDatetime
{ $$
= $1; }
7247 | ConstInterval opt_interval
7252 | ConstInterval
'(' Iconst
')' opt_interval
7257 if
(list_length
($5) != 1)
7259 (errcode
(ERRCODE_SYNTAX_ERROR
),
7260 errmsg
("interval precision specified twice"),
7261 scanner_errposition
(@
1)));
7262 $$
->typmods
= lappend
($5, makeIntConst
($3, @
3));
7265 $$
->typmods
= list_make2
(makeIntConst
(INTERVAL_FULL_RANGE
, -1),
7266 makeIntConst
($3, @
3));
7270 /* We have a separate ConstTypename to allow defaulting fixed-length
7271 * types such as CHAR() and BIT() to an unspecified length.
7272 * SQL9x requires that these default to a length of one, but this
7273 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
7274 * where there is an obvious better choice to make.
7275 * Note that ConstInterval is not included here since it must
7276 * be pushed up higher in the rules to accomodate the postfix
7277 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
7278 * the generic-type-name case in AExprConst to avoid premature
7279 * reduce/reduce conflicts against function names.
7282 Numeric
{ $$
= $1; }
7283 | ConstBit
{ $$
= $1; }
7284 | ConstCharacter
{ $$
= $1; }
7285 | ConstDatetime
{ $$
= $1; }
7289 * GenericType covers all type names that don't have special syntax mandated
7290 * by the standard, including qualified names. We also allow type modifiers.
7291 * To avoid parsing conflicts against function invocations, the modifiers
7292 * have to be shown as expr_list here, but parse analysis will only accept
7293 * constants for them.
7296 type_function_name opt_type_modifiers
7298 $$
= makeTypeName
($1);
7302 | type_function_name attrs opt_type_modifiers
7304 $$
= makeTypeNameFromNameList
(lcons
(makeString
($1), $2));
7310 opt_type_modifiers: '(' expr_list
')' { $$
= $2; }
7311 |
/* EMPTY */ { $$
= NIL
; }
7315 * SQL92 numeric data types
7319 $$
= SystemTypeName
("int4");
7324 $$
= SystemTypeName
("int4");
7329 $$
= SystemTypeName
("int2");
7334 $$
= SystemTypeName
("int8");
7339 $$
= SystemTypeName
("float4");
7347 | DOUBLE_P PRECISION
7349 $$
= SystemTypeName
("float8");
7352 | DECIMAL_P opt_type_modifiers
7354 $$
= SystemTypeName
("numeric");
7358 | DEC opt_type_modifiers
7360 $$
= SystemTypeName
("numeric");
7364 | NUMERIC opt_type_modifiers
7366 $$
= SystemTypeName
("numeric");
7372 $$
= SystemTypeName
("bool");
7377 opt_float: '(' Iconst
')'
7380 * Check FLOAT() precision limits assuming IEEE floating
7381 * types - thomas 1997-09-18
7385 (errcode
(ERRCODE_INVALID_PARAMETER_VALUE
),
7386 errmsg
("precision for type float must be at least 1 bit"),
7387 scanner_errposition
(@
2)));
7389 $$
= SystemTypeName
("float4");
7391 $$
= SystemTypeName
("float8");
7394 (errcode
(ERRCODE_INVALID_PARAMETER_VALUE
),
7395 errmsg
("precision for type float must be less than 54 bits"),
7396 scanner_errposition
(@
2)));
7400 $$
= SystemTypeName
("float8");
7405 * SQL92 bit-field data types
7406 * The following implements BIT() and BIT VARYING().
7418 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
7419 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
7420 ConstBit: BitWithLength
7432 BIT opt_varying
'(' expr_list
')'
7436 typname
= $2 ?
"varbit" : "bit";
7437 $$
= SystemTypeName
(typname
);
7446 /* bit defaults to bit(1), varbit to no limit */
7449 $$
= SystemTypeName
("varbit");
7453 $$
= SystemTypeName
("bit");
7454 $$
->typmods
= list_make1
(makeIntConst
(1, -1));
7462 * SQL92 character data types
7463 * The following implements CHAR() and VARCHAR().
7465 Character: CharacterWithLength
7469 | CharacterWithoutLength
7475 ConstCharacter: CharacterWithLength
7479 | CharacterWithoutLength
7481 /* Length was not specified so allow to be unrestricted.
7482 * This handles problems with fixed-length (bpchar) strings
7483 * which in column definitions must default to a length
7484 * of one, but should not be constrained if the length
7485 * was not specified.
7492 CharacterWithLength: character
'(' Iconst
')' opt_charset
7494 if
(($5 != NULL
) && (strcmp
($5, "sql_text") != 0))
7498 type
= palloc
(strlen
($1) + 1 + strlen
($5) + 1);
7505 $$
= SystemTypeName
($1);
7506 $$
->typmods
= list_make1
(makeIntConst
($3, @
3));
7511 CharacterWithoutLength: character opt_charset
7513 if
(($2 != NULL
) && (strcmp
($2, "sql_text") != 0))
7517 type
= palloc
(strlen
($1) + 1 + strlen
($2) + 1);
7524 $$
= SystemTypeName
($1);
7526 /* char defaults to char(1), varchar to no limit */
7527 if
(strcmp
($1, "bpchar") == 0)
7528 $$
->typmods
= list_make1
(makeIntConst
(1, -1));
7534 character: CHARACTER opt_varying
7535 { $$
= $2 ?
"varchar": "bpchar"; }
7536 | CHAR_P opt_varying
7537 { $$
= $2 ?
"varchar": "bpchar"; }
7540 | NATIONAL CHARACTER opt_varying
7541 { $$
= $3 ?
"varchar": "bpchar"; }
7542 | NATIONAL CHAR_P opt_varying
7543 { $$
= $3 ?
"varchar": "bpchar"; }
7545 { $$
= $2 ?
"varchar": "bpchar"; }
7549 VARYING
{ $$
= TRUE
; }
7550 |
/*EMPTY*/ { $$
= FALSE
; }
7554 CHARACTER SET ColId
{ $$
= $3; }
7555 |
/*EMPTY*/ { $$
= NULL
; }
7559 * SQL92 date/time types
7562 TIMESTAMP
'(' Iconst
')' opt_timezone
7565 $$
= SystemTypeName
("timestamptz");
7567 $$
= SystemTypeName
("timestamp");
7568 $$
->typmods
= list_make1
(makeIntConst
($3, @
3));
7571 | TIMESTAMP opt_timezone
7574 $$
= SystemTypeName
("timestamptz");
7576 $$
= SystemTypeName
("timestamp");
7579 | TIME
'(' Iconst
')' opt_timezone
7582 $$
= SystemTypeName
("timetz");
7584 $$
= SystemTypeName
("time");
7585 $$
->typmods
= list_make1
(makeIntConst
($3, @
3));
7591 $$
= SystemTypeName
("timetz");
7593 $$
= SystemTypeName
("time");
7601 $$
= SystemTypeName
("interval");
7607 WITH_TIME ZONE
{ $$
= TRUE
; }
7608 | WITHOUT TIME ZONE
{ $$
= FALSE
; }
7609 |
/*EMPTY*/ { $$
= FALSE
; }
7614 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(YEAR
), @
1)); }
7616 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(MONTH
), @
1)); }
7618 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(DAY
), @
1)); }
7620 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(HOUR
), @
1)); }
7622 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(MINUTE
), @
1)); }
7627 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(YEAR
) |
7628 INTERVAL_MASK
(MONTH
), @
1));
7632 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(DAY
) |
7633 INTERVAL_MASK
(HOUR
), @
1));
7637 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(DAY
) |
7638 INTERVAL_MASK
(HOUR
) |
7639 INTERVAL_MASK
(MINUTE
), @
1));
7641 | DAY_P TO interval_second
7644 linitial
($$
) = makeIntConst
(INTERVAL_MASK
(DAY
) |
7645 INTERVAL_MASK
(HOUR
) |
7646 INTERVAL_MASK
(MINUTE
) |
7647 INTERVAL_MASK
(SECOND
), @
1);
7649 | HOUR_P TO MINUTE_P
7651 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(HOUR
) |
7652 INTERVAL_MASK
(MINUTE
), @
1));
7654 | HOUR_P TO interval_second
7657 linitial
($$
) = makeIntConst
(INTERVAL_MASK
(HOUR
) |
7658 INTERVAL_MASK
(MINUTE
) |
7659 INTERVAL_MASK
(SECOND
), @
1);
7661 | MINUTE_P TO interval_second
7664 linitial
($$
) = makeIntConst
(INTERVAL_MASK
(MINUTE
) |
7665 INTERVAL_MASK
(SECOND
), @
1);
7674 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(SECOND
), @
1));
7676 | SECOND_P
'(' Iconst
')'
7678 $$
= list_make2
(makeIntConst
(INTERVAL_MASK
(SECOND
), @
1),
7679 makeIntConst
($3, @
3));
7684 /*****************************************************************************
7686 * expression grammar
7688 *****************************************************************************/
7691 * General expressions
7692 * This is the heart of the expression syntax.
7694 * We have two expression types: a_expr is the unrestricted kind, and
7695 * b_expr is a subset that must be used in some places to avoid shift/reduce
7696 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
7697 * because that use of AND conflicts with AND as a boolean operator. So,
7698 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
7700 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
7701 * always be used by surrounding it with parens.
7703 * c_expr is all the productions that are common to a_expr and b_expr;
7704 * it's factored out just to eliminate redundant coding.
7706 a_expr: c_expr
{ $$
= $1; }
7707 | a_expr TYPECAST Typename
7708 { $$
= makeTypeCast
($1, $3, @
2); }
7709 | a_expr AT TIME ZONE a_expr
7711 FuncCall
*n
= makeNode
(FuncCall
);
7712 n
->funcname
= SystemFuncName
("timezone");
7713 n
->args
= list_make2
($5, $1);
7714 n
->agg_star
= FALSE
;
7715 n
->agg_distinct
= FALSE
;
7716 n
->func_variadic
= FALSE
;
7721 * These operators must be called out explicitly in order to make use
7722 * of yacc/bison's automatic operator-precedence handling. All other
7723 * operator names are handled by the generic productions using "Op",
7724 * below; and all those operators will have the same precedence.
7726 * If you add more explicitly-known operators, be sure to add them
7727 * also to b_expr and to the MathOp list above.
7729 |
'+' a_expr %prec UMINUS
7730 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", NULL
, $2, @
1); }
7731 |
'-' a_expr %prec UMINUS
7732 { $$
= doNegate
($2, @
1); }
7734 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", $1, $3, @
2); }
7736 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "-", $1, $3, @
2); }
7738 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "*", $1, $3, @
2); }
7740 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "/", $1, $3, @
2); }
7742 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "%", $1, $3, @
2); }
7744 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "^", $1, $3, @
2); }
7746 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $3, @
2); }
7748 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $3, @
2); }
7750 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "=", $1, $3, @
2); }
7752 | a_expr qual_Op a_expr %prec Op
7753 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, $3, @
2); }
7754 | qual_Op a_expr %prec Op
7755 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $1, NULL
, $2, @
1); }
7756 | a_expr qual_Op %prec POSTFIXOP
7757 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, NULL
, @
2); }
7760 { $$
= (Node
*) makeA_Expr
(AEXPR_AND
, NIL
, $1, $3, @
2); }
7762 { $$
= (Node
*) makeA_Expr
(AEXPR_OR
, NIL
, $1, $3, @
2); }
7764 { $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
, $2, @
1); }
7766 | a_expr LIKE a_expr
7767 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~~", $1, $3, @
2); }
7768 | a_expr LIKE a_expr ESCAPE a_expr
7770 FuncCall
*n
= makeNode
(FuncCall
);
7771 n
->funcname
= SystemFuncName
("like_escape");
7772 n
->args
= list_make2
($3, $5);
7773 n
->agg_star
= FALSE
;
7774 n
->agg_distinct
= FALSE
;
7775 n
->func_variadic
= FALSE
;
7777 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~~", $1, (Node
*) n
, @
2);
7779 | a_expr NOT LIKE a_expr
7780 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~~", $1, $4, @
2); }
7781 | a_expr NOT LIKE a_expr ESCAPE a_expr
7783 FuncCall
*n
= makeNode
(FuncCall
);
7784 n
->funcname
= SystemFuncName
("like_escape");
7785 n
->args
= list_make2
($4, $6);
7786 n
->agg_star
= FALSE
;
7787 n
->agg_distinct
= FALSE
;
7788 n
->func_variadic
= FALSE
;
7790 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~~", $1, (Node
*) n
, @
2);
7792 | a_expr ILIKE a_expr
7793 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~~*", $1, $3, @
2); }
7794 | a_expr ILIKE a_expr ESCAPE a_expr
7796 FuncCall
*n
= makeNode
(FuncCall
);
7797 n
->funcname
= SystemFuncName
("like_escape");
7798 n
->args
= list_make2
($3, $5);
7799 n
->agg_star
= FALSE
;
7800 n
->agg_distinct
= FALSE
;
7801 n
->func_variadic
= FALSE
;
7803 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~~*", $1, (Node
*) n
, @
2);
7805 | a_expr NOT ILIKE a_expr
7806 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~~*", $1, $4, @
2); }
7807 | a_expr NOT ILIKE a_expr ESCAPE a_expr
7809 FuncCall
*n
= makeNode
(FuncCall
);
7810 n
->funcname
= SystemFuncName
("like_escape");
7811 n
->args
= list_make2
($4, $6);
7812 n
->agg_star
= FALSE
;
7813 n
->agg_distinct
= FALSE
;
7814 n
->func_variadic
= FALSE
;
7816 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~~*", $1, (Node
*) n
, @
2);
7819 | a_expr SIMILAR TO a_expr %prec SIMILAR
7821 FuncCall
*n
= makeNode
(FuncCall
);
7822 n
->funcname
= SystemFuncName
("similar_escape");
7823 n
->args
= list_make2
($4, makeNullAConst
(-1));
7824 n
->agg_star
= FALSE
;
7825 n
->agg_distinct
= FALSE
;
7826 n
->func_variadic
= FALSE
;
7828 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~", $1, (Node
*) n
, @
2);
7830 | a_expr SIMILAR TO a_expr ESCAPE a_expr
7832 FuncCall
*n
= makeNode
(FuncCall
);
7833 n
->funcname
= SystemFuncName
("similar_escape");
7834 n
->args
= list_make2
($4, $6);
7835 n
->agg_star
= FALSE
;
7836 n
->agg_distinct
= FALSE
;
7837 n
->func_variadic
= FALSE
;
7839 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~", $1, (Node
*) n
, @
2);
7841 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
7843 FuncCall
*n
= makeNode
(FuncCall
);
7844 n
->funcname
= SystemFuncName
("similar_escape");
7845 n
->args
= list_make2
($5, makeNullAConst
(-1));
7846 n
->agg_star
= FALSE
;
7847 n
->agg_distinct
= FALSE
;
7848 n
->func_variadic
= FALSE
;
7850 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~", $1, (Node
*) n
, @
2);
7852 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
7854 FuncCall
*n
= makeNode
(FuncCall
);
7855 n
->funcname
= SystemFuncName
("similar_escape");
7856 n
->args
= list_make2
($5, $7);
7857 n
->agg_star
= FALSE
;
7858 n
->agg_distinct
= FALSE
;
7859 n
->func_variadic
= FALSE
;
7861 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~", $1, (Node
*) n
, @
2);
7865 * Define SQL92-style Null test clause.
7866 * Allow two forms described in the standard:
7869 * Allow two SQL extensions
7875 NullTest
*n
= makeNode
(NullTest
);
7876 n
->arg
= (Expr
*) $1;
7877 n
->nulltesttype
= IS_NULL
;
7882 NullTest
*n
= makeNode
(NullTest
);
7883 n
->arg
= (Expr
*) $1;
7884 n
->nulltesttype
= IS_NULL
;
7887 | a_expr IS NOT NULL_P
7889 NullTest
*n
= makeNode
(NullTest
);
7890 n
->arg
= (Expr
*) $1;
7891 n
->nulltesttype
= IS_NOT_NULL
;
7896 NullTest
*n
= makeNode
(NullTest
);
7897 n
->arg
= (Expr
*) $1;
7898 n
->nulltesttype
= IS_NOT_NULL
;
7903 $$
= (Node
*)makeOverlaps
($1, $3, @
2);
7907 BooleanTest
*b
= makeNode
(BooleanTest
);
7908 b
->arg
= (Expr
*) $1;
7909 b
->booltesttype
= IS_TRUE
;
7912 | a_expr IS NOT TRUE_P
7914 BooleanTest
*b
= makeNode
(BooleanTest
);
7915 b
->arg
= (Expr
*) $1;
7916 b
->booltesttype
= IS_NOT_TRUE
;
7921 BooleanTest
*b
= makeNode
(BooleanTest
);
7922 b
->arg
= (Expr
*) $1;
7923 b
->booltesttype
= IS_FALSE
;
7926 | a_expr IS NOT FALSE_P
7928 BooleanTest
*b
= makeNode
(BooleanTest
);
7929 b
->arg
= (Expr
*) $1;
7930 b
->booltesttype
= IS_NOT_FALSE
;
7935 BooleanTest
*b
= makeNode
(BooleanTest
);
7936 b
->arg
= (Expr
*) $1;
7937 b
->booltesttype
= IS_UNKNOWN
;
7940 | a_expr IS NOT UNKNOWN
7942 BooleanTest
*b
= makeNode
(BooleanTest
);
7943 b
->arg
= (Expr
*) $1;
7944 b
->booltesttype
= IS_NOT_UNKNOWN
;
7947 | a_expr IS DISTINCT FROM a_expr %prec IS
7949 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
, "=", $1, $5, @
2);
7951 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
7953 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
,
7954 (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
,
7959 | a_expr IS OF
'(' type_list
')' %prec IS
7961 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OF
, "=", $1, (Node
*) $5, @
2);
7963 | a_expr IS NOT OF
'(' type_list
')' %prec IS
7965 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OF
, "<>", $1, (Node
*) $6, @
2);
7967 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
7969 $$
= (Node
*) makeA_Expr
(AEXPR_AND
, NIL
,
7970 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">=", $1, $4, @
2),
7971 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<=", $1, $6, @
2),
7974 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
7976 $$
= (Node
*) makeA_Expr
(AEXPR_OR
, NIL
,
7977 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $5, @
2),
7978 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $7, @
2),
7981 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
7983 $$
= (Node
*) makeA_Expr
(AEXPR_OR
, NIL
,
7984 (Node
*) makeA_Expr
(AEXPR_AND
, NIL
,
7985 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">=", $1, $4, @
2),
7986 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<=", $1, $6, @
2),
7988 (Node
*) makeA_Expr
(AEXPR_AND
, NIL
,
7989 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">=", $1, $6, @
2),
7990 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<=", $1, $4, @
2),
7994 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
7996 $$
= (Node
*) makeA_Expr
(AEXPR_AND
, NIL
,
7997 (Node
*) makeA_Expr
(AEXPR_OR
, NIL
,
7998 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $5, @
2),
7999 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $7, @
2),
8001 (Node
*) makeA_Expr
(AEXPR_OR
, NIL
,
8002 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $7, @
2),
8003 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $5, @
2),
8007 | a_expr IN_P in_expr
8009 /* in_expr returns a SubLink or a list of a_exprs */
8010 if
(IsA
($3, SubLink
))
8012 /* generate foo = ANY (subquery) */
8013 SubLink
*n
= (SubLink
*) $3;
8014 n
->subLinkType
= ANY_SUBLINK
;
8016 n
->operName
= list_make1
(makeString
("="));
8022 /* generate scalar IN expression */
8023 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_IN
, "=", $1, $3, @
2);
8026 | a_expr NOT IN_P in_expr
8028 /* in_expr returns a SubLink or a list of a_exprs */
8029 if
(IsA
($4, SubLink
))
8031 /* generate NOT (foo = ANY (subquery)) */
8032 /* Make an = ANY node */
8033 SubLink
*n
= (SubLink
*) $4;
8034 n
->subLinkType
= ANY_SUBLINK
;
8036 n
->operName
= list_make1
(makeString
("="));
8038 /* Stick a NOT on top */
8039 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
, (Node
*) n
, @
2);
8043 /* generate scalar NOT IN expression */
8044 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_IN
, "<>", $1, $4, @
2);
8047 | a_expr subquery_Op sub_type select_with_parens %prec Op
8049 SubLink
*n
= makeNode
(SubLink
);
8050 n
->subLinkType
= $3;
8057 | a_expr subquery_Op sub_type
'(' a_expr
')' %prec Op
8059 if
($3 == ANY_SUBLINK
)
8060 $$
= (Node
*) makeA_Expr
(AEXPR_OP_ANY
, $2, $1, $5, @
2);
8062 $$
= (Node
*) makeA_Expr
(AEXPR_OP_ALL
, $2, $1, $5, @
2);
8064 | UNIQUE select_with_parens
8066 /* Not sure how to get rid of the parentheses
8067 * but there are lots of shift/reduce errors without them.
8069 * Should be able to implement this by plopping the entire
8070 * select into a node, then transforming the target expressions
8071 * from whatever they are into count(*), and testing the
8072 * entire result equal to one.
8073 * But, will probably implement a separate node in the executor.
8076 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
8077 errmsg
("UNIQUE predicate is not yet implemented"),
8078 scanner_errposition
(@
1)));
8080 | a_expr IS DOCUMENT_P %prec IS
8082 $$
= makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
8083 list_make1
($1), @
2);
8085 | a_expr IS NOT DOCUMENT_P %prec IS
8087 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
,
8088 makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
8089 list_make1
($1), @
2),
8095 * Restricted expressions
8097 * b_expr is a subset of the complete expression syntax defined by a_expr.
8099 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
8100 * cause trouble in the places where b_expr is used. For simplicity, we
8101 * just eliminate all the boolean-keyword-operator productions from b_expr.
8105 | b_expr TYPECAST Typename
8106 { $$
= makeTypeCast
($1, $3, @
2); }
8107 |
'+' b_expr %prec UMINUS
8108 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", NULL
, $2, @
1); }
8109 |
'-' b_expr %prec UMINUS
8110 { $$
= doNegate
($2, @
1); }
8112 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", $1, $3, @
2); }
8114 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "-", $1, $3, @
2); }
8116 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "*", $1, $3, @
2); }
8118 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "/", $1, $3, @
2); }
8120 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "%", $1, $3, @
2); }
8122 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "^", $1, $3, @
2); }
8124 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $3, @
2); }
8126 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $3, @
2); }
8128 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "=", $1, $3, @
2); }
8129 | b_expr qual_Op b_expr %prec Op
8130 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, $3, @
2); }
8131 | qual_Op b_expr %prec Op
8132 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $1, NULL
, $2, @
1); }
8133 | b_expr qual_Op %prec POSTFIXOP
8134 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, NULL
, @
2); }
8135 | b_expr IS DISTINCT FROM b_expr %prec IS
8137 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
, "=", $1, $5, @
2);
8139 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
8141 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
,
8142 NULL
, (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
, "=", $1, $6, @
2), @
2);
8144 | b_expr IS OF
'(' type_list
')' %prec IS
8146 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OF
, "=", $1, (Node
*) $5, @
2);
8148 | b_expr IS NOT OF
'(' type_list
')' %prec IS
8150 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OF
, "<>", $1, (Node
*) $6, @
2);
8152 | b_expr IS DOCUMENT_P %prec IS
8154 $$
= makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
8155 list_make1
($1), @
2);
8157 | b_expr IS NOT DOCUMENT_P %prec IS
8159 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
,
8160 makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
8161 list_make1
($1), @
2),
8167 * Productions that can be used in both a_expr and b_expr.
8169 * Note: productions that refer recursively to a_expr or b_expr mostly
8170 * cannot appear here. However, it's OK to refer to a_exprs that occur
8171 * inside parentheses, such as function arguments; that cannot introduce
8172 * ambiguity to the b_expr syntax.
8174 c_expr: columnref
{ $$
= $1; }
8175 | AexprConst
{ $$
= $1; }
8176 | PARAM opt_indirection
8178 ParamRef
*p
= makeNode
(ParamRef
);
8183 A_Indirection
*n
= makeNode
(A_Indirection
);
8184 n
->arg
= (Node
*) p
;
8185 n
->indirection
= check_indirection
($2);
8191 |
'(' a_expr
')' opt_indirection
8195 A_Indirection
*n
= makeNode
(A_Indirection
);
8197 n
->indirection
= check_indirection
($4);
8207 | select_with_parens %prec UMINUS
8209 SubLink
*n
= makeNode
(SubLink
);
8210 n
->subLinkType
= EXPR_SUBLINK
;
8217 | EXISTS select_with_parens
8219 SubLink
*n
= makeNode
(SubLink
);
8220 n
->subLinkType
= EXISTS_SUBLINK
;
8227 | ARRAY select_with_parens
8229 SubLink
*n
= makeNode
(SubLink
);
8230 n
->subLinkType
= ARRAY_SUBLINK
;
8239 A_ArrayExpr
*n
= (A_ArrayExpr
*) $2;
8240 Assert
(IsA
(n
, A_ArrayExpr
));
8241 /* point outermost A_ArrayExpr to the ARRAY keyword */
8247 RowExpr
*r
= makeNode
(RowExpr
);
8249 r
->row_typeid
= InvalidOid
; /* not analyzed yet */
8256 * func_expr is split out from c_expr just so that we have a classification
8257 * for "everything that is a function call or looks like one". This isn't
8258 * very important, but it saves us having to document which variants are
8259 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
8260 * (Note that many of the special SQL functions wouldn't actually make any
8261 * sense as functional index entries, but we ignore that consideration here.)
8263 func_expr: func_name
'(' ')'
8265 FuncCall
*n
= makeNode
(FuncCall
);
8268 n
->agg_star
= FALSE
;
8269 n
->agg_distinct
= FALSE
;
8270 n
->func_variadic
= FALSE
;
8274 | func_name
'(' expr_list
')'
8276 FuncCall
*n
= makeNode
(FuncCall
);
8279 n
->agg_star
= FALSE
;
8280 n
->agg_distinct
= FALSE
;
8281 n
->func_variadic
= FALSE
;
8285 | func_name
'(' VARIADIC a_expr
')'
8287 FuncCall
*n
= makeNode
(FuncCall
);
8289 n
->args
= list_make1
($4);
8290 n
->agg_star
= FALSE
;
8291 n
->agg_distinct
= FALSE
;
8292 n
->func_variadic
= TRUE
;
8296 | func_name
'(' expr_list
',' VARIADIC a_expr
')'
8298 FuncCall
*n
= makeNode
(FuncCall
);
8300 n
->args
= lappend
($3, $6);
8301 n
->agg_star
= FALSE
;
8302 n
->agg_distinct
= FALSE
;
8303 n
->func_variadic
= TRUE
;
8307 | func_name
'(' ALL expr_list
')'
8309 FuncCall
*n
= makeNode
(FuncCall
);
8312 n
->agg_star
= FALSE
;
8313 n
->agg_distinct
= FALSE
;
8314 /* Ideally we'd mark the FuncCall node to indicate
8315 * "must be an aggregate", but there's no provision
8316 * for that in FuncCall at the moment.
8318 n
->func_variadic
= FALSE
;
8322 | func_name
'(' DISTINCT expr_list
')'
8324 FuncCall
*n
= makeNode
(FuncCall
);
8327 n
->agg_star
= FALSE
;
8328 n
->agg_distinct
= TRUE
;
8329 n
->func_variadic
= FALSE
;
8333 | func_name
'(' '*' ')'
8336 * We consider AGGREGATE(*) to invoke a parameterless
8337 * aggregate. This does the right thing for COUNT(*),
8338 * and there are no other aggregates in SQL92 that accept
8341 * The FuncCall node is also marked agg_star = true,
8342 * so that later processing can detect what the argument
8345 FuncCall
*n
= makeNode
(FuncCall
);
8349 n
->agg_distinct
= FALSE
;
8350 n
->func_variadic
= FALSE
;
8357 * Translate as "'now'::text::date".
8359 * We cannot use "'now'::date" because coerce_type() will
8360 * immediately reduce that to a constant representing
8361 * today's date. We need to delay the conversion until
8362 * runtime, else the wrong things will happen when
8363 * CURRENT_DATE is used in a column default value or rule.
8365 * This could be simplified if we had a way to generate
8366 * an expression tree representing runtime application
8367 * of type-input conversion functions. (As of PG 7.3
8368 * that is actually possible, but not clear that we want
8372 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8373 $$
= makeTypeCast
(n
, SystemTypeName
("date"), -1);
8378 * Translate as "'now'::text::timetz".
8379 * See comments for CURRENT_DATE.
8382 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8383 $$
= makeTypeCast
(n
, SystemTypeName
("timetz"), -1);
8385 | CURRENT_TIME
'(' Iconst
')'
8388 * Translate as "'now'::text::timetz(n)".
8389 * See comments for CURRENT_DATE.
8393 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8394 d
= SystemTypeName
("timetz");
8395 d
->typmods
= list_make1
(makeIntConst
($3, @
3));
8396 $$
= makeTypeCast
(n
, d
, -1);
8401 * Translate as "now()", since we have a function that
8402 * does exactly what is needed.
8404 FuncCall
*n
= makeNode
(FuncCall
);
8405 n
->funcname
= SystemFuncName
("now");
8407 n
->agg_star
= FALSE
;
8408 n
->agg_distinct
= FALSE
;
8409 n
->func_variadic
= FALSE
;
8413 | CURRENT_TIMESTAMP
'(' Iconst
')'
8416 * Translate as "'now'::text::timestamptz(n)".
8417 * See comments for CURRENT_DATE.
8421 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8422 d
= SystemTypeName
("timestamptz");
8423 d
->typmods
= list_make1
(makeIntConst
($3, @
3));
8424 $$
= makeTypeCast
(n
, d
, -1);
8429 * Translate as "'now'::text::time".
8430 * See comments for CURRENT_DATE.
8433 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8434 $$
= makeTypeCast
((Node
*)n
, SystemTypeName
("time"), -1);
8436 | LOCALTIME
'(' Iconst
')'
8439 * Translate as "'now'::text::time(n)".
8440 * See comments for CURRENT_DATE.
8444 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8445 d
= SystemTypeName
("time");
8446 d
->typmods
= list_make1
(makeIntConst
($3, @
3));
8447 $$
= makeTypeCast
((Node
*)n
, d
, -1);
8452 * Translate as "'now'::text::timestamp".
8453 * See comments for CURRENT_DATE.
8456 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8457 $$
= makeTypeCast
(n
, SystemTypeName
("timestamp"), -1);
8459 | LOCALTIMESTAMP
'(' Iconst
')'
8462 * Translate as "'now'::text::timestamp(n)".
8463 * See comments for CURRENT_DATE.
8467 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8468 d
= SystemTypeName
("timestamp");
8469 d
->typmods
= list_make1
(makeIntConst
($3, @
3));
8470 $$
= makeTypeCast
(n
, d
, -1);
8474 FuncCall
*n
= makeNode
(FuncCall
);
8475 n
->funcname
= SystemFuncName
("current_user");
8477 n
->agg_star
= FALSE
;
8478 n
->agg_distinct
= FALSE
;
8479 n
->func_variadic
= FALSE
;
8485 FuncCall
*n
= makeNode
(FuncCall
);
8486 n
->funcname
= SystemFuncName
("current_user");
8488 n
->agg_star
= FALSE
;
8489 n
->agg_distinct
= FALSE
;
8490 n
->func_variadic
= FALSE
;
8496 FuncCall
*n
= makeNode
(FuncCall
);
8497 n
->funcname
= SystemFuncName
("session_user");
8499 n
->agg_star
= FALSE
;
8500 n
->agg_distinct
= FALSE
;
8501 n
->func_variadic
= FALSE
;
8507 FuncCall
*n
= makeNode
(FuncCall
);
8508 n
->funcname
= SystemFuncName
("current_user");
8510 n
->agg_star
= FALSE
;
8511 n
->agg_distinct
= FALSE
;
8512 n
->func_variadic
= FALSE
;
8518 FuncCall
*n
= makeNode
(FuncCall
);
8519 n
->funcname
= SystemFuncName
("current_database");
8521 n
->agg_star
= FALSE
;
8522 n
->agg_distinct
= FALSE
;
8523 n
->func_variadic
= FALSE
;
8529 FuncCall
*n
= makeNode
(FuncCall
);
8530 n
->funcname
= SystemFuncName
("current_schema");
8532 n
->agg_star
= FALSE
;
8533 n
->agg_distinct
= FALSE
;
8534 n
->func_variadic
= FALSE
;
8538 | CAST
'(' a_expr AS Typename
')'
8539 { $$
= makeTypeCast
($3, $5, @
1); }
8540 | EXTRACT
'(' extract_list
')'
8542 FuncCall
*n
= makeNode
(FuncCall
);
8543 n
->funcname
= SystemFuncName
("date_part");
8545 n
->agg_star
= FALSE
;
8546 n
->agg_distinct
= FALSE
;
8547 n
->func_variadic
= FALSE
;
8551 | OVERLAY
'(' overlay_list
')'
8553 /* overlay(A PLACING B FROM C FOR D) is converted to
8554 * substring(A, 1, C-1) || B || substring(A, C+1, C+D)
8555 * overlay(A PLACING B FROM C) is converted to
8556 * substring(A, 1, C-1) || B || substring(A, C+1, C+char_length(B))
8558 FuncCall
*n
= makeNode
(FuncCall
);
8559 n
->funcname
= SystemFuncName
("overlay");
8561 n
->agg_star
= FALSE
;
8562 n
->agg_distinct
= FALSE
;
8563 n
->func_variadic
= FALSE
;
8567 | POSITION
'(' position_list
')'
8569 /* position(A in B) is converted to position(B, A) */
8570 FuncCall
*n
= makeNode
(FuncCall
);
8571 n
->funcname
= SystemFuncName
("position");
8573 n
->agg_star
= FALSE
;
8574 n
->agg_distinct
= FALSE
;
8575 n
->func_variadic
= FALSE
;
8579 | SUBSTRING
'(' substr_list
')'
8581 /* substring(A from B for C) is converted to
8582 * substring(A, B, C) - thomas 2000-11-28
8584 FuncCall
*n
= makeNode
(FuncCall
);
8585 n
->funcname
= SystemFuncName
("substring");
8587 n
->agg_star
= FALSE
;
8588 n
->agg_distinct
= FALSE
;
8589 n
->func_variadic
= FALSE
;
8593 | TREAT
'(' a_expr AS Typename
')'
8595 /* TREAT(expr AS target) converts expr of a particular type to target,
8596 * which is defined to be a subtype of the original expression.
8597 * In SQL99, this is intended for use with structured UDTs,
8598 * but let's make this a generally useful form allowing stronger
8599 * coercions than are handled by implicit casting.
8601 FuncCall
*n
= makeNode
(FuncCall
);
8602 /* Convert SystemTypeName() to SystemFuncName() even though
8603 * at the moment they result in the same thing.
8605 n
->funcname
= SystemFuncName
(((Value
*)llast
($5->names
))->val.str
);
8606 n
->args
= list_make1
($3);
8607 n
->agg_star
= FALSE
;
8608 n
->agg_distinct
= FALSE
;
8609 n
->func_variadic
= FALSE
;
8613 | TRIM
'(' BOTH trim_list
')'
8615 /* various trim expressions are defined in SQL92
8616 * - thomas 1997-07-19
8618 FuncCall
*n
= makeNode
(FuncCall
);
8619 n
->funcname
= SystemFuncName
("btrim");
8621 n
->agg_star
= FALSE
;
8622 n
->agg_distinct
= FALSE
;
8623 n
->func_variadic
= FALSE
;
8627 | TRIM
'(' LEADING trim_list
')'
8629 FuncCall
*n
= makeNode
(FuncCall
);
8630 n
->funcname
= SystemFuncName
("ltrim");
8632 n
->agg_star
= FALSE
;
8633 n
->agg_distinct
= FALSE
;
8634 n
->func_variadic
= FALSE
;
8638 | TRIM
'(' TRAILING trim_list
')'
8640 FuncCall
*n
= makeNode
(FuncCall
);
8641 n
->funcname
= SystemFuncName
("rtrim");
8643 n
->agg_star
= FALSE
;
8644 n
->agg_distinct
= FALSE
;
8645 n
->func_variadic
= FALSE
;
8649 | TRIM
'(' trim_list
')'
8651 FuncCall
*n
= makeNode
(FuncCall
);
8652 n
->funcname
= SystemFuncName
("btrim");
8654 n
->agg_star
= FALSE
;
8655 n
->agg_distinct
= FALSE
;
8656 n
->func_variadic
= FALSE
;
8660 | NULLIF
'(' a_expr
',' a_expr
')'
8662 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_NULLIF
, "=", $3, $5, @
1);
8664 | COALESCE
'(' expr_list
')'
8666 CoalesceExpr
*c
= makeNode
(CoalesceExpr
);
8671 | GREATEST
'(' expr_list
')'
8673 MinMaxExpr
*v
= makeNode
(MinMaxExpr
);
8675 v
->op
= IS_GREATEST
;
8679 | LEAST
'(' expr_list
')'
8681 MinMaxExpr
*v
= makeNode
(MinMaxExpr
);
8687 | XMLCONCAT
'(' expr_list
')'
8689 $$
= makeXmlExpr
(IS_XMLCONCAT
, NULL
, NIL
, $3, @
1);
8691 | XMLELEMENT
'(' NAME_P ColLabel
')'
8693 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, NIL
, NIL
, @
1);
8695 | XMLELEMENT
'(' NAME_P ColLabel
',' xml_attributes
')'
8697 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, $6, NIL
, @
1);
8699 | XMLELEMENT
'(' NAME_P ColLabel
',' expr_list
')'
8701 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, NIL
, $6, @
1);
8703 | XMLELEMENT
'(' NAME_P ColLabel
',' xml_attributes
',' expr_list
')'
8705 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, $6, $8, @
1);
8707 | XMLFOREST
'(' xml_attribute_list
')'
8709 $$
= makeXmlExpr
(IS_XMLFOREST
, NULL
, $3, NIL
, @
1);
8711 | XMLPARSE
'(' document_or_content a_expr xml_whitespace_option
')'
8713 XmlExpr
*x
= (XmlExpr
*)
8714 makeXmlExpr
(IS_XMLPARSE
, NULL
, NIL
,
8715 list_make2
($4, makeBoolAConst
($5, -1)),
8720 | XMLPI
'(' NAME_P ColLabel
')'
8722 $$
= makeXmlExpr
(IS_XMLPI
, $4, NULL
, NIL
, @
1);
8724 | XMLPI
'(' NAME_P ColLabel
',' a_expr
')'
8726 $$
= makeXmlExpr
(IS_XMLPI
, $4, NULL
, list_make1
($6), @
1);
8728 | XMLROOT
'(' a_expr
',' xml_root_version opt_xml_root_standalone
')'
8730 $$
= makeXmlExpr
(IS_XMLROOT
, NULL
, NIL
,
8731 list_make3
($3, $5, $6), @
1);
8733 | XMLSERIALIZE
'(' document_or_content a_expr AS SimpleTypename
')'
8735 XmlSerialize
*n
= makeNode
(XmlSerialize
);
8747 xml_root_version: VERSION_P a_expr
8749 | VERSION_P NO VALUE_P
8750 { $$
= makeNullAConst
(-1); }
8753 opt_xml_root_standalone: ',' STANDALONE_P YES_P
8754 { $$
= makeIntConst
(XML_STANDALONE_YES
, -1); }
8755 |
',' STANDALONE_P NO
8756 { $$
= makeIntConst
(XML_STANDALONE_NO
, -1); }
8757 |
',' STANDALONE_P NO VALUE_P
8758 { $$
= makeIntConst
(XML_STANDALONE_NO_VALUE
, -1); }
8760 { $$
= makeIntConst
(XML_STANDALONE_OMITTED
, -1); }
8763 xml_attributes: XMLATTRIBUTES
'(' xml_attribute_list
')' { $$
= $3; }
8766 xml_attribute_list: xml_attribute_el
{ $$
= list_make1
($1); }
8767 | xml_attribute_list
',' xml_attribute_el
{ $$
= lappend
($1, $3); }
8770 xml_attribute_el: a_expr AS ColLabel
8772 $$
= makeNode
(ResTarget
);
8774 $$
->indirection
= NIL
;
8775 $$
->val
= (Node
*) $1;
8780 $$
= makeNode
(ResTarget
);
8782 $$
->indirection
= NIL
;
8783 $$
->val
= (Node
*) $1;
8788 document_or_content: DOCUMENT_P
{ $$
= XMLOPTION_DOCUMENT
; }
8789 | CONTENT_P
{ $$
= XMLOPTION_CONTENT
; }
8792 xml_whitespace_option: PRESERVE WHITESPACE_P
{ $$
= TRUE
; }
8793 | STRIP_P WHITESPACE_P
{ $$
= FALSE
; }
8794 |
/*EMPTY*/ { $$
= FALSE
; }
8798 * Supporting nonterminals for expressions.
8801 /* Explicit row production.
8803 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
8804 * without conflicting with the parenthesized a_expr production. Without the
8805 * ROW keyword, there must be more than one a_expr inside the parens.
8807 row: ROW
'(' expr_list
')' { $$
= $3; }
8808 | ROW
'(' ')' { $$
= NIL
; }
8809 |
'(' expr_list
',' a_expr
')' { $$
= lappend
($2, $4); }
8812 sub_type: ANY
{ $$
= ANY_SUBLINK
; }
8813 | SOME
{ $$
= ANY_SUBLINK
; }
8814 | ALL
{ $$
= ALL_SUBLINK
; }
8817 all_Op: Op
{ $$
= $1; }
8818 | MathOp
{ $$
= $1; }
8821 MathOp: '+' { $$
= "+"; }
8833 { $$
= list_make1
(makeString
($1)); }
8834 | OPERATOR
'(' any_operator
')'
8840 { $$
= list_make1
(makeString
($1)); }
8841 | OPERATOR
'(' any_operator
')'
8847 { $$
= list_make1
(makeString
($1)); }
8848 | OPERATOR
'(' any_operator
')'
8851 { $$
= list_make1
(makeString
("~~")); }
8853 { $$
= list_make1
(makeString
("!~~")); }
8855 { $$
= list_make1
(makeString
("~~*")); }
8857 { $$
= list_make1
(makeString
("!~~*")); }
8858 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
8859 * the regular expression is preprocessed by a function (similar_escape),
8860 * and the ~ operator for posix regular expressions is used.
8861 * x SIMILAR TO y -> x ~ similar_escape(y)
8862 * this transformation is made on the fly by the parser upwards.
8863 * however the SubLink structure which handles any/some/all stuff
8864 * is not ready for such a thing.
8870 $$
= list_make1
($1);
8872 | expr_list
',' a_expr
8874 $$
= lappend
($1, $3);
8878 type_list: Typename
{ $$
= list_make1
($1); }
8879 | type_list
',' Typename
{ $$
= lappend
($1, $3); }
8882 array_expr: '[' expr_list
']'
8884 $$
= makeAArrayExpr
($2, @
1);
8886 |
'[' array_expr_list
']'
8888 $$
= makeAArrayExpr
($2, @
1);
8892 $$
= makeAArrayExpr
(NIL
, @
1);
8896 array_expr_list: array_expr
{ $$
= list_make1
($1); }
8897 | array_expr_list
',' array_expr
{ $$
= lappend
($1, $3); }
8902 extract_arg FROM a_expr
8904 $$
= list_make2
(makeStringConst
($1, @
1), $3);
8906 |
/*EMPTY*/ { $$
= NIL
; }
8909 /* Allow delimited string Sconst in extract_arg as an SQL extension.
8910 * - thomas 2001-04-12
8914 | YEAR_P
{ $$
= "year"; }
8915 | MONTH_P
{ $$
= "month"; }
8916 | DAY_P
{ $$
= "day"; }
8917 | HOUR_P
{ $$
= "hour"; }
8918 | MINUTE_P
{ $$
= "minute"; }
8919 | SECOND_P
{ $$
= "second"; }
8920 | Sconst
{ $$
= $1; }
8923 /* OVERLAY() arguments
8924 * SQL99 defines the OVERLAY() function:
8925 * o overlay(text placing text from int for int)
8926 * o overlay(text placing text from int)
8929 a_expr overlay_placing substr_from substr_for
8931 $$
= list_make4
($1, $2, $3, $4);
8933 | a_expr overlay_placing substr_from
8935 $$
= list_make3
($1, $2, $3);
8944 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
8947 b_expr IN_P b_expr
{ $$
= list_make2
($3, $1); }
8948 |
/*EMPTY*/ { $$
= NIL
; }
8951 /* SUBSTRING() arguments
8952 * SQL9x defines a specific syntax for arguments to SUBSTRING():
8953 * o substring(text from int for int)
8954 * o substring(text from int) get entire string from starting point "int"
8955 * o substring(text for int) get first "int" characters of string
8956 * o substring(text from pattern) get entire string matching pattern
8957 * o substring(text from pattern for escape) same with specified escape char
8958 * We also want to support generic substring functions which accept
8959 * the usual generic list of arguments. So we will accept both styles
8960 * here, and convert the SQL9x style to the generic list for further
8961 * processing. - thomas 2000-11-28
8964 a_expr substr_from substr_for
8966 $$
= list_make3
($1, $2, $3);
8968 | a_expr substr_for substr_from
8970 /* not legal per SQL99, but might as well allow it */
8971 $$
= list_make3
($1, $3, $2);
8973 | a_expr substr_from
8975 $$
= list_make2
($1, $2);
8980 * Since there are no cases where this syntax allows
8981 * a textual FOR value, we forcibly cast the argument
8982 * to int4. The possible matches in pg_proc are
8983 * substring(text,int4) and substring(text,text),
8984 * and we don't want the parser to choose the latter,
8985 * which it is likely to do if the second argument
8986 * is unknown or doesn't have an implicit cast to int4.
8988 $$
= list_make3
($1, makeIntConst
(1, -1),
8990 SystemTypeName
("int4"), -1));
9001 FROM a_expr
{ $$
= $2; }
9004 substr_for: FOR a_expr
{ $$
= $2; }
9007 trim_list: a_expr FROM expr_list
{ $$
= lappend
($3, $1); }
9008 | FROM expr_list
{ $$
= $2; }
9009 | expr_list
{ $$
= $1; }
9012 in_expr: select_with_parens
9014 SubLink
*n
= makeNode
(SubLink
);
9016 /* other fields will be filled later */
9019 |
'(' expr_list
')' { $$
= (Node
*)$2; }
9023 * Define SQL92-style case clause.
9024 * - Full specification
9025 * CASE WHEN a = b THEN c ... ELSE d END
9026 * - Implicit argument
9027 * CASE a WHEN b THEN c ... ELSE d END
9029 case_expr: CASE case_arg when_clause_list case_default END_P
9031 CaseExpr
*c
= makeNode
(CaseExpr
);
9032 c
->casetype
= InvalidOid
; /* not analyzed yet */
9033 c
->arg
= (Expr
*) $2;
9035 c
->defresult
= (Expr
*) $4;
9042 /* There must be at least one */
9043 when_clause
{ $$
= list_make1
($1); }
9044 | when_clause_list when_clause
{ $$
= lappend
($1, $2); }
9048 WHEN a_expr THEN a_expr
9050 CaseWhen
*w
= makeNode
(CaseWhen
);
9051 w
->expr
= (Expr
*) $2;
9052 w
->result
= (Expr
*) $4;
9059 ELSE a_expr
{ $$
= $2; }
9060 |
/*EMPTY*/ { $$
= NULL
; }
9063 case_arg: a_expr
{ $$
= $1; }
9064 |
/*EMPTY*/ { $$
= NULL
; }
9068 * columnref starts with relation_name not ColId, so that OLD and NEW
9069 * references can be accepted. Note that when there are more than two
9070 * dotted names, the first name is not actually a relation name...
9072 columnref: relation_name
9074 $$
= makeColumnRef
($1, NIL
, @
1);
9076 | relation_name indirection
9078 $$
= makeColumnRef
($1, $2, @
1);
9085 $$
= (Node
*) makeString
($2);
9089 $$
= (Node
*) makeNode
(A_Star
);
9093 A_Indices
*ai
= makeNode
(A_Indices
);
9098 |
'[' a_expr
':' a_expr
']'
9100 A_Indices
*ai
= makeNode
(A_Indices
);
9108 indirection_el
{ $$
= list_make1
($1); }
9109 | indirection indirection_el
{ $$
= lappend
($1, $2); }
9113 /*EMPTY*/ { $$
= NIL
; }
9114 | opt_indirection indirection_el
{ $$
= lappend
($1, $2); }
9117 opt_asymmetric: ASYMMETRIC
9122 * The SQL spec defines "contextually typed value expressions" and
9123 * "contextually typed row value constructors", which for our purposes
9124 * are the same as "a_expr" and "row" except that DEFAULT can appear at
9129 a_expr
{ $$
= (Node
*) $1; }
9132 SetToDefault
*n
= makeNode
(SetToDefault
);
9139 ctext_expr
{ $$
= list_make1
($1); }
9140 | ctext_expr_list
',' ctext_expr
{ $$
= lappend
($1, $3); }
9144 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
9145 * making VALUES a fully reserved word, which will probably break more apps
9146 * than allowing the noise-word is worth.
9148 ctext_row: '(' ctext_expr_list
')' { $$
= $2; }
9152 /*****************************************************************************
9154 * target list for SELECT
9156 *****************************************************************************/
9159 target_el
{ $$
= list_make1
($1); }
9160 | target_list
',' target_el
{ $$
= lappend
($1, $3); }
9163 target_el: a_expr AS ColLabel
9165 $$
= makeNode
(ResTarget
);
9167 $$
->indirection
= NIL
;
9168 $$
->val
= (Node
*)$1;
9172 * We support omitting AS only for column labels that aren't
9173 * any known keyword. There is an ambiguity against postfix
9174 * operators: is "a ! b" an infix expression, or a postfix
9175 * expression and a column label? We prefer to resolve this
9176 * as an infix expression, which we accomplish by assigning
9177 * IDENT a precedence higher than POSTFIXOP.
9181 $$
= makeNode
(ResTarget
);
9183 $$
->indirection
= NIL
;
9184 $$
->val
= (Node
*)$1;
9189 $$
= makeNode
(ResTarget
);
9191 $$
->indirection
= NIL
;
9192 $$
->val
= (Node
*)$1;
9197 ColumnRef
*n
= makeNode
(ColumnRef
);
9198 n
->fields
= list_make1
(makeNode
(A_Star
));
9201 $$
= makeNode
(ResTarget
);
9203 $$
->indirection
= NIL
;
9204 $$
->val
= (Node
*)n
;
9210 /*****************************************************************************
9212 * Names and constants
9214 *****************************************************************************/
9217 SpecialRuleRelation
{ $$
= $1; }
9218 | ColId
{ $$
= $1; }
9221 qualified_name_list:
9222 qualified_name
{ $$
= list_make1
($1); }
9223 | qualified_name_list
',' qualified_name
{ $$
= lappend
($1, $3); }
9227 * The production for a qualified relation name has to exactly match the
9228 * production for a qualified func_name, because in a FROM clause we cannot
9229 * tell which we are parsing until we see what comes after it ('(' for a
9230 * func_name, something else for a relation). Therefore we allow 'indirection'
9231 * which may contain subscripts, and reject that case in the C code.
9236 $$
= makeNode
(RangeVar
);
9237 $$
->catalogname
= NULL
;
9238 $$
->schemaname
= NULL
;
9242 | relation_name indirection
9244 check_qualified_name
($2);
9245 $$
= makeNode
(RangeVar
);
9246 switch
(list_length
($2))
9249 $$
->catalogname
= NULL
;
9250 $$
->schemaname
= $1;
9251 $$
->relname
= strVal
(linitial
($2));
9254 $$
->catalogname
= $1;
9255 $$
->schemaname
= strVal
(linitial
($2));
9256 $$
->relname
= strVal
(lsecond
($2));
9260 (errcode
(ERRCODE_SYNTAX_ERROR
),
9261 errmsg
("improper qualified name (too many dotted names): %s",
9262 NameListToString
(lcons
(makeString
($1), $2))),
9263 scanner_errposition
(@
1)));
9271 { $$
= list_make1
(makeString
($1)); }
9272 | name_list
',' name
9273 { $$
= lappend
($1, makeString
($3)); }
9277 name: ColId
{ $$
= $1; };
9285 attr_name: ColLabel
{ $$
= $1; };
9287 index_name: ColId
{ $$
= $1; };
9289 file_name: Sconst
{ $$
= $1; };
9292 * The production for a qualified func_name has to exactly match the
9293 * production for a qualified columnref, because we cannot tell which we
9294 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
9295 * anything else for a columnref). Therefore we allow 'indirection' which
9296 * may contain subscripts, and reject that case in the C code. (If we
9297 * ever implement SQL99-like methods, such syntax may actually become legal!)
9299 func_name: type_function_name
9300 { $$
= list_make1
(makeString
($1)); }
9301 | relation_name indirection
9302 { $$
= check_func_name
(lcons
(makeString
($1), $2)); }
9311 $$
= makeIntConst
($1, @
1);
9315 $$
= makeFloatConst
($1, @
1);
9319 $$
= makeStringConst
($1, @
1);
9323 $$
= makeBitStringConst
($1, @
1);
9327 /* This is a bit constant per SQL99:
9328 * Without Feature F511, "BIT data type",
9329 * a <general literal> shall not be a
9330 * <bit string literal> or a <hex string literal>.
9332 $$
= makeBitStringConst
($1, @
1);
9336 /* generic type 'literal' syntax */
9337 TypeName
*t
= makeTypeNameFromNameList
($1);
9339 $$
= makeStringConstCast
($2, @
2, t
);
9341 | func_name
'(' expr_list
')' Sconst
9343 /* generic syntax with a type modifier */
9344 TypeName
*t
= makeTypeNameFromNameList
($1);
9347 $$
= makeStringConstCast
($5, @
5, t
);
9349 | ConstTypename Sconst
9351 $$
= makeStringConstCast
($2, @
2, $1);
9353 | ConstInterval Sconst opt_interval
9357 $$
= makeStringConstCast
($2, @
2, t
);
9359 | ConstInterval
'(' Iconst
')' Sconst opt_interval
9364 if
(list_length
($6) != 1)
9366 (errcode
(ERRCODE_SYNTAX_ERROR
),
9367 errmsg
("interval precision specified twice"),
9368 scanner_errposition
(@
1)));
9369 t
->typmods
= lappend
($6, makeIntConst
($3, @
3));
9372 t
->typmods
= list_make2
(makeIntConst
(INTERVAL_FULL_RANGE
, -1),
9373 makeIntConst
($3, @
3));
9374 $$
= makeStringConstCast
($5, @
5, t
);
9378 $$
= makeBoolAConst
(TRUE
, @
1);
9382 $$
= makeBoolAConst
(FALSE
, @
1);
9386 $$
= makeNullAConst
(@
1);
9390 Iconst: ICONST
{ $$
= $1; };
9391 Sconst: SCONST
{ $$
= $1; };
9392 RoleId: ColId
{ $$
= $1; };
9394 SignedIconst: Iconst
{ $$
= $1; }
9395 |
'+' Iconst
{ $$
= + $2; }
9396 |
'-' Iconst
{ $$
= - $2; }
9400 * Name classification hierarchy.
9402 * IDENT is the lexeme returned by the lexer for identifiers that match
9403 * no known keyword. In most cases, we can accept certain keywords as
9404 * names, not only IDENTs. We prefer to accept as many such keywords
9405 * as possible to minimize the impact of "reserved words" on programmers.
9406 * So, we divide names into several possible classes. The classification
9407 * is chosen in part to make keywords acceptable as names wherever possible.
9410 /* Column identifier --- names that can be column, table, etc names.
9412 ColId: IDENT
{ $$
= $1; }
9413 | unreserved_keyword
{ $$
= pstrdup
($1); }
9414 | col_name_keyword
{ $$
= pstrdup
($1); }
9417 /* Type/function identifier --- names that can be type or function names.
9419 type_function_name: IDENT
{ $$
= $1; }
9420 | unreserved_keyword
{ $$
= pstrdup
($1); }
9421 | type_func_name_keyword
{ $$
= pstrdup
($1); }
9424 /* Column label --- allowed labels in "AS" clauses.
9425 * This presently includes *all* Postgres keywords.
9427 ColLabel: IDENT
{ $$
= $1; }
9428 | unreserved_keyword
{ $$
= pstrdup
($1); }
9429 | col_name_keyword
{ $$
= pstrdup
($1); }
9430 | type_func_name_keyword
{ $$
= pstrdup
($1); }
9431 | reserved_keyword
{ $$
= pstrdup
($1); }
9436 * Keyword category lists. Generally, every keyword present in
9437 * the Postgres grammar should appear in exactly one of these lists.
9439 * Put a new keyword into the first list that it can go into without causing
9440 * shift or reduce conflicts. The earlier lists define "less reserved"
9441 * categories of keywords.
9443 * Make sure that each keyword's category in keywords.c matches where
9444 * it is listed here. (Someday we may be able to generate these lists and
9445 * keywords.c's table from a common master list.)
9448 /* "Unreserved" keywords --- available for use as any kind of name.
9690 /* Column identifier --- keywords that can be column, table, etc names.
9692 * Many of these keywords will in fact be recognized as type or function
9693 * names too; but they have special productions for the purpose, and so
9694 * can't be treated as "generic" type or function names.
9696 * The type names appearing here are not usable as function names
9697 * because they can be followed by '(' in typename productions, which
9698 * looks too much like a function call for an LR(1) parser.
9748 /* Type/function identifier --- keywords that can be type or function names.
9750 * Most of these are keywords that are used as operators in expressions;
9751 * in general such keywords can't be column names because they would be
9752 * ambiguous with variables, but they are unambiguous as function identifiers.
9754 * Do not include POSITION, SUBSTRING, etc here since they have explicit
9755 * productions in a_expr to support the goofy SQL9x argument syntax.
9756 * - thomas 2000-11-28
9758 type_func_name_keyword:
9782 /* Reserved keyword --- these keywords are usable only as a ColLabel.
9784 * Keywords appear here if they could not be distinguished from variable,
9785 * type, or function names in some contexts. Don't put things here unless
9870 SpecialRuleRelation:
9877 (errcode
(ERRCODE_SYNTAX_ERROR
),
9878 errmsg
("OLD used in query that is not in a rule"),
9879 scanner_errposition
(@
1)));
9887 (errcode
(ERRCODE_SYNTAX_ERROR
),
9888 errmsg
("NEW used in query that is not in a rule"),
9889 scanner_errposition
(@
1)));
9896 makeColumnRef
(char *colname
, List
*indirection
, int location
)
9899 * Generate a ColumnRef node, with an A_Indirection node added if there
9900 * is any subscripting in the specified indirection list. However,
9901 * any field selection at the start of the indirection list must be
9902 * transposed into the "fields" part of the ColumnRef node.
9904 ColumnRef
*c
= makeNode
(ColumnRef
);
9908 c
->location
= location
;
9909 foreach
(l
, indirection
)
9911 if
(IsA
(lfirst
(l
), A_Indices
))
9913 A_Indirection
*i
= makeNode
(A_Indirection
);
9917 /* easy case - all indirection goes to A_Indirection */
9918 c
->fields
= list_make1
(makeString
(colname
));
9919 i
->indirection
= check_indirection
(indirection
);
9923 /* got to split the list in two */
9924 i
->indirection
= check_indirection
(list_copy_tail
(indirection
,
9926 indirection
= list_truncate
(indirection
, nfields
);
9927 c
->fields
= lcons
(makeString
(colname
), indirection
);
9929 i
->arg
= (Node
*) c
;
9932 else if
(IsA
(lfirst
(l
), A_Star
))
9934 /* We only allow '*' at the end of a ColumnRef */
9935 if
(lnext
(l
) != NULL
)
9936 yyerror("improper use of \"*\"");
9940 /* No subscripting, so all indirection gets added to field list */
9941 c
->fields
= lcons
(makeString
(colname
), indirection
);
9946 makeTypeCast
(Node
*arg
, TypeName
*typename
, int location
)
9948 TypeCast
*n
= makeNode
(TypeCast
);
9950 n
->typename
= typename
;
9951 n
->location
= location
;
9956 makeStringConst
(char *str
, int location
)
9958 A_Const
*n
= makeNode
(A_Const
);
9960 n
->val.type
= T_String
;
9961 n
->val.val.str
= str
;
9962 n
->location
= location
;
9968 makeStringConstCast
(char *str
, int location
, TypeName
*typename
)
9970 Node
*s
= makeStringConst
(str
, location
);
9972 return makeTypeCast
(s
, typename
, -1);
9976 makeIntConst
(int val
, int location
)
9978 A_Const
*n
= makeNode
(A_Const
);
9980 n
->val.type
= T_Integer
;
9981 n
->val.val.ival
= val
;
9982 n
->location
= location
;
9988 makeFloatConst
(char *str
, int location
)
9990 A_Const
*n
= makeNode
(A_Const
);
9992 n
->val.type
= T_Float
;
9993 n
->val.val.str
= str
;
9994 n
->location
= location
;
10000 makeBitStringConst
(char *str
, int location
)
10002 A_Const
*n
= makeNode
(A_Const
);
10004 n
->val.type
= T_BitString
;
10005 n
->val.val.str
= str
;
10006 n
->location
= location
;
10012 makeNullAConst
(int location
)
10014 A_Const
*n
= makeNode
(A_Const
);
10016 n
->val.type
= T_Null
;
10017 n
->location
= location
;
10023 makeAConst
(Value
*v
, int location
)
10030 n
= makeFloatConst
(v
->val.str
, location
);
10034 n
= makeIntConst
(v
->val.ival
, location
);
10039 n
= makeStringConst
(v
->val.str
, location
);
10046 /* makeBoolAConst()
10047 * Create an A_Const string node and put it inside a boolean cast.
10050 makeBoolAConst
(bool state
, int location
)
10052 A_Const
*n
= makeNode
(A_Const
);
10054 n
->val.type
= T_String
;
10055 n
->val.val.str
= (state ?
"t" : "f");
10056 n
->location
= location
;
10058 return makeTypeCast
((Node
*)n
, SystemTypeName
("bool"), -1);
10062 * Create and populate a FuncCall node to support the OVERLAPS operator.
10065 makeOverlaps
(List
*largs
, List
*rargs
, int location
)
10067 FuncCall
*n
= makeNode
(FuncCall
);
10069 n
->funcname
= SystemFuncName
("overlaps");
10070 if
(list_length
(largs
) == 1)
10071 largs
= lappend
(largs
, largs
);
10072 else if
(list_length
(largs
) != 2)
10074 (errcode
(ERRCODE_SYNTAX_ERROR
),
10075 errmsg
("wrong number of parameters on left side of OVERLAPS expression"),
10076 scanner_errposition
(location
)));
10077 if
(list_length
(rargs
) == 1)
10078 rargs
= lappend
(rargs
, rargs
);
10079 else if
(list_length
(rargs
) != 2)
10081 (errcode
(ERRCODE_SYNTAX_ERROR
),
10082 errmsg
("wrong number of parameters on right side of OVERLAPS expression"),
10083 scanner_errposition
(location
)));
10084 n
->args
= list_concat
(largs
, rargs
);
10085 n
->agg_star
= FALSE
;
10086 n
->agg_distinct
= FALSE
;
10087 n
->func_variadic
= FALSE
;
10088 n
->location
= location
;
10092 /* check_qualified_name --- check the result of qualified_name production
10094 * It's easiest to let the grammar production for qualified_name allow
10095 * subscripts and '*', which we then must reject here.
10098 check_qualified_name
(List
*names
)
10104 if
(!IsA
(lfirst
(i
), String
))
10105 yyerror("syntax error");
10109 /* check_func_name --- check the result of func_name production
10111 * It's easiest to let the grammar production for func_name allow subscripts
10112 * and '*', which we then must reject here.
10115 check_func_name
(List
*names
)
10121 if
(!IsA
(lfirst
(i
), String
))
10122 yyerror("syntax error");
10127 /* check_indirection --- check the result of indirection production
10129 * We only allow '*' at the end of the list, but it's hard to enforce that
10130 * in the grammar, so do it here.
10133 check_indirection
(List
*indirection
)
10137 foreach
(l
, indirection
)
10139 if
(IsA
(lfirst
(l
), A_Star
))
10141 if
(lnext
(l
) != NULL
)
10142 yyerror("improper use of \"*\"");
10145 return indirection
;
10148 /* extractArgTypes()
10149 * Given a list of FunctionParameter nodes, extract a list of just the
10150 * argument types (TypeNames) for input parameters only. This is what
10151 * is needed to look up an existing function, which is what is wanted by
10152 * the productions that use this call.
10155 extractArgTypes
(List
*parameters
)
10157 List
*result
= NIL
;
10160 foreach
(i
, parameters
)
10162 FunctionParameter
*p
= (FunctionParameter
*) lfirst
(i
);
10164 if
(p
->mode
!= FUNC_PARAM_OUT
&& p
->mode
!= FUNC_PARAM_TABLE
)
10165 result
= lappend
(result
, p
->argType
);
10170 /* findLeftmostSelect()
10171 * Find the leftmost component SelectStmt in a set-operation parsetree.
10173 static SelectStmt
*
10174 findLeftmostSelect
(SelectStmt
*node
)
10176 while
(node
&& node
->op
!= SETOP_NONE
)
10178 Assert
(node
&& IsA
(node
, SelectStmt
) && node
->larg
== NULL
);
10182 /* insertSelectOptions()
10183 * Insert ORDER BY, etc into an already-constructed SelectStmt.
10185 * This routine is just to avoid duplicating code in SelectStmt productions.
10188 insertSelectOptions
(SelectStmt
*stmt
,
10189 List
*sortClause
, List
*lockingClause
,
10190 Node
*limitOffset
, Node
*limitCount
,
10191 WithClause
*withClause
)
10193 Assert
(IsA
(stmt
, SelectStmt
));
10196 * Tests here are to reject constructs like
10197 * (SELECT foo ORDER BY bar) ORDER BY baz
10201 if
(stmt
->sortClause
)
10203 (errcode
(ERRCODE_SYNTAX_ERROR
),
10204 errmsg
("multiple ORDER BY clauses not allowed"),
10205 scanner_errposition
(exprLocation
((Node
*) sortClause
))));
10206 stmt
->sortClause
= sortClause
;
10208 /* We can handle multiple locking clauses, though */
10209 stmt
->lockingClause
= list_concat
(stmt
->lockingClause
, lockingClause
);
10212 if
(stmt
->limitOffset
)
10214 (errcode
(ERRCODE_SYNTAX_ERROR
),
10215 errmsg
("multiple OFFSET clauses not allowed"),
10216 scanner_errposition
(exprLocation
(limitOffset
))));
10217 stmt
->limitOffset
= limitOffset
;
10221 if
(stmt
->limitCount
)
10223 (errcode
(ERRCODE_SYNTAX_ERROR
),
10224 errmsg
("multiple LIMIT clauses not allowed"),
10225 scanner_errposition
(exprLocation
(limitCount
))));
10226 stmt
->limitCount
= limitCount
;
10230 if
(stmt
->withClause
)
10232 (errcode
(ERRCODE_SYNTAX_ERROR
),
10233 errmsg
("multiple WITH clauses not allowed"),
10234 scanner_errposition
(exprLocation
((Node
*) withClause
))));
10235 stmt
->withClause
= withClause
;
10240 makeSetOp
(SetOperation op
, bool all
, Node
*larg
, Node
*rarg
)
10242 SelectStmt
*n
= makeNode
(SelectStmt
);
10246 n
->larg
= (SelectStmt
*) larg
;
10247 n
->rarg
= (SelectStmt
*) rarg
;
10251 /* SystemFuncName()
10252 * Build a properly-qualified reference to a built-in function.
10255 SystemFuncName
(char *name
)
10257 return list_make2
(makeString
("pg_catalog"), makeString
(name
));
10260 /* SystemTypeName()
10261 * Build a properly-qualified reference to a built-in type.
10263 * typmod is defaulted, but may be changed afterwards by caller.
10264 * Likewise for the location.
10267 SystemTypeName
(char *name
)
10269 return makeTypeNameFromNameList
(list_make2
(makeString
("pg_catalog"),
10270 makeString
(name
)));
10274 * Handle negation of a numeric constant.
10276 * Formerly, we did this here because the optimizer couldn't cope with
10277 * indexquals that looked like "var = -4" --- it wants "var = const"
10278 * and a unary minus operator applied to a constant didn't qualify.
10279 * As of Postgres 7.0, that problem doesn't exist anymore because there
10280 * is a constant-subexpression simplifier in the optimizer. However,
10281 * there's still a good reason for doing this here, which is that we can
10282 * postpone committing to a particular internal representation for simple
10283 * negative constants. It's better to leave "-123.456" in string form
10284 * until we know what the desired type is.
10287 doNegate
(Node
*n
, int location
)
10289 if
(IsA
(n
, A_Const
))
10291 A_Const
*con
= (A_Const
*)n
;
10293 /* report the constant's location as that of the '-' sign */
10294 con
->location
= location
;
10296 if
(con
->val.type
== T_Integer
)
10298 con
->val.val.ival
= -con
->val.val.ival
;
10301 if
(con
->val.type
== T_Float
)
10303 doNegateFloat
(&con
->val
);
10308 return
(Node
*) makeSimpleA_Expr
(AEXPR_OP
, "-", NULL
, n
, location
);
10312 doNegateFloat
(Value
*v
)
10314 char *oldval
= v
->val.str
;
10316 Assert
(IsA
(v
, Float
));
10317 if
(*oldval
== '+')
10319 if
(*oldval
== '-')
10320 v
->val.str
= oldval
+1; /* just strip the '-' */
10323 char *newval
= (char *) palloc
(strlen
(oldval
) + 2);
10326 strcpy
(newval
+1, oldval
);
10327 v
->val.str
= newval
;
10332 makeAArrayExpr
(List
*elements
, int location
)
10334 A_ArrayExpr
*n
= makeNode
(A_ArrayExpr
);
10336 n
->elements
= elements
;
10337 n
->location
= location
;
10342 makeXmlExpr
(XmlExprOp op
, char *name
, List
*named_args
, List
*args
,
10345 XmlExpr
*x
= makeNode
(XmlExpr
);
10350 * named_args is a list of ResTarget; it'll be split apart into separate
10351 * expression and name lists in transformXmlExpr().
10353 x
->named_args
= named_args
;
10354 x
->arg_names
= NIL
;
10356 /* xmloption, if relevant, must be filled in by caller */
10357 /* type and typmod will be filled in during parse analysis */
10358 x
->location
= location
;
10363 * Initialize to parse one query string
10368 QueryIsRule
= FALSE
;
10372 * Merge the input and output parameters of a table function.
10375 mergeTableFuncParameters
(List
*func_args
, List
*columns
)
10379 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
10380 foreach
(lc
, func_args
)
10382 FunctionParameter
*p
= (FunctionParameter
*) lfirst
(lc
);
10384 if
(p
->mode
!= FUNC_PARAM_IN
&& p
->mode
!= FUNC_PARAM_VARIADIC
)
10386 (errcode
(ERRCODE_SYNTAX_ERROR
),
10387 errmsg
("OUT and INOUT arguments aren't allowed in TABLE functions")));
10390 return list_concat
(func_args
, columns
);
10394 * Determine return type of a TABLE function. A single result column
10395 * returns setof that column's type; otherwise return setof record.
10398 TableFuncTypeName
(List
*columns
)
10402 if
(list_length
(columns
) == 1)
10404 FunctionParameter
*p
= (FunctionParameter
*) linitial
(columns
);
10406 result
= (TypeName
*) copyObject
(p
->argType
);
10409 result
= SystemTypeName
("record");
10411 result
->setof
= true
;
10417 * Must undefine base_yylex before including scan.c, since we want it
10418 * to create the function base_yylex not filtered_base_yylex.