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
);
135 %name
-prefix
="base_yy"
146 DropBehavior dbehavior
;
147 OnCommitAction oncommit
;
154 FunctionParameter
*fun_param
;
155 FunctionParameterMode fun_param_mode
;
156 FuncWithArgs
*funwithargs
;
167 PrivTarget
*privtarget
;
170 VariableSetStmt
*vsetstmt
;
173 %type
<node
> stmt schema_stmt
174 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterGroupStmt
175 AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterTableStmt
176 AlterUserStmt AlterUserSetStmt AlterRoleStmt AlterRoleSetStmt
177 AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
178 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
179 CreateDomainStmt CreateGroupStmt CreateOpClassStmt
180 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
181 CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
182 CreateAssertStmt CreateTrigStmt CreateUserStmt CreateRoleStmt
183 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt
184 DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
185 DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
186 DropUserStmt DropdbStmt DropTableSpaceStmt ExplainStmt FetchStmt
187 GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
188 LockStmt NotifyStmt ExplainableStmt PreparableStmt
189 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
190 RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
191 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
192 SelectStmt TransactionStmt TruncateStmt
193 UnlistenStmt UpdateStmt VacuumStmt
194 VariableResetStmt VariableSetStmt VariableShowStmt
195 ViewStmt CheckPointStmt CreateConversionStmt
196 DeallocateStmt PrepareStmt ExecuteStmt
197 DropOwnedStmt ReassignOwnedStmt
198 AlterTSConfigurationStmt AlterTSDictionaryStmt
200 %type
<node
> select_no_parens select_with_parens select_clause
201 simple_select values_clause
203 %type
<node
> alter_column_default opclass_item opclass_drop alter_using
204 %type
<ival
> add_drop opt_asc_desc opt_nulls_order
206 %type
<node
> alter_table_cmd
207 %type
<list
> alter_table_cmds
209 %type
<dbehavior
> opt_drop_behavior
211 %type
<list
> createdb_opt_list alterdb_opt_list copy_opt_list
212 transaction_mode_list
213 %type
<defelt
> createdb_opt_item alterdb_opt_item copy_opt_item
214 transaction_mode_item
216 %type
<ival
> opt_lock lock_type cast_context
217 %type
<boolean
> opt_force opt_or_replace
218 opt_grant_grant_option opt_grant_admin_option
219 opt_nowait opt_if_exists opt_with_data
221 %type
<list
> OptRoleList
222 %type
<defelt
> OptRoleElem
224 %type
<str
> OptSchemaName
225 %type
<list
> OptSchemaEltList
227 %type
<boolean
> TriggerActionTime TriggerForSpec opt_trusted opt_restart_seqs
228 %type
<str
> opt_lancompiler
230 %type
<str
> TriggerEvents
231 %type
<value
> TriggerFuncArg
233 %type
<str
> relation_name copy_file_name
234 database_name access_method_clause access_method attr_name
235 index_name name file_name cluster_index_specification
237 %type
<list
> func_name handler_name qual_Op qual_all_Op subquery_Op
238 opt_class opt_validator
240 %type
<range
> qualified_name OptConstrFromTable
242 %type
<str
> all_Op MathOp SpecialRuleRelation
244 %type
<str
> iso_level opt_encoding
246 %type
<list
> grantee_list
247 %type
<str
> privilege
248 %type
<list
> privileges privilege_list
249 %type
<privtarget
> privilege_target
250 %type
<funwithargs
> function_with_argtypes
251 %type
<list
> function_with_argtypes_list
252 %type
<chr
> TriggerOneEvent
254 %type
<list
> stmtblock stmtmulti
255 OptTableElementList TableElementList OptInherit definition
256 OptWith opt_distinct opt_definition func_args func_args_list
257 func_as createfunc_opt_list alterfunc_opt_list
258 aggr_args old_aggr_definition old_aggr_list
259 oper_argtypes RuleActionList RuleActionMulti
260 opt_column_list columnList opt_name_list
261 sort_clause opt_sort_clause sortby_list index_params
262 name_list from_clause from_list opt_array_bounds
263 qualified_name_list any_name any_name_list
264 any_operator expr_list attrs
265 target_list insert_column_list set_target_list
266 set_clause_list set_clause multiple_set_clause
267 ctext_expr_list ctext_row def_list indirection opt_indirection
268 group_clause TriggerFuncArgs select_limit
269 opt_select_limit opclass_item_list opclass_drop_list
270 opt_opfamily transaction_mode_list_or_empty
271 TableFuncElementList opt_type_modifiers
273 execute_param_clause using_clause returning_clause
274 enum_val_list table_func_column_list
276 %type
<range
> OptTempTableName
277 %type
<into
> into_clause create_as_target
279 %type
<defelt
> createfunc_opt_item common_func_opt_item
280 %type
<fun_param
> func_arg table_func_column
281 %type
<fun_param_mode
> arg_class
282 %type
<typnam
> func_return func_type
284 %type
<boolean
> TriggerForType OptTemp
285 %type
<oncommit
> OnCommitOption
287 %type
<node
> for_locking_item
288 %type
<list
> for_locking_clause opt_for_locking_clause for_locking_items
289 %type
<list
> locked_rels_list
290 %type
<boolean
> opt_all
292 %type
<node
> join_outer join_qual
293 %type
<jtype
> join_type
295 %type
<list
> extract_list overlay_list position_list
296 %type
<list
> substr_list trim_list
297 %type
<list
> opt_interval interval_second
298 %type
<node
> overlay_placing substr_from substr_for
300 %type
<boolean
> opt_instead opt_analyze
301 %type
<boolean
> index_opt_unique opt_verbose opt_full
302 %type
<boolean
> opt_freeze opt_default opt_recheck
303 %type
<defelt
> opt_binary opt_oids copy_delimiter
305 %type
<boolean
> copy_from
307 %type
<ival
> opt_column event cursor_options opt_hold opt_set_data
308 %type
<objtype
> reindex_type drop_type comment_type
310 %type
<node
> fetch_direction select_limit_value select_offset_value
311 select_offset_value2 opt_select_fetch_first_value
312 %type
<ival
> row_or_rows first_or_next
314 %type
<list
> OptSeqOptList SeqOptList
315 %type
<defelt
> SeqOptElem
317 %type
<istmt
> insert_rest
319 %type
<vsetstmt
> set_rest SetResetClause
321 %type
<node
> TableElement ConstraintElem TableFuncElement
322 %type
<node
> columnDef
323 %type
<defelt
> def_elem old_aggr_elem
324 %type
<node
> def_arg columnElem where_clause where_or_current_clause
325 a_expr b_expr c_expr func_expr AexprConst indirection_el
326 columnref in_expr having_clause func_table array_expr
327 %type
<list
> row type_list array_expr_list
328 %type
<node
> case_expr case_arg when_clause case_default
329 %type
<list
> when_clause_list
330 %type
<ival
> sub_type
331 %type
<list
> OptCreateAs CreateAsList
332 %type
<node
> CreateAsElement ctext_expr
333 %type
<value
> NumericOnly FloatOnly IntegerOnly
334 %type
<alias
> alias_clause
335 %type
<sortby
> sortby
336 %type
<ielem
> index_elem
337 %type
<node
> table_ref
338 %type
<jexpr
> joined_table
339 %type
<range
> relation_expr
340 %type
<range
> relation_expr_opt_alias
341 %type
<target
> target_el single_set_clause set_target insert_column_item
343 %type
<typnam
> Typename SimpleTypename ConstTypename
344 GenericType Numeric opt_float
345 Character ConstCharacter
346 CharacterWithLength CharacterWithoutLength
347 ConstDatetime ConstInterval
348 Bit ConstBit BitWithLength BitWithoutLength
349 %type
<str
> character
350 %type
<str
> extract_arg
351 %type
<str
> opt_charset
352 %type
<boolean
> opt_varying opt_timezone
354 %type
<ival
> Iconst SignedIconst
355 %type
<str
> Sconst comment_text
356 %type
<str
> RoleId opt_granted_by opt_boolean ColId_or_Sconst
357 %type
<list
> var_list
358 %type
<str
> ColId ColLabel var_name type_function_name param_name
359 %type
<node
> var_value zone_value
361 %type
<keyword
> unreserved_keyword type_func_name_keyword
362 %type
<keyword
> col_name_keyword reserved_keyword
364 %type
<node
> TableConstraint TableLikeClause
365 %type
<list
> TableLikeOptionList
366 %type
<ival
> TableLikeOption
367 %type
<list
> ColQualList
368 %type
<node
> ColConstraint ColConstraintElem ConstraintAttr
369 %type
<ival
> key_actions key_delete key_match key_update key_action
370 %type
<ival
> ConstraintAttributeSpec ConstraintDeferrabilitySpec
373 %type
<list
> constraints_set_list
374 %type
<boolean
> constraints_set_mode
375 %type
<str
> OptTableSpace OptConsTableSpace OptTableSpaceOwner
376 %type
<list
> opt_check_option
378 %type
<target
> xml_attribute_el
379 %type
<list
> xml_attribute_list xml_attributes
380 %type
<node
> xml_root_version opt_xml_root_standalone
381 %type
<ival
> document_or_content
382 %type
<boolean
> xml_whitespace_option
384 %type
<node
> common_table_expr
385 %type
<with
> with_clause
386 %type
<list
> cte_list
390 * If you make any token changes, update the keyword table in
391 * parser/keywords.c and add new keywords to the appropriate one of
392 * the reserved-or-not-so-reserved keyword lists, below; search
393 * this file for "Name classification hierarchy".
396 /* ordinary key words in alphabetical order */
397 %token
<keyword
> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
398 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
399 ASSERTION ASSIGNMENT ASYMMETRIC AT AUTHORIZATION
401 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
404 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
405 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
406 CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT
407 COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
408 CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
409 CREATEROLE CREATEUSER CROSS CSV CTYPE CURRENT_P
410 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
411 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
413 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
414 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
415 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
417 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT EXCLUDING
418 EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
420 FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOR FORCE FOREIGN FORWARD
421 FREEZE FROM FULL FUNCTION
423 GLOBAL GRANT GRANTED GREATEST GROUP_P
425 HANDLER HAVING HEADER_P HOLD HOUR_P
427 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
428 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY
429 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
430 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
436 LANCOMPILER LANGUAGE LARGE_P LAST_P LEADING LEAST LEFT LEVEL
437 LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP LOCATION
440 MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
442 NAME_P NAMES NATIONAL NATURAL NCHAR NEW NEXT NO NOCREATEDB
443 NOCREATEROLE NOCREATEUSER NOINHERIT NOLOGIN_P NONE NOSUPERUSER
444 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NULLS_P NUMERIC
446 OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OR
447 ORDER OUT_P OUTER_P OVERLAPS OVERLAY OWNED OWNER
449 PARSER PARTIAL PASSWORD PLACING PLANS POSITION
450 PRECISION PRESERVE PREPARE PREPARED PRIMARY
451 PRIOR PRIVILEGES PROCEDURAL PROCEDURE
455 READ REAL REASSIGN RECHECK RECURSIVE REFERENCES REINDEX RELATIVE_P RELEASE
456 RENAME REPEATABLE REPLACE REPLICA RESET RESTART RESTRICT RETURNING RETURNS
457 REVOKE RIGHT ROLE ROLLBACK ROW ROWS RULE
459 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE
460 SERIALIZABLE SESSION SESSION_USER SET SETOF SHARE
461 SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT
462 STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING SUPERUSER_P
463 SYMMETRIC SYSID SYSTEM_P
465 TABLE TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
466 TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
467 TRUNCATE TRUSTED TYPE_P
469 UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
472 VACUUM VALID VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
473 VERBOSE VERSION_P VIEW VOLATILE
475 WHEN WHERE WHITESPACE_P WITH WITHOUT WORK WRITE
477 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLFOREST XMLPARSE
478 XMLPI XMLROOT XMLSERIALIZE
484 /* The grammar thinks these are keywords, but they are not in the keywords.c
485 * list and so can never be entered directly. The filter in parser.c
486 * creates these tokens when required.
488 %token NULLS_FIRST NULLS_LAST WITH_TIME
490 /* Special token types, not actually keywords - see the "lex" file */
491 %token
<str
> IDENT FCONST SCONST BCONST XCONST Op
492 %token
<ival
> ICONST PARAM
494 /* precedence: lowest to highest */
495 %nonassoc SET
/* see relation_expr_opt_alias */
503 %nonassoc LIKE ILIKE SIMILAR
508 %left POSTFIXOP
/* dummy for postfix Op rules */
509 %nonassoc IDENT
/* to support target_el without AS */
510 %left Op OPERATOR
/* multi-character ops and user-defined operators */
513 %nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN
/* sets precedence for IS NULL, etc */
517 /* Unary Operators */
518 %left AT ZONE
/* sets precedence for AT TIME ZONE */
525 * These might seem to be low-precedence, but actually they are not part
526 * of the arithmetic hierarchy at all in their use as JOIN operators.
527 * We make them high-precedence to support their use as function names.
528 * They wouldn't be given a precedence at all, were it not that we need
529 * left-associativity among the JOIN rules themselves.
531 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
532 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
533 %right PRESERVE STRIP_P
537 * Handle comment-only lines, and ;; SELECT * FROM pg_class ;;;
538 * psql already handles such cases, but other interfaces don't.
541 stmtblock: stmtmulti
{ parsetree
= $1; }
544 /* the thrashing around here is to discard "empty" statements... */
545 stmtmulti: stmtmulti
';' stmt
547 $$
= lappend
($1, $3);
561 | AlterDatabaseSetStmt
565 | AlterObjectSchemaStmt
571 | AlterTSConfigurationStmt
572 | AlterTSDictionaryStmt
585 | CreateConversionStmt
596 | CreateTableSpaceStmt
655 /*****************************************************************************
657 * Create a new Postgres DBMS role
659 *****************************************************************************/
662 CREATE ROLE RoleId opt_with OptRoleList
664 CreateRoleStmt
*n
= makeNode
(CreateRoleStmt
);
665 n
->stmt_type
= ROLESTMT_ROLE
;
678 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
679 * for backwards compatibility). Note: the only option required by SQL99
680 * is "WITH ADMIN name".
683 OptRoleList OptRoleElem
{ $$
= lappend
($1, $2); }
684 |
/* EMPTY */ { $$
= NIL
; }
690 $$
= makeDefElem
("password",
691 (Node
*)makeString
($2));
695 $$
= makeDefElem
("password", NULL
);
697 | ENCRYPTED PASSWORD Sconst
699 $$
= makeDefElem
("encryptedPassword",
700 (Node
*)makeString
($3));
702 | UNENCRYPTED PASSWORD Sconst
704 $$
= makeDefElem
("unencryptedPassword",
705 (Node
*)makeString
($3));
709 $$
= makeDefElem
("superuser", (Node
*)makeInteger
(TRUE
));
713 $$
= makeDefElem
("superuser", (Node
*)makeInteger
(FALSE
));
717 $$
= makeDefElem
("inherit", (Node
*)makeInteger
(TRUE
));
721 $$
= makeDefElem
("inherit", (Node
*)makeInteger
(FALSE
));
725 $$
= makeDefElem
("createdb", (Node
*)makeInteger
(TRUE
));
729 $$
= makeDefElem
("createdb", (Node
*)makeInteger
(FALSE
));
733 $$
= makeDefElem
("createrole", (Node
*)makeInteger
(TRUE
));
737 $$
= makeDefElem
("createrole", (Node
*)makeInteger
(FALSE
));
741 /* For backwards compatibility, synonym for SUPERUSER */
742 $$
= makeDefElem
("superuser", (Node
*)makeInteger
(TRUE
));
746 $$
= makeDefElem
("superuser", (Node
*)makeInteger
(FALSE
));
750 $$
= makeDefElem
("canlogin", (Node
*)makeInteger
(TRUE
));
754 $$
= makeDefElem
("canlogin", (Node
*)makeInteger
(FALSE
));
756 | CONNECTION LIMIT SignedIconst
758 $$
= makeDefElem
("connectionlimit", (Node
*)makeInteger
($3));
762 $$
= makeDefElem
("validUntil", (Node
*)makeString
($3));
764 /* Supported but not documented for roles, for use by ALTER GROUP. */
767 $$
= makeDefElem
("rolemembers", (Node
*)$2);
769 /* The following are not supported by ALTER ROLE/USER/GROUP */
772 $$
= makeDefElem
("sysid", (Node
*)makeInteger
($2));
776 $$
= makeDefElem
("adminmembers", (Node
*)$2);
780 $$
= makeDefElem
("rolemembers", (Node
*)$2);
782 | IN_P ROLE name_list
784 $$
= makeDefElem
("addroleto", (Node
*)$3);
786 | IN_P GROUP_P name_list
788 $$
= makeDefElem
("addroleto", (Node
*)$3);
793 /*****************************************************************************
795 * Create a new Postgres DBMS user (role with implied login ability)
797 *****************************************************************************/
800 CREATE USER RoleId opt_with OptRoleList
802 CreateRoleStmt
*n
= makeNode
(CreateRoleStmt
);
803 n
->stmt_type
= ROLESTMT_USER
;
811 /*****************************************************************************
813 * Alter a postgresql DBMS role
815 *****************************************************************************/
818 ALTER ROLE RoleId opt_with OptRoleList
820 AlterRoleStmt
*n
= makeNode
(AlterRoleStmt
);
822 n
->action
= +1; /* add, if there are members */
829 ALTER ROLE RoleId SetResetClause
831 AlterRoleSetStmt
*n
= makeNode
(AlterRoleSetStmt
);
839 /*****************************************************************************
841 * Alter a postgresql DBMS user
843 *****************************************************************************/
846 ALTER USER RoleId opt_with OptRoleList
848 AlterRoleStmt
*n
= makeNode
(AlterRoleStmt
);
850 n
->action
= +1; /* add, if there are members */
858 ALTER USER RoleId SetResetClause
860 AlterRoleSetStmt
*n
= makeNode
(AlterRoleSetStmt
);
868 /*****************************************************************************
870 * Drop a postgresql DBMS role
872 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
873 * might own objects in multiple databases, there is presently no way to
874 * implement either cascading or restricting. Caveat DBA.
875 *****************************************************************************/
880 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
881 n
->missing_ok
= FALSE
;
885 | DROP ROLE IF_P EXISTS name_list
887 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
888 n
->missing_ok
= TRUE
;
894 /*****************************************************************************
896 * Drop a postgresql DBMS user
898 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
899 * might own objects in multiple databases, there is presently no way to
900 * implement either cascading or restricting. Caveat DBA.
901 *****************************************************************************/
906 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
907 n
->missing_ok
= FALSE
;
911 | DROP USER IF_P EXISTS name_list
913 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
915 n
->missing_ok
= TRUE
;
921 /*****************************************************************************
923 * Create a postgresql group (role without login ability)
925 *****************************************************************************/
928 CREATE GROUP_P RoleId opt_with OptRoleList
930 CreateRoleStmt
*n
= makeNode
(CreateRoleStmt
);
931 n
->stmt_type
= ROLESTMT_GROUP
;
939 /*****************************************************************************
941 * Alter a postgresql group
943 *****************************************************************************/
946 ALTER GROUP_P RoleId add_drop USER name_list
948 AlterRoleStmt
*n
= makeNode
(AlterRoleStmt
);
951 n
->options
= list_make1
(makeDefElem
("rolemembers",
957 add_drop: ADD_P
{ $$
= +1; }
962 /*****************************************************************************
964 * Drop a postgresql group
966 * XXX see above notes about cascading DROP USER; groups have same problem.
967 *****************************************************************************/
970 DROP GROUP_P name_list
972 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
973 n
->missing_ok
= FALSE
;
977 | DROP GROUP_P IF_P EXISTS name_list
979 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
980 n
->missing_ok
= TRUE
;
987 /*****************************************************************************
989 * Manipulate a schema
991 *****************************************************************************/
994 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
996 CreateSchemaStmt
*n
= makeNode
(CreateSchemaStmt
);
997 /* One can omit the schema name or the authorization id. */
1006 | CREATE SCHEMA ColId OptSchemaEltList
1008 CreateSchemaStmt
*n
= makeNode
(CreateSchemaStmt
);
1009 /* ...but not both */
1019 |
/* EMPTY */ { $$
= NULL
; }
1023 OptSchemaEltList schema_stmt
{ $$
= lappend
($1, $2); }
1024 |
/* EMPTY */ { $$
= NIL
; }
1028 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1029 * statement (in addition to by themselves).
1041 /*****************************************************************************
1043 * Set PG internal variable
1044 * SET name TO 'var_value'
1045 * Include SQL92 syntax (thomas 1997-10-22):
1046 * SET TIME ZONE 'var_value'
1048 *****************************************************************************/
1053 VariableSetStmt
*n
= $2;
1054 n
->is_local
= false
;
1057 | SET LOCAL set_rest
1059 VariableSetStmt
*n
= $3;
1063 | SET SESSION set_rest
1065 VariableSetStmt
*n
= $3;
1066 n
->is_local
= false
;
1071 set_rest: /* Generic SET syntaxes: */
1072 var_name TO var_list
1074 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1075 n
->kind
= VAR_SET_VALUE
;
1080 | var_name
'=' var_list
1082 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1083 n
->kind
= VAR_SET_VALUE
;
1088 | var_name TO DEFAULT
1090 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1091 n
->kind
= VAR_SET_DEFAULT
;
1095 | var_name
'=' DEFAULT
1097 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1098 n
->kind
= VAR_SET_DEFAULT
;
1102 | var_name FROM CURRENT_P
1104 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1105 n
->kind
= VAR_SET_CURRENT
;
1109 /* Special syntaxes mandated by SQL standard: */
1110 | TIME ZONE zone_value
1112 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1113 n
->kind
= VAR_SET_VALUE
;
1114 n
->name
= "timezone";
1116 n
->args
= list_make1
($3);
1118 n
->kind
= VAR_SET_DEFAULT
;
1121 | TRANSACTION transaction_mode_list
1123 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1124 n
->kind
= VAR_SET_MULTI
;
1125 n
->name
= "TRANSACTION";
1129 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1131 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1132 n
->kind
= VAR_SET_MULTI
;
1133 n
->name
= "SESSION CHARACTERISTICS";
1140 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
1141 errmsg
("current database cannot be changed"),
1142 scanner_errposition
(@
2)));
1143 $$
= NULL
; /*not reached*/
1147 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1148 n
->kind
= VAR_SET_VALUE
;
1149 n
->name
= "search_path";
1150 n
->args
= list_make1
(makeStringConst
($2, @
2));
1153 | NAMES opt_encoding
1155 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1156 n
->kind
= VAR_SET_VALUE
;
1157 n
->name
= "client_encoding";
1159 n
->args
= list_make1
(makeStringConst
($2, @
2));
1161 n
->kind
= VAR_SET_DEFAULT
;
1164 | ROLE ColId_or_Sconst
1166 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1167 n
->kind
= VAR_SET_VALUE
;
1169 n
->args
= list_make1
(makeStringConst
($2, @
2));
1172 | SESSION AUTHORIZATION ColId_or_Sconst
1174 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1175 n
->kind
= VAR_SET_VALUE
;
1176 n
->name
= "session_authorization";
1177 n
->args
= list_make1
(makeStringConst
($3, @
3));
1180 | SESSION AUTHORIZATION DEFAULT
1182 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1183 n
->kind
= VAR_SET_DEFAULT
;
1184 n
->name
= "session_authorization";
1187 | XML_P OPTION document_or_content
1189 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1190 n
->kind
= VAR_SET_VALUE
;
1191 n
->name
= "xmloption";
1192 n
->args
= list_make1
(makeStringConst
($3 == XMLOPTION_DOCUMENT ?
"DOCUMENT" : "CONTENT", @
3));
1197 var_name: ColId
{ $$
= $1; }
1198 | var_name
'.' ColId
1200 $$
= palloc
(strlen
($1) + strlen
($3) + 2);
1201 sprintf
($$
, "%s.%s", $1, $3);
1205 var_list: var_value
{ $$
= list_make1
($1); }
1206 | var_list
',' var_value
{ $$
= lappend
($1, $3); }
1209 var_value: opt_boolean
1210 { $$
= makeStringConst
($1, @
1); }
1212 { $$
= makeStringConst
($1, @
1); }
1214 { $$
= makeAConst
($1, @
1); }
1217 iso_level: READ UNCOMMITTED
{ $$
= "read uncommitted"; }
1218 | READ COMMITTED
{ $$
= "read committed"; }
1219 | REPEATABLE READ
{ $$
= "repeatable read"; }
1220 | SERIALIZABLE
{ $$
= "serializable"; }
1224 TRUE_P
{ $$
= "true"; }
1225 | FALSE_P
{ $$
= "false"; }
1227 | OFF
{ $$
= "off"; }
1230 /* Timezone values can be:
1231 * - a string such as 'pst8pdt'
1232 * - an identifier such as "pst8pdt"
1233 * - an integer or floating point number
1234 * - a time interval per SQL99
1235 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1236 * so use IDENT and reject anything which is a reserved word.
1241 $$
= makeStringConst
($1, @
1);
1245 $$
= makeStringConst
($1, @
1);
1247 | ConstInterval Sconst opt_interval
1252 A_Const
*n
= (A_Const
*) linitial
($3);
1253 if
((n
->val.val.ival
& ~
(INTERVAL_MASK
(HOUR
) | INTERVAL_MASK
(MINUTE
))) != 0)
1255 (errcode
(ERRCODE_SYNTAX_ERROR
),
1256 errmsg
("time zone interval must be HOUR or HOUR TO MINUTE"),
1257 scanner_errposition
(@
3)));
1260 $$
= makeStringConstCast
($2, @
2, t
);
1262 | ConstInterval
'(' Iconst
')' Sconst opt_interval
1267 A_Const
*n
= (A_Const
*) linitial
($6);
1268 if
((n
->val.val.ival
& ~
(INTERVAL_MASK
(HOUR
) | INTERVAL_MASK
(MINUTE
))) != 0)
1270 (errcode
(ERRCODE_SYNTAX_ERROR
),
1271 errmsg
("time zone interval must be HOUR or HOUR TO MINUTE"),
1272 scanner_errposition
(@
6)));
1273 if
(list_length
($6) != 1)
1275 (errcode
(ERRCODE_SYNTAX_ERROR
),
1276 errmsg
("interval precision specified twice"),
1277 scanner_errposition
(@
1)));
1278 t
->typmods
= lappend
($6, makeIntConst
($3, @
3));
1281 t
->typmods
= list_make2
(makeIntConst
(INTERVAL_FULL_RANGE
, -1),
1282 makeIntConst
($3, @
3));
1283 $$
= makeStringConstCast
($5, @
5, t
);
1285 | NumericOnly
{ $$
= makeAConst
($1, @
1); }
1286 | DEFAULT
{ $$
= NULL
; }
1287 | LOCAL
{ $$
= NULL
; }
1292 | DEFAULT
{ $$
= NULL
; }
1293 |
/*EMPTY*/ { $$
= NULL
; }
1298 | SCONST
{ $$
= $1; }
1304 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1305 n
->kind
= VAR_RESET
;
1311 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1312 n
->kind
= VAR_RESET
;
1313 n
->name
= "timezone";
1316 | RESET TRANSACTION ISOLATION LEVEL
1318 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1319 n
->kind
= VAR_RESET
;
1320 n
->name
= "transaction_isolation";
1323 | RESET SESSION AUTHORIZATION
1325 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1326 n
->kind
= VAR_RESET
;
1327 n
->name
= "session_authorization";
1332 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1333 n
->kind
= VAR_RESET_ALL
;
1338 /* SetResetClause allows SET or RESET without LOCAL */
1340 SET set_rest
{ $$
= $2; }
1341 | VariableResetStmt
{ $$
= (VariableSetStmt
*) $1; }
1348 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1354 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1355 n
->name
= "timezone";
1358 | SHOW TRANSACTION ISOLATION LEVEL
1360 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1361 n
->name
= "transaction_isolation";
1364 | SHOW SESSION AUTHORIZATION
1366 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1367 n
->name
= "session_authorization";
1372 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1380 SET CONSTRAINTS constraints_set_list constraints_set_mode
1382 ConstraintsSetStmt
*n
= makeNode
(ConstraintsSetStmt
);
1383 n
->constraints
= $3;
1389 constraints_set_list:
1391 | qualified_name_list
{ $$
= $1; }
1394 constraints_set_mode:
1395 DEFERRED
{ $$
= TRUE
; }
1396 | IMMEDIATE
{ $$
= FALSE
; }
1401 * Checkpoint statement
1406 CheckPointStmt
*n
= makeNode
(CheckPointStmt
);
1412 /*****************************************************************************
1414 * DISCARD { ALL | TEMP | PLANS }
1416 *****************************************************************************/
1421 DiscardStmt
*n
= makeNode
(DiscardStmt
);
1422 n
->target
= DISCARD_ALL
;
1427 DiscardStmt
*n
= makeNode
(DiscardStmt
);
1428 n
->target
= DISCARD_TEMP
;
1433 DiscardStmt
*n
= makeNode
(DiscardStmt
);
1434 n
->target
= DISCARD_TEMP
;
1439 DiscardStmt
*n
= makeNode
(DiscardStmt
);
1440 n
->target
= DISCARD_PLANS
;
1446 /*****************************************************************************
1448 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations
1450 * Note: we accept all subcommands for each of the four variants, and sort
1451 * out what's really legal at execution time.
1452 *****************************************************************************/
1455 ALTER TABLE relation_expr alter_table_cmds
1457 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
1460 n
->relkind
= OBJECT_TABLE
;
1463 | ALTER INDEX relation_expr alter_table_cmds
1465 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
1468 n
->relkind
= OBJECT_INDEX
;
1471 | ALTER SEQUENCE relation_expr alter_table_cmds
1473 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
1476 n
->relkind
= OBJECT_SEQUENCE
;
1479 | ALTER VIEW relation_expr alter_table_cmds
1481 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
1484 n
->relkind
= OBJECT_VIEW
;
1490 alter_table_cmd
{ $$
= list_make1
($1); }
1491 | alter_table_cmds
',' alter_table_cmd
{ $$
= lappend
($1, $3); }
1495 /* ALTER TABLE <name> ADD [COLUMN] <coldef> */
1496 ADD_P opt_column columnDef
1498 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1499 n
->subtype
= AT_AddColumn
;
1503 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1504 | ALTER opt_column ColId alter_column_default
1506 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1507 n
->subtype
= AT_ColumnDefault
;
1512 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1513 | ALTER opt_column ColId DROP NOT NULL_P
1515 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1516 n
->subtype
= AT_DropNotNull
;
1520 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1521 | ALTER opt_column ColId SET NOT NULL_P
1523 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1524 n
->subtype
= AT_SetNotNull
;
1528 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <IntegerOnly> */
1529 | ALTER opt_column ColId SET STATISTICS IntegerOnly
1531 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1532 n
->subtype
= AT_SetStatistics
;
1534 n
->def
= (Node
*) $6;
1537 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1538 | ALTER opt_column ColId SET STORAGE ColId
1540 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1541 n
->subtype
= AT_SetStorage
;
1543 n
->def
= (Node
*) makeString
($6);
1546 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1547 | DROP opt_column ColId opt_drop_behavior
1549 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1550 n
->subtype
= AT_DropColumn
;
1556 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
1557 * [ USING <expression> ]
1559 | ALTER opt_column ColId opt_set_data TYPE_P Typename alter_using
1561 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1562 n
->subtype
= AT_AlterColumnType
;
1564 n
->def
= (Node
*) $6;
1568 /* ALTER TABLE <name> ADD CONSTRAINT ... */
1569 | ADD_P TableConstraint
1571 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1572 n
->subtype
= AT_AddConstraint
;
1576 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1577 | DROP CONSTRAINT name opt_drop_behavior
1579 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1580 n
->subtype
= AT_DropConstraint
;
1585 /* ALTER TABLE <name> SET WITHOUT OIDS */
1588 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1589 n
->subtype
= AT_DropOids
;
1592 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1595 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1596 n
->subtype
= AT_ClusterOn
;
1600 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1601 | SET WITHOUT CLUSTER
1603 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1604 n
->subtype
= AT_DropCluster
;
1608 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
1609 | ENABLE_P TRIGGER name
1611 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1612 n
->subtype
= AT_EnableTrig
;
1616 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
1617 | ENABLE_P ALWAYS TRIGGER name
1619 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1620 n
->subtype
= AT_EnableAlwaysTrig
;
1624 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
1625 | ENABLE_P REPLICA TRIGGER name
1627 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1628 n
->subtype
= AT_EnableReplicaTrig
;
1632 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
1633 | ENABLE_P TRIGGER ALL
1635 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1636 n
->subtype
= AT_EnableTrigAll
;
1639 /* ALTER TABLE <name> ENABLE TRIGGER USER */
1640 | ENABLE_P TRIGGER USER
1642 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1643 n
->subtype
= AT_EnableTrigUser
;
1646 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
1647 | DISABLE_P TRIGGER name
1649 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1650 n
->subtype
= AT_DisableTrig
;
1654 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
1655 | DISABLE_P TRIGGER ALL
1657 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1658 n
->subtype
= AT_DisableTrigAll
;
1661 /* ALTER TABLE <name> DISABLE TRIGGER USER */
1662 | DISABLE_P TRIGGER USER
1664 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1665 n
->subtype
= AT_DisableTrigUser
;
1668 /* ALTER TABLE <name> ENABLE RULE <rule> */
1669 | ENABLE_P RULE name
1671 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1672 n
->subtype
= AT_EnableRule
;
1676 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
1677 | ENABLE_P ALWAYS RULE name
1679 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1680 n
->subtype
= AT_EnableAlwaysRule
;
1684 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
1685 | ENABLE_P REPLICA RULE name
1687 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1688 n
->subtype
= AT_EnableReplicaRule
;
1692 /* ALTER TABLE <name> DISABLE RULE <rule> */
1693 | DISABLE_P RULE name
1695 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1696 n
->subtype
= AT_DisableRule
;
1700 /* ALTER TABLE <name> INHERIT <parent> */
1701 | INHERIT qualified_name
1703 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1704 n
->subtype
= AT_AddInherit
;
1705 n
->def
= (Node
*) $2;
1708 /* ALTER TABLE <name> NO INHERIT <parent> */
1709 | NO INHERIT qualified_name
1711 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1712 n
->subtype
= AT_DropInherit
;
1713 n
->def
= (Node
*) $3;
1716 /* ALTER TABLE <name> OWNER TO RoleId */
1719 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1720 n
->subtype
= AT_ChangeOwner
;
1724 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1725 | SET TABLESPACE name
1727 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1728 n
->subtype
= AT_SetTableSpace
;
1732 /* ALTER TABLE <name> SET (...) */
1735 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1736 n
->subtype
= AT_SetRelOptions
;
1737 n
->def
= (Node
*)$2;
1740 /* ALTER TABLE <name> RESET (...) */
1743 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1744 n
->subtype
= AT_ResetRelOptions
;
1745 n
->def
= (Node
*)$2;
1750 alter_column_default:
1751 SET DEFAULT a_expr
{ $$
= $3; }
1752 | DROP DEFAULT
{ $$
= NULL
; }
1756 CASCADE
{ $$
= DROP_CASCADE
; }
1757 | RESTRICT
{ $$
= DROP_RESTRICT
; }
1758 |
/* EMPTY */ { $$
= DROP_RESTRICT
; /* default */ }
1762 USING a_expr
{ $$
= $2; }
1763 |
/* EMPTY */ { $$
= NULL
; }
1768 /*****************************************************************************
1771 * close <portalname>
1773 *****************************************************************************/
1778 ClosePortalStmt
*n
= makeNode
(ClosePortalStmt
);
1784 ClosePortalStmt
*n
= makeNode
(ClosePortalStmt
);
1785 n
->portalname
= NULL
;
1791 /*****************************************************************************
1794 * COPY relname ['(' columnList ')'] FROM/TO file [WITH options]
1796 * BINARY, OIDS, and DELIMITERS kept in old locations
1797 * for backward compatibility. 2002-06-18
1799 * COPY ( SELECT ... ) TO file [WITH options]
1800 * This form doesn't have the backwards-compatible option
1803 *****************************************************************************/
1805 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
1806 copy_from copy_file_name copy_delimiter opt_with copy_opt_list
1808 CopyStmt
*n
= makeNode
(CopyStmt
);
1816 /* Concatenate user-supplied flags */
1818 n
->options
= lappend
(n
->options
, $2);
1820 n
->options
= lappend
(n
->options
, $5);
1822 n
->options
= lappend
(n
->options
, $8);
1824 n
->options
= list_concat
(n
->options
, $10);
1827 | COPY select_with_parens TO copy_file_name opt_with
1830 CopyStmt
*n
= makeNode
(CopyStmt
);
1843 | TO
{ $$
= FALSE
; }
1847 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
1848 * used depends on the direction. (It really doesn't make sense to copy from
1849 * stdout. We silently correct the "typo".) - AY 9/94
1853 | STDIN
{ $$
= NULL
; }
1854 | STDOUT
{ $$
= NULL
; }
1860 copy_opt_list copy_opt_item
{ $$
= lappend
($1, $2); }
1861 |
/* EMPTY */ { $$
= NIL
; }
1868 $$
= makeDefElem
("binary", (Node
*)makeInteger
(TRUE
));
1872 $$
= makeDefElem
("oids", (Node
*)makeInteger
(TRUE
));
1874 | DELIMITER opt_as Sconst
1876 $$
= makeDefElem
("delimiter", (Node
*)makeString
($3));
1878 | NULL_P opt_as Sconst
1880 $$
= makeDefElem
("null", (Node
*)makeString
($3));
1884 $$
= makeDefElem
("csv", (Node
*)makeInteger
(TRUE
));
1888 $$
= makeDefElem
("header", (Node
*)makeInteger
(TRUE
));
1890 | QUOTE opt_as Sconst
1892 $$
= makeDefElem
("quote", (Node
*)makeString
($3));
1894 | ESCAPE opt_as Sconst
1896 $$
= makeDefElem
("escape", (Node
*)makeString
($3));
1898 | FORCE QUOTE columnList
1900 $$
= makeDefElem
("force_quote", (Node
*)$3);
1902 | FORCE NOT NULL_P columnList
1904 $$
= makeDefElem
("force_notnull", (Node
*)$4);
1908 /* The following exist for backward compatibility */
1913 $$
= makeDefElem
("binary", (Node
*)makeInteger
(TRUE
));
1915 |
/*EMPTY*/ { $$
= NULL
; }
1921 $$
= makeDefElem
("oids", (Node
*)makeInteger
(TRUE
));
1923 |
/*EMPTY*/ { $$
= NULL
; }
1927 /* USING DELIMITERS kept for backward compatibility. 2002-06-15 */
1928 opt_using DELIMITERS Sconst
1930 $$
= makeDefElem
("delimiter", (Node
*)makeString
($3));
1932 |
/*EMPTY*/ { $$
= NULL
; }
1941 /*****************************************************************************
1944 * CREATE TABLE relname
1946 *****************************************************************************/
1948 CreateStmt: CREATE OptTemp TABLE qualified_name
'(' OptTableElementList
')'
1949 OptInherit OptWith OnCommitOption OptTableSpace
1951 CreateStmt
*n
= makeNode
(CreateStmt
);
1955 n
->inhRelations
= $8;
1956 n
->constraints
= NIL
;
1959 n
->tablespacename
= $11;
1962 | CREATE OptTemp TABLE qualified_name OF qualified_name
1963 '(' OptTableElementList
')' OptWith OnCommitOption OptTableSpace
1965 /* SQL99 CREATE TABLE OF <UDT> (cols) seems to be satisfied
1966 * by our inheritance capabilities. Let's try it...
1968 CreateStmt
*n
= makeNode
(CreateStmt
);
1972 n
->inhRelations
= list_make1
($6);
1973 n
->constraints
= NIL
;
1976 n
->tablespacename
= $12;
1982 * Redundancy here is needed to avoid shift/reduce conflicts,
1983 * since TEMP is not a reserved word. See also OptTempTableName.
1985 * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
1986 * the LOCAL keyword is really meaningless.
1988 OptTemp: TEMPORARY
{ $$
= TRUE
; }
1989 | TEMP
{ $$
= TRUE
; }
1990 | LOCAL TEMPORARY
{ $$
= TRUE
; }
1991 | LOCAL TEMP
{ $$
= TRUE
; }
1992 | GLOBAL TEMPORARY
{ $$
= TRUE
; }
1993 | GLOBAL TEMP
{ $$
= TRUE
; }
1994 |
/*EMPTY*/ { $$
= FALSE
; }
1997 OptTableElementList:
1998 TableElementList
{ $$
= $1; }
1999 |
/*EMPTY*/ { $$
= NIL
; }
2005 $$
= list_make1
($1);
2007 | TableElementList
',' TableElement
2009 $$
= lappend
($1, $3);
2014 columnDef
{ $$
= $1; }
2015 | TableLikeClause
{ $$
= $1; }
2016 | TableConstraint
{ $$
= $1; }
2019 columnDef: ColId Typename ColQualList
2021 ColumnDef
*n
= makeNode
(ColumnDef
);
2024 n
->constraints
= $3;
2031 ColQualList ColConstraint
{ $$
= lappend
($1, $2); }
2032 |
/*EMPTY*/ { $$
= NIL
; }
2036 CONSTRAINT name ColConstraintElem
2038 switch
(nodeTag
($3))
2042 Constraint
*n
= (Constraint
*)$3;
2046 case T_FkConstraint
:
2048 FkConstraint
*n
= (FkConstraint
*)$3;
2049 n
->constr_name
= $2;
2057 | ColConstraintElem
{ $$
= $1; }
2058 | ConstraintAttr
{ $$
= $1; }
2061 /* DEFAULT NULL is already the default for Postgres.
2062 * But define it here and carry it forward into the system
2063 * to make it explicit.
2064 * - thomas 1998-09-13
2066 * WITH NULL and NULL are not SQL92-standard syntax elements,
2067 * so leave them out. Use DEFAULT NULL to explicitly indicate
2068 * that a column may have that value. WITH NULL leads to
2069 * shift/reduce conflicts with WITH TIME ZONE anyway.
2070 * - thomas 1999-01-08
2072 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
2073 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
2074 * or be part of a_expr NOT LIKE or similar constructs).
2079 Constraint
*n
= makeNode
(Constraint
);
2080 n
->contype
= CONSTR_NOTNULL
;
2083 n
->cooked_expr
= NULL
;
2085 n
->indexspace
= NULL
;
2090 Constraint
*n
= makeNode
(Constraint
);
2091 n
->contype
= CONSTR_NULL
;
2094 n
->cooked_expr
= NULL
;
2096 n
->indexspace
= NULL
;
2099 | UNIQUE opt_definition OptConsTableSpace
2101 Constraint
*n
= makeNode
(Constraint
);
2102 n
->contype
= CONSTR_UNIQUE
;
2105 n
->cooked_expr
= NULL
;
2111 | PRIMARY KEY opt_definition OptConsTableSpace
2113 Constraint
*n
= makeNode
(Constraint
);
2114 n
->contype
= CONSTR_PRIMARY
;
2117 n
->cooked_expr
= NULL
;
2123 | CHECK
'(' a_expr
')'
2125 Constraint
*n
= makeNode
(Constraint
);
2126 n
->contype
= CONSTR_CHECK
;
2129 n
->cooked_expr
= NULL
;
2131 n
->indexspace
= NULL
;
2136 Constraint
*n
= makeNode
(Constraint
);
2137 n
->contype
= CONSTR_DEFAULT
;
2140 n
->cooked_expr
= NULL
;
2142 n
->indexspace
= NULL
;
2145 | REFERENCES qualified_name opt_column_list key_match key_actions
2147 FkConstraint
*n
= makeNode
(FkConstraint
);
2148 n
->constr_name
= NULL
;
2152 n
->fk_matchtype
= $4;
2153 n
->fk_upd_action
= (char) ($5 >> 8);
2154 n
->fk_del_action
= (char) ($5 & 0xFF);
2155 n
->deferrable
= FALSE
;
2156 n
->initdeferred
= FALSE
;
2162 * ConstraintAttr represents constraint attributes, which we parse as if
2163 * they were independent constraint clauses, in order to avoid shift/reduce
2164 * conflicts (since NOT might start either an independent NOT NULL clause
2165 * or an attribute). parse_utilcmd.c is responsible for attaching the
2166 * attribute information to the preceding "real" constraint node, and for
2167 * complaining if attribute clauses appear in the wrong place or wrong
2170 * See also ConstraintAttributeSpec, which can be used in places where
2171 * there is no parsing conflict.
2176 Constraint
*n
= makeNode
(Constraint
);
2177 n
->contype
= CONSTR_ATTR_DEFERRABLE
;
2182 Constraint
*n
= makeNode
(Constraint
);
2183 n
->contype
= CONSTR_ATTR_NOT_DEFERRABLE
;
2186 | INITIALLY DEFERRED
2188 Constraint
*n
= makeNode
(Constraint
);
2189 n
->contype
= CONSTR_ATTR_DEFERRED
;
2192 | INITIALLY IMMEDIATE
2194 Constraint
*n
= makeNode
(Constraint
);
2195 n
->contype
= CONSTR_ATTR_IMMEDIATE
;
2202 * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2203 * This seems to be a poor man's inheritance capability, with the resulting
2204 * tables completely decoupled except for the original commonality in definitions.
2206 * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2207 * which is a part of SQL:2003.
2210 LIKE qualified_name TableLikeOptionList
2212 InhRelation
*n
= makeNode
(InhRelation
);
2219 TableLikeOptionList:
2220 TableLikeOptionList TableLikeOption
{ $$
= lappend_int
($1, $2); }
2221 |
/* EMPTY */ { $$
= NIL
; }
2225 INCLUDING DEFAULTS
{ $$
= CREATE_TABLE_LIKE_INCLUDING_DEFAULTS
; }
2226 | EXCLUDING DEFAULTS
{ $$
= CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS
; }
2227 | INCLUDING CONSTRAINTS
{ $$
= CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS
; }
2228 | EXCLUDING CONSTRAINTS
{ $$
= CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS
; }
2229 | INCLUDING INDEXES
{ $$
= CREATE_TABLE_LIKE_INCLUDING_INDEXES
; }
2230 | EXCLUDING INDEXES
{ $$
= CREATE_TABLE_LIKE_EXCLUDING_INDEXES
; }
2234 /* ConstraintElem specifies constraint syntax which is not embedded into
2235 * a column definition. ColConstraintElem specifies the embedded form.
2236 * - thomas 1997-12-03
2239 CONSTRAINT name ConstraintElem
2241 switch
(nodeTag
($3))
2245 Constraint
*n
= (Constraint
*)$3;
2249 case T_FkConstraint
:
2251 FkConstraint
*n
= (FkConstraint
*)$3;
2252 n
->constr_name
= $2;
2260 | ConstraintElem
{ $$
= $1; }
2264 CHECK
'(' a_expr
')'
2266 Constraint
*n
= makeNode
(Constraint
);
2267 n
->contype
= CONSTR_CHECK
;
2270 n
->cooked_expr
= NULL
;
2271 n
->indexspace
= NULL
;
2274 | UNIQUE
'(' columnList
')' opt_definition OptConsTableSpace
2276 Constraint
*n
= makeNode
(Constraint
);
2277 n
->contype
= CONSTR_UNIQUE
;
2280 n
->cooked_expr
= NULL
;
2286 | PRIMARY KEY
'(' columnList
')' opt_definition OptConsTableSpace
2288 Constraint
*n
= makeNode
(Constraint
);
2289 n
->contype
= CONSTR_PRIMARY
;
2292 n
->cooked_expr
= NULL
;
2298 | FOREIGN KEY
'(' columnList
')' REFERENCES qualified_name
2299 opt_column_list key_match key_actions ConstraintAttributeSpec
2301 FkConstraint
*n
= makeNode
(FkConstraint
);
2302 n
->constr_name
= NULL
;
2306 n
->fk_matchtype
= $9;
2307 n
->fk_upd_action
= (char) ($10 >> 8);
2308 n
->fk_del_action
= (char) ($10 & 0xFF);
2309 n
->deferrable
= ($11 & 1) != 0;
2310 n
->initdeferred
= ($11 & 2) != 0;
2316 '(' columnList
')' { $$
= $2; }
2317 |
/*EMPTY*/ { $$
= NIL
; }
2321 columnElem
{ $$
= list_make1
($1); }
2322 | columnList
',' columnElem
{ $$
= lappend
($1, $3); }
2327 $$
= (Node
*) makeString
($1);
2331 key_match: MATCH FULL
2333 $$
= FKCONSTR_MATCH_FULL
;
2338 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
2339 errmsg
("MATCH PARTIAL not yet implemented"),
2340 scanner_errposition
(@
1)));
2341 $$
= FKCONSTR_MATCH_PARTIAL
;
2345 $$
= FKCONSTR_MATCH_UNSPECIFIED
;
2349 $$
= FKCONSTR_MATCH_UNSPECIFIED
;
2354 * We combine the update and delete actions into one value temporarily
2355 * for simplicity of parsing, and then break them down again in the
2356 * calling production. update is in the left 8 bits, delete in the right.
2357 * Note that NOACTION is the default.
2361 { $$
= ($1 << 8) |
(FKCONSTR_ACTION_NOACTION
& 0xFF); }
2363 { $$
= (FKCONSTR_ACTION_NOACTION
<< 8) |
($1 & 0xFF); }
2364 | key_update key_delete
2365 { $$
= ($1 << 8) |
($2 & 0xFF); }
2366 | key_delete key_update
2367 { $$
= ($2 << 8) |
($1 & 0xFF); }
2369 { $$
= (FKCONSTR_ACTION_NOACTION
<< 8) |
(FKCONSTR_ACTION_NOACTION
& 0xFF); }
2372 key_update: ON UPDATE key_action
{ $$
= $3; }
2375 key_delete: ON DELETE_P key_action
{ $$
= $3; }
2379 NO ACTION
{ $$
= FKCONSTR_ACTION_NOACTION
; }
2380 | RESTRICT
{ $$
= FKCONSTR_ACTION_RESTRICT
; }
2381 | CASCADE
{ $$
= FKCONSTR_ACTION_CASCADE
; }
2382 | SET NULL_P
{ $$
= FKCONSTR_ACTION_SETNULL
; }
2383 | SET DEFAULT
{ $$
= FKCONSTR_ACTION_SETDEFAULT
; }
2386 OptInherit: INHERITS
'(' qualified_name_list
')' { $$
= $3; }
2387 |
/*EMPTY*/ { $$
= NIL
; }
2390 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
2392 WITH definition
{ $$
= $2; }
2393 | WITH OIDS
{ $$
= list_make1
(defWithOids
(true
)); }
2394 | WITHOUT OIDS
{ $$
= list_make1
(defWithOids
(false
)); }
2395 |
/*EMPTY*/ { $$
= NIL
; }
2398 OnCommitOption: ON COMMIT DROP
{ $$
= ONCOMMIT_DROP
; }
2399 | ON COMMIT DELETE_P ROWS
{ $$
= ONCOMMIT_DELETE_ROWS
; }
2400 | ON COMMIT PRESERVE ROWS
{ $$
= ONCOMMIT_PRESERVE_ROWS
; }
2401 |
/*EMPTY*/ { $$
= ONCOMMIT_NOOP
; }
2404 OptTableSpace: TABLESPACE name
{ $$
= $2; }
2405 |
/*EMPTY*/ { $$
= NULL
; }
2408 OptConsTableSpace: USING INDEX TABLESPACE name
{ $$
= $4; }
2409 |
/*EMPTY*/ { $$
= NULL
; }
2414 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
2419 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
2422 * When the SelectStmt is a set-operation tree, we must
2423 * stuff the INTO information into the leftmost component
2424 * Select, because that's where analyze.c will expect
2425 * to find it. Similarly, the output column names must
2426 * be attached to that Select's target list.
2428 SelectStmt
*n
= findLeftmostSelect
((SelectStmt
*) $6);
2429 if
(n
->intoClause
!= NULL
)
2431 (errcode
(ERRCODE_SYNTAX_ERROR
),
2432 errmsg
("CREATE TABLE AS cannot specify INTO"),
2433 scanner_errposition
(exprLocation
((Node
*) n
->intoClause
))));
2434 $4->rel
->istemp
= $2;
2436 /* Implement WITH NO DATA by forcing top-level LIMIT 0 */
2438 ((SelectStmt
*) $6)->limitCount
= makeIntConst
(0, -1);
2444 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
2446 $$
= makeNode
(IntoClause
);
2451 $$
->tableSpaceName
= $5;
2456 '(' CreateAsList
')' { $$
= $2; }
2457 |
/*EMPTY*/ { $$
= NIL
; }
2461 CreateAsElement
{ $$
= list_make1
($1); }
2462 | CreateAsList
',' CreateAsElement
{ $$
= lappend
($1, $3); }
2468 ColumnDef
*n
= makeNode
(ColumnDef
);
2473 n
->is_not_null
= false
;
2474 n
->raw_default
= NULL
;
2475 n
->cooked_default
= NULL
;
2476 n
->constraints
= NIL
;
2482 WITH DATA_P
{ $$
= TRUE
; }
2483 | WITH NO DATA_P
{ $$
= FALSE
; }
2484 |
/*EMPTY*/ { $$
= TRUE
; }
2488 /*****************************************************************************
2491 * CREATE SEQUENCE seqname
2492 * ALTER SEQUENCE seqname
2494 *****************************************************************************/
2497 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
2499 CreateSeqStmt
*n
= makeNode
(CreateSeqStmt
);
2508 ALTER SEQUENCE relation_expr SeqOptList
2510 AlterSeqStmt
*n
= makeNode
(AlterSeqStmt
);
2517 OptSeqOptList: SeqOptList
{ $$
= $1; }
2518 |
/*EMPTY*/ { $$
= NIL
; }
2521 SeqOptList: SeqOptElem
{ $$
= list_make1
($1); }
2522 | SeqOptList SeqOptElem
{ $$
= lappend
($1, $2); }
2525 SeqOptElem: CACHE NumericOnly
2527 $$
= makeDefElem
("cache", (Node
*)$2);
2531 $$
= makeDefElem
("cycle", (Node
*)makeInteger
(TRUE
));
2535 $$
= makeDefElem
("cycle", (Node
*)makeInteger
(FALSE
));
2537 | INCREMENT opt_by NumericOnly
2539 $$
= makeDefElem
("increment", (Node
*)$3);
2541 | MAXVALUE NumericOnly
2543 $$
= makeDefElem
("maxvalue", (Node
*)$2);
2545 | MINVALUE NumericOnly
2547 $$
= makeDefElem
("minvalue", (Node
*)$2);
2551 $$
= makeDefElem
("maxvalue", NULL
);
2555 $$
= makeDefElem
("minvalue", NULL
);
2559 $$
= makeDefElem
("owned_by", (Node
*)$3);
2561 | START opt_with NumericOnly
2563 $$
= makeDefElem
("start", (Node
*)$3);
2567 $$
= makeDefElem
("restart", NULL
);
2569 | RESTART opt_with NumericOnly
2571 $$
= makeDefElem
("restart", (Node
*)$3);
2580 FloatOnly
{ $$
= $1; }
2581 | IntegerOnly
{ $$
= $1; }
2584 FloatOnly: FCONST
{ $$
= makeFloat
($1); }
2592 IntegerOnly: SignedIconst
{ $$
= makeInteger
($1); };
2595 /*****************************************************************************
2598 * CREATE PROCEDURAL LANGUAGE ...
2599 * DROP PROCEDURAL LANGUAGE ...
2601 *****************************************************************************/
2604 CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2606 CreatePLangStmt
*n
= makeNode
(CreatePLangStmt
);
2608 /* parameters are all to be supplied by system */
2610 n
->plvalidator
= NIL
;
2611 n
->pltrusted
= false
;
2614 | CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2615 HANDLER handler_name opt_validator opt_lancompiler
2617 CreatePLangStmt
*n
= makeNode
(CreatePLangStmt
);
2620 n
->plvalidator
= $8;
2622 /* LANCOMPILER is now ignored entirely */
2628 TRUSTED
{ $$
= TRUE
; }
2629 |
/*EMPTY*/ { $$
= FALSE
; }
2632 /* This ought to be just func_name, but that causes reduce/reduce conflicts
2633 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
2634 * Work around by using simple names, instead.
2637 name
{ $$
= list_make1
(makeString
($1)); }
2638 | name attrs
{ $$
= lcons
(makeString
($1), $2); }
2642 VALIDATOR handler_name
{ $$
= $2; }
2643 |
/*EMPTY*/ { $$
= NIL
; }
2647 LANCOMPILER Sconst
{ $$
= $2; }
2648 |
/*EMPTY*/ { $$
= NULL
; }
2652 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
2654 DropPLangStmt
*n
= makeNode
(DropPLangStmt
);
2657 n
->missing_ok
= false
;
2660 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
2662 DropPLangStmt
*n
= makeNode
(DropPLangStmt
);
2665 n
->missing_ok
= true
;
2675 /*****************************************************************************
2678 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
2680 *****************************************************************************/
2682 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
2684 CreateTableSpaceStmt
*n
= makeNode
(CreateTableSpaceStmt
);
2685 n
->tablespacename
= $3;
2692 OptTableSpaceOwner: OWNER name
{ $$
= $2; }
2693 |
/*EMPTY */ { $$
= NULL
; }
2696 /*****************************************************************************
2699 * DROP TABLESPACE <tablespace>
2701 * No need for drop behaviour as we cannot implement dependencies for
2702 * objects in other databases; we can only support RESTRICT.
2704 ****************************************************************************/
2706 DropTableSpaceStmt: DROP TABLESPACE name
2708 DropTableSpaceStmt
*n
= makeNode
(DropTableSpaceStmt
);
2709 n
->tablespacename
= $3;
2710 n
->missing_ok
= false
;
2713 | DROP TABLESPACE IF_P EXISTS name
2715 DropTableSpaceStmt
*n
= makeNode
(DropTableSpaceStmt
);
2716 n
->tablespacename
= $5;
2717 n
->missing_ok
= true
;
2722 /*****************************************************************************
2725 * CREATE TRIGGER ...
2728 *****************************************************************************/
2731 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
2732 qualified_name TriggerForSpec EXECUTE PROCEDURE
2733 func_name
'(' TriggerFuncArgs
')'
2735 CreateTrigStmt
*n
= makeNode
(CreateTrigStmt
);
2742 memcpy
(n
->actions
, $5, 4);
2743 n
->isconstraint
= FALSE
;
2744 n
->deferrable
= FALSE
;
2745 n
->initdeferred
= FALSE
;
2746 n
->constrrel
= NULL
;
2749 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
2750 qualified_name OptConstrFromTable
2751 ConstraintAttributeSpec
2752 FOR EACH ROW EXECUTE PROCEDURE
2753 func_name
'(' TriggerFuncArgs
')'
2755 CreateTrigStmt
*n
= makeNode
(CreateTrigStmt
);
2762 memcpy
(n
->actions
, $6, 4);
2763 n
->isconstraint
= TRUE
;
2764 n
->deferrable
= ($10 & 1) != 0;
2765 n
->initdeferred
= ($10 & 2) != 0;
2773 BEFORE
{ $$
= TRUE
; }
2774 | AFTER
{ $$
= FALSE
; }
2780 char *e
= palloc
(4);
2781 e
[0] = $1; e
[1] = '\0';
2784 | TriggerOneEvent OR TriggerOneEvent
2786 char *e
= palloc
(4);
2787 e
[0] = $1; e
[1] = $3; e
[2] = '\0';
2790 | TriggerOneEvent OR TriggerOneEvent OR TriggerOneEvent
2792 char *e
= palloc
(4);
2793 e
[0] = $1; e
[1] = $3; e
[2] = $5; e
[3] = '\0';
2799 INSERT
{ $$
= 'i'; }
2800 | DELETE_P
{ $$
= 'd'; }
2801 | UPDATE
{ $$
= 'u'; }
2802 | TRUNCATE
{ $$
= 't'; }
2806 FOR TriggerForOpt TriggerForType
2813 * If ROW/STATEMENT not specified, default to
2814 * STATEMENT, per SQL
2827 | STATEMENT
{ $$
= FALSE
; }
2831 TriggerFuncArg
{ $$
= list_make1
($1); }
2832 | TriggerFuncArgs
',' TriggerFuncArg
{ $$
= lappend
($1, $3); }
2833 |
/*EMPTY*/ { $$
= NIL
; }
2840 snprintf
(buf
, sizeof
(buf
), "%d", $1);
2841 $$
= makeString
(pstrdup
(buf
));
2843 | FCONST
{ $$
= makeString
($1); }
2844 | Sconst
{ $$
= makeString
($1); }
2845 | BCONST
{ $$
= makeString
($1); }
2846 | XCONST
{ $$
= makeString
($1); }
2847 | ColId
{ $$
= makeString
($1); }
2851 FROM qualified_name
{ $$
= $2; }
2852 |
/*EMPTY*/ { $$
= NULL
; }
2855 ConstraintAttributeSpec:
2856 ConstraintDeferrabilitySpec
2858 | ConstraintDeferrabilitySpec ConstraintTimeSpec
2860 if
($1 == 0 && $2 != 0)
2862 (errcode
(ERRCODE_SYNTAX_ERROR
),
2863 errmsg
("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
2864 scanner_errposition
(@
1)));
2867 | ConstraintTimeSpec
2874 | ConstraintTimeSpec ConstraintDeferrabilitySpec
2876 if
($2 == 0 && $1 != 0)
2878 (errcode
(ERRCODE_SYNTAX_ERROR
),
2879 errmsg
("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
2880 scanner_errposition
(@
1)));
2887 ConstraintDeferrabilitySpec:
2888 NOT DEFERRABLE
{ $$
= 0; }
2889 | DEFERRABLE
{ $$
= 1; }
2893 INITIALLY IMMEDIATE
{ $$
= 0; }
2894 | INITIALLY DEFERRED
{ $$
= 2; }
2899 DROP TRIGGER name ON qualified_name opt_drop_behavior
2901 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
2905 n
->removeType
= OBJECT_TRIGGER
;
2906 n
->missing_ok
= false
;
2909 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
2911 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
2915 n
->removeType
= OBJECT_TRIGGER
;
2916 n
->missing_ok
= true
;
2922 /*****************************************************************************
2925 * CREATE ASSERTION ...
2926 * DROP ASSERTION ...
2928 *****************************************************************************/
2931 CREATE ASSERTION name CHECK
'(' a_expr
')'
2932 ConstraintAttributeSpec
2934 CreateTrigStmt
*n
= makeNode
(CreateTrigStmt
);
2936 n
->args
= list_make1
($6);
2937 n
->isconstraint
= TRUE
;
2938 n
->deferrable
= ($8 & 1) != 0;
2939 n
->initdeferred
= ($8 & 2) != 0;
2942 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
2943 errmsg
("CREATE ASSERTION is not yet implemented")));
2950 DROP ASSERTION name opt_drop_behavior
2952 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
2956 n
->removeType
= OBJECT_TRIGGER
; /* XXX */
2958 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
2959 errmsg
("DROP ASSERTION is not yet implemented")));
2965 /*****************************************************************************
2968 * define (aggregate,operator,type)
2970 *****************************************************************************/
2973 CREATE AGGREGATE func_name aggr_args definition
2975 DefineStmt
*n
= makeNode
(DefineStmt
);
2976 n
->kind
= OBJECT_AGGREGATE
;
2977 n
->oldstyle
= false
;
2983 | CREATE AGGREGATE func_name old_aggr_definition
2985 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
2986 DefineStmt
*n
= makeNode
(DefineStmt
);
2987 n
->kind
= OBJECT_AGGREGATE
;
2994 | CREATE OPERATOR any_operator definition
2996 DefineStmt
*n
= makeNode
(DefineStmt
);
2997 n
->kind
= OBJECT_OPERATOR
;
2998 n
->oldstyle
= false
;
3004 | CREATE TYPE_P any_name definition
3006 DefineStmt
*n
= makeNode
(DefineStmt
);
3007 n
->kind
= OBJECT_TYPE
;
3008 n
->oldstyle
= false
;
3014 | CREATE TYPE_P any_name
3016 /* Shell type (identified by lack of definition) */
3017 DefineStmt
*n
= makeNode
(DefineStmt
);
3018 n
->kind
= OBJECT_TYPE
;
3019 n
->oldstyle
= false
;
3022 n
->definition
= NIL
;
3025 | CREATE TYPE_P any_name AS
'(' TableFuncElementList
')'
3027 CompositeTypeStmt
*n
= makeNode
(CompositeTypeStmt
);
3028 RangeVar
*r
= makeNode
(RangeVar
);
3030 /* can't use qualified_name, sigh */
3031 switch
(list_length
($3))
3034 r
->catalogname
= NULL
;
3035 r
->schemaname
= NULL
;
3036 r
->relname
= strVal
(linitial
($3));
3039 r
->catalogname
= NULL
;
3040 r
->schemaname
= strVal
(linitial
($3));
3041 r
->relname
= strVal
(lsecond
($3));
3044 r
->catalogname
= strVal
(linitial
($3));
3045 r
->schemaname
= strVal
(lsecond
($3));
3046 r
->relname
= strVal
(lthird
($3));
3050 (errcode
(ERRCODE_SYNTAX_ERROR
),
3051 errmsg
("improper qualified name (too many dotted names): %s",
3052 NameListToString
($3)),
3053 scanner_errposition
(@
3)));
3061 | CREATE TYPE_P any_name AS ENUM_P
'(' enum_val_list
')'
3063 CreateEnumStmt
*n
= makeNode
(CreateEnumStmt
);
3068 | CREATE TEXT_P SEARCH PARSER any_name definition
3070 DefineStmt
*n
= makeNode
(DefineStmt
);
3071 n
->kind
= OBJECT_TSPARSER
;
3077 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
3079 DefineStmt
*n
= makeNode
(DefineStmt
);
3080 n
->kind
= OBJECT_TSDICTIONARY
;
3086 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
3088 DefineStmt
*n
= makeNode
(DefineStmt
);
3089 n
->kind
= OBJECT_TSTEMPLATE
;
3095 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
3097 DefineStmt
*n
= makeNode
(DefineStmt
);
3098 n
->kind
= OBJECT_TSCONFIGURATION
;
3106 definition: '(' def_list
')' { $$
= $2; }
3109 def_list: def_elem
{ $$
= list_make1
($1); }
3110 | def_list
',' def_elem
{ $$
= lappend
($1, $3); }
3113 def_elem: ColLabel
'=' def_arg
3115 $$
= makeDefElem
($1, (Node
*)$3);
3119 $$
= makeDefElem
($1, NULL
);
3123 /* Note: any simple identifier will be returned as a type name! */
3124 def_arg: func_type
{ $$
= (Node
*)$1; }
3125 | reserved_keyword
{ $$
= (Node
*)makeString
(pstrdup
($1)); }
3126 | qual_all_Op
{ $$
= (Node
*)$1; }
3127 | NumericOnly
{ $$
= (Node
*)$1; }
3128 | Sconst
{ $$
= (Node
*)makeString
($1); }
3131 aggr_args: '(' type_list
')' { $$
= $2; }
3132 |
'(' '*' ')' { $$
= NIL
; }
3135 old_aggr_definition: '(' old_aggr_list
')' { $$
= $2; }
3138 old_aggr_list: old_aggr_elem
{ $$
= list_make1
($1); }
3139 | old_aggr_list
',' old_aggr_elem
{ $$
= lappend
($1, $3); }
3142 old_aggr_elem: IDENT
'=' def_arg
3144 $$
= makeDefElem
($1, (Node
*)$3);
3148 enum_val_list: Sconst
3149 { $$
= list_make1
(makeString
($1)); }
3150 | enum_val_list
',' Sconst
3151 { $$
= lappend
($1, makeString
($3)); }
3155 /*****************************************************************************
3158 * CREATE OPERATOR CLASS ...
3159 * CREATE OPERATOR FAMILY ...
3160 * ALTER OPERATOR FAMILY ...
3161 * DROP OPERATOR CLASS ...
3162 * DROP OPERATOR FAMILY ...
3164 *****************************************************************************/
3167 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
3168 USING access_method opt_opfamily AS opclass_item_list
3170 CreateOpClassStmt
*n
= makeNode
(CreateOpClassStmt
);
3171 n
->opclassname
= $4;
3175 n
->opfamilyname
= $11;
3182 opclass_item
{ $$
= list_make1
($1); }
3183 | opclass_item_list
',' opclass_item
{ $$
= lappend
($1, $3); }
3187 OPERATOR Iconst any_operator opt_recheck
3189 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3190 n
->itemtype
= OPCLASS_ITEM_OPERATOR
;
3196 | OPERATOR Iconst any_operator oper_argtypes opt_recheck
3198 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3199 n
->itemtype
= OPCLASS_ITEM_OPERATOR
;
3205 | FUNCTION Iconst func_name func_args
3207 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3208 n
->itemtype
= OPCLASS_ITEM_FUNCTION
;
3210 n
->args
= extractArgTypes
($4);
3214 | FUNCTION Iconst
'(' type_list
')' func_name func_args
3216 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3217 n
->itemtype
= OPCLASS_ITEM_FUNCTION
;
3219 n
->args
= extractArgTypes
($7);
3226 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3227 n
->itemtype
= OPCLASS_ITEM_STORAGETYPE
;
3233 opt_default: DEFAULT
{ $$
= TRUE
; }
3234 |
/*EMPTY*/ { $$
= FALSE
; }
3237 opt_opfamily: FAMILY any_name
{ $$
= $2; }
3238 |
/*EMPTY*/ { $$
= NIL
; }
3241 opt_recheck: RECHECK
3244 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
3245 errmsg
("RECHECK is no longer supported"),
3246 errhint
("Update your data type."),
3247 scanner_errposition
(@
1)));
3250 |
/*EMPTY*/ { $$
= FALSE
; }
3255 CREATE OPERATOR FAMILY any_name USING access_method
3257 CreateOpFamilyStmt
*n
= makeNode
(CreateOpFamilyStmt
);
3258 n
->opfamilyname
= $4;
3265 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
3267 AlterOpFamilyStmt
*n
= makeNode
(AlterOpFamilyStmt
);
3268 n
->opfamilyname
= $4;
3274 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
3276 AlterOpFamilyStmt
*n
= makeNode
(AlterOpFamilyStmt
);
3277 n
->opfamilyname
= $4;
3286 opclass_drop
{ $$
= list_make1
($1); }
3287 | opclass_drop_list
',' opclass_drop
{ $$
= lappend
($1, $3); }
3291 OPERATOR Iconst
'(' type_list
')'
3293 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3294 n
->itemtype
= OPCLASS_ITEM_OPERATOR
;
3299 | FUNCTION Iconst
'(' type_list
')'
3301 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3302 n
->itemtype
= OPCLASS_ITEM_FUNCTION
;
3311 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
3313 RemoveOpClassStmt
*n
= makeNode
(RemoveOpClassStmt
);
3314 n
->opclassname
= $4;
3317 n
->missing_ok
= false
;
3320 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
3322 RemoveOpClassStmt
*n
= makeNode
(RemoveOpClassStmt
);
3323 n
->opclassname
= $6;
3326 n
->missing_ok
= true
;
3332 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
3334 RemoveOpFamilyStmt
*n
= makeNode
(RemoveOpFamilyStmt
);
3335 n
->opfamilyname
= $4;
3338 n
->missing_ok
= false
;
3341 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
3343 RemoveOpFamilyStmt
*n
= makeNode
(RemoveOpFamilyStmt
);
3344 n
->opfamilyname
= $6;
3347 n
->missing_ok
= true
;
3353 /*****************************************************************************
3357 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
3358 * REASSIGN OWNED BY username [, username ...] TO username
3360 *****************************************************************************/
3362 DROP OWNED BY name_list opt_drop_behavior
3364 DropOwnedStmt
*n
= makeNode
(DropOwnedStmt
);
3372 REASSIGN OWNED BY name_list TO name
3374 ReassignOwnedStmt
*n
= makeNode
(ReassignOwnedStmt
);
3381 /*****************************************************************************
3385 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
3386 * [ RESTRICT | CASCADE ]
3388 *****************************************************************************/
3390 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
3392 DropStmt
*n
= makeNode
(DropStmt
);
3394 n
->missing_ok
= TRUE
;
3399 | DROP drop_type any_name_list opt_drop_behavior
3401 DropStmt
*n
= makeNode
(DropStmt
);
3403 n
->missing_ok
= FALSE
;
3411 drop_type: TABLE
{ $$
= OBJECT_TABLE
; }
3412 | SEQUENCE
{ $$
= OBJECT_SEQUENCE
; }
3413 | VIEW
{ $$
= OBJECT_VIEW
; }
3414 | INDEX
{ $$
= OBJECT_INDEX
; }
3415 | TYPE_P
{ $$
= OBJECT_TYPE
; }
3416 | DOMAIN_P
{ $$
= OBJECT_DOMAIN
; }
3417 | CONVERSION_P
{ $$
= OBJECT_CONVERSION
; }
3418 | SCHEMA
{ $$
= OBJECT_SCHEMA
; }
3419 | TEXT_P SEARCH PARSER
{ $$
= OBJECT_TSPARSER
; }
3420 | TEXT_P SEARCH DICTIONARY
{ $$
= OBJECT_TSDICTIONARY
; }
3421 | TEXT_P SEARCH TEMPLATE
{ $$
= OBJECT_TSTEMPLATE
; }
3422 | TEXT_P SEARCH CONFIGURATION
{ $$
= OBJECT_TSCONFIGURATION
; }
3426 any_name
{ $$
= list_make1
($1); }
3427 | any_name_list
',' any_name
{ $$
= lappend
($1, $3); }
3430 any_name: ColId
{ $$
= list_make1
(makeString
($1)); }
3431 | ColId attrs
{ $$
= lcons
(makeString
($1), $2); }
3434 attrs: '.' attr_name
3435 { $$
= list_make1
(makeString
($2)); }
3436 | attrs
'.' attr_name
3437 { $$
= lappend
($1, makeString
($3)); }
3441 /*****************************************************************************
3444 * truncate table relname1, relname2, ...
3446 *****************************************************************************/
3449 TRUNCATE opt_table qualified_name_list opt_restart_seqs opt_drop_behavior
3451 TruncateStmt
*n
= makeNode
(TruncateStmt
);
3453 n
->restart_seqs
= $4;
3460 CONTINUE_P IDENTITY_P
{ $$
= false
; }
3461 | RESTART IDENTITY_P
{ $$
= true
; }
3462 |
/* EMPTY */ { $$
= false
; }
3465 /*****************************************************************************
3467 * The COMMENT ON statement can take different forms based upon the type of
3468 * the object associated with the comment. The form of the statement is:
3470 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
3471 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
3472 * CAST | COLUMN | SCHEMA | TABLESPACE | ROLE |
3473 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
3474 * TEXT SEARCH TEMPLATE |
3475 * TEXT SEARCH CONFIGURATION ] <objname> |
3476 * AGGREGATE <aggname> (arg1, ...) |
3477 * FUNCTION <funcname> (arg1, arg2, ...) |
3478 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
3479 * TRIGGER <triggername> ON <relname> |
3480 * CONSTRAINT <constraintname> ON <relname> |
3481 * RULE <rulename> ON <relname> ]
3484 *****************************************************************************/
3487 COMMENT ON comment_type any_name IS comment_text
3489 CommentStmt
*n
= makeNode
(CommentStmt
);
3496 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
3498 CommentStmt
*n
= makeNode
(CommentStmt
);
3499 n
->objtype
= OBJECT_AGGREGATE
;
3505 | COMMENT ON FUNCTION func_name func_args IS comment_text
3507 CommentStmt
*n
= makeNode
(CommentStmt
);
3508 n
->objtype
= OBJECT_FUNCTION
;
3510 n
->objargs
= extractArgTypes
($5);
3514 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
3516 CommentStmt
*n
= makeNode
(CommentStmt
);
3517 n
->objtype
= OBJECT_OPERATOR
;
3523 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
3525 CommentStmt
*n
= makeNode
(CommentStmt
);
3526 n
->objtype
= OBJECT_CONSTRAINT
;
3527 n
->objname
= lappend
($6, makeString
($4));
3532 | COMMENT ON RULE name ON any_name IS comment_text
3534 CommentStmt
*n
= makeNode
(CommentStmt
);
3535 n
->objtype
= OBJECT_RULE
;
3536 n
->objname
= lappend
($6, makeString
($4));
3541 | COMMENT ON RULE name IS comment_text
3543 /* Obsolete syntax supported for awhile for compatibility */
3544 CommentStmt
*n
= makeNode
(CommentStmt
);
3545 n
->objtype
= OBJECT_RULE
;
3546 n
->objname
= list_make1
(makeString
($4));
3551 | COMMENT ON TRIGGER name ON any_name IS comment_text
3553 CommentStmt
*n
= makeNode
(CommentStmt
);
3554 n
->objtype
= OBJECT_TRIGGER
;
3555 n
->objname
= lappend
($6, makeString
($4));
3560 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
3562 CommentStmt
*n
= makeNode
(CommentStmt
);
3563 n
->objtype
= OBJECT_OPCLASS
;
3565 n
->objargs
= list_make1
(makeString
($7));
3569 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
3571 CommentStmt
*n
= makeNode
(CommentStmt
);
3572 n
->objtype
= OBJECT_OPFAMILY
;
3574 n
->objargs
= list_make1
(makeString
($7));
3578 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
3580 CommentStmt
*n
= makeNode
(CommentStmt
);
3581 n
->objtype
= OBJECT_LARGEOBJECT
;
3582 n
->objname
= list_make1
($5);
3587 | COMMENT ON CAST
'(' Typename AS Typename
')' IS comment_text
3589 CommentStmt
*n
= makeNode
(CommentStmt
);
3590 n
->objtype
= OBJECT_CAST
;
3591 n
->objname
= list_make1
($5);
3592 n
->objargs
= list_make1
($7);
3596 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
3598 CommentStmt
*n
= makeNode
(CommentStmt
);
3599 n
->objtype
= OBJECT_LANGUAGE
;
3605 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
3607 CommentStmt
*n
= makeNode
(CommentStmt
);
3608 n
->objtype
= OBJECT_TSPARSER
;
3613 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
3615 CommentStmt
*n
= makeNode
(CommentStmt
);
3616 n
->objtype
= OBJECT_TSDICTIONARY
;
3621 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
3623 CommentStmt
*n
= makeNode
(CommentStmt
);
3624 n
->objtype
= OBJECT_TSTEMPLATE
;
3629 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
3631 CommentStmt
*n
= makeNode
(CommentStmt
);
3632 n
->objtype
= OBJECT_TSCONFIGURATION
;
3640 COLUMN
{ $$
= OBJECT_COLUMN
; }
3641 | DATABASE
{ $$
= OBJECT_DATABASE
; }
3642 | SCHEMA
{ $$
= OBJECT_SCHEMA
; }
3643 | INDEX
{ $$
= OBJECT_INDEX
; }
3644 | SEQUENCE
{ $$
= OBJECT_SEQUENCE
; }
3645 | TABLE
{ $$
= OBJECT_TABLE
; }
3646 | DOMAIN_P
{ $$
= OBJECT_TYPE
; }
3647 | TYPE_P
{ $$
= OBJECT_TYPE
; }
3648 | VIEW
{ $$
= OBJECT_VIEW
; }
3649 | CONVERSION_P
{ $$
= OBJECT_CONVERSION
; }
3650 | TABLESPACE
{ $$
= OBJECT_TABLESPACE
; }
3651 | ROLE
{ $$
= OBJECT_ROLE
; }
3656 | NULL_P
{ $$
= NULL
; }
3659 /*****************************************************************************
3664 *****************************************************************************/
3666 FetchStmt: FETCH fetch_direction from_in name
3668 FetchStmt
*n
= (FetchStmt
*) $2;
3675 FetchStmt
*n
= makeNode
(FetchStmt
);
3676 n
->direction
= FETCH_FORWARD
;
3682 | MOVE fetch_direction from_in name
3684 FetchStmt
*n
= (FetchStmt
*) $2;
3691 FetchStmt
*n
= makeNode
(FetchStmt
);
3692 n
->direction
= FETCH_FORWARD
;
3703 FetchStmt
*n
= makeNode
(FetchStmt
);
3704 n
->direction
= FETCH_FORWARD
;
3710 FetchStmt
*n
= makeNode
(FetchStmt
);
3711 n
->direction
= FETCH_FORWARD
;
3717 FetchStmt
*n
= makeNode
(FetchStmt
);
3718 n
->direction
= FETCH_BACKWARD
;
3724 FetchStmt
*n
= makeNode
(FetchStmt
);
3725 n
->direction
= FETCH_ABSOLUTE
;
3731 FetchStmt
*n
= makeNode
(FetchStmt
);
3732 n
->direction
= FETCH_ABSOLUTE
;
3736 | ABSOLUTE_P SignedIconst
3738 FetchStmt
*n
= makeNode
(FetchStmt
);
3739 n
->direction
= FETCH_ABSOLUTE
;
3743 | RELATIVE_P SignedIconst
3745 FetchStmt
*n
= makeNode
(FetchStmt
);
3746 n
->direction
= FETCH_RELATIVE
;
3752 FetchStmt
*n
= makeNode
(FetchStmt
);
3753 n
->direction
= FETCH_FORWARD
;
3759 FetchStmt
*n
= makeNode
(FetchStmt
);
3760 n
->direction
= FETCH_FORWARD
;
3761 n
->howMany
= FETCH_ALL
;
3766 FetchStmt
*n
= makeNode
(FetchStmt
);
3767 n
->direction
= FETCH_FORWARD
;
3771 | FORWARD SignedIconst
3773 FetchStmt
*n
= makeNode
(FetchStmt
);
3774 n
->direction
= FETCH_FORWARD
;
3780 FetchStmt
*n
= makeNode
(FetchStmt
);
3781 n
->direction
= FETCH_FORWARD
;
3782 n
->howMany
= FETCH_ALL
;
3787 FetchStmt
*n
= makeNode
(FetchStmt
);
3788 n
->direction
= FETCH_BACKWARD
;
3792 | BACKWARD SignedIconst
3794 FetchStmt
*n
= makeNode
(FetchStmt
);
3795 n
->direction
= FETCH_BACKWARD
;
3801 FetchStmt
*n
= makeNode
(FetchStmt
);
3802 n
->direction
= FETCH_BACKWARD
;
3803 n
->howMany
= FETCH_ALL
;
3813 /*****************************************************************************
3815 * GRANT and REVOKE statements
3817 *****************************************************************************/
3819 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
3820 opt_grant_grant_option
3822 GrantStmt
*n
= makeNode
(GrantStmt
);
3825 n
->objtype
= ($4)->objtype
;
3826 n
->objects
= ($4)->objs
;
3828 n
->grant_option
= $7;
3834 REVOKE privileges ON privilege_target
3835 FROM grantee_list opt_drop_behavior
3837 GrantStmt
*n
= makeNode
(GrantStmt
);
3838 n
->is_grant
= false
;
3839 n
->grant_option
= false
;
3841 n
->objtype
= ($4)->objtype
;
3842 n
->objects
= ($4)->objs
;
3847 | REVOKE GRANT OPTION FOR privileges ON privilege_target
3848 FROM grantee_list opt_drop_behavior
3850 GrantStmt
*n
= makeNode
(GrantStmt
);
3851 n
->is_grant
= false
;
3852 n
->grant_option
= true
;
3854 n
->objtype
= ($7)->objtype
;
3855 n
->objects
= ($7)->objs
;
3864 * A privilege list is represented as a list of strings; the validity of
3865 * the privilege names gets checked at execution. This is a bit annoying
3866 * but we have little choice because of the syntactic conflict with lists
3867 * of role names in GRANT/REVOKE. What's more, we have to call out in
3868 * the "privilege" production any reserved keywords that need to be usable
3869 * as privilege names.
3872 /* either ALL [PRIVILEGES] or a list of individual privileges */
3873 privileges: privilege_list
3881 privilege_list: privilege
3882 { $$
= list_make1
(makeString
($1)); }
3883 | privilege_list
',' privilege
3884 { $$
= lappend
($1, makeString
($3)); }
3887 privilege: SELECT
{ $$
= pstrdup
($1); }
3888 | REFERENCES
{ $$
= pstrdup
($1); }
3889 | CREATE
{ $$
= pstrdup
($1); }
3890 | ColId
{ $$
= $1; }
3894 /* Don't bother trying to fold the first two rules into one using
3895 * opt_table. You're going to get conflicts.
3900 PrivTarget
*n
= makeNode
(PrivTarget
);
3901 n
->objtype
= ACL_OBJECT_RELATION
;
3905 | TABLE qualified_name_list
3907 PrivTarget
*n
= makeNode
(PrivTarget
);
3908 n
->objtype
= ACL_OBJECT_RELATION
;
3912 | SEQUENCE qualified_name_list
3914 PrivTarget
*n
= makeNode
(PrivTarget
);
3915 n
->objtype
= ACL_OBJECT_SEQUENCE
;
3919 | FUNCTION function_with_argtypes_list
3921 PrivTarget
*n
= makeNode
(PrivTarget
);
3922 n
->objtype
= ACL_OBJECT_FUNCTION
;
3926 | DATABASE name_list
3928 PrivTarget
*n
= makeNode
(PrivTarget
);
3929 n
->objtype
= ACL_OBJECT_DATABASE
;
3933 | LANGUAGE name_list
3935 PrivTarget
*n
= makeNode
(PrivTarget
);
3936 n
->objtype
= ACL_OBJECT_LANGUAGE
;
3942 PrivTarget
*n
= makeNode
(PrivTarget
);
3943 n
->objtype
= ACL_OBJECT_NAMESPACE
;
3947 | TABLESPACE name_list
3949 PrivTarget
*n
= makeNode
(PrivTarget
);
3950 n
->objtype
= ACL_OBJECT_TABLESPACE
;
3958 grantee
{ $$
= list_make1
($1); }
3959 | grantee_list
',' grantee
{ $$
= lappend
($1, $3); }
3964 PrivGrantee
*n
= makeNode
(PrivGrantee
);
3965 /* This hack lets us avoid reserving PUBLIC as a keyword*/
3966 if
(strcmp
($1, "public") == 0)
3974 PrivGrantee
*n
= makeNode
(PrivGrantee
);
3975 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
3976 if
(strcmp
($2, "public") == 0)
3985 opt_grant_grant_option:
3986 WITH GRANT OPTION
{ $$
= TRUE
; }
3987 |
/*EMPTY*/ { $$
= FALSE
; }
3990 function_with_argtypes_list:
3991 function_with_argtypes
{ $$
= list_make1
($1); }
3992 | function_with_argtypes_list
',' function_with_argtypes
3993 { $$
= lappend
($1, $3); }
3996 function_with_argtypes:
3999 FuncWithArgs
*n
= makeNode
(FuncWithArgs
);
4001 n
->funcargs
= extractArgTypes
($2);
4006 /*****************************************************************************
4008 * GRANT and REVOKE ROLE statements
4010 *****************************************************************************/
4013 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4015 GrantRoleStmt
*n
= makeNode
(GrantRoleStmt
);
4017 n
->granted_roles
= $2;
4018 n
->grantee_roles
= $4;
4026 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4028 GrantRoleStmt
*n
= makeNode
(GrantRoleStmt
);
4029 n
->is_grant
= false
;
4030 n
->admin_opt
= false
;
4031 n
->granted_roles
= $2;
4032 n
->grantee_roles
= $4;
4036 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4038 GrantRoleStmt
*n
= makeNode
(GrantRoleStmt
);
4039 n
->is_grant
= false
;
4040 n
->admin_opt
= true
;
4041 n
->granted_roles
= $5;
4042 n
->grantee_roles
= $7;
4048 opt_grant_admin_option: WITH ADMIN OPTION
{ $$
= TRUE
; }
4049 |
/*EMPTY*/ { $$
= FALSE
; }
4052 opt_granted_by: GRANTED BY RoleId
{ $$
= $3; }
4053 |
/*EMPTY*/ { $$
= NULL
; }
4057 /*****************************************************************************
4059 * QUERY: CREATE INDEX
4061 * Note: we can't factor CONCURRENTLY into a separate production without
4062 * making it a reserved word.
4064 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
4065 * willing to make TABLESPACE a fully reserved word.
4066 *****************************************************************************/
4068 IndexStmt: CREATE index_opt_unique INDEX index_name
4069 ON qualified_name access_method_clause
'(' index_params
')'
4070 opt_definition OptTableSpace where_clause
4072 IndexStmt
*n
= makeNode
(IndexStmt
);
4074 n
->concurrent
= false
;
4077 n
->accessMethod
= $7;
4078 n
->indexParams
= $9;
4080 n
->tableSpace
= $12;
4081 n
->whereClause
= $13;
4084 | CREATE index_opt_unique INDEX CONCURRENTLY index_name
4085 ON qualified_name access_method_clause
'(' index_params
')'
4086 opt_definition OptTableSpace where_clause
4088 IndexStmt
*n
= makeNode
(IndexStmt
);
4090 n
->concurrent
= true
;
4093 n
->accessMethod
= $8;
4094 n
->indexParams
= $10;
4096 n
->tableSpace
= $13;
4097 n
->whereClause
= $14;
4103 UNIQUE
{ $$
= TRUE
; }
4104 |
/*EMPTY*/ { $$
= FALSE
; }
4107 access_method_clause:
4108 USING access_method
{ $$
= $2; }
4109 |
/*EMPTY*/ { $$
= DEFAULT_INDEX_TYPE
; }
4112 index_params: index_elem
{ $$
= list_make1
($1); }
4113 | index_params
',' index_elem
{ $$
= lappend
($1, $3); }
4117 * Index attributes can be either simple column references, or arbitrary
4118 * expressions in parens. For backwards-compatibility reasons, we allow
4119 * an expression that's just a function call to be written without parens.
4121 index_elem: ColId opt_class opt_asc_desc opt_nulls_order
4123 $$
= makeNode
(IndexElem
);
4128 $$
->nulls_ordering
= $4;
4130 | func_expr opt_class opt_asc_desc opt_nulls_order
4132 $$
= makeNode
(IndexElem
);
4137 $$
->nulls_ordering
= $4;
4139 |
'(' a_expr
')' opt_class opt_asc_desc opt_nulls_order
4141 $$
= makeNode
(IndexElem
);
4146 $$
->nulls_ordering
= $6;
4150 opt_class: any_name
{ $$
= $1; }
4151 | USING any_name
{ $$
= $2; }
4152 |
/*EMPTY*/ { $$
= NIL
; }
4155 opt_asc_desc: ASC
{ $$
= SORTBY_ASC
; }
4156 | DESC
{ $$
= SORTBY_DESC
; }
4157 |
/*EMPTY*/ { $$
= SORTBY_DEFAULT
; }
4160 opt_nulls_order: NULLS_FIRST
{ $$
= SORTBY_NULLS_FIRST
; }
4161 | NULLS_LAST
{ $$
= SORTBY_NULLS_LAST
; }
4162 |
/*EMPTY*/ { $$
= SORTBY_NULLS_DEFAULT
; }
4166 /*****************************************************************************
4169 * create [or replace] function <fname>
4170 * [(<type-1> { , <type-n>})]
4172 * as <filename or code in language as appropriate>
4173 * language <lang> [with parameters]
4175 *****************************************************************************/
4178 CREATE opt_or_replace FUNCTION func_name func_args
4179 RETURNS func_return createfunc_opt_list opt_definition
4181 CreateFunctionStmt
*n
= makeNode
(CreateFunctionStmt
);
4190 | CREATE opt_or_replace FUNCTION func_name func_args
4191 RETURNS TABLE
'(' table_func_column_list
')' createfunc_opt_list opt_definition
4193 CreateFunctionStmt
*n
= makeNode
(CreateFunctionStmt
);
4196 n
->parameters
= mergeTableFuncParameters
($5, $9);
4197 n
->returnType
= TableFuncTypeName
($9);
4198 n
->returnType
->location
= @
7;
4200 n
->withClause
= $12;
4203 | CREATE opt_or_replace FUNCTION func_name func_args
4204 createfunc_opt_list opt_definition
4206 CreateFunctionStmt
*n
= makeNode
(CreateFunctionStmt
);
4210 n
->returnType
= NULL
;
4218 OR REPLACE
{ $$
= TRUE
; }
4219 |
/*EMPTY*/ { $$
= FALSE
; }
4222 func_args: '(' func_args_list
')' { $$
= $2; }
4223 |
'(' ')' { $$
= NIL
; }
4227 func_arg
{ $$
= list_make1
($1); }
4228 | func_args_list
',' func_arg
{ $$
= lappend
($1, $3); }
4232 * The style with arg_class first is SQL99 standard, but Oracle puts
4233 * param_name first; accept both since it's likely people will try both
4234 * anyway. Don't bother trying to save productions by letting arg_class
4235 * have an empty alternative ... you'll get shift/reduce conflicts.
4237 * We can catch over-specified arguments here if we want to,
4238 * but for now better to silently swallow typmod, etc.
4239 * - thomas 2000-03-22
4242 arg_class param_name func_type
4244 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4250 | param_name arg_class func_type
4252 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4258 | param_name func_type
4260 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4263 n
->mode
= FUNC_PARAM_IN
;
4266 | arg_class func_type
4268 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4276 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4279 n
->mode
= FUNC_PARAM_IN
;
4284 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
4285 arg_class: IN_P
{ $$
= FUNC_PARAM_IN
; }
4286 | OUT_P
{ $$
= FUNC_PARAM_OUT
; }
4287 | INOUT
{ $$
= FUNC_PARAM_INOUT
; }
4288 | IN_P OUT_P
{ $$
= FUNC_PARAM_INOUT
; }
4289 | VARIADIC
{ $$
= FUNC_PARAM_VARIADIC
; }
4293 * Ideally param_name should be ColId, but that causes too many conflicts.
4295 param_name: type_function_name
4301 /* We can catch over-specified results here if we want to,
4302 * but for now better to silently swallow typmod, etc.
4303 * - thomas 2000-03-22
4310 * We would like to make the %TYPE productions here be ColId attrs etc,
4311 * but that causes reduce/reduce conflicts. type_function_name
4312 * is next best choice.
4314 func_type: Typename
{ $$
= $1; }
4315 | type_function_name attrs
'%' TYPE_P
4317 $$
= makeTypeNameFromNameList
(lcons
(makeString
($1), $2));
4318 $$
->pct_type
= true
;
4321 | SETOF type_function_name attrs
'%' TYPE_P
4323 $$
= makeTypeNameFromNameList
(lcons
(makeString
($2), $3));
4324 $$
->pct_type
= true
;
4331 createfunc_opt_list:
4332 /* Must be at least one to prevent conflict */
4333 createfunc_opt_item
{ $$
= list_make1
($1); }
4334 | createfunc_opt_list createfunc_opt_item
{ $$
= lappend
($1, $2); }
4338 * Options common to both CREATE FUNCTION and ALTER FUNCTION
4340 common_func_opt_item:
4341 CALLED ON NULL_P INPUT_P
4343 $$
= makeDefElem
("strict", (Node
*)makeInteger
(FALSE
));
4345 | RETURNS NULL_P ON NULL_P INPUT_P
4347 $$
= makeDefElem
("strict", (Node
*)makeInteger
(TRUE
));
4351 $$
= makeDefElem
("strict", (Node
*)makeInteger
(TRUE
));
4355 $$
= makeDefElem
("volatility", (Node
*)makeString
("immutable"));
4359 $$
= makeDefElem
("volatility", (Node
*)makeString
("stable"));
4363 $$
= makeDefElem
("volatility", (Node
*)makeString
("volatile"));
4365 | EXTERNAL SECURITY DEFINER
4367 $$
= makeDefElem
("security", (Node
*)makeInteger
(TRUE
));
4369 | EXTERNAL SECURITY INVOKER
4371 $$
= makeDefElem
("security", (Node
*)makeInteger
(FALSE
));
4375 $$
= makeDefElem
("security", (Node
*)makeInteger
(TRUE
));
4379 $$
= makeDefElem
("security", (Node
*)makeInteger
(FALSE
));
4383 $$
= makeDefElem
("cost", (Node
*)$2);
4387 $$
= makeDefElem
("rows", (Node
*)$2);
4391 /* we abuse the normal content of a DefElem here */
4392 $$
= makeDefElem
("set", (Node
*)$1);
4396 createfunc_opt_item:
4399 $$
= makeDefElem
("as", (Node
*)$2);
4401 | LANGUAGE ColId_or_Sconst
4403 $$
= makeDefElem
("language", (Node
*)makeString
($2));
4405 | common_func_opt_item
4411 func_as: Sconst
{ $$
= list_make1
(makeString
($1)); }
4414 $$
= list_make2
(makeString
($1), makeString
($3));
4419 WITH definition
{ $$
= $2; }
4420 |
/*EMPTY*/ { $$
= NIL
; }
4423 table_func_column: param_name func_type
4425 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4428 n
->mode
= FUNC_PARAM_TABLE
;
4433 table_func_column_list:
4436 $$
= list_make1
($1);
4438 | table_func_column_list
',' table_func_column
4440 $$
= lappend
($1, $3);
4444 /*****************************************************************************
4447 * RENAME and OWNER subcommands are already provided by the generic
4448 * ALTER infrastructure, here we just specify alterations that can
4449 * only be applied to functions.
4451 *****************************************************************************/
4453 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
4455 AlterFunctionStmt
*n
= makeNode
(AlterFunctionStmt
);
4463 /* At least one option must be specified */
4464 common_func_opt_item
{ $$
= list_make1
($1); }
4465 | alterfunc_opt_list common_func_opt_item
{ $$
= lappend
($1, $2); }
4468 /* Ignored, merely for SQL compliance */
4475 /*****************************************************************************
4479 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
4480 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
4481 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
4483 *****************************************************************************/
4486 DROP FUNCTION func_name func_args opt_drop_behavior
4488 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4489 n
->kind
= OBJECT_FUNCTION
;
4491 n
->args
= extractArgTypes
($4);
4493 n
->missing_ok
= false
;
4496 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
4498 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4499 n
->kind
= OBJECT_FUNCTION
;
4501 n
->args
= extractArgTypes
($6);
4503 n
->missing_ok
= true
;
4509 DROP AGGREGATE func_name aggr_args opt_drop_behavior
4511 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4512 n
->kind
= OBJECT_AGGREGATE
;
4516 n
->missing_ok
= false
;
4519 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
4521 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4522 n
->kind
= OBJECT_AGGREGATE
;
4526 n
->missing_ok
= true
;
4532 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
4534 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4535 n
->kind
= OBJECT_OPERATOR
;
4539 n
->missing_ok
= false
;
4542 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
4544 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4545 n
->kind
= OBJECT_OPERATOR
;
4549 n
->missing_ok
= true
;
4558 (errcode
(ERRCODE_SYNTAX_ERROR
),
4559 errmsg
("missing argument"),
4560 errhint
("Use NONE to denote the missing argument of a unary operator."),
4561 scanner_errposition
(@
3)));
4563 |
'(' Typename
',' Typename
')'
4564 { $$
= list_make2
($2, $4); }
4565 |
'(' NONE
',' Typename
')' /* left unary */
4566 { $$
= list_make2
(NULL
, $4); }
4567 |
'(' Typename
',' NONE
')' /* right unary */
4568 { $$
= list_make2
($2, NULL
); }
4573 { $$
= list_make1
(makeString
($1)); }
4574 | ColId
'.' any_operator
4575 { $$
= lcons
(makeString
($1), $3); }
4579 /*****************************************************************************
4581 * CREATE CAST / DROP CAST
4583 *****************************************************************************/
4585 CreateCastStmt: CREATE CAST
'(' Typename AS Typename
')'
4586 WITH FUNCTION function_with_argtypes cast_context
4588 CreateCastStmt
*n
= makeNode
(CreateCastStmt
);
4592 n
->context
= (CoercionContext
) $11;
4596 | CREATE CAST
'(' Typename AS Typename
')'
4597 WITHOUT FUNCTION cast_context
4599 CreateCastStmt
*n
= makeNode
(CreateCastStmt
);
4603 n
->context
= (CoercionContext
) $10;
4607 | CREATE CAST
'(' Typename AS Typename
')'
4608 WITH INOUT cast_context
4610 CreateCastStmt
*n
= makeNode
(CreateCastStmt
);
4614 n
->context
= (CoercionContext
) $10;
4620 cast_context: AS IMPLICIT_P
{ $$
= COERCION_IMPLICIT
; }
4621 | AS ASSIGNMENT
{ $$
= COERCION_ASSIGNMENT
; }
4622 |
/*EMPTY*/ { $$
= COERCION_EXPLICIT
; }
4626 DropCastStmt: DROP CAST opt_if_exists
'(' Typename AS Typename
')' opt_drop_behavior
4628 DropCastStmt
*n
= makeNode
(DropCastStmt
);
4637 opt_if_exists: IF_P EXISTS
{ $$
= TRUE
; }
4638 |
/*EMPTY*/ { $$
= FALSE
; }
4642 /*****************************************************************************
4646 * REINDEX type <name> [FORCE]
4648 * FORCE no longer does anything, but we accept it for backwards compatibility
4649 *****************************************************************************/
4652 REINDEX reindex_type qualified_name opt_force
4654 ReindexStmt
*n
= makeNode
(ReindexStmt
);
4660 | REINDEX SYSTEM_P name opt_force
4662 ReindexStmt
*n
= makeNode
(ReindexStmt
);
4663 n
->kind
= OBJECT_DATABASE
;
4666 n
->do_system
= true
;
4670 | REINDEX DATABASE name opt_force
4672 ReindexStmt
*n
= makeNode
(ReindexStmt
);
4673 n
->kind
= OBJECT_DATABASE
;
4676 n
->do_system
= true
;
4683 INDEX
{ $$
= OBJECT_INDEX
; }
4684 | TABLE
{ $$
= OBJECT_TABLE
; }
4687 opt_force: FORCE
{ $$
= TRUE
; }
4688 |
/* EMPTY */ { $$
= FALSE
; }
4692 /*****************************************************************************
4694 * ALTER THING name RENAME TO newname
4696 *****************************************************************************/
4698 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
4700 RenameStmt
*n
= makeNode
(RenameStmt
);
4701 n
->renameType
= OBJECT_AGGREGATE
;
4707 | ALTER CONVERSION_P any_name RENAME TO name
4709 RenameStmt
*n
= makeNode
(RenameStmt
);
4710 n
->renameType
= OBJECT_CONVERSION
;
4715 | ALTER DATABASE database_name RENAME TO database_name
4717 RenameStmt
*n
= makeNode
(RenameStmt
);
4718 n
->renameType
= OBJECT_DATABASE
;
4723 | ALTER FUNCTION function_with_argtypes RENAME TO name
4725 RenameStmt
*n
= makeNode
(RenameStmt
);
4726 n
->renameType
= OBJECT_FUNCTION
;
4727 n
->object
= $3->funcname
;
4728 n
->objarg
= $3->funcargs
;
4732 | ALTER GROUP_P RoleId RENAME TO RoleId
4734 RenameStmt
*n
= makeNode
(RenameStmt
);
4735 n
->renameType
= OBJECT_ROLE
;
4740 | ALTER opt_procedural LANGUAGE name RENAME TO name
4742 RenameStmt
*n
= makeNode
(RenameStmt
);
4743 n
->renameType
= OBJECT_LANGUAGE
;
4748 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
4750 RenameStmt
*n
= makeNode
(RenameStmt
);
4751 n
->renameType
= OBJECT_OPCLASS
;
4757 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
4759 RenameStmt
*n
= makeNode
(RenameStmt
);
4760 n
->renameType
= OBJECT_OPFAMILY
;
4766 | ALTER SCHEMA name RENAME TO name
4768 RenameStmt
*n
= makeNode
(RenameStmt
);
4769 n
->renameType
= OBJECT_SCHEMA
;
4774 | ALTER TABLE relation_expr RENAME TO name
4776 RenameStmt
*n
= makeNode
(RenameStmt
);
4777 n
->renameType
= OBJECT_TABLE
;
4783 | ALTER SEQUENCE relation_expr RENAME TO name
4785 RenameStmt
*n
= makeNode
(RenameStmt
);
4786 n
->renameType
= OBJECT_SEQUENCE
;
4792 | ALTER VIEW relation_expr RENAME TO name
4794 RenameStmt
*n
= makeNode
(RenameStmt
);
4795 n
->renameType
= OBJECT_VIEW
;
4801 | ALTER INDEX relation_expr RENAME TO name
4803 RenameStmt
*n
= makeNode
(RenameStmt
);
4804 n
->renameType
= OBJECT_INDEX
;
4810 | ALTER TABLE relation_expr RENAME opt_column name TO name
4812 RenameStmt
*n
= makeNode
(RenameStmt
);
4813 n
->renameType
= OBJECT_COLUMN
;
4819 | ALTER TRIGGER name ON relation_expr RENAME TO name
4821 RenameStmt
*n
= makeNode
(RenameStmt
);
4822 n
->renameType
= OBJECT_TRIGGER
;
4828 | ALTER ROLE RoleId RENAME TO RoleId
4830 RenameStmt
*n
= makeNode
(RenameStmt
);
4831 n
->renameType
= OBJECT_ROLE
;
4836 | ALTER USER RoleId RENAME TO RoleId
4838 RenameStmt
*n
= makeNode
(RenameStmt
);
4839 n
->renameType
= OBJECT_ROLE
;
4844 | ALTER TABLESPACE name RENAME TO name
4846 RenameStmt
*n
= makeNode
(RenameStmt
);
4847 n
->renameType
= OBJECT_TABLESPACE
;
4852 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
4854 RenameStmt
*n
= makeNode
(RenameStmt
);
4855 n
->renameType
= OBJECT_TSPARSER
;
4860 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
4862 RenameStmt
*n
= makeNode
(RenameStmt
);
4863 n
->renameType
= OBJECT_TSDICTIONARY
;
4868 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
4870 RenameStmt
*n
= makeNode
(RenameStmt
);
4871 n
->renameType
= OBJECT_TSTEMPLATE
;
4876 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
4878 RenameStmt
*n
= makeNode
(RenameStmt
);
4879 n
->renameType
= OBJECT_TSCONFIGURATION
;
4884 | ALTER TYPE_P any_name RENAME TO name
4886 RenameStmt
*n
= makeNode
(RenameStmt
);
4887 n
->renameType
= OBJECT_TYPE
;
4894 opt_column: COLUMN
{ $$
= COLUMN
; }
4895 |
/*EMPTY*/ { $$
= 0; }
4898 opt_set_data: SET DATA_P
{ $$
= 1; }
4899 |
/*EMPTY*/ { $$
= 0; }
4902 /*****************************************************************************
4904 * ALTER THING name SET SCHEMA name
4906 *****************************************************************************/
4908 AlterObjectSchemaStmt:
4909 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
4911 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4912 n
->objectType
= OBJECT_AGGREGATE
;
4918 | ALTER DOMAIN_P any_name SET SCHEMA name
4920 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4921 n
->objectType
= OBJECT_DOMAIN
;
4926 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
4928 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4929 n
->objectType
= OBJECT_FUNCTION
;
4930 n
->object
= $3->funcname
;
4931 n
->objarg
= $3->funcargs
;
4935 | ALTER TABLE relation_expr SET SCHEMA name
4937 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4938 n
->objectType
= OBJECT_TABLE
;
4943 | ALTER SEQUENCE relation_expr SET SCHEMA name
4945 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4946 n
->objectType
= OBJECT_SEQUENCE
;
4951 | ALTER VIEW relation_expr SET SCHEMA name
4953 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4954 n
->objectType
= OBJECT_VIEW
;
4959 | ALTER TYPE_P any_name SET SCHEMA name
4961 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
4962 n
->objectType
= OBJECT_TYPE
;
4969 /*****************************************************************************
4971 * ALTER THING name OWNER TO newname
4973 *****************************************************************************/
4975 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
4977 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
4978 n
->objectType
= OBJECT_AGGREGATE
;
4984 | ALTER CONVERSION_P any_name OWNER TO RoleId
4986 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
4987 n
->objectType
= OBJECT_CONVERSION
;
4992 | ALTER DATABASE database_name OWNER TO RoleId
4994 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
4995 n
->objectType
= OBJECT_DATABASE
;
4996 n
->object
= list_make1
(makeString
($3));
5000 | ALTER DOMAIN_P any_name OWNER TO RoleId
5002 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5003 n
->objectType
= OBJECT_DOMAIN
;
5008 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
5010 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5011 n
->objectType
= OBJECT_FUNCTION
;
5012 n
->object
= $3->funcname
;
5013 n
->objarg
= $3->funcargs
;
5017 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
5019 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5020 n
->objectType
= OBJECT_LANGUAGE
;
5021 n
->object
= list_make1
(makeString
($4));
5025 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
5027 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5028 n
->objectType
= OBJECT_OPERATOR
;
5034 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
5036 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5037 n
->objectType
= OBJECT_OPCLASS
;
5043 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
5045 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5046 n
->objectType
= OBJECT_OPFAMILY
;
5052 | ALTER SCHEMA name OWNER TO RoleId
5054 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5055 n
->objectType
= OBJECT_SCHEMA
;
5056 n
->object
= list_make1
(makeString
($3));
5060 | ALTER TYPE_P any_name OWNER TO RoleId
5062 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5063 n
->objectType
= OBJECT_TYPE
;
5068 | ALTER TABLESPACE name OWNER TO RoleId
5070 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5071 n
->objectType
= OBJECT_TABLESPACE
;
5072 n
->object
= list_make1
(makeString
($3));
5076 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
5078 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5079 n
->objectType
= OBJECT_TSDICTIONARY
;
5084 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
5086 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5087 n
->objectType
= OBJECT_TSCONFIGURATION
;
5095 /*****************************************************************************
5097 * QUERY: Define Rewrite Rule
5099 *****************************************************************************/
5101 RuleStmt: CREATE opt_or_replace RULE name AS
5102 { QueryIsRule
=TRUE
; }
5103 ON event TO qualified_name where_clause
5104 DO opt_instead RuleActionList
5106 RuleStmt
*n
= makeNode
(RuleStmt
);
5110 n
->whereClause
= $11;
5120 NOTHING
{ $$
= NIL
; }
5121 | RuleActionStmt
{ $$
= list_make1
($1); }
5122 |
'(' RuleActionMulti
')' { $$
= $2; }
5125 /* the thrashing around here is to discard "empty" statements... */
5127 RuleActionMulti
';' RuleActionStmtOrEmpty
5129 $$
= lappend
($1, $3);
5133 | RuleActionStmtOrEmpty
5135 $$
= list_make1
($1);
5149 RuleActionStmtOrEmpty:
5150 RuleActionStmt
{ $$
= $1; }
5151 |
/*EMPTY*/ { $$
= NULL
; }
5154 event: SELECT
{ $$
= CMD_SELECT
; }
5155 | UPDATE
{ $$
= CMD_UPDATE
; }
5156 | DELETE_P
{ $$
= CMD_DELETE
; }
5157 | INSERT
{ $$
= CMD_INSERT
; }
5161 INSTEAD
{ $$
= TRUE
; }
5162 | ALSO
{ $$
= FALSE
; }
5163 |
/*EMPTY*/ { $$
= FALSE
; }
5168 DROP RULE name ON qualified_name opt_drop_behavior
5170 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
5174 n
->removeType
= OBJECT_RULE
;
5175 n
->missing_ok
= false
;
5178 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
5180 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
5184 n
->removeType
= OBJECT_RULE
;
5185 n
->missing_ok
= true
;
5191 /*****************************************************************************
5194 * NOTIFY <identifier> can appear both in rule bodies and
5195 * as a query-level command
5197 *****************************************************************************/
5199 NotifyStmt: NOTIFY ColId
5201 NotifyStmt
*n
= makeNode
(NotifyStmt
);
5202 n
->conditionname
= $2;
5207 ListenStmt: LISTEN ColId
5209 ListenStmt
*n
= makeNode
(ListenStmt
);
5210 n
->conditionname
= $2;
5218 UnlistenStmt
*n
= makeNode
(UnlistenStmt
);
5219 n
->conditionname
= $2;
5224 UnlistenStmt
*n
= makeNode
(UnlistenStmt
);
5225 n
->conditionname
= NULL
;
5231 /*****************************************************************************
5235 * BEGIN / COMMIT / ROLLBACK
5236 * (also older versions END / ABORT)
5238 *****************************************************************************/
5241 ABORT_P opt_transaction
5243 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5244 n
->kind
= TRANS_STMT_ROLLBACK
;
5248 | BEGIN_P opt_transaction transaction_mode_list_or_empty
5250 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5251 n
->kind
= TRANS_STMT_BEGIN
;
5255 | START TRANSACTION transaction_mode_list_or_empty
5257 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5258 n
->kind
= TRANS_STMT_START
;
5262 | COMMIT opt_transaction
5264 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5265 n
->kind
= TRANS_STMT_COMMIT
;
5269 | END_P opt_transaction
5271 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5272 n
->kind
= TRANS_STMT_COMMIT
;
5276 | ROLLBACK opt_transaction
5278 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5279 n
->kind
= TRANS_STMT_ROLLBACK
;
5285 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5286 n
->kind
= TRANS_STMT_SAVEPOINT
;
5287 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5288 (Node
*)makeString
($2)));
5291 | RELEASE SAVEPOINT ColId
5293 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5294 n
->kind
= TRANS_STMT_RELEASE
;
5295 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5296 (Node
*)makeString
($3)));
5301 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5302 n
->kind
= TRANS_STMT_RELEASE
;
5303 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5304 (Node
*)makeString
($2)));
5307 | ROLLBACK opt_transaction TO SAVEPOINT ColId
5309 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5310 n
->kind
= TRANS_STMT_ROLLBACK_TO
;
5311 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5312 (Node
*)makeString
($5)));
5315 | ROLLBACK opt_transaction TO ColId
5317 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5318 n
->kind
= TRANS_STMT_ROLLBACK_TO
;
5319 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5320 (Node
*)makeString
($4)));
5323 | PREPARE TRANSACTION Sconst
5325 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5326 n
->kind
= TRANS_STMT_PREPARE
;
5330 | COMMIT PREPARED Sconst
5332 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5333 n
->kind
= TRANS_STMT_COMMIT_PREPARED
;
5337 | ROLLBACK PREPARED Sconst
5339 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5340 n
->kind
= TRANS_STMT_ROLLBACK_PREPARED
;
5346 opt_transaction: WORK
{}
5351 transaction_mode_item:
5352 ISOLATION LEVEL iso_level
5353 { $$
= makeDefElem
("transaction_isolation",
5354 makeStringConst
($3, @
3)); }
5356 { $$
= makeDefElem
("transaction_read_only",
5357 makeIntConst
(TRUE
, @
1)); }
5359 { $$
= makeDefElem
("transaction_read_only",
5360 makeIntConst
(FALSE
, @
1)); }
5363 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
5364 transaction_mode_list:
5365 transaction_mode_item
5366 { $$
= list_make1
($1); }
5367 | transaction_mode_list
',' transaction_mode_item
5368 { $$
= lappend
($1, $3); }
5369 | transaction_mode_list transaction_mode_item
5370 { $$
= lappend
($1, $2); }
5373 transaction_mode_list_or_empty:
5374 transaction_mode_list
5380 /*****************************************************************************
5383 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
5384 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
5386 *****************************************************************************/
5388 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
5389 AS SelectStmt opt_check_option
5391 ViewStmt
*n
= makeNode
(ViewStmt
);
5393 n
->view
->istemp
= $2;
5399 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
5400 AS SelectStmt opt_check_option
5402 ViewStmt
*n
= makeNode
(ViewStmt
);
5404 n
->view
->istemp
= $4;
5416 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
5417 errmsg
("WITH CHECK OPTION is not implemented")));
5419 | WITH CASCADED CHECK OPTION
5422 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
5423 errmsg
("WITH CHECK OPTION is not implemented")));
5425 | WITH LOCAL CHECK OPTION
5428 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
5429 errmsg
("WITH CHECK OPTION is not implemented")));
5431 |
/* EMPTY */ { $$
= NIL
; }
5434 /*****************************************************************************
5439 *****************************************************************************/
5441 LoadStmt: LOAD file_name
5443 LoadStmt
*n
= makeNode
(LoadStmt
);
5450 /*****************************************************************************
5454 *****************************************************************************/
5457 CREATE DATABASE database_name opt_with createdb_opt_list
5459 CreatedbStmt
*n
= makeNode
(CreatedbStmt
);
5467 createdb_opt_list createdb_opt_item
{ $$
= lappend
($1, $2); }
5468 |
/* EMPTY */ { $$
= NIL
; }
5472 TABLESPACE opt_equal name
5474 $$
= makeDefElem
("tablespace", (Node
*)makeString
($3));
5476 | TABLESPACE opt_equal DEFAULT
5478 $$
= makeDefElem
("tablespace", NULL
);
5480 | LOCATION opt_equal Sconst
5482 $$
= makeDefElem
("location", (Node
*)makeString
($3));
5484 | LOCATION opt_equal DEFAULT
5486 $$
= makeDefElem
("location", NULL
);
5488 | TEMPLATE opt_equal name
5490 $$
= makeDefElem
("template", (Node
*)makeString
($3));
5492 | TEMPLATE opt_equal DEFAULT
5494 $$
= makeDefElem
("template", NULL
);
5496 | ENCODING opt_equal Sconst
5498 $$
= makeDefElem
("encoding", (Node
*)makeString
($3));
5500 | ENCODING opt_equal Iconst
5502 $$
= makeDefElem
("encoding", (Node
*)makeInteger
($3));
5504 | ENCODING opt_equal DEFAULT
5506 $$
= makeDefElem
("encoding", NULL
);
5508 | COLLATE opt_equal Sconst
5510 $$
= makeDefElem
("collate", (Node
*)makeString
($3));
5512 | COLLATE opt_equal DEFAULT
5514 $$
= makeDefElem
("collate", NULL
);
5516 | CTYPE opt_equal Sconst
5518 $$
= makeDefElem
("ctype", (Node
*)makeString
($3));
5520 | CTYPE opt_equal DEFAULT
5522 $$
= makeDefElem
("ctype", NULL
);
5524 | CONNECTION LIMIT opt_equal SignedIconst
5526 $$
= makeDefElem
("connectionlimit", (Node
*)makeInteger
($4));
5528 | OWNER opt_equal name
5530 $$
= makeDefElem
("owner", (Node
*)makeString
($3));
5532 | OWNER opt_equal DEFAULT
5534 $$
= makeDefElem
("owner", NULL
);
5539 * Though the equals sign doesn't match other WITH options, pg_dump uses
5540 * equals for backward compatibility, and it doesn't seem worth removing it.
5547 /*****************************************************************************
5551 *****************************************************************************/
5554 ALTER DATABASE database_name opt_with alterdb_opt_list
5556 AlterDatabaseStmt
*n
= makeNode
(AlterDatabaseStmt
);
5563 AlterDatabaseSetStmt:
5564 ALTER DATABASE database_name SetResetClause
5566 AlterDatabaseSetStmt
*n
= makeNode
(AlterDatabaseSetStmt
);
5575 alterdb_opt_list alterdb_opt_item
{ $$
= lappend
($1, $2); }
5576 |
/* EMPTY */ { $$
= NIL
; }
5580 CONNECTION LIMIT opt_equal SignedIconst
5582 $$
= makeDefElem
("connectionlimit", (Node
*)makeInteger
($4));
5587 /*****************************************************************************
5589 * DROP DATABASE [ IF EXISTS ]
5591 * This is implicitly CASCADE, no need for drop behavior
5592 *****************************************************************************/
5594 DropdbStmt: DROP DATABASE database_name
5596 DropdbStmt
*n
= makeNode
(DropdbStmt
);
5598 n
->missing_ok
= FALSE
;
5601 | DROP DATABASE IF_P EXISTS database_name
5603 DropdbStmt
*n
= makeNode
(DropdbStmt
);
5605 n
->missing_ok
= TRUE
;
5611 /*****************************************************************************
5613 * Manipulate a domain
5615 *****************************************************************************/
5618 CREATE DOMAIN_P any_name opt_as Typename ColQualList
5620 CreateDomainStmt
*n
= makeNode
(CreateDomainStmt
);
5623 n
->constraints
= $6;
5629 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
5630 ALTER DOMAIN_P any_name alter_column_default
5632 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
5638 /* ALTER DOMAIN <domain> DROP NOT NULL */
5639 | ALTER DOMAIN_P any_name DROP NOT NULL_P
5641 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
5646 /* ALTER DOMAIN <domain> SET NOT NULL */
5647 | ALTER DOMAIN_P any_name SET NOT NULL_P
5649 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
5654 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
5655 | ALTER DOMAIN_P any_name ADD_P TableConstraint
5657 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
5663 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
5664 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
5666 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
5680 /*****************************************************************************
5682 * Manipulate a text search dictionary or configuration
5684 *****************************************************************************/
5686 AlterTSDictionaryStmt:
5687 ALTER TEXT_P SEARCH DICTIONARY any_name definition
5689 AlterTSDictionaryStmt
*n
= makeNode
(AlterTSDictionaryStmt
);
5696 AlterTSConfigurationStmt:
5697 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
5699 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5703 n
->override
= false
;
5707 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
5709 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5717 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
5719 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5722 n
->dicts
= list_make2
($9,$11);
5723 n
->override
= false
;
5727 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
5729 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5732 n
->dicts
= list_make2
($11,$13);
5733 n
->override
= false
;
5737 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
5739 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5742 n
->missing_ok
= false
;
5745 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
5747 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
5750 n
->missing_ok
= true
;
5756 /*****************************************************************************
5758 * Manipulate a conversion
5760 * CREATE [DEFAULT] CONVERSION <conversion_name>
5761 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
5763 *****************************************************************************/
5765 CreateConversionStmt:
5766 CREATE opt_default CONVERSION_P any_name FOR Sconst
5767 TO Sconst FROM any_name
5769 CreateConversionStmt
*n
= makeNode
(CreateConversionStmt
);
5770 n
->conversion_name
= $4;
5771 n
->for_encoding_name
= $6;
5772 n
->to_encoding_name
= $8;
5779 /*****************************************************************************
5782 * CLUSTER <qualified_name> [ USING <index_name> ]
5784 * CLUSTER <index_name> ON <qualified_name> (for pre-8.3)
5786 *****************************************************************************/
5789 CLUSTER qualified_name cluster_index_specification
5791 ClusterStmt
*n
= makeNode
(ClusterStmt
);
5798 ClusterStmt
*n
= makeNode
(ClusterStmt
);
5800 n
->indexname
= NULL
;
5803 /* kept for pre-8.3 compatibility */
5804 | CLUSTER index_name ON qualified_name
5806 ClusterStmt
*n
= makeNode
(ClusterStmt
);
5813 cluster_index_specification:
5814 USING index_name
{ $$
= $2; }
5815 |
/*EMPTY*/ { $$
= NULL
; }
5819 /*****************************************************************************
5825 *****************************************************************************/
5827 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
5829 VacuumStmt
*n
= makeNode
(VacuumStmt
);
5833 n
->freeze_min_age
= $3 ?
0 : -1;
5839 | VACUUM opt_full opt_freeze opt_verbose qualified_name
5841 VacuumStmt
*n
= makeNode
(VacuumStmt
);
5845 n
->freeze_min_age
= $3 ?
0 : -1;
5851 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
5853 VacuumStmt
*n
= (VacuumStmt
*) $5;
5856 n
->freeze_min_age
= $3 ?
0 : -1;
5863 analyze_keyword opt_verbose
5865 VacuumStmt
*n
= makeNode
(VacuumStmt
);
5869 n
->freeze_min_age
= -1;
5875 | analyze_keyword opt_verbose qualified_name opt_name_list
5877 VacuumStmt
*n
= makeNode
(VacuumStmt
);
5881 n
->freeze_min_age
= -1;
5891 | ANALYSE
/* British */ {}
5895 VERBOSE
{ $$
= TRUE
; }
5896 |
/*EMPTY*/ { $$
= FALSE
; }
5899 opt_full: FULL
{ $$
= TRUE
; }
5900 |
/*EMPTY*/ { $$
= FALSE
; }
5903 opt_freeze: FREEZE
{ $$
= TRUE
; }
5904 |
/*EMPTY*/ { $$
= FALSE
; }
5908 '(' name_list
')' { $$
= $2; }
5909 |
/*EMPTY*/ { $$
= NIL
; }
5913 /*****************************************************************************
5916 * EXPLAIN [ANALYZE] [VERBOSE] query
5918 *****************************************************************************/
5920 ExplainStmt: EXPLAIN opt_analyze opt_verbose ExplainableStmt
5922 ExplainStmt
*n
= makeNode
(ExplainStmt
);
5937 | ExecuteStmt
/* by default all are $$=$1 */
5941 analyze_keyword
{ $$
= TRUE
; }
5942 |
/* EMPTY */ { $$
= FALSE
; }
5945 /*****************************************************************************
5948 * PREPARE <plan_name> [(args, ...)] AS <query>
5950 *****************************************************************************/
5952 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
5954 PrepareStmt
*n
= makeNode
(PrepareStmt
);
5962 prep_type_clause: '(' type_list
')' { $$
= $2; }
5963 |
/* EMPTY */ { $$
= NIL
; }
5970 | DeleteStmt
/* by default all are $$=$1 */
5973 /*****************************************************************************
5975 * EXECUTE <plan_name> [(params, ...)]
5976 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
5978 *****************************************************************************/
5980 ExecuteStmt: EXECUTE name execute_param_clause
5982 ExecuteStmt
*n
= makeNode
(ExecuteStmt
);
5988 | CREATE OptTemp TABLE create_as_target AS
5989 EXECUTE name execute_param_clause
5991 ExecuteStmt
*n
= makeNode
(ExecuteStmt
);
5994 $4->rel
->istemp
= $2;
5998 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
5999 errmsg
("column name list not allowed in CREATE TABLE / AS EXECUTE")));
6000 /* ... because it's not implemented, but it could be */
6005 execute_param_clause: '(' expr_list
')' { $$
= $2; }
6006 |
/* EMPTY */ { $$
= NIL
; }
6009 /*****************************************************************************
6012 * DEALLOCATE [PREPARE] <plan_name>
6014 *****************************************************************************/
6016 DeallocateStmt: DEALLOCATE name
6018 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
6022 | DEALLOCATE PREPARE name
6024 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
6030 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
6034 | DEALLOCATE PREPARE ALL
6036 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
6042 /*****************************************************************************
6047 *****************************************************************************/
6050 INSERT INTO qualified_name insert_rest returning_clause
6053 $4->returningList
= $5;
6061 $$
= makeNode
(InsertStmt
);
6063 $$
->selectStmt
= $1;
6065 |
'(' insert_column_list
')' SelectStmt
6067 $$
= makeNode
(InsertStmt
);
6069 $$
->selectStmt
= $4;
6073 $$
= makeNode
(InsertStmt
);
6075 $$
->selectStmt
= NULL
;
6081 { $$
= list_make1
($1); }
6082 | insert_column_list
',' insert_column_item
6083 { $$
= lappend
($1, $3); }
6087 ColId opt_indirection
6089 $$
= makeNode
(ResTarget
);
6091 $$
->indirection
= check_indirection
($2);
6098 RETURNING target_list
{ $$
= $2; }
6099 |
/* EMPTY */ { $$
= NIL
; }
6103 /*****************************************************************************
6108 *****************************************************************************/
6110 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
6111 using_clause where_or_current_clause returning_clause
6113 DeleteStmt
*n
= makeNode
(DeleteStmt
);
6115 n
->usingClause
= $4;
6116 n
->whereClause
= $5;
6117 n
->returningList
= $6;
6123 USING from_list
{ $$
= $2; }
6124 |
/*EMPTY*/ { $$
= NIL
; }
6127 LockStmt: LOCK_P opt_table qualified_name_list opt_lock opt_nowait
6129 LockStmt
*n
= makeNode
(LockStmt
);
6138 opt_lock: IN_P lock_type MODE
{ $$
= $2; }
6139 |
/*EMPTY*/ { $$
= AccessExclusiveLock
; }
6142 lock_type: ACCESS SHARE
{ $$
= AccessShareLock
; }
6143 | ROW SHARE
{ $$
= RowShareLock
; }
6144 | ROW EXCLUSIVE
{ $$
= RowExclusiveLock
; }
6145 | SHARE UPDATE EXCLUSIVE
{ $$
= ShareUpdateExclusiveLock
; }
6146 | SHARE
{ $$
= ShareLock
; }
6147 | SHARE ROW EXCLUSIVE
{ $$
= ShareRowExclusiveLock
; }
6148 | EXCLUSIVE
{ $$
= ExclusiveLock
; }
6149 | ACCESS EXCLUSIVE
{ $$
= AccessExclusiveLock
; }
6152 opt_nowait: NOWAIT
{ $$
= TRUE
; }
6153 |
/*EMPTY*/ { $$
= FALSE
; }
6157 /*****************************************************************************
6160 * UpdateStmt (UPDATE)
6162 *****************************************************************************/
6164 UpdateStmt: UPDATE relation_expr_opt_alias
6167 where_or_current_clause
6170 UpdateStmt
*n
= makeNode
(UpdateStmt
);
6174 n
->whereClause
= $6;
6175 n
->returningList
= $7;
6181 set_clause
{ $$
= $1; }
6182 | set_clause_list
',' set_clause
{ $$
= list_concat
($1,$3); }
6186 single_set_clause
{ $$
= list_make1
($1); }
6187 | multiple_set_clause
{ $$
= $1; }
6191 set_target
'=' ctext_expr
6194 $$
->val
= (Node
*) $3;
6198 multiple_set_clause:
6199 '(' set_target_list
')' '=' ctext_row
6205 * Break the ctext_row apart, merge individual expressions
6206 * into the destination ResTargets. XXX this approach
6207 * cannot work for general row expressions as sources.
6209 if
(list_length
($2) != list_length
($5))
6211 (errcode
(ERRCODE_SYNTAX_ERROR
),
6212 errmsg
("number of columns does not match number of values"),
6213 scanner_errposition
(@
1)));
6214 forboth
(col_cell
, $2, val_cell
, $5)
6216 ResTarget
*res_col
= (ResTarget
*) lfirst
(col_cell
);
6217 Node
*res_val
= (Node
*) lfirst
(val_cell
);
6219 res_col
->val
= res_val
;
6227 ColId opt_indirection
6229 $$
= makeNode
(ResTarget
);
6231 $$
->indirection
= check_indirection
($2);
6232 $$
->val
= NULL
; /* upper production sets this */
6238 set_target
{ $$
= list_make1
($1); }
6239 | set_target_list
',' set_target
{ $$
= lappend
($1,$3); }
6243 /*****************************************************************************
6248 *****************************************************************************/
6249 DeclareCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR SelectStmt
6251 DeclareCursorStmt
*n
= makeNode
(DeclareCursorStmt
);
6253 /* currently we always set FAST_PLAN option */
6254 n
->options
= $3 |
$5 | CURSOR_OPT_FAST_PLAN
;
6260 cursor_options: /*EMPTY*/ { $$
= 0; }
6261 | cursor_options NO SCROLL
{ $$
= $1 | CURSOR_OPT_NO_SCROLL
; }
6262 | cursor_options SCROLL
{ $$
= $1 | CURSOR_OPT_SCROLL
; }
6263 | cursor_options BINARY
{ $$
= $1 | CURSOR_OPT_BINARY
; }
6264 | cursor_options INSENSITIVE
{ $$
= $1 | CURSOR_OPT_INSENSITIVE
; }
6267 opt_hold: /* EMPTY */ { $$
= 0; }
6268 | WITH HOLD
{ $$
= CURSOR_OPT_HOLD
; }
6269 | WITHOUT HOLD
{ $$
= 0; }
6272 /*****************************************************************************
6277 *****************************************************************************/
6279 /* A complete SELECT statement looks like this.
6281 * The rule returns either a single SelectStmt node or a tree of them,
6282 * representing a set-operation tree.
6284 * There is an ambiguity when a sub-SELECT is within an a_expr and there
6285 * are excess parentheses: do the parentheses belong to the sub-SELECT or
6286 * to the surrounding a_expr? We don't really care, but yacc wants to know.
6287 * To resolve the ambiguity, we are careful to define the grammar so that
6288 * the decision is staved off as long as possible: as long as we can keep
6289 * absorbing parentheses into the sub-SELECT, we will do so, and only when
6290 * it's no longer possible to do that will we decide that parens belong to
6291 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
6292 * parentheses are treated as part of the sub-select. The necessity of doing
6293 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
6294 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
6295 * SELECT viewpoint when we see the UNION.
6297 * This approach is implemented by defining a nonterminal select_with_parens,
6298 * which represents a SELECT with at least one outer layer of parentheses,
6299 * and being careful to use select_with_parens, never '(' SelectStmt ')',
6300 * in the expression grammar. We will then have shift-reduce conflicts
6301 * which we can resolve in favor of always treating '(' <select> ')' as
6302 * a select_with_parens. To resolve the conflicts, the productions that
6303 * conflict with the select_with_parens productions are manually given
6304 * precedences lower than the precedence of ')', thereby ensuring that we
6305 * shift ')' (and then reduce to select_with_parens) rather than trying to
6306 * reduce the inner <select> nonterminal to something else. We use UMINUS
6307 * precedence for this, which is a fairly arbitrary choice.
6309 * To be able to define select_with_parens itself without ambiguity, we need
6310 * a nonterminal select_no_parens that represents a SELECT structure with no
6311 * outermost parentheses. This is a little bit tedious, but it works.
6313 * In non-expression contexts, we use SelectStmt which can represent a SELECT
6314 * with or without outer parentheses.
6317 SelectStmt: select_no_parens %prec UMINUS
6318 | select_with_parens %prec UMINUS
6322 '(' select_no_parens
')' { $$
= $2; }
6323 |
'(' select_with_parens
')' { $$
= $2; }
6327 * This rule parses the equivalent of the standard's <query expression>.
6328 * The duplicative productions are annoying, but hard to get rid of without
6329 * creating shift/reduce conflicts.
6331 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
6332 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
6333 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
6337 simple_select
{ $$
= $1; }
6338 | select_clause sort_clause
6340 insertSelectOptions
((SelectStmt
*) $1, $2, NIL
,
6344 | select_clause opt_sort_clause for_locking_clause opt_select_limit
6346 insertSelectOptions
((SelectStmt
*) $1, $2, $3,
6347 list_nth
($4, 0), list_nth
($4, 1),
6351 | select_clause opt_sort_clause select_limit opt_for_locking_clause
6353 insertSelectOptions
((SelectStmt
*) $1, $2, $4,
6354 list_nth
($3, 0), list_nth
($3, 1),
6358 | with_clause simple_select
6360 insertSelectOptions
((SelectStmt
*) $2, NULL
, NIL
,
6365 | with_clause select_clause sort_clause
6367 insertSelectOptions
((SelectStmt
*) $2, $3, NIL
,
6372 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
6374 insertSelectOptions
((SelectStmt
*) $2, $3, $4,
6375 list_nth
($5, 0), list_nth
($5, 1),
6379 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
6381 insertSelectOptions
((SelectStmt
*) $2, $3, $5,
6382 list_nth
($4, 0), list_nth
($4, 1),
6389 simple_select
{ $$
= $1; }
6390 | select_with_parens
{ $$
= $1; }
6394 * This rule parses SELECT statements that can appear within set operations,
6395 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
6396 * the ordering of the set operations. Without '(' and ')' we want the
6397 * operations to be ordered per the precedence specs at the head of this file.
6399 * As with select_no_parens, simple_select cannot have outer parentheses,
6400 * but can have parenthesized subclauses.
6402 * Note that sort clauses cannot be included at this level --- SQL92 requires
6403 * SELECT foo UNION SELECT bar ORDER BY baz
6405 * (SELECT foo UNION SELECT bar) ORDER BY baz
6407 * SELECT foo UNION (SELECT bar ORDER BY baz)
6408 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
6409 * described as part of the select_no_parens production, not simple_select.
6410 * This does not limit functionality, because you can reintroduce these
6411 * clauses inside parentheses.
6413 * NOTE: only the leftmost component SelectStmt should have INTO.
6414 * However, this is not checked by the grammar; parse analysis must check it.
6417 SELECT opt_distinct target_list
6418 into_clause from_clause where_clause
6419 group_clause having_clause
6421 SelectStmt
*n
= makeNode
(SelectStmt
);
6422 n
->distinctClause
= $2;
6426 n
->whereClause
= $6;
6427 n
->groupClause
= $7;
6428 n
->havingClause
= $8;
6431 | values_clause
{ $$
= $1; }
6432 | select_clause UNION opt_all select_clause
6434 $$
= makeSetOp
(SETOP_UNION
, $3, $1, $4);
6436 | select_clause INTERSECT opt_all select_clause
6438 $$
= makeSetOp
(SETOP_INTERSECT
, $3, $1, $4);
6440 | select_clause EXCEPT opt_all select_clause
6442 $$
= makeSetOp
(SETOP_EXCEPT
, $3, $1, $4);
6447 * SQL standard WITH clause looks like:
6449 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
6450 * AS (query) [ SEARCH or CYCLE clause ]
6452 * We don't currently support the SEARCH or CYCLE clause.
6457 $$
= makeNode
(WithClause
);
6459 $$
->recursive
= false
;
6462 | WITH RECURSIVE cte_list
6464 $$
= makeNode
(WithClause
);
6466 $$
->recursive
= true
;
6472 common_table_expr
{ $$
= list_make1
($1); }
6473 | cte_list
',' common_table_expr
{ $$
= lappend
($1, $3); }
6476 common_table_expr: name opt_name_list AS select_with_parens
6478 CommonTableExpr
*n
= makeNode
(CommonTableExpr
);
6480 n
->aliascolnames
= $2;
6488 INTO OptTempTableName
6490 $$
= makeNode
(IntoClause
);
6494 $$
->onCommit
= ONCOMMIT_NOOP
;
6495 $$
->tableSpaceName
= NULL
;
6502 * Redundancy here is needed to avoid shift/reduce conflicts,
6503 * since TEMP is not a reserved word. See also OptTemp.
6506 TEMPORARY opt_table qualified_name
6511 | TEMP opt_table qualified_name
6516 | LOCAL TEMPORARY opt_table qualified_name
6521 | LOCAL TEMP opt_table qualified_name
6526 | GLOBAL TEMPORARY opt_table qualified_name
6531 | GLOBAL TEMP opt_table qualified_name
6536 | TABLE qualified_name
6552 opt_all: ALL
{ $$
= TRUE
; }
6553 | DISTINCT
{ $$
= FALSE
; }
6554 |
/*EMPTY*/ { $$
= FALSE
; }
6557 /* We use (NIL) as a placeholder to indicate that all target expressions
6558 * should be placed in the DISTINCT list during parsetree analysis.
6561 DISTINCT
{ $$
= list_make1
(NIL
); }
6562 | DISTINCT ON
'(' expr_list
')' { $$
= $4; }
6564 |
/*EMPTY*/ { $$
= NIL
; }
6568 sort_clause
{ $$
= $1;}
6569 |
/*EMPTY*/ { $$
= NIL
; }
6573 ORDER BY sortby_list
{ $$
= $3; }
6577 sortby
{ $$
= list_make1
($1); }
6578 | sortby_list
',' sortby
{ $$
= lappend
($1, $3); }
6581 sortby: a_expr USING qual_all_Op opt_nulls_order
6583 $$
= makeNode
(SortBy
);
6585 $$
->sortby_dir
= SORTBY_USING
;
6586 $$
->sortby_nulls
= $4;
6590 | a_expr opt_asc_desc opt_nulls_order
6592 $$
= makeNode
(SortBy
);
6594 $$
->sortby_dir
= $2;
6595 $$
->sortby_nulls
= $3;
6597 $$
->location
= -1; /* no operator */
6603 LIMIT select_limit_value OFFSET select_offset_value
6604 { $$
= list_make2
($4, $2); }
6605 | OFFSET select_offset_value LIMIT select_limit_value
6606 { $$
= list_make2
($2, $4); }
6607 | LIMIT select_limit_value
6608 { $$
= list_make2
(NULL
, $2); }
6609 | OFFSET select_offset_value
6610 { $$
= list_make2
($2, NULL
); }
6611 | LIMIT select_limit_value
',' select_offset_value
6613 /* Disabled because it was too confusing, bjm 2002-02-18 */
6615 (errcode
(ERRCODE_SYNTAX_ERROR
),
6616 errmsg
("LIMIT #,# syntax is not supported"),
6617 errhint
("Use separate LIMIT and OFFSET clauses."),
6618 scanner_errposition
(@
1)));
6620 /* SQL:2008 syntax variants */
6621 | OFFSET select_offset_value2 row_or_rows
6622 { $$
= list_make2
($2, NULL
); }
6623 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
6624 { $$
= list_make2
(NULL
, $3); }
6625 | OFFSET select_offset_value2 row_or_rows FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
6626 { $$
= list_make2
($2, $6); }
6630 select_limit
{ $$
= $1; }
6632 { $$
= list_make2
(NULL
,NULL
); }
6639 /* LIMIT ALL is represented as a NULL constant */
6640 $$
= makeNullAConst
(@
1);
6645 * Allowing full expressions without parentheses causes various parsing
6646 * problems with the trailing ROW/ROWS key words. SQL only calls for
6647 * constants, so we allow the rest only with parentheses.
6649 opt_select_fetch_first_value:
6650 SignedIconst
{ $$
= makeIntConst
($1, @
1); }
6651 |
'(' a_expr
')' { $$
= $2; }
6652 |
/*EMPTY*/ { $$
= makeIntConst
(1, -1); }
6655 select_offset_value:
6660 * Again, the trailing ROW/ROWS in this case prevent the full expression
6661 * syntax. c_expr is the best we can do.
6663 select_offset_value2:
6679 GROUP_P BY expr_list
{ $$
= $3; }
6680 |
/*EMPTY*/ { $$
= NIL
; }
6684 HAVING a_expr
{ $$
= $2; }
6685 |
/*EMPTY*/ { $$
= NULL
; }
6689 for_locking_items
{ $$
= $1; }
6690 | FOR READ ONLY
{ $$
= NIL
; }
6693 opt_for_locking_clause:
6694 for_locking_clause
{ $$
= $1; }
6695 |
/* EMPTY */ { $$
= NIL
; }
6699 for_locking_item
{ $$
= list_make1
($1); }
6700 | for_locking_items for_locking_item
{ $$
= lappend
($1, $2); }
6704 FOR UPDATE locked_rels_list opt_nowait
6706 LockingClause
*n
= makeNode
(LockingClause
);
6708 n
->forUpdate
= TRUE
;
6712 | FOR SHARE locked_rels_list opt_nowait
6714 LockingClause
*n
= makeNode
(LockingClause
);
6716 n
->forUpdate
= FALSE
;
6723 OF qualified_name_list
{ $$
= $2; }
6724 |
/* EMPTY */ { $$
= NIL
; }
6731 SelectStmt
*n
= makeNode
(SelectStmt
);
6732 n
->valuesLists
= list_make1
($2);
6735 | values_clause
',' ctext_row
6737 SelectStmt
*n
= (SelectStmt
*) $1;
6738 n
->valuesLists
= lappend
(n
->valuesLists
, $3);
6744 /*****************************************************************************
6746 * clauses common to all Optimizable Stmts:
6747 * from_clause - allow list of both JOIN expressions and table names
6748 * where_clause - qualifications for joins or restrictions
6750 *****************************************************************************/
6753 FROM from_list
{ $$
= $2; }
6754 |
/*EMPTY*/ { $$
= NIL
; }
6758 table_ref
{ $$
= list_make1
($1); }
6759 | from_list
',' table_ref
{ $$
= lappend
($1, $3); }
6763 * table_ref is where an alias clause can be attached. Note we cannot make
6764 * alias_clause have an empty production because that causes parse conflicts
6765 * between table_ref := '(' joined_table ')' alias_clause
6766 * and joined_table := '(' joined_table ')'. So, we must have the
6767 * redundant-looking productions here instead.
6769 table_ref: relation_expr
6773 | relation_expr alias_clause
6780 RangeFunction
*n
= makeNode
(RangeFunction
);
6781 n
->funccallnode
= $1;
6782 n
->coldeflist
= NIL
;
6785 | func_table alias_clause
6787 RangeFunction
*n
= makeNode
(RangeFunction
);
6788 n
->funccallnode
= $1;
6790 n
->coldeflist
= NIL
;
6793 | func_table AS
'(' TableFuncElementList
')'
6795 RangeFunction
*n
= makeNode
(RangeFunction
);
6796 n
->funccallnode
= $1;
6800 | func_table AS ColId
'(' TableFuncElementList
')'
6802 RangeFunction
*n
= makeNode
(RangeFunction
);
6803 Alias
*a
= makeNode
(Alias
);
6804 n
->funccallnode
= $1;
6810 | func_table ColId
'(' TableFuncElementList
')'
6812 RangeFunction
*n
= makeNode
(RangeFunction
);
6813 Alias
*a
= makeNode
(Alias
);
6814 n
->funccallnode
= $1;
6820 | select_with_parens
6823 * The SQL spec does not permit a subselect
6824 * (<derived_table>) without an alias clause,
6825 * so we don't either. This avoids the problem
6826 * of needing to invent a unique refname for it.
6827 * That could be surmounted if there's sufficient
6828 * popular demand, but for now let's just implement
6829 * the spec and see if anyone complains.
6830 * However, it does seem like a good idea to emit
6831 * an error message that's better than "syntax error".
6833 if
(IsA
($1, SelectStmt
) &&
6834 ((SelectStmt
*) $1)->valuesLists
)
6836 (errcode
(ERRCODE_SYNTAX_ERROR
),
6837 errmsg
("VALUES in FROM must have an alias"),
6838 errhint
("For example, FROM (VALUES ...) [AS] foo."),
6839 scanner_errposition
(@
1)));
6842 (errcode
(ERRCODE_SYNTAX_ERROR
),
6843 errmsg
("subquery in FROM must have an alias"),
6844 errhint
("For example, FROM (SELECT ...) [AS] foo."),
6845 scanner_errposition
(@
1)));
6848 | select_with_parens alias_clause
6850 RangeSubselect
*n
= makeNode
(RangeSubselect
);
6859 |
'(' joined_table
')' alias_clause
6868 * It may seem silly to separate joined_table from table_ref, but there is
6869 * method in SQL92's madness: if you don't do it this way you get reduce-
6870 * reduce conflicts, because it's not clear to the parser generator whether
6871 * to expect alias_clause after ')' or not. For the same reason we must
6872 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
6873 * join_type to expand to empty; if we try it, the parser generator can't
6874 * figure out when to reduce an empty join_type right after table_ref.
6876 * Note that a CROSS JOIN is the same as an unqualified
6877 * INNER JOIN, and an INNER JOIN/ON has the same shape
6878 * but a qualification expression to limit membership.
6879 * A NATURAL JOIN implicitly matches column names between
6880 * tables and the shape is determined by which columns are
6881 * in common. We'll collect columns during the later transformations.
6885 '(' joined_table
')'
6889 | table_ref CROSS JOIN table_ref
6891 /* CROSS JOIN is same as unqualified inner join */
6892 JoinExpr
*n
= makeNode
(JoinExpr
);
6893 n
->jointype
= JOIN_INNER
;
6894 n
->isNatural
= FALSE
;
6901 | table_ref join_type JOIN table_ref join_qual
6903 JoinExpr
*n
= makeNode
(JoinExpr
);
6905 n
->isNatural
= FALSE
;
6908 if
($5 != NULL
&& IsA
($5, List
))
6909 n
->using
= (List
*) $5; /* USING clause */
6911 n
->quals
= $5; /* ON clause */
6914 | table_ref JOIN table_ref join_qual
6916 /* letting join_type reduce to empty doesn't work */
6917 JoinExpr
*n
= makeNode
(JoinExpr
);
6918 n
->jointype
= JOIN_INNER
;
6919 n
->isNatural
= FALSE
;
6922 if
($4 != NULL
&& IsA
($4, List
))
6923 n
->using
= (List
*) $4; /* USING clause */
6925 n
->quals
= $4; /* ON clause */
6928 | table_ref NATURAL join_type JOIN table_ref
6930 JoinExpr
*n
= makeNode
(JoinExpr
);
6932 n
->isNatural
= TRUE
;
6935 n
->using
= NIL
; /* figure out which columns later... */
6936 n
->quals
= NULL
; /* fill later */
6939 | table_ref NATURAL JOIN table_ref
6941 /* letting join_type reduce to empty doesn't work */
6942 JoinExpr
*n
= makeNode
(JoinExpr
);
6943 n
->jointype
= JOIN_INNER
;
6944 n
->isNatural
= TRUE
;
6947 n
->using
= NIL
; /* figure out which columns later... */
6948 n
->quals
= NULL
; /* fill later */
6954 AS ColId
'(' name_list
')'
6956 $$
= makeNode
(Alias
);
6962 $$
= makeNode
(Alias
);
6965 | ColId
'(' name_list
')'
6967 $$
= makeNode
(Alias
);
6973 $$
= makeNode
(Alias
);
6978 join_type: FULL join_outer
{ $$
= JOIN_FULL
; }
6979 | LEFT join_outer
{ $$
= JOIN_LEFT
; }
6980 | RIGHT join_outer
{ $$
= JOIN_RIGHT
; }
6981 | INNER_P
{ $$
= JOIN_INNER
; }
6984 /* OUTER is just noise... */
6985 join_outer: OUTER_P
{ $$
= NULL
; }
6986 |
/*EMPTY*/ { $$
= NULL
; }
6989 /* JOIN qualification clauses
6990 * Possibilities are:
6991 * USING ( column list ) allows only unqualified column names,
6992 * which must match between tables.
6993 * ON expr allows more general qualifications.
6995 * We return USING as a List node, while an ON-expr will not be a List.
6998 join_qual: USING
'(' name_list
')' { $$
= (Node
*) $3; }
6999 | ON a_expr
{ $$
= $2; }
7006 /* default inheritance */
7008 $$
->inhOpt
= INH_DEFAULT
;
7011 | qualified_name
'*'
7013 /* inheritance query */
7015 $$
->inhOpt
= INH_YES
;
7018 | ONLY qualified_name
7020 /* no inheritance */
7022 $$
->inhOpt
= INH_NO
;
7025 | ONLY
'(' qualified_name
')'
7027 /* no inheritance, SQL99-style syntax */
7029 $$
->inhOpt
= INH_NO
;
7036 * Given "UPDATE foo set set ...", we have to decide without looking any
7037 * further ahead whether the first "set" is an alias or the UPDATE's SET
7038 * keyword. Since "set" is allowed as a column name both interpretations
7039 * are feasible. We resolve the shift/reduce conflict by giving the first
7040 * relation_expr_opt_alias production a higher precedence than the SET token
7041 * has, causing the parser to prefer to reduce, in effect assuming that the
7042 * SET is not an alias.
7044 relation_expr_opt_alias: relation_expr %prec UMINUS
7048 | relation_expr ColId
7050 Alias
*alias
= makeNode
(Alias
);
7051 alias
->aliasname
= $2;
7055 | relation_expr AS ColId
7057 Alias
*alias
= makeNode
(Alias
);
7058 alias
->aliasname
= $3;
7065 func_table: func_expr
{ $$
= $1; }
7070 WHERE a_expr
{ $$
= $2; }
7071 |
/*EMPTY*/ { $$
= NULL
; }
7074 /* variant for UPDATE and DELETE */
7075 where_or_current_clause:
7076 WHERE a_expr
{ $$
= $2; }
7077 | WHERE CURRENT_P OF name
7079 CurrentOfExpr
*n
= makeNode
(CurrentOfExpr
);
7080 /* cvarno is filled in by parse analysis */
7081 n
->cursor_name
= $4;
7082 n
->cursor_param
= 0;
7085 | WHERE CURRENT_P OF PARAM
7087 CurrentOfExpr
*n
= makeNode
(CurrentOfExpr
);
7088 /* cvarno is filled in by parse analysis */
7089 n
->cursor_name
= NULL
;
7090 n
->cursor_param
= $4;
7093 |
/*EMPTY*/ { $$
= NULL
; }
7097 TableFuncElementList:
7100 $$
= list_make1
($1);
7102 | TableFuncElementList
',' TableFuncElement
7104 $$
= lappend
($1, $3);
7108 TableFuncElement: ColId Typename
7110 ColumnDef
*n
= makeNode
(ColumnDef
);
7113 n
->constraints
= NIL
;
7119 /*****************************************************************************
7122 * SQL92 introduces a large amount of type-specific syntax.
7123 * Define individual clauses to handle these cases, and use
7124 * the generic case to handle regular type-extensible Postgres syntax.
7125 * - thomas 1997-10-10
7127 *****************************************************************************/
7129 Typename: SimpleTypename opt_array_bounds
7132 $$
->arrayBounds
= $2;
7134 | SETOF SimpleTypename opt_array_bounds
7137 $$
->arrayBounds
= $3;
7140 /* SQL standard syntax, currently only one-dimensional */
7141 | SimpleTypename ARRAY
'[' Iconst
']'
7144 $$
->arrayBounds
= list_make1
(makeInteger
($4));
7146 | SETOF SimpleTypename ARRAY
'[' Iconst
']'
7149 $$
->arrayBounds
= list_make1
(makeInteger
($5));
7152 | SimpleTypename ARRAY
7155 $$
->arrayBounds
= list_make1
(makeInteger
(-1));
7157 | SETOF SimpleTypename ARRAY
7160 $$
->arrayBounds
= list_make1
(makeInteger
(-1));
7166 opt_array_bounds
'[' ']'
7167 { $$
= lappend
($1, makeInteger
(-1)); }
7168 | opt_array_bounds
'[' Iconst
']'
7169 { $$
= lappend
($1, makeInteger
($3)); }
7175 GenericType
{ $$
= $1; }
7176 | Numeric
{ $$
= $1; }
7178 | Character
{ $$
= $1; }
7179 | ConstDatetime
{ $$
= $1; }
7180 | ConstInterval opt_interval
7185 | ConstInterval
'(' Iconst
')' opt_interval
7190 if
(list_length
($5) != 1)
7192 (errcode
(ERRCODE_SYNTAX_ERROR
),
7193 errmsg
("interval precision specified twice"),
7194 scanner_errposition
(@
1)));
7195 $$
->typmods
= lappend
($5, makeIntConst
($3, @
3));
7198 $$
->typmods
= list_make2
(makeIntConst
(INTERVAL_FULL_RANGE
, -1),
7199 makeIntConst
($3, @
3));
7203 /* We have a separate ConstTypename to allow defaulting fixed-length
7204 * types such as CHAR() and BIT() to an unspecified length.
7205 * SQL9x requires that these default to a length of one, but this
7206 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
7207 * where there is an obvious better choice to make.
7208 * Note that ConstInterval is not included here since it must
7209 * be pushed up higher in the rules to accomodate the postfix
7210 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
7211 * the generic-type-name case in AExprConst to avoid premature
7212 * reduce/reduce conflicts against function names.
7215 Numeric
{ $$
= $1; }
7216 | ConstBit
{ $$
= $1; }
7217 | ConstCharacter
{ $$
= $1; }
7218 | ConstDatetime
{ $$
= $1; }
7222 * GenericType covers all type names that don't have special syntax mandated
7223 * by the standard, including qualified names. We also allow type modifiers.
7224 * To avoid parsing conflicts against function invocations, the modifiers
7225 * have to be shown as expr_list here, but parse analysis will only accept
7226 * constants for them.
7229 type_function_name opt_type_modifiers
7231 $$
= makeTypeName
($1);
7235 | type_function_name attrs opt_type_modifiers
7237 $$
= makeTypeNameFromNameList
(lcons
(makeString
($1), $2));
7243 opt_type_modifiers: '(' expr_list
')' { $$
= $2; }
7244 |
/* EMPTY */ { $$
= NIL
; }
7248 * SQL92 numeric data types
7252 $$
= SystemTypeName
("int4");
7257 $$
= SystemTypeName
("int4");
7262 $$
= SystemTypeName
("int2");
7267 $$
= SystemTypeName
("int8");
7272 $$
= SystemTypeName
("float4");
7280 | DOUBLE_P PRECISION
7282 $$
= SystemTypeName
("float8");
7285 | DECIMAL_P opt_type_modifiers
7287 $$
= SystemTypeName
("numeric");
7291 | DEC opt_type_modifiers
7293 $$
= SystemTypeName
("numeric");
7297 | NUMERIC opt_type_modifiers
7299 $$
= SystemTypeName
("numeric");
7305 $$
= SystemTypeName
("bool");
7310 opt_float: '(' Iconst
')'
7313 * Check FLOAT() precision limits assuming IEEE floating
7314 * types - thomas 1997-09-18
7318 (errcode
(ERRCODE_INVALID_PARAMETER_VALUE
),
7319 errmsg
("precision for type float must be at least 1 bit"),
7320 scanner_errposition
(@
2)));
7322 $$
= SystemTypeName
("float4");
7324 $$
= SystemTypeName
("float8");
7327 (errcode
(ERRCODE_INVALID_PARAMETER_VALUE
),
7328 errmsg
("precision for type float must be less than 54 bits"),
7329 scanner_errposition
(@
2)));
7333 $$
= SystemTypeName
("float8");
7338 * SQL92 bit-field data types
7339 * The following implements BIT() and BIT VARYING().
7351 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
7352 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
7353 ConstBit: BitWithLength
7365 BIT opt_varying
'(' expr_list
')'
7369 typname
= $2 ?
"varbit" : "bit";
7370 $$
= SystemTypeName
(typname
);
7379 /* bit defaults to bit(1), varbit to no limit */
7382 $$
= SystemTypeName
("varbit");
7386 $$
= SystemTypeName
("bit");
7387 $$
->typmods
= list_make1
(makeIntConst
(1, -1));
7395 * SQL92 character data types
7396 * The following implements CHAR() and VARCHAR().
7398 Character: CharacterWithLength
7402 | CharacterWithoutLength
7408 ConstCharacter: CharacterWithLength
7412 | CharacterWithoutLength
7414 /* Length was not specified so allow to be unrestricted.
7415 * This handles problems with fixed-length (bpchar) strings
7416 * which in column definitions must default to a length
7417 * of one, but should not be constrained if the length
7418 * was not specified.
7425 CharacterWithLength: character
'(' Iconst
')' opt_charset
7427 if
(($5 != NULL
) && (strcmp
($5, "sql_text") != 0))
7431 type
= palloc
(strlen
($1) + 1 + strlen
($5) + 1);
7438 $$
= SystemTypeName
($1);
7439 $$
->typmods
= list_make1
(makeIntConst
($3, @
3));
7444 CharacterWithoutLength: character opt_charset
7446 if
(($2 != NULL
) && (strcmp
($2, "sql_text") != 0))
7450 type
= palloc
(strlen
($1) + 1 + strlen
($2) + 1);
7457 $$
= SystemTypeName
($1);
7459 /* char defaults to char(1), varchar to no limit */
7460 if
(strcmp
($1, "bpchar") == 0)
7461 $$
->typmods
= list_make1
(makeIntConst
(1, -1));
7467 character: CHARACTER opt_varying
7468 { $$
= $2 ?
"varchar": "bpchar"; }
7469 | CHAR_P opt_varying
7470 { $$
= $2 ?
"varchar": "bpchar"; }
7473 | NATIONAL CHARACTER opt_varying
7474 { $$
= $3 ?
"varchar": "bpchar"; }
7475 | NATIONAL CHAR_P opt_varying
7476 { $$
= $3 ?
"varchar": "bpchar"; }
7478 { $$
= $2 ?
"varchar": "bpchar"; }
7482 VARYING
{ $$
= TRUE
; }
7483 |
/*EMPTY*/ { $$
= FALSE
; }
7487 CHARACTER SET ColId
{ $$
= $3; }
7488 |
/*EMPTY*/ { $$
= NULL
; }
7492 * SQL92 date/time types
7495 TIMESTAMP
'(' Iconst
')' opt_timezone
7498 $$
= SystemTypeName
("timestamptz");
7500 $$
= SystemTypeName
("timestamp");
7501 $$
->typmods
= list_make1
(makeIntConst
($3, @
3));
7504 | TIMESTAMP opt_timezone
7507 $$
= SystemTypeName
("timestamptz");
7509 $$
= SystemTypeName
("timestamp");
7512 | TIME
'(' Iconst
')' opt_timezone
7515 $$
= SystemTypeName
("timetz");
7517 $$
= SystemTypeName
("time");
7518 $$
->typmods
= list_make1
(makeIntConst
($3, @
3));
7524 $$
= SystemTypeName
("timetz");
7526 $$
= SystemTypeName
("time");
7534 $$
= SystemTypeName
("interval");
7540 WITH_TIME ZONE
{ $$
= TRUE
; }
7541 | WITHOUT TIME ZONE
{ $$
= FALSE
; }
7542 |
/*EMPTY*/ { $$
= FALSE
; }
7547 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(YEAR
), @
1)); }
7549 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(MONTH
), @
1)); }
7551 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(DAY
), @
1)); }
7553 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(HOUR
), @
1)); }
7555 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(MINUTE
), @
1)); }
7560 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(YEAR
) |
7561 INTERVAL_MASK
(MONTH
), @
1));
7565 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(DAY
) |
7566 INTERVAL_MASK
(HOUR
), @
1));
7570 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(DAY
) |
7571 INTERVAL_MASK
(HOUR
) |
7572 INTERVAL_MASK
(MINUTE
), @
1));
7574 | DAY_P TO interval_second
7577 linitial
($$
) = makeIntConst
(INTERVAL_MASK
(DAY
) |
7578 INTERVAL_MASK
(HOUR
) |
7579 INTERVAL_MASK
(MINUTE
) |
7580 INTERVAL_MASK
(SECOND
), @
1);
7582 | HOUR_P TO MINUTE_P
7584 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(HOUR
) |
7585 INTERVAL_MASK
(MINUTE
), @
1));
7587 | HOUR_P TO interval_second
7590 linitial
($$
) = makeIntConst
(INTERVAL_MASK
(HOUR
) |
7591 INTERVAL_MASK
(MINUTE
) |
7592 INTERVAL_MASK
(SECOND
), @
1);
7594 | MINUTE_P TO interval_second
7597 linitial
($$
) = makeIntConst
(INTERVAL_MASK
(MINUTE
) |
7598 INTERVAL_MASK
(SECOND
), @
1);
7607 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(SECOND
), @
1));
7609 | SECOND_P
'(' Iconst
')'
7611 $$
= list_make2
(makeIntConst
(INTERVAL_MASK
(SECOND
), @
1),
7612 makeIntConst
($3, @
3));
7617 /*****************************************************************************
7619 * expression grammar
7621 *****************************************************************************/
7624 * General expressions
7625 * This is the heart of the expression syntax.
7627 * We have two expression types: a_expr is the unrestricted kind, and
7628 * b_expr is a subset that must be used in some places to avoid shift/reduce
7629 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
7630 * because that use of AND conflicts with AND as a boolean operator. So,
7631 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
7633 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
7634 * always be used by surrounding it with parens.
7636 * c_expr is all the productions that are common to a_expr and b_expr;
7637 * it's factored out just to eliminate redundant coding.
7639 a_expr: c_expr
{ $$
= $1; }
7640 | a_expr TYPECAST Typename
7641 { $$
= makeTypeCast
($1, $3, @
2); }
7642 | a_expr AT TIME ZONE a_expr
7644 FuncCall
*n
= makeNode
(FuncCall
);
7645 n
->funcname
= SystemFuncName
("timezone");
7646 n
->args
= list_make2
($5, $1);
7647 n
->agg_star
= FALSE
;
7648 n
->agg_distinct
= FALSE
;
7649 n
->func_variadic
= FALSE
;
7654 * These operators must be called out explicitly in order to make use
7655 * of yacc/bison's automatic operator-precedence handling. All other
7656 * operator names are handled by the generic productions using "Op",
7657 * below; and all those operators will have the same precedence.
7659 * If you add more explicitly-known operators, be sure to add them
7660 * also to b_expr and to the MathOp list above.
7662 |
'+' a_expr %prec UMINUS
7663 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", NULL
, $2, @
1); }
7664 |
'-' a_expr %prec UMINUS
7665 { $$
= doNegate
($2, @
1); }
7667 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", $1, $3, @
2); }
7669 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "-", $1, $3, @
2); }
7671 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "*", $1, $3, @
2); }
7673 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "/", $1, $3, @
2); }
7675 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "%", $1, $3, @
2); }
7677 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "^", $1, $3, @
2); }
7679 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $3, @
2); }
7681 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $3, @
2); }
7683 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "=", $1, $3, @
2); }
7685 | a_expr qual_Op a_expr %prec Op
7686 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, $3, @
2); }
7687 | qual_Op a_expr %prec Op
7688 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $1, NULL
, $2, @
1); }
7689 | a_expr qual_Op %prec POSTFIXOP
7690 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, NULL
, @
2); }
7693 { $$
= (Node
*) makeA_Expr
(AEXPR_AND
, NIL
, $1, $3, @
2); }
7695 { $$
= (Node
*) makeA_Expr
(AEXPR_OR
, NIL
, $1, $3, @
2); }
7697 { $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
, $2, @
1); }
7699 | a_expr LIKE a_expr
7700 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~~", $1, $3, @
2); }
7701 | a_expr LIKE a_expr ESCAPE a_expr
7703 FuncCall
*n
= makeNode
(FuncCall
);
7704 n
->funcname
= SystemFuncName
("like_escape");
7705 n
->args
= list_make2
($3, $5);
7706 n
->agg_star
= FALSE
;
7707 n
->agg_distinct
= FALSE
;
7708 n
->func_variadic
= FALSE
;
7710 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~~", $1, (Node
*) n
, @
2);
7712 | a_expr NOT LIKE a_expr
7713 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~~", $1, $4, @
2); }
7714 | a_expr NOT LIKE a_expr ESCAPE a_expr
7716 FuncCall
*n
= makeNode
(FuncCall
);
7717 n
->funcname
= SystemFuncName
("like_escape");
7718 n
->args
= list_make2
($4, $6);
7719 n
->agg_star
= FALSE
;
7720 n
->agg_distinct
= FALSE
;
7721 n
->func_variadic
= FALSE
;
7723 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~~", $1, (Node
*) n
, @
2);
7725 | a_expr ILIKE a_expr
7726 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~~*", $1, $3, @
2); }
7727 | a_expr ILIKE a_expr ESCAPE a_expr
7729 FuncCall
*n
= makeNode
(FuncCall
);
7730 n
->funcname
= SystemFuncName
("like_escape");
7731 n
->args
= list_make2
($3, $5);
7732 n
->agg_star
= FALSE
;
7733 n
->agg_distinct
= FALSE
;
7734 n
->func_variadic
= FALSE
;
7736 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~~*", $1, (Node
*) n
, @
2);
7738 | a_expr NOT ILIKE a_expr
7739 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~~*", $1, $4, @
2); }
7740 | a_expr NOT ILIKE a_expr ESCAPE a_expr
7742 FuncCall
*n
= makeNode
(FuncCall
);
7743 n
->funcname
= SystemFuncName
("like_escape");
7744 n
->args
= list_make2
($4, $6);
7745 n
->agg_star
= FALSE
;
7746 n
->agg_distinct
= FALSE
;
7747 n
->func_variadic
= FALSE
;
7749 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~~*", $1, (Node
*) n
, @
2);
7752 | a_expr SIMILAR TO a_expr %prec SIMILAR
7754 FuncCall
*n
= makeNode
(FuncCall
);
7755 n
->funcname
= SystemFuncName
("similar_escape");
7756 n
->args
= list_make2
($4, makeNullAConst
(-1));
7757 n
->agg_star
= FALSE
;
7758 n
->agg_distinct
= FALSE
;
7759 n
->func_variadic
= FALSE
;
7761 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~", $1, (Node
*) n
, @
2);
7763 | a_expr SIMILAR TO a_expr ESCAPE a_expr
7765 FuncCall
*n
= makeNode
(FuncCall
);
7766 n
->funcname
= SystemFuncName
("similar_escape");
7767 n
->args
= list_make2
($4, $6);
7768 n
->agg_star
= FALSE
;
7769 n
->agg_distinct
= FALSE
;
7770 n
->func_variadic
= FALSE
;
7772 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~", $1, (Node
*) n
, @
2);
7774 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
7776 FuncCall
*n
= makeNode
(FuncCall
);
7777 n
->funcname
= SystemFuncName
("similar_escape");
7778 n
->args
= list_make2
($5, makeNullAConst
(-1));
7779 n
->agg_star
= FALSE
;
7780 n
->agg_distinct
= FALSE
;
7781 n
->func_variadic
= FALSE
;
7783 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~", $1, (Node
*) n
, @
2);
7785 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
7787 FuncCall
*n
= makeNode
(FuncCall
);
7788 n
->funcname
= SystemFuncName
("similar_escape");
7789 n
->args
= list_make2
($5, $7);
7790 n
->agg_star
= FALSE
;
7791 n
->agg_distinct
= FALSE
;
7792 n
->func_variadic
= FALSE
;
7794 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~", $1, (Node
*) n
, @
2);
7798 * Define SQL92-style Null test clause.
7799 * Allow two forms described in the standard:
7802 * Allow two SQL extensions
7808 NullTest
*n
= makeNode
(NullTest
);
7809 n
->arg
= (Expr
*) $1;
7810 n
->nulltesttype
= IS_NULL
;
7815 NullTest
*n
= makeNode
(NullTest
);
7816 n
->arg
= (Expr
*) $1;
7817 n
->nulltesttype
= IS_NULL
;
7820 | a_expr IS NOT NULL_P
7822 NullTest
*n
= makeNode
(NullTest
);
7823 n
->arg
= (Expr
*) $1;
7824 n
->nulltesttype
= IS_NOT_NULL
;
7829 NullTest
*n
= makeNode
(NullTest
);
7830 n
->arg
= (Expr
*) $1;
7831 n
->nulltesttype
= IS_NOT_NULL
;
7836 $$
= (Node
*)makeOverlaps
($1, $3, @
2);
7840 BooleanTest
*b
= makeNode
(BooleanTest
);
7841 b
->arg
= (Expr
*) $1;
7842 b
->booltesttype
= IS_TRUE
;
7845 | a_expr IS NOT TRUE_P
7847 BooleanTest
*b
= makeNode
(BooleanTest
);
7848 b
->arg
= (Expr
*) $1;
7849 b
->booltesttype
= IS_NOT_TRUE
;
7854 BooleanTest
*b
= makeNode
(BooleanTest
);
7855 b
->arg
= (Expr
*) $1;
7856 b
->booltesttype
= IS_FALSE
;
7859 | a_expr IS NOT FALSE_P
7861 BooleanTest
*b
= makeNode
(BooleanTest
);
7862 b
->arg
= (Expr
*) $1;
7863 b
->booltesttype
= IS_NOT_FALSE
;
7868 BooleanTest
*b
= makeNode
(BooleanTest
);
7869 b
->arg
= (Expr
*) $1;
7870 b
->booltesttype
= IS_UNKNOWN
;
7873 | a_expr IS NOT UNKNOWN
7875 BooleanTest
*b
= makeNode
(BooleanTest
);
7876 b
->arg
= (Expr
*) $1;
7877 b
->booltesttype
= IS_NOT_UNKNOWN
;
7880 | a_expr IS DISTINCT FROM a_expr %prec IS
7882 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
, "=", $1, $5, @
2);
7884 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
7886 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
,
7887 (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
,
7892 | a_expr IS OF
'(' type_list
')' %prec IS
7894 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OF
, "=", $1, (Node
*) $5, @
2);
7896 | a_expr IS NOT OF
'(' type_list
')' %prec IS
7898 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OF
, "<>", $1, (Node
*) $6, @
2);
7900 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
7902 $$
= (Node
*) makeA_Expr
(AEXPR_AND
, NIL
,
7903 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">=", $1, $4, @
2),
7904 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<=", $1, $6, @
2),
7907 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
7909 $$
= (Node
*) makeA_Expr
(AEXPR_OR
, NIL
,
7910 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $5, @
2),
7911 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $7, @
2),
7914 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
7916 $$
= (Node
*) makeA_Expr
(AEXPR_OR
, NIL
,
7917 (Node
*) makeA_Expr
(AEXPR_AND
, NIL
,
7918 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">=", $1, $4, @
2),
7919 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<=", $1, $6, @
2),
7921 (Node
*) makeA_Expr
(AEXPR_AND
, NIL
,
7922 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">=", $1, $6, @
2),
7923 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<=", $1, $4, @
2),
7927 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
7929 $$
= (Node
*) makeA_Expr
(AEXPR_AND
, NIL
,
7930 (Node
*) makeA_Expr
(AEXPR_OR
, NIL
,
7931 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $5, @
2),
7932 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $7, @
2),
7934 (Node
*) makeA_Expr
(AEXPR_OR
, NIL
,
7935 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $7, @
2),
7936 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $5, @
2),
7940 | a_expr IN_P in_expr
7942 /* in_expr returns a SubLink or a list of a_exprs */
7943 if
(IsA
($3, SubLink
))
7945 /* generate foo = ANY (subquery) */
7946 SubLink
*n
= (SubLink
*) $3;
7947 n
->subLinkType
= ANY_SUBLINK
;
7949 n
->operName
= list_make1
(makeString
("="));
7955 /* generate scalar IN expression */
7956 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_IN
, "=", $1, $3, @
2);
7959 | a_expr NOT IN_P in_expr
7961 /* in_expr returns a SubLink or a list of a_exprs */
7962 if
(IsA
($4, SubLink
))
7964 /* generate NOT (foo = ANY (subquery)) */
7965 /* Make an = ANY node */
7966 SubLink
*n
= (SubLink
*) $4;
7967 n
->subLinkType
= ANY_SUBLINK
;
7969 n
->operName
= list_make1
(makeString
("="));
7971 /* Stick a NOT on top */
7972 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
, (Node
*) n
, @
2);
7976 /* generate scalar NOT IN expression */
7977 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_IN
, "<>", $1, $4, @
2);
7980 | a_expr subquery_Op sub_type select_with_parens %prec Op
7982 SubLink
*n
= makeNode
(SubLink
);
7983 n
->subLinkType
= $3;
7990 | a_expr subquery_Op sub_type
'(' a_expr
')' %prec Op
7992 if
($3 == ANY_SUBLINK
)
7993 $$
= (Node
*) makeA_Expr
(AEXPR_OP_ANY
, $2, $1, $5, @
2);
7995 $$
= (Node
*) makeA_Expr
(AEXPR_OP_ALL
, $2, $1, $5, @
2);
7997 | UNIQUE select_with_parens
7999 /* Not sure how to get rid of the parentheses
8000 * but there are lots of shift/reduce errors without them.
8002 * Should be able to implement this by plopping the entire
8003 * select into a node, then transforming the target expressions
8004 * from whatever they are into count(*), and testing the
8005 * entire result equal to one.
8006 * But, will probably implement a separate node in the executor.
8009 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
8010 errmsg
("UNIQUE predicate is not yet implemented"),
8011 scanner_errposition
(@
1)));
8013 | a_expr IS DOCUMENT_P %prec IS
8015 $$
= makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
8016 list_make1
($1), @
2);
8018 | a_expr IS NOT DOCUMENT_P %prec IS
8020 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
,
8021 makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
8022 list_make1
($1), @
2),
8028 * Restricted expressions
8030 * b_expr is a subset of the complete expression syntax defined by a_expr.
8032 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
8033 * cause trouble in the places where b_expr is used. For simplicity, we
8034 * just eliminate all the boolean-keyword-operator productions from b_expr.
8038 | b_expr TYPECAST Typename
8039 { $$
= makeTypeCast
($1, $3, @
2); }
8040 |
'+' b_expr %prec UMINUS
8041 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", NULL
, $2, @
1); }
8042 |
'-' b_expr %prec UMINUS
8043 { $$
= doNegate
($2, @
1); }
8045 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", $1, $3, @
2); }
8047 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "-", $1, $3, @
2); }
8049 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "*", $1, $3, @
2); }
8051 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "/", $1, $3, @
2); }
8053 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "%", $1, $3, @
2); }
8055 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "^", $1, $3, @
2); }
8057 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $3, @
2); }
8059 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $3, @
2); }
8061 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "=", $1, $3, @
2); }
8062 | b_expr qual_Op b_expr %prec Op
8063 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, $3, @
2); }
8064 | qual_Op b_expr %prec Op
8065 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $1, NULL
, $2, @
1); }
8066 | b_expr qual_Op %prec POSTFIXOP
8067 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, NULL
, @
2); }
8068 | b_expr IS DISTINCT FROM b_expr %prec IS
8070 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
, "=", $1, $5, @
2);
8072 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
8074 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
,
8075 NULL
, (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
, "=", $1, $6, @
2), @
2);
8077 | b_expr IS OF
'(' type_list
')' %prec IS
8079 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OF
, "=", $1, (Node
*) $5, @
2);
8081 | b_expr IS NOT OF
'(' type_list
')' %prec IS
8083 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OF
, "<>", $1, (Node
*) $6, @
2);
8085 | b_expr IS DOCUMENT_P %prec IS
8087 $$
= makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
8088 list_make1
($1), @
2);
8090 | b_expr IS NOT DOCUMENT_P %prec IS
8092 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
,
8093 makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
8094 list_make1
($1), @
2),
8100 * Productions that can be used in both a_expr and b_expr.
8102 * Note: productions that refer recursively to a_expr or b_expr mostly
8103 * cannot appear here. However, it's OK to refer to a_exprs that occur
8104 * inside parentheses, such as function arguments; that cannot introduce
8105 * ambiguity to the b_expr syntax.
8107 c_expr: columnref
{ $$
= $1; }
8108 | AexprConst
{ $$
= $1; }
8109 | PARAM opt_indirection
8111 ParamRef
*p
= makeNode
(ParamRef
);
8116 A_Indirection
*n
= makeNode
(A_Indirection
);
8117 n
->arg
= (Node
*) p
;
8118 n
->indirection
= check_indirection
($2);
8124 |
'(' a_expr
')' opt_indirection
8128 A_Indirection
*n
= makeNode
(A_Indirection
);
8130 n
->indirection
= check_indirection
($4);
8140 | select_with_parens %prec UMINUS
8142 SubLink
*n
= makeNode
(SubLink
);
8143 n
->subLinkType
= EXPR_SUBLINK
;
8150 | EXISTS select_with_parens
8152 SubLink
*n
= makeNode
(SubLink
);
8153 n
->subLinkType
= EXISTS_SUBLINK
;
8160 | ARRAY select_with_parens
8162 SubLink
*n
= makeNode
(SubLink
);
8163 n
->subLinkType
= ARRAY_SUBLINK
;
8172 A_ArrayExpr
*n
= (A_ArrayExpr
*) $2;
8173 Assert
(IsA
(n
, A_ArrayExpr
));
8174 /* point outermost A_ArrayExpr to the ARRAY keyword */
8180 RowExpr
*r
= makeNode
(RowExpr
);
8182 r
->row_typeid
= InvalidOid
; /* not analyzed yet */
8189 * func_expr is split out from c_expr just so that we have a classification
8190 * for "everything that is a function call or looks like one". This isn't
8191 * very important, but it saves us having to document which variants are
8192 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
8193 * (Note that many of the special SQL functions wouldn't actually make any
8194 * sense as functional index entries, but we ignore that consideration here.)
8196 func_expr: func_name
'(' ')'
8198 FuncCall
*n
= makeNode
(FuncCall
);
8201 n
->agg_star
= FALSE
;
8202 n
->agg_distinct
= FALSE
;
8203 n
->func_variadic
= FALSE
;
8207 | func_name
'(' expr_list
')'
8209 FuncCall
*n
= makeNode
(FuncCall
);
8212 n
->agg_star
= FALSE
;
8213 n
->agg_distinct
= FALSE
;
8214 n
->func_variadic
= FALSE
;
8218 | func_name
'(' VARIADIC a_expr
')'
8220 FuncCall
*n
= makeNode
(FuncCall
);
8222 n
->args
= list_make1
($4);
8223 n
->agg_star
= FALSE
;
8224 n
->agg_distinct
= FALSE
;
8225 n
->func_variadic
= TRUE
;
8229 | func_name
'(' expr_list
',' VARIADIC a_expr
')'
8231 FuncCall
*n
= makeNode
(FuncCall
);
8233 n
->args
= lappend
($3, $6);
8234 n
->agg_star
= FALSE
;
8235 n
->agg_distinct
= FALSE
;
8236 n
->func_variadic
= TRUE
;
8240 | func_name
'(' ALL expr_list
')'
8242 FuncCall
*n
= makeNode
(FuncCall
);
8245 n
->agg_star
= FALSE
;
8246 n
->agg_distinct
= FALSE
;
8247 /* Ideally we'd mark the FuncCall node to indicate
8248 * "must be an aggregate", but there's no provision
8249 * for that in FuncCall at the moment.
8251 n
->func_variadic
= FALSE
;
8255 | func_name
'(' DISTINCT expr_list
')'
8257 FuncCall
*n
= makeNode
(FuncCall
);
8260 n
->agg_star
= FALSE
;
8261 n
->agg_distinct
= TRUE
;
8262 n
->func_variadic
= FALSE
;
8266 | func_name
'(' '*' ')'
8269 * We consider AGGREGATE(*) to invoke a parameterless
8270 * aggregate. This does the right thing for COUNT(*),
8271 * and there are no other aggregates in SQL92 that accept
8274 * The FuncCall node is also marked agg_star = true,
8275 * so that later processing can detect what the argument
8278 FuncCall
*n
= makeNode
(FuncCall
);
8282 n
->agg_distinct
= FALSE
;
8283 n
->func_variadic
= FALSE
;
8290 * Translate as "'now'::text::date".
8292 * We cannot use "'now'::date" because coerce_type() will
8293 * immediately reduce that to a constant representing
8294 * today's date. We need to delay the conversion until
8295 * runtime, else the wrong things will happen when
8296 * CURRENT_DATE is used in a column default value or rule.
8298 * This could be simplified if we had a way to generate
8299 * an expression tree representing runtime application
8300 * of type-input conversion functions. (As of PG 7.3
8301 * that is actually possible, but not clear that we want
8305 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8306 $$
= makeTypeCast
(n
, SystemTypeName
("date"), -1);
8311 * Translate as "'now'::text::timetz".
8312 * See comments for CURRENT_DATE.
8315 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8316 $$
= makeTypeCast
(n
, SystemTypeName
("timetz"), -1);
8318 | CURRENT_TIME
'(' Iconst
')'
8321 * Translate as "'now'::text::timetz(n)".
8322 * See comments for CURRENT_DATE.
8326 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8327 d
= SystemTypeName
("timetz");
8328 d
->typmods
= list_make1
(makeIntConst
($3, @
3));
8329 $$
= makeTypeCast
(n
, d
, -1);
8334 * Translate as "now()", since we have a function that
8335 * does exactly what is needed.
8337 FuncCall
*n
= makeNode
(FuncCall
);
8338 n
->funcname
= SystemFuncName
("now");
8340 n
->agg_star
= FALSE
;
8341 n
->agg_distinct
= FALSE
;
8342 n
->func_variadic
= FALSE
;
8346 | CURRENT_TIMESTAMP
'(' Iconst
')'
8349 * Translate as "'now'::text::timestamptz(n)".
8350 * See comments for CURRENT_DATE.
8354 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8355 d
= SystemTypeName
("timestamptz");
8356 d
->typmods
= list_make1
(makeIntConst
($3, @
3));
8357 $$
= makeTypeCast
(n
, d
, -1);
8362 * Translate as "'now'::text::time".
8363 * See comments for CURRENT_DATE.
8366 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8367 $$
= makeTypeCast
((Node
*)n
, SystemTypeName
("time"), -1);
8369 | LOCALTIME
'(' Iconst
')'
8372 * Translate as "'now'::text::time(n)".
8373 * See comments for CURRENT_DATE.
8377 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8378 d
= SystemTypeName
("time");
8379 d
->typmods
= list_make1
(makeIntConst
($3, @
3));
8380 $$
= makeTypeCast
((Node
*)n
, d
, -1);
8385 * Translate as "'now'::text::timestamp".
8386 * See comments for CURRENT_DATE.
8389 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8390 $$
= makeTypeCast
(n
, SystemTypeName
("timestamp"), -1);
8392 | LOCALTIMESTAMP
'(' Iconst
')'
8395 * Translate as "'now'::text::timestamp(n)".
8396 * See comments for CURRENT_DATE.
8400 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8401 d
= SystemTypeName
("timestamp");
8402 d
->typmods
= list_make1
(makeIntConst
($3, @
3));
8403 $$
= makeTypeCast
(n
, d
, -1);
8407 FuncCall
*n
= makeNode
(FuncCall
);
8408 n
->funcname
= SystemFuncName
("current_user");
8410 n
->agg_star
= FALSE
;
8411 n
->agg_distinct
= FALSE
;
8412 n
->func_variadic
= FALSE
;
8418 FuncCall
*n
= makeNode
(FuncCall
);
8419 n
->funcname
= SystemFuncName
("current_user");
8421 n
->agg_star
= FALSE
;
8422 n
->agg_distinct
= FALSE
;
8423 n
->func_variadic
= FALSE
;
8429 FuncCall
*n
= makeNode
(FuncCall
);
8430 n
->funcname
= SystemFuncName
("session_user");
8432 n
->agg_star
= FALSE
;
8433 n
->agg_distinct
= FALSE
;
8434 n
->func_variadic
= FALSE
;
8440 FuncCall
*n
= makeNode
(FuncCall
);
8441 n
->funcname
= SystemFuncName
("current_user");
8443 n
->agg_star
= FALSE
;
8444 n
->agg_distinct
= FALSE
;
8445 n
->func_variadic
= FALSE
;
8451 FuncCall
*n
= makeNode
(FuncCall
);
8452 n
->funcname
= SystemFuncName
("current_database");
8454 n
->agg_star
= FALSE
;
8455 n
->agg_distinct
= FALSE
;
8456 n
->func_variadic
= FALSE
;
8462 FuncCall
*n
= makeNode
(FuncCall
);
8463 n
->funcname
= SystemFuncName
("current_schema");
8465 n
->agg_star
= FALSE
;
8466 n
->agg_distinct
= FALSE
;
8467 n
->func_variadic
= FALSE
;
8471 | CAST
'(' a_expr AS Typename
')'
8472 { $$
= makeTypeCast
($3, $5, @
1); }
8473 | EXTRACT
'(' extract_list
')'
8475 FuncCall
*n
= makeNode
(FuncCall
);
8476 n
->funcname
= SystemFuncName
("date_part");
8478 n
->agg_star
= FALSE
;
8479 n
->agg_distinct
= FALSE
;
8480 n
->func_variadic
= FALSE
;
8484 | OVERLAY
'(' overlay_list
')'
8486 /* overlay(A PLACING B FROM C FOR D) is converted to
8487 * substring(A, 1, C-1) || B || substring(A, C+1, C+D)
8488 * overlay(A PLACING B FROM C) is converted to
8489 * substring(A, 1, C-1) || B || substring(A, C+1, C+char_length(B))
8491 FuncCall
*n
= makeNode
(FuncCall
);
8492 n
->funcname
= SystemFuncName
("overlay");
8494 n
->agg_star
= FALSE
;
8495 n
->agg_distinct
= FALSE
;
8496 n
->func_variadic
= FALSE
;
8500 | POSITION
'(' position_list
')'
8502 /* position(A in B) is converted to position(B, A) */
8503 FuncCall
*n
= makeNode
(FuncCall
);
8504 n
->funcname
= SystemFuncName
("position");
8506 n
->agg_star
= FALSE
;
8507 n
->agg_distinct
= FALSE
;
8508 n
->func_variadic
= FALSE
;
8512 | SUBSTRING
'(' substr_list
')'
8514 /* substring(A from B for C) is converted to
8515 * substring(A, B, C) - thomas 2000-11-28
8517 FuncCall
*n
= makeNode
(FuncCall
);
8518 n
->funcname
= SystemFuncName
("substring");
8520 n
->agg_star
= FALSE
;
8521 n
->agg_distinct
= FALSE
;
8522 n
->func_variadic
= FALSE
;
8526 | TREAT
'(' a_expr AS Typename
')'
8528 /* TREAT(expr AS target) converts expr of a particular type to target,
8529 * which is defined to be a subtype of the original expression.
8530 * In SQL99, this is intended for use with structured UDTs,
8531 * but let's make this a generally useful form allowing stronger
8532 * coercions than are handled by implicit casting.
8534 FuncCall
*n
= makeNode
(FuncCall
);
8535 /* Convert SystemTypeName() to SystemFuncName() even though
8536 * at the moment they result in the same thing.
8538 n
->funcname
= SystemFuncName
(((Value
*)llast
($5->names
))->val.str
);
8539 n
->args
= list_make1
($3);
8540 n
->agg_star
= FALSE
;
8541 n
->agg_distinct
= FALSE
;
8542 n
->func_variadic
= FALSE
;
8546 | TRIM
'(' BOTH trim_list
')'
8548 /* various trim expressions are defined in SQL92
8549 * - thomas 1997-07-19
8551 FuncCall
*n
= makeNode
(FuncCall
);
8552 n
->funcname
= SystemFuncName
("btrim");
8554 n
->agg_star
= FALSE
;
8555 n
->agg_distinct
= FALSE
;
8556 n
->func_variadic
= FALSE
;
8560 | TRIM
'(' LEADING trim_list
')'
8562 FuncCall
*n
= makeNode
(FuncCall
);
8563 n
->funcname
= SystemFuncName
("ltrim");
8565 n
->agg_star
= FALSE
;
8566 n
->agg_distinct
= FALSE
;
8567 n
->func_variadic
= FALSE
;
8571 | TRIM
'(' TRAILING trim_list
')'
8573 FuncCall
*n
= makeNode
(FuncCall
);
8574 n
->funcname
= SystemFuncName
("rtrim");
8576 n
->agg_star
= FALSE
;
8577 n
->agg_distinct
= FALSE
;
8578 n
->func_variadic
= FALSE
;
8582 | TRIM
'(' trim_list
')'
8584 FuncCall
*n
= makeNode
(FuncCall
);
8585 n
->funcname
= SystemFuncName
("btrim");
8587 n
->agg_star
= FALSE
;
8588 n
->agg_distinct
= FALSE
;
8589 n
->func_variadic
= FALSE
;
8593 | NULLIF
'(' a_expr
',' a_expr
')'
8595 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_NULLIF
, "=", $3, $5, @
1);
8597 | COALESCE
'(' expr_list
')'
8599 CoalesceExpr
*c
= makeNode
(CoalesceExpr
);
8604 | GREATEST
'(' expr_list
')'
8606 MinMaxExpr
*v
= makeNode
(MinMaxExpr
);
8608 v
->op
= IS_GREATEST
;
8612 | LEAST
'(' expr_list
')'
8614 MinMaxExpr
*v
= makeNode
(MinMaxExpr
);
8620 | XMLCONCAT
'(' expr_list
')'
8622 $$
= makeXmlExpr
(IS_XMLCONCAT
, NULL
, NIL
, $3, @
1);
8624 | XMLELEMENT
'(' NAME_P ColLabel
')'
8626 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, NIL
, NIL
, @
1);
8628 | XMLELEMENT
'(' NAME_P ColLabel
',' xml_attributes
')'
8630 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, $6, NIL
, @
1);
8632 | XMLELEMENT
'(' NAME_P ColLabel
',' expr_list
')'
8634 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, NIL
, $6, @
1);
8636 | XMLELEMENT
'(' NAME_P ColLabel
',' xml_attributes
',' expr_list
')'
8638 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, $6, $8, @
1);
8640 | XMLFOREST
'(' xml_attribute_list
')'
8642 $$
= makeXmlExpr
(IS_XMLFOREST
, NULL
, $3, NIL
, @
1);
8644 | XMLPARSE
'(' document_or_content a_expr xml_whitespace_option
')'
8646 XmlExpr
*x
= (XmlExpr
*)
8647 makeXmlExpr
(IS_XMLPARSE
, NULL
, NIL
,
8648 list_make2
($4, makeBoolAConst
($5, -1)),
8653 | XMLPI
'(' NAME_P ColLabel
')'
8655 $$
= makeXmlExpr
(IS_XMLPI
, $4, NULL
, NIL
, @
1);
8657 | XMLPI
'(' NAME_P ColLabel
',' a_expr
')'
8659 $$
= makeXmlExpr
(IS_XMLPI
, $4, NULL
, list_make1
($6), @
1);
8661 | XMLROOT
'(' a_expr
',' xml_root_version opt_xml_root_standalone
')'
8663 $$
= makeXmlExpr
(IS_XMLROOT
, NULL
, NIL
,
8664 list_make3
($3, $5, $6), @
1);
8666 | XMLSERIALIZE
'(' document_or_content a_expr AS SimpleTypename
')'
8668 XmlSerialize
*n
= makeNode
(XmlSerialize
);
8680 xml_root_version: VERSION_P a_expr
8682 | VERSION_P NO VALUE_P
8683 { $$
= makeNullAConst
(-1); }
8686 opt_xml_root_standalone: ',' STANDALONE_P YES_P
8687 { $$
= makeIntConst
(XML_STANDALONE_YES
, -1); }
8688 |
',' STANDALONE_P NO
8689 { $$
= makeIntConst
(XML_STANDALONE_NO
, -1); }
8690 |
',' STANDALONE_P NO VALUE_P
8691 { $$
= makeIntConst
(XML_STANDALONE_NO_VALUE
, -1); }
8693 { $$
= makeIntConst
(XML_STANDALONE_OMITTED
, -1); }
8696 xml_attributes: XMLATTRIBUTES
'(' xml_attribute_list
')' { $$
= $3; }
8699 xml_attribute_list: xml_attribute_el
{ $$
= list_make1
($1); }
8700 | xml_attribute_list
',' xml_attribute_el
{ $$
= lappend
($1, $3); }
8703 xml_attribute_el: a_expr AS ColLabel
8705 $$
= makeNode
(ResTarget
);
8707 $$
->indirection
= NIL
;
8708 $$
->val
= (Node
*) $1;
8713 $$
= makeNode
(ResTarget
);
8715 $$
->indirection
= NIL
;
8716 $$
->val
= (Node
*) $1;
8721 document_or_content: DOCUMENT_P
{ $$
= XMLOPTION_DOCUMENT
; }
8722 | CONTENT_P
{ $$
= XMLOPTION_CONTENT
; }
8725 xml_whitespace_option: PRESERVE WHITESPACE_P
{ $$
= TRUE
; }
8726 | STRIP_P WHITESPACE_P
{ $$
= FALSE
; }
8727 |
/*EMPTY*/ { $$
= FALSE
; }
8731 * Supporting nonterminals for expressions.
8734 /* Explicit row production.
8736 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
8737 * without conflicting with the parenthesized a_expr production. Without the
8738 * ROW keyword, there must be more than one a_expr inside the parens.
8740 row: ROW
'(' expr_list
')' { $$
= $3; }
8741 | ROW
'(' ')' { $$
= NIL
; }
8742 |
'(' expr_list
',' a_expr
')' { $$
= lappend
($2, $4); }
8745 sub_type: ANY
{ $$
= ANY_SUBLINK
; }
8746 | SOME
{ $$
= ANY_SUBLINK
; }
8747 | ALL
{ $$
= ALL_SUBLINK
; }
8750 all_Op: Op
{ $$
= $1; }
8751 | MathOp
{ $$
= $1; }
8754 MathOp: '+' { $$
= "+"; }
8766 { $$
= list_make1
(makeString
($1)); }
8767 | OPERATOR
'(' any_operator
')'
8773 { $$
= list_make1
(makeString
($1)); }
8774 | OPERATOR
'(' any_operator
')'
8780 { $$
= list_make1
(makeString
($1)); }
8781 | OPERATOR
'(' any_operator
')'
8784 { $$
= list_make1
(makeString
("~~")); }
8786 { $$
= list_make1
(makeString
("!~~")); }
8788 { $$
= list_make1
(makeString
("~~*")); }
8790 { $$
= list_make1
(makeString
("!~~*")); }
8791 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
8792 * the regular expression is preprocessed by a function (similar_escape),
8793 * and the ~ operator for posix regular expressions is used.
8794 * x SIMILAR TO y -> x ~ similar_escape(y)
8795 * this transformation is made on the fly by the parser upwards.
8796 * however the SubLink structure which handles any/some/all stuff
8797 * is not ready for such a thing.
8803 $$
= list_make1
($1);
8805 | expr_list
',' a_expr
8807 $$
= lappend
($1, $3);
8811 type_list: Typename
{ $$
= list_make1
($1); }
8812 | type_list
',' Typename
{ $$
= lappend
($1, $3); }
8815 array_expr: '[' expr_list
']'
8817 $$
= makeAArrayExpr
($2, @
1);
8819 |
'[' array_expr_list
']'
8821 $$
= makeAArrayExpr
($2, @
1);
8825 $$
= makeAArrayExpr
(NIL
, @
1);
8829 array_expr_list: array_expr
{ $$
= list_make1
($1); }
8830 | array_expr_list
',' array_expr
{ $$
= lappend
($1, $3); }
8835 extract_arg FROM a_expr
8837 $$
= list_make2
(makeStringConst
($1, @
1), $3);
8839 |
/*EMPTY*/ { $$
= NIL
; }
8842 /* Allow delimited string SCONST in extract_arg as an SQL extension.
8843 * - thomas 2001-04-12
8847 | YEAR_P
{ $$
= "year"; }
8848 | MONTH_P
{ $$
= "month"; }
8849 | DAY_P
{ $$
= "day"; }
8850 | HOUR_P
{ $$
= "hour"; }
8851 | MINUTE_P
{ $$
= "minute"; }
8852 | SECOND_P
{ $$
= "second"; }
8853 | SCONST
{ $$
= $1; }
8856 /* OVERLAY() arguments
8857 * SQL99 defines the OVERLAY() function:
8858 * o overlay(text placing text from int for int)
8859 * o overlay(text placing text from int)
8862 a_expr overlay_placing substr_from substr_for
8864 $$
= list_make4
($1, $2, $3, $4);
8866 | a_expr overlay_placing substr_from
8868 $$
= list_make3
($1, $2, $3);
8877 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
8880 b_expr IN_P b_expr
{ $$
= list_make2
($3, $1); }
8881 |
/*EMPTY*/ { $$
= NIL
; }
8884 /* SUBSTRING() arguments
8885 * SQL9x defines a specific syntax for arguments to SUBSTRING():
8886 * o substring(text from int for int)
8887 * o substring(text from int) get entire string from starting point "int"
8888 * o substring(text for int) get first "int" characters of string
8889 * o substring(text from pattern) get entire string matching pattern
8890 * o substring(text from pattern for escape) same with specified escape char
8891 * We also want to support generic substring functions which accept
8892 * the usual generic list of arguments. So we will accept both styles
8893 * here, and convert the SQL9x style to the generic list for further
8894 * processing. - thomas 2000-11-28
8897 a_expr substr_from substr_for
8899 $$
= list_make3
($1, $2, $3);
8901 | a_expr substr_for substr_from
8903 /* not legal per SQL99, but might as well allow it */
8904 $$
= list_make3
($1, $3, $2);
8906 | a_expr substr_from
8908 $$
= list_make2
($1, $2);
8913 * Since there are no cases where this syntax allows
8914 * a textual FOR value, we forcibly cast the argument
8915 * to int4. The possible matches in pg_proc are
8916 * substring(text,int4) and substring(text,text),
8917 * and we don't want the parser to choose the latter,
8918 * which it is likely to do if the second argument
8919 * is unknown or doesn't have an implicit cast to int4.
8921 $$
= list_make3
($1, makeIntConst
(1, -1),
8923 SystemTypeName
("int4"), -1));
8934 FROM a_expr
{ $$
= $2; }
8937 substr_for: FOR a_expr
{ $$
= $2; }
8940 trim_list: a_expr FROM expr_list
{ $$
= lappend
($3, $1); }
8941 | FROM expr_list
{ $$
= $2; }
8942 | expr_list
{ $$
= $1; }
8945 in_expr: select_with_parens
8947 SubLink
*n
= makeNode
(SubLink
);
8949 /* other fields will be filled later */
8952 |
'(' expr_list
')' { $$
= (Node
*)$2; }
8956 * Define SQL92-style case clause.
8957 * - Full specification
8958 * CASE WHEN a = b THEN c ... ELSE d END
8959 * - Implicit argument
8960 * CASE a WHEN b THEN c ... ELSE d END
8962 case_expr: CASE case_arg when_clause_list case_default END_P
8964 CaseExpr
*c
= makeNode
(CaseExpr
);
8965 c
->casetype
= InvalidOid
; /* not analyzed yet */
8966 c
->arg
= (Expr
*) $2;
8968 c
->defresult
= (Expr
*) $4;
8975 /* There must be at least one */
8976 when_clause
{ $$
= list_make1
($1); }
8977 | when_clause_list when_clause
{ $$
= lappend
($1, $2); }
8981 WHEN a_expr THEN a_expr
8983 CaseWhen
*w
= makeNode
(CaseWhen
);
8984 w
->expr
= (Expr
*) $2;
8985 w
->result
= (Expr
*) $4;
8992 ELSE a_expr
{ $$
= $2; }
8993 |
/*EMPTY*/ { $$
= NULL
; }
8996 case_arg: a_expr
{ $$
= $1; }
8997 |
/*EMPTY*/ { $$
= NULL
; }
9001 * columnref starts with relation_name not ColId, so that OLD and NEW
9002 * references can be accepted. Note that when there are more than two
9003 * dotted names, the first name is not actually a relation name...
9005 columnref: relation_name
9007 $$
= makeColumnRef
($1, NIL
, @
1);
9009 | relation_name indirection
9011 $$
= makeColumnRef
($1, $2, @
1);
9018 $$
= (Node
*) makeString
($2);
9022 $$
= (Node
*) makeNode
(A_Star
);
9026 A_Indices
*ai
= makeNode
(A_Indices
);
9031 |
'[' a_expr
':' a_expr
']'
9033 A_Indices
*ai
= makeNode
(A_Indices
);
9041 indirection_el
{ $$
= list_make1
($1); }
9042 | indirection indirection_el
{ $$
= lappend
($1, $2); }
9046 /*EMPTY*/ { $$
= NIL
; }
9047 | opt_indirection indirection_el
{ $$
= lappend
($1, $2); }
9050 opt_asymmetric: ASYMMETRIC
9055 * The SQL spec defines "contextually typed value expressions" and
9056 * "contextually typed row value constructors", which for our purposes
9057 * are the same as "a_expr" and "row" except that DEFAULT can appear at
9062 a_expr
{ $$
= (Node
*) $1; }
9065 SetToDefault
*n
= makeNode
(SetToDefault
);
9072 ctext_expr
{ $$
= list_make1
($1); }
9073 | ctext_expr_list
',' ctext_expr
{ $$
= lappend
($1, $3); }
9077 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
9078 * making VALUES a fully reserved word, which will probably break more apps
9079 * than allowing the noise-word is worth.
9081 ctext_row: '(' ctext_expr_list
')' { $$
= $2; }
9085 /*****************************************************************************
9087 * target list for SELECT
9089 *****************************************************************************/
9092 target_el
{ $$
= list_make1
($1); }
9093 | target_list
',' target_el
{ $$
= lappend
($1, $3); }
9096 target_el: a_expr AS ColLabel
9098 $$
= makeNode
(ResTarget
);
9100 $$
->indirection
= NIL
;
9101 $$
->val
= (Node
*)$1;
9105 * We support omitting AS only for column labels that aren't
9106 * any known keyword. There is an ambiguity against postfix
9107 * operators: is "a ! b" an infix expression, or a postfix
9108 * expression and a column label? We prefer to resolve this
9109 * as an infix expression, which we accomplish by assigning
9110 * IDENT a precedence higher than POSTFIXOP.
9114 $$
= makeNode
(ResTarget
);
9116 $$
->indirection
= NIL
;
9117 $$
->val
= (Node
*)$1;
9122 $$
= makeNode
(ResTarget
);
9124 $$
->indirection
= NIL
;
9125 $$
->val
= (Node
*)$1;
9130 ColumnRef
*n
= makeNode
(ColumnRef
);
9131 n
->fields
= list_make1
(makeNode
(A_Star
));
9134 $$
= makeNode
(ResTarget
);
9136 $$
->indirection
= NIL
;
9137 $$
->val
= (Node
*)n
;
9143 /*****************************************************************************
9145 * Names and constants
9147 *****************************************************************************/
9150 SpecialRuleRelation
{ $$
= $1; }
9151 | ColId
{ $$
= $1; }
9154 qualified_name_list:
9155 qualified_name
{ $$
= list_make1
($1); }
9156 | qualified_name_list
',' qualified_name
{ $$
= lappend
($1, $3); }
9160 * The production for a qualified relation name has to exactly match the
9161 * production for a qualified func_name, because in a FROM clause we cannot
9162 * tell which we are parsing until we see what comes after it ('(' for a
9163 * func_name, something else for a relation). Therefore we allow 'indirection'
9164 * which may contain subscripts, and reject that case in the C code.
9169 $$
= makeNode
(RangeVar
);
9170 $$
->catalogname
= NULL
;
9171 $$
->schemaname
= NULL
;
9175 | relation_name indirection
9177 check_qualified_name
($2);
9178 $$
= makeNode
(RangeVar
);
9179 switch
(list_length
($2))
9182 $$
->catalogname
= NULL
;
9183 $$
->schemaname
= $1;
9184 $$
->relname
= strVal
(linitial
($2));
9187 $$
->catalogname
= $1;
9188 $$
->schemaname
= strVal
(linitial
($2));
9189 $$
->relname
= strVal
(lsecond
($2));
9193 (errcode
(ERRCODE_SYNTAX_ERROR
),
9194 errmsg
("improper qualified name (too many dotted names): %s",
9195 NameListToString
(lcons
(makeString
($1), $2))),
9196 scanner_errposition
(@
1)));
9204 { $$
= list_make1
(makeString
($1)); }
9205 | name_list
',' name
9206 { $$
= lappend
($1, makeString
($3)); }
9210 name: ColId
{ $$
= $1; };
9218 attr_name: ColLabel
{ $$
= $1; };
9220 index_name: ColId
{ $$
= $1; };
9222 file_name: Sconst
{ $$
= $1; };
9225 * The production for a qualified func_name has to exactly match the
9226 * production for a qualified columnref, because we cannot tell which we
9227 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
9228 * anything else for a columnref). Therefore we allow 'indirection' which
9229 * may contain subscripts, and reject that case in the C code. (If we
9230 * ever implement SQL99-like methods, such syntax may actually become legal!)
9232 func_name: type_function_name
9233 { $$
= list_make1
(makeString
($1)); }
9234 | relation_name indirection
9235 { $$
= check_func_name
(lcons
(makeString
($1), $2)); }
9244 $$
= makeIntConst
($1, @
1);
9248 $$
= makeFloatConst
($1, @
1);
9252 $$
= makeStringConst
($1, @
1);
9256 $$
= makeBitStringConst
($1, @
1);
9260 /* This is a bit constant per SQL99:
9261 * Without Feature F511, "BIT data type",
9262 * a <general literal> shall not be a
9263 * <bit string literal> or a <hex string literal>.
9265 $$
= makeBitStringConst
($1, @
1);
9269 /* generic type 'literal' syntax */
9270 TypeName
*t
= makeTypeNameFromNameList
($1);
9272 $$
= makeStringConstCast
($2, @
2, t
);
9274 | func_name
'(' expr_list
')' Sconst
9276 /* generic syntax with a type modifier */
9277 TypeName
*t
= makeTypeNameFromNameList
($1);
9280 $$
= makeStringConstCast
($5, @
5, t
);
9282 | ConstTypename Sconst
9284 $$
= makeStringConstCast
($2, @
2, $1);
9286 | ConstInterval Sconst opt_interval
9290 $$
= makeStringConstCast
($2, @
2, t
);
9292 | ConstInterval
'(' Iconst
')' Sconst opt_interval
9297 if
(list_length
($6) != 1)
9299 (errcode
(ERRCODE_SYNTAX_ERROR
),
9300 errmsg
("interval precision specified twice"),
9301 scanner_errposition
(@
1)));
9302 t
->typmods
= lappend
($6, makeIntConst
($3, @
3));
9305 t
->typmods
= list_make2
(makeIntConst
(INTERVAL_FULL_RANGE
, -1),
9306 makeIntConst
($3, @
3));
9307 $$
= makeStringConstCast
($5, @
5, t
);
9311 $$
= makeBoolAConst
(TRUE
, @
1);
9315 $$
= makeBoolAConst
(FALSE
, @
1);
9319 $$
= makeNullAConst
(@
1);
9323 Iconst: ICONST
{ $$
= $1; };
9324 Sconst: SCONST
{ $$
= $1; };
9325 RoleId: ColId
{ $$
= $1; };
9327 SignedIconst: ICONST
{ $$
= $1; }
9328 |
'+' ICONST
{ $$
= + $2; }
9329 |
'-' ICONST
{ $$
= - $2; }
9333 * Name classification hierarchy.
9335 * IDENT is the lexeme returned by the lexer for identifiers that match
9336 * no known keyword. In most cases, we can accept certain keywords as
9337 * names, not only IDENTs. We prefer to accept as many such keywords
9338 * as possible to minimize the impact of "reserved words" on programmers.
9339 * So, we divide names into several possible classes. The classification
9340 * is chosen in part to make keywords acceptable as names wherever possible.
9343 /* Column identifier --- names that can be column, table, etc names.
9345 ColId: IDENT
{ $$
= $1; }
9346 | unreserved_keyword
{ $$
= pstrdup
($1); }
9347 | col_name_keyword
{ $$
= pstrdup
($1); }
9350 /* Type/function identifier --- names that can be type or function names.
9352 type_function_name: IDENT
{ $$
= $1; }
9353 | unreserved_keyword
{ $$
= pstrdup
($1); }
9354 | type_func_name_keyword
{ $$
= pstrdup
($1); }
9357 /* Column label --- allowed labels in "AS" clauses.
9358 * This presently includes *all* Postgres keywords.
9360 ColLabel: IDENT
{ $$
= $1; }
9361 | unreserved_keyword
{ $$
= pstrdup
($1); }
9362 | col_name_keyword
{ $$
= pstrdup
($1); }
9363 | type_func_name_keyword
{ $$
= pstrdup
($1); }
9364 | reserved_keyword
{ $$
= pstrdup
($1); }
9369 * Keyword category lists. Generally, every keyword present in
9370 * the Postgres grammar should appear in exactly one of these lists.
9372 * Put a new keyword into the first list that it can go into without causing
9373 * shift or reduce conflicts. The earlier lists define "less reserved"
9374 * categories of keywords.
9376 * Make sure that each keyword's category in keywords.c matches where
9377 * it is listed here. (Someday we may be able to generate these lists and
9378 * keywords.c's table from a common master list.)
9381 /* "Unreserved" keywords --- available for use as any kind of name.
9623 /* Column identifier --- keywords that can be column, table, etc names.
9625 * Many of these keywords will in fact be recognized as type or function
9626 * names too; but they have special productions for the purpose, and so
9627 * can't be treated as "generic" type or function names.
9629 * The type names appearing here are not usable as function names
9630 * because they can be followed by '(' in typename productions, which
9631 * looks too much like a function call for an LR(1) parser.
9681 /* Type/function identifier --- keywords that can be type or function names.
9683 * Most of these are keywords that are used as operators in expressions;
9684 * in general such keywords can't be column names because they would be
9685 * ambiguous with variables, but they are unambiguous as function identifiers.
9687 * Do not include POSITION, SUBSTRING, etc here since they have explicit
9688 * productions in a_expr to support the goofy SQL9x argument syntax.
9689 * - thomas 2000-11-28
9691 type_func_name_keyword:
9715 /* Reserved keyword --- these keywords are usable only as a ColLabel.
9717 * Keywords appear here if they could not be distinguished from variable,
9718 * type, or function names in some contexts. Don't put things here unless
9803 SpecialRuleRelation:
9810 (errcode
(ERRCODE_SYNTAX_ERROR
),
9811 errmsg
("OLD used in query that is not in a rule"),
9812 scanner_errposition
(@
1)));
9820 (errcode
(ERRCODE_SYNTAX_ERROR
),
9821 errmsg
("NEW used in query that is not in a rule"),
9822 scanner_errposition
(@
1)));
9829 makeColumnRef
(char *colname
, List
*indirection
, int location
)
9832 * Generate a ColumnRef node, with an A_Indirection node added if there
9833 * is any subscripting in the specified indirection list. However,
9834 * any field selection at the start of the indirection list must be
9835 * transposed into the "fields" part of the ColumnRef node.
9837 ColumnRef
*c
= makeNode
(ColumnRef
);
9841 c
->location
= location
;
9842 foreach
(l
, indirection
)
9844 if
(IsA
(lfirst
(l
), A_Indices
))
9846 A_Indirection
*i
= makeNode
(A_Indirection
);
9850 /* easy case - all indirection goes to A_Indirection */
9851 c
->fields
= list_make1
(makeString
(colname
));
9852 i
->indirection
= check_indirection
(indirection
);
9856 /* got to split the list in two */
9857 i
->indirection
= check_indirection
(list_copy_tail
(indirection
,
9859 indirection
= list_truncate
(indirection
, nfields
);
9860 c
->fields
= lcons
(makeString
(colname
), indirection
);
9862 i
->arg
= (Node
*) c
;
9865 else if
(IsA
(lfirst
(l
), A_Star
))
9867 /* We only allow '*' at the end of a ColumnRef */
9868 if
(lnext
(l
) != NULL
)
9869 yyerror("improper use of \"*\"");
9873 /* No subscripting, so all indirection gets added to field list */
9874 c
->fields
= lcons
(makeString
(colname
), indirection
);
9879 makeTypeCast
(Node
*arg
, TypeName
*typename
, int location
)
9881 TypeCast
*n
= makeNode
(TypeCast
);
9883 n
->typename
= typename
;
9884 n
->location
= location
;
9889 makeStringConst
(char *str
, int location
)
9891 A_Const
*n
= makeNode
(A_Const
);
9893 n
->val.type
= T_String
;
9894 n
->val.val.str
= str
;
9895 n
->location
= location
;
9901 makeStringConstCast
(char *str
, int location
, TypeName
*typename
)
9903 Node
*s
= makeStringConst
(str
, location
);
9905 return makeTypeCast
(s
, typename
, -1);
9909 makeIntConst
(int val
, int location
)
9911 A_Const
*n
= makeNode
(A_Const
);
9913 n
->val.type
= T_Integer
;
9914 n
->val.val.ival
= val
;
9915 n
->location
= location
;
9921 makeFloatConst
(char *str
, int location
)
9923 A_Const
*n
= makeNode
(A_Const
);
9925 n
->val.type
= T_Float
;
9926 n
->val.val.str
= str
;
9927 n
->location
= location
;
9933 makeBitStringConst
(char *str
, int location
)
9935 A_Const
*n
= makeNode
(A_Const
);
9937 n
->val.type
= T_BitString
;
9938 n
->val.val.str
= str
;
9939 n
->location
= location
;
9945 makeNullAConst
(int location
)
9947 A_Const
*n
= makeNode
(A_Const
);
9949 n
->val.type
= T_Null
;
9950 n
->location
= location
;
9956 makeAConst
(Value
*v
, int location
)
9963 n
= makeFloatConst
(v
->val.str
, location
);
9967 n
= makeIntConst
(v
->val.ival
, location
);
9972 n
= makeStringConst
(v
->val.str
, location
);
9980 * Create an A_Const string node and put it inside a boolean cast.
9983 makeBoolAConst
(bool state
, int location
)
9985 A_Const
*n
= makeNode
(A_Const
);
9987 n
->val.type
= T_String
;
9988 n
->val.val.str
= (state ?
"t" : "f");
9989 n
->location
= location
;
9991 return makeTypeCast
((Node
*)n
, SystemTypeName
("bool"), -1);
9995 * Create and populate a FuncCall node to support the OVERLAPS operator.
9998 makeOverlaps
(List
*largs
, List
*rargs
, int location
)
10000 FuncCall
*n
= makeNode
(FuncCall
);
10002 n
->funcname
= SystemFuncName
("overlaps");
10003 if
(list_length
(largs
) == 1)
10004 largs
= lappend
(largs
, largs
);
10005 else if
(list_length
(largs
) != 2)
10007 (errcode
(ERRCODE_SYNTAX_ERROR
),
10008 errmsg
("wrong number of parameters on left side of OVERLAPS expression"),
10009 scanner_errposition
(location
)));
10010 if
(list_length
(rargs
) == 1)
10011 rargs
= lappend
(rargs
, rargs
);
10012 else if
(list_length
(rargs
) != 2)
10014 (errcode
(ERRCODE_SYNTAX_ERROR
),
10015 errmsg
("wrong number of parameters on right side of OVERLAPS expression"),
10016 scanner_errposition
(location
)));
10017 n
->args
= list_concat
(largs
, rargs
);
10018 n
->agg_star
= FALSE
;
10019 n
->agg_distinct
= FALSE
;
10020 n
->func_variadic
= FALSE
;
10021 n
->location
= location
;
10025 /* check_qualified_name --- check the result of qualified_name production
10027 * It's easiest to let the grammar production for qualified_name allow
10028 * subscripts and '*', which we then must reject here.
10031 check_qualified_name
(List
*names
)
10037 if
(!IsA
(lfirst
(i
), String
))
10038 yyerror("syntax error");
10042 /* check_func_name --- check the result of func_name production
10044 * It's easiest to let the grammar production for func_name allow subscripts
10045 * and '*', which we then must reject here.
10048 check_func_name
(List
*names
)
10054 if
(!IsA
(lfirst
(i
), String
))
10055 yyerror("syntax error");
10060 /* check_indirection --- check the result of indirection production
10062 * We only allow '*' at the end of the list, but it's hard to enforce that
10063 * in the grammar, so do it here.
10066 check_indirection
(List
*indirection
)
10070 foreach
(l
, indirection
)
10072 if
(IsA
(lfirst
(l
), A_Star
))
10074 if
(lnext
(l
) != NULL
)
10075 yyerror("improper use of \"*\"");
10078 return indirection
;
10081 /* extractArgTypes()
10082 * Given a list of FunctionParameter nodes, extract a list of just the
10083 * argument types (TypeNames) for input parameters only. This is what
10084 * is needed to look up an existing function, which is what is wanted by
10085 * the productions that use this call.
10088 extractArgTypes
(List
*parameters
)
10090 List
*result
= NIL
;
10093 foreach
(i
, parameters
)
10095 FunctionParameter
*p
= (FunctionParameter
*) lfirst
(i
);
10097 if
(p
->mode
!= FUNC_PARAM_OUT
&& p
->mode
!= FUNC_PARAM_TABLE
)
10098 result
= lappend
(result
, p
->argType
);
10103 /* findLeftmostSelect()
10104 * Find the leftmost component SelectStmt in a set-operation parsetree.
10106 static SelectStmt
*
10107 findLeftmostSelect
(SelectStmt
*node
)
10109 while
(node
&& node
->op
!= SETOP_NONE
)
10111 Assert
(node
&& IsA
(node
, SelectStmt
) && node
->larg
== NULL
);
10115 /* insertSelectOptions()
10116 * Insert ORDER BY, etc into an already-constructed SelectStmt.
10118 * This routine is just to avoid duplicating code in SelectStmt productions.
10121 insertSelectOptions
(SelectStmt
*stmt
,
10122 List
*sortClause
, List
*lockingClause
,
10123 Node
*limitOffset
, Node
*limitCount
,
10124 WithClause
*withClause
)
10126 Assert
(IsA
(stmt
, SelectStmt
));
10129 * Tests here are to reject constructs like
10130 * (SELECT foo ORDER BY bar) ORDER BY baz
10134 if
(stmt
->sortClause
)
10136 (errcode
(ERRCODE_SYNTAX_ERROR
),
10137 errmsg
("multiple ORDER BY clauses not allowed"),
10138 scanner_errposition
(exprLocation
((Node
*) sortClause
))));
10139 stmt
->sortClause
= sortClause
;
10141 /* We can handle multiple locking clauses, though */
10142 stmt
->lockingClause
= list_concat
(stmt
->lockingClause
, lockingClause
);
10145 if
(stmt
->limitOffset
)
10147 (errcode
(ERRCODE_SYNTAX_ERROR
),
10148 errmsg
("multiple OFFSET clauses not allowed"),
10149 scanner_errposition
(exprLocation
(limitOffset
))));
10150 stmt
->limitOffset
= limitOffset
;
10154 if
(stmt
->limitCount
)
10156 (errcode
(ERRCODE_SYNTAX_ERROR
),
10157 errmsg
("multiple LIMIT clauses not allowed"),
10158 scanner_errposition
(exprLocation
(limitCount
))));
10159 stmt
->limitCount
= limitCount
;
10163 if
(stmt
->withClause
)
10165 (errcode
(ERRCODE_SYNTAX_ERROR
),
10166 errmsg
("multiple WITH clauses not allowed"),
10167 scanner_errposition
(exprLocation
((Node
*) withClause
))));
10168 stmt
->withClause
= withClause
;
10173 makeSetOp
(SetOperation op
, bool all
, Node
*larg
, Node
*rarg
)
10175 SelectStmt
*n
= makeNode
(SelectStmt
);
10179 n
->larg
= (SelectStmt
*) larg
;
10180 n
->rarg
= (SelectStmt
*) rarg
;
10184 /* SystemFuncName()
10185 * Build a properly-qualified reference to a built-in function.
10188 SystemFuncName
(char *name
)
10190 return list_make2
(makeString
("pg_catalog"), makeString
(name
));
10193 /* SystemTypeName()
10194 * Build a properly-qualified reference to a built-in type.
10196 * typmod is defaulted, but may be changed afterwards by caller.
10197 * Likewise for the location.
10200 SystemTypeName
(char *name
)
10202 return makeTypeNameFromNameList
(list_make2
(makeString
("pg_catalog"),
10203 makeString
(name
)));
10207 * Handle negation of a numeric constant.
10209 * Formerly, we did this here because the optimizer couldn't cope with
10210 * indexquals that looked like "var = -4" --- it wants "var = const"
10211 * and a unary minus operator applied to a constant didn't qualify.
10212 * As of Postgres 7.0, that problem doesn't exist anymore because there
10213 * is a constant-subexpression simplifier in the optimizer. However,
10214 * there's still a good reason for doing this here, which is that we can
10215 * postpone committing to a particular internal representation for simple
10216 * negative constants. It's better to leave "-123.456" in string form
10217 * until we know what the desired type is.
10220 doNegate
(Node
*n
, int location
)
10222 if
(IsA
(n
, A_Const
))
10224 A_Const
*con
= (A_Const
*)n
;
10226 /* report the constant's location as that of the '-' sign */
10227 con
->location
= location
;
10229 if
(con
->val.type
== T_Integer
)
10231 con
->val.val.ival
= -con
->val.val.ival
;
10234 if
(con
->val.type
== T_Float
)
10236 doNegateFloat
(&con
->val
);
10241 return
(Node
*) makeSimpleA_Expr
(AEXPR_OP
, "-", NULL
, n
, location
);
10245 doNegateFloat
(Value
*v
)
10247 char *oldval
= v
->val.str
;
10249 Assert
(IsA
(v
, Float
));
10250 if
(*oldval
== '+')
10252 if
(*oldval
== '-')
10253 v
->val.str
= oldval
+1; /* just strip the '-' */
10256 char *newval
= (char *) palloc
(strlen
(oldval
) + 2);
10259 strcpy
(newval
+1, oldval
);
10260 v
->val.str
= newval
;
10265 makeAArrayExpr
(List
*elements
, int location
)
10267 A_ArrayExpr
*n
= makeNode
(A_ArrayExpr
);
10269 n
->elements
= elements
;
10270 n
->location
= location
;
10275 makeXmlExpr
(XmlExprOp op
, char *name
, List
*named_args
, List
*args
,
10278 XmlExpr
*x
= makeNode
(XmlExpr
);
10283 * named_args is a list of ResTarget; it'll be split apart into separate
10284 * expression and name lists in transformXmlExpr().
10286 x
->named_args
= named_args
;
10287 x
->arg_names
= NIL
;
10289 /* xmloption, if relevant, must be filled in by caller */
10290 /* type and typmod will be filled in during parse analysis */
10291 x
->location
= location
;
10296 * Initialize to parse one query string
10301 QueryIsRule
= FALSE
;
10305 * Merge the input and output parameters of a table function.
10308 mergeTableFuncParameters
(List
*func_args
, List
*columns
)
10312 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
10313 foreach
(lc
, func_args
)
10315 FunctionParameter
*p
= (FunctionParameter
*) lfirst
(lc
);
10317 if
(p
->mode
!= FUNC_PARAM_IN
&& p
->mode
!= FUNC_PARAM_VARIADIC
)
10319 (errcode
(ERRCODE_SYNTAX_ERROR
),
10320 errmsg
("OUT and INOUT arguments aren't allowed in TABLE functions")));
10323 return list_concat
(func_args
, columns
);
10327 * Determine return type of a TABLE function. A single result column
10328 * returns setof that column's type; otherwise return setof record.
10331 TableFuncTypeName
(List
*columns
)
10335 if
(list_length
(columns
) == 1)
10337 FunctionParameter
*p
= (FunctionParameter
*) linitial
(columns
);
10339 result
= (TypeName
*) copyObject
(p
->argType
);
10342 result
= SystemTypeName
("record");
10344 result
->setof
= true
;
10350 * Must undefine base_yylex before including scan.c, since we want it
10351 * to create the function base_yylex not filtered_base_yylex.