4 /*-------------------------------------------------------------------------
7 * POSTGRES SQL YACC rules/actions
9 * Portions Copyright (c) 1996-2009, 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 "catalog/pg_trigger.h"
57 #include "commands/defrem.h"
58 #include "nodes/makefuncs.h"
59 #include "nodes/nodeFuncs.h"
60 #include "parser/gramparse.h"
61 #include "storage/lmgr.h"
62 #include "utils/date.h"
63 #include "utils/datetime.h"
64 #include "utils/numeric.h"
65 #include "utils/xml.h"
68 /* Location tracking support --- simpler than bison's default */
69 #define YYLLOC_DEFAULT(Current, Rhs, N) \
72 (Current
) = (Rhs
)[1]; \
74 (Current
) = (Rhs
)[0]; \
78 * The %name-prefix option below will make bison call base_yylex, but we
79 * really want it to call filtered_base_yylex (see parser.c).
81 #define base_yylex filtered_base_yylex
84 * Bison doesn't allocate anything that needs to live across parser calls,
85 * so we can easily have it use palloc instead of malloc. This prevents
86 * memory leaks if we error out during parsing. Note this only works with
87 * bison >= 2.0. However, in bison 1.875 the default is to use alloca()
88 * if possible, so there's not really much problem anyhow, at least if
89 * you're building with gcc.
91 #define YYMALLOC palloc
94 extern List
*parsetree
; /* final parse result is delivered here */
96 static bool QueryIsRule
= FALSE
;
98 /* Private struct for the result of privilege_target production */
99 typedef
struct PrivTarget
101 GrantObjectType objtype
;
106 * If you need access to certain yacc-generated variables and find that
107 * they're static by default, uncomment the next line. (this is not a
110 /*#define __YYSCLASS*/
112 static Node
*makeColumnRef
(char *colname
, List
*indirection
, int location
);
113 static Node
*makeTypeCast
(Node
*arg
, TypeName
*typename
, int location
);
114 static Node
*makeStringConst
(char *str
, int location
);
115 static Node
*makeStringConstCast
(char *str
, int location
, TypeName
*typename
);
116 static Node
*makeIntConst
(int val
, int location
);
117 static Node
*makeFloatConst
(char *str
, int location
);
118 static Node
*makeBitStringConst
(char *str
, int location
);
119 static Node
*makeNullAConst
(int location
);
120 static Node
*makeAConst
(Value
*v
, int location
);
121 static Node
*makeBoolAConst
(bool state
, int location
);
122 static FuncCall
*makeOverlaps
(List
*largs
, List
*rargs
, int location
);
123 static void check_qualified_name
(List
*names
);
124 static List
*check_func_name
(List
*names
);
125 static List
*check_indirection
(List
*indirection
);
126 static List
*extractArgTypes
(List
*parameters
);
127 static SelectStmt
*findLeftmostSelect
(SelectStmt
*node
);
128 static void insertSelectOptions
(SelectStmt
*stmt
,
129 List
*sortClause
, List
*lockingClause
,
130 Node
*limitOffset
, Node
*limitCount
,
131 WithClause
*withClause
);
132 static Node
*makeSetOp
(SetOperation op
, bool all
, Node
*larg
, Node
*rarg
);
133 static Node
*doNegate
(Node
*n
, int location
);
134 static void doNegateFloat
(Value
*v
);
135 static Node
*makeAArrayExpr
(List
*elements
, int location
);
136 static Node
*makeXmlExpr
(XmlExprOp op
, char *name
, List
*named_args
,
137 List
*args
, int location
);
138 static List
*mergeTableFuncParameters
(List
*func_args
, List
*columns
);
139 static TypeName
*TableFuncTypeName
(List
*columns
);
144 %name
-prefix
="base_yy"
155 DropBehavior dbehavior
;
156 OnCommitAction oncommit
;
163 FunctionParameter
*fun_param
;
164 FunctionParameterMode fun_param_mode
;
165 FuncWithArgs
*funwithargs
;
177 struct PrivTarget
*privtarget
;
178 AccessPriv
*accesspriv
;
181 VariableSetStmt
*vsetstmt
;
184 %type
<node
> stmt schema_stmt
185 AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterFdwStmt
186 AlterForeignServerStmt AlterGroupStmt
187 AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterTableStmt
188 AlterUserStmt AlterUserMappingStmt AlterUserSetStmt AlterRoleStmt AlterRoleSetStmt
189 AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
190 ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
191 CreateDomainStmt CreateGroupStmt CreateOpClassStmt
192 CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
193 CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
194 CreateFdwStmt CreateForeignServerStmt CreateAssertStmt CreateTrigStmt
195 CreateUserStmt CreateUserMappingStmt CreateRoleStmt
196 CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt
197 DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
198 DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
199 DropUserStmt DropdbStmt DropTableSpaceStmt DropFdwStmt
200 DropForeignServerStmt DropUserMappingStmt ExplainStmt FetchStmt
201 GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
202 LockStmt NotifyStmt ExplainableStmt PreparableStmt
203 CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
204 RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
205 RuleActionStmt RuleActionStmtOrEmpty RuleStmt
206 SelectStmt TransactionStmt TruncateStmt
207 UnlistenStmt UpdateStmt VacuumStmt
208 VariableResetStmt VariableSetStmt VariableShowStmt
209 ViewStmt CheckPointStmt CreateConversionStmt
210 DeallocateStmt PrepareStmt ExecuteStmt
211 DropOwnedStmt ReassignOwnedStmt
212 AlterTSConfigurationStmt AlterTSDictionaryStmt
214 %type
<node
> select_no_parens select_with_parens select_clause
215 simple_select values_clause
217 %type
<node
> alter_column_default opclass_item opclass_drop alter_using
218 %type
<ival
> add_drop opt_asc_desc opt_nulls_order
220 %type
<node
> alter_table_cmd
221 %type
<list
> alter_table_cmds
223 %type
<dbehavior
> opt_drop_behavior
225 %type
<list
> createdb_opt_list alterdb_opt_list copy_opt_list
226 transaction_mode_list
227 %type
<defelt
> createdb_opt_item alterdb_opt_item copy_opt_item
228 transaction_mode_item
230 %type
<ival
> opt_lock lock_type cast_context
231 %type
<boolean
> opt_force opt_or_replace
232 opt_grant_grant_option opt_grant_admin_option
233 opt_nowait opt_if_exists opt_with_data
235 %type
<list
> OptRoleList
236 %type
<defelt
> OptRoleElem
239 %type
<str
> foreign_server_version opt_foreign_server_version
240 %type
<str
> auth_ident
242 %type
<str
> OptSchemaName
243 %type
<list
> OptSchemaEltList
245 %type
<boolean
> TriggerActionTime TriggerForSpec opt_trusted opt_restart_seqs
246 %type
<str
> opt_lancompiler
248 %type
<ival
> TriggerEvents TriggerOneEvent
249 %type
<value
> TriggerFuncArg
251 %type
<str
> relation_name copy_file_name
252 database_name access_method_clause access_method attr_name
253 index_name name file_name cluster_index_specification
255 %type
<list
> func_name handler_name qual_Op qual_all_Op subquery_Op
256 opt_class opt_validator validator_clause
258 %type
<range
> qualified_name OptConstrFromTable
260 %type
<str
> all_Op MathOp SpecialRuleRelation
262 %type
<str
> iso_level opt_encoding
264 %type
<list
> grantee_list
265 %type
<accesspriv
> privilege
266 %type
<list
> privileges privilege_list
267 %type
<privtarget
> privilege_target
268 %type
<funwithargs
> function_with_argtypes
269 %type
<list
> function_with_argtypes_list
271 %type
<list
> stmtblock stmtmulti
272 OptTableElementList TableElementList OptInherit definition
273 reloptions opt_reloptions
274 OptWith opt_distinct opt_definition func_args func_args_list
275 func_args_with_defaults func_args_with_defaults_list
276 func_as createfunc_opt_list alterfunc_opt_list
277 aggr_args old_aggr_definition old_aggr_list
278 oper_argtypes RuleActionList RuleActionMulti
279 opt_column_list columnList opt_name_list
280 sort_clause opt_sort_clause sortby_list index_params
281 name_list from_clause from_list opt_array_bounds
282 qualified_name_list any_name any_name_list
283 any_operator expr_list attrs
284 target_list insert_column_list set_target_list
285 set_clause_list set_clause multiple_set_clause
286 ctext_expr_list ctext_row def_list indirection opt_indirection
287 reloption_list group_clause TriggerFuncArgs select_limit
288 opt_select_limit opclass_item_list opclass_drop_list
289 opt_opfamily transaction_mode_list_or_empty
290 TableFuncElementList opt_type_modifiers
292 execute_param_clause using_clause returning_clause
293 enum_val_list table_func_column_list
294 create_generic_options alter_generic_options
297 %type
<range
> OptTempTableName
298 %type
<into
> into_clause create_as_target
300 %type
<defelt
> createfunc_opt_item common_func_opt_item
301 %type
<fun_param
> func_arg func_arg_with_default table_func_column
302 %type
<fun_param_mode
> arg_class
303 %type
<typnam
> func_return func_type
305 %type
<boolean
> TriggerForType OptTemp
306 %type
<oncommit
> OnCommitOption
308 %type
<node
> for_locking_item
309 %type
<list
> for_locking_clause opt_for_locking_clause for_locking_items
310 %type
<list
> locked_rels_list
311 %type
<boolean
> opt_all
313 %type
<node
> join_outer join_qual
314 %type
<jtype
> join_type
316 %type
<list
> extract_list overlay_list position_list
317 %type
<list
> substr_list trim_list
318 %type
<list
> opt_interval interval_second
319 %type
<node
> overlay_placing substr_from substr_for
321 %type
<boolean
> opt_instead opt_analyze
322 %type
<boolean
> index_opt_unique opt_verbose opt_full
323 %type
<boolean
> opt_freeze opt_default opt_recheck
324 %type
<defelt
> opt_binary opt_oids copy_delimiter
326 %type
<boolean
> copy_from
328 %type
<ival
> opt_column event cursor_options opt_hold opt_set_data
329 %type
<objtype
> reindex_type drop_type comment_type
331 %type
<node
> fetch_direction select_limit_value select_offset_value
332 select_offset_value2 opt_select_fetch_first_value
333 %type
<ival
> row_or_rows first_or_next
335 %type
<list
> OptSeqOptList SeqOptList
336 %type
<defelt
> SeqOptElem
338 %type
<istmt
> insert_rest
340 %type
<vsetstmt
> set_rest SetResetClause
342 %type
<node
> TableElement ConstraintElem TableFuncElement
343 %type
<node
> columnDef
344 %type
<defelt
> def_elem reloption_elem old_aggr_elem
345 %type
<node
> def_arg columnElem where_clause where_or_current_clause
346 a_expr b_expr c_expr func_expr AexprConst indirection_el
347 columnref in_expr having_clause func_table array_expr
348 %type
<list
> row type_list array_expr_list
349 %type
<node
> case_expr case_arg when_clause case_default
350 %type
<list
> when_clause_list
351 %type
<ival
> sub_type
352 %type
<list
> OptCreateAs CreateAsList
353 %type
<node
> CreateAsElement ctext_expr
354 %type
<value
> NumericOnly
355 %type
<alias
> alias_clause
356 %type
<sortby
> sortby
357 %type
<ielem
> index_elem
358 %type
<node
> table_ref
359 %type
<jexpr
> joined_table
360 %type
<range
> relation_expr
361 %type
<range
> relation_expr_opt_alias
362 %type
<target
> target_el single_set_clause set_target insert_column_item
364 %type
<str
> generic_option_name
365 %type
<node
> generic_option_arg
366 %type
<defelt
> generic_option_elem alter_generic_option_elem
367 %type
<list
> generic_option_list alter_generic_option_list
369 %type
<typnam
> Typename SimpleTypename ConstTypename
370 GenericType Numeric opt_float
371 Character ConstCharacter
372 CharacterWithLength CharacterWithoutLength
373 ConstDatetime ConstInterval
374 Bit ConstBit BitWithLength BitWithoutLength
375 %type
<str
> character
376 %type
<str
> extract_arg
377 %type
<str
> opt_charset
378 %type
<boolean
> opt_varying opt_timezone
380 %type
<ival
> Iconst SignedIconst
381 %type
<str
> Sconst comment_text
382 %type
<str
> RoleId opt_granted_by opt_boolean ColId_or_Sconst
383 %type
<list
> var_list
384 %type
<str
> ColId ColLabel var_name type_function_name param_name
385 %type
<node
> var_value zone_value
387 %type
<keyword
> unreserved_keyword type_func_name_keyword
388 %type
<keyword
> col_name_keyword reserved_keyword
390 %type
<node
> TableConstraint TableLikeClause
391 %type
<list
> TableLikeOptionList
392 %type
<ival
> TableLikeOption
393 %type
<list
> ColQualList
394 %type
<node
> ColConstraint ColConstraintElem ConstraintAttr
395 %type
<ival
> key_actions key_delete key_match key_update key_action
396 %type
<ival
> ConstraintAttributeSpec ConstraintDeferrabilitySpec
399 %type
<list
> constraints_set_list
400 %type
<boolean
> constraints_set_mode
401 %type
<str
> OptTableSpace OptConsTableSpace OptTableSpaceOwner
402 %type
<list
> opt_check_option
404 %type
<target
> xml_attribute_el
405 %type
<list
> xml_attribute_list xml_attributes
406 %type
<node
> xml_root_version opt_xml_root_standalone
407 %type
<ival
> document_or_content
408 %type
<boolean
> xml_whitespace_option
410 %type
<node
> common_table_expr
411 %type
<with
> with_clause
412 %type
<list
> cte_list
414 %type
<list
> window_clause window_definition_list opt_partition_clause
415 %type
<windef
> window_definition over_clause window_specification
416 %type
<str
> opt_existing_window_name
417 %type
<ival
> opt_frame_clause frame_extent frame_bound
421 * If you make any token changes, update the keyword table in
422 * src/include/parser/kwlist.h and add new keywords to the appropriate one of
423 * the reserved-or-not-so-reserved keyword lists, below; search
424 * this file for "Name classification hierarchy".
427 /* ordinary key words in alphabetical order */
428 %token
<keyword
> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
429 AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
430 ASSERTION ASSIGNMENT ASYMMETRIC AT AUTHORIZATION
432 BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
435 CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
436 CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
437 CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT
438 COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
439 CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB
440 CREATEROLE CREATEUSER CROSS CSV CURRENT_P
441 CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
442 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
444 DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
445 DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
446 DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
448 EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT
449 EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
451 FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOLLOWING FOR FORCE FOREIGN FORWARD
452 FREEZE FROM FULL FUNCTION
454 GLOBAL GRANT GRANTED GREATEST GROUP_P
456 HANDLER HAVING HEADER_P HOLD HOUR_P
458 IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
459 INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY
460 INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
461 INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
467 LANCOMPILER LANGUAGE LARGE_P LAST_P LC_COLLATE_P LC_CTYPE_P LEADING
468 LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP
469 LOCATION LOCK_P LOGIN_P
471 MAPPING MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
473 NAME_P NAMES NATIONAL NATURAL NCHAR NEW NEXT NO NOCREATEDB
474 NOCREATEROLE NOCREATEUSER NOINHERIT NOLOGIN_P NONE NOSUPERUSER
475 NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NULLS_P NUMERIC
477 OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OPTIONS OR
478 ORDER OUT_P OUTER_P OVER OVERLAPS OVERLAY OWNED OWNER
480 PARSER PARTIAL PARTITION PASSWORD PLACING PLANS POSITION
481 PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
482 PRIOR PRIVILEGES PROCEDURAL PROCEDURE
486 RANGE READ REAL REASSIGN RECHECK RECURSIVE REFERENCES REINDEX
487 RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA RESET RESTART
488 RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROW ROWS RULE
490 SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE
491 SERIALIZABLE SERVER SESSION SESSION_USER SET SETOF SHARE
492 SHOW SIMILAR SIMPLE SMALLINT SOME STABLE STANDALONE_P START STATEMENT
493 STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING SUPERUSER_P
494 SYMMETRIC SYSID SYSTEM_P
496 TABLE TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
497 TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
498 TRUNCATE TRUSTED TYPE_P
500 UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
503 VACUUM VALID VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
504 VERBOSE VERSION_P VIEW VOLATILE
506 WHEN WHERE WHITESPACE_P WINDOW WITH WITHOUT WORK WRAPPER WRITE
508 XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLFOREST XMLPARSE
509 XMLPI XMLROOT XMLSERIALIZE
515 /* The grammar thinks these are keywords, but they are not in the kwlist.h
516 * list and so can never be entered directly. The filter in parser.c
517 * creates these tokens when required.
519 %token NULLS_FIRST NULLS_LAST WITH_TIME
521 /* Special token types, not actually keywords - see the "lex" file */
522 %token
<str
> IDENT FCONST SCONST BCONST XCONST Op
523 %token
<ival
> ICONST PARAM
525 /* precedence: lowest to highest */
526 %nonassoc SET
/* see relation_expr_opt_alias */
534 %nonassoc LIKE ILIKE SIMILAR
539 %left POSTFIXOP
/* dummy for postfix Op rules */
541 * To support target_el without AS, we must give IDENT an explicit priority
542 * between POSTFIXOP and Op. We can safely assign the same priority to
543 * various unreserved keywords as needed to resolve ambiguities (this can't
544 * have any bad effects since obviously the keywords will still behave the
545 * same as if they weren't keywords). We need to do this for PARTITION,
546 * RANGE, ROWS to support opt_existing_window_name; and for RANGE, ROWS
547 * so that they can follow a_expr without creating
548 * postfix-operator problems.
550 %nonassoc IDENT PARTITION RANGE ROWS
551 %left Op OPERATOR
/* multi-character ops and user-defined operators */
554 %nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN
/* sets precedence for IS NULL, etc */
558 /* Unary Operators */
559 %left AT ZONE
/* sets precedence for AT TIME ZONE */
566 * These might seem to be low-precedence, but actually they are not part
567 * of the arithmetic hierarchy at all in their use as JOIN operators.
568 * We make them high-precedence to support their use as function names.
569 * They wouldn't be given a precedence at all, were it not that we need
570 * left-associativity among the JOIN rules themselves.
572 %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
573 /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
574 %right PRESERVE STRIP_P
578 * Handle comment-only lines, and ;; SELECT * FROM pg_class ;;;
579 * psql already handles such cases, but other interfaces don't.
582 stmtblock: stmtmulti
{ parsetree
= $1; }
585 /* the thrashing around here is to discard "empty" statements... */
586 stmtmulti: stmtmulti
';' stmt
588 $$
= lappend
($1, $3);
602 | AlterDatabaseSetStmt
605 | AlterForeignServerStmt
608 | AlterObjectSchemaStmt
614 | AlterTSConfigurationStmt
615 | AlterTSDictionaryStmt
616 | AlterUserMappingStmt
629 | CreateConversionStmt
632 | CreateForeignServerStmt
642 | CreateTableSpaceStmt
646 | CreateUserMappingStmt
656 | DropForeignServerStmt
668 | DropUserMappingStmt
705 /*****************************************************************************
707 * Create a new Postgres DBMS role
709 *****************************************************************************/
712 CREATE ROLE RoleId opt_with OptRoleList
714 CreateRoleStmt
*n
= makeNode
(CreateRoleStmt
);
715 n
->stmt_type
= ROLESTMT_ROLE
;
728 * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
729 * for backwards compatibility). Note: the only option required by SQL99
730 * is "WITH ADMIN name".
733 OptRoleList OptRoleElem
{ $$
= lappend
($1, $2); }
734 |
/* EMPTY */ { $$
= NIL
; }
740 $$
= makeDefElem
("password",
741 (Node
*)makeString
($2));
745 $$
= makeDefElem
("password", NULL
);
747 | ENCRYPTED PASSWORD Sconst
749 $$
= makeDefElem
("encryptedPassword",
750 (Node
*)makeString
($3));
752 | UNENCRYPTED PASSWORD Sconst
754 $$
= makeDefElem
("unencryptedPassword",
755 (Node
*)makeString
($3));
759 $$
= makeDefElem
("superuser", (Node
*)makeInteger
(TRUE
));
763 $$
= makeDefElem
("superuser", (Node
*)makeInteger
(FALSE
));
767 $$
= makeDefElem
("inherit", (Node
*)makeInteger
(TRUE
));
771 $$
= makeDefElem
("inherit", (Node
*)makeInteger
(FALSE
));
775 $$
= makeDefElem
("createdb", (Node
*)makeInteger
(TRUE
));
779 $$
= makeDefElem
("createdb", (Node
*)makeInteger
(FALSE
));
783 $$
= makeDefElem
("createrole", (Node
*)makeInteger
(TRUE
));
787 $$
= makeDefElem
("createrole", (Node
*)makeInteger
(FALSE
));
791 /* For backwards compatibility, synonym for SUPERUSER */
792 $$
= makeDefElem
("superuser", (Node
*)makeInteger
(TRUE
));
796 $$
= makeDefElem
("superuser", (Node
*)makeInteger
(FALSE
));
800 $$
= makeDefElem
("canlogin", (Node
*)makeInteger
(TRUE
));
804 $$
= makeDefElem
("canlogin", (Node
*)makeInteger
(FALSE
));
806 | CONNECTION LIMIT SignedIconst
808 $$
= makeDefElem
("connectionlimit", (Node
*)makeInteger
($3));
812 $$
= makeDefElem
("validUntil", (Node
*)makeString
($3));
814 /* Supported but not documented for roles, for use by ALTER GROUP. */
817 $$
= makeDefElem
("rolemembers", (Node
*)$2);
819 /* The following are not supported by ALTER ROLE/USER/GROUP */
822 $$
= makeDefElem
("sysid", (Node
*)makeInteger
($2));
826 $$
= makeDefElem
("adminmembers", (Node
*)$2);
830 $$
= makeDefElem
("rolemembers", (Node
*)$2);
832 | IN_P ROLE name_list
834 $$
= makeDefElem
("addroleto", (Node
*)$3);
836 | IN_P GROUP_P name_list
838 $$
= makeDefElem
("addroleto", (Node
*)$3);
843 /*****************************************************************************
845 * Create a new Postgres DBMS user (role with implied login ability)
847 *****************************************************************************/
850 CREATE USER RoleId opt_with OptRoleList
852 CreateRoleStmt
*n
= makeNode
(CreateRoleStmt
);
853 n
->stmt_type
= ROLESTMT_USER
;
861 /*****************************************************************************
863 * Alter a postgresql DBMS role
865 *****************************************************************************/
868 ALTER ROLE RoleId opt_with OptRoleList
870 AlterRoleStmt
*n
= makeNode
(AlterRoleStmt
);
872 n
->action
= +1; /* add, if there are members */
879 ALTER ROLE RoleId SetResetClause
881 AlterRoleSetStmt
*n
= makeNode
(AlterRoleSetStmt
);
889 /*****************************************************************************
891 * Alter a postgresql DBMS user
893 *****************************************************************************/
896 ALTER USER RoleId opt_with OptRoleList
898 AlterRoleStmt
*n
= makeNode
(AlterRoleStmt
);
900 n
->action
= +1; /* add, if there are members */
908 ALTER USER RoleId SetResetClause
910 AlterRoleSetStmt
*n
= makeNode
(AlterRoleSetStmt
);
918 /*****************************************************************************
920 * Drop a postgresql DBMS role
922 * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
923 * might own objects in multiple databases, there is presently no way to
924 * implement either cascading or restricting. Caveat DBA.
925 *****************************************************************************/
930 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
931 n
->missing_ok
= FALSE
;
935 | DROP ROLE IF_P EXISTS name_list
937 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
938 n
->missing_ok
= TRUE
;
944 /*****************************************************************************
946 * Drop a postgresql DBMS user
948 * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
949 * might own objects in multiple databases, there is presently no way to
950 * implement either cascading or restricting. Caveat DBA.
951 *****************************************************************************/
956 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
957 n
->missing_ok
= FALSE
;
961 | DROP USER IF_P EXISTS name_list
963 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
965 n
->missing_ok
= TRUE
;
971 /*****************************************************************************
973 * Create a postgresql group (role without login ability)
975 *****************************************************************************/
978 CREATE GROUP_P RoleId opt_with OptRoleList
980 CreateRoleStmt
*n
= makeNode
(CreateRoleStmt
);
981 n
->stmt_type
= ROLESTMT_GROUP
;
989 /*****************************************************************************
991 * Alter a postgresql group
993 *****************************************************************************/
996 ALTER GROUP_P RoleId add_drop USER name_list
998 AlterRoleStmt
*n
= makeNode
(AlterRoleStmt
);
1001 n
->options
= list_make1
(makeDefElem
("rolemembers",
1007 add_drop: ADD_P
{ $$
= +1; }
1012 /*****************************************************************************
1014 * Drop a postgresql group
1016 * XXX see above notes about cascading DROP USER; groups have same problem.
1017 *****************************************************************************/
1020 DROP GROUP_P name_list
1022 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
1023 n
->missing_ok
= FALSE
;
1027 | DROP GROUP_P IF_P EXISTS name_list
1029 DropRoleStmt
*n
= makeNode
(DropRoleStmt
);
1030 n
->missing_ok
= TRUE
;
1037 /*****************************************************************************
1039 * Manipulate a schema
1041 *****************************************************************************/
1044 CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
1046 CreateSchemaStmt
*n
= makeNode
(CreateSchemaStmt
);
1047 /* One can omit the schema name or the authorization id. */
1056 | CREATE SCHEMA ColId OptSchemaEltList
1058 CreateSchemaStmt
*n
= makeNode
(CreateSchemaStmt
);
1059 /* ...but not both */
1069 |
/* EMPTY */ { $$
= NULL
; }
1073 OptSchemaEltList schema_stmt
{ $$
= lappend
($1, $2); }
1074 |
/* EMPTY */ { $$
= NIL
; }
1078 * schema_stmt are the ones that can show up inside a CREATE SCHEMA
1079 * statement (in addition to by themselves).
1091 /*****************************************************************************
1093 * Set PG internal variable
1094 * SET name TO 'var_value'
1095 * Include SQL92 syntax (thomas 1997-10-22):
1096 * SET TIME ZONE 'var_value'
1098 *****************************************************************************/
1103 VariableSetStmt
*n
= $2;
1104 n
->is_local
= false
;
1107 | SET LOCAL set_rest
1109 VariableSetStmt
*n
= $3;
1113 | SET SESSION set_rest
1115 VariableSetStmt
*n
= $3;
1116 n
->is_local
= false
;
1121 set_rest: /* Generic SET syntaxes: */
1122 var_name TO var_list
1124 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1125 n
->kind
= VAR_SET_VALUE
;
1130 | var_name
'=' var_list
1132 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1133 n
->kind
= VAR_SET_VALUE
;
1138 | var_name TO DEFAULT
1140 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1141 n
->kind
= VAR_SET_DEFAULT
;
1145 | var_name
'=' DEFAULT
1147 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1148 n
->kind
= VAR_SET_DEFAULT
;
1152 | var_name FROM CURRENT_P
1154 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1155 n
->kind
= VAR_SET_CURRENT
;
1159 /* Special syntaxes mandated by SQL standard: */
1160 | TIME ZONE zone_value
1162 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1163 n
->kind
= VAR_SET_VALUE
;
1164 n
->name
= "timezone";
1166 n
->args
= list_make1
($3);
1168 n
->kind
= VAR_SET_DEFAULT
;
1171 | TRANSACTION transaction_mode_list
1173 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1174 n
->kind
= VAR_SET_MULTI
;
1175 n
->name
= "TRANSACTION";
1179 | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
1181 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1182 n
->kind
= VAR_SET_MULTI
;
1183 n
->name
= "SESSION CHARACTERISTICS";
1190 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
1191 errmsg
("current database cannot be changed"),
1192 scanner_errposition
(@
2)));
1193 $$
= NULL
; /*not reached*/
1197 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1198 n
->kind
= VAR_SET_VALUE
;
1199 n
->name
= "search_path";
1200 n
->args
= list_make1
(makeStringConst
($2, @
2));
1203 | NAMES opt_encoding
1205 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1206 n
->kind
= VAR_SET_VALUE
;
1207 n
->name
= "client_encoding";
1209 n
->args
= list_make1
(makeStringConst
($2, @
2));
1211 n
->kind
= VAR_SET_DEFAULT
;
1214 | ROLE ColId_or_Sconst
1216 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1217 n
->kind
= VAR_SET_VALUE
;
1219 n
->args
= list_make1
(makeStringConst
($2, @
2));
1222 | SESSION AUTHORIZATION ColId_or_Sconst
1224 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1225 n
->kind
= VAR_SET_VALUE
;
1226 n
->name
= "session_authorization";
1227 n
->args
= list_make1
(makeStringConst
($3, @
3));
1230 | SESSION AUTHORIZATION DEFAULT
1232 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1233 n
->kind
= VAR_SET_DEFAULT
;
1234 n
->name
= "session_authorization";
1237 | XML_P OPTION document_or_content
1239 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1240 n
->kind
= VAR_SET_VALUE
;
1241 n
->name
= "xmloption";
1242 n
->args
= list_make1
(makeStringConst
($3 == XMLOPTION_DOCUMENT ?
"DOCUMENT" : "CONTENT", @
3));
1247 var_name: ColId
{ $$
= $1; }
1248 | var_name
'.' ColId
1250 $$
= palloc
(strlen
($1) + strlen
($3) + 2);
1251 sprintf
($$
, "%s.%s", $1, $3);
1255 var_list: var_value
{ $$
= list_make1
($1); }
1256 | var_list
',' var_value
{ $$
= lappend
($1, $3); }
1259 var_value: opt_boolean
1260 { $$
= makeStringConst
($1, @
1); }
1262 { $$
= makeStringConst
($1, @
1); }
1264 { $$
= makeAConst
($1, @
1); }
1267 iso_level: READ UNCOMMITTED
{ $$
= "read uncommitted"; }
1268 | READ COMMITTED
{ $$
= "read committed"; }
1269 | REPEATABLE READ
{ $$
= "repeatable read"; }
1270 | SERIALIZABLE
{ $$
= "serializable"; }
1274 TRUE_P
{ $$
= "true"; }
1275 | FALSE_P
{ $$
= "false"; }
1277 | OFF
{ $$
= "off"; }
1280 /* Timezone values can be:
1281 * - a string such as 'pst8pdt'
1282 * - an identifier such as "pst8pdt"
1283 * - an integer or floating point number
1284 * - a time interval per SQL99
1285 * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
1286 * so use IDENT (meaning we reject anything that is a key word).
1291 $$
= makeStringConst
($1, @
1);
1295 $$
= makeStringConst
($1, @
1);
1297 | ConstInterval Sconst opt_interval
1302 A_Const
*n
= (A_Const
*) linitial
($3);
1303 if
((n
->val.val.ival
& ~
(INTERVAL_MASK
(HOUR
) | INTERVAL_MASK
(MINUTE
))) != 0)
1305 (errcode
(ERRCODE_SYNTAX_ERROR
),
1306 errmsg
("time zone interval must be HOUR or HOUR TO MINUTE"),
1307 scanner_errposition
(@
3)));
1310 $$
= makeStringConstCast
($2, @
2, t
);
1312 | ConstInterval
'(' Iconst
')' Sconst opt_interval
1317 A_Const
*n
= (A_Const
*) linitial
($6);
1318 if
((n
->val.val.ival
& ~
(INTERVAL_MASK
(HOUR
) | INTERVAL_MASK
(MINUTE
))) != 0)
1320 (errcode
(ERRCODE_SYNTAX_ERROR
),
1321 errmsg
("time zone interval must be HOUR or HOUR TO MINUTE"),
1322 scanner_errposition
(@
6)));
1323 if
(list_length
($6) != 1)
1325 (errcode
(ERRCODE_SYNTAX_ERROR
),
1326 errmsg
("interval precision specified twice"),
1327 scanner_errposition
(@
1)));
1328 t
->typmods
= lappend
($6, makeIntConst
($3, @
3));
1331 t
->typmods
= list_make2
(makeIntConst
(INTERVAL_FULL_RANGE
, -1),
1332 makeIntConst
($3, @
3));
1333 $$
= makeStringConstCast
($5, @
5, t
);
1335 | NumericOnly
{ $$
= makeAConst
($1, @
1); }
1336 | DEFAULT
{ $$
= NULL
; }
1337 | LOCAL
{ $$
= NULL
; }
1342 | DEFAULT
{ $$
= NULL
; }
1343 |
/*EMPTY*/ { $$
= NULL
; }
1348 | Sconst
{ $$
= $1; }
1354 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1355 n
->kind
= VAR_RESET
;
1361 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1362 n
->kind
= VAR_RESET
;
1363 n
->name
= "timezone";
1366 | RESET TRANSACTION ISOLATION LEVEL
1368 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1369 n
->kind
= VAR_RESET
;
1370 n
->name
= "transaction_isolation";
1373 | RESET SESSION AUTHORIZATION
1375 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1376 n
->kind
= VAR_RESET
;
1377 n
->name
= "session_authorization";
1382 VariableSetStmt
*n
= makeNode
(VariableSetStmt
);
1383 n
->kind
= VAR_RESET_ALL
;
1388 /* SetResetClause allows SET or RESET without LOCAL */
1390 SET set_rest
{ $$
= $2; }
1391 | VariableResetStmt
{ $$
= (VariableSetStmt
*) $1; }
1398 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1404 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1405 n
->name
= "timezone";
1408 | SHOW TRANSACTION ISOLATION LEVEL
1410 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1411 n
->name
= "transaction_isolation";
1414 | SHOW SESSION AUTHORIZATION
1416 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1417 n
->name
= "session_authorization";
1422 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
1430 SET CONSTRAINTS constraints_set_list constraints_set_mode
1432 ConstraintsSetStmt
*n
= makeNode
(ConstraintsSetStmt
);
1433 n
->constraints
= $3;
1439 constraints_set_list:
1441 | qualified_name_list
{ $$
= $1; }
1444 constraints_set_mode:
1445 DEFERRED
{ $$
= TRUE
; }
1446 | IMMEDIATE
{ $$
= FALSE
; }
1451 * Checkpoint statement
1456 CheckPointStmt
*n
= makeNode
(CheckPointStmt
);
1462 /*****************************************************************************
1464 * DISCARD { ALL | TEMP | PLANS }
1466 *****************************************************************************/
1471 DiscardStmt
*n
= makeNode
(DiscardStmt
);
1472 n
->target
= DISCARD_ALL
;
1477 DiscardStmt
*n
= makeNode
(DiscardStmt
);
1478 n
->target
= DISCARD_TEMP
;
1483 DiscardStmt
*n
= makeNode
(DiscardStmt
);
1484 n
->target
= DISCARD_TEMP
;
1489 DiscardStmt
*n
= makeNode
(DiscardStmt
);
1490 n
->target
= DISCARD_PLANS
;
1496 /*****************************************************************************
1498 * ALTER [ TABLE | INDEX | SEQUENCE | VIEW ] variations
1500 * Note: we accept all subcommands for each of the four variants, and sort
1501 * out what's really legal at execution time.
1502 *****************************************************************************/
1505 ALTER TABLE relation_expr alter_table_cmds
1507 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
1510 n
->relkind
= OBJECT_TABLE
;
1513 | ALTER INDEX qualified_name alter_table_cmds
1515 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
1518 n
->relkind
= OBJECT_INDEX
;
1521 | ALTER SEQUENCE qualified_name alter_table_cmds
1523 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
1526 n
->relkind
= OBJECT_SEQUENCE
;
1529 | ALTER VIEW qualified_name alter_table_cmds
1531 AlterTableStmt
*n
= makeNode
(AlterTableStmt
);
1534 n
->relkind
= OBJECT_VIEW
;
1540 alter_table_cmd
{ $$
= list_make1
($1); }
1541 | alter_table_cmds
',' alter_table_cmd
{ $$
= lappend
($1, $3); }
1545 /* ALTER TABLE <name> ADD [COLUMN] <coldef> */
1546 ADD_P opt_column columnDef
1548 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1549 n
->subtype
= AT_AddColumn
;
1553 /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1554 | ALTER opt_column ColId alter_column_default
1556 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1557 n
->subtype
= AT_ColumnDefault
;
1562 /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
1563 | ALTER opt_column ColId DROP NOT NULL_P
1565 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1566 n
->subtype
= AT_DropNotNull
;
1570 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
1571 | ALTER opt_column ColId SET NOT NULL_P
1573 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1574 n
->subtype
= AT_SetNotNull
;
1578 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
1579 | ALTER opt_column ColId SET STATISTICS SignedIconst
1581 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1582 n
->subtype
= AT_SetStatistics
;
1584 n
->def
= (Node
*) makeInteger
($6);
1587 /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1588 | ALTER opt_column ColId SET STORAGE ColId
1590 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1591 n
->subtype
= AT_SetStorage
;
1593 n
->def
= (Node
*) makeString
($6);
1596 /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1597 | DROP opt_column ColId opt_drop_behavior
1599 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1600 n
->subtype
= AT_DropColumn
;
1606 * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
1607 * [ USING <expression> ]
1609 | ALTER opt_column ColId opt_set_data TYPE_P Typename alter_using
1611 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1612 n
->subtype
= AT_AlterColumnType
;
1614 n
->def
= (Node
*) $6;
1618 /* ALTER TABLE <name> ADD CONSTRAINT ... */
1619 | ADD_P TableConstraint
1621 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1622 n
->subtype
= AT_AddConstraint
;
1626 /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1627 | DROP CONSTRAINT name opt_drop_behavior
1629 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1630 n
->subtype
= AT_DropConstraint
;
1635 /* ALTER TABLE <name> SET WITH OIDS */
1638 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1639 n
->subtype
= AT_AddOids
;
1642 /* ALTER TABLE <name> SET WITHOUT OIDS */
1645 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1646 n
->subtype
= AT_DropOids
;
1649 /* ALTER TABLE <name> CLUSTER ON <indexname> */
1652 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1653 n
->subtype
= AT_ClusterOn
;
1657 /* ALTER TABLE <name> SET WITHOUT CLUSTER */
1658 | SET WITHOUT CLUSTER
1660 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1661 n
->subtype
= AT_DropCluster
;
1665 /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
1666 | ENABLE_P TRIGGER name
1668 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1669 n
->subtype
= AT_EnableTrig
;
1673 /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
1674 | ENABLE_P ALWAYS TRIGGER name
1676 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1677 n
->subtype
= AT_EnableAlwaysTrig
;
1681 /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
1682 | ENABLE_P REPLICA TRIGGER name
1684 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1685 n
->subtype
= AT_EnableReplicaTrig
;
1689 /* ALTER TABLE <name> ENABLE TRIGGER ALL */
1690 | ENABLE_P TRIGGER ALL
1692 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1693 n
->subtype
= AT_EnableTrigAll
;
1696 /* ALTER TABLE <name> ENABLE TRIGGER USER */
1697 | ENABLE_P TRIGGER USER
1699 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1700 n
->subtype
= AT_EnableTrigUser
;
1703 /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
1704 | DISABLE_P TRIGGER name
1706 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1707 n
->subtype
= AT_DisableTrig
;
1711 /* ALTER TABLE <name> DISABLE TRIGGER ALL */
1712 | DISABLE_P TRIGGER ALL
1714 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1715 n
->subtype
= AT_DisableTrigAll
;
1718 /* ALTER TABLE <name> DISABLE TRIGGER USER */
1719 | DISABLE_P TRIGGER USER
1721 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1722 n
->subtype
= AT_DisableTrigUser
;
1725 /* ALTER TABLE <name> ENABLE RULE <rule> */
1726 | ENABLE_P RULE name
1728 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1729 n
->subtype
= AT_EnableRule
;
1733 /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
1734 | ENABLE_P ALWAYS RULE name
1736 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1737 n
->subtype
= AT_EnableAlwaysRule
;
1741 /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
1742 | ENABLE_P REPLICA RULE name
1744 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1745 n
->subtype
= AT_EnableReplicaRule
;
1749 /* ALTER TABLE <name> DISABLE RULE <rule> */
1750 | DISABLE_P RULE name
1752 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1753 n
->subtype
= AT_DisableRule
;
1757 /* ALTER TABLE <name> INHERIT <parent> */
1758 | INHERIT qualified_name
1760 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1761 n
->subtype
= AT_AddInherit
;
1762 n
->def
= (Node
*) $2;
1765 /* ALTER TABLE <name> NO INHERIT <parent> */
1766 | NO INHERIT qualified_name
1768 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1769 n
->subtype
= AT_DropInherit
;
1770 n
->def
= (Node
*) $3;
1773 /* ALTER TABLE <name> OWNER TO RoleId */
1776 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1777 n
->subtype
= AT_ChangeOwner
;
1781 /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
1782 | SET TABLESPACE name
1784 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1785 n
->subtype
= AT_SetTableSpace
;
1789 /* ALTER TABLE <name> SET (...) */
1792 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1793 n
->subtype
= AT_SetRelOptions
;
1794 n
->def
= (Node
*)$2;
1797 /* ALTER TABLE <name> RESET (...) */
1800 AlterTableCmd
*n
= makeNode
(AlterTableCmd
);
1801 n
->subtype
= AT_ResetRelOptions
;
1802 n
->def
= (Node
*)$2;
1807 alter_column_default:
1808 SET DEFAULT a_expr
{ $$
= $3; }
1809 | DROP DEFAULT
{ $$
= NULL
; }
1813 CASCADE
{ $$
= DROP_CASCADE
; }
1814 | RESTRICT
{ $$
= DROP_RESTRICT
; }
1815 |
/* EMPTY */ { $$
= DROP_RESTRICT
; /* default */ }
1819 USING a_expr
{ $$
= $2; }
1820 |
/* EMPTY */ { $$
= NULL
; }
1824 '(' reloption_list
')' { $$
= $2; }
1827 opt_reloptions: WITH reloptions
{ $$
= $2; }
1828 |
/* EMPTY */ { $$
= NIL
; }
1832 reloption_elem
{ $$
= list_make1
($1); }
1833 | reloption_list
',' reloption_elem
{ $$
= lappend
($1, $3); }
1836 /* This should match def_elem and also allow qualified names */
1838 ColLabel
'=' def_arg
1840 $$
= makeDefElem
($1, (Node
*) $3);
1844 $$
= makeDefElem
($1, NULL
);
1846 | ColLabel
'.' ColLabel
'=' def_arg
1848 $$
= makeDefElemExtended
($1, $3, (Node
*) $5,
1851 | ColLabel
'.' ColLabel
1853 $$
= makeDefElemExtended
($1, $3, NULL
, DEFELEM_UNSPEC
);
1858 /*****************************************************************************
1861 * close <portalname>
1863 *****************************************************************************/
1868 ClosePortalStmt
*n
= makeNode
(ClosePortalStmt
);
1874 ClosePortalStmt
*n
= makeNode
(ClosePortalStmt
);
1875 n
->portalname
= NULL
;
1881 /*****************************************************************************
1884 * COPY relname ['(' columnList ')'] FROM/TO file [WITH options]
1886 * BINARY, OIDS, and DELIMITERS kept in old locations
1887 * for backward compatibility. 2002-06-18
1889 * COPY ( SELECT ... ) TO file [WITH options]
1890 * This form doesn't have the backwards-compatible option
1893 *****************************************************************************/
1895 CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
1896 copy_from copy_file_name copy_delimiter opt_with copy_opt_list
1898 CopyStmt
*n
= makeNode
(CopyStmt
);
1906 /* Concatenate user-supplied flags */
1908 n
->options
= lappend
(n
->options
, $2);
1910 n
->options
= lappend
(n
->options
, $5);
1912 n
->options
= lappend
(n
->options
, $8);
1914 n
->options
= list_concat
(n
->options
, $10);
1917 | COPY select_with_parens TO copy_file_name opt_with
1920 CopyStmt
*n
= makeNode
(CopyStmt
);
1933 | TO
{ $$
= FALSE
; }
1937 * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
1938 * used depends on the direction. (It really doesn't make sense to copy from
1939 * stdout. We silently correct the "typo".) - AY 9/94
1943 | STDIN
{ $$
= NULL
; }
1944 | STDOUT
{ $$
= NULL
; }
1950 copy_opt_list copy_opt_item
{ $$
= lappend
($1, $2); }
1951 |
/* EMPTY */ { $$
= NIL
; }
1958 $$
= makeDefElem
("binary", (Node
*)makeInteger
(TRUE
));
1962 $$
= makeDefElem
("oids", (Node
*)makeInteger
(TRUE
));
1964 | DELIMITER opt_as Sconst
1966 $$
= makeDefElem
("delimiter", (Node
*)makeString
($3));
1968 | NULL_P opt_as Sconst
1970 $$
= makeDefElem
("null", (Node
*)makeString
($3));
1974 $$
= makeDefElem
("csv", (Node
*)makeInteger
(TRUE
));
1978 $$
= makeDefElem
("header", (Node
*)makeInteger
(TRUE
));
1980 | QUOTE opt_as Sconst
1982 $$
= makeDefElem
("quote", (Node
*)makeString
($3));
1984 | ESCAPE opt_as Sconst
1986 $$
= makeDefElem
("escape", (Node
*)makeString
($3));
1988 | FORCE QUOTE columnList
1990 $$
= makeDefElem
("force_quote", (Node
*)$3);
1992 | FORCE NOT NULL_P columnList
1994 $$
= makeDefElem
("force_notnull", (Node
*)$4);
1998 /* The following exist for backward compatibility */
2003 $$
= makeDefElem
("binary", (Node
*)makeInteger
(TRUE
));
2005 |
/*EMPTY*/ { $$
= NULL
; }
2011 $$
= makeDefElem
("oids", (Node
*)makeInteger
(TRUE
));
2013 |
/*EMPTY*/ { $$
= NULL
; }
2017 /* USING DELIMITERS kept for backward compatibility. 2002-06-15 */
2018 opt_using DELIMITERS Sconst
2020 $$
= makeDefElem
("delimiter", (Node
*)makeString
($3));
2022 |
/*EMPTY*/ { $$
= NULL
; }
2031 /*****************************************************************************
2034 * CREATE TABLE relname
2036 *****************************************************************************/
2038 CreateStmt: CREATE OptTemp TABLE qualified_name
'(' OptTableElementList
')'
2039 OptInherit OptWith OnCommitOption OptTableSpace
2041 CreateStmt
*n
= makeNode
(CreateStmt
);
2045 n
->inhRelations
= $8;
2046 n
->constraints
= NIL
;
2049 n
->tablespacename
= $11;
2052 | CREATE OptTemp TABLE qualified_name OF qualified_name
2053 '(' OptTableElementList
')' OptWith OnCommitOption OptTableSpace
2055 /* SQL99 CREATE TABLE OF <UDT> (cols) seems to be satisfied
2056 * by our inheritance capabilities. Let's try it...
2058 CreateStmt
*n
= makeNode
(CreateStmt
);
2062 n
->inhRelations
= list_make1
($6);
2063 n
->constraints
= NIL
;
2066 n
->tablespacename
= $12;
2072 * Redundancy here is needed to avoid shift/reduce conflicts,
2073 * since TEMP is not a reserved word. See also OptTempTableName.
2075 * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
2076 * the LOCAL keyword is really meaningless.
2078 OptTemp: TEMPORARY
{ $$
= TRUE
; }
2079 | TEMP
{ $$
= TRUE
; }
2080 | LOCAL TEMPORARY
{ $$
= TRUE
; }
2081 | LOCAL TEMP
{ $$
= TRUE
; }
2082 | GLOBAL TEMPORARY
{ $$
= TRUE
; }
2083 | GLOBAL TEMP
{ $$
= TRUE
; }
2084 |
/*EMPTY*/ { $$
= FALSE
; }
2087 OptTableElementList:
2088 TableElementList
{ $$
= $1; }
2089 |
/*EMPTY*/ { $$
= NIL
; }
2095 $$
= list_make1
($1);
2097 | TableElementList
',' TableElement
2099 $$
= lappend
($1, $3);
2104 columnDef
{ $$
= $1; }
2105 | TableLikeClause
{ $$
= $1; }
2106 | TableConstraint
{ $$
= $1; }
2109 columnDef: ColId Typename ColQualList
2111 ColumnDef
*n
= makeNode
(ColumnDef
);
2114 n
->constraints
= $3;
2121 ColQualList ColConstraint
{ $$
= lappend
($1, $2); }
2122 |
/*EMPTY*/ { $$
= NIL
; }
2126 CONSTRAINT name ColConstraintElem
2128 switch
(nodeTag
($3))
2132 Constraint
*n
= (Constraint
*)$3;
2136 case T_FkConstraint
:
2138 FkConstraint
*n
= (FkConstraint
*)$3;
2139 n
->constr_name
= $2;
2147 | ColConstraintElem
{ $$
= $1; }
2148 | ConstraintAttr
{ $$
= $1; }
2151 /* DEFAULT NULL is already the default for Postgres.
2152 * But define it here and carry it forward into the system
2153 * to make it explicit.
2154 * - thomas 1998-09-13
2156 * WITH NULL and NULL are not SQL92-standard syntax elements,
2157 * so leave them out. Use DEFAULT NULL to explicitly indicate
2158 * that a column may have that value. WITH NULL leads to
2159 * shift/reduce conflicts with WITH TIME ZONE anyway.
2160 * - thomas 1999-01-08
2162 * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
2163 * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
2164 * or be part of a_expr NOT LIKE or similar constructs).
2169 Constraint
*n
= makeNode
(Constraint
);
2170 n
->contype
= CONSTR_NOTNULL
;
2173 n
->cooked_expr
= NULL
;
2175 n
->indexspace
= NULL
;
2180 Constraint
*n
= makeNode
(Constraint
);
2181 n
->contype
= CONSTR_NULL
;
2184 n
->cooked_expr
= NULL
;
2186 n
->indexspace
= NULL
;
2189 | UNIQUE opt_definition OptConsTableSpace
2191 Constraint
*n
= makeNode
(Constraint
);
2192 n
->contype
= CONSTR_UNIQUE
;
2195 n
->cooked_expr
= NULL
;
2201 | PRIMARY KEY opt_definition OptConsTableSpace
2203 Constraint
*n
= makeNode
(Constraint
);
2204 n
->contype
= CONSTR_PRIMARY
;
2207 n
->cooked_expr
= NULL
;
2213 | CHECK
'(' a_expr
')'
2215 Constraint
*n
= makeNode
(Constraint
);
2216 n
->contype
= CONSTR_CHECK
;
2219 n
->cooked_expr
= NULL
;
2221 n
->indexspace
= NULL
;
2226 Constraint
*n
= makeNode
(Constraint
);
2227 n
->contype
= CONSTR_DEFAULT
;
2230 n
->cooked_expr
= NULL
;
2232 n
->indexspace
= NULL
;
2235 | REFERENCES qualified_name opt_column_list key_match key_actions
2237 FkConstraint
*n
= makeNode
(FkConstraint
);
2238 n
->constr_name
= NULL
;
2242 n
->fk_matchtype
= $4;
2243 n
->fk_upd_action
= (char) ($5 >> 8);
2244 n
->fk_del_action
= (char) ($5 & 0xFF);
2245 n
->deferrable
= FALSE
;
2246 n
->initdeferred
= FALSE
;
2252 * ConstraintAttr represents constraint attributes, which we parse as if
2253 * they were independent constraint clauses, in order to avoid shift/reduce
2254 * conflicts (since NOT might start either an independent NOT NULL clause
2255 * or an attribute). parse_utilcmd.c is responsible for attaching the
2256 * attribute information to the preceding "real" constraint node, and for
2257 * complaining if attribute clauses appear in the wrong place or wrong
2260 * See also ConstraintAttributeSpec, which can be used in places where
2261 * there is no parsing conflict.
2266 Constraint
*n
= makeNode
(Constraint
);
2267 n
->contype
= CONSTR_ATTR_DEFERRABLE
;
2272 Constraint
*n
= makeNode
(Constraint
);
2273 n
->contype
= CONSTR_ATTR_NOT_DEFERRABLE
;
2276 | INITIALLY DEFERRED
2278 Constraint
*n
= makeNode
(Constraint
);
2279 n
->contype
= CONSTR_ATTR_DEFERRED
;
2282 | INITIALLY IMMEDIATE
2284 Constraint
*n
= makeNode
(Constraint
);
2285 n
->contype
= CONSTR_ATTR_IMMEDIATE
;
2292 * SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
2293 * This seems to be a poor man's inheritance capability, with the resulting
2294 * tables completely decoupled except for the original commonality in definitions.
2296 * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
2297 * which is a part of SQL:2003.
2300 LIKE qualified_name TableLikeOptionList
2302 InhRelation
*n
= makeNode
(InhRelation
);
2309 TableLikeOptionList:
2310 TableLikeOptionList TableLikeOption
{ $$
= lappend_int
($1, $2); }
2311 |
/* EMPTY */ { $$
= NIL
; }
2315 INCLUDING DEFAULTS
{ $$
= CREATE_TABLE_LIKE_INCLUDING_DEFAULTS
; }
2316 | EXCLUDING DEFAULTS
{ $$
= CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS
; }
2317 | INCLUDING CONSTRAINTS
{ $$
= CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS
; }
2318 | EXCLUDING CONSTRAINTS
{ $$
= CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS
; }
2319 | INCLUDING INDEXES
{ $$
= CREATE_TABLE_LIKE_INCLUDING_INDEXES
; }
2320 | EXCLUDING INDEXES
{ $$
= CREATE_TABLE_LIKE_EXCLUDING_INDEXES
; }
2324 /* ConstraintElem specifies constraint syntax which is not embedded into
2325 * a column definition. ColConstraintElem specifies the embedded form.
2326 * - thomas 1997-12-03
2329 CONSTRAINT name ConstraintElem
2331 switch
(nodeTag
($3))
2335 Constraint
*n
= (Constraint
*)$3;
2339 case T_FkConstraint
:
2341 FkConstraint
*n
= (FkConstraint
*)$3;
2342 n
->constr_name
= $2;
2350 | ConstraintElem
{ $$
= $1; }
2354 CHECK
'(' a_expr
')'
2356 Constraint
*n
= makeNode
(Constraint
);
2357 n
->contype
= CONSTR_CHECK
;
2360 n
->cooked_expr
= NULL
;
2361 n
->indexspace
= NULL
;
2364 | UNIQUE
'(' columnList
')' opt_definition OptConsTableSpace
2366 Constraint
*n
= makeNode
(Constraint
);
2367 n
->contype
= CONSTR_UNIQUE
;
2370 n
->cooked_expr
= NULL
;
2376 | PRIMARY KEY
'(' columnList
')' opt_definition OptConsTableSpace
2378 Constraint
*n
= makeNode
(Constraint
);
2379 n
->contype
= CONSTR_PRIMARY
;
2382 n
->cooked_expr
= NULL
;
2388 | FOREIGN KEY
'(' columnList
')' REFERENCES qualified_name
2389 opt_column_list key_match key_actions ConstraintAttributeSpec
2391 FkConstraint
*n
= makeNode
(FkConstraint
);
2392 n
->constr_name
= NULL
;
2396 n
->fk_matchtype
= $9;
2397 n
->fk_upd_action
= (char) ($10 >> 8);
2398 n
->fk_del_action
= (char) ($10 & 0xFF);
2399 n
->deferrable
= ($11 & 1) != 0;
2400 n
->initdeferred
= ($11 & 2) != 0;
2406 '(' columnList
')' { $$
= $2; }
2407 |
/*EMPTY*/ { $$
= NIL
; }
2411 columnElem
{ $$
= list_make1
($1); }
2412 | columnList
',' columnElem
{ $$
= lappend
($1, $3); }
2417 $$
= (Node
*) makeString
($1);
2421 key_match: MATCH FULL
2423 $$
= FKCONSTR_MATCH_FULL
;
2428 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
2429 errmsg
("MATCH PARTIAL not yet implemented"),
2430 scanner_errposition
(@
1)));
2431 $$
= FKCONSTR_MATCH_PARTIAL
;
2435 $$
= FKCONSTR_MATCH_UNSPECIFIED
;
2439 $$
= FKCONSTR_MATCH_UNSPECIFIED
;
2444 * We combine the update and delete actions into one value temporarily
2445 * for simplicity of parsing, and then break them down again in the
2446 * calling production. update is in the left 8 bits, delete in the right.
2447 * Note that NOACTION is the default.
2451 { $$
= ($1 << 8) |
(FKCONSTR_ACTION_NOACTION
& 0xFF); }
2453 { $$
= (FKCONSTR_ACTION_NOACTION
<< 8) |
($1 & 0xFF); }
2454 | key_update key_delete
2455 { $$
= ($1 << 8) |
($2 & 0xFF); }
2456 | key_delete key_update
2457 { $$
= ($2 << 8) |
($1 & 0xFF); }
2459 { $$
= (FKCONSTR_ACTION_NOACTION
<< 8) |
(FKCONSTR_ACTION_NOACTION
& 0xFF); }
2462 key_update: ON UPDATE key_action
{ $$
= $3; }
2465 key_delete: ON DELETE_P key_action
{ $$
= $3; }
2469 NO ACTION
{ $$
= FKCONSTR_ACTION_NOACTION
; }
2470 | RESTRICT
{ $$
= FKCONSTR_ACTION_RESTRICT
; }
2471 | CASCADE
{ $$
= FKCONSTR_ACTION_CASCADE
; }
2472 | SET NULL_P
{ $$
= FKCONSTR_ACTION_SETNULL
; }
2473 | SET DEFAULT
{ $$
= FKCONSTR_ACTION_SETDEFAULT
; }
2476 OptInherit: INHERITS
'(' qualified_name_list
')' { $$
= $3; }
2477 |
/*EMPTY*/ { $$
= NIL
; }
2480 /* WITH (options) is preferred, WITH OIDS and WITHOUT OIDS are legacy forms */
2482 WITH reloptions
{ $$
= $2; }
2483 | WITH OIDS
{ $$
= list_make1
(defWithOids
(true
)); }
2484 | WITHOUT OIDS
{ $$
= list_make1
(defWithOids
(false
)); }
2485 |
/*EMPTY*/ { $$
= NIL
; }
2488 OnCommitOption: ON COMMIT DROP
{ $$
= ONCOMMIT_DROP
; }
2489 | ON COMMIT DELETE_P ROWS
{ $$
= ONCOMMIT_DELETE_ROWS
; }
2490 | ON COMMIT PRESERVE ROWS
{ $$
= ONCOMMIT_PRESERVE_ROWS
; }
2491 |
/*EMPTY*/ { $$
= ONCOMMIT_NOOP
; }
2494 OptTableSpace: TABLESPACE name
{ $$
= $2; }
2495 |
/*EMPTY*/ { $$
= NULL
; }
2498 OptConsTableSpace: USING INDEX TABLESPACE name
{ $$
= $4; }
2499 |
/*EMPTY*/ { $$
= NULL
; }
2504 * Note: CREATE TABLE ... AS SELECT ... is just another spelling for
2509 CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
2512 * When the SelectStmt is a set-operation tree, we must
2513 * stuff the INTO information into the leftmost component
2514 * Select, because that's where analyze.c will expect
2515 * to find it. Similarly, the output column names must
2516 * be attached to that Select's target list.
2518 SelectStmt
*n
= findLeftmostSelect
((SelectStmt
*) $6);
2519 if
(n
->intoClause
!= NULL
)
2521 (errcode
(ERRCODE_SYNTAX_ERROR
),
2522 errmsg
("CREATE TABLE AS cannot specify INTO"),
2523 scanner_errposition
(exprLocation
((Node
*) n
->intoClause
))));
2524 $4->rel
->istemp
= $2;
2526 /* Implement WITH NO DATA by forcing top-level LIMIT 0 */
2528 ((SelectStmt
*) $6)->limitCount
= makeIntConst
(0, -1);
2534 qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
2536 $$
= makeNode
(IntoClause
);
2541 $$
->tableSpaceName
= $5;
2546 '(' CreateAsList
')' { $$
= $2; }
2547 |
/*EMPTY*/ { $$
= NIL
; }
2551 CreateAsElement
{ $$
= list_make1
($1); }
2552 | CreateAsList
',' CreateAsElement
{ $$
= lappend
($1, $3); }
2558 ColumnDef
*n
= makeNode
(ColumnDef
);
2563 n
->is_not_null
= false
;
2564 n
->raw_default
= NULL
;
2565 n
->cooked_default
= NULL
;
2566 n
->constraints
= NIL
;
2572 WITH DATA_P
{ $$
= TRUE
; }
2573 | WITH NO DATA_P
{ $$
= FALSE
; }
2574 |
/*EMPTY*/ { $$
= TRUE
; }
2578 /*****************************************************************************
2581 * CREATE SEQUENCE seqname
2582 * ALTER SEQUENCE seqname
2584 *****************************************************************************/
2587 CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
2589 CreateSeqStmt
*n
= makeNode
(CreateSeqStmt
);
2598 ALTER SEQUENCE qualified_name SeqOptList
2600 AlterSeqStmt
*n
= makeNode
(AlterSeqStmt
);
2607 OptSeqOptList: SeqOptList
{ $$
= $1; }
2608 |
/*EMPTY*/ { $$
= NIL
; }
2611 SeqOptList: SeqOptElem
{ $$
= list_make1
($1); }
2612 | SeqOptList SeqOptElem
{ $$
= lappend
($1, $2); }
2615 SeqOptElem: CACHE NumericOnly
2617 $$
= makeDefElem
("cache", (Node
*)$2);
2621 $$
= makeDefElem
("cycle", (Node
*)makeInteger
(TRUE
));
2625 $$
= makeDefElem
("cycle", (Node
*)makeInteger
(FALSE
));
2627 | INCREMENT opt_by NumericOnly
2629 $$
= makeDefElem
("increment", (Node
*)$3);
2631 | MAXVALUE NumericOnly
2633 $$
= makeDefElem
("maxvalue", (Node
*)$2);
2635 | MINVALUE NumericOnly
2637 $$
= makeDefElem
("minvalue", (Node
*)$2);
2641 $$
= makeDefElem
("maxvalue", NULL
);
2645 $$
= makeDefElem
("minvalue", NULL
);
2649 $$
= makeDefElem
("owned_by", (Node
*)$3);
2651 | START opt_with NumericOnly
2653 $$
= makeDefElem
("start", (Node
*)$3);
2657 $$
= makeDefElem
("restart", NULL
);
2659 | RESTART opt_with NumericOnly
2661 $$
= makeDefElem
("restart", (Node
*)$3);
2670 FCONST
{ $$
= makeFloat
($1); }
2676 | SignedIconst
{ $$
= makeInteger
($1); };
2679 /*****************************************************************************
2682 * CREATE PROCEDURAL LANGUAGE ...
2683 * DROP PROCEDURAL LANGUAGE ...
2685 *****************************************************************************/
2688 CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2690 CreatePLangStmt
*n
= makeNode
(CreatePLangStmt
);
2692 /* parameters are all to be supplied by system */
2694 n
->plvalidator
= NIL
;
2695 n
->pltrusted
= false
;
2698 | CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2699 HANDLER handler_name opt_validator opt_lancompiler
2701 CreatePLangStmt
*n
= makeNode
(CreatePLangStmt
);
2704 n
->plvalidator
= $8;
2706 /* LANCOMPILER is now ignored entirely */
2712 TRUSTED
{ $$
= TRUE
; }
2713 |
/*EMPTY*/ { $$
= FALSE
; }
2716 /* This ought to be just func_name, but that causes reduce/reduce conflicts
2717 * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
2718 * Work around by using simple names, instead.
2721 name
{ $$
= list_make1
(makeString
($1)); }
2722 | name attrs
{ $$
= lcons
(makeString
($1), $2); }
2726 VALIDATOR handler_name
{ $$
= $2; }
2727 | NO VALIDATOR
{ $$
= NIL
; }
2731 validator_clause
{ $$
= $1; }
2732 |
/*EMPTY*/ { $$
= NIL
; }
2736 LANCOMPILER Sconst
{ $$
= $2; }
2737 |
/*EMPTY*/ { $$
= NULL
; }
2741 DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
2743 DropPLangStmt
*n
= makeNode
(DropPLangStmt
);
2746 n
->missing_ok
= false
;
2749 | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
2751 DropPLangStmt
*n
= makeNode
(DropPLangStmt
);
2754 n
->missing_ok
= true
;
2764 /*****************************************************************************
2767 * CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
2769 *****************************************************************************/
2771 CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
2773 CreateTableSpaceStmt
*n
= makeNode
(CreateTableSpaceStmt
);
2774 n
->tablespacename
= $3;
2781 OptTableSpaceOwner: OWNER name
{ $$
= $2; }
2782 |
/*EMPTY */ { $$
= NULL
; }
2785 /*****************************************************************************
2788 * DROP TABLESPACE <tablespace>
2790 * No need for drop behaviour as we cannot implement dependencies for
2791 * objects in other databases; we can only support RESTRICT.
2793 ****************************************************************************/
2795 DropTableSpaceStmt: DROP TABLESPACE name
2797 DropTableSpaceStmt
*n
= makeNode
(DropTableSpaceStmt
);
2798 n
->tablespacename
= $3;
2799 n
->missing_ok
= false
;
2802 | DROP TABLESPACE IF_P EXISTS name
2804 DropTableSpaceStmt
*n
= makeNode
(DropTableSpaceStmt
);
2805 n
->tablespacename
= $5;
2806 n
->missing_ok
= true
;
2811 /*****************************************************************************
2814 * CREATE FOREIGN DATA WRAPPER name [ VALIDATOR name ]
2816 *****************************************************************************/
2818 CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_validator create_generic_options
2820 CreateFdwStmt
*n
= makeNode
(CreateFdwStmt
);
2828 /*****************************************************************************
2831 * DROP FOREIGN DATA WRAPPER name
2833 ****************************************************************************/
2835 DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
2837 DropFdwStmt
*n
= makeNode
(DropFdwStmt
);
2839 n
->missing_ok
= false
;
2843 | DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior
2845 DropFdwStmt
*n
= makeNode
(DropFdwStmt
);
2847 n
->missing_ok
= true
;
2853 /*****************************************************************************
2856 * ALTER FOREIGN DATA WRAPPER name
2858 ****************************************************************************/
2860 AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name validator_clause alter_generic_options
2862 AlterFdwStmt
*n
= makeNode
(AlterFdwStmt
);
2865 n
->change_validator
= true
;
2869 | ALTER FOREIGN DATA_P WRAPPER name validator_clause
2871 AlterFdwStmt
*n
= makeNode
(AlterFdwStmt
);
2874 n
->change_validator
= true
;
2877 | ALTER FOREIGN DATA_P WRAPPER name alter_generic_options
2879 AlterFdwStmt
*n
= makeNode
(AlterFdwStmt
);
2886 /* Options definition for CREATE FDW, SERVER and USER MAPPING */
2887 create_generic_options:
2888 OPTIONS
'(' generic_option_list
')' { $$
= $3; }
2889 |
/*EMPTY*/ { $$
= NIL
; }
2892 generic_option_list:
2895 $$
= list_make1
($1);
2897 | generic_option_list
',' generic_option_elem
2899 $$
= lappend
($1, $3);
2903 /* Options definition for ALTER FDW, SERVER and USER MAPPING */
2904 alter_generic_options:
2905 OPTIONS
'(' alter_generic_option_list
')' { $$
= $3; }
2908 alter_generic_option_list:
2909 alter_generic_option_elem
2911 $$
= list_make1
($1);
2913 | alter_generic_option_list
',' alter_generic_option_elem
2915 $$
= lappend
($1, $3);
2919 alter_generic_option_elem:
2924 | SET generic_option_elem
2927 $$
->defaction
= DEFELEM_SET
;
2929 | ADD_P generic_option_elem
2932 $$
->defaction
= DEFELEM_ADD
;
2934 | DROP generic_option_name
2936 $$
= makeDefElemExtended
(NULL
, $2, NULL
, DEFELEM_DROP
);
2940 generic_option_elem:
2941 generic_option_name generic_option_arg
2943 $$
= makeDefElem
($1, $2);
2947 generic_option_name:
2948 ColLabel
{ $$
= $1; }
2951 /* We could use def_arg here, but the spec only requires string literals */
2953 Sconst
{ $$
= (Node
*) makeString
($1); }
2956 /*****************************************************************************
2959 * CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
2961 *****************************************************************************/
2963 CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
2964 FOREIGN DATA_P WRAPPER name create_generic_options
2966 CreateForeignServerStmt
*n
= makeNode
(CreateForeignServerStmt
);
2977 TYPE_P Sconst
{ $$
= $2; }
2978 |
/*EMPTY*/ { $$
= NULL
; }
2982 foreign_server_version:
2983 VERSION_P Sconst
{ $$
= $2; }
2984 | VERSION_P NULL_P
{ $$
= NULL
; }
2987 opt_foreign_server_version:
2988 foreign_server_version
{ $$
= $1; }
2989 |
/*EMPTY*/ { $$
= NULL
; }
2992 /*****************************************************************************
2997 ****************************************************************************/
2999 DropForeignServerStmt: DROP SERVER name opt_drop_behavior
3001 DropForeignServerStmt
*n
= makeNode
(DropForeignServerStmt
);
3003 n
->missing_ok
= false
;
3007 | DROP SERVER IF_P EXISTS name opt_drop_behavior
3009 DropForeignServerStmt
*n
= makeNode
(DropForeignServerStmt
);
3011 n
->missing_ok
= true
;
3017 /*****************************************************************************
3020 * ALTER SERVER name [VERSION] [OPTIONS]
3022 ****************************************************************************/
3024 AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
3026 AlterForeignServerStmt
*n
= makeNode
(AlterForeignServerStmt
);
3030 n
->has_version
= true
;
3033 | ALTER SERVER name foreign_server_version
3035 AlterForeignServerStmt
*n
= makeNode
(AlterForeignServerStmt
);
3038 n
->has_version
= true
;
3041 | ALTER SERVER name alter_generic_options
3043 AlterForeignServerStmt
*n
= makeNode
(AlterForeignServerStmt
);
3050 /*****************************************************************************
3053 * CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
3055 *****************************************************************************/
3057 CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
3059 CreateUserMappingStmt
*n
= makeNode
(CreateUserMappingStmt
);
3067 /* User mapping authorization identifier */
3069 CURRENT_USER
{ $$
= "current_user"; }
3070 | USER
{ $$
= "current_user"; }
3071 | RoleId
{ $$
= (strcmp
($1, "public") == 0) ? NULL
: $1; }
3074 /*****************************************************************************
3077 * DROP USER MAPPING FOR auth_ident SERVER name
3079 ****************************************************************************/
3081 DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
3083 DropUserMappingStmt
*n
= makeNode
(DropUserMappingStmt
);
3086 n
->missing_ok
= false
;
3089 | DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
3091 DropUserMappingStmt
*n
= makeNode
(DropUserMappingStmt
);
3094 n
->missing_ok
= true
;
3099 /*****************************************************************************
3102 * ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
3104 ****************************************************************************/
3106 AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
3108 AlterUserMappingStmt
*n
= makeNode
(AlterUserMappingStmt
);
3116 /*****************************************************************************
3119 * CREATE TRIGGER ...
3122 *****************************************************************************/
3125 CREATE TRIGGER name TriggerActionTime TriggerEvents ON
3126 qualified_name TriggerForSpec EXECUTE PROCEDURE
3127 func_name
'(' TriggerFuncArgs
')'
3129 CreateTrigStmt
*n
= makeNode
(CreateTrigStmt
);
3137 n
->isconstraint
= FALSE
;
3138 n
->deferrable
= FALSE
;
3139 n
->initdeferred
= FALSE
;
3140 n
->constrrel
= NULL
;
3143 | CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
3144 qualified_name OptConstrFromTable
3145 ConstraintAttributeSpec
3146 FOR EACH ROW EXECUTE PROCEDURE
3147 func_name
'(' TriggerFuncArgs
')'
3149 CreateTrigStmt
*n
= makeNode
(CreateTrigStmt
);
3157 n
->isconstraint
= TRUE
;
3158 n
->deferrable
= ($10 & 1) != 0;
3159 n
->initdeferred
= ($10 & 2) != 0;
3166 BEFORE
{ $$
= TRUE
; }
3167 | AFTER
{ $$
= FALSE
; }
3173 | TriggerEvents OR TriggerOneEvent
3176 yyerror("duplicate trigger events specified");
3182 INSERT
{ $$
= TRIGGER_TYPE_INSERT
; }
3183 | DELETE_P
{ $$
= TRIGGER_TYPE_DELETE
; }
3184 | UPDATE
{ $$
= TRIGGER_TYPE_UPDATE
; }
3185 | TRUNCATE
{ $$
= TRIGGER_TYPE_TRUNCATE
; }
3189 FOR TriggerForOpt TriggerForType
3196 * If ROW/STATEMENT not specified, default to
3197 * STATEMENT, per SQL
3210 | STATEMENT
{ $$
= FALSE
; }
3214 TriggerFuncArg
{ $$
= list_make1
($1); }
3215 | TriggerFuncArgs
',' TriggerFuncArg
{ $$
= lappend
($1, $3); }
3216 |
/*EMPTY*/ { $$
= NIL
; }
3223 snprintf
(buf
, sizeof
(buf
), "%d", $1);
3224 $$
= makeString
(pstrdup
(buf
));
3226 | FCONST
{ $$
= makeString
($1); }
3227 | Sconst
{ $$
= makeString
($1); }
3228 | BCONST
{ $$
= makeString
($1); }
3229 | XCONST
{ $$
= makeString
($1); }
3230 | ColId
{ $$
= makeString
($1); }
3234 FROM qualified_name
{ $$
= $2; }
3235 |
/*EMPTY*/ { $$
= NULL
; }
3238 ConstraintAttributeSpec:
3239 ConstraintDeferrabilitySpec
3241 | ConstraintDeferrabilitySpec ConstraintTimeSpec
3243 if
($1 == 0 && $2 != 0)
3245 (errcode
(ERRCODE_SYNTAX_ERROR
),
3246 errmsg
("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3247 scanner_errposition
(@
1)));
3250 | ConstraintTimeSpec
3257 | ConstraintTimeSpec ConstraintDeferrabilitySpec
3259 if
($2 == 0 && $1 != 0)
3261 (errcode
(ERRCODE_SYNTAX_ERROR
),
3262 errmsg
("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3263 scanner_errposition
(@
1)));
3270 ConstraintDeferrabilitySpec:
3271 NOT DEFERRABLE
{ $$
= 0; }
3272 | DEFERRABLE
{ $$
= 1; }
3276 INITIALLY IMMEDIATE
{ $$
= 0; }
3277 | INITIALLY DEFERRED
{ $$
= 2; }
3282 DROP TRIGGER name ON qualified_name opt_drop_behavior
3284 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
3288 n
->removeType
= OBJECT_TRIGGER
;
3289 n
->missing_ok
= false
;
3292 | DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
3294 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
3298 n
->removeType
= OBJECT_TRIGGER
;
3299 n
->missing_ok
= true
;
3305 /*****************************************************************************
3308 * CREATE ASSERTION ...
3309 * DROP ASSERTION ...
3311 *****************************************************************************/
3314 CREATE ASSERTION name CHECK
'(' a_expr
')'
3315 ConstraintAttributeSpec
3317 CreateTrigStmt
*n
= makeNode
(CreateTrigStmt
);
3319 n
->args
= list_make1
($6);
3320 n
->isconstraint
= TRUE
;
3321 n
->deferrable
= ($8 & 1) != 0;
3322 n
->initdeferred
= ($8 & 2) != 0;
3325 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
3326 errmsg
("CREATE ASSERTION is not yet implemented")));
3333 DROP ASSERTION name opt_drop_behavior
3335 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
3339 n
->removeType
= OBJECT_TRIGGER
; /* XXX */
3341 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
3342 errmsg
("DROP ASSERTION is not yet implemented")));
3348 /*****************************************************************************
3351 * define (aggregate,operator,type)
3353 *****************************************************************************/
3356 CREATE AGGREGATE func_name aggr_args definition
3358 DefineStmt
*n
= makeNode
(DefineStmt
);
3359 n
->kind
= OBJECT_AGGREGATE
;
3360 n
->oldstyle
= false
;
3366 | CREATE AGGREGATE func_name old_aggr_definition
3368 /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
3369 DefineStmt
*n
= makeNode
(DefineStmt
);
3370 n
->kind
= OBJECT_AGGREGATE
;
3377 | CREATE OPERATOR any_operator definition
3379 DefineStmt
*n
= makeNode
(DefineStmt
);
3380 n
->kind
= OBJECT_OPERATOR
;
3381 n
->oldstyle
= false
;
3387 | CREATE TYPE_P any_name definition
3389 DefineStmt
*n
= makeNode
(DefineStmt
);
3390 n
->kind
= OBJECT_TYPE
;
3391 n
->oldstyle
= false
;
3397 | CREATE TYPE_P any_name
3399 /* Shell type (identified by lack of definition) */
3400 DefineStmt
*n
= makeNode
(DefineStmt
);
3401 n
->kind
= OBJECT_TYPE
;
3402 n
->oldstyle
= false
;
3405 n
->definition
= NIL
;
3408 | CREATE TYPE_P any_name AS
'(' TableFuncElementList
')'
3410 CompositeTypeStmt
*n
= makeNode
(CompositeTypeStmt
);
3411 RangeVar
*r
= makeNode
(RangeVar
);
3413 /* can't use qualified_name, sigh */
3414 switch
(list_length
($3))
3417 r
->catalogname
= NULL
;
3418 r
->schemaname
= NULL
;
3419 r
->relname
= strVal
(linitial
($3));
3422 r
->catalogname
= NULL
;
3423 r
->schemaname
= strVal
(linitial
($3));
3424 r
->relname
= strVal
(lsecond
($3));
3427 r
->catalogname
= strVal
(linitial
($3));
3428 r
->schemaname
= strVal
(lsecond
($3));
3429 r
->relname
= strVal
(lthird
($3));
3433 (errcode
(ERRCODE_SYNTAX_ERROR
),
3434 errmsg
("improper qualified name (too many dotted names): %s",
3435 NameListToString
($3)),
3436 scanner_errposition
(@
3)));
3444 | CREATE TYPE_P any_name AS ENUM_P
'(' enum_val_list
')'
3446 CreateEnumStmt
*n
= makeNode
(CreateEnumStmt
);
3451 | CREATE TEXT_P SEARCH PARSER any_name definition
3453 DefineStmt
*n
= makeNode
(DefineStmt
);
3454 n
->kind
= OBJECT_TSPARSER
;
3460 | CREATE TEXT_P SEARCH DICTIONARY any_name definition
3462 DefineStmt
*n
= makeNode
(DefineStmt
);
3463 n
->kind
= OBJECT_TSDICTIONARY
;
3469 | CREATE TEXT_P SEARCH TEMPLATE any_name definition
3471 DefineStmt
*n
= makeNode
(DefineStmt
);
3472 n
->kind
= OBJECT_TSTEMPLATE
;
3478 | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
3480 DefineStmt
*n
= makeNode
(DefineStmt
);
3481 n
->kind
= OBJECT_TSCONFIGURATION
;
3489 definition: '(' def_list
')' { $$
= $2; }
3492 def_list: def_elem
{ $$
= list_make1
($1); }
3493 | def_list
',' def_elem
{ $$
= lappend
($1, $3); }
3496 def_elem: ColLabel
'=' def_arg
3498 $$
= makeDefElem
($1, (Node
*) $3);
3502 $$
= makeDefElem
($1, NULL
);
3506 /* Note: any simple identifier will be returned as a type name! */
3507 def_arg: func_type
{ $$
= (Node
*)$1; }
3508 | reserved_keyword
{ $$
= (Node
*)makeString
(pstrdup
($1)); }
3509 | qual_all_Op
{ $$
= (Node
*)$1; }
3510 | NumericOnly
{ $$
= (Node
*)$1; }
3511 | Sconst
{ $$
= (Node
*)makeString
($1); }
3514 aggr_args: '(' type_list
')' { $$
= $2; }
3515 |
'(' '*' ')' { $$
= NIL
; }
3518 old_aggr_definition: '(' old_aggr_list
')' { $$
= $2; }
3521 old_aggr_list: old_aggr_elem
{ $$
= list_make1
($1); }
3522 | old_aggr_list
',' old_aggr_elem
{ $$
= lappend
($1, $3); }
3526 * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
3527 * the item names needed in old aggregate definitions are likely to become
3530 old_aggr_elem: IDENT
'=' def_arg
3532 $$
= makeDefElem
($1, (Node
*)$3);
3536 enum_val_list: Sconst
3537 { $$
= list_make1
(makeString
($1)); }
3538 | enum_val_list
',' Sconst
3539 { $$
= lappend
($1, makeString
($3)); }
3543 /*****************************************************************************
3546 * CREATE OPERATOR CLASS ...
3547 * CREATE OPERATOR FAMILY ...
3548 * ALTER OPERATOR FAMILY ...
3549 * DROP OPERATOR CLASS ...
3550 * DROP OPERATOR FAMILY ...
3552 *****************************************************************************/
3555 CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
3556 USING access_method opt_opfamily AS opclass_item_list
3558 CreateOpClassStmt
*n
= makeNode
(CreateOpClassStmt
);
3559 n
->opclassname
= $4;
3563 n
->opfamilyname
= $11;
3570 opclass_item
{ $$
= list_make1
($1); }
3571 | opclass_item_list
',' opclass_item
{ $$
= lappend
($1, $3); }
3575 OPERATOR Iconst any_operator opt_recheck
3577 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3578 n
->itemtype
= OPCLASS_ITEM_OPERATOR
;
3584 | OPERATOR Iconst any_operator oper_argtypes opt_recheck
3586 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3587 n
->itemtype
= OPCLASS_ITEM_OPERATOR
;
3593 | FUNCTION Iconst func_name func_args
3595 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3596 n
->itemtype
= OPCLASS_ITEM_FUNCTION
;
3598 n
->args
= extractArgTypes
($4);
3602 | FUNCTION Iconst
'(' type_list
')' func_name func_args
3604 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3605 n
->itemtype
= OPCLASS_ITEM_FUNCTION
;
3607 n
->args
= extractArgTypes
($7);
3614 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3615 n
->itemtype
= OPCLASS_ITEM_STORAGETYPE
;
3621 opt_default: DEFAULT
{ $$
= TRUE
; }
3622 |
/*EMPTY*/ { $$
= FALSE
; }
3625 opt_opfamily: FAMILY any_name
{ $$
= $2; }
3626 |
/*EMPTY*/ { $$
= NIL
; }
3629 opt_recheck: RECHECK
3632 * RECHECK no longer does anything in opclass definitions,
3633 * but we still accept it to ease porting of old database
3637 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
3638 errmsg
("RECHECK is no longer required"),
3639 errhint
("Update your data type."),
3640 scanner_errposition
(@
1)));
3643 |
/*EMPTY*/ { $$
= FALSE
; }
3648 CREATE OPERATOR FAMILY any_name USING access_method
3650 CreateOpFamilyStmt
*n
= makeNode
(CreateOpFamilyStmt
);
3651 n
->opfamilyname
= $4;
3658 ALTER OPERATOR FAMILY any_name USING access_method ADD_P opclass_item_list
3660 AlterOpFamilyStmt
*n
= makeNode
(AlterOpFamilyStmt
);
3661 n
->opfamilyname
= $4;
3667 | ALTER OPERATOR FAMILY any_name USING access_method DROP opclass_drop_list
3669 AlterOpFamilyStmt
*n
= makeNode
(AlterOpFamilyStmt
);
3670 n
->opfamilyname
= $4;
3679 opclass_drop
{ $$
= list_make1
($1); }
3680 | opclass_drop_list
',' opclass_drop
{ $$
= lappend
($1, $3); }
3684 OPERATOR Iconst
'(' type_list
')'
3686 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3687 n
->itemtype
= OPCLASS_ITEM_OPERATOR
;
3692 | FUNCTION Iconst
'(' type_list
')'
3694 CreateOpClassItem
*n
= makeNode
(CreateOpClassItem
);
3695 n
->itemtype
= OPCLASS_ITEM_FUNCTION
;
3704 DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
3706 RemoveOpClassStmt
*n
= makeNode
(RemoveOpClassStmt
);
3707 n
->opclassname
= $4;
3710 n
->missing_ok
= false
;
3713 | DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
3715 RemoveOpClassStmt
*n
= makeNode
(RemoveOpClassStmt
);
3716 n
->opclassname
= $6;
3719 n
->missing_ok
= true
;
3725 DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
3727 RemoveOpFamilyStmt
*n
= makeNode
(RemoveOpFamilyStmt
);
3728 n
->opfamilyname
= $4;
3731 n
->missing_ok
= false
;
3734 | DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
3736 RemoveOpFamilyStmt
*n
= makeNode
(RemoveOpFamilyStmt
);
3737 n
->opfamilyname
= $6;
3740 n
->missing_ok
= true
;
3746 /*****************************************************************************
3750 * DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
3751 * REASSIGN OWNED BY username [, username ...] TO username
3753 *****************************************************************************/
3755 DROP OWNED BY name_list opt_drop_behavior
3757 DropOwnedStmt
*n
= makeNode
(DropOwnedStmt
);
3765 REASSIGN OWNED BY name_list TO name
3767 ReassignOwnedStmt
*n
= makeNode
(ReassignOwnedStmt
);
3774 /*****************************************************************************
3778 * DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
3779 * [ RESTRICT | CASCADE ]
3781 *****************************************************************************/
3783 DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
3785 DropStmt
*n
= makeNode
(DropStmt
);
3787 n
->missing_ok
= TRUE
;
3792 | DROP drop_type any_name_list opt_drop_behavior
3794 DropStmt
*n
= makeNode
(DropStmt
);
3796 n
->missing_ok
= FALSE
;
3804 drop_type: TABLE
{ $$
= OBJECT_TABLE
; }
3805 | SEQUENCE
{ $$
= OBJECT_SEQUENCE
; }
3806 | VIEW
{ $$
= OBJECT_VIEW
; }
3807 | INDEX
{ $$
= OBJECT_INDEX
; }
3808 | TYPE_P
{ $$
= OBJECT_TYPE
; }
3809 | DOMAIN_P
{ $$
= OBJECT_DOMAIN
; }
3810 | CONVERSION_P
{ $$
= OBJECT_CONVERSION
; }
3811 | SCHEMA
{ $$
= OBJECT_SCHEMA
; }
3812 | TEXT_P SEARCH PARSER
{ $$
= OBJECT_TSPARSER
; }
3813 | TEXT_P SEARCH DICTIONARY
{ $$
= OBJECT_TSDICTIONARY
; }
3814 | TEXT_P SEARCH TEMPLATE
{ $$
= OBJECT_TSTEMPLATE
; }
3815 | TEXT_P SEARCH CONFIGURATION
{ $$
= OBJECT_TSCONFIGURATION
; }
3819 any_name
{ $$
= list_make1
($1); }
3820 | any_name_list
',' any_name
{ $$
= lappend
($1, $3); }
3823 any_name: ColId
{ $$
= list_make1
(makeString
($1)); }
3824 | ColId attrs
{ $$
= lcons
(makeString
($1), $2); }
3827 attrs: '.' attr_name
3828 { $$
= list_make1
(makeString
($2)); }
3829 | attrs
'.' attr_name
3830 { $$
= lappend
($1, makeString
($3)); }
3834 /*****************************************************************************
3837 * truncate table relname1, relname2, ...
3839 *****************************************************************************/
3842 TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
3844 TruncateStmt
*n
= makeNode
(TruncateStmt
);
3846 n
->restart_seqs
= $4;
3853 CONTINUE_P IDENTITY_P
{ $$
= false
; }
3854 | RESTART IDENTITY_P
{ $$
= true
; }
3855 |
/* EMPTY */ { $$
= false
; }
3858 /*****************************************************************************
3860 * The COMMENT ON statement can take different forms based upon the type of
3861 * the object associated with the comment. The form of the statement is:
3863 * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
3864 * CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
3865 * CAST | COLUMN | SCHEMA | TABLESPACE | ROLE |
3866 * TEXT SEARCH PARSER | TEXT SEARCH DICTIONARY |
3867 * TEXT SEARCH TEMPLATE |
3868 * TEXT SEARCH CONFIGURATION ] <objname> |
3869 * AGGREGATE <aggname> (arg1, ...) |
3870 * FUNCTION <funcname> (arg1, arg2, ...) |
3871 * OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
3872 * TRIGGER <triggername> ON <relname> |
3873 * CONSTRAINT <constraintname> ON <relname> |
3874 * RULE <rulename> ON <relname> ]
3877 *****************************************************************************/
3880 COMMENT ON comment_type any_name IS comment_text
3882 CommentStmt
*n
= makeNode
(CommentStmt
);
3889 | COMMENT ON AGGREGATE func_name aggr_args IS comment_text
3891 CommentStmt
*n
= makeNode
(CommentStmt
);
3892 n
->objtype
= OBJECT_AGGREGATE
;
3898 | COMMENT ON FUNCTION func_name func_args IS comment_text
3900 CommentStmt
*n
= makeNode
(CommentStmt
);
3901 n
->objtype
= OBJECT_FUNCTION
;
3903 n
->objargs
= extractArgTypes
($5);
3907 | COMMENT ON OPERATOR any_operator oper_argtypes IS comment_text
3909 CommentStmt
*n
= makeNode
(CommentStmt
);
3910 n
->objtype
= OBJECT_OPERATOR
;
3916 | COMMENT ON CONSTRAINT name ON any_name IS comment_text
3918 CommentStmt
*n
= makeNode
(CommentStmt
);
3919 n
->objtype
= OBJECT_CONSTRAINT
;
3920 n
->objname
= lappend
($6, makeString
($4));
3925 | COMMENT ON RULE name ON any_name IS comment_text
3927 CommentStmt
*n
= makeNode
(CommentStmt
);
3928 n
->objtype
= OBJECT_RULE
;
3929 n
->objname
= lappend
($6, makeString
($4));
3934 | COMMENT ON RULE name IS comment_text
3936 /* Obsolete syntax supported for awhile for compatibility */
3937 CommentStmt
*n
= makeNode
(CommentStmt
);
3938 n
->objtype
= OBJECT_RULE
;
3939 n
->objname
= list_make1
(makeString
($4));
3944 | COMMENT ON TRIGGER name ON any_name IS comment_text
3946 CommentStmt
*n
= makeNode
(CommentStmt
);
3947 n
->objtype
= OBJECT_TRIGGER
;
3948 n
->objname
= lappend
($6, makeString
($4));
3953 | COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
3955 CommentStmt
*n
= makeNode
(CommentStmt
);
3956 n
->objtype
= OBJECT_OPCLASS
;
3958 n
->objargs
= list_make1
(makeString
($7));
3962 | COMMENT ON OPERATOR FAMILY any_name USING access_method IS comment_text
3964 CommentStmt
*n
= makeNode
(CommentStmt
);
3965 n
->objtype
= OBJECT_OPFAMILY
;
3967 n
->objargs
= list_make1
(makeString
($7));
3971 | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
3973 CommentStmt
*n
= makeNode
(CommentStmt
);
3974 n
->objtype
= OBJECT_LARGEOBJECT
;
3975 n
->objname
= list_make1
($5);
3980 | COMMENT ON CAST
'(' Typename AS Typename
')' IS comment_text
3982 CommentStmt
*n
= makeNode
(CommentStmt
);
3983 n
->objtype
= OBJECT_CAST
;
3984 n
->objname
= list_make1
($5);
3985 n
->objargs
= list_make1
($7);
3989 | COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
3991 CommentStmt
*n
= makeNode
(CommentStmt
);
3992 n
->objtype
= OBJECT_LANGUAGE
;
3998 | COMMENT ON TEXT_P SEARCH PARSER any_name IS comment_text
4000 CommentStmt
*n
= makeNode
(CommentStmt
);
4001 n
->objtype
= OBJECT_TSPARSER
;
4006 | COMMENT ON TEXT_P SEARCH DICTIONARY any_name IS comment_text
4008 CommentStmt
*n
= makeNode
(CommentStmt
);
4009 n
->objtype
= OBJECT_TSDICTIONARY
;
4014 | COMMENT ON TEXT_P SEARCH TEMPLATE any_name IS comment_text
4016 CommentStmt
*n
= makeNode
(CommentStmt
);
4017 n
->objtype
= OBJECT_TSTEMPLATE
;
4022 | COMMENT ON TEXT_P SEARCH CONFIGURATION any_name IS comment_text
4024 CommentStmt
*n
= makeNode
(CommentStmt
);
4025 n
->objtype
= OBJECT_TSCONFIGURATION
;
4033 COLUMN
{ $$
= OBJECT_COLUMN
; }
4034 | DATABASE
{ $$
= OBJECT_DATABASE
; }
4035 | SCHEMA
{ $$
= OBJECT_SCHEMA
; }
4036 | INDEX
{ $$
= OBJECT_INDEX
; }
4037 | SEQUENCE
{ $$
= OBJECT_SEQUENCE
; }
4038 | TABLE
{ $$
= OBJECT_TABLE
; }
4039 | DOMAIN_P
{ $$
= OBJECT_TYPE
; }
4040 | TYPE_P
{ $$
= OBJECT_TYPE
; }
4041 | VIEW
{ $$
= OBJECT_VIEW
; }
4042 | CONVERSION_P
{ $$
= OBJECT_CONVERSION
; }
4043 | TABLESPACE
{ $$
= OBJECT_TABLESPACE
; }
4044 | ROLE
{ $$
= OBJECT_ROLE
; }
4049 | NULL_P
{ $$
= NULL
; }
4052 /*****************************************************************************
4057 *****************************************************************************/
4059 FetchStmt: FETCH fetch_direction from_in name
4061 FetchStmt
*n
= (FetchStmt
*) $2;
4068 FetchStmt
*n
= makeNode
(FetchStmt
);
4069 n
->direction
= FETCH_FORWARD
;
4075 | MOVE fetch_direction from_in name
4077 FetchStmt
*n
= (FetchStmt
*) $2;
4084 FetchStmt
*n
= makeNode
(FetchStmt
);
4085 n
->direction
= FETCH_FORWARD
;
4096 FetchStmt
*n
= makeNode
(FetchStmt
);
4097 n
->direction
= FETCH_FORWARD
;
4103 FetchStmt
*n
= makeNode
(FetchStmt
);
4104 n
->direction
= FETCH_FORWARD
;
4110 FetchStmt
*n
= makeNode
(FetchStmt
);
4111 n
->direction
= FETCH_BACKWARD
;
4117 FetchStmt
*n
= makeNode
(FetchStmt
);
4118 n
->direction
= FETCH_ABSOLUTE
;
4124 FetchStmt
*n
= makeNode
(FetchStmt
);
4125 n
->direction
= FETCH_ABSOLUTE
;
4129 | ABSOLUTE_P SignedIconst
4131 FetchStmt
*n
= makeNode
(FetchStmt
);
4132 n
->direction
= FETCH_ABSOLUTE
;
4136 | RELATIVE_P SignedIconst
4138 FetchStmt
*n
= makeNode
(FetchStmt
);
4139 n
->direction
= FETCH_RELATIVE
;
4145 FetchStmt
*n
= makeNode
(FetchStmt
);
4146 n
->direction
= FETCH_FORWARD
;
4152 FetchStmt
*n
= makeNode
(FetchStmt
);
4153 n
->direction
= FETCH_FORWARD
;
4154 n
->howMany
= FETCH_ALL
;
4159 FetchStmt
*n
= makeNode
(FetchStmt
);
4160 n
->direction
= FETCH_FORWARD
;
4164 | FORWARD SignedIconst
4166 FetchStmt
*n
= makeNode
(FetchStmt
);
4167 n
->direction
= FETCH_FORWARD
;
4173 FetchStmt
*n
= makeNode
(FetchStmt
);
4174 n
->direction
= FETCH_FORWARD
;
4175 n
->howMany
= FETCH_ALL
;
4180 FetchStmt
*n
= makeNode
(FetchStmt
);
4181 n
->direction
= FETCH_BACKWARD
;
4185 | BACKWARD SignedIconst
4187 FetchStmt
*n
= makeNode
(FetchStmt
);
4188 n
->direction
= FETCH_BACKWARD
;
4194 FetchStmt
*n
= makeNode
(FetchStmt
);
4195 n
->direction
= FETCH_BACKWARD
;
4196 n
->howMany
= FETCH_ALL
;
4206 /*****************************************************************************
4208 * GRANT and REVOKE statements
4210 *****************************************************************************/
4212 GrantStmt: GRANT privileges ON privilege_target TO grantee_list
4213 opt_grant_grant_option
4215 GrantStmt
*n
= makeNode
(GrantStmt
);
4218 n
->objtype
= ($4)->objtype
;
4219 n
->objects
= ($4)->objs
;
4221 n
->grant_option
= $7;
4227 REVOKE privileges ON privilege_target
4228 FROM grantee_list opt_drop_behavior
4230 GrantStmt
*n
= makeNode
(GrantStmt
);
4231 n
->is_grant
= false
;
4232 n
->grant_option
= false
;
4234 n
->objtype
= ($4)->objtype
;
4235 n
->objects
= ($4)->objs
;
4240 | REVOKE GRANT OPTION FOR privileges ON privilege_target
4241 FROM grantee_list opt_drop_behavior
4243 GrantStmt
*n
= makeNode
(GrantStmt
);
4244 n
->is_grant
= false
;
4245 n
->grant_option
= true
;
4247 n
->objtype
= ($7)->objtype
;
4248 n
->objects
= ($7)->objs
;
4257 * Privilege names are represented as strings; the validity of the privilege
4258 * names gets checked at execution. This is a bit annoying but we have little
4259 * choice because of the syntactic conflict with lists of role names in
4260 * GRANT/REVOKE. What's more, we have to call out in the "privilege"
4261 * production any reserved keywords that need to be usable as privilege names.
4264 /* either ALL [PRIVILEGES] or a list of individual privileges */
4265 privileges: privilege_list
4271 | ALL
'(' columnList
')'
4273 AccessPriv
*n
= makeNode
(AccessPriv
);
4274 n
->priv_name
= NULL
;
4278 | ALL PRIVILEGES
'(' columnList
')'
4280 AccessPriv
*n
= makeNode
(AccessPriv
);
4281 n
->priv_name
= NULL
;
4287 privilege_list: privilege
{ $$
= list_make1
($1); }
4288 | privilege_list
',' privilege
{ $$
= lappend
($1, $3); }
4291 privilege: SELECT opt_column_list
4293 AccessPriv
*n
= makeNode
(AccessPriv
);
4294 n
->priv_name
= pstrdup
($1);
4298 | REFERENCES opt_column_list
4300 AccessPriv
*n
= makeNode
(AccessPriv
);
4301 n
->priv_name
= pstrdup
($1);
4305 | CREATE opt_column_list
4307 AccessPriv
*n
= makeNode
(AccessPriv
);
4308 n
->priv_name
= pstrdup
($1);
4312 | ColId opt_column_list
4314 AccessPriv
*n
= makeNode
(AccessPriv
);
4322 /* Don't bother trying to fold the first two rules into one using
4323 * opt_table. You're going to get conflicts.
4328 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
4329 n
->objtype
= ACL_OBJECT_RELATION
;
4333 | TABLE qualified_name_list
4335 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
4336 n
->objtype
= ACL_OBJECT_RELATION
;
4340 | SEQUENCE qualified_name_list
4342 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
4343 n
->objtype
= ACL_OBJECT_SEQUENCE
;
4347 | FOREIGN DATA_P WRAPPER name_list
4349 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
4350 n
->objtype
= ACL_OBJECT_FDW
;
4354 | FOREIGN SERVER name_list
4356 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
4357 n
->objtype
= ACL_OBJECT_FOREIGN_SERVER
;
4361 | FUNCTION function_with_argtypes_list
4363 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
4364 n
->objtype
= ACL_OBJECT_FUNCTION
;
4368 | DATABASE name_list
4370 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
4371 n
->objtype
= ACL_OBJECT_DATABASE
;
4375 | LANGUAGE name_list
4377 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
4378 n
->objtype
= ACL_OBJECT_LANGUAGE
;
4384 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
4385 n
->objtype
= ACL_OBJECT_NAMESPACE
;
4389 | TABLESPACE name_list
4391 PrivTarget
*n
= (PrivTarget
*) palloc
(sizeof
(PrivTarget
));
4392 n
->objtype
= ACL_OBJECT_TABLESPACE
;
4400 grantee
{ $$
= list_make1
($1); }
4401 | grantee_list
',' grantee
{ $$
= lappend
($1, $3); }
4406 PrivGrantee
*n
= makeNode
(PrivGrantee
);
4407 /* This hack lets us avoid reserving PUBLIC as a keyword*/
4408 if
(strcmp
($1, "public") == 0)
4416 PrivGrantee
*n
= makeNode
(PrivGrantee
);
4417 /* Treat GROUP PUBLIC as a synonym for PUBLIC */
4418 if
(strcmp
($2, "public") == 0)
4427 opt_grant_grant_option:
4428 WITH GRANT OPTION
{ $$
= TRUE
; }
4429 |
/*EMPTY*/ { $$
= FALSE
; }
4432 function_with_argtypes_list:
4433 function_with_argtypes
{ $$
= list_make1
($1); }
4434 | function_with_argtypes_list
',' function_with_argtypes
4435 { $$
= lappend
($1, $3); }
4438 function_with_argtypes:
4441 FuncWithArgs
*n
= makeNode
(FuncWithArgs
);
4443 n
->funcargs
= extractArgTypes
($2);
4448 /*****************************************************************************
4450 * GRANT and REVOKE ROLE statements
4452 *****************************************************************************/
4455 GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4457 GrantRoleStmt
*n
= makeNode
(GrantRoleStmt
);
4459 n
->granted_roles
= $2;
4460 n
->grantee_roles
= $4;
4468 REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4470 GrantRoleStmt
*n
= makeNode
(GrantRoleStmt
);
4471 n
->is_grant
= false
;
4472 n
->admin_opt
= false
;
4473 n
->granted_roles
= $2;
4474 n
->grantee_roles
= $4;
4478 | REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4480 GrantRoleStmt
*n
= makeNode
(GrantRoleStmt
);
4481 n
->is_grant
= false
;
4482 n
->admin_opt
= true
;
4483 n
->granted_roles
= $5;
4484 n
->grantee_roles
= $7;
4490 opt_grant_admin_option: WITH ADMIN OPTION
{ $$
= TRUE
; }
4491 |
/*EMPTY*/ { $$
= FALSE
; }
4494 opt_granted_by: GRANTED BY RoleId
{ $$
= $3; }
4495 |
/*EMPTY*/ { $$
= NULL
; }
4499 /*****************************************************************************
4501 * QUERY: CREATE INDEX
4503 * Note: we can't factor CONCURRENTLY into a separate production without
4504 * making it a reserved word.
4506 * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
4507 * willing to make TABLESPACE a fully reserved word.
4508 *****************************************************************************/
4510 IndexStmt: CREATE index_opt_unique INDEX index_name
4511 ON qualified_name access_method_clause
'(' index_params
')'
4512 opt_reloptions OptTableSpace where_clause
4514 IndexStmt
*n
= makeNode
(IndexStmt
);
4516 n
->concurrent
= false
;
4519 n
->accessMethod
= $7;
4520 n
->indexParams
= $9;
4522 n
->tableSpace
= $12;
4523 n
->whereClause
= $13;
4526 | CREATE index_opt_unique INDEX CONCURRENTLY index_name
4527 ON qualified_name access_method_clause
'(' index_params
')'
4528 opt_reloptions OptTableSpace where_clause
4530 IndexStmt
*n
= makeNode
(IndexStmt
);
4532 n
->concurrent
= true
;
4535 n
->accessMethod
= $8;
4536 n
->indexParams
= $10;
4538 n
->tableSpace
= $13;
4539 n
->whereClause
= $14;
4545 UNIQUE
{ $$
= TRUE
; }
4546 |
/*EMPTY*/ { $$
= FALSE
; }
4549 access_method_clause:
4550 USING access_method
{ $$
= $2; }
4551 |
/*EMPTY*/ { $$
= DEFAULT_INDEX_TYPE
; }
4554 index_params: index_elem
{ $$
= list_make1
($1); }
4555 | index_params
',' index_elem
{ $$
= lappend
($1, $3); }
4559 * Index attributes can be either simple column references, or arbitrary
4560 * expressions in parens. For backwards-compatibility reasons, we allow
4561 * an expression that's just a function call to be written without parens.
4563 index_elem: ColId opt_class opt_asc_desc opt_nulls_order
4565 $$
= makeNode
(IndexElem
);
4570 $$
->nulls_ordering
= $4;
4572 | func_expr opt_class opt_asc_desc opt_nulls_order
4574 $$
= makeNode
(IndexElem
);
4579 $$
->nulls_ordering
= $4;
4581 |
'(' a_expr
')' opt_class opt_asc_desc opt_nulls_order
4583 $$
= makeNode
(IndexElem
);
4588 $$
->nulls_ordering
= $6;
4592 opt_class: any_name
{ $$
= $1; }
4593 | USING any_name
{ $$
= $2; }
4594 |
/*EMPTY*/ { $$
= NIL
; }
4597 opt_asc_desc: ASC
{ $$
= SORTBY_ASC
; }
4598 | DESC
{ $$
= SORTBY_DESC
; }
4599 |
/*EMPTY*/ { $$
= SORTBY_DEFAULT
; }
4602 opt_nulls_order: NULLS_FIRST
{ $$
= SORTBY_NULLS_FIRST
; }
4603 | NULLS_LAST
{ $$
= SORTBY_NULLS_LAST
; }
4604 |
/*EMPTY*/ { $$
= SORTBY_NULLS_DEFAULT
; }
4608 /*****************************************************************************
4611 * create [or replace] function <fname>
4612 * [(<type-1> { , <type-n>})]
4614 * as <filename or code in language as appropriate>
4615 * language <lang> [with parameters]
4617 *****************************************************************************/
4620 CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4621 RETURNS func_return createfunc_opt_list opt_definition
4623 CreateFunctionStmt
*n
= makeNode
(CreateFunctionStmt
);
4632 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4633 RETURNS TABLE
'(' table_func_column_list
')' createfunc_opt_list opt_definition
4635 CreateFunctionStmt
*n
= makeNode
(CreateFunctionStmt
);
4638 n
->parameters
= mergeTableFuncParameters
($5, $9);
4639 n
->returnType
= TableFuncTypeName
($9);
4640 n
->returnType
->location
= @
7;
4642 n
->withClause
= $12;
4645 | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
4646 createfunc_opt_list opt_definition
4648 CreateFunctionStmt
*n
= makeNode
(CreateFunctionStmt
);
4652 n
->returnType
= NULL
;
4660 OR REPLACE
{ $$
= TRUE
; }
4661 |
/*EMPTY*/ { $$
= FALSE
; }
4664 func_args: '(' func_args_list
')' { $$
= $2; }
4665 |
'(' ')' { $$
= NIL
; }
4669 func_arg
{ $$
= list_make1
($1); }
4670 | func_args_list
',' func_arg
{ $$
= lappend
($1, $3); }
4674 * func_args_with_defaults is separate because we only want to accept
4675 * defaults in CREATE FUNCTION, not in ALTER etc.
4677 func_args_with_defaults:
4678 '(' func_args_with_defaults_list
')' { $$
= $2; }
4679 |
'(' ')' { $$
= NIL
; }
4682 func_args_with_defaults_list:
4683 func_arg_with_default
{ $$
= list_make1
($1); }
4684 | func_args_with_defaults_list
',' func_arg_with_default
4685 { $$
= lappend
($1, $3); }
4689 * The style with arg_class first is SQL99 standard, but Oracle puts
4690 * param_name first; accept both since it's likely people will try both
4691 * anyway. Don't bother trying to save productions by letting arg_class
4692 * have an empty alternative ... you'll get shift/reduce conflicts.
4694 * We can catch over-specified arguments here if we want to,
4695 * but for now better to silently swallow typmod, etc.
4696 * - thomas 2000-03-22
4699 arg_class param_name func_type
4701 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4708 | param_name arg_class func_type
4710 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4717 | param_name func_type
4719 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4722 n
->mode
= FUNC_PARAM_IN
;
4726 | arg_class func_type
4728 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4737 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4740 n
->mode
= FUNC_PARAM_IN
;
4746 /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
4747 arg_class: IN_P
{ $$
= FUNC_PARAM_IN
; }
4748 | OUT_P
{ $$
= FUNC_PARAM_OUT
; }
4749 | INOUT
{ $$
= FUNC_PARAM_INOUT
; }
4750 | IN_P OUT_P
{ $$
= FUNC_PARAM_INOUT
; }
4751 | VARIADIC
{ $$
= FUNC_PARAM_VARIADIC
; }
4755 * Ideally param_name should be ColId, but that causes too many conflicts.
4757 param_name: type_function_name
4763 /* We can catch over-specified results here if we want to,
4764 * but for now better to silently swallow typmod, etc.
4765 * - thomas 2000-03-22
4772 * We would like to make the %TYPE productions here be ColId attrs etc,
4773 * but that causes reduce/reduce conflicts. type_function_name
4774 * is next best choice.
4776 func_type: Typename
{ $$
= $1; }
4777 | type_function_name attrs
'%' TYPE_P
4779 $$
= makeTypeNameFromNameList
(lcons
(makeString
($1), $2));
4780 $$
->pct_type
= true
;
4783 | SETOF type_function_name attrs
'%' TYPE_P
4785 $$
= makeTypeNameFromNameList
(lcons
(makeString
($2), $3));
4786 $$
->pct_type
= true
;
4792 func_arg_with_default:
4797 | func_arg DEFAULT a_expr
4802 | func_arg
'=' a_expr
4810 createfunc_opt_list:
4811 /* Must be at least one to prevent conflict */
4812 createfunc_opt_item
{ $$
= list_make1
($1); }
4813 | createfunc_opt_list createfunc_opt_item
{ $$
= lappend
($1, $2); }
4817 * Options common to both CREATE FUNCTION and ALTER FUNCTION
4819 common_func_opt_item:
4820 CALLED ON NULL_P INPUT_P
4822 $$
= makeDefElem
("strict", (Node
*)makeInteger
(FALSE
));
4824 | RETURNS NULL_P ON NULL_P INPUT_P
4826 $$
= makeDefElem
("strict", (Node
*)makeInteger
(TRUE
));
4830 $$
= makeDefElem
("strict", (Node
*)makeInteger
(TRUE
));
4834 $$
= makeDefElem
("volatility", (Node
*)makeString
("immutable"));
4838 $$
= makeDefElem
("volatility", (Node
*)makeString
("stable"));
4842 $$
= makeDefElem
("volatility", (Node
*)makeString
("volatile"));
4844 | EXTERNAL SECURITY DEFINER
4846 $$
= makeDefElem
("security", (Node
*)makeInteger
(TRUE
));
4848 | EXTERNAL SECURITY INVOKER
4850 $$
= makeDefElem
("security", (Node
*)makeInteger
(FALSE
));
4854 $$
= makeDefElem
("security", (Node
*)makeInteger
(TRUE
));
4858 $$
= makeDefElem
("security", (Node
*)makeInteger
(FALSE
));
4862 $$
= makeDefElem
("cost", (Node
*)$2);
4866 $$
= makeDefElem
("rows", (Node
*)$2);
4870 /* we abuse the normal content of a DefElem here */
4871 $$
= makeDefElem
("set", (Node
*)$1);
4875 createfunc_opt_item:
4878 $$
= makeDefElem
("as", (Node
*)$2);
4880 | LANGUAGE ColId_or_Sconst
4882 $$
= makeDefElem
("language", (Node
*)makeString
($2));
4886 $$
= makeDefElem
("window", (Node
*)makeInteger
(TRUE
));
4888 | common_func_opt_item
4894 func_as: Sconst
{ $$
= list_make1
(makeString
($1)); }
4897 $$
= list_make2
(makeString
($1), makeString
($3));
4902 WITH definition
{ $$
= $2; }
4903 |
/*EMPTY*/ { $$
= NIL
; }
4906 table_func_column: param_name func_type
4908 FunctionParameter
*n
= makeNode
(FunctionParameter
);
4911 n
->mode
= FUNC_PARAM_TABLE
;
4917 table_func_column_list:
4920 $$
= list_make1
($1);
4922 | table_func_column_list
',' table_func_column
4924 $$
= lappend
($1, $3);
4928 /*****************************************************************************
4931 * RENAME and OWNER subcommands are already provided by the generic
4932 * ALTER infrastructure, here we just specify alterations that can
4933 * only be applied to functions.
4935 *****************************************************************************/
4937 ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
4939 AlterFunctionStmt
*n
= makeNode
(AlterFunctionStmt
);
4947 /* At least one option must be specified */
4948 common_func_opt_item
{ $$
= list_make1
($1); }
4949 | alterfunc_opt_list common_func_opt_item
{ $$
= lappend
($1, $2); }
4952 /* Ignored, merely for SQL compliance */
4959 /*****************************************************************************
4963 * DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
4964 * DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
4965 * DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
4967 *****************************************************************************/
4970 DROP FUNCTION func_name func_args opt_drop_behavior
4972 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4973 n
->kind
= OBJECT_FUNCTION
;
4975 n
->args
= extractArgTypes
($4);
4977 n
->missing_ok
= false
;
4980 | DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
4982 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4983 n
->kind
= OBJECT_FUNCTION
;
4985 n
->args
= extractArgTypes
($6);
4987 n
->missing_ok
= true
;
4993 DROP AGGREGATE func_name aggr_args opt_drop_behavior
4995 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
4996 n
->kind
= OBJECT_AGGREGATE
;
5000 n
->missing_ok
= false
;
5003 | DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
5005 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
5006 n
->kind
= OBJECT_AGGREGATE
;
5010 n
->missing_ok
= true
;
5016 DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
5018 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
5019 n
->kind
= OBJECT_OPERATOR
;
5023 n
->missing_ok
= false
;
5026 | DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
5028 RemoveFuncStmt
*n
= makeNode
(RemoveFuncStmt
);
5029 n
->kind
= OBJECT_OPERATOR
;
5033 n
->missing_ok
= true
;
5042 (errcode
(ERRCODE_SYNTAX_ERROR
),
5043 errmsg
("missing argument"),
5044 errhint
("Use NONE to denote the missing argument of a unary operator."),
5045 scanner_errposition
(@
3)));
5047 |
'(' Typename
',' Typename
')'
5048 { $$
= list_make2
($2, $4); }
5049 |
'(' NONE
',' Typename
')' /* left unary */
5050 { $$
= list_make2
(NULL
, $4); }
5051 |
'(' Typename
',' NONE
')' /* right unary */
5052 { $$
= list_make2
($2, NULL
); }
5057 { $$
= list_make1
(makeString
($1)); }
5058 | ColId
'.' any_operator
5059 { $$
= lcons
(makeString
($1), $3); }
5063 /*****************************************************************************
5065 * CREATE CAST / DROP CAST
5067 *****************************************************************************/
5069 CreateCastStmt: CREATE CAST
'(' Typename AS Typename
')'
5070 WITH FUNCTION function_with_argtypes cast_context
5072 CreateCastStmt
*n
= makeNode
(CreateCastStmt
);
5076 n
->context
= (CoercionContext
) $11;
5080 | CREATE CAST
'(' Typename AS Typename
')'
5081 WITHOUT FUNCTION cast_context
5083 CreateCastStmt
*n
= makeNode
(CreateCastStmt
);
5087 n
->context
= (CoercionContext
) $10;
5091 | CREATE CAST
'(' Typename AS Typename
')'
5092 WITH INOUT cast_context
5094 CreateCastStmt
*n
= makeNode
(CreateCastStmt
);
5098 n
->context
= (CoercionContext
) $10;
5104 cast_context: AS IMPLICIT_P
{ $$
= COERCION_IMPLICIT
; }
5105 | AS ASSIGNMENT
{ $$
= COERCION_ASSIGNMENT
; }
5106 |
/*EMPTY*/ { $$
= COERCION_EXPLICIT
; }
5110 DropCastStmt: DROP CAST opt_if_exists
'(' Typename AS Typename
')' opt_drop_behavior
5112 DropCastStmt
*n
= makeNode
(DropCastStmt
);
5121 opt_if_exists: IF_P EXISTS
{ $$
= TRUE
; }
5122 |
/*EMPTY*/ { $$
= FALSE
; }
5126 /*****************************************************************************
5130 * REINDEX type <name> [FORCE]
5132 * FORCE no longer does anything, but we accept it for backwards compatibility
5133 *****************************************************************************/
5136 REINDEX reindex_type qualified_name opt_force
5138 ReindexStmt
*n
= makeNode
(ReindexStmt
);
5144 | REINDEX SYSTEM_P name opt_force
5146 ReindexStmt
*n
= makeNode
(ReindexStmt
);
5147 n
->kind
= OBJECT_DATABASE
;
5150 n
->do_system
= true
;
5154 | REINDEX DATABASE name opt_force
5156 ReindexStmt
*n
= makeNode
(ReindexStmt
);
5157 n
->kind
= OBJECT_DATABASE
;
5160 n
->do_system
= true
;
5167 INDEX
{ $$
= OBJECT_INDEX
; }
5168 | TABLE
{ $$
= OBJECT_TABLE
; }
5171 opt_force: FORCE
{ $$
= TRUE
; }
5172 |
/* EMPTY */ { $$
= FALSE
; }
5176 /*****************************************************************************
5178 * ALTER THING name RENAME TO newname
5180 *****************************************************************************/
5182 RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
5184 RenameStmt
*n
= makeNode
(RenameStmt
);
5185 n
->renameType
= OBJECT_AGGREGATE
;
5191 | ALTER CONVERSION_P any_name RENAME TO name
5193 RenameStmt
*n
= makeNode
(RenameStmt
);
5194 n
->renameType
= OBJECT_CONVERSION
;
5199 | ALTER DATABASE database_name RENAME TO database_name
5201 RenameStmt
*n
= makeNode
(RenameStmt
);
5202 n
->renameType
= OBJECT_DATABASE
;
5207 | ALTER FUNCTION function_with_argtypes RENAME TO name
5209 RenameStmt
*n
= makeNode
(RenameStmt
);
5210 n
->renameType
= OBJECT_FUNCTION
;
5211 n
->object
= $3->funcname
;
5212 n
->objarg
= $3->funcargs
;
5216 | ALTER GROUP_P RoleId RENAME TO RoleId
5218 RenameStmt
*n
= makeNode
(RenameStmt
);
5219 n
->renameType
= OBJECT_ROLE
;
5224 | ALTER opt_procedural LANGUAGE name RENAME TO name
5226 RenameStmt
*n
= makeNode
(RenameStmt
);
5227 n
->renameType
= OBJECT_LANGUAGE
;
5232 | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
5234 RenameStmt
*n
= makeNode
(RenameStmt
);
5235 n
->renameType
= OBJECT_OPCLASS
;
5241 | ALTER OPERATOR FAMILY any_name USING access_method RENAME TO name
5243 RenameStmt
*n
= makeNode
(RenameStmt
);
5244 n
->renameType
= OBJECT_OPFAMILY
;
5250 | ALTER SCHEMA name RENAME TO name
5252 RenameStmt
*n
= makeNode
(RenameStmt
);
5253 n
->renameType
= OBJECT_SCHEMA
;
5258 | ALTER TABLE relation_expr RENAME TO name
5260 RenameStmt
*n
= makeNode
(RenameStmt
);
5261 n
->renameType
= OBJECT_TABLE
;
5267 | ALTER SEQUENCE qualified_name RENAME TO name
5269 RenameStmt
*n
= makeNode
(RenameStmt
);
5270 n
->renameType
= OBJECT_SEQUENCE
;
5276 | ALTER VIEW qualified_name RENAME TO name
5278 RenameStmt
*n
= makeNode
(RenameStmt
);
5279 n
->renameType
= OBJECT_VIEW
;
5285 | ALTER INDEX qualified_name RENAME TO name
5287 RenameStmt
*n
= makeNode
(RenameStmt
);
5288 n
->renameType
= OBJECT_INDEX
;
5294 | ALTER TABLE relation_expr RENAME opt_column name TO name
5296 RenameStmt
*n
= makeNode
(RenameStmt
);
5297 n
->renameType
= OBJECT_COLUMN
;
5303 | ALTER TRIGGER name ON qualified_name RENAME TO name
5305 RenameStmt
*n
= makeNode
(RenameStmt
);
5306 n
->renameType
= OBJECT_TRIGGER
;
5312 | ALTER ROLE RoleId RENAME TO RoleId
5314 RenameStmt
*n
= makeNode
(RenameStmt
);
5315 n
->renameType
= OBJECT_ROLE
;
5320 | ALTER USER RoleId RENAME TO RoleId
5322 RenameStmt
*n
= makeNode
(RenameStmt
);
5323 n
->renameType
= OBJECT_ROLE
;
5328 | ALTER TABLESPACE name RENAME TO name
5330 RenameStmt
*n
= makeNode
(RenameStmt
);
5331 n
->renameType
= OBJECT_TABLESPACE
;
5336 | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
5338 RenameStmt
*n
= makeNode
(RenameStmt
);
5339 n
->renameType
= OBJECT_TSPARSER
;
5344 | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
5346 RenameStmt
*n
= makeNode
(RenameStmt
);
5347 n
->renameType
= OBJECT_TSDICTIONARY
;
5352 | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
5354 RenameStmt
*n
= makeNode
(RenameStmt
);
5355 n
->renameType
= OBJECT_TSTEMPLATE
;
5360 | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
5362 RenameStmt
*n
= makeNode
(RenameStmt
);
5363 n
->renameType
= OBJECT_TSCONFIGURATION
;
5368 | ALTER TYPE_P any_name RENAME TO name
5370 RenameStmt
*n
= makeNode
(RenameStmt
);
5371 n
->renameType
= OBJECT_TYPE
;
5378 opt_column: COLUMN
{ $$
= COLUMN
; }
5379 |
/*EMPTY*/ { $$
= 0; }
5382 opt_set_data: SET DATA_P
{ $$
= 1; }
5383 |
/*EMPTY*/ { $$
= 0; }
5386 /*****************************************************************************
5388 * ALTER THING name SET SCHEMA name
5390 *****************************************************************************/
5392 AlterObjectSchemaStmt:
5393 ALTER AGGREGATE func_name aggr_args SET SCHEMA name
5395 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
5396 n
->objectType
= OBJECT_AGGREGATE
;
5402 | ALTER DOMAIN_P any_name SET SCHEMA name
5404 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
5405 n
->objectType
= OBJECT_DOMAIN
;
5410 | ALTER FUNCTION function_with_argtypes SET SCHEMA name
5412 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
5413 n
->objectType
= OBJECT_FUNCTION
;
5414 n
->object
= $3->funcname
;
5415 n
->objarg
= $3->funcargs
;
5419 | ALTER TABLE relation_expr SET SCHEMA name
5421 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
5422 n
->objectType
= OBJECT_TABLE
;
5427 | ALTER SEQUENCE qualified_name SET SCHEMA name
5429 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
5430 n
->objectType
= OBJECT_SEQUENCE
;
5435 | ALTER VIEW qualified_name SET SCHEMA name
5437 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
5438 n
->objectType
= OBJECT_VIEW
;
5443 | ALTER TYPE_P any_name SET SCHEMA name
5445 AlterObjectSchemaStmt
*n
= makeNode
(AlterObjectSchemaStmt
);
5446 n
->objectType
= OBJECT_TYPE
;
5453 /*****************************************************************************
5455 * ALTER THING name OWNER TO newname
5457 *****************************************************************************/
5459 AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
5461 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5462 n
->objectType
= OBJECT_AGGREGATE
;
5468 | ALTER CONVERSION_P any_name OWNER TO RoleId
5470 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5471 n
->objectType
= OBJECT_CONVERSION
;
5476 | ALTER DATABASE database_name OWNER TO RoleId
5478 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5479 n
->objectType
= OBJECT_DATABASE
;
5480 n
->object
= list_make1
(makeString
($3));
5484 | ALTER DOMAIN_P any_name OWNER TO RoleId
5486 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5487 n
->objectType
= OBJECT_DOMAIN
;
5492 | ALTER FUNCTION function_with_argtypes OWNER TO RoleId
5494 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5495 n
->objectType
= OBJECT_FUNCTION
;
5496 n
->object
= $3->funcname
;
5497 n
->objarg
= $3->funcargs
;
5501 | ALTER opt_procedural LANGUAGE name OWNER TO RoleId
5503 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5504 n
->objectType
= OBJECT_LANGUAGE
;
5505 n
->object
= list_make1
(makeString
($4));
5509 | ALTER OPERATOR any_operator oper_argtypes OWNER TO RoleId
5511 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5512 n
->objectType
= OBJECT_OPERATOR
;
5518 | ALTER OPERATOR CLASS any_name USING access_method OWNER TO RoleId
5520 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5521 n
->objectType
= OBJECT_OPCLASS
;
5527 | ALTER OPERATOR FAMILY any_name USING access_method OWNER TO RoleId
5529 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5530 n
->objectType
= OBJECT_OPFAMILY
;
5536 | ALTER SCHEMA name OWNER TO RoleId
5538 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5539 n
->objectType
= OBJECT_SCHEMA
;
5540 n
->object
= list_make1
(makeString
($3));
5544 | ALTER TYPE_P any_name OWNER TO RoleId
5546 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5547 n
->objectType
= OBJECT_TYPE
;
5552 | ALTER TABLESPACE name OWNER TO RoleId
5554 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5555 n
->objectType
= OBJECT_TABLESPACE
;
5556 n
->object
= list_make1
(makeString
($3));
5560 | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleId
5562 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5563 n
->objectType
= OBJECT_TSDICTIONARY
;
5568 | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleId
5570 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5571 n
->objectType
= OBJECT_TSCONFIGURATION
;
5576 | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleId
5578 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5579 n
->objectType
= OBJECT_FDW
;
5580 n
->object
= list_make1
(makeString
($5));
5584 | ALTER SERVER name OWNER TO RoleId
5586 AlterOwnerStmt
*n
= makeNode
(AlterOwnerStmt
);
5587 n
->objectType
= OBJECT_FOREIGN_SERVER
;
5588 n
->object
= list_make1
(makeString
($3));
5595 /*****************************************************************************
5597 * QUERY: Define Rewrite Rule
5599 *****************************************************************************/
5601 RuleStmt: CREATE opt_or_replace RULE name AS
5602 { QueryIsRule
=TRUE
; }
5603 ON event TO qualified_name where_clause
5604 DO opt_instead RuleActionList
5606 RuleStmt
*n
= makeNode
(RuleStmt
);
5610 n
->whereClause
= $11;
5620 NOTHING
{ $$
= NIL
; }
5621 | RuleActionStmt
{ $$
= list_make1
($1); }
5622 |
'(' RuleActionMulti
')' { $$
= $2; }
5625 /* the thrashing around here is to discard "empty" statements... */
5627 RuleActionMulti
';' RuleActionStmtOrEmpty
5629 $$
= lappend
($1, $3);
5633 | RuleActionStmtOrEmpty
5635 $$
= list_make1
($1);
5649 RuleActionStmtOrEmpty:
5650 RuleActionStmt
{ $$
= $1; }
5651 |
/*EMPTY*/ { $$
= NULL
; }
5654 event: SELECT
{ $$
= CMD_SELECT
; }
5655 | UPDATE
{ $$
= CMD_UPDATE
; }
5656 | DELETE_P
{ $$
= CMD_DELETE
; }
5657 | INSERT
{ $$
= CMD_INSERT
; }
5661 INSTEAD
{ $$
= TRUE
; }
5662 | ALSO
{ $$
= FALSE
; }
5663 |
/*EMPTY*/ { $$
= FALSE
; }
5668 DROP RULE name ON qualified_name opt_drop_behavior
5670 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
5674 n
->removeType
= OBJECT_RULE
;
5675 n
->missing_ok
= false
;
5678 | DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
5680 DropPropertyStmt
*n
= makeNode
(DropPropertyStmt
);
5684 n
->removeType
= OBJECT_RULE
;
5685 n
->missing_ok
= true
;
5691 /*****************************************************************************
5694 * NOTIFY <identifier> can appear both in rule bodies and
5695 * as a query-level command
5697 *****************************************************************************/
5699 NotifyStmt: NOTIFY ColId
5701 NotifyStmt
*n
= makeNode
(NotifyStmt
);
5702 n
->conditionname
= $2;
5707 ListenStmt: LISTEN ColId
5709 ListenStmt
*n
= makeNode
(ListenStmt
);
5710 n
->conditionname
= $2;
5718 UnlistenStmt
*n
= makeNode
(UnlistenStmt
);
5719 n
->conditionname
= $2;
5724 UnlistenStmt
*n
= makeNode
(UnlistenStmt
);
5725 n
->conditionname
= NULL
;
5731 /*****************************************************************************
5735 * BEGIN / COMMIT / ROLLBACK
5736 * (also older versions END / ABORT)
5738 *****************************************************************************/
5741 ABORT_P opt_transaction
5743 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5744 n
->kind
= TRANS_STMT_ROLLBACK
;
5748 | BEGIN_P opt_transaction transaction_mode_list_or_empty
5750 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5751 n
->kind
= TRANS_STMT_BEGIN
;
5755 | START TRANSACTION transaction_mode_list_or_empty
5757 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5758 n
->kind
= TRANS_STMT_START
;
5762 | COMMIT opt_transaction
5764 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5765 n
->kind
= TRANS_STMT_COMMIT
;
5769 | END_P opt_transaction
5771 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5772 n
->kind
= TRANS_STMT_COMMIT
;
5776 | ROLLBACK opt_transaction
5778 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5779 n
->kind
= TRANS_STMT_ROLLBACK
;
5785 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5786 n
->kind
= TRANS_STMT_SAVEPOINT
;
5787 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5788 (Node
*)makeString
($2)));
5791 | RELEASE SAVEPOINT ColId
5793 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5794 n
->kind
= TRANS_STMT_RELEASE
;
5795 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5796 (Node
*)makeString
($3)));
5801 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5802 n
->kind
= TRANS_STMT_RELEASE
;
5803 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5804 (Node
*)makeString
($2)));
5807 | ROLLBACK opt_transaction TO SAVEPOINT ColId
5809 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5810 n
->kind
= TRANS_STMT_ROLLBACK_TO
;
5811 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5812 (Node
*)makeString
($5)));
5815 | ROLLBACK opt_transaction TO ColId
5817 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5818 n
->kind
= TRANS_STMT_ROLLBACK_TO
;
5819 n
->options
= list_make1
(makeDefElem
("savepoint_name",
5820 (Node
*)makeString
($4)));
5823 | PREPARE TRANSACTION Sconst
5825 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5826 n
->kind
= TRANS_STMT_PREPARE
;
5830 | COMMIT PREPARED Sconst
5832 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5833 n
->kind
= TRANS_STMT_COMMIT_PREPARED
;
5837 | ROLLBACK PREPARED Sconst
5839 TransactionStmt
*n
= makeNode
(TransactionStmt
);
5840 n
->kind
= TRANS_STMT_ROLLBACK_PREPARED
;
5846 opt_transaction: WORK
{}
5851 transaction_mode_item:
5852 ISOLATION LEVEL iso_level
5853 { $$
= makeDefElem
("transaction_isolation",
5854 makeStringConst
($3, @
3)); }
5856 { $$
= makeDefElem
("transaction_read_only",
5857 makeIntConst
(TRUE
, @
1)); }
5859 { $$
= makeDefElem
("transaction_read_only",
5860 makeIntConst
(FALSE
, @
1)); }
5863 /* Syntax with commas is SQL-spec, without commas is Postgres historical */
5864 transaction_mode_list:
5865 transaction_mode_item
5866 { $$
= list_make1
($1); }
5867 | transaction_mode_list
',' transaction_mode_item
5868 { $$
= lappend
($1, $3); }
5869 | transaction_mode_list transaction_mode_item
5870 { $$
= lappend
($1, $2); }
5873 transaction_mode_list_or_empty:
5874 transaction_mode_list
5880 /*****************************************************************************
5883 * CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
5884 * AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
5886 *****************************************************************************/
5888 ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list
5889 AS SelectStmt opt_check_option
5891 ViewStmt
*n
= makeNode
(ViewStmt
);
5893 n
->view
->istemp
= $2;
5899 | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list
5900 AS SelectStmt opt_check_option
5902 ViewStmt
*n
= makeNode
(ViewStmt
);
5904 n
->view
->istemp
= $4;
5916 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
5917 errmsg
("WITH CHECK OPTION is not implemented")));
5919 | WITH CASCADED CHECK OPTION
5922 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
5923 errmsg
("WITH CHECK OPTION is not implemented")));
5925 | WITH LOCAL CHECK OPTION
5928 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
5929 errmsg
("WITH CHECK OPTION is not implemented")));
5931 |
/* EMPTY */ { $$
= NIL
; }
5934 /*****************************************************************************
5939 *****************************************************************************/
5941 LoadStmt: LOAD file_name
5943 LoadStmt
*n
= makeNode
(LoadStmt
);
5950 /*****************************************************************************
5954 *****************************************************************************/
5957 CREATE DATABASE database_name opt_with createdb_opt_list
5959 CreatedbStmt
*n
= makeNode
(CreatedbStmt
);
5967 createdb_opt_list createdb_opt_item
{ $$
= lappend
($1, $2); }
5968 |
/* EMPTY */ { $$
= NIL
; }
5972 TABLESPACE opt_equal name
5974 $$
= makeDefElem
("tablespace", (Node
*)makeString
($3));
5976 | TABLESPACE opt_equal DEFAULT
5978 $$
= makeDefElem
("tablespace", NULL
);
5980 | LOCATION opt_equal Sconst
5982 $$
= makeDefElem
("location", (Node
*)makeString
($3));
5984 | LOCATION opt_equal DEFAULT
5986 $$
= makeDefElem
("location", NULL
);
5988 | TEMPLATE opt_equal name
5990 $$
= makeDefElem
("template", (Node
*)makeString
($3));
5992 | TEMPLATE opt_equal DEFAULT
5994 $$
= makeDefElem
("template", NULL
);
5996 | ENCODING opt_equal Sconst
5998 $$
= makeDefElem
("encoding", (Node
*)makeString
($3));
6000 | ENCODING opt_equal Iconst
6002 $$
= makeDefElem
("encoding", (Node
*)makeInteger
($3));
6004 | ENCODING opt_equal DEFAULT
6006 $$
= makeDefElem
("encoding", NULL
);
6008 | LC_COLLATE_P opt_equal Sconst
6010 $$
= makeDefElem
("lc_collate", (Node
*)makeString
($3));
6012 | LC_COLLATE_P opt_equal DEFAULT
6014 $$
= makeDefElem
("lc_collate", NULL
);
6016 | LC_CTYPE_P opt_equal Sconst
6018 $$
= makeDefElem
("lc_ctype", (Node
*)makeString
($3));
6020 | LC_CTYPE_P opt_equal DEFAULT
6022 $$
= makeDefElem
("lc_ctype", NULL
);
6024 | CONNECTION LIMIT opt_equal SignedIconst
6026 $$
= makeDefElem
("connectionlimit", (Node
*)makeInteger
($4));
6028 | OWNER opt_equal name
6030 $$
= makeDefElem
("owner", (Node
*)makeString
($3));
6032 | OWNER opt_equal DEFAULT
6034 $$
= makeDefElem
("owner", NULL
);
6039 * Though the equals sign doesn't match other WITH options, pg_dump uses
6040 * equals for backward compatibility, and it doesn't seem worth removing it.
6047 /*****************************************************************************
6051 *****************************************************************************/
6054 ALTER DATABASE database_name opt_with alterdb_opt_list
6056 AlterDatabaseStmt
*n
= makeNode
(AlterDatabaseStmt
);
6061 | ALTER DATABASE database_name SET TABLESPACE name
6063 AlterDatabaseStmt
*n
= makeNode
(AlterDatabaseStmt
);
6065 n
->options
= list_make1
(makeDefElem
("tablespace",
6066 (Node
*)makeString
($6)));
6071 AlterDatabaseSetStmt:
6072 ALTER DATABASE database_name SetResetClause
6074 AlterDatabaseSetStmt
*n
= makeNode
(AlterDatabaseSetStmt
);
6083 alterdb_opt_list alterdb_opt_item
{ $$
= lappend
($1, $2); }
6084 |
/* EMPTY */ { $$
= NIL
; }
6088 CONNECTION LIMIT opt_equal SignedIconst
6090 $$
= makeDefElem
("connectionlimit", (Node
*)makeInteger
($4));
6095 /*****************************************************************************
6097 * DROP DATABASE [ IF EXISTS ]
6099 * This is implicitly CASCADE, no need for drop behavior
6100 *****************************************************************************/
6102 DropdbStmt: DROP DATABASE database_name
6104 DropdbStmt
*n
= makeNode
(DropdbStmt
);
6106 n
->missing_ok
= FALSE
;
6109 | DROP DATABASE IF_P EXISTS database_name
6111 DropdbStmt
*n
= makeNode
(DropdbStmt
);
6113 n
->missing_ok
= TRUE
;
6119 /*****************************************************************************
6121 * Manipulate a domain
6123 *****************************************************************************/
6126 CREATE DOMAIN_P any_name opt_as Typename ColQualList
6128 CreateDomainStmt
*n
= makeNode
(CreateDomainStmt
);
6131 n
->constraints
= $6;
6137 /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
6138 ALTER DOMAIN_P any_name alter_column_default
6140 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
6146 /* ALTER DOMAIN <domain> DROP NOT NULL */
6147 | ALTER DOMAIN_P any_name DROP NOT NULL_P
6149 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
6154 /* ALTER DOMAIN <domain> SET NOT NULL */
6155 | ALTER DOMAIN_P any_name SET NOT NULL_P
6157 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
6162 /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
6163 | ALTER DOMAIN_P any_name ADD_P TableConstraint
6165 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
6171 /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
6172 | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
6174 AlterDomainStmt
*n
= makeNode
(AlterDomainStmt
);
6188 /*****************************************************************************
6190 * Manipulate a text search dictionary or configuration
6192 *****************************************************************************/
6194 AlterTSDictionaryStmt:
6195 ALTER TEXT_P SEARCH DICTIONARY any_name definition
6197 AlterTSDictionaryStmt
*n
= makeNode
(AlterTSDictionaryStmt
);
6204 AlterTSConfigurationStmt:
6205 ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
6207 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
6211 n
->override
= false
;
6215 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list WITH any_name_list
6217 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
6225 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name WITH any_name
6227 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
6230 n
->dicts
= list_make2
($9,$11);
6231 n
->override
= false
;
6235 | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name WITH any_name
6237 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
6240 n
->dicts
= list_make2
($11,$13);
6241 n
->override
= false
;
6245 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
6247 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
6250 n
->missing_ok
= false
;
6253 | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
6255 AlterTSConfigurationStmt
*n
= makeNode
(AlterTSConfigurationStmt
);
6258 n
->missing_ok
= true
;
6264 /*****************************************************************************
6266 * Manipulate a conversion
6268 * CREATE [DEFAULT] CONVERSION <conversion_name>
6269 * FOR <encoding_name> TO <encoding_name> FROM <func_name>
6271 *****************************************************************************/
6273 CreateConversionStmt:
6274 CREATE opt_default CONVERSION_P any_name FOR Sconst
6275 TO Sconst FROM any_name
6277 CreateConversionStmt
*n
= makeNode
(CreateConversionStmt
);
6278 n
->conversion_name
= $4;
6279 n
->for_encoding_name
= $6;
6280 n
->to_encoding_name
= $8;
6287 /*****************************************************************************
6290 * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
6292 * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
6294 *****************************************************************************/
6297 CLUSTER opt_verbose qualified_name cluster_index_specification
6299 ClusterStmt
*n
= makeNode
(ClusterStmt
);
6305 | CLUSTER opt_verbose
6307 ClusterStmt
*n
= makeNode
(ClusterStmt
);
6309 n
->indexname
= NULL
;
6313 /* kept for pre-8.3 compatibility */
6314 | CLUSTER opt_verbose index_name ON qualified_name
6316 ClusterStmt
*n
= makeNode
(ClusterStmt
);
6324 cluster_index_specification:
6325 USING index_name
{ $$
= $2; }
6326 |
/*EMPTY*/ { $$
= NULL
; }
6330 /*****************************************************************************
6336 *****************************************************************************/
6338 VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
6340 VacuumStmt
*n
= makeNode
(VacuumStmt
);
6344 n
->freeze_min_age
= $3 ?
0 : -1;
6345 n
->freeze_table_age
= $3 ?
0 : -1;
6351 | VACUUM opt_full opt_freeze opt_verbose qualified_name
6353 VacuumStmt
*n
= makeNode
(VacuumStmt
);
6357 n
->freeze_min_age
= $3 ?
0 : -1;
6358 n
->freeze_table_age
= $3 ?
0 : -1;
6364 | VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
6366 VacuumStmt
*n
= (VacuumStmt
*) $5;
6369 n
->freeze_min_age
= $3 ?
0 : -1;
6370 n
->freeze_table_age
= $3 ?
0 : -1;
6377 analyze_keyword opt_verbose
6379 VacuumStmt
*n
= makeNode
(VacuumStmt
);
6383 n
->freeze_min_age
= -1;
6384 n
->freeze_table_age
= -1;
6390 | analyze_keyword opt_verbose qualified_name opt_name_list
6392 VacuumStmt
*n
= makeNode
(VacuumStmt
);
6396 n
->freeze_min_age
= -1;
6397 n
->freeze_table_age
= -1;
6407 | ANALYSE
/* British */ {}
6411 VERBOSE
{ $$
= TRUE
; }
6412 |
/*EMPTY*/ { $$
= FALSE
; }
6415 opt_full: FULL
{ $$
= TRUE
; }
6416 |
/*EMPTY*/ { $$
= FALSE
; }
6419 opt_freeze: FREEZE
{ $$
= TRUE
; }
6420 |
/*EMPTY*/ { $$
= FALSE
; }
6424 '(' name_list
')' { $$
= $2; }
6425 |
/*EMPTY*/ { $$
= NIL
; }
6429 /*****************************************************************************
6432 * EXPLAIN [ANALYZE] [VERBOSE] query
6434 *****************************************************************************/
6436 ExplainStmt: EXPLAIN opt_analyze opt_verbose ExplainableStmt
6438 ExplainStmt
*n
= makeNode
(ExplainStmt
);
6453 | ExecuteStmt
/* by default all are $$=$1 */
6457 analyze_keyword
{ $$
= TRUE
; }
6458 |
/* EMPTY */ { $$
= FALSE
; }
6461 /*****************************************************************************
6464 * PREPARE <plan_name> [(args, ...)] AS <query>
6466 *****************************************************************************/
6468 PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
6470 PrepareStmt
*n
= makeNode
(PrepareStmt
);
6478 prep_type_clause: '(' type_list
')' { $$
= $2; }
6479 |
/* EMPTY */ { $$
= NIL
; }
6486 | DeleteStmt
/* by default all are $$=$1 */
6489 /*****************************************************************************
6491 * EXECUTE <plan_name> [(params, ...)]
6492 * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
6494 *****************************************************************************/
6496 ExecuteStmt: EXECUTE name execute_param_clause
6498 ExecuteStmt
*n
= makeNode
(ExecuteStmt
);
6504 | CREATE OptTemp TABLE create_as_target AS
6505 EXECUTE name execute_param_clause
6507 ExecuteStmt
*n
= makeNode
(ExecuteStmt
);
6510 $4->rel
->istemp
= $2;
6514 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
6515 errmsg
("column name list not allowed in CREATE TABLE / AS EXECUTE")));
6516 /* ... because it's not implemented, but it could be */
6521 execute_param_clause: '(' expr_list
')' { $$
= $2; }
6522 |
/* EMPTY */ { $$
= NIL
; }
6525 /*****************************************************************************
6528 * DEALLOCATE [PREPARE] <plan_name>
6530 *****************************************************************************/
6532 DeallocateStmt: DEALLOCATE name
6534 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
6538 | DEALLOCATE PREPARE name
6540 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
6546 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
6550 | DEALLOCATE PREPARE ALL
6552 DeallocateStmt
*n
= makeNode
(DeallocateStmt
);
6558 /*****************************************************************************
6563 *****************************************************************************/
6566 INSERT INTO qualified_name insert_rest returning_clause
6569 $4->returningList
= $5;
6577 $$
= makeNode
(InsertStmt
);
6579 $$
->selectStmt
= $1;
6581 |
'(' insert_column_list
')' SelectStmt
6583 $$
= makeNode
(InsertStmt
);
6585 $$
->selectStmt
= $4;
6589 $$
= makeNode
(InsertStmt
);
6591 $$
->selectStmt
= NULL
;
6597 { $$
= list_make1
($1); }
6598 | insert_column_list
',' insert_column_item
6599 { $$
= lappend
($1, $3); }
6603 ColId opt_indirection
6605 $$
= makeNode
(ResTarget
);
6607 $$
->indirection
= check_indirection
($2);
6614 RETURNING target_list
{ $$
= $2; }
6615 |
/* EMPTY */ { $$
= NIL
; }
6619 /*****************************************************************************
6624 *****************************************************************************/
6626 DeleteStmt: DELETE_P FROM relation_expr_opt_alias
6627 using_clause where_or_current_clause returning_clause
6629 DeleteStmt
*n
= makeNode
(DeleteStmt
);
6631 n
->usingClause
= $4;
6632 n
->whereClause
= $5;
6633 n
->returningList
= $6;
6639 USING from_list
{ $$
= $2; }
6640 |
/*EMPTY*/ { $$
= NIL
; }
6644 /*****************************************************************************
6649 *****************************************************************************/
6651 LockStmt: LOCK_P opt_table relation_expr_list opt_lock opt_nowait
6653 LockStmt
*n
= makeNode
(LockStmt
);
6662 opt_lock: IN_P lock_type MODE
{ $$
= $2; }
6663 |
/*EMPTY*/ { $$
= AccessExclusiveLock
; }
6666 lock_type: ACCESS SHARE
{ $$
= AccessShareLock
; }
6667 | ROW SHARE
{ $$
= RowShareLock
; }
6668 | ROW EXCLUSIVE
{ $$
= RowExclusiveLock
; }
6669 | SHARE UPDATE EXCLUSIVE
{ $$
= ShareUpdateExclusiveLock
; }
6670 | SHARE
{ $$
= ShareLock
; }
6671 | SHARE ROW EXCLUSIVE
{ $$
= ShareRowExclusiveLock
; }
6672 | EXCLUSIVE
{ $$
= ExclusiveLock
; }
6673 | ACCESS EXCLUSIVE
{ $$
= AccessExclusiveLock
; }
6676 opt_nowait: NOWAIT
{ $$
= TRUE
; }
6677 |
/*EMPTY*/ { $$
= FALSE
; }
6681 /*****************************************************************************
6684 * UpdateStmt (UPDATE)
6686 *****************************************************************************/
6688 UpdateStmt: UPDATE relation_expr_opt_alias
6691 where_or_current_clause
6694 UpdateStmt
*n
= makeNode
(UpdateStmt
);
6698 n
->whereClause
= $6;
6699 n
->returningList
= $7;
6705 set_clause
{ $$
= $1; }
6706 | set_clause_list
',' set_clause
{ $$
= list_concat
($1,$3); }
6710 single_set_clause
{ $$
= list_make1
($1); }
6711 | multiple_set_clause
{ $$
= $1; }
6715 set_target
'=' ctext_expr
6718 $$
->val
= (Node
*) $3;
6722 multiple_set_clause:
6723 '(' set_target_list
')' '=' ctext_row
6729 * Break the ctext_row apart, merge individual expressions
6730 * into the destination ResTargets. XXX this approach
6731 * cannot work for general row expressions as sources.
6733 if
(list_length
($2) != list_length
($5))
6735 (errcode
(ERRCODE_SYNTAX_ERROR
),
6736 errmsg
("number of columns does not match number of values"),
6737 scanner_errposition
(@
1)));
6738 forboth
(col_cell
, $2, val_cell
, $5)
6740 ResTarget
*res_col
= (ResTarget
*) lfirst
(col_cell
);
6741 Node
*res_val
= (Node
*) lfirst
(val_cell
);
6743 res_col
->val
= res_val
;
6751 ColId opt_indirection
6753 $$
= makeNode
(ResTarget
);
6755 $$
->indirection
= check_indirection
($2);
6756 $$
->val
= NULL
; /* upper production sets this */
6762 set_target
{ $$
= list_make1
($1); }
6763 | set_target_list
',' set_target
{ $$
= lappend
($1,$3); }
6767 /*****************************************************************************
6772 *****************************************************************************/
6773 DeclareCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR SelectStmt
6775 DeclareCursorStmt
*n
= makeNode
(DeclareCursorStmt
);
6777 /* currently we always set FAST_PLAN option */
6778 n
->options
= $3 |
$5 | CURSOR_OPT_FAST_PLAN
;
6784 cursor_options: /*EMPTY*/ { $$
= 0; }
6785 | cursor_options NO SCROLL
{ $$
= $1 | CURSOR_OPT_NO_SCROLL
; }
6786 | cursor_options SCROLL
{ $$
= $1 | CURSOR_OPT_SCROLL
; }
6787 | cursor_options BINARY
{ $$
= $1 | CURSOR_OPT_BINARY
; }
6788 | cursor_options INSENSITIVE
{ $$
= $1 | CURSOR_OPT_INSENSITIVE
; }
6791 opt_hold: /* EMPTY */ { $$
= 0; }
6792 | WITH HOLD
{ $$
= CURSOR_OPT_HOLD
; }
6793 | WITHOUT HOLD
{ $$
= 0; }
6796 /*****************************************************************************
6801 *****************************************************************************/
6803 /* A complete SELECT statement looks like this.
6805 * The rule returns either a single SelectStmt node or a tree of them,
6806 * representing a set-operation tree.
6808 * There is an ambiguity when a sub-SELECT is within an a_expr and there
6809 * are excess parentheses: do the parentheses belong to the sub-SELECT or
6810 * to the surrounding a_expr? We don't really care, but yacc wants to know.
6811 * To resolve the ambiguity, we are careful to define the grammar so that
6812 * the decision is staved off as long as possible: as long as we can keep
6813 * absorbing parentheses into the sub-SELECT, we will do so, and only when
6814 * it's no longer possible to do that will we decide that parens belong to
6815 * the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
6816 * parentheses are treated as part of the sub-select. The necessity of doing
6817 * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
6818 * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
6819 * SELECT viewpoint when we see the UNION.
6821 * This approach is implemented by defining a nonterminal select_with_parens,
6822 * which represents a SELECT with at least one outer layer of parentheses,
6823 * and being careful to use select_with_parens, never '(' SelectStmt ')',
6824 * in the expression grammar. We will then have shift-reduce conflicts
6825 * which we can resolve in favor of always treating '(' <select> ')' as
6826 * a select_with_parens. To resolve the conflicts, the productions that
6827 * conflict with the select_with_parens productions are manually given
6828 * precedences lower than the precedence of ')', thereby ensuring that we
6829 * shift ')' (and then reduce to select_with_parens) rather than trying to
6830 * reduce the inner <select> nonterminal to something else. We use UMINUS
6831 * precedence for this, which is a fairly arbitrary choice.
6833 * To be able to define select_with_parens itself without ambiguity, we need
6834 * a nonterminal select_no_parens that represents a SELECT structure with no
6835 * outermost parentheses. This is a little bit tedious, but it works.
6837 * In non-expression contexts, we use SelectStmt which can represent a SELECT
6838 * with or without outer parentheses.
6841 SelectStmt: select_no_parens %prec UMINUS
6842 | select_with_parens %prec UMINUS
6846 '(' select_no_parens
')' { $$
= $2; }
6847 |
'(' select_with_parens
')' { $$
= $2; }
6851 * This rule parses the equivalent of the standard's <query expression>.
6852 * The duplicative productions are annoying, but hard to get rid of without
6853 * creating shift/reduce conflicts.
6855 * FOR UPDATE/SHARE may be before or after LIMIT/OFFSET.
6856 * In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
6857 * We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE/SHARE
6861 simple_select
{ $$
= $1; }
6862 | select_clause sort_clause
6864 insertSelectOptions
((SelectStmt
*) $1, $2, NIL
,
6868 | select_clause opt_sort_clause for_locking_clause opt_select_limit
6870 insertSelectOptions
((SelectStmt
*) $1, $2, $3,
6871 list_nth
($4, 0), list_nth
($4, 1),
6875 | select_clause opt_sort_clause select_limit opt_for_locking_clause
6877 insertSelectOptions
((SelectStmt
*) $1, $2, $4,
6878 list_nth
($3, 0), list_nth
($3, 1),
6882 | with_clause simple_select
6884 insertSelectOptions
((SelectStmt
*) $2, NULL
, NIL
,
6889 | with_clause select_clause sort_clause
6891 insertSelectOptions
((SelectStmt
*) $2, $3, NIL
,
6896 | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
6898 insertSelectOptions
((SelectStmt
*) $2, $3, $4,
6899 list_nth
($5, 0), list_nth
($5, 1),
6903 | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
6905 insertSelectOptions
((SelectStmt
*) $2, $3, $5,
6906 list_nth
($4, 0), list_nth
($4, 1),
6913 simple_select
{ $$
= $1; }
6914 | select_with_parens
{ $$
= $1; }
6918 * This rule parses SELECT statements that can appear within set operations,
6919 * including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
6920 * the ordering of the set operations. Without '(' and ')' we want the
6921 * operations to be ordered per the precedence specs at the head of this file.
6923 * As with select_no_parens, simple_select cannot have outer parentheses,
6924 * but can have parenthesized subclauses.
6926 * Note that sort clauses cannot be included at this level --- SQL92 requires
6927 * SELECT foo UNION SELECT bar ORDER BY baz
6929 * (SELECT foo UNION SELECT bar) ORDER BY baz
6931 * SELECT foo UNION (SELECT bar ORDER BY baz)
6932 * Likewise for WITH, FOR UPDATE and LIMIT. Therefore, those clauses are
6933 * described as part of the select_no_parens production, not simple_select.
6934 * This does not limit functionality, because you can reintroduce these
6935 * clauses inside parentheses.
6937 * NOTE: only the leftmost component SelectStmt should have INTO.
6938 * However, this is not checked by the grammar; parse analysis must check it.
6941 SELECT opt_distinct target_list
6942 into_clause from_clause where_clause
6943 group_clause having_clause window_clause
6945 SelectStmt
*n
= makeNode
(SelectStmt
);
6946 n
->distinctClause
= $2;
6950 n
->whereClause
= $6;
6951 n
->groupClause
= $7;
6952 n
->havingClause
= $8;
6953 n
->windowClause
= $9;
6956 | values_clause
{ $$
= $1; }
6957 | TABLE relation_expr
6959 /* same as SELECT * FROM relation_expr */
6960 ColumnRef
*cr
= makeNode
(ColumnRef
);
6961 ResTarget
*rt
= makeNode
(ResTarget
);
6962 SelectStmt
*n
= makeNode
(SelectStmt
);
6964 cr
->fields
= list_make1
(makeNode
(A_Star
));
6968 rt
->indirection
= NIL
;
6969 rt
->val
= (Node
*)cr
;
6972 n
->targetList
= list_make1
(rt
);
6973 n
->fromClause
= list_make1
($2);
6976 | select_clause UNION opt_all select_clause
6978 $$
= makeSetOp
(SETOP_UNION
, $3, $1, $4);
6980 | select_clause INTERSECT opt_all select_clause
6982 $$
= makeSetOp
(SETOP_INTERSECT
, $3, $1, $4);
6984 | select_clause EXCEPT opt_all select_clause
6986 $$
= makeSetOp
(SETOP_EXCEPT
, $3, $1, $4);
6991 * SQL standard WITH clause looks like:
6993 * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
6994 * AS (query) [ SEARCH or CYCLE clause ]
6996 * We don't currently support the SEARCH or CYCLE clause.
7001 $$
= makeNode
(WithClause
);
7003 $$
->recursive
= false
;
7006 | WITH RECURSIVE cte_list
7008 $$
= makeNode
(WithClause
);
7010 $$
->recursive
= true
;
7016 common_table_expr
{ $$
= list_make1
($1); }
7017 | cte_list
',' common_table_expr
{ $$
= lappend
($1, $3); }
7020 common_table_expr: name opt_name_list AS select_with_parens
7022 CommonTableExpr
*n
= makeNode
(CommonTableExpr
);
7024 n
->aliascolnames
= $2;
7032 INTO OptTempTableName
7034 $$
= makeNode
(IntoClause
);
7038 $$
->onCommit
= ONCOMMIT_NOOP
;
7039 $$
->tableSpaceName
= NULL
;
7046 * Redundancy here is needed to avoid shift/reduce conflicts,
7047 * since TEMP is not a reserved word. See also OptTemp.
7050 TEMPORARY opt_table qualified_name
7055 | TEMP opt_table qualified_name
7060 | LOCAL TEMPORARY opt_table qualified_name
7065 | LOCAL TEMP opt_table qualified_name
7070 | GLOBAL TEMPORARY opt_table qualified_name
7075 | GLOBAL TEMP opt_table qualified_name
7080 | TABLE qualified_name
7096 opt_all: ALL
{ $$
= TRUE
; }
7097 | DISTINCT
{ $$
= FALSE
; }
7098 |
/*EMPTY*/ { $$
= FALSE
; }
7101 /* We use (NIL) as a placeholder to indicate that all target expressions
7102 * should be placed in the DISTINCT list during parsetree analysis.
7105 DISTINCT
{ $$
= list_make1
(NIL
); }
7106 | DISTINCT ON
'(' expr_list
')' { $$
= $4; }
7108 |
/*EMPTY*/ { $$
= NIL
; }
7112 sort_clause
{ $$
= $1;}
7113 |
/*EMPTY*/ { $$
= NIL
; }
7117 ORDER BY sortby_list
{ $$
= $3; }
7121 sortby
{ $$
= list_make1
($1); }
7122 | sortby_list
',' sortby
{ $$
= lappend
($1, $3); }
7125 sortby: a_expr USING qual_all_Op opt_nulls_order
7127 $$
= makeNode
(SortBy
);
7129 $$
->sortby_dir
= SORTBY_USING
;
7130 $$
->sortby_nulls
= $4;
7134 | a_expr opt_asc_desc opt_nulls_order
7136 $$
= makeNode
(SortBy
);
7138 $$
->sortby_dir
= $2;
7139 $$
->sortby_nulls
= $3;
7141 $$
->location
= -1; /* no operator */
7147 LIMIT select_limit_value OFFSET select_offset_value
7148 { $$
= list_make2
($4, $2); }
7149 | OFFSET select_offset_value LIMIT select_limit_value
7150 { $$
= list_make2
($2, $4); }
7151 | LIMIT select_limit_value
7152 { $$
= list_make2
(NULL
, $2); }
7153 | OFFSET select_offset_value
7154 { $$
= list_make2
($2, NULL
); }
7155 | LIMIT select_limit_value
',' select_offset_value
7157 /* Disabled because it was too confusing, bjm 2002-02-18 */
7159 (errcode
(ERRCODE_SYNTAX_ERROR
),
7160 errmsg
("LIMIT #,# syntax is not supported"),
7161 errhint
("Use separate LIMIT and OFFSET clauses."),
7162 scanner_errposition
(@
1)));
7164 /* SQL:2008 syntax variants */
7165 | OFFSET select_offset_value2 row_or_rows
7166 { $$
= list_make2
($2, NULL
); }
7167 | FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
7168 { $$
= list_make2
(NULL
, $3); }
7169 | OFFSET select_offset_value2 row_or_rows FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
7170 { $$
= list_make2
($2, $6); }
7174 select_limit
{ $$
= $1; }
7176 { $$
= list_make2
(NULL
,NULL
); }
7183 /* LIMIT ALL is represented as a NULL constant */
7184 $$
= makeNullAConst
(@
1);
7189 * Allowing full expressions without parentheses causes various parsing
7190 * problems with the trailing ROW/ROWS key words. SQL only calls for
7191 * constants, so we allow the rest only with parentheses.
7193 opt_select_fetch_first_value:
7194 SignedIconst
{ $$
= makeIntConst
($1, @
1); }
7195 |
'(' a_expr
')' { $$
= $2; }
7196 |
/*EMPTY*/ { $$
= makeIntConst
(1, -1); }
7199 select_offset_value:
7204 * Again, the trailing ROW/ROWS in this case prevent the full expression
7205 * syntax. c_expr is the best we can do.
7207 select_offset_value2:
7224 GROUP_P BY expr_list
{ $$
= $3; }
7225 |
/*EMPTY*/ { $$
= NIL
; }
7229 HAVING a_expr
{ $$
= $2; }
7230 |
/*EMPTY*/ { $$
= NULL
; }
7234 for_locking_items
{ $$
= $1; }
7235 | FOR READ ONLY
{ $$
= NIL
; }
7238 opt_for_locking_clause:
7239 for_locking_clause
{ $$
= $1; }
7240 |
/* EMPTY */ { $$
= NIL
; }
7244 for_locking_item
{ $$
= list_make1
($1); }
7245 | for_locking_items for_locking_item
{ $$
= lappend
($1, $2); }
7249 FOR UPDATE locked_rels_list opt_nowait
7251 LockingClause
*n
= makeNode
(LockingClause
);
7253 n
->forUpdate
= TRUE
;
7257 | FOR SHARE locked_rels_list opt_nowait
7259 LockingClause
*n
= makeNode
(LockingClause
);
7261 n
->forUpdate
= FALSE
;
7268 OF qualified_name_list
{ $$
= $2; }
7269 |
/* EMPTY */ { $$
= NIL
; }
7276 SelectStmt
*n
= makeNode
(SelectStmt
);
7277 n
->valuesLists
= list_make1
($2);
7280 | values_clause
',' ctext_row
7282 SelectStmt
*n
= (SelectStmt
*) $1;
7283 n
->valuesLists
= lappend
(n
->valuesLists
, $3);
7289 /*****************************************************************************
7291 * clauses common to all Optimizable Stmts:
7292 * from_clause - allow list of both JOIN expressions and table names
7293 * where_clause - qualifications for joins or restrictions
7295 *****************************************************************************/
7298 FROM from_list
{ $$
= $2; }
7299 |
/*EMPTY*/ { $$
= NIL
; }
7303 table_ref
{ $$
= list_make1
($1); }
7304 | from_list
',' table_ref
{ $$
= lappend
($1, $3); }
7308 * table_ref is where an alias clause can be attached. Note we cannot make
7309 * alias_clause have an empty production because that causes parse conflicts
7310 * between table_ref := '(' joined_table ')' alias_clause
7311 * and joined_table := '(' joined_table ')'. So, we must have the
7312 * redundant-looking productions here instead.
7314 table_ref: relation_expr
7318 | relation_expr alias_clause
7325 RangeFunction
*n
= makeNode
(RangeFunction
);
7326 n
->funccallnode
= $1;
7327 n
->coldeflist
= NIL
;
7330 | func_table alias_clause
7332 RangeFunction
*n
= makeNode
(RangeFunction
);
7333 n
->funccallnode
= $1;
7335 n
->coldeflist
= NIL
;
7338 | func_table AS
'(' TableFuncElementList
')'
7340 RangeFunction
*n
= makeNode
(RangeFunction
);
7341 n
->funccallnode
= $1;
7345 | func_table AS ColId
'(' TableFuncElementList
')'
7347 RangeFunction
*n
= makeNode
(RangeFunction
);
7348 Alias
*a
= makeNode
(Alias
);
7349 n
->funccallnode
= $1;
7355 | func_table ColId
'(' TableFuncElementList
')'
7357 RangeFunction
*n
= makeNode
(RangeFunction
);
7358 Alias
*a
= makeNode
(Alias
);
7359 n
->funccallnode
= $1;
7365 | select_with_parens
7368 * The SQL spec does not permit a subselect
7369 * (<derived_table>) without an alias clause,
7370 * so we don't either. This avoids the problem
7371 * of needing to invent a unique refname for it.
7372 * That could be surmounted if there's sufficient
7373 * popular demand, but for now let's just implement
7374 * the spec and see if anyone complains.
7375 * However, it does seem like a good idea to emit
7376 * an error message that's better than "syntax error".
7378 if
(IsA
($1, SelectStmt
) &&
7379 ((SelectStmt
*) $1)->valuesLists
)
7381 (errcode
(ERRCODE_SYNTAX_ERROR
),
7382 errmsg
("VALUES in FROM must have an alias"),
7383 errhint
("For example, FROM (VALUES ...) [AS] foo."),
7384 scanner_errposition
(@
1)));
7387 (errcode
(ERRCODE_SYNTAX_ERROR
),
7388 errmsg
("subquery in FROM must have an alias"),
7389 errhint
("For example, FROM (SELECT ...) [AS] foo."),
7390 scanner_errposition
(@
1)));
7393 | select_with_parens alias_clause
7395 RangeSubselect
*n
= makeNode
(RangeSubselect
);
7404 |
'(' joined_table
')' alias_clause
7413 * It may seem silly to separate joined_table from table_ref, but there is
7414 * method in SQL92's madness: if you don't do it this way you get reduce-
7415 * reduce conflicts, because it's not clear to the parser generator whether
7416 * to expect alias_clause after ')' or not. For the same reason we must
7417 * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
7418 * join_type to expand to empty; if we try it, the parser generator can't
7419 * figure out when to reduce an empty join_type right after table_ref.
7421 * Note that a CROSS JOIN is the same as an unqualified
7422 * INNER JOIN, and an INNER JOIN/ON has the same shape
7423 * but a qualification expression to limit membership.
7424 * A NATURAL JOIN implicitly matches column names between
7425 * tables and the shape is determined by which columns are
7426 * in common. We'll collect columns during the later transformations.
7430 '(' joined_table
')'
7434 | table_ref CROSS JOIN table_ref
7436 /* CROSS JOIN is same as unqualified inner join */
7437 JoinExpr
*n
= makeNode
(JoinExpr
);
7438 n
->jointype
= JOIN_INNER
;
7439 n
->isNatural
= FALSE
;
7446 | table_ref join_type JOIN table_ref join_qual
7448 JoinExpr
*n
= makeNode
(JoinExpr
);
7450 n
->isNatural
= FALSE
;
7453 if
($5 != NULL
&& IsA
($5, List
))
7454 n
->using
= (List
*) $5; /* USING clause */
7456 n
->quals
= $5; /* ON clause */
7459 | table_ref JOIN table_ref join_qual
7461 /* letting join_type reduce to empty doesn't work */
7462 JoinExpr
*n
= makeNode
(JoinExpr
);
7463 n
->jointype
= JOIN_INNER
;
7464 n
->isNatural
= FALSE
;
7467 if
($4 != NULL
&& IsA
($4, List
))
7468 n
->using
= (List
*) $4; /* USING clause */
7470 n
->quals
= $4; /* ON clause */
7473 | table_ref NATURAL join_type JOIN table_ref
7475 JoinExpr
*n
= makeNode
(JoinExpr
);
7477 n
->isNatural
= TRUE
;
7480 n
->using
= NIL
; /* figure out which columns later... */
7481 n
->quals
= NULL
; /* fill later */
7484 | table_ref NATURAL JOIN table_ref
7486 /* letting join_type reduce to empty doesn't work */
7487 JoinExpr
*n
= makeNode
(JoinExpr
);
7488 n
->jointype
= JOIN_INNER
;
7489 n
->isNatural
= TRUE
;
7492 n
->using
= NIL
; /* figure out which columns later... */
7493 n
->quals
= NULL
; /* fill later */
7499 AS ColId
'(' name_list
')'
7501 $$
= makeNode
(Alias
);
7507 $$
= makeNode
(Alias
);
7510 | ColId
'(' name_list
')'
7512 $$
= makeNode
(Alias
);
7518 $$
= makeNode
(Alias
);
7523 join_type: FULL join_outer
{ $$
= JOIN_FULL
; }
7524 | LEFT join_outer
{ $$
= JOIN_LEFT
; }
7525 | RIGHT join_outer
{ $$
= JOIN_RIGHT
; }
7526 | INNER_P
{ $$
= JOIN_INNER
; }
7529 /* OUTER is just noise... */
7530 join_outer: OUTER_P
{ $$
= NULL
; }
7531 |
/*EMPTY*/ { $$
= NULL
; }
7534 /* JOIN qualification clauses
7535 * Possibilities are:
7536 * USING ( column list ) allows only unqualified column names,
7537 * which must match between tables.
7538 * ON expr allows more general qualifications.
7540 * We return USING as a List node, while an ON-expr will not be a List.
7543 join_qual: USING
'(' name_list
')' { $$
= (Node
*) $3; }
7544 | ON a_expr
{ $$
= $2; }
7551 /* default inheritance */
7553 $$
->inhOpt
= INH_DEFAULT
;
7556 | qualified_name
'*'
7558 /* inheritance query */
7560 $$
->inhOpt
= INH_YES
;
7563 | ONLY qualified_name
7565 /* no inheritance */
7567 $$
->inhOpt
= INH_NO
;
7570 | ONLY
'(' qualified_name
')'
7572 /* no inheritance, SQL99-style syntax */
7574 $$
->inhOpt
= INH_NO
;
7581 relation_expr
{ $$
= list_make1
($1); }
7582 | relation_expr_list
',' relation_expr
{ $$
= lappend
($1, $3); }
7587 * Given "UPDATE foo set set ...", we have to decide without looking any
7588 * further ahead whether the first "set" is an alias or the UPDATE's SET
7589 * keyword. Since "set" is allowed as a column name both interpretations
7590 * are feasible. We resolve the shift/reduce conflict by giving the first
7591 * relation_expr_opt_alias production a higher precedence than the SET token
7592 * has, causing the parser to prefer to reduce, in effect assuming that the
7593 * SET is not an alias.
7595 relation_expr_opt_alias: relation_expr %prec UMINUS
7599 | relation_expr ColId
7601 Alias
*alias
= makeNode
(Alias
);
7602 alias
->aliasname
= $2;
7606 | relation_expr AS ColId
7608 Alias
*alias
= makeNode
(Alias
);
7609 alias
->aliasname
= $3;
7616 func_table: func_expr
{ $$
= $1; }
7621 WHERE a_expr
{ $$
= $2; }
7622 |
/*EMPTY*/ { $$
= NULL
; }
7625 /* variant for UPDATE and DELETE */
7626 where_or_current_clause:
7627 WHERE a_expr
{ $$
= $2; }
7628 | WHERE CURRENT_P OF name
7630 CurrentOfExpr
*n
= makeNode
(CurrentOfExpr
);
7631 /* cvarno is filled in by parse analysis */
7632 n
->cursor_name
= $4;
7633 n
->cursor_param
= 0;
7636 | WHERE CURRENT_P OF PARAM
7638 CurrentOfExpr
*n
= makeNode
(CurrentOfExpr
);
7639 /* cvarno is filled in by parse analysis */
7640 n
->cursor_name
= NULL
;
7641 n
->cursor_param
= $4;
7644 |
/*EMPTY*/ { $$
= NULL
; }
7648 TableFuncElementList:
7651 $$
= list_make1
($1);
7653 | TableFuncElementList
',' TableFuncElement
7655 $$
= lappend
($1, $3);
7659 TableFuncElement: ColId Typename
7661 ColumnDef
*n
= makeNode
(ColumnDef
);
7664 n
->constraints
= NIL
;
7670 /*****************************************************************************
7673 * SQL92 introduces a large amount of type-specific syntax.
7674 * Define individual clauses to handle these cases, and use
7675 * the generic case to handle regular type-extensible Postgres syntax.
7676 * - thomas 1997-10-10
7678 *****************************************************************************/
7680 Typename: SimpleTypename opt_array_bounds
7683 $$
->arrayBounds
= $2;
7685 | SETOF SimpleTypename opt_array_bounds
7688 $$
->arrayBounds
= $3;
7691 /* SQL standard syntax, currently only one-dimensional */
7692 | SimpleTypename ARRAY
'[' Iconst
']'
7695 $$
->arrayBounds
= list_make1
(makeInteger
($4));
7697 | SETOF SimpleTypename ARRAY
'[' Iconst
']'
7700 $$
->arrayBounds
= list_make1
(makeInteger
($5));
7703 | SimpleTypename ARRAY
7706 $$
->arrayBounds
= list_make1
(makeInteger
(-1));
7708 | SETOF SimpleTypename ARRAY
7711 $$
->arrayBounds
= list_make1
(makeInteger
(-1));
7717 opt_array_bounds
'[' ']'
7718 { $$
= lappend
($1, makeInteger
(-1)); }
7719 | opt_array_bounds
'[' Iconst
']'
7720 { $$
= lappend
($1, makeInteger
($3)); }
7726 GenericType
{ $$
= $1; }
7727 | Numeric
{ $$
= $1; }
7729 | Character
{ $$
= $1; }
7730 | ConstDatetime
{ $$
= $1; }
7731 | ConstInterval opt_interval
7736 | ConstInterval
'(' Iconst
')' opt_interval
7741 if
(list_length
($5) != 1)
7743 (errcode
(ERRCODE_SYNTAX_ERROR
),
7744 errmsg
("interval precision specified twice"),
7745 scanner_errposition
(@
1)));
7746 $$
->typmods
= lappend
($5, makeIntConst
($3, @
3));
7749 $$
->typmods
= list_make2
(makeIntConst
(INTERVAL_FULL_RANGE
, -1),
7750 makeIntConst
($3, @
3));
7754 /* We have a separate ConstTypename to allow defaulting fixed-length
7755 * types such as CHAR() and BIT() to an unspecified length.
7756 * SQL9x requires that these default to a length of one, but this
7757 * makes no sense for constructs like CHAR 'hi' and BIT '0101',
7758 * where there is an obvious better choice to make.
7759 * Note that ConstInterval is not included here since it must
7760 * be pushed up higher in the rules to accomodate the postfix
7761 * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
7762 * the generic-type-name case in AExprConst to avoid premature
7763 * reduce/reduce conflicts against function names.
7766 Numeric
{ $$
= $1; }
7767 | ConstBit
{ $$
= $1; }
7768 | ConstCharacter
{ $$
= $1; }
7769 | ConstDatetime
{ $$
= $1; }
7773 * GenericType covers all type names that don't have special syntax mandated
7774 * by the standard, including qualified names. We also allow type modifiers.
7775 * To avoid parsing conflicts against function invocations, the modifiers
7776 * have to be shown as expr_list here, but parse analysis will only accept
7777 * constants for them.
7780 type_function_name opt_type_modifiers
7782 $$
= makeTypeName
($1);
7786 | type_function_name attrs opt_type_modifiers
7788 $$
= makeTypeNameFromNameList
(lcons
(makeString
($1), $2));
7794 opt_type_modifiers: '(' expr_list
')' { $$
= $2; }
7795 |
/* EMPTY */ { $$
= NIL
; }
7799 * SQL92 numeric data types
7803 $$
= SystemTypeName
("int4");
7808 $$
= SystemTypeName
("int4");
7813 $$
= SystemTypeName
("int2");
7818 $$
= SystemTypeName
("int8");
7823 $$
= SystemTypeName
("float4");
7831 | DOUBLE_P PRECISION
7833 $$
= SystemTypeName
("float8");
7836 | DECIMAL_P opt_type_modifiers
7838 $$
= SystemTypeName
("numeric");
7842 | DEC opt_type_modifiers
7844 $$
= SystemTypeName
("numeric");
7848 | NUMERIC opt_type_modifiers
7850 $$
= SystemTypeName
("numeric");
7856 $$
= SystemTypeName
("bool");
7861 opt_float: '(' Iconst
')'
7864 * Check FLOAT() precision limits assuming IEEE floating
7865 * types - thomas 1997-09-18
7869 (errcode
(ERRCODE_INVALID_PARAMETER_VALUE
),
7870 errmsg
("precision for type float must be at least 1 bit"),
7871 scanner_errposition
(@
2)));
7873 $$
= SystemTypeName
("float4");
7875 $$
= SystemTypeName
("float8");
7878 (errcode
(ERRCODE_INVALID_PARAMETER_VALUE
),
7879 errmsg
("precision for type float must be less than 54 bits"),
7880 scanner_errposition
(@
2)));
7884 $$
= SystemTypeName
("float8");
7889 * SQL92 bit-field data types
7890 * The following implements BIT() and BIT VARYING().
7902 /* ConstBit is like Bit except "BIT" defaults to unspecified length */
7903 /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
7904 ConstBit: BitWithLength
7916 BIT opt_varying
'(' expr_list
')'
7920 typname
= $2 ?
"varbit" : "bit";
7921 $$
= SystemTypeName
(typname
);
7930 /* bit defaults to bit(1), varbit to no limit */
7933 $$
= SystemTypeName
("varbit");
7937 $$
= SystemTypeName
("bit");
7938 $$
->typmods
= list_make1
(makeIntConst
(1, -1));
7946 * SQL92 character data types
7947 * The following implements CHAR() and VARCHAR().
7949 Character: CharacterWithLength
7953 | CharacterWithoutLength
7959 ConstCharacter: CharacterWithLength
7963 | CharacterWithoutLength
7965 /* Length was not specified so allow to be unrestricted.
7966 * This handles problems with fixed-length (bpchar) strings
7967 * which in column definitions must default to a length
7968 * of one, but should not be constrained if the length
7969 * was not specified.
7976 CharacterWithLength: character
'(' Iconst
')' opt_charset
7978 if
(($5 != NULL
) && (strcmp
($5, "sql_text") != 0))
7982 type
= palloc
(strlen
($1) + 1 + strlen
($5) + 1);
7989 $$
= SystemTypeName
($1);
7990 $$
->typmods
= list_make1
(makeIntConst
($3, @
3));
7995 CharacterWithoutLength: character opt_charset
7997 if
(($2 != NULL
) && (strcmp
($2, "sql_text") != 0))
8001 type
= palloc
(strlen
($1) + 1 + strlen
($2) + 1);
8008 $$
= SystemTypeName
($1);
8010 /* char defaults to char(1), varchar to no limit */
8011 if
(strcmp
($1, "bpchar") == 0)
8012 $$
->typmods
= list_make1
(makeIntConst
(1, -1));
8018 character: CHARACTER opt_varying
8019 { $$
= $2 ?
"varchar": "bpchar"; }
8020 | CHAR_P opt_varying
8021 { $$
= $2 ?
"varchar": "bpchar"; }
8024 | NATIONAL CHARACTER opt_varying
8025 { $$
= $3 ?
"varchar": "bpchar"; }
8026 | NATIONAL CHAR_P opt_varying
8027 { $$
= $3 ?
"varchar": "bpchar"; }
8029 { $$
= $2 ?
"varchar": "bpchar"; }
8033 VARYING
{ $$
= TRUE
; }
8034 |
/*EMPTY*/ { $$
= FALSE
; }
8038 CHARACTER SET ColId
{ $$
= $3; }
8039 |
/*EMPTY*/ { $$
= NULL
; }
8043 * SQL92 date/time types
8046 TIMESTAMP
'(' Iconst
')' opt_timezone
8049 $$
= SystemTypeName
("timestamptz");
8051 $$
= SystemTypeName
("timestamp");
8052 $$
->typmods
= list_make1
(makeIntConst
($3, @
3));
8055 | TIMESTAMP opt_timezone
8058 $$
= SystemTypeName
("timestamptz");
8060 $$
= SystemTypeName
("timestamp");
8063 | TIME
'(' Iconst
')' opt_timezone
8066 $$
= SystemTypeName
("timetz");
8068 $$
= SystemTypeName
("time");
8069 $$
->typmods
= list_make1
(makeIntConst
($3, @
3));
8075 $$
= SystemTypeName
("timetz");
8077 $$
= SystemTypeName
("time");
8085 $$
= SystemTypeName
("interval");
8091 WITH_TIME ZONE
{ $$
= TRUE
; }
8092 | WITHOUT TIME ZONE
{ $$
= FALSE
; }
8093 |
/*EMPTY*/ { $$
= FALSE
; }
8098 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(YEAR
), @
1)); }
8100 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(MONTH
), @
1)); }
8102 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(DAY
), @
1)); }
8104 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(HOUR
), @
1)); }
8106 { $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(MINUTE
), @
1)); }
8111 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(YEAR
) |
8112 INTERVAL_MASK
(MONTH
), @
1));
8116 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(DAY
) |
8117 INTERVAL_MASK
(HOUR
), @
1));
8121 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(DAY
) |
8122 INTERVAL_MASK
(HOUR
) |
8123 INTERVAL_MASK
(MINUTE
), @
1));
8125 | DAY_P TO interval_second
8128 linitial
($$
) = makeIntConst
(INTERVAL_MASK
(DAY
) |
8129 INTERVAL_MASK
(HOUR
) |
8130 INTERVAL_MASK
(MINUTE
) |
8131 INTERVAL_MASK
(SECOND
), @
1);
8133 | HOUR_P TO MINUTE_P
8135 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(HOUR
) |
8136 INTERVAL_MASK
(MINUTE
), @
1));
8138 | HOUR_P TO interval_second
8141 linitial
($$
) = makeIntConst
(INTERVAL_MASK
(HOUR
) |
8142 INTERVAL_MASK
(MINUTE
) |
8143 INTERVAL_MASK
(SECOND
), @
1);
8145 | MINUTE_P TO interval_second
8148 linitial
($$
) = makeIntConst
(INTERVAL_MASK
(MINUTE
) |
8149 INTERVAL_MASK
(SECOND
), @
1);
8158 $$
= list_make1
(makeIntConst
(INTERVAL_MASK
(SECOND
), @
1));
8160 | SECOND_P
'(' Iconst
')'
8162 $$
= list_make2
(makeIntConst
(INTERVAL_MASK
(SECOND
), @
1),
8163 makeIntConst
($3, @
3));
8168 /*****************************************************************************
8170 * expression grammar
8172 *****************************************************************************/
8175 * General expressions
8176 * This is the heart of the expression syntax.
8178 * We have two expression types: a_expr is the unrestricted kind, and
8179 * b_expr is a subset that must be used in some places to avoid shift/reduce
8180 * conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
8181 * because that use of AND conflicts with AND as a boolean operator. So,
8182 * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
8184 * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
8185 * always be used by surrounding it with parens.
8187 * c_expr is all the productions that are common to a_expr and b_expr;
8188 * it's factored out just to eliminate redundant coding.
8190 a_expr: c_expr
{ $$
= $1; }
8191 | a_expr TYPECAST Typename
8192 { $$
= makeTypeCast
($1, $3, @
2); }
8193 | a_expr AT TIME ZONE a_expr
8195 FuncCall
*n
= makeNode
(FuncCall
);
8196 n
->funcname
= SystemFuncName
("timezone");
8197 n
->args
= list_make2
($5, $1);
8198 n
->agg_star
= FALSE
;
8199 n
->agg_distinct
= FALSE
;
8200 n
->func_variadic
= FALSE
;
8206 * These operators must be called out explicitly in order to make use
8207 * of yacc/bison's automatic operator-precedence handling. All other
8208 * operator names are handled by the generic productions using "Op",
8209 * below; and all those operators will have the same precedence.
8211 * If you add more explicitly-known operators, be sure to add them
8212 * also to b_expr and to the MathOp list above.
8214 |
'+' a_expr %prec UMINUS
8215 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", NULL
, $2, @
1); }
8216 |
'-' a_expr %prec UMINUS
8217 { $$
= doNegate
($2, @
1); }
8219 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", $1, $3, @
2); }
8221 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "-", $1, $3, @
2); }
8223 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "*", $1, $3, @
2); }
8225 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "/", $1, $3, @
2); }
8227 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "%", $1, $3, @
2); }
8229 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "^", $1, $3, @
2); }
8231 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $3, @
2); }
8233 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $3, @
2); }
8235 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "=", $1, $3, @
2); }
8237 | a_expr qual_Op a_expr %prec Op
8238 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, $3, @
2); }
8239 | qual_Op a_expr %prec Op
8240 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $1, NULL
, $2, @
1); }
8241 | a_expr qual_Op %prec POSTFIXOP
8242 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, NULL
, @
2); }
8245 { $$
= (Node
*) makeA_Expr
(AEXPR_AND
, NIL
, $1, $3, @
2); }
8247 { $$
= (Node
*) makeA_Expr
(AEXPR_OR
, NIL
, $1, $3, @
2); }
8249 { $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
, $2, @
1); }
8251 | a_expr LIKE a_expr
8252 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~~", $1, $3, @
2); }
8253 | a_expr LIKE a_expr ESCAPE a_expr
8255 FuncCall
*n
= makeNode
(FuncCall
);
8256 n
->funcname
= SystemFuncName
("like_escape");
8257 n
->args
= list_make2
($3, $5);
8258 n
->agg_star
= FALSE
;
8259 n
->agg_distinct
= FALSE
;
8260 n
->func_variadic
= FALSE
;
8263 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~~", $1, (Node
*) n
, @
2);
8265 | a_expr NOT LIKE a_expr
8266 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~~", $1, $4, @
2); }
8267 | a_expr NOT LIKE a_expr ESCAPE a_expr
8269 FuncCall
*n
= makeNode
(FuncCall
);
8270 n
->funcname
= SystemFuncName
("like_escape");
8271 n
->args
= list_make2
($4, $6);
8272 n
->agg_star
= FALSE
;
8273 n
->agg_distinct
= FALSE
;
8274 n
->func_variadic
= FALSE
;
8277 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~~", $1, (Node
*) n
, @
2);
8279 | a_expr ILIKE a_expr
8280 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~~*", $1, $3, @
2); }
8281 | a_expr ILIKE a_expr ESCAPE a_expr
8283 FuncCall
*n
= makeNode
(FuncCall
);
8284 n
->funcname
= SystemFuncName
("like_escape");
8285 n
->args
= list_make2
($3, $5);
8286 n
->agg_star
= FALSE
;
8287 n
->agg_distinct
= FALSE
;
8288 n
->func_variadic
= FALSE
;
8291 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~~*", $1, (Node
*) n
, @
2);
8293 | a_expr NOT ILIKE a_expr
8294 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~~*", $1, $4, @
2); }
8295 | a_expr NOT ILIKE a_expr ESCAPE a_expr
8297 FuncCall
*n
= makeNode
(FuncCall
);
8298 n
->funcname
= SystemFuncName
("like_escape");
8299 n
->args
= list_make2
($4, $6);
8300 n
->agg_star
= FALSE
;
8301 n
->agg_distinct
= FALSE
;
8302 n
->func_variadic
= FALSE
;
8305 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~~*", $1, (Node
*) n
, @
2);
8308 | a_expr SIMILAR TO a_expr %prec SIMILAR
8310 FuncCall
*n
= makeNode
(FuncCall
);
8311 n
->funcname
= SystemFuncName
("similar_escape");
8312 n
->args
= list_make2
($4, makeNullAConst
(-1));
8313 n
->agg_star
= FALSE
;
8314 n
->agg_distinct
= FALSE
;
8315 n
->func_variadic
= FALSE
;
8318 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~", $1, (Node
*) n
, @
2);
8320 | a_expr SIMILAR TO a_expr ESCAPE a_expr
8322 FuncCall
*n
= makeNode
(FuncCall
);
8323 n
->funcname
= SystemFuncName
("similar_escape");
8324 n
->args
= list_make2
($4, $6);
8325 n
->agg_star
= FALSE
;
8326 n
->agg_distinct
= FALSE
;
8327 n
->func_variadic
= FALSE
;
8330 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "~", $1, (Node
*) n
, @
2);
8332 | a_expr NOT SIMILAR TO a_expr %prec SIMILAR
8334 FuncCall
*n
= makeNode
(FuncCall
);
8335 n
->funcname
= SystemFuncName
("similar_escape");
8336 n
->args
= list_make2
($5, makeNullAConst
(-1));
8337 n
->agg_star
= FALSE
;
8338 n
->agg_distinct
= FALSE
;
8339 n
->func_variadic
= FALSE
;
8342 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~", $1, (Node
*) n
, @
2);
8344 | a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
8346 FuncCall
*n
= makeNode
(FuncCall
);
8347 n
->funcname
= SystemFuncName
("similar_escape");
8348 n
->args
= list_make2
($5, $7);
8349 n
->agg_star
= FALSE
;
8350 n
->agg_distinct
= FALSE
;
8351 n
->func_variadic
= FALSE
;
8354 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "!~", $1, (Node
*) n
, @
2);
8358 * Define SQL92-style Null test clause.
8359 * Allow two forms described in the standard:
8362 * Allow two SQL extensions
8368 NullTest
*n
= makeNode
(NullTest
);
8369 n
->arg
= (Expr
*) $1;
8370 n
->nulltesttype
= IS_NULL
;
8375 NullTest
*n
= makeNode
(NullTest
);
8376 n
->arg
= (Expr
*) $1;
8377 n
->nulltesttype
= IS_NULL
;
8380 | a_expr IS NOT NULL_P
8382 NullTest
*n
= makeNode
(NullTest
);
8383 n
->arg
= (Expr
*) $1;
8384 n
->nulltesttype
= IS_NOT_NULL
;
8389 NullTest
*n
= makeNode
(NullTest
);
8390 n
->arg
= (Expr
*) $1;
8391 n
->nulltesttype
= IS_NOT_NULL
;
8396 $$
= (Node
*)makeOverlaps
($1, $3, @
2);
8400 BooleanTest
*b
= makeNode
(BooleanTest
);
8401 b
->arg
= (Expr
*) $1;
8402 b
->booltesttype
= IS_TRUE
;
8405 | a_expr IS NOT TRUE_P
8407 BooleanTest
*b
= makeNode
(BooleanTest
);
8408 b
->arg
= (Expr
*) $1;
8409 b
->booltesttype
= IS_NOT_TRUE
;
8414 BooleanTest
*b
= makeNode
(BooleanTest
);
8415 b
->arg
= (Expr
*) $1;
8416 b
->booltesttype
= IS_FALSE
;
8419 | a_expr IS NOT FALSE_P
8421 BooleanTest
*b
= makeNode
(BooleanTest
);
8422 b
->arg
= (Expr
*) $1;
8423 b
->booltesttype
= IS_NOT_FALSE
;
8428 BooleanTest
*b
= makeNode
(BooleanTest
);
8429 b
->arg
= (Expr
*) $1;
8430 b
->booltesttype
= IS_UNKNOWN
;
8433 | a_expr IS NOT UNKNOWN
8435 BooleanTest
*b
= makeNode
(BooleanTest
);
8436 b
->arg
= (Expr
*) $1;
8437 b
->booltesttype
= IS_NOT_UNKNOWN
;
8440 | a_expr IS DISTINCT FROM a_expr %prec IS
8442 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
, "=", $1, $5, @
2);
8444 | a_expr IS NOT DISTINCT FROM a_expr %prec IS
8446 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
,
8447 (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
,
8452 | a_expr IS OF
'(' type_list
')' %prec IS
8454 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OF
, "=", $1, (Node
*) $5, @
2);
8456 | a_expr IS NOT OF
'(' type_list
')' %prec IS
8458 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OF
, "<>", $1, (Node
*) $6, @
2);
8461 * Ideally we would not use hard-wired operators below but instead use
8462 * opclasses. However, mixed data types and other issues make this
8463 * difficult: http://archives.postgresql.org/pgsql-hackers/2008-08/msg01142.php
8465 | a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
8467 $$
= (Node
*) makeA_Expr
(AEXPR_AND
, NIL
,
8468 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">=", $1, $4, @
2),
8469 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<=", $1, $6, @
2),
8472 | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
8474 $$
= (Node
*) makeA_Expr
(AEXPR_OR
, NIL
,
8475 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $5, @
2),
8476 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $7, @
2),
8479 | a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
8481 $$
= (Node
*) makeA_Expr
(AEXPR_OR
, NIL
,
8482 (Node
*) makeA_Expr
(AEXPR_AND
, NIL
,
8483 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">=", $1, $4, @
2),
8484 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<=", $1, $6, @
2),
8486 (Node
*) makeA_Expr
(AEXPR_AND
, NIL
,
8487 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">=", $1, $6, @
2),
8488 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<=", $1, $4, @
2),
8492 | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
8494 $$
= (Node
*) makeA_Expr
(AEXPR_AND
, NIL
,
8495 (Node
*) makeA_Expr
(AEXPR_OR
, NIL
,
8496 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $5, @
2),
8497 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $7, @
2),
8499 (Node
*) makeA_Expr
(AEXPR_OR
, NIL
,
8500 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $7, @
2),
8501 (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $5, @
2),
8505 | a_expr IN_P in_expr
8507 /* in_expr returns a SubLink or a list of a_exprs */
8508 if
(IsA
($3, SubLink
))
8510 /* generate foo = ANY (subquery) */
8511 SubLink
*n
= (SubLink
*) $3;
8512 n
->subLinkType
= ANY_SUBLINK
;
8514 n
->operName
= list_make1
(makeString
("="));
8520 /* generate scalar IN expression */
8521 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_IN
, "=", $1, $3, @
2);
8524 | a_expr NOT IN_P in_expr
8526 /* in_expr returns a SubLink or a list of a_exprs */
8527 if
(IsA
($4, SubLink
))
8529 /* generate NOT (foo = ANY (subquery)) */
8530 /* Make an = ANY node */
8531 SubLink
*n
= (SubLink
*) $4;
8532 n
->subLinkType
= ANY_SUBLINK
;
8534 n
->operName
= list_make1
(makeString
("="));
8536 /* Stick a NOT on top */
8537 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
, (Node
*) n
, @
2);
8541 /* generate scalar NOT IN expression */
8542 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_IN
, "<>", $1, $4, @
2);
8545 | a_expr subquery_Op sub_type select_with_parens %prec Op
8547 SubLink
*n
= makeNode
(SubLink
);
8548 n
->subLinkType
= $3;
8555 | a_expr subquery_Op sub_type
'(' a_expr
')' %prec Op
8557 if
($3 == ANY_SUBLINK
)
8558 $$
= (Node
*) makeA_Expr
(AEXPR_OP_ANY
, $2, $1, $5, @
2);
8560 $$
= (Node
*) makeA_Expr
(AEXPR_OP_ALL
, $2, $1, $5, @
2);
8562 | UNIQUE select_with_parens
8564 /* Not sure how to get rid of the parentheses
8565 * but there are lots of shift/reduce errors without them.
8567 * Should be able to implement this by plopping the entire
8568 * select into a node, then transforming the target expressions
8569 * from whatever they are into count(*), and testing the
8570 * entire result equal to one.
8571 * But, will probably implement a separate node in the executor.
8574 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
8575 errmsg
("UNIQUE predicate is not yet implemented"),
8576 scanner_errposition
(@
1)));
8578 | a_expr IS DOCUMENT_P %prec IS
8580 $$
= makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
8581 list_make1
($1), @
2);
8583 | a_expr IS NOT DOCUMENT_P %prec IS
8585 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
,
8586 makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
8587 list_make1
($1), @
2),
8593 * Restricted expressions
8595 * b_expr is a subset of the complete expression syntax defined by a_expr.
8597 * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
8598 * cause trouble in the places where b_expr is used. For simplicity, we
8599 * just eliminate all the boolean-keyword-operator productions from b_expr.
8603 | b_expr TYPECAST Typename
8604 { $$
= makeTypeCast
($1, $3, @
2); }
8605 |
'+' b_expr %prec UMINUS
8606 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", NULL
, $2, @
1); }
8607 |
'-' b_expr %prec UMINUS
8608 { $$
= doNegate
($2, @
1); }
8610 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "+", $1, $3, @
2); }
8612 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "-", $1, $3, @
2); }
8614 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "*", $1, $3, @
2); }
8616 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "/", $1, $3, @
2); }
8618 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "%", $1, $3, @
2); }
8620 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "^", $1, $3, @
2); }
8622 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "<", $1, $3, @
2); }
8624 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, ">", $1, $3, @
2); }
8626 { $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OP
, "=", $1, $3, @
2); }
8627 | b_expr qual_Op b_expr %prec Op
8628 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, $3, @
2); }
8629 | qual_Op b_expr %prec Op
8630 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $1, NULL
, $2, @
1); }
8631 | b_expr qual_Op %prec POSTFIXOP
8632 { $$
= (Node
*) makeA_Expr
(AEXPR_OP
, $2, $1, NULL
, @
2); }
8633 | b_expr IS DISTINCT FROM b_expr %prec IS
8635 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
, "=", $1, $5, @
2);
8637 | b_expr IS NOT DISTINCT FROM b_expr %prec IS
8639 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
,
8640 NULL
, (Node
*) makeSimpleA_Expr
(AEXPR_DISTINCT
, "=", $1, $6, @
2), @
2);
8642 | b_expr IS OF
'(' type_list
')' %prec IS
8644 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OF
, "=", $1, (Node
*) $5, @
2);
8646 | b_expr IS NOT OF
'(' type_list
')' %prec IS
8648 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_OF
, "<>", $1, (Node
*) $6, @
2);
8650 | b_expr IS DOCUMENT_P %prec IS
8652 $$
= makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
8653 list_make1
($1), @
2);
8655 | b_expr IS NOT DOCUMENT_P %prec IS
8657 $$
= (Node
*) makeA_Expr
(AEXPR_NOT
, NIL
, NULL
,
8658 makeXmlExpr
(IS_DOCUMENT
, NULL
, NIL
,
8659 list_make1
($1), @
2),
8665 * Productions that can be used in both a_expr and b_expr.
8667 * Note: productions that refer recursively to a_expr or b_expr mostly
8668 * cannot appear here. However, it's OK to refer to a_exprs that occur
8669 * inside parentheses, such as function arguments; that cannot introduce
8670 * ambiguity to the b_expr syntax.
8672 c_expr: columnref
{ $$
= $1; }
8673 | AexprConst
{ $$
= $1; }
8674 | PARAM opt_indirection
8676 ParamRef
*p
= makeNode
(ParamRef
);
8681 A_Indirection
*n
= makeNode
(A_Indirection
);
8682 n
->arg
= (Node
*) p
;
8683 n
->indirection
= check_indirection
($2);
8689 |
'(' a_expr
')' opt_indirection
8693 A_Indirection
*n
= makeNode
(A_Indirection
);
8695 n
->indirection
= check_indirection
($4);
8705 | select_with_parens %prec UMINUS
8707 SubLink
*n
= makeNode
(SubLink
);
8708 n
->subLinkType
= EXPR_SUBLINK
;
8715 | EXISTS select_with_parens
8717 SubLink
*n
= makeNode
(SubLink
);
8718 n
->subLinkType
= EXISTS_SUBLINK
;
8725 | ARRAY select_with_parens
8727 SubLink
*n
= makeNode
(SubLink
);
8728 n
->subLinkType
= ARRAY_SUBLINK
;
8737 A_ArrayExpr
*n
= (A_ArrayExpr
*) $2;
8738 Assert
(IsA
(n
, A_ArrayExpr
));
8739 /* point outermost A_ArrayExpr to the ARRAY keyword */
8745 RowExpr
*r
= makeNode
(RowExpr
);
8747 r
->row_typeid
= InvalidOid
; /* not analyzed yet */
8754 * func_expr is split out from c_expr just so that we have a classification
8755 * for "everything that is a function call or looks like one". This isn't
8756 * very important, but it saves us having to document which variants are
8757 * legal in the backwards-compatible functional-index syntax for CREATE INDEX.
8758 * (Note that many of the special SQL functions wouldn't actually make any
8759 * sense as functional index entries, but we ignore that consideration here.)
8761 func_expr: func_name
'(' ')' over_clause
8763 FuncCall
*n
= makeNode
(FuncCall
);
8766 n
->agg_star
= FALSE
;
8767 n
->agg_distinct
= FALSE
;
8768 n
->func_variadic
= FALSE
;
8773 | func_name
'(' expr_list
')' over_clause
8775 FuncCall
*n
= makeNode
(FuncCall
);
8778 n
->agg_star
= FALSE
;
8779 n
->agg_distinct
= FALSE
;
8780 n
->func_variadic
= FALSE
;
8785 | func_name
'(' VARIADIC a_expr
')' over_clause
8787 FuncCall
*n
= makeNode
(FuncCall
);
8789 n
->args
= list_make1
($4);
8790 n
->agg_star
= FALSE
;
8791 n
->agg_distinct
= FALSE
;
8792 n
->func_variadic
= TRUE
;
8797 | func_name
'(' expr_list
',' VARIADIC a_expr
')' over_clause
8799 FuncCall
*n
= makeNode
(FuncCall
);
8801 n
->args
= lappend
($3, $6);
8802 n
->agg_star
= FALSE
;
8803 n
->agg_distinct
= FALSE
;
8804 n
->func_variadic
= TRUE
;
8809 | func_name
'(' ALL expr_list
')' over_clause
8811 FuncCall
*n
= makeNode
(FuncCall
);
8814 n
->agg_star
= FALSE
;
8815 n
->agg_distinct
= FALSE
;
8816 /* Ideally we'd mark the FuncCall node to indicate
8817 * "must be an aggregate", but there's no provision
8818 * for that in FuncCall at the moment.
8820 n
->func_variadic
= FALSE
;
8825 | func_name
'(' DISTINCT expr_list
')' over_clause
8827 FuncCall
*n
= makeNode
(FuncCall
);
8830 n
->agg_star
= FALSE
;
8831 n
->agg_distinct
= TRUE
;
8832 n
->func_variadic
= FALSE
;
8837 | func_name
'(' '*' ')' over_clause
8840 * We consider AGGREGATE(*) to invoke a parameterless
8841 * aggregate. This does the right thing for COUNT(*),
8842 * and there are no other aggregates in SQL92 that accept
8845 * The FuncCall node is also marked agg_star = true,
8846 * so that later processing can detect what the argument
8849 FuncCall
*n
= makeNode
(FuncCall
);
8853 n
->agg_distinct
= FALSE
;
8854 n
->func_variadic
= FALSE
;
8862 * Translate as "'now'::text::date".
8864 * We cannot use "'now'::date" because coerce_type() will
8865 * immediately reduce that to a constant representing
8866 * today's date. We need to delay the conversion until
8867 * runtime, else the wrong things will happen when
8868 * CURRENT_DATE is used in a column default value or rule.
8870 * This could be simplified if we had a way to generate
8871 * an expression tree representing runtime application
8872 * of type-input conversion functions. (As of PG 7.3
8873 * that is actually possible, but not clear that we want
8877 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8878 $$
= makeTypeCast
(n
, SystemTypeName
("date"), -1);
8883 * Translate as "'now'::text::timetz".
8884 * See comments for CURRENT_DATE.
8887 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8888 $$
= makeTypeCast
(n
, SystemTypeName
("timetz"), -1);
8890 | CURRENT_TIME
'(' Iconst
')'
8893 * Translate as "'now'::text::timetz(n)".
8894 * See comments for CURRENT_DATE.
8898 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8899 d
= SystemTypeName
("timetz");
8900 d
->typmods
= list_make1
(makeIntConst
($3, @
3));
8901 $$
= makeTypeCast
(n
, d
, -1);
8906 * Translate as "now()", since we have a function that
8907 * does exactly what is needed.
8909 FuncCall
*n
= makeNode
(FuncCall
);
8910 n
->funcname
= SystemFuncName
("now");
8912 n
->agg_star
= FALSE
;
8913 n
->agg_distinct
= FALSE
;
8914 n
->func_variadic
= FALSE
;
8919 | CURRENT_TIMESTAMP
'(' Iconst
')'
8922 * Translate as "'now'::text::timestamptz(n)".
8923 * See comments for CURRENT_DATE.
8927 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8928 d
= SystemTypeName
("timestamptz");
8929 d
->typmods
= list_make1
(makeIntConst
($3, @
3));
8930 $$
= makeTypeCast
(n
, d
, -1);
8935 * Translate as "'now'::text::time".
8936 * See comments for CURRENT_DATE.
8939 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8940 $$
= makeTypeCast
((Node
*)n
, SystemTypeName
("time"), -1);
8942 | LOCALTIME
'(' Iconst
')'
8945 * Translate as "'now'::text::time(n)".
8946 * See comments for CURRENT_DATE.
8950 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8951 d
= SystemTypeName
("time");
8952 d
->typmods
= list_make1
(makeIntConst
($3, @
3));
8953 $$
= makeTypeCast
((Node
*)n
, d
, -1);
8958 * Translate as "'now'::text::timestamp".
8959 * See comments for CURRENT_DATE.
8962 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8963 $$
= makeTypeCast
(n
, SystemTypeName
("timestamp"), -1);
8965 | LOCALTIMESTAMP
'(' Iconst
')'
8968 * Translate as "'now'::text::timestamp(n)".
8969 * See comments for CURRENT_DATE.
8973 n
= makeStringConstCast
("now", @
1, SystemTypeName
("text"));
8974 d
= SystemTypeName
("timestamp");
8975 d
->typmods
= list_make1
(makeIntConst
($3, @
3));
8976 $$
= makeTypeCast
(n
, d
, -1);
8980 FuncCall
*n
= makeNode
(FuncCall
);
8981 n
->funcname
= SystemFuncName
("current_user");
8983 n
->agg_star
= FALSE
;
8984 n
->agg_distinct
= FALSE
;
8985 n
->func_variadic
= FALSE
;
8992 FuncCall
*n
= makeNode
(FuncCall
);
8993 n
->funcname
= SystemFuncName
("current_user");
8995 n
->agg_star
= FALSE
;
8996 n
->agg_distinct
= FALSE
;
8997 n
->func_variadic
= FALSE
;
9004 FuncCall
*n
= makeNode
(FuncCall
);
9005 n
->funcname
= SystemFuncName
("session_user");
9007 n
->agg_star
= FALSE
;
9008 n
->agg_distinct
= FALSE
;
9009 n
->func_variadic
= FALSE
;
9016 FuncCall
*n
= makeNode
(FuncCall
);
9017 n
->funcname
= SystemFuncName
("current_user");
9019 n
->agg_star
= FALSE
;
9020 n
->agg_distinct
= FALSE
;
9021 n
->func_variadic
= FALSE
;
9028 FuncCall
*n
= makeNode
(FuncCall
);
9029 n
->funcname
= SystemFuncName
("current_database");
9031 n
->agg_star
= FALSE
;
9032 n
->agg_distinct
= FALSE
;
9033 n
->func_variadic
= FALSE
;
9040 FuncCall
*n
= makeNode
(FuncCall
);
9041 n
->funcname
= SystemFuncName
("current_schema");
9043 n
->agg_star
= FALSE
;
9044 n
->agg_distinct
= FALSE
;
9045 n
->func_variadic
= FALSE
;
9050 | CAST
'(' a_expr AS Typename
')'
9051 { $$
= makeTypeCast
($3, $5, @
1); }
9052 | EXTRACT
'(' extract_list
')'
9054 FuncCall
*n
= makeNode
(FuncCall
);
9055 n
->funcname
= SystemFuncName
("date_part");
9057 n
->agg_star
= FALSE
;
9058 n
->agg_distinct
= FALSE
;
9059 n
->func_variadic
= FALSE
;
9064 | OVERLAY
'(' overlay_list
')'
9066 /* overlay(A PLACING B FROM C FOR D) is converted to
9067 * substring(A, 1, C-1) || B || substring(A, C+1, C+D)
9068 * overlay(A PLACING B FROM C) is converted to
9069 * substring(A, 1, C-1) || B || substring(A, C+1, C+char_length(B))
9071 FuncCall
*n
= makeNode
(FuncCall
);
9072 n
->funcname
= SystemFuncName
("overlay");
9074 n
->agg_star
= FALSE
;
9075 n
->agg_distinct
= FALSE
;
9076 n
->func_variadic
= FALSE
;
9081 | POSITION
'(' position_list
')'
9083 /* position(A in B) is converted to position(B, A) */
9084 FuncCall
*n
= makeNode
(FuncCall
);
9085 n
->funcname
= SystemFuncName
("position");
9087 n
->agg_star
= FALSE
;
9088 n
->agg_distinct
= FALSE
;
9089 n
->func_variadic
= FALSE
;
9094 | SUBSTRING
'(' substr_list
')'
9096 /* substring(A from B for C) is converted to
9097 * substring(A, B, C) - thomas 2000-11-28
9099 FuncCall
*n
= makeNode
(FuncCall
);
9100 n
->funcname
= SystemFuncName
("substring");
9102 n
->agg_star
= FALSE
;
9103 n
->agg_distinct
= FALSE
;
9104 n
->func_variadic
= FALSE
;
9109 | TREAT
'(' a_expr AS Typename
')'
9111 /* TREAT(expr AS target) converts expr of a particular type to target,
9112 * which is defined to be a subtype of the original expression.
9113 * In SQL99, this is intended for use with structured UDTs,
9114 * but let's make this a generally useful form allowing stronger
9115 * coercions than are handled by implicit casting.
9117 FuncCall
*n
= makeNode
(FuncCall
);
9118 /* Convert SystemTypeName() to SystemFuncName() even though
9119 * at the moment they result in the same thing.
9121 n
->funcname
= SystemFuncName
(((Value
*)llast
($5->names
))->val.str
);
9122 n
->args
= list_make1
($3);
9123 n
->agg_star
= FALSE
;
9124 n
->agg_distinct
= FALSE
;
9125 n
->func_variadic
= FALSE
;
9130 | TRIM
'(' BOTH trim_list
')'
9132 /* various trim expressions are defined in SQL92
9133 * - thomas 1997-07-19
9135 FuncCall
*n
= makeNode
(FuncCall
);
9136 n
->funcname
= SystemFuncName
("btrim");
9138 n
->agg_star
= FALSE
;
9139 n
->agg_distinct
= FALSE
;
9140 n
->func_variadic
= FALSE
;
9145 | TRIM
'(' LEADING trim_list
')'
9147 FuncCall
*n
= makeNode
(FuncCall
);
9148 n
->funcname
= SystemFuncName
("ltrim");
9150 n
->agg_star
= FALSE
;
9151 n
->agg_distinct
= FALSE
;
9152 n
->func_variadic
= FALSE
;
9157 | TRIM
'(' TRAILING trim_list
')'
9159 FuncCall
*n
= makeNode
(FuncCall
);
9160 n
->funcname
= SystemFuncName
("rtrim");
9162 n
->agg_star
= FALSE
;
9163 n
->agg_distinct
= FALSE
;
9164 n
->func_variadic
= FALSE
;
9169 | TRIM
'(' trim_list
')'
9171 FuncCall
*n
= makeNode
(FuncCall
);
9172 n
->funcname
= SystemFuncName
("btrim");
9174 n
->agg_star
= FALSE
;
9175 n
->agg_distinct
= FALSE
;
9176 n
->func_variadic
= FALSE
;
9181 | NULLIF
'(' a_expr
',' a_expr
')'
9183 $$
= (Node
*) makeSimpleA_Expr
(AEXPR_NULLIF
, "=", $3, $5, @
1);
9185 | COALESCE
'(' expr_list
')'
9187 CoalesceExpr
*c
= makeNode
(CoalesceExpr
);
9192 | GREATEST
'(' expr_list
')'
9194 MinMaxExpr
*v
= makeNode
(MinMaxExpr
);
9196 v
->op
= IS_GREATEST
;
9200 | LEAST
'(' expr_list
')'
9202 MinMaxExpr
*v
= makeNode
(MinMaxExpr
);
9208 | XMLCONCAT
'(' expr_list
')'
9210 $$
= makeXmlExpr
(IS_XMLCONCAT
, NULL
, NIL
, $3, @
1);
9212 | XMLELEMENT
'(' NAME_P ColLabel
')'
9214 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, NIL
, NIL
, @
1);
9216 | XMLELEMENT
'(' NAME_P ColLabel
',' xml_attributes
')'
9218 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, $6, NIL
, @
1);
9220 | XMLELEMENT
'(' NAME_P ColLabel
',' expr_list
')'
9222 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, NIL
, $6, @
1);
9224 | XMLELEMENT
'(' NAME_P ColLabel
',' xml_attributes
',' expr_list
')'
9226 $$
= makeXmlExpr
(IS_XMLELEMENT
, $4, $6, $8, @
1);
9228 | XMLFOREST
'(' xml_attribute_list
')'
9230 $$
= makeXmlExpr
(IS_XMLFOREST
, NULL
, $3, NIL
, @
1);
9232 | XMLPARSE
'(' document_or_content a_expr xml_whitespace_option
')'
9234 XmlExpr
*x
= (XmlExpr
*)
9235 makeXmlExpr
(IS_XMLPARSE
, NULL
, NIL
,
9236 list_make2
($4, makeBoolAConst
($5, -1)),
9241 | XMLPI
'(' NAME_P ColLabel
')'
9243 $$
= makeXmlExpr
(IS_XMLPI
, $4, NULL
, NIL
, @
1);
9245 | XMLPI
'(' NAME_P ColLabel
',' a_expr
')'
9247 $$
= makeXmlExpr
(IS_XMLPI
, $4, NULL
, list_make1
($6), @
1);
9249 | XMLROOT
'(' a_expr
',' xml_root_version opt_xml_root_standalone
')'
9251 $$
= makeXmlExpr
(IS_XMLROOT
, NULL
, NIL
,
9252 list_make3
($3, $5, $6), @
1);
9254 | XMLSERIALIZE
'(' document_or_content a_expr AS SimpleTypename
')'
9256 XmlSerialize
*n
= makeNode
(XmlSerialize
);
9268 xml_root_version: VERSION_P a_expr
9270 | VERSION_P NO VALUE_P
9271 { $$
= makeNullAConst
(-1); }
9274 opt_xml_root_standalone: ',' STANDALONE_P YES_P
9275 { $$
= makeIntConst
(XML_STANDALONE_YES
, -1); }
9276 |
',' STANDALONE_P NO
9277 { $$
= makeIntConst
(XML_STANDALONE_NO
, -1); }
9278 |
',' STANDALONE_P NO VALUE_P
9279 { $$
= makeIntConst
(XML_STANDALONE_NO_VALUE
, -1); }
9281 { $$
= makeIntConst
(XML_STANDALONE_OMITTED
, -1); }
9284 xml_attributes: XMLATTRIBUTES
'(' xml_attribute_list
')' { $$
= $3; }
9287 xml_attribute_list: xml_attribute_el
{ $$
= list_make1
($1); }
9288 | xml_attribute_list
',' xml_attribute_el
{ $$
= lappend
($1, $3); }
9291 xml_attribute_el: a_expr AS ColLabel
9293 $$
= makeNode
(ResTarget
);
9295 $$
->indirection
= NIL
;
9296 $$
->val
= (Node
*) $1;
9301 $$
= makeNode
(ResTarget
);
9303 $$
->indirection
= NIL
;
9304 $$
->val
= (Node
*) $1;
9309 document_or_content: DOCUMENT_P
{ $$
= XMLOPTION_DOCUMENT
; }
9310 | CONTENT_P
{ $$
= XMLOPTION_CONTENT
; }
9313 xml_whitespace_option: PRESERVE WHITESPACE_P
{ $$
= TRUE
; }
9314 | STRIP_P WHITESPACE_P
{ $$
= FALSE
; }
9315 |
/*EMPTY*/ { $$
= FALSE
; }
9319 * Window Definitions
9322 WINDOW window_definition_list
{ $$
= $2; }
9323 |
/*EMPTY*/ { $$
= NIL
; }
9326 window_definition_list:
9327 window_definition
{ $$
= list_make1
($1); }
9328 | window_definition_list
',' window_definition
9329 { $$
= lappend
($1, $3); }
9333 ColId AS window_specification
9341 over_clause: OVER window_specification
9345 WindowDef
*n
= makeNode
(WindowDef
);
9348 n
->partitionClause
= NIL
;
9349 n
->orderClause
= NIL
;
9350 n
->frameOptions
= FRAMEOPTION_DEFAULTS
;
9358 window_specification: '(' opt_existing_window_name opt_partition_clause
9359 opt_sort_clause opt_frame_clause
')'
9361 WindowDef
*n
= makeNode
(WindowDef
);
9364 n
->partitionClause
= $3;
9365 n
->orderClause
= $4;
9366 n
->frameOptions
= $5;
9373 * If we see PARTITION, RANGE, or ROWS as the first token after the '('
9374 * of a window_specification, we want the assumption to be that there is
9375 * no existing_window_name; but those keywords are unreserved and so could
9376 * be ColIds. We fix this by making them have the same precedence as IDENT
9377 * and giving the empty production here a slightly higher precedence, so
9378 * that the shift/reduce conflict is resolved in favor of reducing the rule.
9379 * These keywords are thus precluded from being an existing_window_name but
9380 * are not reserved for any other purpose.
9382 opt_existing_window_name: ColId
{ $$
= $1; }
9383 |
/*EMPTY*/ %prec Op
{ $$
= NULL
; }
9386 opt_partition_clause: PARTITION BY expr_list
{ $$
= $3; }
9387 |
/*EMPTY*/ { $$
= NIL
; }
9391 * This is only a subset of the full SQL:2008 frame_clause grammar.
9392 * We don't support <expression> PRECEDING, <expression> FOLLOWING,
9393 * nor <window frame exclusion> yet.
9398 $$
= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE |
$2;
9402 $$
= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS |
$2;
9405 { $$
= FRAMEOPTION_DEFAULTS
; }
9408 frame_extent: frame_bound
9410 /* reject invalid cases */
9411 if
($1 & FRAMEOPTION_START_UNBOUNDED_FOLLOWING
)
9413 (errcode
(ERRCODE_WINDOWING_ERROR
),
9414 errmsg
("frame start cannot be UNBOUNDED FOLLOWING"),
9415 scanner_errposition
(@
1)));
9416 if
($1 & FRAMEOPTION_START_CURRENT_ROW
)
9418 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
9419 errmsg
("frame start at CURRENT ROW is not implemented"),
9420 scanner_errposition
(@
1)));
9421 $$
= $1 | FRAMEOPTION_END_CURRENT_ROW
;
9423 | BETWEEN frame_bound AND frame_bound
9425 /* reject invalid cases */
9426 if
($2 & FRAMEOPTION_START_UNBOUNDED_FOLLOWING
)
9428 (errcode
(ERRCODE_WINDOWING_ERROR
),
9429 errmsg
("frame start cannot be UNBOUNDED FOLLOWING"),
9430 scanner_errposition
(@
2)));
9431 if
($2 & FRAMEOPTION_START_CURRENT_ROW
)
9433 (errcode
(ERRCODE_FEATURE_NOT_SUPPORTED
),
9434 errmsg
("frame start at CURRENT ROW is not implemented"),
9435 scanner_errposition
(@
2)));
9436 if
($4 & FRAMEOPTION_START_UNBOUNDED_PRECEDING
)
9438 (errcode
(ERRCODE_WINDOWING_ERROR
),
9439 errmsg
("frame end cannot be UNBOUNDED PRECEDING"),
9440 scanner_errposition
(@
4)));
9441 /* shift converts START_ options to END_ options */
9442 $$
= FRAMEOPTION_BETWEEN |
$2 |
($4 << 1);
9447 * This is used for both frame start and frame end, with output set up on
9448 * the assumption it's frame start; the frame_extent productions must reject
9454 $$
= FRAMEOPTION_START_UNBOUNDED_PRECEDING
;
9456 | UNBOUNDED FOLLOWING
9458 $$
= FRAMEOPTION_START_UNBOUNDED_FOLLOWING
;
9462 $$
= FRAMEOPTION_START_CURRENT_ROW
;
9468 * Supporting nonterminals for expressions.
9471 /* Explicit row production.
9473 * SQL99 allows an optional ROW keyword, so we can now do single-element rows
9474 * without conflicting with the parenthesized a_expr production. Without the
9475 * ROW keyword, there must be more than one a_expr inside the parens.
9477 row: ROW
'(' expr_list
')' { $$
= $3; }
9478 | ROW
'(' ')' { $$
= NIL
; }
9479 |
'(' expr_list
',' a_expr
')' { $$
= lappend
($2, $4); }
9482 sub_type: ANY
{ $$
= ANY_SUBLINK
; }
9483 | SOME
{ $$
= ANY_SUBLINK
; }
9484 | ALL
{ $$
= ALL_SUBLINK
; }
9487 all_Op: Op
{ $$
= $1; }
9488 | MathOp
{ $$
= $1; }
9491 MathOp: '+' { $$
= "+"; }
9503 { $$
= list_make1
(makeString
($1)); }
9504 | OPERATOR
'(' any_operator
')'
9510 { $$
= list_make1
(makeString
($1)); }
9511 | OPERATOR
'(' any_operator
')'
9517 { $$
= list_make1
(makeString
($1)); }
9518 | OPERATOR
'(' any_operator
')'
9521 { $$
= list_make1
(makeString
("~~")); }
9523 { $$
= list_make1
(makeString
("!~~")); }
9525 { $$
= list_make1
(makeString
("~~*")); }
9527 { $$
= list_make1
(makeString
("!~~*")); }
9528 /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
9529 * the regular expression is preprocessed by a function (similar_escape),
9530 * and the ~ operator for posix regular expressions is used.
9531 * x SIMILAR TO y -> x ~ similar_escape(y)
9532 * this transformation is made on the fly by the parser upwards.
9533 * however the SubLink structure which handles any/some/all stuff
9534 * is not ready for such a thing.
9540 $$
= list_make1
($1);
9542 | expr_list
',' a_expr
9544 $$
= lappend
($1, $3);
9548 type_list: Typename
{ $$
= list_make1
($1); }
9549 | type_list
',' Typename
{ $$
= lappend
($1, $3); }
9552 array_expr: '[' expr_list
']'
9554 $$
= makeAArrayExpr
($2, @
1);
9556 |
'[' array_expr_list
']'
9558 $$
= makeAArrayExpr
($2, @
1);
9562 $$
= makeAArrayExpr
(NIL
, @
1);
9566 array_expr_list: array_expr
{ $$
= list_make1
($1); }
9567 | array_expr_list
',' array_expr
{ $$
= lappend
($1, $3); }
9572 extract_arg FROM a_expr
9574 $$
= list_make2
(makeStringConst
($1, @
1), $3);
9576 |
/*EMPTY*/ { $$
= NIL
; }
9579 /* Allow delimited string Sconst in extract_arg as an SQL extension.
9580 * - thomas 2001-04-12
9584 | YEAR_P
{ $$
= "year"; }
9585 | MONTH_P
{ $$
= "month"; }
9586 | DAY_P
{ $$
= "day"; }
9587 | HOUR_P
{ $$
= "hour"; }
9588 | MINUTE_P
{ $$
= "minute"; }
9589 | SECOND_P
{ $$
= "second"; }
9590 | Sconst
{ $$
= $1; }
9593 /* OVERLAY() arguments
9594 * SQL99 defines the OVERLAY() function:
9595 * o overlay(text placing text from int for int)
9596 * o overlay(text placing text from int)
9599 a_expr overlay_placing substr_from substr_for
9601 $$
= list_make4
($1, $2, $3, $4);
9603 | a_expr overlay_placing substr_from
9605 $$
= list_make3
($1, $2, $3);
9614 /* position_list uses b_expr not a_expr to avoid conflict with general IN */
9617 b_expr IN_P b_expr
{ $$
= list_make2
($3, $1); }
9618 |
/*EMPTY*/ { $$
= NIL
; }
9621 /* SUBSTRING() arguments
9622 * SQL9x defines a specific syntax for arguments to SUBSTRING():
9623 * o substring(text from int for int)
9624 * o substring(text from int) get entire string from starting point "int"
9625 * o substring(text for int) get first "int" characters of string
9626 * o substring(text from pattern) get entire string matching pattern
9627 * o substring(text from pattern for escape) same with specified escape char
9628 * We also want to support generic substring functions which accept
9629 * the usual generic list of arguments. So we will accept both styles
9630 * here, and convert the SQL9x style to the generic list for further
9631 * processing. - thomas 2000-11-28
9634 a_expr substr_from substr_for
9636 $$
= list_make3
($1, $2, $3);
9638 | a_expr substr_for substr_from
9640 /* not legal per SQL99, but might as well allow it */
9641 $$
= list_make3
($1, $3, $2);
9643 | a_expr substr_from
9645 $$
= list_make2
($1, $2);
9650 * Since there are no cases where this syntax allows
9651 * a textual FOR value, we forcibly cast the argument
9652 * to int4. The possible matches in pg_proc are
9653 * substring(text,int4) and substring(text,text),
9654 * and we don't want the parser to choose the latter,
9655 * which it is likely to do if the second argument
9656 * is unknown or doesn't have an implicit cast to int4.
9658 $$
= list_make3
($1, makeIntConst
(1, -1),
9660 SystemTypeName
("int4"), -1));
9671 FROM a_expr
{ $$
= $2; }
9674 substr_for: FOR a_expr
{ $$
= $2; }
9677 trim_list: a_expr FROM expr_list
{ $$
= lappend
($3, $1); }
9678 | FROM expr_list
{ $$
= $2; }
9679 | expr_list
{ $$
= $1; }
9682 in_expr: select_with_parens
9684 SubLink
*n
= makeNode
(SubLink
);
9686 /* other fields will be filled later */
9689 |
'(' expr_list
')' { $$
= (Node
*)$2; }
9693 * Define SQL92-style case clause.
9694 * - Full specification
9695 * CASE WHEN a = b THEN c ... ELSE d END
9696 * - Implicit argument
9697 * CASE a WHEN b THEN c ... ELSE d END
9699 case_expr: CASE case_arg when_clause_list case_default END_P
9701 CaseExpr
*c
= makeNode
(CaseExpr
);
9702 c
->casetype
= InvalidOid
; /* not analyzed yet */
9703 c
->arg
= (Expr
*) $2;
9705 c
->defresult
= (Expr
*) $4;
9712 /* There must be at least one */
9713 when_clause
{ $$
= list_make1
($1); }
9714 | when_clause_list when_clause
{ $$
= lappend
($1, $2); }
9718 WHEN a_expr THEN a_expr
9720 CaseWhen
*w
= makeNode
(CaseWhen
);
9721 w
->expr
= (Expr
*) $2;
9722 w
->result
= (Expr
*) $4;
9729 ELSE a_expr
{ $$
= $2; }
9730 |
/*EMPTY*/ { $$
= NULL
; }
9733 case_arg: a_expr
{ $$
= $1; }
9734 |
/*EMPTY*/ { $$
= NULL
; }
9738 * columnref starts with relation_name not ColId, so that OLD and NEW
9739 * references can be accepted. Note that when there are more than two
9740 * dotted names, the first name is not actually a relation name...
9742 columnref: relation_name
9744 $$
= makeColumnRef
($1, NIL
, @
1);
9746 | relation_name indirection
9748 $$
= makeColumnRef
($1, $2, @
1);
9755 $$
= (Node
*) makeString
($2);
9759 $$
= (Node
*) makeNode
(A_Star
);
9763 A_Indices
*ai
= makeNode
(A_Indices
);
9768 |
'[' a_expr
':' a_expr
']'
9770 A_Indices
*ai
= makeNode
(A_Indices
);
9778 indirection_el
{ $$
= list_make1
($1); }
9779 | indirection indirection_el
{ $$
= lappend
($1, $2); }
9783 /*EMPTY*/ { $$
= NIL
; }
9784 | opt_indirection indirection_el
{ $$
= lappend
($1, $2); }
9787 opt_asymmetric: ASYMMETRIC
9792 * The SQL spec defines "contextually typed value expressions" and
9793 * "contextually typed row value constructors", which for our purposes
9794 * are the same as "a_expr" and "row" except that DEFAULT can appear at
9799 a_expr
{ $$
= (Node
*) $1; }
9802 SetToDefault
*n
= makeNode
(SetToDefault
);
9809 ctext_expr
{ $$
= list_make1
($1); }
9810 | ctext_expr_list
',' ctext_expr
{ $$
= lappend
($1, $3); }
9814 * We should allow ROW '(' ctext_expr_list ')' too, but that seems to require
9815 * making VALUES a fully reserved word, which will probably break more apps
9816 * than allowing the noise-word is worth.
9818 ctext_row: '(' ctext_expr_list
')' { $$
= $2; }
9822 /*****************************************************************************
9824 * target list for SELECT
9826 *****************************************************************************/
9829 target_el
{ $$
= list_make1
($1); }
9830 | target_list
',' target_el
{ $$
= lappend
($1, $3); }
9833 target_el: a_expr AS ColLabel
9835 $$
= makeNode
(ResTarget
);
9837 $$
->indirection
= NIL
;
9838 $$
->val
= (Node
*)$1;
9842 * We support omitting AS only for column labels that aren't
9843 * any known keyword. There is an ambiguity against postfix
9844 * operators: is "a ! b" an infix expression, or a postfix
9845 * expression and a column label? We prefer to resolve this
9846 * as an infix expression, which we accomplish by assigning
9847 * IDENT a precedence higher than POSTFIXOP.
9851 $$
= makeNode
(ResTarget
);
9853 $$
->indirection
= NIL
;
9854 $$
->val
= (Node
*)$1;
9859 $$
= makeNode
(ResTarget
);
9861 $$
->indirection
= NIL
;
9862 $$
->val
= (Node
*)$1;
9867 ColumnRef
*n
= makeNode
(ColumnRef
);
9868 n
->fields
= list_make1
(makeNode
(A_Star
));
9871 $$
= makeNode
(ResTarget
);
9873 $$
->indirection
= NIL
;
9874 $$
->val
= (Node
*)n
;
9880 /*****************************************************************************
9882 * Names and constants
9884 *****************************************************************************/
9887 SpecialRuleRelation
{ $$
= $1; }
9888 | ColId
{ $$
= $1; }
9891 qualified_name_list:
9892 qualified_name
{ $$
= list_make1
($1); }
9893 | qualified_name_list
',' qualified_name
{ $$
= lappend
($1, $3); }
9897 * The production for a qualified relation name has to exactly match the
9898 * production for a qualified func_name, because in a FROM clause we cannot
9899 * tell which we are parsing until we see what comes after it ('(' for a
9900 * func_name, something else for a relation). Therefore we allow 'indirection'
9901 * which may contain subscripts, and reject that case in the C code.
9906 $$
= makeNode
(RangeVar
);
9907 $$
->catalogname
= NULL
;
9908 $$
->schemaname
= NULL
;
9912 | relation_name indirection
9914 check_qualified_name
($2);
9915 $$
= makeNode
(RangeVar
);
9916 switch
(list_length
($2))
9919 $$
->catalogname
= NULL
;
9920 $$
->schemaname
= $1;
9921 $$
->relname
= strVal
(linitial
($2));
9924 $$
->catalogname
= $1;
9925 $$
->schemaname
= strVal
(linitial
($2));
9926 $$
->relname
= strVal
(lsecond
($2));
9930 (errcode
(ERRCODE_SYNTAX_ERROR
),
9931 errmsg
("improper qualified name (too many dotted names): %s",
9932 NameListToString
(lcons
(makeString
($1), $2))),
9933 scanner_errposition
(@
1)));
9941 { $$
= list_make1
(makeString
($1)); }
9942 | name_list
',' name
9943 { $$
= lappend
($1, makeString
($3)); }
9947 name: ColId
{ $$
= $1; };
9955 attr_name: ColLabel
{ $$
= $1; };
9957 index_name: ColId
{ $$
= $1; };
9959 file_name: Sconst
{ $$
= $1; };
9962 * The production for a qualified func_name has to exactly match the
9963 * production for a qualified columnref, because we cannot tell which we
9964 * are parsing until we see what comes after it ('(' or Sconst for a func_name,
9965 * anything else for a columnref). Therefore we allow 'indirection' which
9966 * may contain subscripts, and reject that case in the C code. (If we
9967 * ever implement SQL99-like methods, such syntax may actually become legal!)
9969 func_name: type_function_name
9970 { $$
= list_make1
(makeString
($1)); }
9971 | relation_name indirection
9972 { $$
= check_func_name
(lcons
(makeString
($1), $2)); }
9981 $$
= makeIntConst
($1, @
1);
9985 $$
= makeFloatConst
($1, @
1);
9989 $$
= makeStringConst
($1, @
1);
9993 $$
= makeBitStringConst
($1, @
1);
9997 /* This is a bit constant per SQL99:
9998 * Without Feature F511, "BIT data type",
9999 * a <general literal> shall not be a
10000 * <bit string literal> or a <hex string literal>.
10002 $$
= makeBitStringConst
($1, @
1);
10006 /* generic type 'literal' syntax */
10007 TypeName
*t
= makeTypeNameFromNameList
($1);
10009 $$
= makeStringConstCast
($2, @
2, t
);
10011 | func_name
'(' expr_list
')' Sconst
10013 /* generic syntax with a type modifier */
10014 TypeName
*t
= makeTypeNameFromNameList
($1);
10017 $$
= makeStringConstCast
($5, @
5, t
);
10019 | ConstTypename Sconst
10021 $$
= makeStringConstCast
($2, @
2, $1);
10023 | ConstInterval Sconst opt_interval
10027 $$
= makeStringConstCast
($2, @
2, t
);
10029 | ConstInterval
'(' Iconst
')' Sconst opt_interval
10034 if
(list_length
($6) != 1)
10036 (errcode
(ERRCODE_SYNTAX_ERROR
),
10037 errmsg
("interval precision specified twice"),
10038 scanner_errposition
(@
1)));
10039 t
->typmods
= lappend
($6, makeIntConst
($3, @
3));
10042 t
->typmods
= list_make2
(makeIntConst
(INTERVAL_FULL_RANGE
, -1),
10043 makeIntConst
($3, @
3));
10044 $$
= makeStringConstCast
($5, @
5, t
);
10048 $$
= makeBoolAConst
(TRUE
, @
1);
10052 $$
= makeBoolAConst
(FALSE
, @
1);
10056 $$
= makeNullAConst
(@
1);
10060 Iconst: ICONST
{ $$
= $1; };
10061 Sconst: SCONST
{ $$
= $1; };
10062 RoleId: ColId
{ $$
= $1; };
10064 SignedIconst: Iconst
{ $$
= $1; }
10065 |
'+' Iconst
{ $$
= + $2; }
10066 |
'-' Iconst
{ $$
= - $2; }
10070 * Name classification hierarchy.
10072 * IDENT is the lexeme returned by the lexer for identifiers that match
10073 * no known keyword. In most cases, we can accept certain keywords as
10074 * names, not only IDENTs. We prefer to accept as many such keywords
10075 * as possible to minimize the impact of "reserved words" on programmers.
10076 * So, we divide names into several possible classes. The classification
10077 * is chosen in part to make keywords acceptable as names wherever possible.
10080 /* Column identifier --- names that can be column, table, etc names.
10082 ColId: IDENT
{ $$
= $1; }
10083 | unreserved_keyword
{ $$
= pstrdup
($1); }
10084 | col_name_keyword
{ $$
= pstrdup
($1); }
10087 /* Type/function identifier --- names that can be type or function names.
10089 type_function_name: IDENT
{ $$
= $1; }
10090 | unreserved_keyword
{ $$
= pstrdup
($1); }
10091 | type_func_name_keyword
{ $$
= pstrdup
($1); }
10094 /* Column label --- allowed labels in "AS" clauses.
10095 * This presently includes *all* Postgres keywords.
10097 ColLabel: IDENT
{ $$
= $1; }
10098 | unreserved_keyword
{ $$
= pstrdup
($1); }
10099 | col_name_keyword
{ $$
= pstrdup
($1); }
10100 | type_func_name_keyword
{ $$
= pstrdup
($1); }
10101 | reserved_keyword
{ $$
= pstrdup
($1); }
10106 * Keyword category lists. Generally, every keyword present in
10107 * the Postgres grammar should appear in exactly one of these lists.
10109 * Put a new keyword into the first list that it can go into without causing
10110 * shift or reduce conflicts. The earlier lists define "less reserved"
10111 * categories of keywords.
10113 * Make sure that each keyword's category in keywords.c matches where
10114 * it is listed here. (Someday we may be able to generate these lists and
10115 * keywords.c's table from a common master list.)
10118 /* "Unreserved" keywords --- available for use as any kind of name.
10120 unreserved_keyword:
10369 /* Column identifier --- keywords that can be column, table, etc names.
10371 * Many of these keywords will in fact be recognized as type or function
10372 * names too; but they have special productions for the purpose, and so
10373 * can't be treated as "generic" type or function names.
10375 * The type names appearing here are not usable as function names
10376 * because they can be followed by '(' in typename productions, which
10377 * looks too much like a function call for an LR(1) parser.
10427 /* Type/function identifier --- keywords that can be type or function names.
10429 * Most of these are keywords that are used as operators in expressions;
10430 * in general such keywords can't be column names because they would be
10431 * ambiguous with variables, but they are unambiguous as function identifiers.
10433 * Do not include POSITION, SUBSTRING, etc here since they have explicit
10434 * productions in a_expr to support the goofy SQL9x argument syntax.
10435 * - thomas 2000-11-28
10437 type_func_name_keyword:
10462 /* Reserved keyword --- these keywords are usable only as a ColLabel.
10464 * Keywords appear here if they could not be distinguished from variable,
10465 * type, or function names in some contexts. Don't put things here unless
10490 | CURRENT_TIMESTAMP
10551 SpecialRuleRelation:
10558 (errcode
(ERRCODE_SYNTAX_ERROR
),
10559 errmsg
("OLD used in query that is not in a rule"),
10560 scanner_errposition
(@
1)));
10568 (errcode
(ERRCODE_SYNTAX_ERROR
),
10569 errmsg
("NEW used in query that is not in a rule"),
10570 scanner_errposition
(@
1)));
10577 makeColumnRef
(char *colname
, List
*indirection
, int location
)
10580 * Generate a ColumnRef node, with an A_Indirection node added if there
10581 * is any subscripting in the specified indirection list. However,
10582 * any field selection at the start of the indirection list must be
10583 * transposed into the "fields" part of the ColumnRef node.
10585 ColumnRef
*c
= makeNode
(ColumnRef
);
10589 c
->location
= location
;
10590 foreach
(l
, indirection
)
10592 if
(IsA
(lfirst
(l
), A_Indices
))
10594 A_Indirection
*i
= makeNode
(A_Indirection
);
10598 /* easy case - all indirection goes to A_Indirection */
10599 c
->fields
= list_make1
(makeString
(colname
));
10600 i
->indirection
= check_indirection
(indirection
);
10604 /* got to split the list in two */
10605 i
->indirection
= check_indirection
(list_copy_tail
(indirection
,
10607 indirection
= list_truncate
(indirection
, nfields
);
10608 c
->fields
= lcons
(makeString
(colname
), indirection
);
10610 i
->arg
= (Node
*) c
;
10613 else if
(IsA
(lfirst
(l
), A_Star
))
10615 /* We only allow '*' at the end of a ColumnRef */
10616 if
(lnext
(l
) != NULL
)
10617 yyerror("improper use of \"*\"");
10621 /* No subscripting, so all indirection gets added to field list */
10622 c
->fields
= lcons
(makeString
(colname
), indirection
);
10627 makeTypeCast
(Node
*arg
, TypeName
*typename
, int location
)
10629 TypeCast
*n
= makeNode
(TypeCast
);
10631 n
->typename
= typename
;
10632 n
->location
= location
;
10637 makeStringConst
(char *str
, int location
)
10639 A_Const
*n
= makeNode
(A_Const
);
10641 n
->val.type
= T_String
;
10642 n
->val.val.str
= str
;
10643 n
->location
= location
;
10649 makeStringConstCast
(char *str
, int location
, TypeName
*typename
)
10651 Node
*s
= makeStringConst
(str
, location
);
10653 return makeTypeCast
(s
, typename
, -1);
10657 makeIntConst
(int val
, int location
)
10659 A_Const
*n
= makeNode
(A_Const
);
10661 n
->val.type
= T_Integer
;
10662 n
->val.val.ival
= val
;
10663 n
->location
= location
;
10669 makeFloatConst
(char *str
, int location
)
10671 A_Const
*n
= makeNode
(A_Const
);
10673 n
->val.type
= T_Float
;
10674 n
->val.val.str
= str
;
10675 n
->location
= location
;
10681 makeBitStringConst
(char *str
, int location
)
10683 A_Const
*n
= makeNode
(A_Const
);
10685 n
->val.type
= T_BitString
;
10686 n
->val.val.str
= str
;
10687 n
->location
= location
;
10693 makeNullAConst
(int location
)
10695 A_Const
*n
= makeNode
(A_Const
);
10697 n
->val.type
= T_Null
;
10698 n
->location
= location
;
10704 makeAConst
(Value
*v
, int location
)
10711 n
= makeFloatConst
(v
->val.str
, location
);
10715 n
= makeIntConst
(v
->val.ival
, location
);
10720 n
= makeStringConst
(v
->val.str
, location
);
10727 /* makeBoolAConst()
10728 * Create an A_Const string node and put it inside a boolean cast.
10731 makeBoolAConst
(bool state
, int location
)
10733 A_Const
*n
= makeNode
(A_Const
);
10735 n
->val.type
= T_String
;
10736 n
->val.val.str
= (state ?
"t" : "f");
10737 n
->location
= location
;
10739 return makeTypeCast
((Node
*)n
, SystemTypeName
("bool"), -1);
10743 * Create and populate a FuncCall node to support the OVERLAPS operator.
10746 makeOverlaps
(List
*largs
, List
*rargs
, int location
)
10748 FuncCall
*n
= makeNode
(FuncCall
);
10750 n
->funcname
= SystemFuncName
("overlaps");
10751 if
(list_length
(largs
) == 1)
10752 largs
= lappend
(largs
, largs
);
10753 else if
(list_length
(largs
) != 2)
10755 (errcode
(ERRCODE_SYNTAX_ERROR
),
10756 errmsg
("wrong number of parameters on left side of OVERLAPS expression"),
10757 scanner_errposition
(location
)));
10758 if
(list_length
(rargs
) == 1)
10759 rargs
= lappend
(rargs
, rargs
);
10760 else if
(list_length
(rargs
) != 2)
10762 (errcode
(ERRCODE_SYNTAX_ERROR
),
10763 errmsg
("wrong number of parameters on right side of OVERLAPS expression"),
10764 scanner_errposition
(location
)));
10765 n
->args
= list_concat
(largs
, rargs
);
10766 n
->agg_star
= FALSE
;
10767 n
->agg_distinct
= FALSE
;
10768 n
->func_variadic
= FALSE
;
10770 n
->location
= location
;
10774 /* check_qualified_name --- check the result of qualified_name production
10776 * It's easiest to let the grammar production for qualified_name allow
10777 * subscripts and '*', which we then must reject here.
10780 check_qualified_name
(List
*names
)
10786 if
(!IsA
(lfirst
(i
), String
))
10787 yyerror("syntax error");
10791 /* check_func_name --- check the result of func_name production
10793 * It's easiest to let the grammar production for func_name allow subscripts
10794 * and '*', which we then must reject here.
10797 check_func_name
(List
*names
)
10803 if
(!IsA
(lfirst
(i
), String
))
10804 yyerror("syntax error");
10809 /* check_indirection --- check the result of indirection production
10811 * We only allow '*' at the end of the list, but it's hard to enforce that
10812 * in the grammar, so do it here.
10815 check_indirection
(List
*indirection
)
10819 foreach
(l
, indirection
)
10821 if
(IsA
(lfirst
(l
), A_Star
))
10823 if
(lnext
(l
) != NULL
)
10824 yyerror("improper use of \"*\"");
10827 return indirection
;
10830 /* extractArgTypes()
10831 * Given a list of FunctionParameter nodes, extract a list of just the
10832 * argument types (TypeNames) for input parameters only. This is what
10833 * is needed to look up an existing function, which is what is wanted by
10834 * the productions that use this call.
10837 extractArgTypes
(List
*parameters
)
10839 List
*result
= NIL
;
10842 foreach
(i
, parameters
)
10844 FunctionParameter
*p
= (FunctionParameter
*) lfirst
(i
);
10846 if
(p
->mode
!= FUNC_PARAM_OUT
&& p
->mode
!= FUNC_PARAM_TABLE
)
10847 result
= lappend
(result
, p
->argType
);
10852 /* findLeftmostSelect()
10853 * Find the leftmost component SelectStmt in a set-operation parsetree.
10855 static SelectStmt
*
10856 findLeftmostSelect
(SelectStmt
*node
)
10858 while
(node
&& node
->op
!= SETOP_NONE
)
10860 Assert
(node
&& IsA
(node
, SelectStmt
) && node
->larg
== NULL
);
10864 /* insertSelectOptions()
10865 * Insert ORDER BY, etc into an already-constructed SelectStmt.
10867 * This routine is just to avoid duplicating code in SelectStmt productions.
10870 insertSelectOptions
(SelectStmt
*stmt
,
10871 List
*sortClause
, List
*lockingClause
,
10872 Node
*limitOffset
, Node
*limitCount
,
10873 WithClause
*withClause
)
10875 Assert
(IsA
(stmt
, SelectStmt
));
10878 * Tests here are to reject constructs like
10879 * (SELECT foo ORDER BY bar) ORDER BY baz
10883 if
(stmt
->sortClause
)
10885 (errcode
(ERRCODE_SYNTAX_ERROR
),
10886 errmsg
("multiple ORDER BY clauses not allowed"),
10887 scanner_errposition
(exprLocation
((Node
*) sortClause
))));
10888 stmt
->sortClause
= sortClause
;
10890 /* We can handle multiple locking clauses, though */
10891 stmt
->lockingClause
= list_concat
(stmt
->lockingClause
, lockingClause
);
10894 if
(stmt
->limitOffset
)
10896 (errcode
(ERRCODE_SYNTAX_ERROR
),
10897 errmsg
("multiple OFFSET clauses not allowed"),
10898 scanner_errposition
(exprLocation
(limitOffset
))));
10899 stmt
->limitOffset
= limitOffset
;
10903 if
(stmt
->limitCount
)
10905 (errcode
(ERRCODE_SYNTAX_ERROR
),
10906 errmsg
("multiple LIMIT clauses not allowed"),
10907 scanner_errposition
(exprLocation
(limitCount
))));
10908 stmt
->limitCount
= limitCount
;
10912 if
(stmt
->withClause
)
10914 (errcode
(ERRCODE_SYNTAX_ERROR
),
10915 errmsg
("multiple WITH clauses not allowed"),
10916 scanner_errposition
(exprLocation
((Node
*) withClause
))));
10917 stmt
->withClause
= withClause
;
10922 makeSetOp
(SetOperation op
, bool all
, Node
*larg
, Node
*rarg
)
10924 SelectStmt
*n
= makeNode
(SelectStmt
);
10928 n
->larg
= (SelectStmt
*) larg
;
10929 n
->rarg
= (SelectStmt
*) rarg
;
10933 /* SystemFuncName()
10934 * Build a properly-qualified reference to a built-in function.
10937 SystemFuncName
(char *name
)
10939 return list_make2
(makeString
("pg_catalog"), makeString
(name
));
10942 /* SystemTypeName()
10943 * Build a properly-qualified reference to a built-in type.
10945 * typmod is defaulted, but may be changed afterwards by caller.
10946 * Likewise for the location.
10949 SystemTypeName
(char *name
)
10951 return makeTypeNameFromNameList
(list_make2
(makeString
("pg_catalog"),
10952 makeString
(name
)));
10956 * Handle negation of a numeric constant.
10958 * Formerly, we did this here because the optimizer couldn't cope with
10959 * indexquals that looked like "var = -4" --- it wants "var = const"
10960 * and a unary minus operator applied to a constant didn't qualify.
10961 * As of Postgres 7.0, that problem doesn't exist anymore because there
10962 * is a constant-subexpression simplifier in the optimizer. However,
10963 * there's still a good reason for doing this here, which is that we can
10964 * postpone committing to a particular internal representation for simple
10965 * negative constants. It's better to leave "-123.456" in string form
10966 * until we know what the desired type is.
10969 doNegate
(Node
*n
, int location
)
10971 if
(IsA
(n
, A_Const
))
10973 A_Const
*con
= (A_Const
*)n
;
10975 /* report the constant's location as that of the '-' sign */
10976 con
->location
= location
;
10978 if
(con
->val.type
== T_Integer
)
10980 con
->val.val.ival
= -con
->val.val.ival
;
10983 if
(con
->val.type
== T_Float
)
10985 doNegateFloat
(&con
->val
);
10990 return
(Node
*) makeSimpleA_Expr
(AEXPR_OP
, "-", NULL
, n
, location
);
10994 doNegateFloat
(Value
*v
)
10996 char *oldval
= v
->val.str
;
10998 Assert
(IsA
(v
, Float
));
10999 if
(*oldval
== '+')
11001 if
(*oldval
== '-')
11002 v
->val.str
= oldval
+1; /* just strip the '-' */
11005 char *newval
= (char *) palloc
(strlen
(oldval
) + 2);
11008 strcpy
(newval
+1, oldval
);
11009 v
->val.str
= newval
;
11014 makeAArrayExpr
(List
*elements
, int location
)
11016 A_ArrayExpr
*n
= makeNode
(A_ArrayExpr
);
11018 n
->elements
= elements
;
11019 n
->location
= location
;
11024 makeXmlExpr
(XmlExprOp op
, char *name
, List
*named_args
, List
*args
,
11027 XmlExpr
*x
= makeNode
(XmlExpr
);
11032 * named_args is a list of ResTarget; it'll be split apart into separate
11033 * expression and name lists in transformXmlExpr().
11035 x
->named_args
= named_args
;
11036 x
->arg_names
= NIL
;
11038 /* xmloption, if relevant, must be filled in by caller */
11039 /* type and typmod will be filled in during parse analysis */
11040 x
->location
= location
;
11045 * Initialize to parse one query string
11050 QueryIsRule
= FALSE
;
11054 * Merge the input and output parameters of a table function.
11057 mergeTableFuncParameters
(List
*func_args
, List
*columns
)
11061 /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
11062 foreach
(lc
, func_args
)
11064 FunctionParameter
*p
= (FunctionParameter
*) lfirst
(lc
);
11066 if
(p
->mode
!= FUNC_PARAM_IN
&& p
->mode
!= FUNC_PARAM_VARIADIC
)
11068 (errcode
(ERRCODE_SYNTAX_ERROR
),
11069 errmsg
("OUT and INOUT arguments aren't allowed in TABLE functions")));
11072 return list_concat
(func_args
, columns
);
11076 * Determine return type of a TABLE function. A single result column
11077 * returns setof that column's type; otherwise return setof record.
11080 TableFuncTypeName
(List
*columns
)
11084 if
(list_length
(columns
) == 1)
11086 FunctionParameter
*p
= (FunctionParameter
*) linitial
(columns
);
11088 result
= (TypeName
*) copyObject
(p
->argType
);
11091 result
= SystemTypeName
("record");
11093 result
->setof
= true
;
11099 * Must undefine base_yylex before including scan.c, since we want it
11100 * to create the function base_yylex not filtered_base_yylex.