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
4239 { $$
= 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
;
4467 table_func_column_list:
4470 $$
= list_make1
($1);
4472 | table_func_column_list
',' table_func_column
4474 $$
= lappend
($1, $3);
4478 /*****************************************************************************
4481 * RENAME and OWNER subcommands are already provided by the generic
4482 * ALTER infrastructure, here we just specify alterations that can
4483 * only be applied to functions.
4485 *****************************************************************************/
4487 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
4489 AlterFunctionStmt
*n
= makeNode
(AlterFunctionStmt
);
4497 /* At least one option must be specified */
4498 common_func_opt_item
{ $$
= list_make1
($1); }
4499 | alterfunc_opt_list common_func_opt_item
{ $$
= lappend
($1, $2); }
4502 /* Ignored, merely for SQL compliance */
4509 /*****************************************************************************
4513 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
4514 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
4515 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
4517 *****************************************************************************/
4520 DROP FUNCTION func_name func_args opt_drop_behavior
4522 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4523 n
->kind
= OBJECT_FUNCTION
;
4525 n
->args
= extractArgTypes
($4);
4527 n
->missing_ok
= false
;
4530 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
4532 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4533 n
->kind
= OBJECT_FUNCTION
;
4535 n
->args
= extractArgTypes
($6);
4537 n
->missing_ok
= true
;
4543 DROP AGGREGATE func_name aggr_args opt_drop_behavior
4545 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4546 n
->kind
= OBJECT_AGGREGATE
;
4550 n
->missing_ok
= false
;
4553 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
4555 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4556 n
->kind
= OBJECT_AGGREGATE
;
4560 n
->missing_ok
= true
;
4566 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
4568 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4569 n
->kind
= OBJECT_OPERATOR
;
4573 n
->missing_ok
= false
;
4576 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
4578 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4579 n
->kind
= OBJECT_OPERATOR
;
4583 n
->missing_ok
= true
;
4592 (errcode
(ERRCODE_SYNTAX_ERROR
),
4593 errmsg
("missing argument"),
4594 errhint
("Use NONE to denote the missing argument of a unary operator."),
4595 scanner_errposition
(@
3)));
4597 |
'(' Typename
',' Typename
')'
4598 { $$
= list_make2
($2, $4); }
4599 |
'(' NONE
',' Typename
')' /* left unary */
4600 { $$
= list_make2
(NULL
, $4); }
4601 |
'(' Typename
',' NONE
')' /* right unary */
4602 { $$
= list_make2
($2, NULL
); }
4607 { $$
= list_make1
(makeString
($1)); }
4608 | ColId
'.' any_operator
4609 { $$
= lcons
(makeString
($1), $3); }
4613 /*****************************************************************************
4615 * CREATE CAST / DROP CAST
4617 *****************************************************************************/
4619 CreateCastStmt: CREATE CAST
'(' Typename AS Typename
')'
4620 WITH FUNCTION function_with_argtypes cast_context
4622 CreateCastStmt
*n
= makeNode
(CreateCastStmt
);
4626 n
->context
= (CoercionContext
) $11;
4630 | CREATE CAST
'(' Typename AS Typename
')'
4631 WITHOUT FUNCTION cast_context
4633 CreateCastStmt
*n
= makeNode
(CreateCastStmt
);
4637 n
->context
= (CoercionContext
) $10;
4641 | CREATE CAST
'(' Typename AS Typename
')'
4642 WITH INOUT cast_context
4644 CreateCastStmt
*n
= makeNode
(CreateCastStmt
);
4648 n
->context
= (CoercionContext
) $10;
4654 cast_context: AS IMPLICIT_P
{ $$
= COERCION_IMPLICIT
; }
4655 | AS ASSIGNMENT
{ $$
= COERCION_ASSIGNMENT
; }
4656 |
/*EMPTY*/ { $$
= COERCION_EXPLICIT
; }
4660 DropCastStmt: DROP CAST opt_if_exists
'(' Typename AS Typename
')' opt_drop_behavior
4662 DropCastStmt
*n
= makeNode
(DropCastStmt
);
4671 opt_if_exists: IF_P EXISTS
{ $$
= TRUE
; }
4672 |
/*EMPTY*/ { $$
= FALSE
; }
4676 /*****************************************************************************
4680 * REINDEX type <name> [FORCE]
4682 * FORCE no longer does anything, but we accept it for backwards compatibility
4683 *****************************************************************************/
4686 REINDEX reindex_type qualified_name opt_force
4688 ReindexStmt
*n
= makeNode
(ReindexStmt
);
4694 | REINDEX SYSTEM_P name opt_force
4696 ReindexStmt
*n
= makeNode
(ReindexStmt
);
4697 n
->kind
= OBJECT_DATABASE
;
4700 n
->do_system
= true
;
4704 | REINDEX DATABASE name opt_force
4706 ReindexStmt
*n
= makeNode
(ReindexStmt
);
4707 n
->kind
= OBJECT_DATABASE
;
4710 n
->do_system
= true
;
4717 INDEX
{ $$
= OBJECT_INDEX
; }
4718 | TABLE
{ $$
= OBJECT_TABLE
; }
4721 opt_force: FORCE
{ $$
= TRUE
; }
4722 |
/* EMPTY */ { $$
= FALSE
; }
4726 /*****************************************************************************
4728 * ALTER THING name RENAME TO newname
4730 *****************************************************************************/
4732 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
4734 RenameStmt
*n
= makeNode
(RenameStmt
);
4735 n
->renameType
= OBJECT_AGGREGATE
;
4741 | ALTER CONVERSION_P any_name RENAME TO name
4743 RenameStmt
*n
= makeNode
(RenameStmt
);
4744 n
->renameType
= OBJECT_CONVERSION
;
4749 | ALTER DATABASE database_name RENAME TO database_name
4751 RenameStmt
*n
= makeNode
(RenameStmt
);
4752 n
->renameType
= OBJECT_DATABASE
;
4757 | ALTER FUNCTION function_with_argtypes RENAME TO name
4759 RenameStmt
*n
= makeNode
(RenameStmt
);
4760 n
->renameType
= OBJECT_FUNCTION
;
4761 n
->object
= $3->funcname
;
4762 n
->objarg
= $3->funcargs
;
4766 | ALTER GROUP_P RoleId RENAME TO RoleId
4768 RenameStmt
*n
= makeNode
(RenameStmt
);
4769 n
->renameType
= OBJECT_ROLE
;
4774 | ALTER opt_procedural LANGUAGE name RENAME TO name
4776 RenameStmt
*n
= makeNode
(RenameStmt
);
4777 n
->renameType
= OBJECT_LANGUAGE
;
4782 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
4784 RenameStmt
*n
= makeNode
(RenameStmt
);
4785 n
->renameType
= OBJECT_OPCLASS
;
4791 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
4793 RenameStmt
*n
= makeNode
(RenameStmt
);
4794 n
->renameType
= OBJECT_OPFAMILY
;
4800 | ALTER SCHEMA name RENAME TO name
4802 RenameStmt
*n
= makeNode
(RenameStmt
);
4803 n
->renameType
= OBJECT_SCHEMA
;
4808 | ALTER TABLE relation_expr RENAME TO name
4810 RenameStmt
*n
= makeNode
(RenameStmt
);
4811 n
->renameType
= OBJECT_TABLE
;
4817 | ALTER SEQUENCE relation_expr RENAME TO name
4819 RenameStmt
*n
= makeNode
(RenameStmt
);
4820 n
->renameType
= OBJECT_SEQUENCE
;
4826 | ALTER VIEW relation_expr RENAME TO name
4828 RenameStmt
*n
= makeNode
(RenameStmt
);
4829 n
->renameType
= OBJECT_VIEW
;
4835 | ALTER INDEX relation_expr RENAME TO name
4837 RenameStmt
*n
= makeNode
(RenameStmt
);
4838 n
->renameType
= OBJECT_INDEX
;
4844 | ALTER TABLE relation_expr RENAME opt_column name TO name
4846 RenameStmt
*n
= makeNode
(RenameStmt
);
4847 n
->renameType
= OBJECT_COLUMN
;
4853 | ALTER TRIGGER name ON relation_expr RENAME TO name
4855 RenameStmt
*n
= makeNode
(RenameStmt
);
4856 n
->renameType
= OBJECT_TRIGGER
;
4862 | ALTER ROLE RoleId RENAME TO RoleId
4864 RenameStmt
*n
= makeNode
(RenameStmt
);
4865 n
->renameType
= OBJECT_ROLE
;
4870 | ALTER USER RoleId RENAME TO RoleId
4872 RenameStmt
*n
= makeNode
(RenameStmt
);
4873 n
->renameType
= OBJECT_ROLE
;
4878 | ALTER TABLESPACE name RENAME TO name
4880 RenameStmt
*n
= makeNode
(RenameStmt
);
4881 n
->renameType
= OBJECT_TABLESPACE
;
4886 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
4888 RenameStmt
*n
= makeNode
(RenameStmt
);
4889 n
->renameType
= OBJECT_TSPARSER
;
4894 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
4896 RenameStmt
*n
= makeNode
(RenameStmt
);
4897 n
->renameType
= OBJECT_TSDICTIONARY
;
4902 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
4904 RenameStmt
*n
= makeNode
(RenameStmt
);
4905 n
->renameType
= OBJECT_TSTEMPLATE
;
4910 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
4912 RenameStmt
*n
= makeNode
(RenameStmt
);
4913 n
->renameType
= OBJECT_TSCONFIGURATION
;
4918 | ALTER TYPE_P any_name RENAME TO name
4920 RenameStmt
*n
= makeNode
(RenameStmt
);
4921 n
->renameType
= OBJECT_TYPE
;
4928 opt_column: COLUMN
{ $$
= COLUMN
; }
4929 |
/*EMPTY*/ { $$
= 0; }
4932 opt_set_data: SET DATA_P
{ $$
= 1; }
4933 |
/*EMPTY*/ { $$
= 0; }
4936 /*****************************************************************************
4938 * ALTER THING name SET SCHEMA name
4940 *****************************************************************************/
4942 AlterObjectSchemaStmt:
4943 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
4945 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4946 n
->objectType
= OBJECT_AGGREGATE
;
4952 | ALTER DOMAIN_P any_name SET SCHEMA name
4954 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4955 n
->objectType
= OBJECT_DOMAIN
;
4960 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
4962 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4963 n
->objectType
= OBJECT_FUNCTION
;
4964 n
->object
= $3->funcname
;
4965 n
->objarg
= $3->funcargs
;
4969 | ALTER TABLE relation_expr SET SCHEMA name
4971 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4972 n
->objectType
= OBJECT_TABLE
;
4977 | ALTER SEQUENCE relation_expr SET SCHEMA name
4979 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4980 n
->objectType
= OBJECT_SEQUENCE
;
4985 | ALTER VIEW relation_expr SET SCHEMA name
4987 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4988 n
->objectType
= OBJECT_VIEW
;
4993 | ALTER TYPE_P any_name SET SCHEMA name
4995 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4996 n
->objectType
= OBJECT_TYPE
;
5003 /*****************************************************************************
5005 * ALTER THING name OWNER TO newname
5007 *****************************************************************************/
5009 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
5011 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5012 n
->objectType
= OBJECT_AGGREGATE
;
5018 | ALTER CONVERSION_P any_name OWNER TO RoleId
5020 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5021 n
->objectType
= OBJECT_CONVERSION
;
5026 | ALTER DATABASE database_name OWNER TO RoleId
5028 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5029 n
->objectType
= OBJECT_DATABASE
;
5030 n
->object
= list_make1
(makeString
($3));
5034 | ALTER DOMAIN_P any_name OWNER TO RoleId
5036 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5037 n
->objectType
= OBJECT_DOMAIN
;
5042 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
5044 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5045 n
->objectType
= OBJECT_FUNCTION
;
5046 n
->object
= $3->funcname
;
5047 n
->objarg
= $3->funcargs
;
5051 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
5053 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5054 n
->objectType
= OBJECT_LANGUAGE
;
5055 n
->object
= list_make1
(makeString
($4));
5059 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
5061 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5062 n
->objectType
= OBJECT_OPERATOR
;
5068 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
5070 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5071 n
->objectType
= OBJECT_OPCLASS
;
5077 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
5079 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5080 n
->objectType
= OBJECT_OPFAMILY
;
5086 | ALTER SCHEMA name OWNER TO RoleId
5088 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5089 n
->objectType
= OBJECT_SCHEMA
;
5090 n
->object
= list_make1
(makeString
($3));
5094 | ALTER TYPE_P any_name OWNER TO RoleId
5096 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5097 n
->objectType
= OBJECT_TYPE
;
5102 | ALTER TABLESPACE name OWNER TO RoleId
5104 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5105 n
->objectType
= OBJECT_TABLESPACE
;
5106 n
->object
= list_make1
(makeString
($3));
5110 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
5112 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5113 n
->objectType
= OBJECT_TSDICTIONARY
;
5118 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
5120 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5121 n
->objectType
= OBJECT_TSCONFIGURATION
;
5129 /*****************************************************************************
5131 * QUERY: Define Rewrite Rule
5133 *****************************************************************************/
5135 RuleStmt: CREATE opt_or_replace RULE name AS
5136 { QueryIsRule
=TRUE
; }
5137 ON event TO qualified_name where_clause
5138 DO opt_instead RuleActionList
5140 RuleStmt
*n
= makeNode
(RuleStmt
);
5144 n
->whereClause
= $11;
5154 NOTHING
{ $$
= NIL
; }
5155 | RuleActionStmt
{ $$
= list_make1
($1); }
5156 |
'(' RuleActionMulti
')' { $$
= $2; }
5159 /* the thrashing around here is to discard "empty" statements... */
5161 RuleActionMulti
';' RuleActionStmtOrEmpty
5163 $$
= lappend
($1, $3);
5167 | RuleActionStmtOrEmpty
5169 $$
= list_make1
($1);
5183 RuleActionStmtOrEmpty:
5184 RuleActionStmt
{ $$
= $1; }
5185 |
/*EMPTY*/ { $$
= NULL
; }
5188 event: SELECT
{ $$
= CMD_SELECT
; }
5189 | UPDATE
{ $$
= CMD_UPDATE
; }
5190 | DELETE_P
{ $$
= CMD_DELETE
; }
5191 | INSERT
{ $$
= CMD_INSERT
; }
5195 INSTEAD
{ $$
= TRUE
; }
5196 | ALSO
{ $$
= FALSE
; }
5197 |
/*EMPTY*/ { $$
= FALSE
; }
5202 DROP RULE name ON qualified_name opt_drop_behavior
5204 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
5208 n
->removeType
= OBJECT_RULE
;
5209 n
->missing_ok
= false
;
5212 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
5214 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
5218 n
->removeType
= OBJECT_RULE
;
5219 n
->missing_ok
= true
;
5225 /*****************************************************************************
5228 * NOTIFY <identifier> can appear both in rule bodies and
5229 * as a query-level command
5231 *****************************************************************************/
5233 NotifyStmt: NOTIFY ColId
5235 NotifyStmt
*n
= makeNode
(NotifyStmt
);
5236 n
->conditionname
= $2;
5241 ListenStmt: LISTEN ColId
5243 ListenStmt
*n
= makeNode
(ListenStmt
);
5244 n
->conditionname
= $2;
5252 UnlistenStmt
*n
= makeNode
(UnlistenStmt
);
5253 n
->conditionname
= $2;
5258 UnlistenStmt
*n
= makeNode
(UnlistenStmt
);
5259 n
->conditionname
= NULL
;
5265 /*****************************************************************************
5269 * BEGIN / COMMIT / ROLLBACK
5270 * (also older versions END / ABORT)
5272 *****************************************************************************/
5275 ABORT_P opt_transaction
5277 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5278 n
->kind
= TRANS_STMT_ROLLBACK
;
5282 | BEGIN_P opt_transaction transaction_mode_list_or_empty
5284 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5285 n
->kind
= TRANS_STMT_BEGIN
;
5289 | START TRANSACTION transaction_mode_list_or_empty
5291 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5292 n
->kind
= TRANS_STMT_START
;
5296 | COMMIT opt_transaction
5298 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5299 n
->kind
= TRANS_STMT_COMMIT
;
5303 | END_P opt_transaction
5305 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5306 n
->kind
= TRANS_STMT_COMMIT
;
5310 | ROLLBACK opt_transaction
5312 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5313 n
->kind
= TRANS_STMT_ROLLBACK
;
5319 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5320 n
->kind
= TRANS_STMT_SAVEPOINT
;
5321 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5322 (Node
*)makeString
($2)));
5325 | RELEASE SAVEPOINT ColId
5327 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5328 n
->kind
= TRANS_STMT_RELEASE
;
5329 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5330 (Node
*)makeString
($3)));
5335 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5336 n
->kind
= TRANS_STMT_RELEASE
;
5337 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5338 (Node
*)makeString
($2)));
5341 | ROLLBACK opt_transaction TO SAVEPOINT ColId
5343 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5344 n
->kind
= TRANS_STMT_ROLLBACK_TO
;
5345 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5346 (Node
*)makeString
($5)));
5349 | ROLLBACK opt_transaction TO ColId
5351 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5352 n
->kind
= TRANS_STMT_ROLLBACK_TO
;
5353 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5354 (Node
*)makeString
($4)));
5357 | PREPARE TRANSACTION Sconst
5359 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5360 n
->kind
= TRANS_STMT_PREPARE
;
5364 | COMMIT PREPARED Sconst
5366 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5367 n
->kind
= TRANS_STMT_COMMIT_PREPARED
;
5371 | ROLLBACK PREPARED Sconst
5373 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5374 n
->kind
= TRANS_STMT_ROLLBACK_PREPARED
;
5380 opt_transaction: WORK
{}
5385 transaction_mode_item:
5386 ISOLATION LEVEL iso_level
5387 { $$
= makeDefElem
("transaction_isolation",
5388 makeStringConst
($3, @
3)); }
5390 { $$
= makeDefElem
("transaction_read_only",
5391 makeIntConst
(TRUE
, @
1)); }
5393 { $$
= makeDefElem
("transaction_read_only",
5394 makeIntConst
(FALSE
, @
1)); }
5397 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
5398 transaction_mode_list:
5399 transaction_mode_item
5400 { $$
= list_make1
($1); }
5401 | transaction_mode_list
',' transaction_mode_item
5402 { $$
= lappend
($1, $3); }
5403 | transaction_mode_list transaction_mode_item
5404 { $$
= lappend
($1, $2); }
5407 transaction_mode_list_or_empty:
5408 transaction_mode_list
5414 /*****************************************************************************
5417 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
5418 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
5420 *****************************************************************************/
5422 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
5423 AS SelectStmt opt_check_option
5425 ViewStmt
*n
= makeNode
(ViewStmt
);
5427 n
->view
->istemp
= $2;
5433 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
5434 AS SelectStmt opt_check_option
5436 ViewStmt
*n
= makeNode
(ViewStmt
);
5438 n
->view
->istemp
= $4;
5450 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
5451 errmsg
("WITH CHECK OPTION is not implemented")));
5453 | WITH CASCADED CHECK OPTION
5456 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
5457 errmsg
("WITH CHECK OPTION is not implemented")));
5459 | WITH LOCAL CHECK OPTION
5462 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
5463 errmsg
("WITH CHECK OPTION is not implemented")));
5465 |
/* EMPTY */ { $$
= NIL
; }
5468 /*****************************************************************************
5473 *****************************************************************************/
5475 LoadStmt: LOAD file_name
5477 LoadStmt
*n
= makeNode
(LoadStmt
);
5484 /*****************************************************************************
5488 *****************************************************************************/
5491 CREATE DATABASE database_name opt_with createdb_opt_list
5493 CreatedbStmt
*n
= makeNode
(CreatedbStmt
);
5501 createdb_opt_list createdb_opt_item
{ $$
= lappend
($1, $2); }
5502 |
/* EMPTY */ { $$
= NIL
; }
5506 TABLESPACE opt_equal name
5508 $$
= makeDefElem
("tablespace", (Node
*)makeString
($3));
5510 | TABLESPACE opt_equal DEFAULT
5512 $$
= makeDefElem
("tablespace", NULL
);
5514 | LOCATION opt_equal Sconst
5516 $$
= makeDefElem
("location", (Node
*)makeString
($3));
5518 | LOCATION opt_equal DEFAULT
5520 $$
= makeDefElem
("location", NULL
);
5522 | TEMPLATE opt_equal name
5524 $$
= makeDefElem
("template", (Node
*)makeString
($3));
5526 | TEMPLATE opt_equal DEFAULT
5528 $$
= makeDefElem
("template", NULL
);
5530 | ENCODING opt_equal Sconst
5532 $$
= makeDefElem
("encoding", (Node
*)makeString
($3));
5534 | ENCODING opt_equal Iconst
5536 $$
= makeDefElem
("encoding", (Node
*)makeInteger
($3));
5538 | ENCODING opt_equal DEFAULT
5540 $$
= makeDefElem
("encoding", NULL
);
5542 | COLLATE opt_equal Sconst
5544 $$
= makeDefElem
("collate", (Node
*)makeString
($3));
5546 | COLLATE opt_equal DEFAULT
5548 $$
= makeDefElem
("collate", NULL
);
5550 | CTYPE opt_equal Sconst
5552 $$
= makeDefElem
("ctype", (Node
*)makeString
($3));
5554 | CTYPE opt_equal DEFAULT
5556 $$
= makeDefElem
("ctype", NULL
);
5558 | CONNECTION LIMIT opt_equal SignedIconst
5560 $$
= makeDefElem
("connectionlimit", (Node
*)makeInteger
($4));
5562 | OWNER opt_equal name
5564 $$
= makeDefElem
("owner", (Node
*)makeString
($3));
5566 | OWNER opt_equal DEFAULT
5568 $$
= makeDefElem
("owner", NULL
);
5573 * Though the equals sign doesn't match other WITH options, pg_dump uses
5574 * equals for backward compatibility, and it doesn't seem worth removing it.
5581 /*****************************************************************************
5585 *****************************************************************************/
5588 ALTER DATABASE database_name opt_with alterdb_opt_list
5590 AlterDatabaseStmt
*n
= makeNode
(AlterDatabaseStmt
);
5595 | ALTER DATABASE database_name SET TABLESPACE name
5597 AlterDatabaseStmt
*n
= makeNode
(AlterDatabaseStmt
);
5599 n
->options
= list_make1
(makeDefElem
("tablespace",
5600 (Node
*)makeString
($6)));
5605 AlterDatabaseSetStmt:
5606 ALTER DATABASE database_name SetResetClause
5608 AlterDatabaseSetStmt
*n
= makeNode
(AlterDatabaseSetStmt
);
5617 alterdb_opt_list alterdb_opt_item
{ $$
= lappend
($1, $2); }
5618 |
/* EMPTY */ { $$
= NIL
; }
5622 CONNECTION LIMIT opt_equal SignedIconst
5624 $$
= makeDefElem
("connectionlimit", (Node
*)makeInteger
($4));
5629 /*****************************************************************************
5631 * DROP DATABASE [ IF EXISTS ]
5633 * This is implicitly CASCADE, no need for drop behavior
5634 *****************************************************************************/
5636 DropdbStmt: DROP DATABASE database_name
5638 DropdbStmt
*n
= makeNode
(DropdbStmt
);
5640 n
->missing_ok
= FALSE
;
5643 | DROP DATABASE IF_P EXISTS database_name
5645 DropdbStmt
*n
= makeNode
(DropdbStmt
);
5647 n
->missing_ok
= TRUE
;
5653 /*****************************************************************************
5655 * Manipulate a domain
5657 *****************************************************************************/
5660 CREATE DOMAIN_P any_name opt_as Typename ColQualList
5662 CreateDomainStmt
*n
= makeNode
(CreateDomainStmt
);
5665 n
->constraints
= $6;
5671 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
5672 ALTER DOMAIN_P any_name alter_column_default
5674 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
5680 /* ALTER DOMAIN <domain> DROP NOT NULL */
5681 | ALTER DOMAIN_P any_name DROP NOT NULL_P
5683 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
5688 /* ALTER DOMAIN <domain> SET NOT NULL */
5689 | ALTER DOMAIN_P any_name SET NOT NULL_P
5691 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
5696 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
5697 | ALTER DOMAIN_P any_name ADD_P TableConstraint
5699 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
5705 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
5706 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
5708 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
5722 /*****************************************************************************
5724 * Manipulate a text search dictionary or configuration
5726 *****************************************************************************/
5728 AlterTSDictionaryStmt:
5729 ALTER TEXT_P SEARCH DICTIONARY any_name definition
5731 AlterTSDictionaryStmt
*n
= makeNode
(AlterTSDictionaryStmt
);
5738 AlterTSConfigurationStmt:
5739 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
5741 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5745 n
->override
= false
;
5749 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
5751 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5759 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
5761 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5764 n
->dicts
= list_make2
($9,$11);
5765 n
->override
= false
;
5769 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
5771 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5774 n
->dicts
= list_make2
($11,$13);
5775 n
->override
= false
;
5779 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
5781 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5784 n
->missing_ok
= false
;
5787 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
5789 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5792 n
->missing_ok
= true
;
5798 /*****************************************************************************
5800 * Manipulate a conversion
5802 * CREATE [DEFAULT] CONVERSION <conversion_name>
5803 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
5805 *****************************************************************************/
5807 CreateConversionStmt:
5808 CREATE opt_default CONVERSION_P any_name FOR Sconst
5809 TO Sconst FROM any_name
5811 CreateConversionStmt
*n
= makeNode
(CreateConversionStmt
);
5812 n
->conversion_name
= $4;
5813 n
->for_encoding_name
= $6;
5814 n
->to_encoding_name
= $8;
5821 /*****************************************************************************
5824 * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
5826 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
5828 *****************************************************************************/
5831 CLUSTER opt_verbose qualified_name cluster_index_specification
5833 ClusterStmt
*n
= makeNode
(ClusterStmt
);
5839 | CLUSTER opt_verbose
5841 ClusterStmt
*n
= makeNode
(ClusterStmt
);
5843 n
->indexname
= NULL
;
5847 /* kept for pre-8.3 compatibility */
5848 | CLUSTER opt_verbose index_name ON qualified_name
5850 ClusterStmt
*n
= makeNode
(ClusterStmt
);
5858 cluster_index_specification:
5859 USING index_name
{ $$
= $2; }
5860 |
/*EMPTY*/ { $$
= NULL
; }
5864 /*****************************************************************************
5870 *****************************************************************************/
5872 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
5874 VacuumStmt
*n
= makeNode
(VacuumStmt
);
5878 n
->freeze_min_age
= $3 ?
0 : -1;
5879 n
->scan_all
= $2 ||
$3;
5885 | VACUUM opt_full opt_freeze opt_verbose qualified_name
5887 VacuumStmt
*n
= makeNode
(VacuumStmt
);
5891 n
->freeze_min_age
= $3 ?
0 : -1;
5892 n
->scan_all
= $2 ||
$3;
5898 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
5900 VacuumStmt
*n
= (VacuumStmt
*) $5;
5903 n
->freeze_min_age
= $3 ?
0 : -1;
5904 n
->scan_all
= $2 ||
$3;
5911 analyze_keyword opt_verbose
5913 VacuumStmt
*n
= makeNode
(VacuumStmt
);
5917 n
->freeze_min_age
= -1;
5923 | analyze_keyword opt_verbose qualified_name opt_name_list
5925 VacuumStmt
*n
= makeNode
(VacuumStmt
);
5929 n
->freeze_min_age
= -1;
5939 | ANALYSE
/* British */ {}
5943 VERBOSE
{ $$
= TRUE
; }
5944 |
/*EMPTY*/ { $$
= FALSE
; }
5947 opt_full: FULL
{ $$
= TRUE
; }
5948 |
/*EMPTY*/ { $$
= FALSE
; }
5951 opt_freeze: FREEZE
{ $$
= TRUE
; }
5952 |
/*EMPTY*/ { $$
= FALSE
; }
5956 '(' name_list
')' { $$
= $2; }
5957 |
/*EMPTY*/ { $$
= NIL
; }
5961 /*****************************************************************************
5964 * EXPLAIN [ANALYZE] [VERBOSE] query
5966 *****************************************************************************/
5968 ExplainStmt: EXPLAIN opt_analyze opt_verbose ExplainableStmt
5970 ExplainStmt
*n
= makeNode
(ExplainStmt
);
5985 | ExecuteStmt
/* by default all are $$=$1 */
5989 analyze_keyword
{ $$
= TRUE
; }
5990 |
/* EMPTY */ { $$
= FALSE
; }
5993 /*****************************************************************************
5996 * PREPARE <plan_name> [(args, ...)] AS <query>
5998 *****************************************************************************/
6000 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
6002 PrepareStmt
*n
= makeNode
(PrepareStmt
);
6010 prep_type_clause: '(' type_list
')' { $$
= $2; }
6011 |
/* EMPTY */ { $$
= NIL
; }
6018 | DeleteStmt
/* by default all are $$=$1 */
6021 /*****************************************************************************
6023 * EXECUTE <plan_name> [(params, ...)]
6024 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
6026 *****************************************************************************/
6028 ExecuteStmt: EXECUTE name execute_param_clause
6030 ExecuteStmt
*n
= makeNode
(ExecuteStmt
);
6036 | CREATE OptTemp TABLE create_as_target AS
6037 EXECUTE name execute_param_clause
6039 ExecuteStmt
*n
= makeNode
(ExecuteStmt
);
6042 $4->rel
->istemp
= $2;
6046 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
6047 errmsg
("column name list not allowed in CREATE TABLE / AS EXECUTE")));
6048 /* ... because it's not implemented, but it could be */
6053 execute_param_clause: '(' expr_list
')' { $$
= $2; }
6054 |
/* EMPTY */ { $$
= NIL
; }
6057 /*****************************************************************************
6060 * DEALLOCATE [PREPARE] <plan_name>
6062 *****************************************************************************/
6064 DeallocateStmt: DEALLOCATE name
6066 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
6070 | DEALLOCATE PREPARE name
6072 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
6078 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
6082 | DEALLOCATE PREPARE ALL
6084 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
6090 /*****************************************************************************
6095 *****************************************************************************/
6098 INSERT INTO qualified_name insert_rest returning_clause
6101 $4->returningList
= $5;
6109 $$
= makeNode
(InsertStmt
);
6111 $$
->selectStmt
= $1;
6113 |
'(' insert_column_list
')' SelectStmt
6115 $$
= makeNode
(InsertStmt
);
6117 $$
->selectStmt
= $4;
6121 $$
= makeNode
(InsertStmt
);
6123 $$
->selectStmt
= NULL
;
6129 { $$
= list_make1
($1); }
6130 | insert_column_list
',' insert_column_item
6131 { $$
= lappend
($1, $3); }
6135 ColId opt_indirection
6137 $$
= makeNode
(ResTarget
);
6139 $$
->indirection
= check_indirection
($2);
6146 RETURNING target_list
{ $$
= $2; }
6147 |
/* EMPTY */ { $$
= NIL
; }
6151 /*****************************************************************************
6156 *****************************************************************************/
6158 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
6159 using_clause where_or_current_clause returning_clause
6161 DeleteStmt
*n
= makeNode
(DeleteStmt
);
6163 n
->usingClause
= $4;
6164 n
->whereClause
= $5;
6165 n
->returningList
= $6;
6171 USING from_list
{ $$
= $2; }
6172 |
/*EMPTY*/ { $$
= NIL
; }
6175 LockStmt: LOCK_P opt_table qualified_name_list opt_lock opt_nowait
6177 LockStmt
*n
= makeNode
(LockStmt
);
6186 opt_lock: IN_P lock_type MODE
{ $$
= $2; }
6187 |
/*EMPTY*/ { $$
= AccessExclusiveLock
; }
6190 lock_type: ACCESS SHARE
{ $$
= AccessShareLock
; }
6191 | ROW SHARE
{ $$
= RowShareLock
; }
6192 | ROW EXCLUSIVE
{ $$
= RowExclusiveLock
; }
6193 | SHARE UPDATE EXCLUSIVE
{ $$
= ShareUpdateExclusiveLock
; }
6194 | SHARE
{ $$
= ShareLock
; }
6195 | SHARE ROW EXCLUSIVE
{ $$
= ShareRowExclusiveLock
; }
6196 | EXCLUSIVE
{ $$
= ExclusiveLock
; }
6197 | ACCESS EXCLUSIVE
{ $$
= AccessExclusiveLock
; }
6200 opt_nowait: NOWAIT
{ $$
= TRUE
; }
6201 |
/*EMPTY*/ { $$
= FALSE
; }
6205 /*****************************************************************************
6208 * UpdateStmt (UPDATE)
6210 *****************************************************************************/
6212 UpdateStmt: UPDATE relation_expr_opt_alias
6215 where_or_current_clause
6218 UpdateStmt
*n
= makeNode
(UpdateStmt
);
6222 n
->whereClause
= $6;
6223 n
->returningList
= $7;
6229 set_clause
{ $$
= $1; }
6230 | set_clause_list
',' set_clause
{ $$
= list_concat
($1,$3); }
6234 single_set_clause
{ $$
= list_make1
($1); }
6235 | multiple_set_clause
{ $$
= $1; }
6239 set_target
'=' ctext_expr
6242 $$
->val
= (Node
*) $3;
6246 multiple_set_clause:
6247 '(' set_target_list
')' '=' ctext_row
6253 * Break the ctext_row apart, merge individual expressions
6254 * into the destination ResTargets. XXX this approach
6255 * cannot work for general row expressions as sources.
6257 if
(list_length
($2) != list_length
($5))
6259 (errcode
(ERRCODE_SYNTAX_ERROR
),
6260 errmsg
("number of columns does not match number of values"),
6261 scanner_errposition
(@
1)));
6262 forboth
(col_cell
, $2, val_cell
, $5)
6264 ResTarget
*res_col
= (ResTarget
*) lfirst
(col_cell
);
6265 Node
*res_val
= (Node
*) lfirst
(val_cell
);
6267 res_col
->val
= res_val
;
6275 ColId opt_indirection
6277 $$
= makeNode
(ResTarget
);
6279 $$
->indirection
= check_indirection
($2);
6280 $$
->val
= NULL
; /* upper production sets this */
6286 set_target
{ $$
= list_make1
($1); }
6287 | set_target_list
',' set_target
{ $$
= lappend
($1,$3); }
6291 /*****************************************************************************
6296 *****************************************************************************/
6297 DeclareCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR SelectStmt
6299 DeclareCursorStmt
*n
= makeNode
(DeclareCursorStmt
);
6301 /* currently we always set FAST_PLAN option */
6302 n
->options
= $3 |
$5 | CURSOR_OPT_FAST_PLAN
;
6308 cursor_options: /*EMPTY*/ { $$
= 0; }
6309 | cursor_options NO SCROLL
{ $$
= $1 | CURSOR_OPT_NO_SCROLL
; }
6310 | cursor_options SCROLL
{ $$
= $1 | CURSOR_OPT_SCROLL
; }
6311 | cursor_options BINARY
{ $$
= $1 | CURSOR_OPT_BINARY
; }
6312 | cursor_options INSENSITIVE
{ $$
= $1 | CURSOR_OPT_INSENSITIVE
; }
6315 opt_hold: /* EMPTY */ { $$
= 0; }
6316 | WITH HOLD
{ $$
= CURSOR_OPT_HOLD
; }
6317 | WITHOUT HOLD
{ $$
= 0; }
6320 /*****************************************************************************
6325 *****************************************************************************/
6327 /* A complete SELECT statement looks like this.
6329 * The rule returns either a single SelectStmt node or a tree of them,
6330 * representing a set-operation tree.
6332 * There is an ambiguity when a sub-SELECT is within an a_expr and there
6333 * are excess parentheses: do the parentheses belong to the sub-SELECT or
6334 * to the surrounding a_expr? We don't really care, but yacc wants to know.
6335 * To resolve the ambiguity, we are careful to define the grammar so that
6336 * the decision is staved off as long as possible: as long as we can keep
6337 * absorbing parentheses into the sub-SELECT, we will do so, and only when
6338 * it's no longer possible to do that will we decide that parens belong to
6339 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
6340 * parentheses are treated as part of the sub-select. The necessity of doing
6341 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
6342 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
6343 * SELECT viewpoint when we see the UNION.
6345 * This approach is implemented by defining a nonterminal select_with_parens,
6346 * which represents a SELECT with at least one outer layer of parentheses,
6347 * and being careful to use select_with_parens, never '(' SelectStmt ')',
6348 * in the expression grammar. We will then have shift-reduce conflicts
6349 * which we can resolve in favor of always treating '(' <select> ')' as
6350 * a select_with_parens. To resolve the conflicts, the productions that
6351 * conflict with the select_with_parens productions are manually given
6352 * precedences lower than the precedence of ')', thereby ensuring that we
6353 * shift ')' (and then reduce to select_with_parens) rather than trying to
6354 * reduce the inner <select> nonterminal to something else. We use UMINUS
6355 * precedence for this, which is a fairly arbitrary choice.
6357 * To be able to define select_with_parens itself without ambiguity, we need
6358 * a nonterminal select_no_parens that represents a SELECT structure with no
6359 * outermost parentheses. This is a little bit tedious, but it works.
6361 * In non-expression contexts, we use SelectStmt which can represent a SELECT
6362 * with or without outer parentheses.
6365 SelectStmt: select_no_parens %prec UMINUS
6366 | select_with_parens %prec UMINUS
6370 '(' select_no_parens
')' { $$
= $2; }
6371 |
'(' select_with_parens
')' { $$
= $2; }
6375 * This rule parses the equivalent of the standard's <query expression>.
6376 * The duplicative productions are annoying, but hard to get rid of without
6377 * creating shift/reduce conflicts.
6379 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
6380 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
6381 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
6385 simple_select
{ $$
= $1; }
6386 | select_clause sort_clause
6388 insertSelectOptions
((SelectStmt
*) $1, $2, NIL
,
6392 | select_clause opt_sort_clause for_locking_clause opt_select_limit
6394 insertSelectOptions
((SelectStmt
*) $1, $2, $3,
6395 list_nth
($4, 0), list_nth
($4, 1),
6399 | select_clause opt_sort_clause select_limit opt_for_locking_clause
6401 insertSelectOptions
((SelectStmt
*) $1, $2, $4,
6402 list_nth
($3, 0), list_nth
($3, 1),
6406 | with_clause simple_select
6408 insertSelectOptions
((SelectStmt
*) $2, NULL
, NIL
,
6413 | with_clause select_clause sort_clause
6415 insertSelectOptions
((SelectStmt
*) $2, $3, NIL
,
6420 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
6422 insertSelectOptions
((SelectStmt
*) $2, $3, $4,
6423 list_nth
($5, 0), list_nth
($5, 1),
6427 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
6429 insertSelectOptions
((SelectStmt
*) $2, $3, $5,
6430 list_nth
($4, 0), list_nth
($4, 1),
6437 simple_select
{ $$
= $1; }
6438 | select_with_parens
{ $$
= $1; }
6442 * This rule parses SELECT statements that can appear within set operations,
6443 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
6444 * the ordering of the set operations. Without '(' and ')' we want the
6445 * operations to be ordered per the precedence specs at the head of this file.
6447 * As with select_no_parens, simple_select cannot have outer parentheses,
6448 * but can have parenthesized subclauses.
6450 * Note that sort clauses cannot be included at this level --- SQL92 requires
6451 * SELECT foo UNION SELECT bar ORDER BY baz
6453 * (SELECT foo UNION SELECT bar) ORDER BY baz
6455 * SELECT foo UNION (SELECT bar ORDER BY baz)
6456 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
6457 * described as part of the select_no_parens production, not simple_select.
6458 * This does not limit functionality, because you can reintroduce these
6459 * clauses inside parentheses.
6461 * NOTE: only the leftmost component SelectStmt should have INTO.
6462 * However, this is not checked by the grammar; parse analysis must check it.
6465 SELECT opt_distinct target_list
6466 into_clause from_clause where_clause
6467 group_clause having_clause
6469 SelectStmt
*n
= makeNode
(SelectStmt
);
6470 n
->distinctClause
= $2;
6474 n
->whereClause
= $6;
6475 n
->groupClause
= $7;
6476 n
->havingClause
= $8;
6479 | values_clause
{ $$
= $1; }
6480 | TABLE relation_expr
6482 /* same as SELECT * FROM relation_expr */
6483 ColumnRef
*cr
= makeNode
(ColumnRef
);
6484 ResTarget
*rt
= makeNode
(ResTarget
);
6485 SelectStmt
*n
= makeNode
(SelectStmt
);
6487 cr
->fields
= list_make1
(makeNode
(A_Star
));
6491 rt
->indirection
= NIL
;
6492 rt
->val
= (Node
*)cr
;
6495 n
->targetList
= list_make1
(rt
);
6496 n
->fromClause
= list_make1
($2);
6499 | select_clause UNION opt_all select_clause
6501 $$
= makeSetOp
(SETOP_UNION
, $3, $1, $4);
6503 | select_clause INTERSECT opt_all select_clause
6505 $$
= makeSetOp
(SETOP_INTERSECT
, $3, $1, $4);
6507 | select_clause EXCEPT opt_all select_clause
6509 $$
= makeSetOp
(SETOP_EXCEPT
, $3, $1, $4);
6514 * SQL standard WITH clause looks like:
6516 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
6517 * AS (query) [ SEARCH or CYCLE clause ]
6519 * We don't currently support the SEARCH or CYCLE clause.
6524 $$
= makeNode
(WithClause
);
6526 $$
->recursive
= false
;
6529 | WITH RECURSIVE cte_list
6531 $$
= makeNode
(WithClause
);
6533 $$
->recursive
= true
;
6539 common_table_expr
{ $$
= list_make1
($1); }
6540 | cte_list
',' common_table_expr
{ $$
= lappend
($1, $3); }
6543 common_table_expr: name opt_name_list AS select_with_parens
6545 CommonTableExpr
*n
= makeNode
(CommonTableExpr
);
6547 n
->aliascolnames
= $2;
6555 INTO OptTempTableName
6557 $$
= makeNode
(IntoClause
);
6561 $$
->onCommit
= ONCOMMIT_NOOP
;
6562 $$
->tableSpaceName
= NULL
;
6569 * Redundancy here is needed to avoid shift/reduce conflicts,
6570 * since TEMP is not a reserved word. See also OptTemp.
6573 TEMPORARY opt_table qualified_name
6578 | TEMP opt_table qualified_name
6583 | LOCAL TEMPORARY opt_table qualified_name
6588 | LOCAL TEMP opt_table qualified_name
6593 | GLOBAL TEMPORARY opt_table qualified_name
6598 | GLOBAL TEMP opt_table qualified_name
6603 | TABLE qualified_name
6619 opt_all: ALL
{ $$
= TRUE
; }
6620 | DISTINCT
{ $$
= FALSE
; }
6621 |
/*EMPTY*/ { $$
= FALSE
; }
6624 /* We use (NIL) as a placeholder to indicate that all target expressions
6625 * should be placed in the DISTINCT list during parsetree analysis.
6628 DISTINCT
{ $$
= list_make1
(NIL
); }
6629 | DISTINCT ON
'(' expr_list
')' { $$
= $4; }
6631 |
/*EMPTY*/ { $$
= NIL
; }
6635 sort_clause
{ $$
= $1;}
6636 |
/*EMPTY*/ { $$
= NIL
; }
6640 ORDER BY sortby_list
{ $$
= $3; }
6644 sortby
{ $$
= list_make1
($1); }
6645 | sortby_list
',' sortby
{ $$
= lappend
($1, $3); }
6648 sortby: a_expr USING qual_all_Op opt_nulls_order
6650 $$
= makeNode
(SortBy
);
6652 $$
->sortby_dir
= SORTBY_USING
;
6653 $$
->sortby_nulls
= $4;
6657 | a_expr opt_asc_desc opt_nulls_order
6659 $$
= makeNode
(SortBy
);
6661 $$
->sortby_dir
= $2;
6662 $$
->sortby_nulls
= $3;
6664 $$
->location
= -1; /* no operator */
6670 LIMIT select_limit_value OFFSET select_offset_value
6671 { $$
= list_make2
($4, $2); }
6672 | OFFSET select_offset_value LIMIT select_limit_value
6673 { $$
= list_make2
($2, $4); }
6674 | LIMIT select_limit_value
6675 { $$
= list_make2
(NULL
, $2); }
6676 | OFFSET select_offset_value
6677 { $$
= list_make2
($2, NULL
); }
6678 | LIMIT select_limit_value
',' select_offset_value
6680 /* Disabled because it was too confusing, bjm 2002-02-18 */
6682 (errcode
(ERRCODE_SYNTAX_ERROR
),
6683 errmsg
("LIMIT #,# syntax is not supported"),
6684 errhint
("Use separate LIMIT and OFFSET clauses."),
6685 scanner_errposition
(@
1)));
6687 /* SQL:2008 syntax variants */
6688 | OFFSET select_offset_value2 row_or_rows
6689 { $$
= list_make2
($2, NULL
); }
6690 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
6691 { $$
= list_make2
(NULL
, $3); }
6692 | OFFSET select_offset_value2 row_or_rows FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
6693 { $$
= list_make2
($2, $6); }
6697 select_limit
{ $$
= $1; }
6699 { $$
= list_make2
(NULL
,NULL
); }
6706 /* LIMIT ALL is represented as a NULL constant */
6707 $$
= makeNullAConst
(@
1);
6712 * Allowing full expressions without parentheses causes various parsing
6713 * problems with the trailing ROW/ROWS key words. SQL only calls for
6714 * constants, so we allow the rest only with parentheses.
6716 opt_select_fetch_first_value:
6717 SignedIconst
{ $$
= makeIntConst
($1, @
1); }
6718 |
'(' a_expr
')' { $$
= $2; }
6719 |
/*EMPTY*/ { $$
= makeIntConst
(1, -1); }
6722 select_offset_value:
6727 * Again, the trailing ROW/ROWS in this case prevent the full expression
6728 * syntax. c_expr is the best we can do.
6730 select_offset_value2:
6747 GROUP_P BY expr_list
{ $$
= $3; }
6748 |
/*EMPTY*/ { $$
= NIL
; }
6752 HAVING a_expr
{ $$
= $2; }
6753 |
/*EMPTY*/ { $$
= NULL
; }
6757 for_locking_items
{ $$
= $1; }
6758 | FOR READ ONLY
{ $$
= NIL
; }
6761 opt_for_locking_clause:
6762 for_locking_clause
{ $$
= $1; }
6763 |
/* EMPTY */ { $$
= NIL
; }
6767 for_locking_item
{ $$
= list_make1
($1); }
6768 | for_locking_items for_locking_item
{ $$
= lappend
($1, $2); }
6772 FOR UPDATE locked_rels_list opt_nowait
6774 LockingClause
*n
= makeNode
(LockingClause
);
6776 n
->forUpdate
= TRUE
;
6780 | FOR SHARE locked_rels_list opt_nowait
6782 LockingClause
*n
= makeNode
(LockingClause
);
6784 n
->forUpdate
= FALSE
;
6791 OF qualified_name_list
{ $$
= $2; }
6792 |
/* EMPTY */ { $$
= NIL
; }
6799 SelectStmt
*n
= makeNode
(SelectStmt
);
6800 n
->valuesLists
= list_make1
($2);
6803 | values_clause
',' ctext_row
6805 SelectStmt
*n
= (SelectStmt
*) $1;
6806 n
->valuesLists
= lappend
(n
->valuesLists
, $3);
6812 /*****************************************************************************
6814 * clauses common to all Optimizable Stmts:
6815 * from_clause - allow list of both JOIN expressions and table names
6816 * where_clause - qualifications for joins or restrictions
6818 *****************************************************************************/
6821 FROM from_list
{ $$
= $2; }
6822 |
/*EMPTY*/ { $$
= NIL
; }
6826 table_ref
{ $$
= list_make1
($1); }
6827 | from_list
',' table_ref
{ $$
= lappend
($1, $3); }
6831 * table_ref is where an alias clause can be attached. Note we cannot make
6832 * alias_clause have an empty production because that causes parse conflicts
6833 * between table_ref := '(' joined_table ')' alias_clause
6834 * and joined_table := '(' joined_table ')'. So, we must have the
6835 * redundant-looking productions here instead.
6837 table_ref: relation_expr
6841 | relation_expr alias_clause
6848 RangeFunction
*n
= makeNode
(RangeFunction
);
6849 n
->funccallnode
= $1;
6850 n
->coldeflist
= NIL
;
6853 | func_table alias_clause
6855 RangeFunction
*n
= makeNode
(RangeFunction
);
6856 n
->funccallnode
= $1;
6858 n
->coldeflist
= NIL
;
6861 | func_table AS
'(' TableFuncElementList
')'
6863 RangeFunction
*n
= makeNode
(RangeFunction
);
6864 n
->funccallnode
= $1;
6868 | func_table AS ColId
'(' TableFuncElementList
')'
6870 RangeFunction
*n
= makeNode
(RangeFunction
);
6871 Alias
*a
= makeNode
(Alias
);
6872 n
->funccallnode
= $1;
6878 | func_table ColId
'(' TableFuncElementList
')'
6880 RangeFunction
*n
= makeNode
(RangeFunction
);
6881 Alias
*a
= makeNode
(Alias
);
6882 n
->funccallnode
= $1;
6888 | select_with_parens
6891 * The SQL spec does not permit a subselect
6892 * (<derived_table>) without an alias clause,
6893 * so we don't either. This avoids the problem
6894 * of needing to invent a unique refname for it.
6895 * That could be surmounted if there's sufficient
6896 * popular demand, but for now let's just implement
6897 * the spec and see if anyone complains.
6898 * However, it does seem like a good idea to emit
6899 * an error message that's better than "syntax error".
6901 if
(IsA
($1, SelectStmt
) &&
6902 ((SelectStmt
*) $1)->valuesLists
)
6904 (errcode
(ERRCODE_SYNTAX_ERROR
),
6905 errmsg
("VALUES in FROM must have an alias"),
6906 errhint
("For example, FROM (VALUES ...) [AS] foo."),
6907 scanner_errposition
(@
1)));
6910 (errcode
(ERRCODE_SYNTAX_ERROR
),
6911 errmsg
("subquery in FROM must have an alias"),
6912 errhint
("For example, FROM (SELECT ...) [AS] foo."),
6913 scanner_errposition
(@
1)));
6916 | select_with_parens alias_clause
6918 RangeSubselect
*n
= makeNode
(RangeSubselect
);
6927 |
'(' joined_table
')' alias_clause
6936 * It may seem silly to separate joined_table from table_ref, but there is
6937 * method in SQL92's madness: if you don't do it this way you get reduce-
6938 * reduce conflicts, because it's not clear to the parser generator whether
6939 * to expect alias_clause after ')' or not. For the same reason we must
6940 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
6941 * join_type to expand to empty; if we try it, the parser generator can't
6942 * figure out when to reduce an empty join_type right after table_ref.
6944 * Note that a CROSS JOIN is the same as an unqualified
6945 * INNER JOIN, and an INNER JOIN/ON has the same shape
6946 * but a qualification expression to limit membership.
6947 * A NATURAL JOIN implicitly matches column names between
6948 * tables and the shape is determined by which columns are
6949 * in common. We'll collect columns during the later transformations.
6953 '(' joined_table
')'
6957 | table_ref CROSS JOIN table_ref
6959 /* CROSS JOIN is same as unqualified inner join */
6960 JoinExpr
*n
= makeNode
(JoinExpr
);
6961 n
->jointype
= JOIN_INNER
;
6962 n
->isNatural
= FALSE
;
6969 | table_ref join_type JOIN table_ref join_qual
6971 JoinExpr
*n
= makeNode
(JoinExpr
);
6973 n
->isNatural
= FALSE
;
6976 if
($5 != NULL
&& IsA
($5, List
))
6977 n
->using
= (List
*) $5; /* USING clause */
6979 n
->quals
= $5; /* ON clause */
6982 | table_ref JOIN table_ref join_qual
6984 /* letting join_type reduce to empty doesn't work */
6985 JoinExpr
*n
= makeNode
(JoinExpr
);
6986 n
->jointype
= JOIN_INNER
;
6987 n
->isNatural
= FALSE
;
6990 if
($4 != NULL
&& IsA
($4, List
))
6991 n
->using
= (List
*) $4; /* USING clause */
6993 n
->quals
= $4; /* ON clause */
6996 | table_ref NATURAL join_type JOIN table_ref
6998 JoinExpr
*n
= makeNode
(JoinExpr
);
7000 n
->isNatural
= TRUE
;
7003 n
->using
= NIL
; /* figure out which columns later... */
7004 n
->quals
= NULL
; /* fill later */
7007 | table_ref NATURAL JOIN table_ref
7009 /* letting join_type reduce to empty doesn't work */
7010 JoinExpr
*n
= makeNode
(JoinExpr
);
7011 n
->jointype
= JOIN_INNER
;
7012 n
->isNatural
= TRUE
;
7015 n
->using
= NIL
; /* figure out which columns later... */
7016 n
->quals
= NULL
; /* fill later */
7022 AS ColId
'(' name_list
')'
7024 $$
= makeNode
(Alias
);
7030 $$
= makeNode
(Alias
);
7033 | ColId
'(' name_list
')'
7035 $$
= makeNode
(Alias
);
7041 $$
= makeNode
(Alias
);
7046 join_type: FULL join_outer
{ $$
= JOIN_FULL
; }
7047 | LEFT join_outer
{ $$
= JOIN_LEFT
; }
7048 | RIGHT join_outer
{ $$
= JOIN_RIGHT
; }
7049 | INNER_P
{ $$
= JOIN_INNER
; }
7052 /* OUTER is just noise... */
7053 join_outer: OUTER_P
{ $$
= NULL
; }
7054 |
/*EMPTY*/ { $$
= NULL
; }
7057 /* JOIN qualification clauses
7058 * Possibilities are:
7059 * USING ( column list ) allows only unqualified column names,
7060 * which must match between tables.
7061 * ON expr allows more general qualifications.
7063 * We return USING as a List node, while an ON-expr will not be a List.
7066 join_qual: USING
'(' name_list
')' { $$
= (Node
*) $3; }
7067 | ON a_expr
{ $$
= $2; }
7074 /* default inheritance */
7076 $$
->inhOpt
= INH_DEFAULT
;
7079 | qualified_name
'*'
7081 /* inheritance query */
7083 $$
->inhOpt
= INH_YES
;
7086 | ONLY qualified_name
7088 /* no inheritance */
7090 $$
->inhOpt
= INH_NO
;
7093 | ONLY
'(' qualified_name
')'
7095 /* no inheritance, SQL99-style syntax */
7097 $$
->inhOpt
= INH_NO
;
7104 * Given "UPDATE foo set set ...", we have to decide without looking any
7105 * further ahead whether the first "set" is an alias or the UPDATE's SET
7106 * keyword. Since "set" is allowed as a column name both interpretations
7107 * are feasible. We resolve the shift/reduce conflict by giving the first
7108 * relation_expr_opt_alias production a higher precedence than the SET token
7109 * has, causing the parser to prefer to reduce, in effect assuming that the
7110 * SET is not an alias.
7112 relation_expr_opt_alias: relation_expr %prec UMINUS
7116 | relation_expr ColId
7118 Alias
*alias
= makeNode
(Alias
);
7119 alias
->aliasname
= $2;
7123 | relation_expr AS ColId
7125 Alias
*alias
= makeNode
(Alias
);
7126 alias
->aliasname
= $3;
7133 func_table: func_expr
{ $$
= $1; }
7138 WHERE a_expr
{ $$
= $2; }
7139 |
/*EMPTY*/ { $$
= NULL
; }
7142 /* variant for UPDATE and DELETE */
7143 where_or_current_clause:
7144 WHERE a_expr
{ $$
= $2; }
7145 | WHERE CURRENT_P OF name
7147 CurrentOfExpr
*n
= makeNode
(CurrentOfExpr
);
7148 /* cvarno is filled in by parse analysis */
7149 n
->cursor_name
= $4;
7150 n
->cursor_param
= 0;
7153 | WHERE CURRENT_P OF PARAM
7155 CurrentOfExpr
*n
= makeNode
(CurrentOfExpr
);
7156 /* cvarno is filled in by parse analysis */
7157 n
->cursor_name
= NULL
;
7158 n
->cursor_param
= $4;
7161 |
/*EMPTY*/ { $$
= NULL
; }
7165 TableFuncElementList:
7168 $$
= list_make1
($1);
7170 | TableFuncElementList
',' TableFuncElement
7172 $$
= lappend
($1, $3);
7176 TableFuncElement: ColId Typename
7178 ColumnDef
*n
= makeNode
(ColumnDef
);
7181 n
->constraints
= NIL
;
7187 /*****************************************************************************
7190 * SQL92 introduces a large amount of type-specific syntax.
7191 * Define individual clauses to handle these cases, and use
7192 * the generic case to handle regular type-extensible Postgres syntax.
7193 * - thomas 1997-10-10
7195 *****************************************************************************/
7197 Typename: SimpleTypename opt_array_bounds
7200 $$
->arrayBounds
= $2;
7202 | SETOF SimpleTypename opt_array_bounds
7205 $$
->arrayBounds
= $3;
7208 /* SQL standard syntax, currently only one-dimensional */
7209 | SimpleTypename ARRAY
'[' Iconst
']'
7212 $$
->arrayBounds
= list_make1
(makeInteger
($4));
7214 | SETOF SimpleTypename ARRAY
'[' Iconst
']'
7217 $$
->arrayBounds
= list_make1
(makeInteger
($5));
7220 | SimpleTypename ARRAY
7223 $$
->arrayBounds
= list_make1
(makeInteger
(-1));
7225 | SETOF SimpleTypename ARRAY
7228 $$
->arrayBounds
= list_make1
(makeInteger
(-1));
7234 opt_array_bounds
'[' ']'
7235 { $$
= lappend
($1, makeInteger
(-1)); }
7236 | opt_array_bounds
'[' Iconst
']'
7237 { $$
= lappend
($1, makeInteger
($3)); }
7243 GenericType
{ $$
= $1; }
7244 | Numeric
{ $$
= $1; }
7246 | Character
{ $$
= $1; }
7247 | ConstDatetime
{ $$
= $1; }
7248 | ConstInterval opt_interval
7253 | ConstInterval
'(' Iconst
')' opt_interval
7258 if
(list_length
($5) != 1)
7260 (errcode
(ERRCODE_SYNTAX_ERROR
),
7261 errmsg
("interval precision specified twice"),
7262 scanner_errposition
(@
1)));
7263 $$
->typmods
= lappend
($5, makeIntConst
($3, @
3));
7266 $$
->typmods
= list_make2
(makeIntConst
(INTERVAL_FULL_RANGE
, -1),
7267 makeIntConst
($3, @
3));
7271 /* We have a separate ConstTypename to allow defaulting fixed-length
7272 * types such as CHAR() and BIT() to an unspecified length.
7273 * SQL9x requires that these default to a length of one, but this
7274 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
7275 * where there is an obvious better choice to make.
7276 * Note that ConstInterval is not included here since it must
7277 * be pushed up higher in the rules to accomodate the postfix
7278 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
7279 * the generic-type-name case in AExprConst to avoid premature
7280 * reduce/reduce conflicts against function names.
7283 Numeric
{ $$
= $1; }
7284 | ConstBit
{ $$
= $1; }
7285 | ConstCharacter
{ $$
= $1; }
7286 | ConstDatetime
{ $$
= $1; }
7290 * GenericType covers all type names that don't have special syntax mandated
7291 * by the standard, including qualified names. We also allow type modifiers.
7292 * To avoid parsing conflicts against function invocations, the modifiers
7293 * have to be shown as expr_list here, but parse analysis will only accept
7294 * constants for them.
7297 type_function_name opt_type_modifiers
7299 $$
= makeTypeName
($1);
7303 | type_function_name attrs opt_type_modifiers
7305 $$
= makeTypeNameFromNameList
(lcons
(makeString
($1), $2));
7311 opt_type_modifiers: '(' expr_list
')' { $$
= $2; }
7312 |
/* EMPTY */ { $$
= NIL
; }
7316 * SQL92 numeric data types
7320 $$
= SystemTypeName
("int4");
7325 $$
= SystemTypeName
("int4");
7330 $$
= SystemTypeName
("int2");
7335 $$
= SystemTypeName
("int8");
7340 $$
= SystemTypeName
("float4");
7348 | DOUBLE_P PRECISION
7350 $$
= SystemTypeName
("float8");
7353 | DECIMAL_P opt_type_modifiers
7355 $$
= SystemTypeName
("numeric");
7359 | DEC opt_type_modifiers
7361 $$
= SystemTypeName
("numeric");
7365 | NUMERIC opt_type_modifiers
7367 $$
= SystemTypeName
("numeric");
7373 $$
= SystemTypeName
("bool");
7378 opt_float: '(' Iconst
')'
7381 * Check FLOAT() precision limits assuming IEEE floating
7382 * types - thomas 1997-09-18
7386 (errcode
(ERRCODE_INVALID_PARAMETER_VALUE
),
7387 errmsg
("precision for type float must be at least 1 bit"),
7388 scanner_errposition
(@
2)));
7390 $$
= SystemTypeName
("float4");
7392 $$
= SystemTypeName
("float8");
7395 (errcode
(ERRCODE_INVALID_PARAMETER_VALUE
),
7396 errmsg
("precision for type float must be less than 54 bits"),
7397 scanner_errposition
(@
2)));
7401 $$
= SystemTypeName
("float8");
7406 * SQL92 bit-field data types
7407 * The following implements BIT() and BIT VARYING().
7419 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
7420 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
7421 ConstBit: BitWithLength
7433 BIT opt_varying
'(' expr_list
')'
7437 typname
= $2 ?
"varbit" : "bit";
7438 $$
= SystemTypeName
(typname
);
7447 /* bit defaults to bit(1), varbit to no limit */
7450 $$
= SystemTypeName
("varbit");
7454 $$
= SystemTypeName
("bit");
7455 $$
->typmods
= list_make1
(makeIntConst
(1, -1));
7463 * SQL92 character data types
7464 * The following implements CHAR() and VARCHAR().
7466 Character: CharacterWithLength
7470 | CharacterWithoutLength
7476 ConstCharacter: CharacterWithLength
7480 | CharacterWithoutLength
7482 /* Length was not specified so allow to be unrestricted.
7483 * This handles problems with fixed-length (bpchar) strings
7484 * which in column definitions must default to a length
7485 * of one, but should not be constrained if the length
7486 * was not specified.
7493 CharacterWithLength: character
'(' Iconst
')' opt_charset
7495 if
(($5 != NULL
) && (strcmp
($5, "sql_text") != 0))
7499 type
= palloc
(strlen
($1) + 1 + strlen
($5) + 1);
7506 $$
= SystemTypeName
($1);
7507 $$
->typmods
= list_make1
(makeIntConst
($3, @
3));
7512 CharacterWithoutLength: character opt_charset
7514 if
(($2 != NULL
) && (strcmp
($2, "sql_text") != 0))
7518 type
= palloc
(strlen
($1) + 1 + strlen
($2) + 1);
7525 $$
= SystemTypeName
($1);
7527 /* char defaults to char(1), varchar to no limit */
7528 if
(strcmp
($1, "bpchar") == 0)
7529 $$
->typmods
= list_make1
(makeIntConst
(1, -1));
7535 character: CHARACTER opt_varying
7536 { $$
= $2 ?
"varchar": "bpchar"; }
7537 | CHAR_P opt_varying
7538 { $$
= $2 ?
"varchar": "bpchar"; }
7541 | NATIONAL CHARACTER opt_varying
7542 { $$
= $3 ?
"varchar": "bpchar"; }
7543 | NATIONAL CHAR_P opt_varying
7544 { $$
= $3 ?
"varchar": "bpchar"; }
7546 { $$
= $2 ?
"varchar": "bpchar"; }
7550 VARYING
{ $$
= TRUE
; }
7551 |
/*EMPTY*/ { $$
= FALSE
; }
7555 CHARACTER SET ColId
{ $$
= $3; }
7556 |
/*EMPTY*/ { $$
= NULL
; }
7560 * SQL92 date/time types
7563 TIMESTAMP
'(' Iconst
')' opt_timezone
7566 $$
= SystemTypeName
("timestamptz");
7568 $$
= SystemTypeName
("timestamp");
7569 $$
->typmods
= list_make1
(makeIntConst
($3, @
3));
7572 | TIMESTAMP opt_timezone
7575 $$
= SystemTypeName
("timestamptz");
7577 $$
= SystemTypeName
("timestamp");
7580 | TIME
'(' Iconst
')' opt_timezone
7583 $$
= SystemTypeName
("timetz");
7585 $$
= SystemTypeName
("time");
7586 $$
->typmods
= list_make1
(makeIntConst
($3, @
3));
7592 $$
= SystemTypeName
("timetz");
7594 $$
= SystemTypeName
("time");
7602 $$
= SystemTypeName
("interval");
7608 WITH_TIME ZONE
{ $$
= TRUE
; }
7609 | WITHOUT TIME ZONE
{ $$
= FALSE
; }
7610 |
/*EMPTY*/ { $$
= FALSE
; }
7615 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(YEAR
), @
1)); }
7617 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(MONTH
), @
1)); }
7619 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(DAY
), @
1)); }
7621 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(HOUR
), @
1)); }
7623 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(MINUTE
), @
1)); }
7628 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(YEAR
) |
7629 INTERVAL_MASK
(MONTH
), @
1));
7633 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(DAY
) |
7634 INTERVAL_MASK
(HOUR
), @
1));
7638 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(DAY
) |
7639 INTERVAL_MASK
(HOUR
) |
7640 INTERVAL_MASK
(MINUTE
), @
1));
7642 | DAY_P TO interval_second
7645 linitial
($$
) = makeIntConst
(INTERVAL_MASK
(DAY
) |
7646 INTERVAL_MASK
(HOUR
) |
7647 INTERVAL_MASK
(MINUTE
) |
7648 INTERVAL_MASK
(SECOND
), @
1);
7650 | HOUR_P TO MINUTE_P
7652 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(HOUR
) |
7653 INTERVAL_MASK
(MINUTE
), @
1));
7655 | HOUR_P TO interval_second
7658 linitial
($$
) = makeIntConst
(INTERVAL_MASK
(HOUR
) |
7659 INTERVAL_MASK
(MINUTE
) |
7660 INTERVAL_MASK
(SECOND
), @
1);
7662 | MINUTE_P TO interval_second
7665 linitial
($$
) = makeIntConst
(INTERVAL_MASK
(MINUTE
) |
7666 INTERVAL_MASK
(SECOND
), @
1);
7675 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(SECOND
), @
1));
7677 | SECOND_P
'(' Iconst
')'
7679 $$
= list_make2
(makeIntConst
(INTERVAL_MASK
(SECOND
), @
1),
7680 makeIntConst
($3, @
3));
7685 /*****************************************************************************
7687 * expression grammar
7689 *****************************************************************************/
7692 * General expressions
7693 * This is the heart of the expression syntax.
7695 * We have two expression types: a_expr is the unrestricted kind, and
7696 * b_expr is a subset that must be used in some places to avoid shift/reduce
7697 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
7698 * because that use of AND conflicts with AND as a boolean operator. So,
7699 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
7701 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
7702 * always be used by surrounding it with parens.
7704 * c_expr is all the productions that are common to a_expr and b_expr;
7705 * it's factored out just to eliminate redundant coding.
7707 a_expr: c_expr
{ $$
= $1; }
7708 | a_expr TYPECAST Typename
7709 { $$
= makeTypeCast
($1, $3, @
2); }
7710 | a_expr AT TIME ZONE a_expr
7712 FuncCall
*n
= makeNode
(FuncCall
);
7713 n
->funcname
= SystemFuncName
("timezone");
7714 n
->args
= list_make2
($5, $1);
7715 n
->agg_star
= FALSE
;
7716 n
->agg_distinct
= FALSE
;
7717 n
->func_variadic
= FALSE
;
7722 * These operators must be called out explicitly in order to make use
7723 * of yacc/bison's automatic operator-precedence handling. All other
7724 * operator names are handled by the generic productions using "Op",
7725 * below; and all those operators will have the same precedence.
7727 * If you add more explicitly-known operators, be sure to add them
7728 * also to b_expr and to the MathOp list above.
7730 |
'+' a_expr %prec UMINUS
7731 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", NULL
, $2, @
1); }
7732 |
'-' a_expr %prec UMINUS
7733 { $$
= doNegate
($2, @
1); }
7735 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", $1, $3, @
2); }
7737 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "-", $1, $3, @
2); }
7739 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "*", $1, $3, @
2); }
7741 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "/", $1, $3, @
2); }
7743 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "%", $1, $3, @
2); }
7745 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "^", $1, $3, @
2); }
7747 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $3, @
2); }
7749 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $3, @
2); }
7751 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "=", $1, $3, @
2); }
7753 | a_expr qual_Op a_expr %prec Op
7754 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, $3, @
2); }
7755 | qual_Op a_expr %prec Op
7756 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $1, NULL
, $2, @
1); }
7757 | a_expr qual_Op %prec POSTFIXOP
7758 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, NULL
, @
2); }
7761 { $$
= (Node
*) makeA_Expr
(AEXPR_AND
, NIL
, $1, $3, @
2); }
7763 { $$
= (Node
*) makeA_Expr
(AEXPR_OR
, NIL
, $1, $3, @
2); }
7765 { $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
, $2, @
1); }
7767 | a_expr LIKE a_expr
7768 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~~", $1, $3, @
2); }
7769 | a_expr LIKE a_expr ESCAPE a_expr
7771 FuncCall
*n
= makeNode
(FuncCall
);
7772 n
->funcname
= SystemFuncName
("like_escape");
7773 n
->args
= list_make2
($3, $5);
7774 n
->agg_star
= FALSE
;
7775 n
->agg_distinct
= FALSE
;
7776 n
->func_variadic
= FALSE
;
7778 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~~", $1, (Node
*) n
, @
2);
7780 | a_expr NOT LIKE a_expr
7781 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~~", $1, $4, @
2); }
7782 | a_expr NOT LIKE a_expr ESCAPE a_expr
7784 FuncCall
*n
= makeNode
(FuncCall
);
7785 n
->funcname
= SystemFuncName
("like_escape");
7786 n
->args
= list_make2
($4, $6);
7787 n
->agg_star
= FALSE
;
7788 n
->agg_distinct
= FALSE
;
7789 n
->func_variadic
= FALSE
;
7791 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~~", $1, (Node
*) n
, @
2);
7793 | a_expr ILIKE a_expr
7794 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~~*", $1, $3, @
2); }
7795 | a_expr ILIKE a_expr ESCAPE a_expr
7797 FuncCall
*n
= makeNode
(FuncCall
);
7798 n
->funcname
= SystemFuncName
("like_escape");
7799 n
->args
= list_make2
($3, $5);
7800 n
->agg_star
= FALSE
;
7801 n
->agg_distinct
= FALSE
;
7802 n
->func_variadic
= FALSE
;
7804 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~~*", $1, (Node
*) n
, @
2);
7806 | a_expr NOT ILIKE a_expr
7807 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~~*", $1, $4, @
2); }
7808 | a_expr NOT ILIKE a_expr ESCAPE a_expr
7810 FuncCall
*n
= makeNode
(FuncCall
);
7811 n
->funcname
= SystemFuncName
("like_escape");
7812 n
->args
= list_make2
($4, $6);
7813 n
->agg_star
= FALSE
;
7814 n
->agg_distinct
= FALSE
;
7815 n
->func_variadic
= FALSE
;
7817 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~~*", $1, (Node
*) n
, @
2);
7820 | a_expr SIMILAR TO a_expr %prec SIMILAR
7822 FuncCall
*n
= makeNode
(FuncCall
);
7823 n
->funcname
= SystemFuncName
("similar_escape");
7824 n
->args
= list_make2
($4, makeNullAConst
(-1));
7825 n
->agg_star
= FALSE
;
7826 n
->agg_distinct
= FALSE
;
7827 n
->func_variadic
= FALSE
;
7829 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~", $1, (Node
*) n
, @
2);
7831 | a_expr SIMILAR TO a_expr ESCAPE a_expr
7833 FuncCall
*n
= makeNode
(FuncCall
);
7834 n
->funcname
= SystemFuncName
("similar_escape");
7835 n
->args
= list_make2
($4, $6);
7836 n
->agg_star
= FALSE
;
7837 n
->agg_distinct
= FALSE
;
7838 n
->func_variadic
= FALSE
;
7840 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~", $1, (Node
*) n
, @
2);
7842 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
7844 FuncCall
*n
= makeNode
(FuncCall
);
7845 n
->funcname
= SystemFuncName
("similar_escape");
7846 n
->args
= list_make2
($5, makeNullAConst
(-1));
7847 n
->agg_star
= FALSE
;
7848 n
->agg_distinct
= FALSE
;
7849 n
->func_variadic
= FALSE
;
7851 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~", $1, (Node
*) n
, @
2);
7853 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
7855 FuncCall
*n
= makeNode
(FuncCall
);
7856 n
->funcname
= SystemFuncName
("similar_escape");
7857 n
->args
= list_make2
($5, $7);
7858 n
->agg_star
= FALSE
;
7859 n
->agg_distinct
= FALSE
;
7860 n
->func_variadic
= FALSE
;
7862 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~", $1, (Node
*) n
, @
2);
7866 * Define SQL92-style Null test clause.
7867 * Allow two forms described in the standard:
7870 * Allow two SQL extensions
7876 NullTest
*n
= makeNode
(NullTest
);
7877 n
->arg
= (Expr
*) $1;
7878 n
->nulltesttype
= IS_NULL
;
7883 NullTest
*n
= makeNode
(NullTest
);
7884 n
->arg
= (Expr
*) $1;
7885 n
->nulltesttype
= IS_NULL
;
7888 | a_expr IS NOT NULL_P
7890 NullTest
*n
= makeNode
(NullTest
);
7891 n
->arg
= (Expr
*) $1;
7892 n
->nulltesttype
= IS_NOT_NULL
;
7897 NullTest
*n
= makeNode
(NullTest
);
7898 n
->arg
= (Expr
*) $1;
7899 n
->nulltesttype
= IS_NOT_NULL
;
7904 $$
= (Node
*)makeOverlaps
($1, $3, @
2);
7908 BooleanTest
*b
= makeNode
(BooleanTest
);
7909 b
->arg
= (Expr
*) $1;
7910 b
->booltesttype
= IS_TRUE
;
7913 | a_expr IS NOT TRUE_P
7915 BooleanTest
*b
= makeNode
(BooleanTest
);
7916 b
->arg
= (Expr
*) $1;
7917 b
->booltesttype
= IS_NOT_TRUE
;
7922 BooleanTest
*b
= makeNode
(BooleanTest
);
7923 b
->arg
= (Expr
*) $1;
7924 b
->booltesttype
= IS_FALSE
;
7927 | a_expr IS NOT FALSE_P
7929 BooleanTest
*b
= makeNode
(BooleanTest
);
7930 b
->arg
= (Expr
*) $1;
7931 b
->booltesttype
= IS_NOT_FALSE
;
7936 BooleanTest
*b
= makeNode
(BooleanTest
);
7937 b
->arg
= (Expr
*) $1;
7938 b
->booltesttype
= IS_UNKNOWN
;
7941 | a_expr IS NOT UNKNOWN
7943 BooleanTest
*b
= makeNode
(BooleanTest
);
7944 b
->arg
= (Expr
*) $1;
7945 b
->booltesttype
= IS_NOT_UNKNOWN
;
7948 | a_expr IS DISTINCT FROM a_expr %prec IS
7950 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
, "=", $1, $5, @
2);
7952 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
7954 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
,
7955 (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
,
7960 | a_expr IS OF
'(' type_list
')' %prec IS
7962 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OF
, "=", $1, (Node
*) $5, @
2);
7964 | a_expr IS NOT OF
'(' type_list
')' %prec IS
7966 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OF
, "<>", $1, (Node
*) $6, @
2);
7968 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
7970 $$
= (Node
*) makeA_Expr
(AEXPR_AND
, NIL
,
7971 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">=", $1, $4, @
2),
7972 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<=", $1, $6, @
2),
7975 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
7977 $$
= (Node
*) makeA_Expr
(AEXPR_OR
, NIL
,
7978 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $5, @
2),
7979 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $7, @
2),
7982 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
7984 $$
= (Node
*) makeA_Expr
(AEXPR_OR
, NIL
,
7985 (Node
*) makeA_Expr
(AEXPR_AND
, NIL
,
7986 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">=", $1, $4, @
2),
7987 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<=", $1, $6, @
2),
7989 (Node
*) makeA_Expr
(AEXPR_AND
, NIL
,
7990 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">=", $1, $6, @
2),
7991 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<=", $1, $4, @
2),
7995 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
7997 $$
= (Node
*) makeA_Expr
(AEXPR_AND
, NIL
,
7998 (Node
*) makeA_Expr
(AEXPR_OR
, NIL
,
7999 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $5, @
2),
8000 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $7, @
2),
8002 (Node
*) makeA_Expr
(AEXPR_OR
, NIL
,
8003 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $7, @
2),
8004 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $5, @
2),
8008 | a_expr IN_P in_expr
8010 /* in_expr returns a SubLink or a list of a_exprs */
8011 if
(IsA
($3, SubLink
))
8013 /* generate foo = ANY (subquery) */
8014 SubLink
*n
= (SubLink
*) $3;
8015 n
->subLinkType
= ANY_SUBLINK
;
8017 n
->operName
= list_make1
(makeString
("="));
8023 /* generate scalar IN expression */
8024 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_IN
, "=", $1, $3, @
2);
8027 | a_expr NOT IN_P in_expr
8029 /* in_expr returns a SubLink or a list of a_exprs */
8030 if
(IsA
($4, SubLink
))
8032 /* generate NOT (foo = ANY (subquery)) */
8033 /* Make an = ANY node */
8034 SubLink
*n
= (SubLink
*) $4;
8035 n
->subLinkType
= ANY_SUBLINK
;
8037 n
->operName
= list_make1
(makeString
("="));
8039 /* Stick a NOT on top */
8040 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
, (Node
*) n
, @
2);
8044 /* generate scalar NOT IN expression */
8045 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_IN
, "<>", $1, $4, @
2);
8048 | a_expr subquery_Op sub_type select_with_parens %prec Op
8050 SubLink
*n
= makeNode
(SubLink
);
8051 n
->subLinkType
= $3;
8058 | a_expr subquery_Op sub_type
'(' a_expr
')' %prec Op
8060 if
($3 == ANY_SUBLINK
)
8061 $$
= (Node
*) makeA_Expr
(AEXPR_OP_ANY
, $2, $1, $5, @
2);
8063 $$
= (Node
*) makeA_Expr
(AEXPR_OP_ALL
, $2, $1, $5, @
2);
8065 | UNIQUE select_with_parens
8067 /* Not sure how to get rid of the parentheses
8068 * but there are lots of shift/reduce errors without them.
8070 * Should be able to implement this by plopping the entire
8071 * select into a node, then transforming the target expressions
8072 * from whatever they are into count(*), and testing the
8073 * entire result equal to one.
8074 * But, will probably implement a separate node in the executor.
8077 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
8078 errmsg
("UNIQUE predicate is not yet implemented"),
8079 scanner_errposition
(@
1)));
8081 | a_expr IS DOCUMENT_P %prec IS
8083 $$
= makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
8084 list_make1
($1), @
2);
8086 | a_expr IS NOT DOCUMENT_P %prec IS
8088 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
,
8089 makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
8090 list_make1
($1), @
2),
8096 * Restricted expressions
8098 * b_expr is a subset of the complete expression syntax defined by a_expr.
8100 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
8101 * cause trouble in the places where b_expr is used. For simplicity, we
8102 * just eliminate all the boolean-keyword-operator productions from b_expr.
8106 | b_expr TYPECAST Typename
8107 { $$
= makeTypeCast
($1, $3, @
2); }
8108 |
'+' b_expr %prec UMINUS
8109 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", NULL
, $2, @
1); }
8110 |
'-' b_expr %prec UMINUS
8111 { $$
= doNegate
($2, @
1); }
8113 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", $1, $3, @
2); }
8115 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "-", $1, $3, @
2); }
8117 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "*", $1, $3, @
2); }
8119 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "/", $1, $3, @
2); }
8121 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "%", $1, $3, @
2); }
8123 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "^", $1, $3, @
2); }
8125 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $3, @
2); }
8127 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $3, @
2); }
8129 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "=", $1, $3, @
2); }
8130 | b_expr qual_Op b_expr %prec Op
8131 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, $3, @
2); }
8132 | qual_Op b_expr %prec Op
8133 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $1, NULL
, $2, @
1); }
8134 | b_expr qual_Op %prec POSTFIXOP
8135 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, NULL
, @
2); }
8136 | b_expr IS DISTINCT FROM b_expr %prec IS
8138 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
, "=", $1, $5, @
2);
8140 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
8142 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
,
8143 NULL
, (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
, "=", $1, $6, @
2), @
2);
8145 | b_expr IS OF
'(' type_list
')' %prec IS
8147 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OF
, "=", $1, (Node
*) $5, @
2);
8149 | b_expr IS NOT OF
'(' type_list
')' %prec IS
8151 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OF
, "<>", $1, (Node
*) $6, @
2);
8153 | b_expr IS DOCUMENT_P %prec IS
8155 $$
= makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
8156 list_make1
($1), @
2);
8158 | b_expr IS NOT DOCUMENT_P %prec IS
8160 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
,
8161 makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
8162 list_make1
($1), @
2),
8168 * Productions that can be used in both a_expr and b_expr.
8170 * Note: productions that refer recursively to a_expr or b_expr mostly
8171 * cannot appear here. However, it's OK to refer to a_exprs that occur
8172 * inside parentheses, such as function arguments; that cannot introduce
8173 * ambiguity to the b_expr syntax.
8175 c_expr: columnref
{ $$
= $1; }
8176 | AexprConst
{ $$
= $1; }
8177 | PARAM opt_indirection
8179 ParamRef
*p
= makeNode
(ParamRef
);
8184 A_Indirection
*n
= makeNode
(A_Indirection
);
8185 n
->arg
= (Node
*) p
;
8186 n
->indirection
= check_indirection
($2);
8192 |
'(' a_expr
')' opt_indirection
8196 A_Indirection
*n
= makeNode
(A_Indirection
);
8198 n
->indirection
= check_indirection
($4);
8208 | select_with_parens %prec UMINUS
8210 SubLink
*n
= makeNode
(SubLink
);
8211 n
->subLinkType
= EXPR_SUBLINK
;
8218 | EXISTS select_with_parens
8220 SubLink
*n
= makeNode
(SubLink
);
8221 n
->subLinkType
= EXISTS_SUBLINK
;
8228 | ARRAY select_with_parens
8230 SubLink
*n
= makeNode
(SubLink
);
8231 n
->subLinkType
= ARRAY_SUBLINK
;
8240 A_ArrayExpr
*n
= (A_ArrayExpr
*) $2;
8241 Assert
(IsA
(n
, A_ArrayExpr
));
8242 /* point outermost A_ArrayExpr to the ARRAY keyword */
8248 RowExpr
*r
= makeNode
(RowExpr
);
8250 r
->row_typeid
= InvalidOid
; /* not analyzed yet */
8257 * func_expr is split out from c_expr just so that we have a classification
8258 * for "everything that is a function call or looks like one". This isn't
8259 * very important, but it saves us having to document which variants are
8260 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
8261 * (Note that many of the special SQL functions wouldn't actually make any
8262 * sense as functional index entries, but we ignore that consideration here.)
8264 func_expr: func_name
'(' ')'
8266 FuncCall
*n
= makeNode
(FuncCall
);
8269 n
->agg_star
= FALSE
;
8270 n
->agg_distinct
= FALSE
;
8271 n
->func_variadic
= FALSE
;
8275 | func_name
'(' expr_list
')'
8277 FuncCall
*n
= makeNode
(FuncCall
);
8280 n
->agg_star
= FALSE
;
8281 n
->agg_distinct
= FALSE
;
8282 n
->func_variadic
= FALSE
;
8286 | func_name
'(' VARIADIC a_expr
')'
8288 FuncCall
*n
= makeNode
(FuncCall
);
8290 n
->args
= list_make1
($4);
8291 n
->agg_star
= FALSE
;
8292 n
->agg_distinct
= FALSE
;
8293 n
->func_variadic
= TRUE
;
8297 | func_name
'(' expr_list
',' VARIADIC a_expr
')'
8299 FuncCall
*n
= makeNode
(FuncCall
);
8301 n
->args
= lappend
($3, $6);
8302 n
->agg_star
= FALSE
;
8303 n
->agg_distinct
= FALSE
;
8304 n
->func_variadic
= TRUE
;
8308 | func_name
'(' ALL expr_list
')'
8310 FuncCall
*n
= makeNode
(FuncCall
);
8313 n
->agg_star
= FALSE
;
8314 n
->agg_distinct
= FALSE
;
8315 /* Ideally we'd mark the FuncCall node to indicate
8316 * "must be an aggregate", but there's no provision
8317 * for that in FuncCall at the moment.
8319 n
->func_variadic
= FALSE
;
8323 | func_name
'(' DISTINCT expr_list
')'
8325 FuncCall
*n
= makeNode
(FuncCall
);
8328 n
->agg_star
= FALSE
;
8329 n
->agg_distinct
= TRUE
;
8330 n
->func_variadic
= FALSE
;
8334 | func_name
'(' '*' ')'
8337 * We consider AGGREGATE(*) to invoke a parameterless
8338 * aggregate. This does the right thing for COUNT(*),
8339 * and there are no other aggregates in SQL92 that accept
8342 * The FuncCall node is also marked agg_star = true,
8343 * so that later processing can detect what the argument
8346 FuncCall
*n
= makeNode
(FuncCall
);
8350 n
->agg_distinct
= FALSE
;
8351 n
->func_variadic
= FALSE
;
8358 * Translate as "'now'::text::date".
8360 * We cannot use "'now'::date" because coerce_type() will
8361 * immediately reduce that to a constant representing
8362 * today's date. We need to delay the conversion until
8363 * runtime, else the wrong things will happen when
8364 * CURRENT_DATE is used in a column default value or rule.
8366 * This could be simplified if we had a way to generate
8367 * an expression tree representing runtime application
8368 * of type-input conversion functions. (As of PG 7.3
8369 * that is actually possible, but not clear that we want
8373 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8374 $$
= makeTypeCast
(n
, SystemTypeName
("date"), -1);
8379 * Translate as "'now'::text::timetz".
8380 * See comments for CURRENT_DATE.
8383 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8384 $$
= makeTypeCast
(n
, SystemTypeName
("timetz"), -1);
8386 | CURRENT_TIME
'(' Iconst
')'
8389 * Translate as "'now'::text::timetz(n)".
8390 * See comments for CURRENT_DATE.
8394 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8395 d
= SystemTypeName
("timetz");
8396 d
->typmods
= list_make1
(makeIntConst
($3, @
3));
8397 $$
= makeTypeCast
(n
, d
, -1);
8402 * Translate as "now()", since we have a function that
8403 * does exactly what is needed.
8405 FuncCall
*n
= makeNode
(FuncCall
);
8406 n
->funcname
= SystemFuncName
("now");
8408 n
->agg_star
= FALSE
;
8409 n
->agg_distinct
= FALSE
;
8410 n
->func_variadic
= FALSE
;
8414 | CURRENT_TIMESTAMP
'(' Iconst
')'
8417 * Translate as "'now'::text::timestamptz(n)".
8418 * See comments for CURRENT_DATE.
8422 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8423 d
= SystemTypeName
("timestamptz");
8424 d
->typmods
= list_make1
(makeIntConst
($3, @
3));
8425 $$
= makeTypeCast
(n
, d
, -1);
8430 * Translate as "'now'::text::time".
8431 * See comments for CURRENT_DATE.
8434 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8435 $$
= makeTypeCast
((Node
*)n
, SystemTypeName
("time"), -1);
8437 | LOCALTIME
'(' Iconst
')'
8440 * Translate as "'now'::text::time(n)".
8441 * See comments for CURRENT_DATE.
8445 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8446 d
= SystemTypeName
("time");
8447 d
->typmods
= list_make1
(makeIntConst
($3, @
3));
8448 $$
= makeTypeCast
((Node
*)n
, d
, -1);
8453 * Translate as "'now'::text::timestamp".
8454 * See comments for CURRENT_DATE.
8457 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8458 $$
= makeTypeCast
(n
, SystemTypeName
("timestamp"), -1);
8460 | LOCALTIMESTAMP
'(' Iconst
')'
8463 * Translate as "'now'::text::timestamp(n)".
8464 * See comments for CURRENT_DATE.
8468 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8469 d
= SystemTypeName
("timestamp");
8470 d
->typmods
= list_make1
(makeIntConst
($3, @
3));
8471 $$
= makeTypeCast
(n
, d
, -1);
8475 FuncCall
*n
= makeNode
(FuncCall
);
8476 n
->funcname
= SystemFuncName
("current_user");
8478 n
->agg_star
= FALSE
;
8479 n
->agg_distinct
= FALSE
;
8480 n
->func_variadic
= FALSE
;
8486 FuncCall
*n
= makeNode
(FuncCall
);
8487 n
->funcname
= SystemFuncName
("current_user");
8489 n
->agg_star
= FALSE
;
8490 n
->agg_distinct
= FALSE
;
8491 n
->func_variadic
= FALSE
;
8497 FuncCall
*n
= makeNode
(FuncCall
);
8498 n
->funcname
= SystemFuncName
("session_user");
8500 n
->agg_star
= FALSE
;
8501 n
->agg_distinct
= FALSE
;
8502 n
->func_variadic
= FALSE
;
8508 FuncCall
*n
= makeNode
(FuncCall
);
8509 n
->funcname
= SystemFuncName
("current_user");
8511 n
->agg_star
= FALSE
;
8512 n
->agg_distinct
= FALSE
;
8513 n
->func_variadic
= FALSE
;
8519 FuncCall
*n
= makeNode
(FuncCall
);
8520 n
->funcname
= SystemFuncName
("current_database");
8522 n
->agg_star
= FALSE
;
8523 n
->agg_distinct
= FALSE
;
8524 n
->func_variadic
= FALSE
;
8530 FuncCall
*n
= makeNode
(FuncCall
);
8531 n
->funcname
= SystemFuncName
("current_schema");
8533 n
->agg_star
= FALSE
;
8534 n
->agg_distinct
= FALSE
;
8535 n
->func_variadic
= FALSE
;
8539 | CAST
'(' a_expr AS Typename
')'
8540 { $$
= makeTypeCast
($3, $5, @
1); }
8541 | EXTRACT
'(' extract_list
')'
8543 FuncCall
*n
= makeNode
(FuncCall
);
8544 n
->funcname
= SystemFuncName
("date_part");
8546 n
->agg_star
= FALSE
;
8547 n
->agg_distinct
= FALSE
;
8548 n
->func_variadic
= FALSE
;
8552 | OVERLAY
'(' overlay_list
')'
8554 /* overlay(A PLACING B FROM C FOR D) is converted to
8555 * substring(A, 1, C-1) || B || substring(A, C+1, C+D)
8556 * overlay(A PLACING B FROM C) is converted to
8557 * substring(A, 1, C-1) || B || substring(A, C+1, C+char_length(B))
8559 FuncCall
*n
= makeNode
(FuncCall
);
8560 n
->funcname
= SystemFuncName
("overlay");
8562 n
->agg_star
= FALSE
;
8563 n
->agg_distinct
= FALSE
;
8564 n
->func_variadic
= FALSE
;
8568 | POSITION
'(' position_list
')'
8570 /* position(A in B) is converted to position(B, A) */
8571 FuncCall
*n
= makeNode
(FuncCall
);
8572 n
->funcname
= SystemFuncName
("position");
8574 n
->agg_star
= FALSE
;
8575 n
->agg_distinct
= FALSE
;
8576 n
->func_variadic
= FALSE
;
8580 | SUBSTRING
'(' substr_list
')'
8582 /* substring(A from B for C) is converted to
8583 * substring(A, B, C) - thomas 2000-11-28
8585 FuncCall
*n
= makeNode
(FuncCall
);
8586 n
->funcname
= SystemFuncName
("substring");
8588 n
->agg_star
= FALSE
;
8589 n
->agg_distinct
= FALSE
;
8590 n
->func_variadic
= FALSE
;
8594 | TREAT
'(' a_expr AS Typename
')'
8596 /* TREAT(expr AS target) converts expr of a particular type to target,
8597 * which is defined to be a subtype of the original expression.
8598 * In SQL99, this is intended for use with structured UDTs,
8599 * but let's make this a generally useful form allowing stronger
8600 * coercions than are handled by implicit casting.
8602 FuncCall
*n
= makeNode
(FuncCall
);
8603 /* Convert SystemTypeName() to SystemFuncName() even though
8604 * at the moment they result in the same thing.
8606 n
->funcname
= SystemFuncName
(((Value
*)llast
($5->names
))->val.str
);
8607 n
->args
= list_make1
($3);
8608 n
->agg_star
= FALSE
;
8609 n
->agg_distinct
= FALSE
;
8610 n
->func_variadic
= FALSE
;
8614 | TRIM
'(' BOTH trim_list
')'
8616 /* various trim expressions are defined in SQL92
8617 * - thomas 1997-07-19
8619 FuncCall
*n
= makeNode
(FuncCall
);
8620 n
->funcname
= SystemFuncName
("btrim");
8622 n
->agg_star
= FALSE
;
8623 n
->agg_distinct
= FALSE
;
8624 n
->func_variadic
= FALSE
;
8628 | TRIM
'(' LEADING trim_list
')'
8630 FuncCall
*n
= makeNode
(FuncCall
);
8631 n
->funcname
= SystemFuncName
("ltrim");
8633 n
->agg_star
= FALSE
;
8634 n
->agg_distinct
= FALSE
;
8635 n
->func_variadic
= FALSE
;
8639 | TRIM
'(' TRAILING trim_list
')'
8641 FuncCall
*n
= makeNode
(FuncCall
);
8642 n
->funcname
= SystemFuncName
("rtrim");
8644 n
->agg_star
= FALSE
;
8645 n
->agg_distinct
= FALSE
;
8646 n
->func_variadic
= FALSE
;
8650 | TRIM
'(' trim_list
')'
8652 FuncCall
*n
= makeNode
(FuncCall
);
8653 n
->funcname
= SystemFuncName
("btrim");
8655 n
->agg_star
= FALSE
;
8656 n
->agg_distinct
= FALSE
;
8657 n
->func_variadic
= FALSE
;
8661 | NULLIF
'(' a_expr
',' a_expr
')'
8663 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_NULLIF
, "=", $3, $5, @
1);
8665 | COALESCE
'(' expr_list
')'
8667 CoalesceExpr
*c
= makeNode
(CoalesceExpr
);
8672 | GREATEST
'(' expr_list
')'
8674 MinMaxExpr
*v
= makeNode
(MinMaxExpr
);
8676 v
->op
= IS_GREATEST
;
8680 | LEAST
'(' expr_list
')'
8682 MinMaxExpr
*v
= makeNode
(MinMaxExpr
);
8688 | XMLCONCAT
'(' expr_list
')'
8690 $$
= makeXmlExpr
(IS_XMLCONCAT
, NULL
, NIL
, $3, @
1);
8692 | XMLELEMENT
'(' NAME_P ColLabel
')'
8694 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, NIL
, NIL
, @
1);
8696 | XMLELEMENT
'(' NAME_P ColLabel
',' xml_attributes
')'
8698 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, $6, NIL
, @
1);
8700 | XMLELEMENT
'(' NAME_P ColLabel
',' expr_list
')'
8702 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, NIL
, $6, @
1);
8704 | XMLELEMENT
'(' NAME_P ColLabel
',' xml_attributes
',' expr_list
')'
8706 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, $6, $8, @
1);
8708 | XMLFOREST
'(' xml_attribute_list
')'
8710 $$
= makeXmlExpr
(IS_XMLFOREST
, NULL
, $3, NIL
, @
1);
8712 | XMLPARSE
'(' document_or_content a_expr xml_whitespace_option
')'
8714 XmlExpr
*x
= (XmlExpr
*)
8715 makeXmlExpr
(IS_XMLPARSE
, NULL
, NIL
,
8716 list_make2
($4, makeBoolAConst
($5, -1)),
8721 | XMLPI
'(' NAME_P ColLabel
')'
8723 $$
= makeXmlExpr
(IS_XMLPI
, $4, NULL
, NIL
, @
1);
8725 | XMLPI
'(' NAME_P ColLabel
',' a_expr
')'
8727 $$
= makeXmlExpr
(IS_XMLPI
, $4, NULL
, list_make1
($6), @
1);
8729 | XMLROOT
'(' a_expr
',' xml_root_version opt_xml_root_standalone
')'
8731 $$
= makeXmlExpr
(IS_XMLROOT
, NULL
, NIL
,
8732 list_make3
($3, $5, $6), @
1);
8734 | XMLSERIALIZE
'(' document_or_content a_expr AS SimpleTypename
')'
8736 XmlSerialize
*n
= makeNode
(XmlSerialize
);
8748 xml_root_version: VERSION_P a_expr
8750 | VERSION_P NO VALUE_P
8751 { $$
= makeNullAConst
(-1); }
8754 opt_xml_root_standalone: ',' STANDALONE_P YES_P
8755 { $$
= makeIntConst
(XML_STANDALONE_YES
, -1); }
8756 |
',' STANDALONE_P NO
8757 { $$
= makeIntConst
(XML_STANDALONE_NO
, -1); }
8758 |
',' STANDALONE_P NO VALUE_P
8759 { $$
= makeIntConst
(XML_STANDALONE_NO_VALUE
, -1); }
8761 { $$
= makeIntConst
(XML_STANDALONE_OMITTED
, -1); }
8764 xml_attributes: XMLATTRIBUTES
'(' xml_attribute_list
')' { $$
= $3; }
8767 xml_attribute_list: xml_attribute_el
{ $$
= list_make1
($1); }
8768 | xml_attribute_list
',' xml_attribute_el
{ $$
= lappend
($1, $3); }
8771 xml_attribute_el: a_expr AS ColLabel
8773 $$
= makeNode
(ResTarget
);
8775 $$
->indirection
= NIL
;
8776 $$
->val
= (Node
*) $1;
8781 $$
= makeNode
(ResTarget
);
8783 $$
->indirection
= NIL
;
8784 $$
->val
= (Node
*) $1;
8789 document_or_content: DOCUMENT_P
{ $$
= XMLOPTION_DOCUMENT
; }
8790 | CONTENT_P
{ $$
= XMLOPTION_CONTENT
; }
8793 xml_whitespace_option: PRESERVE WHITESPACE_P
{ $$
= TRUE
; }
8794 | STRIP_P WHITESPACE_P
{ $$
= FALSE
; }
8795 |
/*EMPTY*/ { $$
= FALSE
; }
8799 * Supporting nonterminals for expressions.
8802 /* Explicit row production.
8804 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
8805 * without conflicting with the parenthesized a_expr production. Without the
8806 * ROW keyword, there must be more than one a_expr inside the parens.
8808 row: ROW
'(' expr_list
')' { $$
= $3; }
8809 | ROW
'(' ')' { $$
= NIL
; }
8810 |
'(' expr_list
',' a_expr
')' { $$
= lappend
($2, $4); }
8813 sub_type: ANY
{ $$
= ANY_SUBLINK
; }
8814 | SOME
{ $$
= ANY_SUBLINK
; }
8815 | ALL
{ $$
= ALL_SUBLINK
; }
8818 all_Op: Op
{ $$
= $1; }
8819 | MathOp
{ $$
= $1; }
8822 MathOp: '+' { $$
= "+"; }
8834 { $$
= list_make1
(makeString
($1)); }
8835 | OPERATOR
'(' any_operator
')'
8841 { $$
= list_make1
(makeString
($1)); }
8842 | OPERATOR
'(' any_operator
')'
8848 { $$
= list_make1
(makeString
($1)); }
8849 | OPERATOR
'(' any_operator
')'
8852 { $$
= list_make1
(makeString
("~~")); }
8854 { $$
= list_make1
(makeString
("!~~")); }
8856 { $$
= list_make1
(makeString
("~~*")); }
8858 { $$
= list_make1
(makeString
("!~~*")); }
8859 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
8860 * the regular expression is preprocessed by a function (similar_escape),
8861 * and the ~ operator for posix regular expressions is used.
8862 * x SIMILAR TO y -> x ~ similar_escape(y)
8863 * this transformation is made on the fly by the parser upwards.
8864 * however the SubLink structure which handles any/some/all stuff
8865 * is not ready for such a thing.
8871 $$
= list_make1
($1);
8873 | expr_list
',' a_expr
8875 $$
= lappend
($1, $3);
8879 type_list: Typename
{ $$
= list_make1
($1); }
8880 | type_list
',' Typename
{ $$
= lappend
($1, $3); }
8883 array_expr: '[' expr_list
']'
8885 $$
= makeAArrayExpr
($2, @
1);
8887 |
'[' array_expr_list
']'
8889 $$
= makeAArrayExpr
($2, @
1);
8893 $$
= makeAArrayExpr
(NIL
, @
1);
8897 array_expr_list: array_expr
{ $$
= list_make1
($1); }
8898 | array_expr_list
',' array_expr
{ $$
= lappend
($1, $3); }
8903 extract_arg FROM a_expr
8905 $$
= list_make2
(makeStringConst
($1, @
1), $3);
8907 |
/*EMPTY*/ { $$
= NIL
; }
8910 /* Allow delimited string Sconst in extract_arg as an SQL extension.
8911 * - thomas 2001-04-12
8915 | YEAR_P
{ $$
= "year"; }
8916 | MONTH_P
{ $$
= "month"; }
8917 | DAY_P
{ $$
= "day"; }
8918 | HOUR_P
{ $$
= "hour"; }
8919 | MINUTE_P
{ $$
= "minute"; }
8920 | SECOND_P
{ $$
= "second"; }
8921 | Sconst
{ $$
= $1; }
8924 /* OVERLAY() arguments
8925 * SQL99 defines the OVERLAY() function:
8926 * o overlay(text placing text from int for int)
8927 * o overlay(text placing text from int)
8930 a_expr overlay_placing substr_from substr_for
8932 $$
= list_make4
($1, $2, $3, $4);
8934 | a_expr overlay_placing substr_from
8936 $$
= list_make3
($1, $2, $3);
8945 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
8948 b_expr IN_P b_expr
{ $$
= list_make2
($3, $1); }
8949 |
/*EMPTY*/ { $$
= NIL
; }
8952 /* SUBSTRING() arguments
8953 * SQL9x defines a specific syntax for arguments to SUBSTRING():
8954 * o substring(text from int for int)
8955 * o substring(text from int) get entire string from starting point "int"
8956 * o substring(text for int) get first "int" characters of string
8957 * o substring(text from pattern) get entire string matching pattern
8958 * o substring(text from pattern for escape) same with specified escape char
8959 * We also want to support generic substring functions which accept
8960 * the usual generic list of arguments. So we will accept both styles
8961 * here, and convert the SQL9x style to the generic list for further
8962 * processing. - thomas 2000-11-28
8965 a_expr substr_from substr_for
8967 $$
= list_make3
($1, $2, $3);
8969 | a_expr substr_for substr_from
8971 /* not legal per SQL99, but might as well allow it */
8972 $$
= list_make3
($1, $3, $2);
8974 | a_expr substr_from
8976 $$
= list_make2
($1, $2);
8981 * Since there are no cases where this syntax allows
8982 * a textual FOR value, we forcibly cast the argument
8983 * to int4. The possible matches in pg_proc are
8984 * substring(text,int4) and substring(text,text),
8985 * and we don't want the parser to choose the latter,
8986 * which it is likely to do if the second argument
8987 * is unknown or doesn't have an implicit cast to int4.
8989 $$
= list_make3
($1, makeIntConst
(1, -1),
8991 SystemTypeName
("int4"), -1));
9002 FROM a_expr
{ $$
= $2; }
9005 substr_for: FOR a_expr
{ $$
= $2; }
9008 trim_list: a_expr FROM expr_list
{ $$
= lappend
($3, $1); }
9009 | FROM expr_list
{ $$
= $2; }
9010 | expr_list
{ $$
= $1; }
9013 in_expr: select_with_parens
9015 SubLink
*n
= makeNode
(SubLink
);
9017 /* other fields will be filled later */
9020 |
'(' expr_list
')' { $$
= (Node
*)$2; }
9024 * Define SQL92-style case clause.
9025 * - Full specification
9026 * CASE WHEN a = b THEN c ... ELSE d END
9027 * - Implicit argument
9028 * CASE a WHEN b THEN c ... ELSE d END
9030 case_expr: CASE case_arg when_clause_list case_default END_P
9032 CaseExpr
*c
= makeNode
(CaseExpr
);
9033 c
->casetype
= InvalidOid
; /* not analyzed yet */
9034 c
->arg
= (Expr
*) $2;
9036 c
->defresult
= (Expr
*) $4;
9043 /* There must be at least one */
9044 when_clause
{ $$
= list_make1
($1); }
9045 | when_clause_list when_clause
{ $$
= lappend
($1, $2); }
9049 WHEN a_expr THEN a_expr
9051 CaseWhen
*w
= makeNode
(CaseWhen
);
9052 w
->expr
= (Expr
*) $2;
9053 w
->result
= (Expr
*) $4;
9060 ELSE a_expr
{ $$
= $2; }
9061 |
/*EMPTY*/ { $$
= NULL
; }
9064 case_arg: a_expr
{ $$
= $1; }
9065 |
/*EMPTY*/ { $$
= NULL
; }
9069 * columnref starts with relation_name not ColId, so that OLD and NEW
9070 * references can be accepted. Note that when there are more than two
9071 * dotted names, the first name is not actually a relation name...
9073 columnref: relation_name
9075 $$
= makeColumnRef
($1, NIL
, @
1);
9077 | relation_name indirection
9079 $$
= makeColumnRef
($1, $2, @
1);
9086 $$
= (Node
*) makeString
($2);
9090 $$
= (Node
*) makeNode
(A_Star
);
9094 A_Indices
*ai
= makeNode
(A_Indices
);
9099 |
'[' a_expr
':' a_expr
']'
9101 A_Indices
*ai
= makeNode
(A_Indices
);
9109 indirection_el
{ $$
= list_make1
($1); }
9110 | indirection indirection_el
{ $$
= lappend
($1, $2); }
9114 /*EMPTY*/ { $$
= NIL
; }
9115 | opt_indirection indirection_el
{ $$
= lappend
($1, $2); }
9118 opt_asymmetric: ASYMMETRIC
9123 * The SQL spec defines "contextually typed value expressions" and
9124 * "contextually typed row value constructors", which for our purposes
9125 * are the same as "a_expr" and "row" except that DEFAULT can appear at
9130 a_expr
{ $$
= (Node
*) $1; }
9133 SetToDefault
*n
= makeNode
(SetToDefault
);
9140 ctext_expr
{ $$
= list_make1
($1); }
9141 | ctext_expr_list
',' ctext_expr
{ $$
= lappend
($1, $3); }
9145 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
9146 * making VALUES a fully reserved word, which will probably break more apps
9147 * than allowing the noise-word is worth.
9149 ctext_row: '(' ctext_expr_list
')' { $$
= $2; }
9153 /*****************************************************************************
9155 * target list for SELECT
9157 *****************************************************************************/
9160 target_el
{ $$
= list_make1
($1); }
9161 | target_list
',' target_el
{ $$
= lappend
($1, $3); }
9164 target_el: a_expr AS ColLabel
9166 $$
= makeNode
(ResTarget
);
9168 $$
->indirection
= NIL
;
9169 $$
->val
= (Node
*)$1;
9173 * We support omitting AS only for column labels that aren't
9174 * any known keyword. There is an ambiguity against postfix
9175 * operators: is "a ! b" an infix expression, or a postfix
9176 * expression and a column label? We prefer to resolve this
9177 * as an infix expression, which we accomplish by assigning
9178 * IDENT a precedence higher than POSTFIXOP.
9182 $$
= makeNode
(ResTarget
);
9184 $$
->indirection
= NIL
;
9185 $$
->val
= (Node
*)$1;
9190 $$
= makeNode
(ResTarget
);
9192 $$
->indirection
= NIL
;
9193 $$
->val
= (Node
*)$1;
9198 ColumnRef
*n
= makeNode
(ColumnRef
);
9199 n
->fields
= list_make1
(makeNode
(A_Star
));
9202 $$
= makeNode
(ResTarget
);
9204 $$
->indirection
= NIL
;
9205 $$
->val
= (Node
*)n
;
9211 /*****************************************************************************
9213 * Names and constants
9215 *****************************************************************************/
9218 SpecialRuleRelation
{ $$
= $1; }
9219 | ColId
{ $$
= $1; }
9222 qualified_name_list:
9223 qualified_name
{ $$
= list_make1
($1); }
9224 | qualified_name_list
',' qualified_name
{ $$
= lappend
($1, $3); }
9228 * The production for a qualified relation name has to exactly match the
9229 * production for a qualified func_name, because in a FROM clause we cannot
9230 * tell which we are parsing until we see what comes after it ('(' for a
9231 * func_name, something else for a relation). Therefore we allow 'indirection'
9232 * which may contain subscripts, and reject that case in the C code.
9237 $$
= makeNode
(RangeVar
);
9238 $$
->catalogname
= NULL
;
9239 $$
->schemaname
= NULL
;
9243 | relation_name indirection
9245 check_qualified_name
($2);
9246 $$
= makeNode
(RangeVar
);
9247 switch
(list_length
($2))
9250 $$
->catalogname
= NULL
;
9251 $$
->schemaname
= $1;
9252 $$
->relname
= strVal
(linitial
($2));
9255 $$
->catalogname
= $1;
9256 $$
->schemaname
= strVal
(linitial
($2));
9257 $$
->relname
= strVal
(lsecond
($2));
9261 (errcode
(ERRCODE_SYNTAX_ERROR
),
9262 errmsg
("improper qualified name (too many dotted names): %s",
9263 NameListToString
(lcons
(makeString
($1), $2))),
9264 scanner_errposition
(@
1)));
9272 { $$
= list_make1
(makeString
($1)); }
9273 | name_list
',' name
9274 { $$
= lappend
($1, makeString
($3)); }
9278 name: ColId
{ $$
= $1; };
9286 attr_name: ColLabel
{ $$
= $1; };
9288 index_name: ColId
{ $$
= $1; };
9290 file_name: Sconst
{ $$
= $1; };
9293 * The production for a qualified func_name has to exactly match the
9294 * production for a qualified columnref, because we cannot tell which we
9295 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
9296 * anything else for a columnref). Therefore we allow 'indirection' which
9297 * may contain subscripts, and reject that case in the C code. (If we
9298 * ever implement SQL99-like methods, such syntax may actually become legal!)
9300 func_name: type_function_name
9301 { $$
= list_make1
(makeString
($1)); }
9302 | relation_name indirection
9303 { $$
= check_func_name
(lcons
(makeString
($1), $2)); }
9312 $$
= makeIntConst
($1, @
1);
9316 $$
= makeFloatConst
($1, @
1);
9320 $$
= makeStringConst
($1, @
1);
9324 $$
= makeBitStringConst
($1, @
1);
9328 /* This is a bit constant per SQL99:
9329 * Without Feature F511, "BIT data type",
9330 * a <general literal> shall not be a
9331 * <bit string literal> or a <hex string literal>.
9333 $$
= makeBitStringConst
($1, @
1);
9337 /* generic type 'literal' syntax */
9338 TypeName
*t
= makeTypeNameFromNameList
($1);
9340 $$
= makeStringConstCast
($2, @
2, t
);
9342 | func_name
'(' expr_list
')' Sconst
9344 /* generic syntax with a type modifier */
9345 TypeName
*t
= makeTypeNameFromNameList
($1);
9348 $$
= makeStringConstCast
($5, @
5, t
);
9350 | ConstTypename Sconst
9352 $$
= makeStringConstCast
($2, @
2, $1);
9354 | ConstInterval Sconst opt_interval
9358 $$
= makeStringConstCast
($2, @
2, t
);
9360 | ConstInterval
'(' Iconst
')' Sconst opt_interval
9365 if
(list_length
($6) != 1)
9367 (errcode
(ERRCODE_SYNTAX_ERROR
),
9368 errmsg
("interval precision specified twice"),
9369 scanner_errposition
(@
1)));
9370 t
->typmods
= lappend
($6, makeIntConst
($3, @
3));
9373 t
->typmods
= list_make2
(makeIntConst
(INTERVAL_FULL_RANGE
, -1),
9374 makeIntConst
($3, @
3));
9375 $$
= makeStringConstCast
($5, @
5, t
);
9379 $$
= makeBoolAConst
(TRUE
, @
1);
9383 $$
= makeBoolAConst
(FALSE
, @
1);
9387 $$
= makeNullAConst
(@
1);
9391 Iconst: ICONST
{ $$
= $1; };
9392 Sconst: SCONST
{ $$
= $1; };
9393 RoleId: ColId
{ $$
= $1; };
9395 SignedIconst: Iconst
{ $$
= $1; }
9396 |
'+' Iconst
{ $$
= + $2; }
9397 |
'-' Iconst
{ $$
= - $2; }
9401 * Name classification hierarchy.
9403 * IDENT is the lexeme returned by the lexer for identifiers that match
9404 * no known keyword. In most cases, we can accept certain keywords as
9405 * names, not only IDENTs. We prefer to accept as many such keywords
9406 * as possible to minimize the impact of "reserved words" on programmers.
9407 * So, we divide names into several possible classes. The classification
9408 * is chosen in part to make keywords acceptable as names wherever possible.
9411 /* Column identifier --- names that can be column, table, etc names.
9413 ColId: IDENT
{ $$
= $1; }
9414 | unreserved_keyword
{ $$
= pstrdup
($1); }
9415 | col_name_keyword
{ $$
= pstrdup
($1); }
9418 /* Type/function identifier --- names that can be type or function names.
9420 type_function_name: IDENT
{ $$
= $1; }
9421 | unreserved_keyword
{ $$
= pstrdup
($1); }
9422 | type_func_name_keyword
{ $$
= pstrdup
($1); }
9425 /* Column label --- allowed labels in "AS" clauses.
9426 * This presently includes *all* Postgres keywords.
9428 ColLabel: IDENT
{ $$
= $1; }
9429 | unreserved_keyword
{ $$
= pstrdup
($1); }
9430 | col_name_keyword
{ $$
= pstrdup
($1); }
9431 | type_func_name_keyword
{ $$
= pstrdup
($1); }
9432 | reserved_keyword
{ $$
= pstrdup
($1); }
9437 * Keyword category lists. Generally, every keyword present in
9438 * the Postgres grammar should appear in exactly one of these lists.
9440 * Put a new keyword into the first list that it can go into without causing
9441 * shift or reduce conflicts. The earlier lists define "less reserved"
9442 * categories of keywords.
9444 * Make sure that each keyword's category in keywords.c matches where
9445 * it is listed here. (Someday we may be able to generate these lists and
9446 * keywords.c's table from a common master list.)
9449 /* "Unreserved" keywords --- available for use as any kind of name.
9691 /* Column identifier --- keywords that can be column, table, etc names.
9693 * Many of these keywords will in fact be recognized as type or function
9694 * names too; but they have special productions for the purpose, and so
9695 * can't be treated as "generic" type or function names.
9697 * The type names appearing here are not usable as function names
9698 * because they can be followed by '(' in typename productions, which
9699 * looks too much like a function call for an LR(1) parser.
9749 /* Type/function identifier --- keywords that can be type or function names.
9751 * Most of these are keywords that are used as operators in expressions;
9752 * in general such keywords can't be column names because they would be
9753 * ambiguous with variables, but they are unambiguous as function identifiers.
9755 * Do not include POSITION, SUBSTRING, etc here since they have explicit
9756 * productions in a_expr to support the goofy SQL9x argument syntax.
9757 * - thomas 2000-11-28
9759 type_func_name_keyword:
9783 /* Reserved keyword --- these keywords are usable only as a ColLabel.
9785 * Keywords appear here if they could not be distinguished from variable,
9786 * type, or function names in some contexts. Don't put things here unless
9871 SpecialRuleRelation:
9878 (errcode
(ERRCODE_SYNTAX_ERROR
),
9879 errmsg
("OLD used in query that is not in a rule"),
9880 scanner_errposition
(@
1)));
9888 (errcode
(ERRCODE_SYNTAX_ERROR
),
9889 errmsg
("NEW used in query that is not in a rule"),
9890 scanner_errposition
(@
1)));
9897 makeColumnRef
(char *colname
, List
*indirection
, int location
)
9900 * Generate a ColumnRef node, with an A_Indirection node added if there
9901 * is any subscripting in the specified indirection list. However,
9902 * any field selection at the start of the indirection list must be
9903 * transposed into the "fields" part of the ColumnRef node.
9905 ColumnRef
*c
= makeNode
(ColumnRef
);
9909 c
->location
= location
;
9910 foreach
(l
, indirection
)
9912 if
(IsA
(lfirst
(l
), A_Indices
))
9914 A_Indirection
*i
= makeNode
(A_Indirection
);
9918 /* easy case - all indirection goes to A_Indirection */
9919 c
->fields
= list_make1
(makeString
(colname
));
9920 i
->indirection
= check_indirection
(indirection
);
9924 /* got to split the list in two */
9925 i
->indirection
= check_indirection
(list_copy_tail
(indirection
,
9927 indirection
= list_truncate
(indirection
, nfields
);
9928 c
->fields
= lcons
(makeString
(colname
), indirection
);
9930 i
->arg
= (Node
*) c
;
9933 else if
(IsA
(lfirst
(l
), A_Star
))
9935 /* We only allow '*' at the end of a ColumnRef */
9936 if
(lnext
(l
) != NULL
)
9937 yyerror("improper use of \"*\"");
9941 /* No subscripting, so all indirection gets added to field list */
9942 c
->fields
= lcons
(makeString
(colname
), indirection
);
9947 makeTypeCast
(Node
*arg
, TypeName
*typename
, int location
)
9949 TypeCast
*n
= makeNode
(TypeCast
);
9951 n
->typename
= typename
;
9952 n
->location
= location
;
9957 makeStringConst
(char *str
, int location
)
9959 A_Const
*n
= makeNode
(A_Const
);
9961 n
->val.type
= T_String
;
9962 n
->val.val.str
= str
;
9963 n
->location
= location
;
9969 makeStringConstCast
(char *str
, int location
, TypeName
*typename
)
9971 Node
*s
= makeStringConst
(str
, location
);
9973 return makeTypeCast
(s
, typename
, -1);
9977 makeIntConst
(int val
, int location
)
9979 A_Const
*n
= makeNode
(A_Const
);
9981 n
->val.type
= T_Integer
;
9982 n
->val.val.ival
= val
;
9983 n
->location
= location
;
9989 makeFloatConst
(char *str
, int location
)
9991 A_Const
*n
= makeNode
(A_Const
);
9993 n
->val.type
= T_Float
;
9994 n
->val.val.str
= str
;
9995 n
->location
= location
;
10001 makeBitStringConst
(char *str
, int location
)
10003 A_Const
*n
= makeNode
(A_Const
);
10005 n
->val.type
= T_BitString
;
10006 n
->val.val.str
= str
;
10007 n
->location
= location
;
10013 makeNullAConst
(int location
)
10015 A_Const
*n
= makeNode
(A_Const
);
10017 n
->val.type
= T_Null
;
10018 n
->location
= location
;
10024 makeAConst
(Value
*v
, int location
)
10031 n
= makeFloatConst
(v
->val.str
, location
);
10035 n
= makeIntConst
(v
->val.ival
, location
);
10040 n
= makeStringConst
(v
->val.str
, location
);
10047 /* makeBoolAConst()
10048 * Create an A_Const string node and put it inside a boolean cast.
10051 makeBoolAConst
(bool state
, int location
)
10053 A_Const
*n
= makeNode
(A_Const
);
10055 n
->val.type
= T_String
;
10056 n
->val.val.str
= (state ?
"t" : "f");
10057 n
->location
= location
;
10059 return makeTypeCast
((Node
*)n
, SystemTypeName
("bool"), -1);
10063 * Create and populate a FuncCall node to support the OVERLAPS operator.
10066 makeOverlaps
(List
*largs
, List
*rargs
, int location
)
10068 FuncCall
*n
= makeNode
(FuncCall
);
10070 n
->funcname
= SystemFuncName
("overlaps");
10071 if
(list_length
(largs
) == 1)
10072 largs
= lappend
(largs
, largs
);
10073 else if
(list_length
(largs
) != 2)
10075 (errcode
(ERRCODE_SYNTAX_ERROR
),
10076 errmsg
("wrong number of parameters on left side of OVERLAPS expression"),
10077 scanner_errposition
(location
)));
10078 if
(list_length
(rargs
) == 1)
10079 rargs
= lappend
(rargs
, rargs
);
10080 else if
(list_length
(rargs
) != 2)
10082 (errcode
(ERRCODE_SYNTAX_ERROR
),
10083 errmsg
("wrong number of parameters on right side of OVERLAPS expression"),
10084 scanner_errposition
(location
)));
10085 n
->args
= list_concat
(largs
, rargs
);
10086 n
->agg_star
= FALSE
;
10087 n
->agg_distinct
= FALSE
;
10088 n
->func_variadic
= FALSE
;
10089 n
->location
= location
;
10093 /* check_qualified_name --- check the result of qualified_name production
10095 * It's easiest to let the grammar production for qualified_name allow
10096 * subscripts and '*', which we then must reject here.
10099 check_qualified_name
(List
*names
)
10105 if
(!IsA
(lfirst
(i
), String
))
10106 yyerror("syntax error");
10110 /* check_func_name --- check the result of func_name production
10112 * It's easiest to let the grammar production for func_name allow subscripts
10113 * and '*', which we then must reject here.
10116 check_func_name
(List
*names
)
10122 if
(!IsA
(lfirst
(i
), String
))
10123 yyerror("syntax error");
10128 /* check_indirection --- check the result of indirection production
10130 * We only allow '*' at the end of the list, but it's hard to enforce that
10131 * in the grammar, so do it here.
10134 check_indirection
(List
*indirection
)
10138 foreach
(l
, indirection
)
10140 if
(IsA
(lfirst
(l
), A_Star
))
10142 if
(lnext
(l
) != NULL
)
10143 yyerror("improper use of \"*\"");
10146 return indirection
;
10149 /* extractArgTypes()
10150 * Given a list of FunctionParameter nodes, extract a list of just the
10151 * argument types (TypeNames) for input parameters only. This is what
10152 * is needed to look up an existing function, which is what is wanted by
10153 * the productions that use this call.
10156 extractArgTypes
(List
*parameters
)
10158 List
*result
= NIL
;
10161 foreach
(i
, parameters
)
10163 FunctionParameter
*p
= (FunctionParameter
*) lfirst
(i
);
10165 if
(p
->mode
!= FUNC_PARAM_OUT
&& p
->mode
!= FUNC_PARAM_TABLE
)
10166 result
= lappend
(result
, p
->argType
);
10171 /* findLeftmostSelect()
10172 * Find the leftmost component SelectStmt in a set-operation parsetree.
10174 static SelectStmt
*
10175 findLeftmostSelect
(SelectStmt
*node
)
10177 while
(node
&& node
->op
!= SETOP_NONE
)
10179 Assert
(node
&& IsA
(node
, SelectStmt
) && node
->larg
== NULL
);
10183 /* insertSelectOptions()
10184 * Insert ORDER BY, etc into an already-constructed SelectStmt.
10186 * This routine is just to avoid duplicating code in SelectStmt productions.
10189 insertSelectOptions
(SelectStmt
*stmt
,
10190 List
*sortClause
, List
*lockingClause
,
10191 Node
*limitOffset
, Node
*limitCount
,
10192 WithClause
*withClause
)
10194 Assert
(IsA
(stmt
, SelectStmt
));
10197 * Tests here are to reject constructs like
10198 * (SELECT foo ORDER BY bar) ORDER BY baz
10202 if
(stmt
->sortClause
)
10204 (errcode
(ERRCODE_SYNTAX_ERROR
),
10205 errmsg
("multiple ORDER BY clauses not allowed"),
10206 scanner_errposition
(exprLocation
((Node
*) sortClause
))));
10207 stmt
->sortClause
= sortClause
;
10209 /* We can handle multiple locking clauses, though */
10210 stmt
->lockingClause
= list_concat
(stmt
->lockingClause
, lockingClause
);
10213 if
(stmt
->limitOffset
)
10215 (errcode
(ERRCODE_SYNTAX_ERROR
),
10216 errmsg
("multiple OFFSET clauses not allowed"),
10217 scanner_errposition
(exprLocation
(limitOffset
))));
10218 stmt
->limitOffset
= limitOffset
;
10222 if
(stmt
->limitCount
)
10224 (errcode
(ERRCODE_SYNTAX_ERROR
),
10225 errmsg
("multiple LIMIT clauses not allowed"),
10226 scanner_errposition
(exprLocation
(limitCount
))));
10227 stmt
->limitCount
= limitCount
;
10231 if
(stmt
->withClause
)
10233 (errcode
(ERRCODE_SYNTAX_ERROR
),
10234 errmsg
("multiple WITH clauses not allowed"),
10235 scanner_errposition
(exprLocation
((Node
*) withClause
))));
10236 stmt
->withClause
= withClause
;
10241 makeSetOp
(SetOperation op
, bool all
, Node
*larg
, Node
*rarg
)
10243 SelectStmt
*n
= makeNode
(SelectStmt
);
10247 n
->larg
= (SelectStmt
*) larg
;
10248 n
->rarg
= (SelectStmt
*) rarg
;
10252 /* SystemFuncName()
10253 * Build a properly-qualified reference to a built-in function.
10256 SystemFuncName
(char *name
)
10258 return list_make2
(makeString
("pg_catalog"), makeString
(name
));
10261 /* SystemTypeName()
10262 * Build a properly-qualified reference to a built-in type.
10264 * typmod is defaulted, but may be changed afterwards by caller.
10265 * Likewise for the location.
10268 SystemTypeName
(char *name
)
10270 return makeTypeNameFromNameList
(list_make2
(makeString
("pg_catalog"),
10271 makeString
(name
)));
10275 * Handle negation of a numeric constant.
10277 * Formerly, we did this here because the optimizer couldn't cope with
10278 * indexquals that looked like "var = -4" --- it wants "var = const"
10279 * and a unary minus operator applied to a constant didn't qualify.
10280 * As of Postgres 7.0, that problem doesn't exist anymore because there
10281 * is a constant-subexpression simplifier in the optimizer. However,
10282 * there's still a good reason for doing this here, which is that we can
10283 * postpone committing to a particular internal representation for simple
10284 * negative constants. It's better to leave "-123.456" in string form
10285 * until we know what the desired type is.
10288 doNegate
(Node
*n
, int location
)
10290 if
(IsA
(n
, A_Const
))
10292 A_Const
*con
= (A_Const
*)n
;
10294 /* report the constant's location as that of the '-' sign */
10295 con
->location
= location
;
10297 if
(con
->val.type
== T_Integer
)
10299 con
->val.val.ival
= -con
->val.val.ival
;
10302 if
(con
->val.type
== T_Float
)
10304 doNegateFloat
(&con
->val
);
10309 return
(Node
*) makeSimpleA_Expr
(AEXPR_OP
, "-", NULL
, n
, location
);
10313 doNegateFloat
(Value
*v
)
10315 char *oldval
= v
->val.str
;
10317 Assert
(IsA
(v
, Float
));
10318 if
(*oldval
== '+')
10320 if
(*oldval
== '-')
10321 v
->val.str
= oldval
+1; /* just strip the '-' */
10324 char *newval
= (char *) palloc
(strlen
(oldval
) + 2);
10327 strcpy
(newval
+1, oldval
);
10328 v
->val.str
= newval
;
10333 makeAArrayExpr
(List
*elements
, int location
)
10335 A_ArrayExpr
*n
= makeNode
(A_ArrayExpr
);
10337 n
->elements
= elements
;
10338 n
->location
= location
;
10343 makeXmlExpr
(XmlExprOp op
, char *name
, List
*named_args
, List
*args
,
10346 XmlExpr
*x
= makeNode
(XmlExpr
);
10351 * named_args is a list of ResTarget; it'll be split apart into separate
10352 * expression and name lists in transformXmlExpr().
10354 x
->named_args
= named_args
;
10355 x
->arg_names
= NIL
;
10357 /* xmloption, if relevant, must be filled in by caller */
10358 /* type and typmod will be filled in during parse analysis */
10359 x
->location
= location
;
10364 * Initialize to parse one query string
10369 QueryIsRule
= FALSE
;
10373 * Merge the input and output parameters of a table function.
10376 mergeTableFuncParameters
(List
*func_args
, List
*columns
)
10380 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
10381 foreach
(lc
, func_args
)
10383 FunctionParameter
*p
= (FunctionParameter
*) lfirst
(lc
);
10385 if
(p
->mode
!= FUNC_PARAM_IN
&& p
->mode
!= FUNC_PARAM_VARIADIC
)
10387 (errcode
(ERRCODE_SYNTAX_ERROR
),
10388 errmsg
("OUT and INOUT arguments aren't allowed in TABLE functions")));
10391 return list_concat
(func_args
, columns
);
10395 * Determine return type of a TABLE function. A single result column
10396 * returns setof that column's type; otherwise return setof record.
10399 TableFuncTypeName
(List
*columns
)
10403 if
(list_length
(columns
) == 1)
10405 FunctionParameter
*p
= (FunctionParameter
*) linitial
(columns
);
10407 result
= (TypeName
*) copyObject
(p
->argType
);
10410 result
= SystemTypeName
("record");
10412 result
->setof
= true
;
10418 * Must undefine base_yylex before including scan.c, since we want it
10419 * to create the function base_yylex not filtered_base_yylex.