4
/*-------------------------------------------------------------------------
7
* POSTGRES SQL YACC rules/actions
9
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
10
* Portions Copyright (c) 1994, Regents of the University of California
14
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.481 2004-12-31 22:00:27 pgsql Exp $
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 inside parse_analyze() 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 "nodes/makefuncs.h"
57
#include "parser/gramparse.h"
58
#include "storage/lmgr.h"
59
#include "utils/date.h"
60
#include "utils/datetime.h"
61
#include "utils/numeric.h"
64
extern List *parsetree; /* final parse result is delivered here */
66
static bool QueryIsRule = FALSE;
69
* If you need access to certain yacc-generated variables and find that
70
* they're static by default, uncomment the next line. (this is not a
73
/*#define __YYSCLASS*/
75
static Node *makeColumnRef(char *relname, List *indirection);
76
static Node *makeTypeCast(Node *arg, TypeName *typename);
77
static Node *makeStringConst(char *str, TypeName *typename);
78
static Node *makeIntConst(int val);
79
static Node *makeFloatConst(char *str);
80
static Node *makeAConst(Value *v);
81
static Node *makeRowNullTest(NullTestType test, RowExpr *row);
82
static DefElem *makeDefElem(char *name, Node *arg);
83
static A_Const *makeBoolAConst(bool state);
84
static FuncCall *makeOverlaps(List *largs, List *rargs);
85
static void check_qualified_name(List *names);
86
static List *check_func_name(List *names);
87
static List *extractArgTypes(List *parameters);
88
static SelectStmt *findLeftmostSelect(SelectStmt *node);
89
static void insertSelectOptions(SelectStmt *stmt,
90
List *sortClause, List *forUpdate,
91
Node *limitOffset, Node *limitCount);
92
static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
93
static Node *doNegate(Node *n);
94
static void doNegateFloat(Value *v);
107
DropBehavior dbehavior;
108
OnCommitAction oncommit;
109
ContainsOids withoids;
116
FunctionParameter *fun_param;
125
PrivTarget *privtarget;
128
VariableSetStmt *vsetstmt;
131
%type <node> stmt schema_stmt
132
AlterDatabaseSetStmt AlterDomainStmt AlterGroupStmt AlterOwnerStmt
133
AlterSeqStmt AlterTableStmt AlterUserStmt AlterUserSetStmt
134
AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
135
ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
136
CreateDomainStmt CreateGroupStmt CreateOpClassStmt CreatePLangStmt
137
CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
138
CreateAssertStmt CreateTrigStmt CreateUserStmt
139
CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt
140
DropGroupStmt DropOpClassStmt DropPLangStmt DropStmt
141
DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt
142
DropUserStmt DropdbStmt DropTableSpaceStmt ExplainStmt FetchStmt
143
GrantStmt IndexStmt InsertStmt ListenStmt LoadStmt
144
LockStmt NotifyStmt ExplainableStmt PreparableStmt
145
CreateFunctionStmt ReindexStmt RemoveAggrStmt
146
RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt
147
RuleActionStmt RuleActionStmtOrEmpty RuleStmt
148
SelectStmt TransactionStmt TruncateStmt
149
UnlistenStmt UpdateStmt VacuumStmt
150
VariableResetStmt VariableSetStmt VariableShowStmt
151
ViewStmt CheckPointStmt CreateConversionStmt
152
DeallocateStmt PrepareStmt ExecuteStmt
154
%type <node> select_no_parens select_with_parens select_clause
157
%type <node> alter_column_default opclass_item alter_using
158
%type <ival> add_drop
160
%type <node> alter_table_cmd alter_rel_cmd
161
%type <list> alter_table_cmds alter_rel_cmds
163
%type <dbehavior> opt_drop_behavior
165
%type <list> createdb_opt_list copy_opt_list transaction_mode_list
166
%type <defelt> createdb_opt_item copy_opt_item transaction_mode_item
168
%type <ival> opt_lock lock_type cast_context
169
%type <boolean> opt_force opt_or_replace
170
opt_grant_grant_option opt_revoke_grant_option
173
%type <boolean> like_including_defaults
175
%type <list> user_list
177
%type <list> OptGroupList
178
%type <defelt> OptGroupElem
180
%type <list> OptUserList
181
%type <defelt> OptUserElem
183
%type <str> OptSchemaName
184
%type <list> OptSchemaEltList
186
%type <boolean> TriggerActionTime TriggerForSpec opt_trusted
187
%type <str> opt_lancompiler
189
%type <str> TriggerEvents
190
%type <value> TriggerFuncArg
192
%type <str> relation_name copy_file_name
193
database_name access_method_clause access_method attr_name
194
index_name name function_name file_name
196
%type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
197
opt_class opt_validator
199
%type <range> qualified_name OptConstrFromTable
201
%type <str> all_Op MathOp SpecialRuleRelation
203
%type <str> iso_level opt_encoding
205
%type <list> grantee_list
206
%type <ival> privilege
207
%type <list> privileges privilege_list
208
%type <privtarget> privilege_target
209
%type <node> function_with_argtypes
210
%type <list> function_with_argtypes_list
211
%type <chr> TriggerOneEvent
213
%type <list> stmtblock stmtmulti
214
OptTableElementList TableElementList OptInherit definition
215
opt_distinct opt_definition func_args
216
func_args_list func_as createfunc_opt_list
217
oper_argtypes RuleActionList RuleActionMulti
218
opt_column_list columnList opt_name_list
219
sort_clause opt_sort_clause sortby_list index_params
220
name_list from_clause from_list opt_array_bounds
221
qualified_name_list any_name any_name_list
222
any_operator expr_list attrs
223
target_list update_target_list insert_column_list
224
insert_target_list def_list indirection opt_indirection
225
group_clause TriggerFuncArgs select_limit
226
opt_select_limit opclass_item_list
227
transaction_mode_list_or_empty
229
prep_type_clause prep_type_list
232
%type <range> into_clause OptTempTableName
234
%type <defelt> createfunc_opt_item
235
%type <fun_param> func_arg
236
%type <typnam> func_return func_type aggr_argtype
238
%type <boolean> arg_class TriggerForType OptTemp
239
%type <oncommit> OnCommitOption
240
%type <withoids> OptWithOids WithOidsAs
242
%type <list> for_update_clause opt_for_update_clause update_list
243
%type <boolean> opt_all
245
%type <node> join_outer join_qual
246
%type <jtype> join_type
248
%type <list> extract_list overlay_list position_list
249
%type <list> substr_list trim_list
250
%type <ival> opt_interval
251
%type <node> overlay_placing substr_from substr_for
253
%type <boolean> opt_instead opt_analyze
254
%type <boolean> index_opt_unique opt_verbose opt_full
255
%type <boolean> opt_freeze opt_default opt_recheck
256
%type <defelt> opt_binary opt_oids copy_delimiter
258
%type <boolean> copy_from opt_hold
260
%type <ival> fetch_count opt_column event cursor_options
261
%type <objtype> reindex_type drop_type comment_type
263
%type <node> fetch_direction select_limit_value select_offset_value
265
%type <list> OptSeqList
266
%type <defelt> OptSeqElem
268
%type <istmt> insert_rest
270
%type <vsetstmt> set_rest
272
%type <node> TableElement ConstraintElem TableFuncElement
273
%type <node> columnDef
274
%type <defelt> def_elem
275
%type <node> def_arg columnElem where_clause
276
a_expr b_expr c_expr func_expr AexprConst indirection_el
277
columnref in_expr having_clause func_table array_expr
278
%type <list> row type_list array_expr_list
279
%type <node> case_expr case_arg when_clause case_default
280
%type <list> when_clause_list
281
%type <ival> sub_type
282
%type <list> OptCreateAs CreateAsList
283
%type <node> CreateAsElement
284
%type <value> NumericOnly FloatOnly IntegerOnly
285
%type <alias> alias_clause
286
%type <sortby> sortby
287
%type <ielem> index_elem
288
%type <node> table_ref
289
%type <jexpr> joined_table
290
%type <range> relation_expr
291
%type <target> target_el insert_target_el update_target_el insert_column_item
293
%type <typnam> Typename SimpleTypename ConstTypename
294
GenericType Numeric opt_float
295
Character ConstCharacter
296
CharacterWithLength CharacterWithoutLength
297
ConstDatetime ConstInterval
298
Bit ConstBit BitWithLength BitWithoutLength
299
%type <str> character
300
%type <str> extract_arg
301
%type <str> opt_charset
302
%type <ival> opt_numeric opt_decimal
303
%type <boolean> opt_varying opt_timezone
306
%type <str> Sconst comment_text
307
%type <str> UserId opt_boolean ColId_or_Sconst
308
%type <list> var_list var_list_or_default
309
%type <str> ColId ColLabel var_name type_name param_name
310
%type <node> var_value zone_value
312
%type <keyword> unreserved_keyword func_name_keyword
313
%type <keyword> col_name_keyword reserved_keyword
315
%type <node> TableConstraint TableLikeClause
316
%type <list> ColQualList
317
%type <node> ColConstraint ColConstraintElem ConstraintAttr
318
%type <ival> key_actions key_delete key_match key_update key_action
319
%type <ival> ConstraintAttributeSpec ConstraintDeferrabilitySpec
322
%type <list> constraints_set_list
323
%type <boolean> constraints_set_mode
324
%type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
328
* If you make any token changes, update the keyword table in
329
* parser/keywords.c and add new keywords to the appropriate one of
330
* the reserved-or-not-so-reserved keyword lists, below.
333
/* ordinary key words in alphabetical order */
334
%token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD AFTER
335
AGGREGATE ALL ALSO ALTER ANALYSE ANALYZE AND ANY ARRAY AS ASC
336
ASSERTION ASSIGNMENT AT AUTHORIZATION
338
BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
341
CACHE CALLED CASCADE CASE CAST CHAIN CHAR_P
342
CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
343
CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT
344
COMMITTED CONSTRAINT CONSTRAINTS CONVERSION_P CONVERT COPY CREATE CREATEDB
345
CREATEUSER CROSS CSV CURRENT_DATE CURRENT_TIME
346
CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
348
DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
349
DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS
350
DESC DISTINCT DO DOMAIN_P DOUBLE_P DROP
352
EACH ELSE ENCODING ENCRYPTED END_P ESCAPE EXCEPT EXCLUDING
353
EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
355
FALSE_P FETCH FIRST_P FLOAT_P FOR FORCE FOREIGN FORWARD
356
FREEZE FROM FULL FUNCTION
360
HANDLER HAVING HOLD HOUR_P
362
ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P INCLUDING INCREMENT
363
INDEX INHERITS INITIALLY INNER_P INOUT INPUT_P
364
INSENSITIVE INSERT INSTEAD INT_P INTEGER INTERSECT
365
INTERVAL INTO INVOKER IS ISNULL ISOLATION
371
LANCOMPILER LANGUAGE LARGE_P LAST_P LEADING LEFT LEVEL LIKE LIMIT
372
LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP LOCATION
375
MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
377
NAMES NATIONAL NATURAL NCHAR NEW NEXT NO NOCREATEDB
378
NOCREATEUSER NONE NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P
381
OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OR
382
ORDER OUT_P OUTER_P OVERLAPS OVERLAY OWNER
384
PARTIAL PASSWORD PLACING POSITION
385
PRECISION PRESERVE PREPARE PRIMARY
386
PRIOR PRIVILEGES PROCEDURAL PROCEDURE
390
READ REAL RECHECK REFERENCES REINDEX RELATIVE_P RELEASE RENAME
391
REPEATABLE REPLACE RESET RESTART RESTRICT RETURNS REVOKE RIGHT
392
ROLLBACK ROW ROWS RULE
394
SAVEPOINT SCHEMA SCROLL SECOND_P SECURITY SELECT SEQUENCE
395
SERIALIZABLE SESSION SESSION_USER SET SETOF SHARE
396
SHOW SIMILAR SIMPLE SMALLINT SOME STABLE START STATEMENT
397
STATISTICS STDIN STDOUT STORAGE STRICT_P SUBSTRING SYSID
399
TABLE TABLESPACE TEMP TEMPLATE TEMPORARY THEN TIME TIMESTAMP
400
TO TOAST TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
401
TRUNCATE TRUSTED TYPE_P
403
UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
404
UPDATE USAGE USER USING
406
VACUUM VALID VALIDATOR VALUES VARCHAR VARYING
407
VERBOSE VIEW VOLATILE
409
WHEN WHERE WITH WITHOUT WORK WRITE
415
/* The grammar thinks these are keywords, but they are not in the keywords.c
416
* list and so can never be entered directly. The filter in parser.c
417
* creates these tokens when required.
421
/* Special token types, not actually keywords - see the "lex" file */
422
%token <str> IDENT FCONST SCONST BCONST XCONST Op
423
%token <ival> ICONST PARAM
425
/* precedence: lowest to highest */
433
%nonassoc LIKE ILIKE SIMILAR
438
%left POSTFIXOP /* dummy for postfix Op rules */
439
%left Op OPERATOR /* multi-character ops and user-defined operators */
442
%nonassoc IS NULL_P TRUE_P FALSE_P UNKNOWN /* sets precedence for IS NULL, etc */
446
/* Unary Operators */
447
%left AT ZONE /* sets precedence for AT TIME ZONE */
454
* These might seem to be low-precedence, but actually they are not part
455
* of the arithmetic hierarchy at all in their use as JOIN operators.
456
* We make them high-precedence to support their use as function names.
457
* They wouldn't be given a precedence at all, were it not that we need
458
* left-associativity among the JOIN rules themselves.
460
%left JOIN UNIONJOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
464
* Handle comment-only lines, and ;; SELECT * FROM pg_class ;;;
465
* psql already handles such cases, but other interfaces don't.
468
stmtblock: stmtmulti { parsetree = $1; }
471
/* the thrashing around here is to discard "empty" statements... */
472
stmtmulti: stmtmulti ';' stmt
474
$$ = lappend($1, $3);
505
| CreateConversionStmt
514
| CreateTableSpaceStmt
565
/*****************************************************************************
567
* Create a new Postgres DBMS user
570
*****************************************************************************/
573
CREATE USER UserId opt_with OptUserList
575
CreateUserStmt *n = makeNode(CreateUserStmt);
587
/*****************************************************************************
589
* Alter a postgresql DBMS user
592
*****************************************************************************/
595
ALTER USER UserId opt_with OptUserList
597
AlterUserStmt *n = makeNode(AlterUserStmt);
606
ALTER USER UserId SET set_rest
608
AlterUserSetStmt *n = makeNode(AlterUserSetStmt);
610
n->variable = $5->name;
614
| ALTER USER UserId VariableResetStmt
616
AlterUserSetStmt *n = makeNode(AlterUserSetStmt);
618
n->variable = ((VariableResetStmt *)$4)->name;
625
/*****************************************************************************
627
* Drop a postgresql DBMS user
629
* XXX Ideally this would have CASCADE/RESTRICT options, but since a user
630
* might own objects in multiple databases, there is presently no way to
631
* implement either cascading or restricting. Caveat DBA.
632
*****************************************************************************/
637
DropUserStmt *n = makeNode(DropUserStmt);
644
* Options for CREATE USER and ALTER USER
647
OptUserList OptUserElem { $$ = lappend($1, $2); }
648
| /* EMPTY */ { $$ = NIL; }
654
$$ = makeDefElem("password", (Node *)makeString($2));
656
| ENCRYPTED PASSWORD Sconst
658
$$ = makeDefElem("encryptedPassword", (Node *)makeString($3));
660
| UNENCRYPTED PASSWORD Sconst
662
$$ = makeDefElem("unencryptedPassword", (Node *)makeString($3));
666
$$ = makeDefElem("sysid", (Node *)makeInteger($2));
670
$$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
674
$$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
678
$$ = makeDefElem("createuser", (Node *)makeInteger(TRUE));
682
$$ = makeDefElem("createuser", (Node *)makeInteger(FALSE));
684
| IN_P GROUP_P user_list
686
$$ = makeDefElem("groupElts", (Node *)$3);
690
$$ = makeDefElem("validUntil", (Node *)makeString($3));
694
user_list: user_list ',' UserId { $$ = lappend($1, makeString($3)); }
695
| UserId { $$ = list_make1(makeString($1)); }
700
/*****************************************************************************
702
* Create a postgresql group
705
*****************************************************************************/
708
CREATE GROUP_P UserId opt_with OptGroupList
710
CreateGroupStmt *n = makeNode(CreateGroupStmt);
718
* Options for CREATE GROUP
721
OptGroupList OptGroupElem { $$ = lappend($1, $2); }
722
| /* EMPTY */ { $$ = NIL; }
728
$$ = makeDefElem("userElts", (Node *)$2);
732
$$ = makeDefElem("sysid", (Node *)makeInteger($2));
737
/*****************************************************************************
739
* Alter a postgresql group
742
*****************************************************************************/
745
ALTER GROUP_P UserId add_drop USER user_list
747
AlterGroupStmt *n = makeNode(AlterGroupStmt);
755
add_drop: ADD { $$ = +1; }
760
/*****************************************************************************
762
* Drop a postgresql group
764
* XXX see above notes about cascading DROP USER; groups have same problem.
765
*****************************************************************************/
770
DropGroupStmt *n = makeNode(DropGroupStmt);
777
/*****************************************************************************
779
* Manipulate a schema
781
*****************************************************************************/
784
CREATE SCHEMA OptSchemaName AUTHORIZATION UserId OptSchemaEltList
786
CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
787
/* One can omit the schema name or the authorization id. */
796
| CREATE SCHEMA ColId OptSchemaEltList
798
CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
799
/* ...but not both */
809
| /* EMPTY */ { $$ = NULL; }
813
OptSchemaEltList schema_stmt { $$ = lappend($1, $2); }
814
| /* EMPTY */ { $$ = NIL; }
818
* schema_stmt are the ones that can show up inside a CREATE SCHEMA
819
* statement (in addition to by themselves).
831
/*****************************************************************************
833
* Set PG internal variable
834
* SET name TO 'var_value'
835
* Include SQL92 syntax (thomas 1997-10-22):
836
* SET TIME ZONE 'var_value'
838
*****************************************************************************/
843
VariableSetStmt *n = $2;
849
VariableSetStmt *n = $3;
853
| SET SESSION set_rest
855
VariableSetStmt *n = $3;
861
set_rest: var_name TO var_list_or_default
863
VariableSetStmt *n = makeNode(VariableSetStmt);
868
| var_name '=' var_list_or_default
870
VariableSetStmt *n = makeNode(VariableSetStmt);
875
| TIME ZONE zone_value
877
VariableSetStmt *n = makeNode(VariableSetStmt);
878
n->name = "timezone";
880
n->args = list_make1($3);
883
| TRANSACTION transaction_mode_list
885
VariableSetStmt *n = makeNode(VariableSetStmt);
886
n->name = "TRANSACTION";
890
| SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
892
VariableSetStmt *n = makeNode(VariableSetStmt);
893
n->name = "SESSION CHARACTERISTICS";
899
VariableSetStmt *n = makeNode(VariableSetStmt);
900
n->name = "client_encoding";
902
n->args = list_make1(makeStringConst($2, NULL));
905
| SESSION AUTHORIZATION ColId_or_Sconst
907
VariableSetStmt *n = makeNode(VariableSetStmt);
908
n->name = "session_authorization";
909
n->args = list_make1(makeStringConst($3, NULL));
912
| SESSION AUTHORIZATION DEFAULT
914
VariableSetStmt *n = makeNode(VariableSetStmt);
915
n->name = "session_authorization";
925
int qLen = strlen($1);
926
char* qualName = palloc(qLen + strlen($3) + 2);
927
strcpy(qualName, $1);
928
qualName[qLen] = '.';
929
strcpy(qualName + qLen + 1, $3);
935
var_list { $$ = $1; }
936
| DEFAULT { $$ = NIL; }
939
var_list: var_value { $$ = list_make1($1); }
940
| var_list ',' var_value { $$ = lappend($1, $3); }
943
var_value: opt_boolean
944
{ $$ = makeStringConst($1, NULL); }
946
{ $$ = makeStringConst($1, NULL); }
948
{ $$ = makeAConst($1); }
951
iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
952
| READ COMMITTED { $$ = "read committed"; }
953
| REPEATABLE READ { $$ = "repeatable read"; }
954
| SERIALIZABLE { $$ = "serializable"; }
958
TRUE_P { $$ = "true"; }
959
| FALSE_P { $$ = "false"; }
961
| OFF { $$ = "off"; }
964
/* Timezone values can be:
965
* - a string such as 'pst8pdt'
966
* - an identifier such as "pst8pdt"
967
* - an integer or floating point number
968
* - a time interval per SQL99
969
* ColId gives reduce/reduce errors against ConstInterval and LOCAL,
970
* so use IDENT and reject anything which is a reserved word.
975
$$ = makeStringConst($1, NULL);
979
$$ = makeStringConst($1, NULL);
981
| ConstInterval Sconst opt_interval
983
A_Const *n = (A_Const *) makeStringConst($2, $1);
984
if ($3 != INTERVAL_FULL_RANGE)
986
if (($3 & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
988
(errcode(ERRCODE_SYNTAX_ERROR),
989
errmsg("time zone interval must be HOUR or HOUR TO MINUTE")));
990
n->typename->typmod = INTERVAL_TYPMOD(INTERVAL_FULL_PRECISION, $3);
994
| ConstInterval '(' Iconst ')' Sconst opt_interval
996
A_Const *n = (A_Const *) makeStringConst($5, $1);
999
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1000
errmsg("INTERVAL(%d) precision must not be negative",
1002
if ($3 > MAX_INTERVAL_PRECISION)
1005
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1006
errmsg("INTERVAL(%d) precision reduced to maximum allowed, %d",
1007
$3, MAX_INTERVAL_PRECISION)));
1008
$3 = MAX_INTERVAL_PRECISION;
1011
if (($6 != INTERVAL_FULL_RANGE)
1012
&& (($6 & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0))
1014
(errcode(ERRCODE_SYNTAX_ERROR),
1015
errmsg("time zone interval must be HOUR or HOUR TO MINUTE")));
1017
n->typename->typmod = INTERVAL_TYPMOD($3, $6);
1021
| NumericOnly { $$ = makeAConst($1); }
1022
| DEFAULT { $$ = NULL; }
1023
| LOCAL { $$ = NULL; }
1028
| DEFAULT { $$ = NULL; }
1029
| /*EMPTY*/ { $$ = NULL; }
1034
| SCONST { $$ = $1; }
1041
VariableShowStmt *n = makeNode(VariableShowStmt);
1047
VariableShowStmt *n = makeNode(VariableShowStmt);
1048
n->name = "timezone";
1051
| SHOW TRANSACTION ISOLATION LEVEL
1053
VariableShowStmt *n = makeNode(VariableShowStmt);
1054
n->name = "transaction_isolation";
1057
| SHOW SESSION AUTHORIZATION
1059
VariableShowStmt *n = makeNode(VariableShowStmt);
1060
n->name = "session_authorization";
1065
VariableShowStmt *n = makeNode(VariableShowStmt);
1074
VariableResetStmt *n = makeNode(VariableResetStmt);
1080
VariableResetStmt *n = makeNode(VariableResetStmt);
1081
n->name = "timezone";
1084
| RESET TRANSACTION ISOLATION LEVEL
1086
VariableResetStmt *n = makeNode(VariableResetStmt);
1087
n->name = "transaction_isolation";
1090
| RESET SESSION AUTHORIZATION
1092
VariableResetStmt *n = makeNode(VariableResetStmt);
1093
n->name = "session_authorization";
1098
VariableResetStmt *n = makeNode(VariableResetStmt);
1106
SET CONSTRAINTS constraints_set_list constraints_set_mode
1108
ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
1109
n->constraints = $3;
1115
constraints_set_list:
1117
| name_list { $$ = $1; }
1120
constraints_set_mode:
1121
DEFERRED { $$ = TRUE; }
1122
| IMMEDIATE { $$ = FALSE; }
1127
* Checkpoint statement
1132
CheckPointStmt *n = makeNode(CheckPointStmt);
1138
/*****************************************************************************
1140
* ALTER [ TABLE | INDEX ] variations
1142
*****************************************************************************/
1145
ALTER TABLE relation_expr alter_table_cmds
1147
AlterTableStmt *n = makeNode(AlterTableStmt);
1150
n->relkind = OBJECT_TABLE;
1153
| ALTER INDEX relation_expr alter_rel_cmds
1155
AlterTableStmt *n = makeNode(AlterTableStmt);
1158
n->relkind = OBJECT_INDEX;
1164
alter_table_cmd { $$ = list_make1($1); }
1165
| alter_table_cmds ',' alter_table_cmd { $$ = lappend($1, $3); }
1168
/* Subcommands that are for ALTER TABLE only */
1170
/* ALTER TABLE <relation> ADD [COLUMN] <coldef> */
1171
ADD opt_column columnDef
1173
AlterTableCmd *n = makeNode(AlterTableCmd);
1174
n->subtype = AT_AddColumn;
1178
/* ALTER TABLE <relation> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
1179
| ALTER opt_column ColId alter_column_default
1181
AlterTableCmd *n = makeNode(AlterTableCmd);
1182
n->subtype = AT_ColumnDefault;
1187
/* ALTER TABLE <relation> ALTER [COLUMN] <colname> DROP NOT NULL */
1188
| ALTER opt_column ColId DROP NOT NULL_P
1190
AlterTableCmd *n = makeNode(AlterTableCmd);
1191
n->subtype = AT_DropNotNull;
1195
/* ALTER TABLE <relation> ALTER [COLUMN] <colname> SET NOT NULL */
1196
| ALTER opt_column ColId SET NOT NULL_P
1198
AlterTableCmd *n = makeNode(AlterTableCmd);
1199
n->subtype = AT_SetNotNull;
1203
/* ALTER TABLE <relation> ALTER [COLUMN] <colname> SET STATISTICS <IntegerOnly> */
1204
| ALTER opt_column ColId SET STATISTICS IntegerOnly
1206
AlterTableCmd *n = makeNode(AlterTableCmd);
1207
n->subtype = AT_SetStatistics;
1209
n->def = (Node *) $6;
1212
/* ALTER TABLE <relation> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
1213
| ALTER opt_column ColId SET STORAGE ColId
1215
AlterTableCmd *n = makeNode(AlterTableCmd);
1216
n->subtype = AT_SetStorage;
1218
n->def = (Node *) makeString($6);
1221
/* ALTER TABLE <relation> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
1222
| DROP opt_column ColId opt_drop_behavior
1224
AlterTableCmd *n = makeNode(AlterTableCmd);
1225
n->subtype = AT_DropColumn;
1231
* ALTER TABLE <relation> ALTER [COLUMN] <colname> TYPE <typename>
1232
* [ USING <expression> ]
1234
| ALTER opt_column ColId TYPE_P Typename alter_using
1236
AlterTableCmd *n = makeNode(AlterTableCmd);
1237
n->subtype = AT_AlterColumnType;
1239
n->def = (Node *) $5;
1243
/* ALTER TABLE <relation> ADD CONSTRAINT ... */
1244
| ADD TableConstraint
1246
AlterTableCmd *n = makeNode(AlterTableCmd);
1247
n->subtype = AT_AddConstraint;
1251
/* ALTER TABLE <relation> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
1252
| DROP CONSTRAINT name opt_drop_behavior
1254
AlterTableCmd *n = makeNode(AlterTableCmd);
1255
n->subtype = AT_DropConstraint;
1260
/* ALTER TABLE <relation> SET WITHOUT OIDS */
1263
AlterTableCmd *n = makeNode(AlterTableCmd);
1264
n->subtype = AT_DropOids;
1267
/* ALTER TABLE <name> CREATE TOAST TABLE -- ONLY */
1268
| CREATE TOAST TABLE
1270
AlterTableCmd *n = makeNode(AlterTableCmd);
1271
n->subtype = AT_ToastTable;
1274
/* ALTER TABLE <name> CLUSTER ON <indexname> */
1277
AlterTableCmd *n = makeNode(AlterTableCmd);
1278
n->subtype = AT_ClusterOn;
1282
/* ALTER TABLE <name> SET WITHOUT CLUSTER */
1283
| SET WITHOUT CLUSTER
1285
AlterTableCmd *n = makeNode(AlterTableCmd);
1286
n->subtype = AT_DropCluster;
1297
alter_rel_cmd { $$ = list_make1($1); }
1298
| alter_rel_cmds ',' alter_rel_cmd { $$ = lappend($1, $3); }
1301
/* Subcommands that are for ALTER TABLE or ALTER INDEX */
1303
/* ALTER [TABLE|INDEX] <name> OWNER TO UserId */
1306
AlterTableCmd *n = makeNode(AlterTableCmd);
1307
n->subtype = AT_ChangeOwner;
1311
/* ALTER [TABLE|INDEX] <name> SET TABLESPACE <tablespacename> */
1312
| SET TABLESPACE name
1314
AlterTableCmd *n = makeNode(AlterTableCmd);
1315
n->subtype = AT_SetTableSpace;
1321
alter_column_default:
1324
/* Treat SET DEFAULT NULL the same as DROP DEFAULT */
1325
if (exprIsNullConstant($3))
1330
| DROP DEFAULT { $$ = NULL; }
1334
CASCADE { $$ = DROP_CASCADE; }
1335
| RESTRICT { $$ = DROP_RESTRICT; }
1336
| /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ }
1340
USING a_expr { $$ = $2; }
1341
| /* EMPTY */ { $$ = NULL; }
1346
/*****************************************************************************
1349
* close <portalname>
1351
*****************************************************************************/
1356
ClosePortalStmt *n = makeNode(ClosePortalStmt);
1363
/*****************************************************************************
1366
* COPY <relname> ['(' columnList ')'] FROM/TO [WITH options]
1368
* BINARY, OIDS, and DELIMITERS kept in old locations
1369
* for backward compatibility. 2002-06-18
1371
*****************************************************************************/
1373
CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids
1374
copy_from copy_file_name copy_delimiter opt_with copy_opt_list
1376
CopyStmt *n = makeNode(CopyStmt);
1383
/* Concatenate user-supplied flags */
1385
n->options = lappend(n->options, $2);
1387
n->options = lappend(n->options, $5);
1389
n->options = lappend(n->options, $8);
1391
n->options = list_concat(n->options, $10);
1398
| TO { $$ = FALSE; }
1402
* copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
1403
* used depends on the direction. (It really doesn't make sense to copy from
1404
* stdout. We silently correct the "typo". - AY 9/94
1408
| STDIN { $$ = NULL; }
1409
| STDOUT { $$ = NULL; }
1415
copy_opt_list copy_opt_item { $$ = lappend($1, $2); }
1416
| /* EMPTY */ { $$ = NIL; }
1423
$$ = makeDefElem("binary", (Node *)makeInteger(TRUE));
1427
$$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
1429
| DELIMITER opt_as Sconst
1431
$$ = makeDefElem("delimiter", (Node *)makeString($3));
1433
| NULL_P opt_as Sconst
1435
$$ = makeDefElem("null", (Node *)makeString($3));
1439
$$ = makeDefElem("csv", (Node *)makeInteger(TRUE));
1441
| QUOTE opt_as Sconst
1443
$$ = makeDefElem("quote", (Node *)makeString($3));
1445
| ESCAPE opt_as Sconst
1447
$$ = makeDefElem("escape", (Node *)makeString($3));
1449
| FORCE QUOTE columnList
1451
$$ = makeDefElem("force_quote", (Node *)$3);
1453
| FORCE NOT NULL_P columnList
1455
$$ = makeDefElem("force_notnull", (Node *)$4);
1459
/* The following exist for backward compatibility */
1464
$$ = makeDefElem("binary", (Node *)makeInteger(TRUE));
1466
| /*EMPTY*/ { $$ = NULL; }
1472
$$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
1474
| /*EMPTY*/ { $$ = NULL; }
1478
/* USING DELIMITERS kept for backward compatibility. 2002-06-15 */
1479
opt_using DELIMITERS Sconst
1481
$$ = makeDefElem("delimiter", (Node *)makeString($3));
1483
| /*EMPTY*/ { $$ = NULL; }
1492
/*****************************************************************************
1495
* CREATE TABLE relname
1497
*****************************************************************************/
1499
CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
1500
OptInherit OptWithOids OnCommitOption OptTableSpace
1502
CreateStmt *n = makeNode(CreateStmt);
1506
n->inhRelations = $8;
1507
n->constraints = NIL;
1510
n->tablespacename = $11;
1513
| CREATE OptTemp TABLE qualified_name OF qualified_name
1514
'(' OptTableElementList ')' OptWithOids OnCommitOption OptTableSpace
1516
/* SQL99 CREATE TABLE OF <UDT> (cols) seems to be satisfied
1517
* by our inheritance capabilities. Let's try it...
1519
CreateStmt *n = makeNode(CreateStmt);
1523
n->inhRelations = list_make1($6);
1524
n->constraints = NIL;
1527
n->tablespacename = $12;
1533
* Redundancy here is needed to avoid shift/reduce conflicts,
1534
* since TEMP is not a reserved word. See also OptTempTableName.
1536
* NOTE: we accept both GLOBAL and LOCAL options; since we have no modules
1537
* the LOCAL keyword is really meaningless.
1539
OptTemp: TEMPORARY { $$ = TRUE; }
1540
| TEMP { $$ = TRUE; }
1541
| LOCAL TEMPORARY { $$ = TRUE; }
1542
| LOCAL TEMP { $$ = TRUE; }
1543
| GLOBAL TEMPORARY { $$ = TRUE; }
1544
| GLOBAL TEMP { $$ = TRUE; }
1545
| /*EMPTY*/ { $$ = FALSE; }
1548
OptTableElementList:
1549
TableElementList { $$ = $1; }
1550
| /*EMPTY*/ { $$ = NIL; }
1556
$$ = list_make1($1);
1558
| TableElementList ',' TableElement
1560
$$ = lappend($1, $3);
1565
columnDef { $$ = $1; }
1566
| TableLikeClause { $$ = $1; }
1567
| TableConstraint { $$ = $1; }
1570
columnDef: ColId Typename ColQualList
1572
ColumnDef *n = makeNode(ColumnDef);
1575
n->constraints = $3;
1582
ColQualList ColConstraint { $$ = lappend($1, $2); }
1583
| /*EMPTY*/ { $$ = NIL; }
1587
CONSTRAINT name ColConstraintElem
1589
switch (nodeTag($3))
1593
Constraint *n = (Constraint *)$3;
1597
case T_FkConstraint:
1599
FkConstraint *n = (FkConstraint *)$3;
1600
n->constr_name = $2;
1608
| ColConstraintElem { $$ = $1; }
1609
| ConstraintAttr { $$ = $1; }
1612
/* DEFAULT NULL is already the default for Postgres.
1613
* But define it here and carry it forward into the system
1614
* to make it explicit.
1615
* - thomas 1998-09-13
1617
* WITH NULL and NULL are not SQL92-standard syntax elements,
1618
* so leave them out. Use DEFAULT NULL to explicitly indicate
1619
* that a column may have that value. WITH NULL leads to
1620
* shift/reduce conflicts with WITH TIME ZONE anyway.
1621
* - thomas 1999-01-08
1623
* DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
1624
* conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
1625
* or be part of a_expr NOT LIKE or similar constructs).
1630
Constraint *n = makeNode(Constraint);
1631
n->contype = CONSTR_NOTNULL;
1634
n->cooked_expr = NULL;
1636
n->indexspace = NULL;
1641
Constraint *n = makeNode(Constraint);
1642
n->contype = CONSTR_NULL;
1645
n->cooked_expr = NULL;
1647
n->indexspace = NULL;
1650
| UNIQUE OptConsTableSpace
1652
Constraint *n = makeNode(Constraint);
1653
n->contype = CONSTR_UNIQUE;
1656
n->cooked_expr = NULL;
1661
| PRIMARY KEY OptConsTableSpace
1663
Constraint *n = makeNode(Constraint);
1664
n->contype = CONSTR_PRIMARY;
1667
n->cooked_expr = NULL;
1672
| CHECK '(' a_expr ')'
1674
Constraint *n = makeNode(Constraint);
1675
n->contype = CONSTR_CHECK;
1678
n->cooked_expr = NULL;
1680
n->indexspace = NULL;
1685
Constraint *n = makeNode(Constraint);
1686
n->contype = CONSTR_DEFAULT;
1688
if (exprIsNullConstant($2))
1690
/* DEFAULT NULL should be reported as empty expr */
1697
n->cooked_expr = NULL;
1699
n->indexspace = NULL;
1702
| REFERENCES qualified_name opt_column_list key_match key_actions
1704
FkConstraint *n = makeNode(FkConstraint);
1705
n->constr_name = NULL;
1709
n->fk_matchtype = $4;
1710
n->fk_upd_action = (char) ($5 >> 8);
1711
n->fk_del_action = (char) ($5 & 0xFF);
1712
n->deferrable = FALSE;
1713
n->initdeferred = FALSE;
1719
* ConstraintAttr represents constraint attributes, which we parse as if
1720
* they were independent constraint clauses, in order to avoid shift/reduce
1721
* conflicts (since NOT might start either an independent NOT NULL clause
1722
* or an attribute). analyze.c is responsible for attaching the attribute
1723
* information to the preceding "real" constraint node, and for complaining
1724
* if attribute clauses appear in the wrong place or wrong combinations.
1726
* See also ConstraintAttributeSpec, which can be used in places where
1727
* there is no parsing conflict.
1732
Constraint *n = makeNode(Constraint);
1733
n->contype = CONSTR_ATTR_DEFERRABLE;
1738
Constraint *n = makeNode(Constraint);
1739
n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
1742
| INITIALLY DEFERRED
1744
Constraint *n = makeNode(Constraint);
1745
n->contype = CONSTR_ATTR_DEFERRED;
1748
| INITIALLY IMMEDIATE
1750
Constraint *n = makeNode(Constraint);
1751
n->contype = CONSTR_ATTR_IMMEDIATE;
1758
* SQL99 supports wholesale borrowing of a table definition via the LIKE clause.
1759
* This seems to be a poor man's inheritance capability, with the resulting
1760
* tables completely decoupled except for the original commonality in definitions.
1762
* This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension
1763
* which is a part of SQL 200N
1766
LIKE qualified_name like_including_defaults
1768
InhRelation *n = makeNode(InhRelation);
1770
n->including_defaults = $3;
1776
like_including_defaults:
1777
INCLUDING DEFAULTS { $$ = true; }
1778
| EXCLUDING DEFAULTS { $$ = false; }
1779
| /* EMPTY */ { $$ = false; }
1783
/* ConstraintElem specifies constraint syntax which is not embedded into
1784
* a column definition. ColConstraintElem specifies the embedded form.
1785
* - thomas 1997-12-03
1788
CONSTRAINT name ConstraintElem
1790
switch (nodeTag($3))
1794
Constraint *n = (Constraint *)$3;
1798
case T_FkConstraint:
1800
FkConstraint *n = (FkConstraint *)$3;
1801
n->constr_name = $2;
1809
| ConstraintElem { $$ = $1; }
1813
CHECK '(' a_expr ')'
1815
Constraint *n = makeNode(Constraint);
1816
n->contype = CONSTR_CHECK;
1819
n->cooked_expr = NULL;
1820
n->indexspace = NULL;
1823
| UNIQUE '(' columnList ')' OptConsTableSpace
1825
Constraint *n = makeNode(Constraint);
1826
n->contype = CONSTR_UNIQUE;
1829
n->cooked_expr = NULL;
1834
| PRIMARY KEY '(' columnList ')' OptConsTableSpace
1836
Constraint *n = makeNode(Constraint);
1837
n->contype = CONSTR_PRIMARY;
1840
n->cooked_expr = NULL;
1845
| FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
1846
opt_column_list key_match key_actions ConstraintAttributeSpec
1848
FkConstraint *n = makeNode(FkConstraint);
1849
n->constr_name = NULL;
1853
n->fk_matchtype = $9;
1854
n->fk_upd_action = (char) ($10 >> 8);
1855
n->fk_del_action = (char) ($10 & 0xFF);
1856
n->deferrable = ($11 & 1) != 0;
1857
n->initdeferred = ($11 & 2) != 0;
1863
'(' columnList ')' { $$ = $2; }
1864
| /*EMPTY*/ { $$ = NIL; }
1868
columnElem { $$ = list_make1($1); }
1869
| columnList ',' columnElem { $$ = lappend($1, $3); }
1874
$$ = (Node *) makeString($1);
1878
key_match: MATCH FULL
1880
$$ = FKCONSTR_MATCH_FULL;
1885
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1886
errmsg("MATCH PARTIAL not yet implemented")));
1887
$$ = FKCONSTR_MATCH_PARTIAL;
1891
$$ = FKCONSTR_MATCH_UNSPECIFIED;
1895
$$ = FKCONSTR_MATCH_UNSPECIFIED;
1900
* We combine the update and delete actions into one value temporarily
1901
* for simplicity of parsing, and then break them down again in the
1902
* calling production. update is in the left 8 bits, delete in the right.
1903
* Note that NOACTION is the default.
1907
{ $$ = ($1 << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
1909
{ $$ = (FKCONSTR_ACTION_NOACTION << 8) | ($1 & 0xFF); }
1910
| key_update key_delete
1911
{ $$ = ($1 << 8) | ($2 & 0xFF); }
1912
| key_delete key_update
1913
{ $$ = ($2 << 8) | ($1 & 0xFF); }
1915
{ $$ = (FKCONSTR_ACTION_NOACTION << 8) | (FKCONSTR_ACTION_NOACTION & 0xFF); }
1918
key_update: ON UPDATE key_action { $$ = $3; }
1921
key_delete: ON DELETE_P key_action { $$ = $3; }
1925
NO ACTION { $$ = FKCONSTR_ACTION_NOACTION; }
1926
| RESTRICT { $$ = FKCONSTR_ACTION_RESTRICT; }
1927
| CASCADE { $$ = FKCONSTR_ACTION_CASCADE; }
1928
| SET NULL_P { $$ = FKCONSTR_ACTION_SETNULL; }
1929
| SET DEFAULT { $$ = FKCONSTR_ACTION_SETDEFAULT; }
1932
OptInherit: INHERITS '(' qualified_name_list ')' { $$ = $3; }
1933
| /*EMPTY*/ { $$ = NIL; }
1937
WITH OIDS { $$ = MUST_HAVE_OIDS; }
1938
| WITHOUT OIDS { $$ = MUST_NOT_HAVE_OIDS; }
1939
| /*EMPTY*/ { $$ = DEFAULT_OIDS; }
1942
OnCommitOption: ON COMMIT DROP { $$ = ONCOMMIT_DROP; }
1943
| ON COMMIT DELETE_P ROWS { $$ = ONCOMMIT_DELETE_ROWS; }
1944
| ON COMMIT PRESERVE ROWS { $$ = ONCOMMIT_PRESERVE_ROWS; }
1945
| /*EMPTY*/ { $$ = ONCOMMIT_NOOP; }
1948
OptTableSpace: TABLESPACE name { $$ = $2; }
1949
| /*EMPTY*/ { $$ = NULL; }
1952
OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
1953
| /*EMPTY*/ { $$ = NULL; }
1958
* Note: CREATE TABLE ... AS SELECT ... is just another spelling for
1963
CREATE OptTemp TABLE qualified_name OptCreateAs WithOidsAs SelectStmt
1966
* When the SelectStmt is a set-operation tree, we must
1967
* stuff the INTO information into the leftmost component
1968
* Select, because that's where analyze.c will expect
1969
* to find it. Similarly, the output column names must
1970
* be attached to that Select's target list.
1972
SelectStmt *n = findLeftmostSelect((SelectStmt *) $7);
1973
if (n->into != NULL)
1975
(errcode(ERRCODE_SYNTAX_ERROR),
1976
errmsg("CREATE TABLE AS may not specify INTO")));
1979
n->intoColNames = $5;
1980
n->intoHasOids = $6;
1986
* To avoid a shift/reduce conflict in CreateAsStmt, we need to
1987
* include the 'AS' terminal in the parsing of WITH/WITHOUT
1988
* OIDS. Unfortunately that means this production is effectively a
1989
* duplicate of OptWithOids.
1992
WITH OIDS AS { $$ = MUST_HAVE_OIDS; }
1993
| WITHOUT OIDS AS { $$ = MUST_NOT_HAVE_OIDS; }
1994
| AS { $$ = DEFAULT_OIDS; }
1998
'(' CreateAsList ')' { $$ = $2; }
1999
| /*EMPTY*/ { $$ = NIL; }
2003
CreateAsElement { $$ = list_make1($1); }
2004
| CreateAsList ',' CreateAsElement { $$ = lappend($1, $3); }
2010
ColumnDef *n = makeNode(ColumnDef);
2015
n->is_not_null = false;
2016
n->raw_default = NULL;
2017
n->cooked_default = NULL;
2018
n->constraints = NIL;
2025
/*****************************************************************************
2028
* CREATE SEQUENCE seqname
2029
* ALTER SEQUENCE seqname
2031
*****************************************************************************/
2034
CREATE OptTemp SEQUENCE qualified_name OptSeqList
2036
CreateSeqStmt *n = makeNode(CreateSeqStmt);
2045
ALTER SEQUENCE qualified_name OptSeqList
2047
AlterSeqStmt *n = makeNode(AlterSeqStmt);
2054
OptSeqList: OptSeqList OptSeqElem { $$ = lappend($1, $2); }
2055
| /*EMPTY*/ { $$ = NIL; }
2058
OptSeqElem: CACHE NumericOnly
2060
$$ = makeDefElem("cache", (Node *)$2);
2064
$$ = makeDefElem("cycle", (Node *)makeInteger(TRUE));
2068
$$ = makeDefElem("cycle", (Node *)makeInteger(FALSE));
2070
| INCREMENT opt_by NumericOnly
2072
$$ = makeDefElem("increment", (Node *)$3);
2074
| MAXVALUE NumericOnly
2076
$$ = makeDefElem("maxvalue", (Node *)$2);
2078
| MINVALUE NumericOnly
2080
$$ = makeDefElem("minvalue", (Node *)$2);
2084
$$ = makeDefElem("maxvalue", NULL);
2088
$$ = makeDefElem("minvalue", NULL);
2090
| START opt_with NumericOnly
2092
$$ = makeDefElem("start", (Node *)$3);
2094
| RESTART opt_with NumericOnly
2096
$$ = makeDefElem("restart", (Node *)$3);
2105
FloatOnly { $$ = $1; }
2106
| IntegerOnly { $$ = $1; }
2109
FloatOnly: FCONST { $$ = makeFloat($1); }
2120
$$ = makeInteger($1);
2124
$$ = makeInteger($2);
2125
$$->val.ival = - $$->val.ival;
2129
/*****************************************************************************
2132
* CREATE PROCEDURAL LANGUAGE ...
2133
* DROP PROCEDURAL LANGUAGE ...
2135
*****************************************************************************/
2138
CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2139
HANDLER handler_name opt_validator opt_lancompiler
2141
CreatePLangStmt *n = makeNode(CreatePLangStmt);
2144
n->plvalidator = $8;
2151
TRUSTED { $$ = TRUE; }
2152
| /*EMPTY*/ { $$ = FALSE; }
2155
/* This ought to be just func_name, but that causes reduce/reduce conflicts
2156
* (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
2157
* Work around by using simple names, instead.
2160
name { $$ = list_make1(makeString($1)); }
2161
| name attrs { $$ = lcons(makeString($1), $2); }
2165
LANCOMPILER Sconst { $$ = $2; }
2166
| /*EMPTY*/ { $$ = ""; }
2170
VALIDATOR handler_name { $$ = $2; }
2171
| /*EMPTY*/ { $$ = NULL; }
2175
DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
2177
DropPLangStmt *n = makeNode(DropPLangStmt);
2189
/*****************************************************************************
2192
* CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
2194
*****************************************************************************/
2196
CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst
2198
CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
2199
n->tablespacename = $3;
2206
OptTableSpaceOwner: OWNER name { $$ = $2; }
2207
| /*EMPTY */ { $$ = NULL; }
2210
/*****************************************************************************
2213
* DROP TABLESPACE <tablespace>
2215
* No need for drop behaviour as we cannot implement dependencies for
2216
* objects in other databases; we can only support RESTRICT.
2218
****************************************************************************/
2220
DropTableSpaceStmt: DROP TABLESPACE name
2222
DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
2223
n->tablespacename = $3;
2228
/*****************************************************************************
2231
* CREATE TRIGGER ...
2234
*****************************************************************************/
2237
CREATE TRIGGER name TriggerActionTime TriggerEvents ON
2238
qualified_name TriggerForSpec EXECUTE PROCEDURE
2239
func_name '(' TriggerFuncArgs ')'
2241
CreateTrigStmt *n = makeNode(CreateTrigStmt);
2248
memcpy(n->actions, $5, 4);
2249
n->isconstraint = FALSE;
2250
n->deferrable = FALSE;
2251
n->initdeferred = FALSE;
2252
n->constrrel = NULL;
2255
| CREATE CONSTRAINT TRIGGER name AFTER TriggerEvents ON
2256
qualified_name OptConstrFromTable
2257
ConstraintAttributeSpec
2258
FOR EACH ROW EXECUTE PROCEDURE
2259
func_name '(' TriggerFuncArgs ')'
2261
CreateTrigStmt *n = makeNode(CreateTrigStmt);
2268
memcpy(n->actions, $6, 4);
2269
n->isconstraint = TRUE;
2270
n->deferrable = ($10 & 1) != 0;
2271
n->initdeferred = ($10 & 2) != 0;
2279
BEFORE { $$ = TRUE; }
2280
| AFTER { $$ = FALSE; }
2286
char *e = palloc(4);
2287
e[0] = $1; e[1] = '\0';
2290
| TriggerOneEvent OR TriggerOneEvent
2292
char *e = palloc(4);
2293
e[0] = $1; e[1] = $3; e[2] = '\0';
2296
| TriggerOneEvent OR TriggerOneEvent OR TriggerOneEvent
2298
char *e = palloc(4);
2299
e[0] = $1; e[1] = $3; e[2] = $5; e[3] = '\0';
2305
INSERT { $$ = 'i'; }
2306
| DELETE_P { $$ = 'd'; }
2307
| UPDATE { $$ = 'u'; }
2311
FOR TriggerForOpt TriggerForType
2318
* If ROW/STATEMENT not specified, default to
2319
* STATEMENT, per SQL
2332
| STATEMENT { $$ = FALSE; }
2336
TriggerFuncArg { $$ = list_make1($1); }
2337
| TriggerFuncArgs ',' TriggerFuncArg { $$ = lappend($1, $3); }
2338
| /*EMPTY*/ { $$ = NIL; }
2345
snprintf(buf, sizeof(buf), "%d", $1);
2346
$$ = makeString(pstrdup(buf));
2348
| FCONST { $$ = makeString($1); }
2349
| Sconst { $$ = makeString($1); }
2350
| BCONST { $$ = makeString($1); }
2351
| XCONST { $$ = makeString($1); }
2352
| ColId { $$ = makeString($1); }
2356
FROM qualified_name { $$ = $2; }
2357
| /*EMPTY*/ { $$ = NULL; }
2360
ConstraintAttributeSpec:
2361
ConstraintDeferrabilitySpec
2363
| ConstraintDeferrabilitySpec ConstraintTimeSpec
2365
if ($1 == 0 && $2 != 0)
2367
(errcode(ERRCODE_SYNTAX_ERROR),
2368
errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE")));
2371
| ConstraintTimeSpec
2378
| ConstraintTimeSpec ConstraintDeferrabilitySpec
2380
if ($2 == 0 && $1 != 0)
2382
(errcode(ERRCODE_SYNTAX_ERROR),
2383
errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE")));
2390
ConstraintDeferrabilitySpec:
2391
NOT DEFERRABLE { $$ = 0; }
2392
| DEFERRABLE { $$ = 1; }
2396
INITIALLY IMMEDIATE { $$ = 0; }
2397
| INITIALLY DEFERRED { $$ = 2; }
2402
DROP TRIGGER name ON qualified_name opt_drop_behavior
2404
DropPropertyStmt *n = makeNode(DropPropertyStmt);
2408
n->removeType = OBJECT_TRIGGER;
2414
/*****************************************************************************
2417
* CREATE ASSERTION ...
2418
* DROP ASSERTION ...
2420
*****************************************************************************/
2423
CREATE ASSERTION name CHECK '(' a_expr ')'
2424
ConstraintAttributeSpec
2426
CreateTrigStmt *n = makeNode(CreateTrigStmt);
2428
n->args = list_make1($6);
2429
n->isconstraint = TRUE;
2430
n->deferrable = ($8 & 1) != 0;
2431
n->initdeferred = ($8 & 2) != 0;
2434
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2435
errmsg("CREATE ASSERTION is not yet implemented")));
2442
DROP ASSERTION name opt_drop_behavior
2444
DropPropertyStmt *n = makeNode(DropPropertyStmt);
2448
n->removeType = OBJECT_TRIGGER; /* XXX */
2450
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2451
errmsg("DROP ASSERTION is not yet implemented")));
2457
/*****************************************************************************
2460
* define (aggregate,operator,type)
2462
*****************************************************************************/
2465
CREATE AGGREGATE func_name definition
2467
DefineStmt *n = makeNode(DefineStmt);
2468
n->kind = OBJECT_AGGREGATE;
2473
| CREATE OPERATOR any_operator definition
2475
DefineStmt *n = makeNode(DefineStmt);
2476
n->kind = OBJECT_OPERATOR;
2481
| CREATE TYPE_P any_name definition
2483
DefineStmt *n = makeNode(DefineStmt);
2484
n->kind = OBJECT_TYPE;
2489
| CREATE TYPE_P any_name AS '(' TableFuncElementList ')'
2491
CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
2492
RangeVar *r = makeNode(RangeVar);
2494
/* can't use qualified_name, sigh */
2495
switch (list_length($3))
2498
r->catalogname = NULL;
2499
r->schemaname = NULL;
2500
r->relname = strVal(linitial($3));
2503
r->catalogname = NULL;
2504
r->schemaname = strVal(linitial($3));
2505
r->relname = strVal(lsecond($3));
2508
r->catalogname = strVal(linitial($3));
2509
r->schemaname = strVal(lsecond($3));
2510
r->relname = strVal(lthird($3));
2514
(errcode(ERRCODE_SYNTAX_ERROR),
2515
errmsg("improper qualified name (too many dotted names): %s",
2516
NameListToString($3))));
2525
definition: '(' def_list ')' { $$ = $2; }
2528
def_list: def_elem { $$ = list_make1($1); }
2529
| def_list ',' def_elem { $$ = lappend($1, $3); }
2532
def_elem: ColLabel '=' def_arg
2534
$$ = makeDefElem($1, (Node *)$3);
2538
$$ = makeDefElem($1, NULL);
2542
/* Note: any simple identifier will be returned as a type name! */
2543
def_arg: func_return { $$ = (Node *)$1; }
2544
| qual_all_Op { $$ = (Node *)$1; }
2545
| NumericOnly { $$ = (Node *)$1; }
2546
| Sconst { $$ = (Node *)makeString($1); }
2550
/*****************************************************************************
2553
* CREATE OPERATOR CLASS ...
2554
* DROP OPERATOR CLASS ...
2556
*****************************************************************************/
2559
CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
2560
USING access_method AS opclass_item_list
2562
CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
2563
n->opclassname = $4;
2573
opclass_item { $$ = list_make1($1); }
2574
| opclass_item_list ',' opclass_item { $$ = lappend($1, $3); }
2578
OPERATOR Iconst any_operator opt_recheck
2580
CreateOpClassItem *n = makeNode(CreateOpClassItem);
2581
n->itemtype = OPCLASS_ITEM_OPERATOR;
2588
| OPERATOR Iconst any_operator '(' oper_argtypes ')' opt_recheck
2590
CreateOpClassItem *n = makeNode(CreateOpClassItem);
2591
n->itemtype = OPCLASS_ITEM_OPERATOR;
2598
| FUNCTION Iconst func_name func_args
2600
CreateOpClassItem *n = makeNode(CreateOpClassItem);
2601
n->itemtype = OPCLASS_ITEM_FUNCTION;
2603
n->args = extractArgTypes($4);
2609
CreateOpClassItem *n = makeNode(CreateOpClassItem);
2610
n->itemtype = OPCLASS_ITEM_STORAGETYPE;
2616
opt_default: DEFAULT { $$ = TRUE; }
2617
| /*EMPTY*/ { $$ = FALSE; }
2620
opt_recheck: RECHECK { $$ = TRUE; }
2621
| /*EMPTY*/ { $$ = FALSE; }
2626
DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
2628
RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
2629
n->opclassname = $4;
2637
/*****************************************************************************
2641
* DROP itemtype itemname [, itemname ...] [ RESTRICT | CASCADE ]
2643
*****************************************************************************/
2645
DropStmt: DROP drop_type any_name_list opt_drop_behavior
2647
DropStmt *n = makeNode(DropStmt);
2655
drop_type: TABLE { $$ = OBJECT_TABLE; }
2656
| SEQUENCE { $$ = OBJECT_SEQUENCE; }
2657
| VIEW { $$ = OBJECT_VIEW; }
2658
| INDEX { $$ = OBJECT_INDEX; }
2659
| TYPE_P { $$ = OBJECT_TYPE; }
2660
| DOMAIN_P { $$ = OBJECT_DOMAIN; }
2661
| CONVERSION_P { $$ = OBJECT_CONVERSION; }
2662
| SCHEMA { $$ = OBJECT_SCHEMA; }
2666
any_name { $$ = list_make1($1); }
2667
| any_name_list ',' any_name { $$ = lappend($1, $3); }
2670
any_name: ColId { $$ = list_make1(makeString($1)); }
2671
| ColId attrs { $$ = lcons(makeString($1), $2); }
2674
attrs: '.' attr_name
2675
{ $$ = list_make1(makeString($2)); }
2676
| attrs '.' attr_name
2677
{ $$ = lappend($1, makeString($3)); }
2681
/*****************************************************************************
2684
* truncate table relname
2686
*****************************************************************************/
2689
TRUNCATE opt_table qualified_name
2691
TruncateStmt *n = makeNode(TruncateStmt);
2697
/*****************************************************************************
2699
* The COMMENT ON statement can take different forms based upon the type of
2700
* the object associated with the comment. The form of the statement is:
2702
* COMMENT ON [ [ DATABASE | DOMAIN | INDEX | SEQUENCE | TABLE | TYPE | VIEW |
2703
* CONVERSION | LANGUAGE | OPERATOR CLASS | LARGE OBJECT |
2704
* CAST ] <objname> |
2705
* AGGREGATE <aggname> (<aggtype>) |
2706
* FUNCTION <funcname> (arg1, arg2, ...) |
2707
* OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
2708
* TRIGGER <triggername> ON <relname> |
2709
* RULE <rulename> ON <relname> ]
2712
*****************************************************************************/
2715
COMMENT ON comment_type any_name IS comment_text
2717
CommentStmt *n = makeNode(CommentStmt);
2724
| COMMENT ON AGGREGATE func_name '(' aggr_argtype ')'
2727
CommentStmt *n = makeNode(CommentStmt);
2728
n->objtype = OBJECT_AGGREGATE;
2730
n->objargs = list_make1($6);
2734
| COMMENT ON FUNCTION func_name func_args IS comment_text
2736
CommentStmt *n = makeNode(CommentStmt);
2737
n->objtype = OBJECT_FUNCTION;
2739
n->objargs = extractArgTypes($5);
2743
| COMMENT ON OPERATOR any_operator '(' oper_argtypes ')'
2746
CommentStmt *n = makeNode(CommentStmt);
2747
n->objtype = OBJECT_OPERATOR;
2753
| COMMENT ON CONSTRAINT name ON any_name IS comment_text
2755
CommentStmt *n = makeNode(CommentStmt);
2756
n->objtype = OBJECT_CONSTRAINT;
2757
n->objname = lappend($6, makeString($4));
2762
| COMMENT ON RULE name ON any_name IS comment_text
2764
CommentStmt *n = makeNode(CommentStmt);
2765
n->objtype = OBJECT_RULE;
2766
n->objname = lappend($6, makeString($4));
2771
| COMMENT ON RULE name IS comment_text
2773
/* Obsolete syntax supported for awhile for compatibility */
2774
CommentStmt *n = makeNode(CommentStmt);
2775
n->objtype = OBJECT_RULE;
2776
n->objname = list_make1(makeString($4));
2781
| COMMENT ON TRIGGER name ON any_name IS comment_text
2783
CommentStmt *n = makeNode(CommentStmt);
2784
n->objtype = OBJECT_TRIGGER;
2785
n->objname = lappend($6, makeString($4));
2790
| COMMENT ON OPERATOR CLASS any_name USING access_method IS comment_text
2792
CommentStmt *n = makeNode(CommentStmt);
2793
n->objtype = OBJECT_OPCLASS;
2795
n->objargs = list_make1(makeString($7));
2799
| COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
2801
CommentStmt *n = makeNode(CommentStmt);
2802
n->objtype = OBJECT_LARGEOBJECT;
2803
n->objname = list_make1($5);
2808
| COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
2810
CommentStmt *n = makeNode(CommentStmt);
2811
n->objtype = OBJECT_CAST;
2812
n->objname = list_make1($5);
2813
n->objargs = list_make1($7);
2817
| COMMENT ON opt_procedural LANGUAGE any_name IS comment_text
2819
CommentStmt *n = makeNode(CommentStmt);
2820
n->objtype = OBJECT_LANGUAGE;
2829
COLUMN { $$ = OBJECT_COLUMN; }
2830
| DATABASE { $$ = OBJECT_DATABASE; }
2831
| SCHEMA { $$ = OBJECT_SCHEMA; }
2832
| INDEX { $$ = OBJECT_INDEX; }
2833
| SEQUENCE { $$ = OBJECT_SEQUENCE; }
2834
| TABLE { $$ = OBJECT_TABLE; }
2835
| DOMAIN_P { $$ = OBJECT_TYPE; }
2836
| TYPE_P { $$ = OBJECT_TYPE; }
2837
| VIEW { $$ = OBJECT_VIEW; }
2838
| CONVERSION_P { $$ = OBJECT_CONVERSION; }
2843
| NULL_P { $$ = NULL; }
2846
/*****************************************************************************
2851
*****************************************************************************/
2853
FetchStmt: FETCH fetch_direction from_in name
2855
FetchStmt *n = (FetchStmt *) $2;
2862
FetchStmt *n = makeNode(FetchStmt);
2863
n->direction = FETCH_FORWARD;
2869
| MOVE fetch_direction from_in name
2871
FetchStmt *n = (FetchStmt *) $2;
2878
FetchStmt *n = makeNode(FetchStmt);
2879
n->direction = FETCH_FORWARD;
2890
FetchStmt *n = makeNode(FetchStmt);
2891
n->direction = FETCH_FORWARD;
2897
FetchStmt *n = makeNode(FetchStmt);
2898
n->direction = FETCH_FORWARD;
2904
FetchStmt *n = makeNode(FetchStmt);
2905
n->direction = FETCH_BACKWARD;
2911
FetchStmt *n = makeNode(FetchStmt);
2912
n->direction = FETCH_ABSOLUTE;
2918
FetchStmt *n = makeNode(FetchStmt);
2919
n->direction = FETCH_ABSOLUTE;
2923
| ABSOLUTE_P fetch_count
2925
FetchStmt *n = makeNode(FetchStmt);
2926
n->direction = FETCH_ABSOLUTE;
2930
| RELATIVE_P fetch_count
2932
FetchStmt *n = makeNode(FetchStmt);
2933
n->direction = FETCH_RELATIVE;
2939
FetchStmt *n = makeNode(FetchStmt);
2940
n->direction = FETCH_FORWARD;
2946
FetchStmt *n = makeNode(FetchStmt);
2947
n->direction = FETCH_FORWARD;
2948
n->howMany = FETCH_ALL;
2953
FetchStmt *n = makeNode(FetchStmt);
2954
n->direction = FETCH_FORWARD;
2958
| FORWARD fetch_count
2960
FetchStmt *n = makeNode(FetchStmt);
2961
n->direction = FETCH_FORWARD;
2967
FetchStmt *n = makeNode(FetchStmt);
2968
n->direction = FETCH_FORWARD;
2969
n->howMany = FETCH_ALL;
2974
FetchStmt *n = makeNode(FetchStmt);
2975
n->direction = FETCH_BACKWARD;
2979
| BACKWARD fetch_count
2981
FetchStmt *n = makeNode(FetchStmt);
2982
n->direction = FETCH_BACKWARD;
2988
FetchStmt *n = makeNode(FetchStmt);
2989
n->direction = FETCH_BACKWARD;
2990
n->howMany = FETCH_ALL;
2997
| '-' Iconst { $$ = - $2; }
3005
/*****************************************************************************
3007
* GRANT and REVOKE statements
3009
*****************************************************************************/
3011
GrantStmt: GRANT privileges ON privilege_target TO grantee_list
3012
opt_grant_grant_option
3014
GrantStmt *n = makeNode(GrantStmt);
3017
n->objtype = ($4)->objtype;
3018
n->objects = ($4)->objs;
3020
n->grant_option = $7;
3025
RevokeStmt: REVOKE opt_revoke_grant_option privileges ON privilege_target
3026
FROM grantee_list opt_drop_behavior
3028
GrantStmt *n = makeNode(GrantStmt);
3029
n->is_grant = false;
3031
n->objtype = ($5)->objtype;
3032
n->objects = ($5)->objs;
3034
n->grant_option = $2;
3042
/* either ALL [PRIVILEGES] or a list of individual privileges */
3043
privileges: privilege_list { $$ = $1; }
3044
| ALL { $$ = list_make1_int(ACL_ALL_RIGHTS); }
3045
| ALL PRIVILEGES { $$ = list_make1_int(ACL_ALL_RIGHTS); }
3049
privilege { $$ = list_make1_int($1); }
3050
| privilege_list ',' privilege { $$ = lappend_int($1, $3); }
3053
/* Not all of these privilege types apply to all objects, but that
3054
* gets sorted out later.
3056
privilege: SELECT { $$ = ACL_SELECT; }
3057
| INSERT { $$ = ACL_INSERT; }
3058
| UPDATE { $$ = ACL_UPDATE; }
3059
| DELETE_P { $$ = ACL_DELETE; }
3060
| RULE { $$ = ACL_RULE; }
3061
| REFERENCES { $$ = ACL_REFERENCES; }
3062
| TRIGGER { $$ = ACL_TRIGGER; }
3063
| EXECUTE { $$ = ACL_EXECUTE; }
3064
| USAGE { $$ = ACL_USAGE; }
3065
| CREATE { $$ = ACL_CREATE; }
3066
| TEMPORARY { $$ = ACL_CREATE_TEMP; }
3067
| TEMP { $$ = ACL_CREATE_TEMP; }
3071
/* Don't bother trying to fold the first two rules into one using
3072
opt_table. You're going to get conflicts. */
3076
PrivTarget *n = makeNode(PrivTarget);
3077
n->objtype = ACL_OBJECT_RELATION;
3081
| TABLE qualified_name_list
3083
PrivTarget *n = makeNode(PrivTarget);
3084
n->objtype = ACL_OBJECT_RELATION;
3088
| FUNCTION function_with_argtypes_list
3090
PrivTarget *n = makeNode(PrivTarget);
3091
n->objtype = ACL_OBJECT_FUNCTION;
3095
| DATABASE name_list
3097
PrivTarget *n = makeNode(PrivTarget);
3098
n->objtype = ACL_OBJECT_DATABASE;
3102
| LANGUAGE name_list
3104
PrivTarget *n = makeNode(PrivTarget);
3105
n->objtype = ACL_OBJECT_LANGUAGE;
3111
PrivTarget *n = makeNode(PrivTarget);
3112
n->objtype = ACL_OBJECT_NAMESPACE;
3116
| TABLESPACE name_list
3118
PrivTarget *n = makeNode(PrivTarget);
3119
n->objtype = ACL_OBJECT_TABLESPACE;
3127
grantee { $$ = list_make1($1); }
3128
| grantee_list ',' grantee { $$ = lappend($1, $3); }
3133
PrivGrantee *n = makeNode(PrivGrantee);
3134
/* This hack lets us avoid reserving PUBLIC as a keyword*/
3135
if (strcmp($1, "public") == 0)
3139
n->groupname = NULL;
3144
PrivGrantee *n = makeNode(PrivGrantee);
3145
/* Treat GROUP PUBLIC as a synonym for PUBLIC */
3146
if (strcmp($2, "public") == 0)
3147
n->groupname = NULL;
3156
opt_grant_grant_option:
3157
WITH GRANT OPTION { $$ = TRUE; }
3158
| /*EMPTY*/ { $$ = FALSE; }
3161
opt_revoke_grant_option:
3162
GRANT OPTION FOR { $$ = TRUE; }
3163
| /*EMPTY*/ { $$ = FALSE; }
3167
function_with_argtypes_list:
3168
function_with_argtypes { $$ = list_make1($1); }
3169
| function_with_argtypes_list ',' function_with_argtypes
3170
{ $$ = lappend($1, $3); }
3173
function_with_argtypes:
3176
FuncWithArgs *n = makeNode(FuncWithArgs);
3178
n->funcargs = extractArgTypes($2);
3184
/*****************************************************************************
3187
* create index <indexname> on <relname>
3188
* [ using <access> ] "(" ( <col> [ using <opclass> ] )+ ")"
3189
* [ tablespace <tablespacename> ] [ where <predicate> ]
3191
* Note: we cannot put TABLESPACE clause after WHERE clause unless we are
3192
* willing to make TABLESPACE a fully reserved word.
3193
*****************************************************************************/
3195
IndexStmt: CREATE index_opt_unique INDEX index_name ON qualified_name
3196
access_method_clause '(' index_params ')' OptTableSpace where_clause
3198
IndexStmt *n = makeNode(IndexStmt);
3202
n->accessMethod = $7;
3203
n->indexParams = $9;
3204
n->tableSpace = $11;
3205
n->whereClause = $12;
3211
UNIQUE { $$ = TRUE; }
3212
| /*EMPTY*/ { $$ = FALSE; }
3215
access_method_clause:
3216
USING access_method { $$ = $2; }
3217
| /*EMPTY*/ { $$ = DEFAULT_INDEX_TYPE; }
3220
index_params: index_elem { $$ = list_make1($1); }
3221
| index_params ',' index_elem { $$ = lappend($1, $3); }
3225
* Index attributes can be either simple column references, or arbitrary
3226
* expressions in parens. For backwards-compatibility reasons, we allow
3227
* an expression that's just a function call to be written without parens.
3229
index_elem: ColId opt_class
3231
$$ = makeNode(IndexElem);
3236
| func_expr opt_class
3238
$$ = makeNode(IndexElem);
3243
| '(' a_expr ')' opt_class
3245
$$ = makeNode(IndexElem);
3252
opt_class: any_name { $$ = $1; }
3253
| USING any_name { $$ = $2; }
3254
| /*EMPTY*/ { $$ = NIL; }
3257
/*****************************************************************************
3260
* create [or replace] function <fname>
3261
* [(<type-1> { , <type-n>})]
3263
* as <filename or code in language as appropriate>
3264
* language <lang> [with parameters]
3266
*****************************************************************************/
3269
CREATE opt_or_replace FUNCTION func_name func_args
3270
RETURNS func_return createfunc_opt_list opt_definition
3272
CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
3284
OR REPLACE { $$ = TRUE; }
3285
| /*EMPTY*/ { $$ = FALSE; }
3288
func_args: '(' func_args_list ')' { $$ = $2; }
3289
| '(' ')' { $$ = NIL; }
3293
func_arg { $$ = list_make1($1); }
3294
| func_args_list ',' func_arg { $$ = lappend($1, $3); }
3297
/* We can catch over-specified arguments here if we want to,
3298
* but for now better to silently swallow typmod, etc.
3299
* - thomas 2000-03-22
3302
arg_class param_name func_type
3304
FunctionParameter *n = makeNode(FunctionParameter);
3309
| arg_class func_type
3311
FunctionParameter *n = makeNode(FunctionParameter);
3318
arg_class: IN_P { $$ = FALSE; }
3322
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3323
errmsg("CREATE FUNCTION / OUT parameters are not implemented")));
3329
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3330
errmsg("CREATE FUNCTION / INOUT parameters are not implemented")));
3333
| /*EMPTY*/ { $$ = FALSE; }
3337
* Ideally param_name should be ColId, but that causes too many conflicts.
3339
param_name: function_name
3345
/* We can catch over-specified arguments here if we want to,
3346
* but for now better to silently swallow typmod, etc.
3347
* - thomas 2000-03-22
3354
* We would like to make the second production here be ColId attrs etc,
3355
* but that causes reduce/reduce conflicts. type_name is next best choice.
3357
func_type: Typename { $$ = $1; }
3358
| type_name attrs '%' TYPE_P
3360
$$ = makeNode(TypeName);
3361
$$->names = lcons(makeString($1), $2);
3362
$$->pct_type = true;
3368
createfunc_opt_list:
3369
/* Must be at least one to prevent conflict */
3370
createfunc_opt_item { $$ = list_make1($1); }
3371
| createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
3374
createfunc_opt_item:
3377
$$ = makeDefElem("as", (Node *)$2);
3379
| LANGUAGE ColId_or_Sconst
3381
$$ = makeDefElem("language", (Node *)makeString($2));
3385
$$ = makeDefElem("volatility", (Node *)makeString("immutable"));
3389
$$ = makeDefElem("volatility", (Node *)makeString("stable"));
3393
$$ = makeDefElem("volatility", (Node *)makeString("volatile"));
3395
| CALLED ON NULL_P INPUT_P
3397
$$ = makeDefElem("strict", (Node *)makeInteger(FALSE));
3399
| RETURNS NULL_P ON NULL_P INPUT_P
3401
$$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
3405
$$ = makeDefElem("strict", (Node *)makeInteger(TRUE));
3407
| EXTERNAL SECURITY DEFINER
3409
$$ = makeDefElem("security", (Node *)makeInteger(TRUE));
3411
| EXTERNAL SECURITY INVOKER
3413
$$ = makeDefElem("security", (Node *)makeInteger(FALSE));
3417
$$ = makeDefElem("security", (Node *)makeInteger(TRUE));
3421
$$ = makeDefElem("security", (Node *)makeInteger(FALSE));
3425
func_as: Sconst { $$ = list_make1(makeString($1)); }
3428
$$ = list_make2(makeString($1), makeString($3));
3433
WITH definition { $$ = $2; }
3434
| /*EMPTY*/ { $$ = NIL; }
3438
/*****************************************************************************
3442
* DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
3443
* DROP AGGREGATE aggname (aggtype) [ RESTRICT | CASCADE ]
3444
* DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
3446
*****************************************************************************/
3449
DROP FUNCTION func_name func_args opt_drop_behavior
3451
RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
3453
n->args = extractArgTypes($4);
3460
DROP AGGREGATE func_name '(' aggr_argtype ')' opt_drop_behavior
3462
RemoveAggrStmt *n = makeNode(RemoveAggrStmt);
3471
Typename { $$ = $1; }
3472
| '*' { $$ = NULL; }
3476
DROP OPERATOR any_operator '(' oper_argtypes ')' opt_drop_behavior
3478
RemoveOperStmt *n = makeNode(RemoveOperStmt);
3490
(errcode(ERRCODE_SYNTAX_ERROR),
3491
errmsg("missing argument"),
3492
errhint("Use NONE to denote the missing argument of a unary operator.")));
3494
| Typename ',' Typename
3495
{ $$ = list_make2($1, $3); }
3496
| NONE ',' Typename /* left unary */
3497
{ $$ = list_make2(NULL, $3); }
3498
| Typename ',' NONE /* right unary */
3499
{ $$ = list_make2($1, NULL); }
3504
{ $$ = list_make1(makeString($1)); }
3505
| ColId '.' any_operator
3506
{ $$ = lcons(makeString($1), $3); }
3510
/*****************************************************************************
3512
* CREATE CAST / DROP CAST
3514
*****************************************************************************/
3516
CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
3517
WITH FUNCTION function_with_argtypes cast_context
3519
CreateCastStmt *n = makeNode(CreateCastStmt);
3522
n->func = (FuncWithArgs *) $10;
3523
n->context = (CoercionContext) $11;
3526
| CREATE CAST '(' Typename AS Typename ')'
3527
WITHOUT FUNCTION cast_context
3529
CreateCastStmt *n = makeNode(CreateCastStmt);
3533
n->context = (CoercionContext) $10;
3538
cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
3539
| AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; }
3540
| /*EMPTY*/ { $$ = COERCION_EXPLICIT; }
3544
DropCastStmt: DROP CAST '(' Typename AS Typename ')' opt_drop_behavior
3546
DropCastStmt *n = makeNode(DropCastStmt);
3556
/*****************************************************************************
3560
* REINDEX type <typename> [FORCE] [ALL]
3562
*****************************************************************************/
3565
REINDEX reindex_type qualified_name opt_force
3567
ReindexStmt *n = makeNode(ReindexStmt);
3574
| REINDEX DATABASE name opt_force
3576
ReindexStmt *n = makeNode(ReindexStmt);
3577
n->kind = OBJECT_DATABASE;
3586
INDEX { $$ = OBJECT_INDEX; }
3587
| TABLE { $$ = OBJECT_TABLE; }
3590
opt_force: FORCE { $$ = TRUE; }
3591
| /* EMPTY */ { $$ = FALSE; }
3595
/*****************************************************************************
3597
* ALTER THING name RENAME TO newname
3599
*****************************************************************************/
3601
RenameStmt: ALTER AGGREGATE func_name '(' aggr_argtype ')' RENAME TO name
3603
RenameStmt *n = makeNode(RenameStmt);
3604
n->renameType = OBJECT_AGGREGATE;
3606
n->objarg = list_make1($5);
3610
| ALTER CONVERSION_P any_name RENAME TO name
3612
RenameStmt *n = makeNode(RenameStmt);
3613
n->renameType = OBJECT_CONVERSION;
3618
| ALTER DATABASE database_name RENAME TO database_name
3620
RenameStmt *n = makeNode(RenameStmt);
3621
n->renameType = OBJECT_DATABASE;
3626
| ALTER FUNCTION func_name func_args RENAME TO name
3628
RenameStmt *n = makeNode(RenameStmt);
3629
n->renameType = OBJECT_FUNCTION;
3631
n->objarg = extractArgTypes($4);
3635
| ALTER GROUP_P UserId RENAME TO UserId
3637
RenameStmt *n = makeNode(RenameStmt);
3638
n->renameType = OBJECT_GROUP;
3643
| ALTER LANGUAGE name RENAME TO name
3645
RenameStmt *n = makeNode(RenameStmt);
3646
n->renameType = OBJECT_LANGUAGE;
3651
| ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
3653
RenameStmt *n = makeNode(RenameStmt);
3654
n->renameType = OBJECT_OPCLASS;
3660
| ALTER SCHEMA name RENAME TO name
3662
RenameStmt *n = makeNode(RenameStmt);
3663
n->renameType = OBJECT_SCHEMA;
3668
| ALTER TABLE relation_expr RENAME TO name
3670
RenameStmt *n = makeNode(RenameStmt);
3671
n->renameType = OBJECT_TABLE;
3677
| ALTER INDEX relation_expr RENAME TO name
3679
RenameStmt *n = makeNode(RenameStmt);
3680
n->renameType = OBJECT_INDEX;
3686
| ALTER TABLE relation_expr RENAME opt_column name TO name
3688
RenameStmt *n = makeNode(RenameStmt);
3689
n->renameType = OBJECT_COLUMN;
3695
| ALTER TRIGGER name ON relation_expr RENAME TO name
3697
RenameStmt *n = makeNode(RenameStmt);
3701
n->renameType = OBJECT_TRIGGER;
3704
| ALTER USER UserId RENAME TO UserId
3706
RenameStmt *n = makeNode(RenameStmt);
3707
n->renameType = OBJECT_USER;
3712
| ALTER TABLESPACE name RENAME TO name
3714
RenameStmt *n = makeNode(RenameStmt);
3715
n->renameType = OBJECT_TABLESPACE;
3722
opt_column: COLUMN { $$ = COLUMN; }
3723
| /*EMPTY*/ { $$ = 0; }
3727
/*****************************************************************************
3729
* ALTER THING name OWNER TO newname.
3731
*****************************************************************************/
3733
AlterOwnerStmt: ALTER AGGREGATE func_name '(' aggr_argtype ')' OWNER TO UserId
3735
AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
3736
n->objectType = OBJECT_AGGREGATE;
3738
n->objarg = list_make1($5);
3742
| ALTER CONVERSION_P any_name OWNER TO UserId
3744
AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
3745
n->objectType = OBJECT_CONVERSION;
3750
| ALTER DATABASE database_name OWNER TO UserId
3752
AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
3753
n->objectType = OBJECT_DATABASE;
3754
n->object = list_make1($3);
3758
| ALTER DOMAIN_P any_name OWNER TO UserId
3760
AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
3761
n->objectType = OBJECT_DOMAIN;
3766
| ALTER FUNCTION func_name func_args OWNER TO UserId
3768
AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
3769
n->objectType = OBJECT_FUNCTION;
3771
n->objarg = extractArgTypes($4);
3775
| ALTER OPERATOR any_operator '(' oper_argtypes ')' OWNER TO UserId
3777
AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
3778
n->objectType = OBJECT_OPERATOR;
3784
| ALTER OPERATOR CLASS any_name USING access_method OWNER TO UserId
3786
AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
3787
n->objectType = OBJECT_OPCLASS;
3793
| ALTER SCHEMA name OWNER TO UserId
3795
AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
3796
n->objectType = OBJECT_SCHEMA;
3797
n->object = list_make1($3);
3801
| ALTER TYPE_P any_name OWNER TO UserId
3803
AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
3804
n->objectType = OBJECT_TYPE;
3809
| ALTER TABLESPACE name OWNER TO UserId
3811
AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
3812
n->objectType = OBJECT_TABLESPACE;
3813
n->object = list_make1($3);
3820
/*****************************************************************************
3822
* QUERY: Define Rewrite Rule
3824
*****************************************************************************/
3826
RuleStmt: CREATE opt_or_replace RULE name AS
3827
{ QueryIsRule=TRUE; }
3828
ON event TO qualified_name where_clause
3829
DO opt_instead RuleActionList
3831
RuleStmt *n = makeNode(RuleStmt);
3835
n->whereClause = $11;
3845
NOTHING { $$ = NIL; }
3846
| RuleActionStmt { $$ = list_make1($1); }
3847
| '(' RuleActionMulti ')' { $$ = $2; }
3850
/* the thrashing around here is to discard "empty" statements... */
3852
RuleActionMulti ';' RuleActionStmtOrEmpty
3854
$$ = lappend($1, $3);
3858
| RuleActionStmtOrEmpty
3860
$$ = list_make1($1);
3874
RuleActionStmtOrEmpty:
3875
RuleActionStmt { $$ = $1; }
3876
| /*EMPTY*/ { $$ = NULL; }
3879
/* change me to select, update, etc. some day */
3880
event: SELECT { $$ = CMD_SELECT; }
3881
| UPDATE { $$ = CMD_UPDATE; }
3882
| DELETE_P { $$ = CMD_DELETE; }
3883
| INSERT { $$ = CMD_INSERT; }
3887
INSTEAD { $$ = TRUE; }
3888
| ALSO { $$ = FALSE; }
3889
| /*EMPTY*/ { $$ = FALSE; }
3894
DROP RULE name ON qualified_name opt_drop_behavior
3896
DropPropertyStmt *n = makeNode(DropPropertyStmt);
3900
n->removeType = OBJECT_RULE;
3906
/*****************************************************************************
3909
* NOTIFY <qualified_name> can appear both in rule bodies and
3910
* as a query-level command
3912
*****************************************************************************/
3914
NotifyStmt: NOTIFY qualified_name
3916
NotifyStmt *n = makeNode(NotifyStmt);
3922
ListenStmt: LISTEN qualified_name
3924
ListenStmt *n = makeNode(ListenStmt);
3931
UNLISTEN qualified_name
3933
UnlistenStmt *n = makeNode(UnlistenStmt);
3939
UnlistenStmt *n = makeNode(UnlistenStmt);
3940
n->relation = makeNode(RangeVar);
3941
n->relation->relname = "*";
3942
n->relation->schemaname = NULL;
3948
/*****************************************************************************
3952
* BEGIN / COMMIT / ROLLBACK
3953
* (also older versions END / ABORT)
3955
*****************************************************************************/
3958
ABORT_P opt_transaction
3960
TransactionStmt *n = makeNode(TransactionStmt);
3961
n->kind = TRANS_STMT_ROLLBACK;
3965
| BEGIN_P opt_transaction transaction_mode_list_or_empty
3967
TransactionStmt *n = makeNode(TransactionStmt);
3968
n->kind = TRANS_STMT_BEGIN;
3972
| START TRANSACTION transaction_mode_list_or_empty
3974
TransactionStmt *n = makeNode(TransactionStmt);
3975
n->kind = TRANS_STMT_START;
3979
| COMMIT opt_transaction
3981
TransactionStmt *n = makeNode(TransactionStmt);
3982
n->kind = TRANS_STMT_COMMIT;
3986
| END_P opt_transaction
3988
TransactionStmt *n = makeNode(TransactionStmt);
3989
n->kind = TRANS_STMT_COMMIT;
3993
| ROLLBACK opt_transaction
3995
TransactionStmt *n = makeNode(TransactionStmt);
3996
n->kind = TRANS_STMT_ROLLBACK;
4002
TransactionStmt *n = makeNode(TransactionStmt);
4003
n->kind = TRANS_STMT_SAVEPOINT;
4004
n->options = list_make1(makeDefElem("savepoint_name",
4005
(Node *)makeString($2)));
4008
| RELEASE SAVEPOINT ColId
4010
TransactionStmt *n = makeNode(TransactionStmt);
4011
n->kind = TRANS_STMT_RELEASE;
4012
n->options = list_make1(makeDefElem("savepoint_name",
4013
(Node *)makeString($3)));
4018
TransactionStmt *n = makeNode(TransactionStmt);
4019
n->kind = TRANS_STMT_RELEASE;
4020
n->options = list_make1(makeDefElem("savepoint_name",
4021
(Node *)makeString($2)));
4024
| ROLLBACK opt_transaction TO SAVEPOINT ColId
4026
TransactionStmt *n = makeNode(TransactionStmt);
4027
n->kind = TRANS_STMT_ROLLBACK_TO;
4028
n->options = list_make1(makeDefElem("savepoint_name",
4029
(Node *)makeString($5)));
4032
| ROLLBACK opt_transaction TO ColId
4034
TransactionStmt *n = makeNode(TransactionStmt);
4035
n->kind = TRANS_STMT_ROLLBACK_TO;
4036
n->options = list_make1(makeDefElem("savepoint_name",
4037
(Node *)makeString($4)));
4042
opt_transaction: WORK {}
4047
transaction_mode_item:
4048
ISOLATION LEVEL iso_level
4049
{ $$ = makeDefElem("transaction_isolation",
4050
makeStringConst($3, NULL)); }
4052
{ $$ = makeDefElem("transaction_read_only",
4053
makeIntConst(TRUE)); }
4055
{ $$ = makeDefElem("transaction_read_only",
4056
makeIntConst(FALSE)); }
4059
/* Syntax with commas is SQL-spec, without commas is Postgres historical */
4060
transaction_mode_list:
4061
transaction_mode_item
4062
{ $$ = list_make1($1); }
4063
| transaction_mode_list ',' transaction_mode_item
4064
{ $$ = lappend($1, $3); }
4065
| transaction_mode_list transaction_mode_item
4066
{ $$ = lappend($1, $2); }
4069
transaction_mode_list_or_empty:
4070
transaction_mode_list
4076
/*****************************************************************************
4079
* create view <viewname> '('target-list ')' AS <query>
4081
*****************************************************************************/
4083
ViewStmt: CREATE opt_or_replace VIEW qualified_name opt_column_list
4086
ViewStmt *n = makeNode(ViewStmt);
4090
n->query = (Query *) $7;
4096
/*****************************************************************************
4101
*****************************************************************************/
4103
LoadStmt: LOAD file_name
4105
LoadStmt *n = makeNode(LoadStmt);
4112
/*****************************************************************************
4116
*****************************************************************************/
4119
CREATE DATABASE database_name opt_with createdb_opt_list
4121
CreatedbStmt *n = makeNode(CreatedbStmt);
4129
createdb_opt_list createdb_opt_item { $$ = lappend($1, $2); }
4130
| /* EMPTY */ { $$ = NIL; }
4134
TABLESPACE opt_equal name
4136
$$ = makeDefElem("tablespace", (Node *)makeString($3));
4138
| TABLESPACE opt_equal DEFAULT
4140
$$ = makeDefElem("tablespace", NULL);
4142
| LOCATION opt_equal Sconst
4144
$$ = makeDefElem("location", (Node *)makeString($3));
4146
| LOCATION opt_equal DEFAULT
4148
$$ = makeDefElem("location", NULL);
4150
| TEMPLATE opt_equal name
4152
$$ = makeDefElem("template", (Node *)makeString($3));
4154
| TEMPLATE opt_equal DEFAULT
4156
$$ = makeDefElem("template", NULL);
4158
| ENCODING opt_equal Sconst
4160
$$ = makeDefElem("encoding", (Node *)makeString($3));
4162
| ENCODING opt_equal Iconst
4164
$$ = makeDefElem("encoding", (Node *)makeInteger($3));
4166
| ENCODING opt_equal DEFAULT
4168
$$ = makeDefElem("encoding", NULL);
4170
| OWNER opt_equal name
4172
$$ = makeDefElem("owner", (Node *)makeString($3));
4174
| OWNER opt_equal DEFAULT
4176
$$ = makeDefElem("owner", NULL);
4181
* Though the equals sign doesn't match other WITH options, pg_dump uses
4182
* equals for backward compability, and it doesn't seem worth removing it.
4190
/*****************************************************************************
4194
*****************************************************************************/
4196
AlterDatabaseSetStmt:
4197
ALTER DATABASE database_name SET set_rest
4199
AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
4201
n->variable = $5->name;
4202
n->value = $5->args;
4205
| ALTER DATABASE database_name VariableResetStmt
4207
AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
4209
n->variable = ((VariableResetStmt *)$4)->name;
4216
/*****************************************************************************
4220
* This is implicitly CASCADE, no need for drop behavior
4221
*****************************************************************************/
4223
DropdbStmt: DROP DATABASE database_name
4225
DropdbStmt *n = makeNode(DropdbStmt);
4232
/*****************************************************************************
4234
* Manipulate a domain
4236
*****************************************************************************/
4239
CREATE DOMAIN_P any_name opt_as Typename ColQualList
4241
CreateDomainStmt *n = makeNode(CreateDomainStmt);
4244
n->constraints = $6;
4250
/* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
4251
ALTER DOMAIN_P any_name alter_column_default
4253
AlterDomainStmt *n = makeNode(AlterDomainStmt);
4259
/* ALTER DOMAIN <domain> DROP NOT NULL */
4260
| ALTER DOMAIN_P any_name DROP NOT NULL_P
4262
AlterDomainStmt *n = makeNode(AlterDomainStmt);
4267
/* ALTER DOMAIN <domain> SET NOT NULL */
4268
| ALTER DOMAIN_P any_name SET NOT NULL_P
4270
AlterDomainStmt *n = makeNode(AlterDomainStmt);
4275
/* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
4276
| ALTER DOMAIN_P any_name ADD TableConstraint
4278
AlterDomainStmt *n = makeNode(AlterDomainStmt);
4284
/* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
4285
| ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
4287
AlterDomainStmt *n = makeNode(AlterDomainStmt);
4301
/*****************************************************************************
4303
* Manipulate a conversion
4305
* CREATE [DEFAULT] CONVERSION <conversion_name>
4306
* FOR <encoding_name> TO <encoding_name> FROM <func_name>
4308
*****************************************************************************/
4310
CreateConversionStmt:
4311
CREATE opt_default CONVERSION_P any_name FOR Sconst
4312
TO Sconst FROM any_name
4314
CreateConversionStmt *n = makeNode(CreateConversionStmt);
4315
n->conversion_name = $4;
4316
n->for_encoding_name = $6;
4317
n->to_encoding_name = $8;
4324
/*****************************************************************************
4327
* cluster <index_name> on <qualified_name>
4328
* cluster <qualified_name>
4331
*****************************************************************************/
4334
CLUSTER index_name ON qualified_name
4336
ClusterStmt *n = makeNode(ClusterStmt);
4341
| CLUSTER qualified_name
4343
ClusterStmt *n = makeNode(ClusterStmt);
4345
n->indexname = NULL;
4350
ClusterStmt *n = makeNode(ClusterStmt);
4352
n->indexname = NULL;
4357
/*****************************************************************************
4363
*****************************************************************************/
4365
VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
4367
VacuumStmt *n = makeNode(VacuumStmt);
4377
| VACUUM opt_full opt_freeze opt_verbose qualified_name
4379
VacuumStmt *n = makeNode(VacuumStmt);
4389
| VACUUM opt_full opt_freeze opt_verbose AnalyzeStmt
4391
VacuumStmt *n = (VacuumStmt *) $5;
4401
analyze_keyword opt_verbose
4403
VacuumStmt *n = makeNode(VacuumStmt);
4413
| analyze_keyword opt_verbose qualified_name opt_name_list
4415
VacuumStmt *n = makeNode(VacuumStmt);
4429
| ANALYSE /* British */ {}
4433
VERBOSE { $$ = TRUE; }
4434
| /*EMPTY*/ { $$ = FALSE; }
4437
opt_full: FULL { $$ = TRUE; }
4438
| /*EMPTY*/ { $$ = FALSE; }
4441
opt_freeze: FREEZE { $$ = TRUE; }
4442
| /*EMPTY*/ { $$ = FALSE; }
4446
'(' name_list ')' { $$ = $2; }
4447
| /*EMPTY*/ { $$ = NIL; }
4451
/*****************************************************************************
4454
* EXPLAIN [ANALYZE] [VERBOSE] query
4456
*****************************************************************************/
4458
ExplainStmt: EXPLAIN opt_analyze opt_verbose ExplainableStmt
4460
ExplainStmt *n = makeNode(ExplainStmt);
4463
n->query = (Query*)$4;
4474
| ExecuteStmt /* by default all are $$=$1 */
4478
analyze_keyword { $$ = TRUE; }
4479
| /* EMPTY */ { $$ = FALSE; }
4482
/*****************************************************************************
4485
* PREPARE <plan_name> [(args, ...)] AS <query>
4487
*****************************************************************************/
4489
PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
4491
PrepareStmt *n = makeNode(PrepareStmt);
4494
n->query = (Query *) $5;
4499
prep_type_clause: '(' prep_type_list ')' { $$ = $2; }
4500
| /* EMPTY */ { $$ = NIL; }
4503
prep_type_list: Typename { $$ = list_make1($1); }
4504
| prep_type_list ',' Typename
4505
{ $$ = lappend($1, $3); }
4512
| DeleteStmt /* by default all are $$=$1 */
4515
/*****************************************************************************
4517
* EXECUTE <plan_name> [(params, ...)]
4518
* CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
4520
*****************************************************************************/
4522
ExecuteStmt: EXECUTE name execute_param_clause
4524
ExecuteStmt *n = makeNode(ExecuteStmt);
4530
| CREATE OptTemp TABLE qualified_name OptCreateAs AS EXECUTE name execute_param_clause
4532
ExecuteStmt *n = makeNode(ExecuteStmt);
4539
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4540
errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
4541
/* ... because it's not implemented, but it could be */
4546
execute_param_clause: '(' expr_list ')' { $$ = $2; }
4547
| /* EMPTY */ { $$ = NIL; }
4550
/*****************************************************************************
4553
* DEALLOCATE [PREPARE] <plan_name>
4555
*****************************************************************************/
4557
DeallocateStmt: DEALLOCATE name
4559
DeallocateStmt *n = makeNode(DeallocateStmt);
4563
| DEALLOCATE PREPARE name
4565
DeallocateStmt *n = makeNode(DeallocateStmt);
4571
/*****************************************************************************
4576
*****************************************************************************/
4579
INSERT INTO qualified_name insert_rest
4587
VALUES '(' insert_target_list ')'
4589
$$ = makeNode(InsertStmt);
4591
$$->targetList = $3;
4592
$$->selectStmt = NULL;
4596
$$ = makeNode(InsertStmt);
4598
$$->targetList = NIL;
4599
$$->selectStmt = NULL;
4603
$$ = makeNode(InsertStmt);
4605
$$->targetList = NIL;
4606
$$->selectStmt = $1;
4608
| '(' insert_column_list ')' VALUES '(' insert_target_list ')'
4610
$$ = makeNode(InsertStmt);
4612
$$->targetList = $6;
4613
$$->selectStmt = NULL;
4615
| '(' insert_column_list ')' SelectStmt
4617
$$ = makeNode(InsertStmt);
4619
$$->targetList = NIL;
4620
$$->selectStmt = $4;
4626
{ $$ = list_make1($1); }
4627
| insert_column_list ',' insert_column_item
4628
{ $$ = lappend($1, $3); }
4632
ColId opt_indirection
4634
$$ = makeNode(ResTarget);
4636
$$->indirection = $2;
4642
/*****************************************************************************
4647
*****************************************************************************/
4649
DeleteStmt: DELETE_P FROM relation_expr where_clause
4651
DeleteStmt *n = makeNode(DeleteStmt);
4653
n->whereClause = $4;
4658
LockStmt: LOCK_P opt_table qualified_name_list opt_lock opt_nowait
4660
LockStmt *n = makeNode(LockStmt);
4669
opt_lock: IN_P lock_type MODE { $$ = $2; }
4670
| /*EMPTY*/ { $$ = AccessExclusiveLock; }
4673
lock_type: ACCESS SHARE { $$ = AccessShareLock; }
4674
| ROW SHARE { $$ = RowShareLock; }
4675
| ROW EXCLUSIVE { $$ = RowExclusiveLock; }
4676
| SHARE UPDATE EXCLUSIVE { $$ = ShareUpdateExclusiveLock; }
4677
| SHARE { $$ = ShareLock; }
4678
| SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
4679
| EXCLUSIVE { $$ = ExclusiveLock; }
4680
| ACCESS EXCLUSIVE { $$ = AccessExclusiveLock; }
4683
opt_nowait: NOWAIT { $$ = TRUE; }
4684
| /*EMPTY*/ { $$ = FALSE; }
4688
/*****************************************************************************
4691
* UpdateStmt (UPDATE)
4693
*****************************************************************************/
4695
UpdateStmt: UPDATE relation_expr
4696
SET update_target_list
4700
UpdateStmt *n = makeNode(UpdateStmt);
4704
n->whereClause = $6;
4710
/*****************************************************************************
4715
*****************************************************************************/
4716
DeclareCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR SelectStmt
4718
DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
4723
n->options |= CURSOR_OPT_HOLD;
4728
cursor_options: /*EMPTY*/ { $$ = 0; }
4729
| cursor_options NO SCROLL { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
4730
| cursor_options SCROLL { $$ = $1 | CURSOR_OPT_SCROLL; }
4731
| cursor_options BINARY { $$ = $1 | CURSOR_OPT_BINARY; }
4732
| cursor_options INSENSITIVE { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
4735
opt_hold: /* EMPTY */ { $$ = FALSE; }
4736
| WITH HOLD { $$ = TRUE; }
4737
| WITHOUT HOLD { $$ = FALSE; }
4740
/*****************************************************************************
4745
*****************************************************************************/
4747
/* A complete SELECT statement looks like this.
4749
* The rule returns either a single SelectStmt node or a tree of them,
4750
* representing a set-operation tree.
4752
* There is an ambiguity when a sub-SELECT is within an a_expr and there
4753
* are excess parentheses: do the parentheses belong to the sub-SELECT or
4754
* to the surrounding a_expr? We don't really care, but yacc wants to know.
4755
* To resolve the ambiguity, we are careful to define the grammar so that
4756
* the decision is staved off as long as possible: as long as we can keep
4757
* absorbing parentheses into the sub-SELECT, we will do so, and only when
4758
* it's no longer possible to do that will we decide that parens belong to
4759
* the expression. For example, in "SELECT (((SELECT 2)) + 3)" the extra
4760
* parentheses are treated as part of the sub-select. The necessity of doing
4761
* it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)". Had we
4762
* parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
4763
* SELECT viewpoint when we see the UNION.
4765
* This approach is implemented by defining a nonterminal select_with_parens,
4766
* which represents a SELECT with at least one outer layer of parentheses,
4767
* and being careful to use select_with_parens, never '(' SelectStmt ')',
4768
* in the expression grammar. We will then have shift-reduce conflicts
4769
* which we can resolve in favor of always treating '(' <select> ')' as
4770
* a select_with_parens. To resolve the conflicts, the productions that
4771
* conflict with the select_with_parens productions are manually given
4772
* precedences lower than the precedence of ')', thereby ensuring that we
4773
* shift ')' (and then reduce to select_with_parens) rather than trying to
4774
* reduce the inner <select> nonterminal to something else. We use UMINUS
4775
* precedence for this, which is a fairly arbitrary choice.
4777
* To be able to define select_with_parens itself without ambiguity, we need
4778
* a nonterminal select_no_parens that represents a SELECT structure with no
4779
* outermost parentheses. This is a little bit tedious, but it works.
4781
* In non-expression contexts, we use SelectStmt which can represent a SELECT
4782
* with or without outer parentheses.
4785
SelectStmt: select_no_parens %prec UMINUS
4786
| select_with_parens %prec UMINUS
4790
'(' select_no_parens ')' { $$ = $2; }
4791
| '(' select_with_parens ')' { $$ = $2; }
4795
* FOR UPDATE may be before or after LIMIT/OFFSET.
4796
* In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
4797
* We now support both orderings, but prefer LIMIT/OFFSET before FOR UPDATE
4801
simple_select { $$ = $1; }
4802
| select_clause sort_clause
4804
insertSelectOptions((SelectStmt *) $1, $2, NIL,
4808
| select_clause opt_sort_clause for_update_clause opt_select_limit
4810
insertSelectOptions((SelectStmt *) $1, $2, $3,
4811
list_nth($4, 0), list_nth($4, 1));
4814
| select_clause opt_sort_clause select_limit opt_for_update_clause
4816
insertSelectOptions((SelectStmt *) $1, $2, $4,
4817
list_nth($3, 0), list_nth($3, 1));
4823
simple_select { $$ = $1; }
4824
| select_with_parens { $$ = $1; }
4828
* This rule parses SELECT statements that can appear within set operations,
4829
* including UNION, INTERSECT and EXCEPT. '(' and ')' can be used to specify
4830
* the ordering of the set operations. Without '(' and ')' we want the
4831
* operations to be ordered per the precedence specs at the head of this file.
4833
* As with select_no_parens, simple_select cannot have outer parentheses,
4834
* but can have parenthesized subclauses.
4836
* Note that sort clauses cannot be included at this level --- SQL92 requires
4837
* SELECT foo UNION SELECT bar ORDER BY baz
4839
* (SELECT foo UNION SELECT bar) ORDER BY baz
4841
* SELECT foo UNION (SELECT bar ORDER BY baz)
4842
* Likewise FOR UPDATE and LIMIT. Therefore, those clauses are described
4843
* as part of the select_no_parens production, not simple_select.
4844
* This does not limit functionality, because you can reintroduce sort and
4845
* limit clauses inside parentheses.
4847
* NOTE: only the leftmost component SelectStmt should have INTO.
4848
* However, this is not checked by the grammar; parse analysis must check it.
4851
SELECT opt_distinct target_list
4852
into_clause from_clause where_clause
4853
group_clause having_clause
4855
SelectStmt *n = makeNode(SelectStmt);
4856
n->distinctClause = $2;
4859
n->intoColNames = NIL;
4860
n->intoHasOids = DEFAULT_OIDS;
4862
n->whereClause = $6;
4863
n->groupClause = $7;
4864
n->havingClause = $8;
4867
| select_clause UNION opt_all select_clause
4869
$$ = makeSetOp(SETOP_UNION, $3, $1, $4);
4871
| select_clause INTERSECT opt_all select_clause
4873
$$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
4875
| select_clause EXCEPT opt_all select_clause
4877
$$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
4882
INTO OptTempTableName { $$ = $2; }
4883
| /*EMPTY*/ { $$ = NULL; }
4887
* Redundancy here is needed to avoid shift/reduce conflicts,
4888
* since TEMP is not a reserved word. See also OptTemp.
4891
TEMPORARY opt_table qualified_name
4896
| TEMP opt_table qualified_name
4901
| LOCAL TEMPORARY opt_table qualified_name
4906
| LOCAL TEMP opt_table qualified_name
4911
| GLOBAL TEMPORARY opt_table qualified_name
4916
| GLOBAL TEMP opt_table qualified_name
4921
| TABLE qualified_name
4937
opt_all: ALL { $$ = TRUE; }
4938
| DISTINCT { $$ = FALSE; }
4939
| /*EMPTY*/ { $$ = FALSE; }
4942
/* We use (NIL) as a placeholder to indicate that all target expressions
4943
* should be placed in the DISTINCT list during parsetree analysis.
4946
DISTINCT { $$ = list_make1(NIL); }
4947
| DISTINCT ON '(' expr_list ')' { $$ = $4; }
4949
| /*EMPTY*/ { $$ = NIL; }
4953
sort_clause { $$ = $1;}
4954
| /*EMPTY*/ { $$ = NIL; }
4958
ORDER BY sortby_list { $$ = $3; }
4962
sortby { $$ = list_make1($1); }
4963
| sortby_list ',' sortby { $$ = lappend($1, $3); }
4966
sortby: a_expr USING qual_all_Op
4968
$$ = makeNode(SortBy);
4970
$$->sortby_kind = SORTBY_USING;
4975
$$ = makeNode(SortBy);
4977
$$->sortby_kind = SORTBY_ASC;
4982
$$ = makeNode(SortBy);
4984
$$->sortby_kind = SORTBY_DESC;
4989
$$ = makeNode(SortBy);
4991
$$->sortby_kind = SORTBY_ASC; /* default */
4998
LIMIT select_limit_value OFFSET select_offset_value
4999
{ $$ = list_make2($4, $2); }
5000
| OFFSET select_offset_value LIMIT select_limit_value
5001
{ $$ = list_make2($2, $4); }
5002
| LIMIT select_limit_value
5003
{ $$ = list_make2(NULL, $2); }
5004
| OFFSET select_offset_value
5005
{ $$ = list_make2($2, NULL); }
5006
| LIMIT select_limit_value ',' select_offset_value
5008
/* Disabled because it was too confusing, bjm 2002-02-18 */
5010
(errcode(ERRCODE_SYNTAX_ERROR),
5011
errmsg("LIMIT #,# syntax is not supported"),
5012
errhint("Use separate LIMIT and OFFSET clauses.")));
5017
select_limit { $$ = $1; }
5019
{ $$ = list_make2(NULL,NULL); }
5026
/* LIMIT ALL is represented as a NULL constant */
5027
A_Const *n = makeNode(A_Const);
5028
n->val.type = T_Null;
5033
select_offset_value:
5038
* jimmy bell-style recursive queries aren't supported in the
5041
* ...however, recursive addattr and rename supported. make special
5046
GROUP_P BY expr_list { $$ = $3; }
5047
| /*EMPTY*/ { $$ = NIL; }
5051
HAVING a_expr { $$ = $2; }
5052
| /*EMPTY*/ { $$ = NULL; }
5056
FOR UPDATE update_list { $$ = $3; }
5057
| FOR READ ONLY { $$ = NULL; }
5060
opt_for_update_clause:
5061
for_update_clause { $$ = $1; }
5062
| /* EMPTY */ { $$ = NULL; }
5066
OF name_list { $$ = $2; }
5067
| /* EMPTY */ { $$ = list_make1(NULL); }
5070
/*****************************************************************************
5072
* clauses common to all Optimizable Stmts:
5073
* from_clause - allow list of both JOIN expressions and table names
5074
* where_clause - qualifications for joins or restrictions
5076
*****************************************************************************/
5079
FROM from_list { $$ = $2; }
5080
| /*EMPTY*/ { $$ = NIL; }
5084
table_ref { $$ = list_make1($1); }
5085
| from_list ',' table_ref { $$ = lappend($1, $3); }
5089
* table_ref is where an alias clause can be attached. Note we cannot make
5090
* alias_clause have an empty production because that causes parse conflicts
5091
* between table_ref := '(' joined_table ')' alias_clause
5092
* and joined_table := '(' joined_table ')'. So, we must have the
5093
* redundant-looking productions here instead.
5095
table_ref: relation_expr
5099
| relation_expr alias_clause
5106
RangeFunction *n = makeNode(RangeFunction);
5107
n->funccallnode = $1;
5108
n->coldeflist = NIL;
5111
| func_table alias_clause
5113
RangeFunction *n = makeNode(RangeFunction);
5114
n->funccallnode = $1;
5116
n->coldeflist = NIL;
5119
| func_table AS '(' TableFuncElementList ')'
5121
RangeFunction *n = makeNode(RangeFunction);
5122
n->funccallnode = $1;
5126
| func_table AS ColId '(' TableFuncElementList ')'
5128
RangeFunction *n = makeNode(RangeFunction);
5129
Alias *a = makeNode(Alias);
5130
n->funccallnode = $1;
5136
| func_table ColId '(' TableFuncElementList ')'
5138
RangeFunction *n = makeNode(RangeFunction);
5139
Alias *a = makeNode(Alias);
5140
n->funccallnode = $1;
5146
| select_with_parens
5149
* The SQL spec does not permit a subselect
5150
* (<derived_table>) without an alias clause,
5151
* so we don't either. This avoids the problem
5152
* of needing to invent a unique refname for it.
5153
* That could be surmounted if there's sufficient
5154
* popular demand, but for now let's just implement
5155
* the spec and see if anyone complains.
5156
* However, it does seem like a good idea to emit
5157
* an error message that's better than "syntax error".
5160
(errcode(ERRCODE_SYNTAX_ERROR),
5161
errmsg("subquery in FROM must have an alias"),
5162
errhint("For example, FROM (SELECT ...) [AS] foo.")));
5165
| select_with_parens alias_clause
5167
RangeSubselect *n = makeNode(RangeSubselect);
5176
| '(' joined_table ')' alias_clause
5185
* It may seem silly to separate joined_table from table_ref, but there is
5186
* method in SQL92's madness: if you don't do it this way you get reduce-
5187
* reduce conflicts, because it's not clear to the parser generator whether
5188
* to expect alias_clause after ')' or not. For the same reason we must
5189
* treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
5190
* join_type to expand to empty; if we try it, the parser generator can't
5191
* figure out when to reduce an empty join_type right after table_ref.
5193
* Note that a CROSS JOIN is the same as an unqualified
5194
* INNER JOIN, and an INNER JOIN/ON has the same shape
5195
* but a qualification expression to limit membership.
5196
* A NATURAL JOIN implicitly matches column names between
5197
* tables and the shape is determined by which columns are
5198
* in common. We'll collect columns during the later transformations.
5202
'(' joined_table ')'
5206
| table_ref CROSS JOIN table_ref
5208
/* CROSS JOIN is same as unqualified inner join */
5209
JoinExpr *n = makeNode(JoinExpr);
5210
n->jointype = JOIN_INNER;
5211
n->isNatural = FALSE;
5218
| table_ref UNIONJOIN table_ref
5220
/* UNION JOIN is made into 1 token to avoid shift/reduce
5221
* conflict against regular UNION keyword.
5223
JoinExpr *n = makeNode(JoinExpr);
5224
n->jointype = JOIN_UNION;
5225
n->isNatural = FALSE;
5232
| table_ref join_type JOIN table_ref join_qual
5234
JoinExpr *n = makeNode(JoinExpr);
5236
n->isNatural = FALSE;
5239
if ($5 != NULL && IsA($5, List))
5240
n->using = (List *) $5; /* USING clause */
5242
n->quals = $5; /* ON clause */
5245
| table_ref JOIN table_ref join_qual
5247
/* letting join_type reduce to empty doesn't work */
5248
JoinExpr *n = makeNode(JoinExpr);
5249
n->jointype = JOIN_INNER;
5250
n->isNatural = FALSE;
5253
if ($4 != NULL && IsA($4, List))
5254
n->using = (List *) $4; /* USING clause */
5256
n->quals = $4; /* ON clause */
5259
| table_ref NATURAL join_type JOIN table_ref
5261
JoinExpr *n = makeNode(JoinExpr);
5263
n->isNatural = TRUE;
5266
n->using = NIL; /* figure out which columns later... */
5267
n->quals = NULL; /* fill later */
5270
| table_ref NATURAL JOIN table_ref
5272
/* letting join_type reduce to empty doesn't work */
5273
JoinExpr *n = makeNode(JoinExpr);
5274
n->jointype = JOIN_INNER;
5275
n->isNatural = TRUE;
5278
n->using = NIL; /* figure out which columns later... */
5279
n->quals = NULL; /* fill later */
5285
AS ColId '(' name_list ')'
5287
$$ = makeNode(Alias);
5293
$$ = makeNode(Alias);
5296
| ColId '(' name_list ')'
5298
$$ = makeNode(Alias);
5304
$$ = makeNode(Alias);
5309
join_type: FULL join_outer { $$ = JOIN_FULL; }
5310
| LEFT join_outer { $$ = JOIN_LEFT; }
5311
| RIGHT join_outer { $$ = JOIN_RIGHT; }
5312
| INNER_P { $$ = JOIN_INNER; }
5315
/* OUTER is just noise... */
5316
join_outer: OUTER_P { $$ = NULL; }
5317
| /*EMPTY*/ { $$ = NULL; }
5320
/* JOIN qualification clauses
5321
* Possibilities are:
5322
* USING ( column list ) allows only unqualified column names,
5323
* which must match between tables.
5324
* ON expr allows more general qualifications.
5326
* We return USING as a List node, while an ON-expr will not be a List.
5329
join_qual: USING '(' name_list ')' { $$ = (Node *) $3; }
5330
| ON a_expr { $$ = $2; }
5337
/* default inheritance */
5339
$$->inhOpt = INH_DEFAULT;
5342
| qualified_name '*'
5344
/* inheritance query */
5346
$$->inhOpt = INH_YES;
5349
| ONLY qualified_name
5351
/* no inheritance */
5353
$$->inhOpt = INH_NO;
5356
| ONLY '(' qualified_name ')'
5358
/* no inheritance, SQL99-style syntax */
5360
$$->inhOpt = INH_NO;
5366
func_table: func_expr { $$ = $1; }
5371
WHERE a_expr { $$ = $2; }
5372
| /*EMPTY*/ { $$ = NULL; }
5376
TableFuncElementList:
5379
$$ = list_make1($1);
5381
| TableFuncElementList ',' TableFuncElement
5383
$$ = lappend($1, $3);
5387
TableFuncElement: ColId Typename
5389
ColumnDef *n = makeNode(ColumnDef);
5392
n->constraints = NIL;
5398
/*****************************************************************************
5401
* SQL92 introduces a large amount of type-specific syntax.
5402
* Define individual clauses to handle these cases, and use
5403
* the generic case to handle regular type-extensible Postgres syntax.
5404
* - thomas 1997-10-10
5406
*****************************************************************************/
5408
Typename: SimpleTypename opt_array_bounds
5411
$$->arrayBounds = $2;
5413
| SETOF SimpleTypename opt_array_bounds
5416
$$->arrayBounds = $3;
5419
| SimpleTypename ARRAY '[' Iconst ']'
5421
/* SQL99's redundant syntax */
5423
$$->arrayBounds = list_make1(makeInteger($4));
5425
| SETOF SimpleTypename ARRAY '[' Iconst ']'
5427
/* SQL99's redundant syntax */
5429
$$->arrayBounds = list_make1(makeInteger($5));
5435
opt_array_bounds '[' ']'
5436
{ $$ = lappend($1, makeInteger(-1)); }
5437
| opt_array_bounds '[' Iconst ']'
5438
{ $$ = lappend($1, makeInteger($3)); }
5444
* XXX ideally, the production for a qualified typename should be ColId attrs
5445
* (there's no obvious reason why the first name should need to be restricted)
5446
* and should be an alternative of GenericType (so that it can be used to
5447
* specify a type for a literal in AExprConst). However doing either causes
5448
* reduce/reduce conflicts that I haven't been able to find a workaround
5452
GenericType { $$ = $1; }
5453
| Numeric { $$ = $1; }
5455
| Character { $$ = $1; }
5456
| ConstDatetime { $$ = $1; }
5457
| ConstInterval opt_interval
5460
if ($2 != INTERVAL_FULL_RANGE)
5461
$$->typmod = INTERVAL_TYPMOD(INTERVAL_FULL_PRECISION, $2);
5463
| ConstInterval '(' Iconst ')' opt_interval
5468
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5469
errmsg("INTERVAL(%d) precision must not be negative",
5471
if ($3 > MAX_INTERVAL_PRECISION)
5474
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5475
errmsg("INTERVAL(%d) precision reduced to maximum allowed, %d",
5476
$3, MAX_INTERVAL_PRECISION)));
5477
$3 = MAX_INTERVAL_PRECISION;
5479
$$->typmod = INTERVAL_TYPMOD($3, $5);
5483
$$ = makeNode(TypeName);
5484
$$->names = lcons(makeString($1), $2);
5489
/* We have a separate ConstTypename to allow defaulting fixed-length
5490
* types such as CHAR() and BIT() to an unspecified length.
5491
* SQL9x requires that these default to a length of one, but this
5492
* makes no sense for constructs like CHAR 'hi' and BIT '0101',
5493
* where there is an obvious better choice to make.
5494
* Note that ConstInterval is not included here since it must
5495
* be pushed up higher in the rules to accomodate the postfix
5496
* options (e.g. INTERVAL '1' YEAR).
5499
GenericType { $$ = $1; }
5500
| Numeric { $$ = $1; }
5501
| ConstBit { $$ = $1; }
5502
| ConstCharacter { $$ = $1; }
5503
| ConstDatetime { $$ = $1; }
5509
$$ = makeTypeName($1);
5513
/* SQL92 numeric data types
5514
* Check FLOAT() precision limits assuming IEEE floating types.
5515
* - thomas 1997-09-18
5516
* Provide real DECIMAL() and NUMERIC() implementations now - Jan 1998-12-30
5520
$$ = SystemTypeName("int4");
5524
$$ = SystemTypeName("int4");
5528
$$ = SystemTypeName("int2");
5532
$$ = SystemTypeName("int8");
5536
$$ = SystemTypeName("float4");
5542
| DOUBLE_P PRECISION
5544
$$ = SystemTypeName("float8");
5546
| DECIMAL_P opt_decimal
5548
$$ = SystemTypeName("numeric");
5553
$$ = SystemTypeName("numeric");
5556
| NUMERIC opt_numeric
5558
$$ = SystemTypeName("numeric");
5563
$$ = SystemTypeName("bool");
5567
opt_float: '(' Iconst ')'
5571
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5572
errmsg("precision for type float must be at least 1 bit")));
5574
$$ = SystemTypeName("float4");
5576
$$ = SystemTypeName("float8");
5579
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5580
errmsg("precision for type float must be less than 54 bits")));
5584
$$ = SystemTypeName("float8");
5589
'(' Iconst ',' Iconst ')'
5591
if ($2 < 1 || $2 > NUMERIC_MAX_PRECISION)
5593
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5594
errmsg("NUMERIC precision %d must be between 1 and %d",
5595
$2, NUMERIC_MAX_PRECISION)));
5596
if ($4 < 0 || $4 > $2)
5598
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5599
errmsg("NUMERIC scale %d must be between 0 and precision %d",
5602
$$ = (($2 << 16) | $4) + VARHDRSZ;
5606
if ($2 < 1 || $2 > NUMERIC_MAX_PRECISION)
5608
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5609
errmsg("NUMERIC precision %d must be between 1 and %d",
5610
$2, NUMERIC_MAX_PRECISION)));
5612
$$ = ($2 << 16) + VARHDRSZ;
5616
/* Insert "-1" meaning "no limit" */
5622
'(' Iconst ',' Iconst ')'
5624
if ($2 < 1 || $2 > NUMERIC_MAX_PRECISION)
5626
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5627
errmsg("DECIMAL precision %d must be between 1 and %d",
5628
$2, NUMERIC_MAX_PRECISION)));
5629
if ($4 < 0 || $4 > $2)
5631
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5632
errmsg("DECIMAL scale %d must be between 0 and precision %d",
5635
$$ = (($2 << 16) | $4) + VARHDRSZ;
5639
if ($2 < 1 || $2 > NUMERIC_MAX_PRECISION)
5641
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5642
errmsg("DECIMAL precision %d must be between 1 and %d",
5643
$2, NUMERIC_MAX_PRECISION)));
5645
$$ = ($2 << 16) + VARHDRSZ;
5649
/* Insert "-1" meaning "no limit" */
5656
* SQL92 bit-field data types
5657
* The following implements BIT() and BIT VARYING().
5669
/* ConstBit is like Bit except "BIT" defaults to unspecified length */
5670
/* See notes for ConstCharacter, which addresses same issue for "CHAR" */
5671
ConstBit: BitWithLength
5683
BIT opt_varying '(' Iconst ')'
5687
typname = $2 ? "varbit" : "bit";
5688
$$ = SystemTypeName(typname);
5691
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5692
errmsg("length for type %s must be at least 1",
5694
else if ($4 > (MaxAttrSize * BITS_PER_BYTE))
5696
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5697
errmsg("length for type %s cannot exceed %d",
5698
typname, MaxAttrSize * BITS_PER_BYTE)));
5706
/* bit defaults to bit(1), varbit to no limit */
5709
$$ = SystemTypeName("varbit");
5714
$$ = SystemTypeName("bit");
5722
* SQL92 character data types
5723
* The following implements CHAR() and VARCHAR().
5725
Character: CharacterWithLength
5729
| CharacterWithoutLength
5735
ConstCharacter: CharacterWithLength
5739
| CharacterWithoutLength
5741
/* Length was not specified so allow to be unrestricted.
5742
* This handles problems with fixed-length (bpchar) strings
5743
* which in column definitions must default to a length
5744
* of one, but should not be constrained if the length
5745
* was not specified.
5752
CharacterWithLength: character '(' Iconst ')' opt_charset
5754
if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
5758
type = palloc(strlen($1) + 1 + strlen($5) + 1);
5765
$$ = SystemTypeName($1);
5769
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5770
errmsg("length for type %s must be at least 1",
5772
else if ($3 > MaxAttrSize)
5774
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5775
errmsg("length for type %s cannot exceed %d",
5778
/* we actually implement these like a varlen, so
5779
* the first 4 bytes is the length. (the difference
5780
* between these and "text" is that we blank-pad and
5781
* truncate where necessary)
5783
$$->typmod = VARHDRSZ + $3;
5787
CharacterWithoutLength: character opt_charset
5789
if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
5793
type = palloc(strlen($1) + 1 + strlen($2) + 1);
5800
$$ = SystemTypeName($1);
5802
/* char defaults to char(1), varchar to no limit */
5803
if (strcmp($1, "bpchar") == 0)
5804
$$->typmod = VARHDRSZ + 1;
5810
character: CHARACTER opt_varying
5811
{ $$ = $2 ? "varchar": "bpchar"; }
5812
| CHAR_P opt_varying
5813
{ $$ = $2 ? "varchar": "bpchar"; }
5816
| NATIONAL CHARACTER opt_varying
5817
{ $$ = $3 ? "varchar": "bpchar"; }
5818
| NATIONAL CHAR_P opt_varying
5819
{ $$ = $3 ? "varchar": "bpchar"; }
5821
{ $$ = $2 ? "varchar": "bpchar"; }
5825
VARYING { $$ = TRUE; }
5826
| /*EMPTY*/ { $$ = FALSE; }
5830
CHARACTER SET ColId { $$ = $3; }
5831
| /*EMPTY*/ { $$ = NULL; }
5835
TIMESTAMP '(' Iconst ')' opt_timezone
5838
$$ = SystemTypeName("timestamptz");
5840
$$ = SystemTypeName("timestamp");
5841
/* XXX the timezone field seems to be unused
5842
* - thomas 2001-09-06
5847
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5848
errmsg("TIMESTAMP(%d)%s precision must not be negative",
5849
$3, ($5 ? " WITH TIME ZONE": ""))));
5850
if ($3 > MAX_TIMESTAMP_PRECISION)
5853
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5854
errmsg("TIMESTAMP(%d)%s precision reduced to maximum allowed, %d",
5855
$3, ($5 ? " WITH TIME ZONE": ""),
5856
MAX_TIMESTAMP_PRECISION)));
5857
$3 = MAX_TIMESTAMP_PRECISION;
5861
| TIMESTAMP opt_timezone
5864
$$ = SystemTypeName("timestamptz");
5866
$$ = SystemTypeName("timestamp");
5867
/* XXX the timezone field seems to be unused
5868
* - thomas 2001-09-06
5871
/* SQL99 specified a default precision of six
5872
* for schema definitions. But for timestamp
5873
* literals we don't want to throw away precision
5874
* so leave this as unspecified for now.
5875
* Later, we may want a different production
5876
* for schemas. - thomas 2001-12-07
5880
| TIME '(' Iconst ')' opt_timezone
5883
$$ = SystemTypeName("timetz");
5885
$$ = SystemTypeName("time");
5888
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5889
errmsg("TIME(%d)%s precision must not be negative",
5890
$3, ($5 ? " WITH TIME ZONE": ""))));
5891
if ($3 > MAX_TIME_PRECISION)
5894
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5895
errmsg("TIME(%d)%s precision reduced to maximum allowed, %d",
5896
$3, ($5 ? " WITH TIME ZONE": ""),
5897
MAX_TIME_PRECISION)));
5898
$3 = MAX_TIME_PRECISION;
5905
$$ = SystemTypeName("timetz");
5907
$$ = SystemTypeName("time");
5908
/* SQL99 specified a default precision of zero.
5909
* See comments for timestamp above on why we will
5910
* leave this unspecified for now. - thomas 2001-12-07
5917
INTERVAL { $$ = SystemTypeName("interval"); }
5921
WITH TIME ZONE { $$ = TRUE; }
5922
| WITHOUT TIME ZONE { $$ = FALSE; }
5923
| /*EMPTY*/ { $$ = FALSE; }
5927
YEAR_P { $$ = INTERVAL_MASK(YEAR); }
5928
| MONTH_P { $$ = INTERVAL_MASK(MONTH); }
5929
| DAY_P { $$ = INTERVAL_MASK(DAY); }
5930
| HOUR_P { $$ = INTERVAL_MASK(HOUR); }
5931
| MINUTE_P { $$ = INTERVAL_MASK(MINUTE); }
5932
| SECOND_P { $$ = INTERVAL_MASK(SECOND); }
5934
{ $$ = INTERVAL_MASK(YEAR) | INTERVAL_MASK(MONTH); }
5936
{ $$ = INTERVAL_MASK(DAY) | INTERVAL_MASK(HOUR); }
5938
{ $$ = INTERVAL_MASK(DAY) | INTERVAL_MASK(HOUR)
5939
| INTERVAL_MASK(MINUTE); }
5941
{ $$ = INTERVAL_MASK(DAY) | INTERVAL_MASK(HOUR)
5942
| INTERVAL_MASK(MINUTE) | INTERVAL_MASK(SECOND); }
5943
| HOUR_P TO MINUTE_P
5944
{ $$ = INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE); }
5945
| HOUR_P TO SECOND_P
5946
{ $$ = INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE)
5947
| INTERVAL_MASK(SECOND); }
5948
| MINUTE_P TO SECOND_P
5949
{ $$ = INTERVAL_MASK(MINUTE) | INTERVAL_MASK(SECOND); }
5950
| /*EMPTY*/ { $$ = INTERVAL_FULL_RANGE; }
5954
/*****************************************************************************
5956
* expression grammar
5958
*****************************************************************************/
5961
* General expressions
5962
* This is the heart of the expression syntax.
5964
* We have two expression types: a_expr is the unrestricted kind, and
5965
* b_expr is a subset that must be used in some places to avoid shift/reduce
5966
* conflicts. For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
5967
* because that use of AND conflicts with AND as a boolean operator. So,
5968
* b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
5970
* Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
5971
* always be used by surrounding it with parens.
5973
* c_expr is all the productions that are common to a_expr and b_expr;
5974
* it's factored out just to eliminate redundant coding.
5976
a_expr: c_expr { $$ = $1; }
5977
| a_expr TYPECAST Typename
5978
{ $$ = makeTypeCast($1, $3); }
5979
| a_expr AT TIME ZONE c_expr
5981
FuncCall *n = makeNode(FuncCall);
5982
n->funcname = SystemFuncName("timezone");
5983
n->args = list_make2($5, $1);
5984
n->agg_star = FALSE;
5985
n->agg_distinct = FALSE;
5989
* These operators must be called out explicitly in order to make use
5990
* of yacc/bison's automatic operator-precedence handling. All other
5991
* operator names are handled by the generic productions using "Op",
5992
* below; and all those operators will have the same precedence.
5994
* If you add more explicitly-known operators, be sure to add them
5995
* also to b_expr and to the MathOp list above.
5997
| '+' a_expr %prec UMINUS
5998
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2); }
5999
| '-' a_expr %prec UMINUS
6000
{ $$ = doNegate($2); }
6002
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", NULL, $2); }
6004
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", NULL, $2); }
6006
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, NULL); }
6008
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, NULL); }
6010
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3); }
6012
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3); }
6014
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3); }
6016
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3); }
6018
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3); }
6020
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3); }
6022
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3); }
6024
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3); }
6026
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3); }
6028
| a_expr qual_Op a_expr %prec Op
6029
{ $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3); }
6030
| qual_Op a_expr %prec Op
6031
{ $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2); }
6032
| a_expr qual_Op %prec POSTFIXOP
6033
{ $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL); }
6036
{ $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3); }
6038
{ $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3); }
6040
{ $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2); }
6042
| a_expr LIKE a_expr
6043
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3); }
6044
| a_expr LIKE a_expr ESCAPE a_expr
6046
FuncCall *n = makeNode(FuncCall);
6047
n->funcname = SystemFuncName("like_escape");
6048
n->args = list_make2($3, $5);
6049
n->agg_star = FALSE;
6050
n->agg_distinct = FALSE;
6051
$$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n);
6053
| a_expr NOT LIKE a_expr
6054
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4); }
6055
| a_expr NOT LIKE a_expr ESCAPE a_expr
6057
FuncCall *n = makeNode(FuncCall);
6058
n->funcname = SystemFuncName("like_escape");
6059
n->args = list_make2($4, $6);
6060
n->agg_star = FALSE;
6061
n->agg_distinct = FALSE;
6062
$$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n);
6064
| a_expr ILIKE a_expr
6065
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3); }
6066
| a_expr ILIKE a_expr ESCAPE a_expr
6068
FuncCall *n = makeNode(FuncCall);
6069
n->funcname = SystemFuncName("like_escape");
6070
n->args = list_make2($3, $5);
6071
n->agg_star = FALSE;
6072
n->agg_distinct = FALSE;
6073
$$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n);
6075
| a_expr NOT ILIKE a_expr
6076
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4); }
6077
| a_expr NOT ILIKE a_expr ESCAPE a_expr
6079
FuncCall *n = makeNode(FuncCall);
6080
n->funcname = SystemFuncName("like_escape");
6081
n->args = list_make2($4, $6);
6082
n->agg_star = FALSE;
6083
n->agg_distinct = FALSE;
6084
$$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n);
6087
| a_expr SIMILAR TO a_expr %prec SIMILAR
6089
A_Const *c = makeNode(A_Const);
6090
FuncCall *n = makeNode(FuncCall);
6091
c->val.type = T_Null;
6092
n->funcname = SystemFuncName("similar_escape");
6093
n->args = list_make2($4, (Node *) c);
6094
n->agg_star = FALSE;
6095
n->agg_distinct = FALSE;
6096
$$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n);
6098
| a_expr SIMILAR TO a_expr ESCAPE a_expr
6100
FuncCall *n = makeNode(FuncCall);
6101
n->funcname = SystemFuncName("similar_escape");
6102
n->args = list_make2($4, $6);
6103
n->agg_star = FALSE;
6104
n->agg_distinct = FALSE;
6105
$$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n);
6107
| a_expr NOT SIMILAR TO a_expr %prec SIMILAR
6109
A_Const *c = makeNode(A_Const);
6110
FuncCall *n = makeNode(FuncCall);
6111
c->val.type = T_Null;
6112
n->funcname = SystemFuncName("similar_escape");
6113
n->args = list_make2($5, (Node *) c);
6114
n->agg_star = FALSE;
6115
n->agg_distinct = FALSE;
6116
$$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n);
6118
| a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
6120
FuncCall *n = makeNode(FuncCall);
6121
n->funcname = SystemFuncName("similar_escape");
6122
n->args = list_make2($5, $7);
6123
n->agg_star = FALSE;
6124
n->agg_distinct = FALSE;
6125
$$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n);
6129
* Define SQL92-style Null test clause.
6130
* Allow two forms described in the standard:
6133
* Allow two SQL extensions
6139
if (IsA($1, RowExpr))
6140
$$ = makeRowNullTest(IS_NULL, (RowExpr *) $1);
6143
NullTest *n = makeNode(NullTest);
6144
n->arg = (Expr *) $1;
6145
n->nulltesttype = IS_NULL;
6151
if (IsA($1, RowExpr))
6152
$$ = makeRowNullTest(IS_NULL, (RowExpr *) $1);
6155
NullTest *n = makeNode(NullTest);
6156
n->arg = (Expr *) $1;
6157
n->nulltesttype = IS_NULL;
6163
if (IsA($1, RowExpr))
6164
$$ = makeRowNullTest(IS_NOT_NULL, (RowExpr *) $1);
6167
NullTest *n = makeNode(NullTest);
6168
n->arg = (Expr *) $1;
6169
n->nulltesttype = IS_NOT_NULL;
6173
| a_expr IS NOT NULL_P
6175
if (IsA($1, RowExpr))
6176
$$ = makeRowNullTest(IS_NOT_NULL, (RowExpr *) $1);
6179
NullTest *n = makeNode(NullTest);
6180
n->arg = (Expr *) $1;
6181
n->nulltesttype = IS_NOT_NULL;
6187
$$ = (Node *)makeOverlaps($1, $3);
6191
BooleanTest *b = makeNode(BooleanTest);
6192
b->arg = (Expr *) $1;
6193
b->booltesttype = IS_TRUE;
6196
| a_expr IS NOT TRUE_P
6198
BooleanTest *b = makeNode(BooleanTest);
6199
b->arg = (Expr *) $1;
6200
b->booltesttype = IS_NOT_TRUE;
6205
BooleanTest *b = makeNode(BooleanTest);
6206
b->arg = (Expr *) $1;
6207
b->booltesttype = IS_FALSE;
6210
| a_expr IS NOT FALSE_P
6212
BooleanTest *b = makeNode(BooleanTest);
6213
b->arg = (Expr *) $1;
6214
b->booltesttype = IS_NOT_FALSE;
6219
BooleanTest *b = makeNode(BooleanTest);
6220
b->arg = (Expr *) $1;
6221
b->booltesttype = IS_UNKNOWN;
6224
| a_expr IS NOT UNKNOWN
6226
BooleanTest *b = makeNode(BooleanTest);
6227
b->arg = (Expr *) $1;
6228
b->booltesttype = IS_NOT_UNKNOWN;
6231
| a_expr IS DISTINCT FROM a_expr %prec IS
6233
$$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5);
6235
| a_expr IS OF '(' type_list ')' %prec IS
6237
$$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5);
6239
| a_expr IS NOT OF '(' type_list ')' %prec IS
6241
$$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "!=", $1, (Node *) $6);
6243
| a_expr BETWEEN b_expr AND b_expr %prec BETWEEN
6245
$$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
6246
(Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3),
6247
(Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $5));
6249
| a_expr NOT BETWEEN b_expr AND b_expr %prec BETWEEN
6251
$$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
6252
(Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $4),
6253
(Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $6));
6255
| a_expr IN_P in_expr
6257
/* in_expr returns a SubLink or a list of a_exprs */
6258
if (IsA($3, SubLink))
6260
SubLink *n = (SubLink *)$3;
6261
n->subLinkType = ANY_SUBLINK;
6262
if (IsA($1, RowExpr))
6263
n->lefthand = ((RowExpr *) $1)->args;
6265
n->lefthand = list_make1($1);
6266
n->operName = list_make1(makeString("="));
6273
foreach(l, (List *) $3)
6276
cmp = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, lfirst(l));
6280
n = (Node *) makeA_Expr(AEXPR_OR, NIL, n, cmp);
6285
| a_expr NOT IN_P in_expr
6287
/* in_expr returns a SubLink or a list of a_exprs */
6288
if (IsA($4, SubLink))
6290
/* Make an IN node */
6291
SubLink *n = (SubLink *)$4;
6292
n->subLinkType = ANY_SUBLINK;
6293
if (IsA($1, RowExpr))
6294
n->lefthand = ((RowExpr *) $1)->args;
6296
n->lefthand = list_make1($1);
6297
n->operName = list_make1(makeString("="));
6298
/* Stick a NOT on top */
6299
$$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n);
6305
foreach(l, (List *) $4)
6308
cmp = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, lfirst(l));
6312
n = (Node *) makeA_Expr(AEXPR_AND, NIL, n, cmp);
6317
| a_expr subquery_Op sub_type select_with_parens %prec Op
6319
SubLink *n = makeNode(SubLink);
6320
n->subLinkType = $3;
6321
if (IsA($1, RowExpr))
6322
n->lefthand = ((RowExpr *) $1)->args;
6324
n->lefthand = list_make1($1);
6329
| a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
6331
if ($3 == ANY_SUBLINK)
6332
$$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5);
6334
$$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5);
6336
| UNIQUE select_with_parens %prec Op
6338
/* Not sure how to get rid of the parentheses
6339
* but there are lots of shift/reduce errors without them.
6341
* Should be able to implement this by plopping the entire
6342
* select into a node, then transforming the target expressions
6343
* from whatever they are into count(*), and testing the
6344
* entire result equal to one.
6345
* But, will probably implement a separate node in the executor.
6348
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6349
errmsg("UNIQUE predicate is not yet implemented")));
6354
* Restricted expressions
6356
* b_expr is a subset of the complete expression syntax defined by a_expr.
6358
* Presently, AND, NOT, IS, and IN are the a_expr keywords that would
6359
* cause trouble in the places where b_expr is used. For simplicity, we
6360
* just eliminate all the boolean-keyword-operator productions from b_expr.
6364
| b_expr TYPECAST Typename
6365
{ $$ = makeTypeCast($1, $3); }
6366
| '+' b_expr %prec UMINUS
6367
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2); }
6368
| '-' b_expr %prec UMINUS
6369
{ $$ = doNegate($2); }
6371
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", NULL, $2); }
6373
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", NULL, $2); }
6375
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, NULL); }
6377
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, NULL); }
6379
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3); }
6381
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3); }
6383
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3); }
6385
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3); }
6387
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3); }
6389
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3); }
6391
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3); }
6393
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3); }
6395
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3); }
6396
| b_expr qual_Op b_expr %prec Op
6397
{ $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3); }
6398
| qual_Op b_expr %prec Op
6399
{ $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2); }
6400
| b_expr qual_Op %prec POSTFIXOP
6401
{ $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL); }
6402
| b_expr IS DISTINCT FROM b_expr %prec IS
6404
$$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5);
6406
| b_expr IS OF '(' type_list ')' %prec IS
6408
$$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5);
6410
| b_expr IS NOT OF '(' type_list ')' %prec IS
6412
$$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "!=", $1, (Node *) $6);
6417
* Productions that can be used in both a_expr and b_expr.
6419
* Note: productions that refer recursively to a_expr or b_expr mostly
6420
* cannot appear here. However, it's OK to refer to a_exprs that occur
6421
* inside parentheses, such as function arguments; that cannot introduce
6422
* ambiguity to the b_expr syntax.
6424
c_expr: columnref { $$ = $1; }
6425
| AexprConst { $$ = $1; }
6426
| PARAM opt_indirection
6428
ParamRef *p = makeNode(ParamRef);
6432
A_Indirection *n = makeNode(A_Indirection);
6433
n->arg = (Node *) p;
6434
n->indirection = $2;
6440
| '(' a_expr ')' opt_indirection
6444
A_Indirection *n = makeNode(A_Indirection);
6446
n->indirection = $4;
6456
| select_with_parens %prec UMINUS
6458
SubLink *n = makeNode(SubLink);
6459
n->subLinkType = EXPR_SUBLINK;
6465
| EXISTS select_with_parens
6467
SubLink *n = makeNode(SubLink);
6468
n->subLinkType = EXISTS_SUBLINK;
6474
| ARRAY select_with_parens
6476
SubLink *n = makeNode(SubLink);
6477
n->subLinkType = ARRAY_SUBLINK;
6487
RowExpr *r = makeNode(RowExpr);
6489
r->row_typeid = InvalidOid; /* not analyzed yet */
6495
* func_expr is split out from c_expr just so that we have a classification
6496
* for "everything that is a function call or looks like one". This isn't
6497
* very important, but it saves us having to document which variants are
6498
* legal in the backwards-compatible functional-index syntax for CREATE INDEX.
6499
* (Note that many of the special SQL functions wouldn't actually make any
6500
* sense as functional index entries, but we ignore that consideration here.)
6502
func_expr: func_name '(' ')'
6504
FuncCall *n = makeNode(FuncCall);
6507
n->agg_star = FALSE;
6508
n->agg_distinct = FALSE;
6511
| func_name '(' expr_list ')'
6513
FuncCall *n = makeNode(FuncCall);
6516
n->agg_star = FALSE;
6517
n->agg_distinct = FALSE;
6520
| func_name '(' ALL expr_list ')'
6522
FuncCall *n = makeNode(FuncCall);
6525
n->agg_star = FALSE;
6526
n->agg_distinct = FALSE;
6527
/* Ideally we'd mark the FuncCall node to indicate
6528
* "must be an aggregate", but there's no provision
6529
* for that in FuncCall at the moment.
6533
| func_name '(' DISTINCT expr_list ')'
6535
FuncCall *n = makeNode(FuncCall);
6538
n->agg_star = FALSE;
6539
n->agg_distinct = TRUE;
6542
| func_name '(' '*' ')'
6545
* For now, we transform AGGREGATE(*) into AGGREGATE(1).
6547
* This does the right thing for COUNT(*) (in fact,
6548
* any certainly-non-null expression would do for COUNT),
6549
* and there are no other aggregates in SQL92 that accept
6552
* The FuncCall node is also marked agg_star = true,
6553
* so that later processing can detect what the argument
6556
FuncCall *n = makeNode(FuncCall);
6557
A_Const *star = makeNode(A_Const);
6559
star->val.type = T_Integer;
6560
star->val.val.ival = 1;
6562
n->args = list_make1(star);
6564
n->agg_distinct = FALSE;
6570
* Translate as "'now'::text::date".
6572
* We cannot use "'now'::date" because coerce_type() will
6573
* immediately reduce that to a constant representing
6574
* today's date. We need to delay the conversion until
6575
* runtime, else the wrong things will happen when
6576
* CURRENT_DATE is used in a column default value or rule.
6578
* This could be simplified if we had a way to generate
6579
* an expression tree representing runtime application
6580
* of type-input conversion functions...
6582
A_Const *s = makeNode(A_Const);
6585
s->val.type = T_String;
6586
s->val.val.str = "now";
6587
s->typename = SystemTypeName("text");
6589
d = SystemTypeName("date");
6591
$$ = (Node *)makeTypeCast((Node *)s, d);
6596
* Translate as "'now'::text::timetz".
6597
* See comments for CURRENT_DATE.
6599
A_Const *s = makeNode(A_Const);
6602
s->val.type = T_String;
6603
s->val.val.str = "now";
6604
s->typename = SystemTypeName("text");
6606
d = SystemTypeName("timetz");
6607
/* SQL99 mandates a default precision of zero for TIME
6608
* fields in schemas. However, for CURRENT_TIME
6609
* let's preserve the microsecond precision we
6610
* might see from the system clock. - thomas 2001-12-07
6614
$$ = (Node *)makeTypeCast((Node *)s, d);
6616
| CURRENT_TIME '(' Iconst ')'
6619
* Translate as "'now'::text::timetz(n)".
6620
* See comments for CURRENT_DATE.
6622
A_Const *s = makeNode(A_Const);
6625
s->val.type = T_String;
6626
s->val.val.str = "now";
6627
s->typename = SystemTypeName("text");
6628
d = SystemTypeName("timetz");
6631
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6632
errmsg("CURRENT_TIME(%d) precision must not be negative",
6634
if ($3 > MAX_TIME_PRECISION)
6637
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6638
errmsg("CURRENT_TIME(%d) precision reduced to maximum allowed, %d",
6639
$3, MAX_TIME_PRECISION)));
6640
$3 = MAX_TIME_PRECISION;
6644
$$ = (Node *)makeTypeCast((Node *)s, d);
6649
* Translate as "'now'::text::timestamptz".
6650
* See comments for CURRENT_DATE.
6652
A_Const *s = makeNode(A_Const);
6655
s->val.type = T_String;
6656
s->val.val.str = "now";
6657
s->typename = SystemTypeName("text");
6659
d = SystemTypeName("timestamptz");
6660
/* SQL99 mandates a default precision of 6 for timestamp.
6661
* Also, that is about as precise as we will get since
6662
* we are using a microsecond time interface.
6663
* - thomas 2001-12-07
6667
$$ = (Node *)makeTypeCast((Node *)s, d);
6669
| CURRENT_TIMESTAMP '(' Iconst ')'
6672
* Translate as "'now'::text::timestamptz(n)".
6673
* See comments for CURRENT_DATE.
6675
A_Const *s = makeNode(A_Const);
6678
s->val.type = T_String;
6679
s->val.val.str = "now";
6680
s->typename = SystemTypeName("text");
6682
d = SystemTypeName("timestamptz");
6685
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6686
errmsg("CURRENT_TIMESTAMP(%d) precision must not be negative",
6688
if ($3 > MAX_TIMESTAMP_PRECISION)
6691
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6692
errmsg("CURRENT_TIMESTAMP(%d) precision reduced to maximum allowed, %d",
6693
$3, MAX_TIMESTAMP_PRECISION)));
6694
$3 = MAX_TIMESTAMP_PRECISION;
6698
$$ = (Node *)makeTypeCast((Node *)s, d);
6703
* Translate as "'now'::text::time".
6704
* See comments for CURRENT_DATE.
6706
A_Const *s = makeNode(A_Const);
6709
s->val.type = T_String;
6710
s->val.val.str = "now";
6711
s->typename = SystemTypeName("text");
6713
d = SystemTypeName("time");
6714
/* SQL99 mandates a default precision of zero for TIME
6715
* fields in schemas. However, for LOCALTIME
6716
* let's preserve the microsecond precision we
6717
* might see from the system clock. - thomas 2001-12-07
6721
$$ = (Node *)makeTypeCast((Node *)s, d);
6723
| LOCALTIME '(' Iconst ')'
6726
* Translate as "'now'::text::time(n)".
6727
* See comments for CURRENT_DATE.
6729
A_Const *s = makeNode(A_Const);
6732
s->val.type = T_String;
6733
s->val.val.str = "now";
6734
s->typename = SystemTypeName("text");
6735
d = SystemTypeName("time");
6738
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6739
errmsg("LOCALTIME(%d) precision must not be negative",
6741
if ($3 > MAX_TIME_PRECISION)
6744
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6745
errmsg("LOCALTIME(%d) precision reduced to maximum allowed, %d",
6746
$3, MAX_TIME_PRECISION)));
6747
$3 = MAX_TIME_PRECISION;
6751
$$ = (Node *)makeTypeCast((Node *)s, d);
6756
* Translate as "'now'::text::timestamp".
6757
* See comments for CURRENT_DATE.
6759
A_Const *s = makeNode(A_Const);
6762
s->val.type = T_String;
6763
s->val.val.str = "now";
6764
s->typename = SystemTypeName("text");
6766
d = SystemTypeName("timestamp");
6767
/* SQL99 mandates a default precision of 6 for timestamp.
6768
* Also, that is about as precise as we will get since
6769
* we are using a microsecond time interface.
6770
* - thomas 2001-12-07
6774
$$ = (Node *)makeTypeCast((Node *)s, d);
6776
| LOCALTIMESTAMP '(' Iconst ')'
6779
* Translate as "'now'::text::timestamp(n)".
6780
* See comments for CURRENT_DATE.
6782
A_Const *s = makeNode(A_Const);
6785
s->val.type = T_String;
6786
s->val.val.str = "now";
6787
s->typename = SystemTypeName("text");
6789
d = SystemTypeName("timestamp");
6792
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6793
errmsg("LOCALTIMESTAMP(%d) precision must not be negative",
6795
if ($3 > MAX_TIMESTAMP_PRECISION)
6798
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6799
errmsg("LOCALTIMESTAMP(%d) precision reduced to maximum allowed, %d",
6800
$3, MAX_TIMESTAMP_PRECISION)));
6801
$3 = MAX_TIMESTAMP_PRECISION;
6805
$$ = (Node *)makeTypeCast((Node *)s, d);
6809
FuncCall *n = makeNode(FuncCall);
6810
n->funcname = SystemFuncName("current_user");
6812
n->agg_star = FALSE;
6813
n->agg_distinct = FALSE;
6818
FuncCall *n = makeNode(FuncCall);
6819
n->funcname = SystemFuncName("session_user");
6821
n->agg_star = FALSE;
6822
n->agg_distinct = FALSE;
6827
FuncCall *n = makeNode(FuncCall);
6828
n->funcname = SystemFuncName("current_user");
6830
n->agg_star = FALSE;
6831
n->agg_distinct = FALSE;
6834
| CAST '(' a_expr AS Typename ')'
6835
{ $$ = makeTypeCast($3, $5); }
6836
| EXTRACT '(' extract_list ')'
6838
FuncCall *n = makeNode(FuncCall);
6839
n->funcname = SystemFuncName("date_part");
6841
n->agg_star = FALSE;
6842
n->agg_distinct = FALSE;
6845
| OVERLAY '(' overlay_list ')'
6847
/* overlay(A PLACING B FROM C FOR D) is converted to
6848
* substring(A, 1, C-1) || B || substring(A, C+1, C+D)
6849
* overlay(A PLACING B FROM C) is converted to
6850
* substring(A, 1, C-1) || B || substring(A, C+1, C+char_length(B))
6852
FuncCall *n = makeNode(FuncCall);
6853
n->funcname = SystemFuncName("overlay");
6855
n->agg_star = FALSE;
6856
n->agg_distinct = FALSE;
6859
| POSITION '(' position_list ')'
6861
/* position(A in B) is converted to position(B, A) */
6862
FuncCall *n = makeNode(FuncCall);
6863
n->funcname = SystemFuncName("position");
6865
n->agg_star = FALSE;
6866
n->agg_distinct = FALSE;
6869
| SUBSTRING '(' substr_list ')'
6871
/* substring(A from B for C) is converted to
6872
* substring(A, B, C) - thomas 2000-11-28
6874
FuncCall *n = makeNode(FuncCall);
6875
n->funcname = SystemFuncName("substring");
6877
n->agg_star = FALSE;
6878
n->agg_distinct = FALSE;
6881
| TREAT '(' a_expr AS Typename ')'
6883
/* TREAT(expr AS target) converts expr of a particular type to target,
6884
* which is defined to be a subtype of the original expression.
6885
* In SQL99, this is intended for use with structured UDTs,
6886
* but let's make this a generally useful form allowing stronger
6887
* coersions than are handled by implicit casting.
6889
FuncCall *n = makeNode(FuncCall);
6890
/* Convert SystemTypeName() to SystemFuncName() even though
6891
* at the moment they result in the same thing.
6893
n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
6894
n->args = list_make1($3);
6897
| TRIM '(' BOTH trim_list ')'
6899
/* various trim expressions are defined in SQL92
6900
* - thomas 1997-07-19
6902
FuncCall *n = makeNode(FuncCall);
6903
n->funcname = SystemFuncName("btrim");
6905
n->agg_star = FALSE;
6906
n->agg_distinct = FALSE;
6909
| TRIM '(' LEADING trim_list ')'
6911
FuncCall *n = makeNode(FuncCall);
6912
n->funcname = SystemFuncName("ltrim");
6914
n->agg_star = FALSE;
6915
n->agg_distinct = FALSE;
6918
| TRIM '(' TRAILING trim_list ')'
6920
FuncCall *n = makeNode(FuncCall);
6921
n->funcname = SystemFuncName("rtrim");
6923
n->agg_star = FALSE;
6924
n->agg_distinct = FALSE;
6927
| TRIM '(' trim_list ')'
6929
FuncCall *n = makeNode(FuncCall);
6930
n->funcname = SystemFuncName("btrim");
6932
n->agg_star = FALSE;
6933
n->agg_distinct = FALSE;
6936
| CONVERT '(' a_expr USING any_name ')'
6938
FuncCall *n = makeNode(FuncCall);
6939
A_Const *c = makeNode(A_Const);
6941
c->val.type = T_String;
6942
c->val.val.str = NameListToQuotedString($5);
6944
n->funcname = SystemFuncName("convert_using");
6945
n->args = list_make2($3, c);
6946
n->agg_star = FALSE;
6947
n->agg_distinct = FALSE;
6950
| CONVERT '(' expr_list ')'
6952
FuncCall *n = makeNode(FuncCall);
6953
n->funcname = SystemFuncName("convert");
6955
n->agg_star = FALSE;
6956
n->agg_distinct = FALSE;
6959
| NULLIF '(' a_expr ',' a_expr ')'
6961
$$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5);
6963
| COALESCE '(' expr_list ')'
6965
CoalesceExpr *c = makeNode(CoalesceExpr);
6972
* Supporting nonterminals for expressions.
6975
/* Explicit row production.
6977
* SQL99 allows an optional ROW keyword, so we can now do single-element rows
6978
* without conflicting with the parenthesized a_expr production. Without the
6979
* ROW keyword, there must be more than one a_expr inside the parens.
6981
row: ROW '(' expr_list ')' { $$ = $3; }
6982
| ROW '(' ')' { $$ = NIL; }
6983
| '(' expr_list ',' a_expr ')' { $$ = lappend($2, $4); }
6986
sub_type: ANY { $$ = ANY_SUBLINK; }
6987
| SOME { $$ = ANY_SUBLINK; }
6988
| ALL { $$ = ALL_SUBLINK; }
6991
all_Op: Op { $$ = $1; }
6992
| MathOp { $$ = $1; }
6995
MathOp: '+' { $$ = "+"; }
7007
{ $$ = list_make1(makeString($1)); }
7008
| OPERATOR '(' any_operator ')'
7014
{ $$ = list_make1(makeString($1)); }
7015
| OPERATOR '(' any_operator ')'
7021
{ $$ = list_make1(makeString($1)); }
7022
| OPERATOR '(' any_operator ')'
7025
{ $$ = list_make1(makeString("~~")); }
7027
{ $$ = list_make1(makeString("!~~")); }
7029
{ $$ = list_make1(makeString("~~*")); }
7031
{ $$ = list_make1(makeString("!~~*")); }
7032
/* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
7033
* the regular expression is preprocessed by a function (similar_escape),
7034
* and the ~ operator for posix regular expressions is used.
7035
* x SIMILAR TO y -> x ~ similar_escape(y)
7036
* this transformation is made on the fly by the parser upwards.
7037
* however the SubLink structure which handles any/some/all stuff
7038
* is not ready for such a thing.
7044
$$ = list_make1($1);
7046
| expr_list ',' a_expr
7048
$$ = lappend($1, $3);
7053
extract_arg FROM a_expr
7055
A_Const *n = makeNode(A_Const);
7056
n->val.type = T_String;
7057
n->val.val.str = $1;
7058
$$ = list_make2((Node *) n, $3);
7060
| /*EMPTY*/ { $$ = NIL; }
7063
type_list: type_list ',' Typename
7065
$$ = lappend($1, $3);
7069
$$ = list_make1($1);
7073
array_expr_list: array_expr
7074
{ $$ = list_make1($1); }
7075
| array_expr_list ',' array_expr
7076
{ $$ = lappend($1, $3); }
7079
array_expr: '[' expr_list ']'
7081
ArrayExpr *n = makeNode(ArrayExpr);
7085
| '[' array_expr_list ']'
7087
ArrayExpr *n = makeNode(ArrayExpr);
7093
/* Allow delimited string SCONST in extract_arg as an SQL extension.
7094
* - thomas 2001-04-12
7099
| YEAR_P { $$ = "year"; }
7100
| MONTH_P { $$ = "month"; }
7101
| DAY_P { $$ = "day"; }
7102
| HOUR_P { $$ = "hour"; }
7103
| MINUTE_P { $$ = "minute"; }
7104
| SECOND_P { $$ = "second"; }
7105
| SCONST { $$ = $1; }
7108
/* OVERLAY() arguments
7109
* SQL99 defines the OVERLAY() function:
7110
* o overlay(text placing text from int for int)
7111
* o overlay(text placing text from int)
7114
a_expr overlay_placing substr_from substr_for
7116
$$ = list_make4($1, $2, $3, $4);
7118
| a_expr overlay_placing substr_from
7120
$$ = list_make3($1, $2, $3);
7129
/* position_list uses b_expr not a_expr to avoid conflict with general IN */
7132
b_expr IN_P b_expr { $$ = list_make2($3, $1); }
7133
| /*EMPTY*/ { $$ = NIL; }
7136
/* SUBSTRING() arguments
7137
* SQL9x defines a specific syntax for arguments to SUBSTRING():
7138
* o substring(text from int for int)
7139
* o substring(text from int) get entire string from starting point "int"
7140
* o substring(text from pattern) get entire string matching pattern
7141
* o substring(text for int) get first "int" characters of string
7142
* We also want to implement generic substring functions which accept
7143
* the usual generic list of arguments. So we will accept both styles
7144
* here, and convert the SQL9x style to the generic list for further
7145
* processing. - thomas 2000-11-28
7148
a_expr substr_from substr_for
7150
$$ = list_make3($1, $2, $3);
7152
| a_expr substr_for substr_from
7154
$$ = list_make3($1, $3, $2);
7156
| a_expr substr_from
7158
$$ = list_make2($1, $2);
7162
A_Const *n = makeNode(A_Const);
7163
n->val.type = T_Integer;
7164
n->val.val.ival = 1;
7165
$$ = list_make3($1, (Node *)n, $2);
7176
FROM a_expr { $$ = $2; }
7179
substr_for: FOR a_expr { $$ = $2; }
7182
trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
7183
| FROM expr_list { $$ = $2; }
7184
| expr_list { $$ = $1; }
7187
in_expr: select_with_parens
7189
SubLink *n = makeNode(SubLink);
7191
/* other fields will be filled later */
7194
| '(' expr_list ')' { $$ = (Node *)$2; }
7198
* Define SQL92-style case clause.
7199
* - Full specification
7200
* CASE WHEN a = b THEN c ... ELSE d END
7201
* - Implicit argument
7202
* CASE a WHEN b THEN c ... ELSE d END
7204
case_expr: CASE case_arg when_clause_list case_default END_P
7206
CaseExpr *c = makeNode(CaseExpr);
7207
c->casetype = InvalidOid; /* not analyzed yet */
7208
c->arg = (Expr *) $2;
7210
c->defresult = (Expr *) $4;
7216
/* There must be at least one */
7217
when_clause { $$ = list_make1($1); }
7218
| when_clause_list when_clause { $$ = lappend($1, $2); }
7222
WHEN a_expr THEN a_expr
7224
CaseWhen *w = makeNode(CaseWhen);
7225
w->expr = (Expr *) $2;
7226
w->result = (Expr *) $4;
7232
ELSE a_expr { $$ = $2; }
7233
| /*EMPTY*/ { $$ = NULL; }
7236
case_arg: a_expr { $$ = $1; }
7237
| /*EMPTY*/ { $$ = NULL; }
7241
* columnref starts with relation_name not ColId, so that OLD and NEW
7242
* references can be accepted. Note that when there are more than two
7243
* dotted names, the first name is not actually a relation name...
7245
columnref: relation_name
7247
$$ = makeColumnRef($1, NIL);
7249
| relation_name indirection
7251
$$ = makeColumnRef($1, $2);
7258
$$ = (Node *) makeString($2);
7262
$$ = (Node *) makeString("*");
7266
A_Indices *ai = makeNode(A_Indices);
7271
| '[' a_expr ':' a_expr ']'
7273
A_Indices *ai = makeNode(A_Indices);
7281
indirection_el { $$ = list_make1($1); }
7282
| indirection indirection_el { $$ = lappend($1, $2); }
7286
/*EMPTY*/ { $$ = NIL; }
7287
| opt_indirection indirection_el { $$ = lappend($1, $2); }
7291
/*****************************************************************************
7293
* target lists for SELECT, UPDATE, INSERT
7295
*****************************************************************************/
7298
target_el { $$ = list_make1($1); }
7299
| target_list ',' target_el { $$ = lappend($1, $3); }
7302
/* AS is not optional because shift/red conflict with unary ops */
7303
target_el: a_expr AS ColLabel
7305
$$ = makeNode(ResTarget);
7307
$$->indirection = NIL;
7308
$$->val = (Node *)$1;
7312
$$ = makeNode(ResTarget);
7314
$$->indirection = NIL;
7315
$$->val = (Node *)$1;
7319
ColumnRef *n = makeNode(ColumnRef);
7320
n->fields = list_make1(makeString("*"));
7322
$$ = makeNode(ResTarget);
7324
$$->indirection = NIL;
7325
$$->val = (Node *)n;
7330
update_target_el { $$ = list_make1($1); }
7331
| update_target_list ',' update_target_el { $$ = lappend($1,$3); }
7335
ColId opt_indirection '=' a_expr
7337
$$ = makeNode(ResTarget);
7339
$$->indirection = $2;
7340
$$->val = (Node *) $4;
7342
| ColId opt_indirection '=' DEFAULT
7344
$$ = makeNode(ResTarget);
7346
$$->indirection = $2;
7347
$$->val = (Node *) makeNode(SetToDefault);
7353
insert_target_el { $$ = list_make1($1); }
7354
| insert_target_list ',' insert_target_el { $$ = lappend($1, $3); }
7360
$$ = makeNode(ResTarget);
7362
$$->indirection = NIL;
7363
$$->val = (Node *)$1;
7367
$$ = makeNode(ResTarget);
7369
$$->indirection = NIL;
7370
$$->val = (Node *) makeNode(SetToDefault);
7375
/*****************************************************************************
7377
* Names and constants
7379
*****************************************************************************/
7382
SpecialRuleRelation { $$ = $1; }
7383
| ColId { $$ = $1; }
7386
qualified_name_list:
7387
qualified_name { $$ = list_make1($1); }
7388
| qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
7392
* The production for a qualified relation name has to exactly match the
7393
* production for a qualified func_name, because in a FROM clause we cannot
7394
* tell which we are parsing until we see what comes after it ('(' for a
7395
* func_name, something else for a relation). Therefore we allow 'indirection'
7396
* which may contain subscripts, and reject that case in the C code.
7401
$$ = makeNode(RangeVar);
7402
$$->catalogname = NULL;
7403
$$->schemaname = NULL;
7406
| relation_name indirection
7408
check_qualified_name($2);
7409
$$ = makeNode(RangeVar);
7410
switch (list_length($2))
7413
$$->catalogname = NULL;
7414
$$->schemaname = $1;
7415
$$->relname = strVal(linitial($2));
7418
$$->catalogname = $1;
7419
$$->schemaname = strVal(linitial($2));
7420
$$->relname = strVal(lsecond($2));
7424
(errcode(ERRCODE_SYNTAX_ERROR),
7425
errmsg("improper qualified name (too many dotted names): %s",
7426
NameListToString(lcons(makeString($1), $2)))));
7433
{ $$ = list_make1(makeString($1)); }
7434
| name_list ',' name
7435
{ $$ = lappend($1, makeString($3)); }
7439
name: ColId { $$ = $1; };
7447
attr_name: ColLabel { $$ = $1; };
7449
index_name: ColId { $$ = $1; };
7451
file_name: Sconst { $$ = $1; };
7454
* The production for a qualified func_name has to exactly match the
7455
* production for a qualified columnref, because we cannot tell which we
7456
* are parsing until we see what comes after it ('(' for a func_name,
7457
* anything else for a columnref). Therefore we allow 'indirection' which
7458
* may contain subscripts, and reject that case in the C code. (If we
7459
* ever implement SQL99-like methods, such syntax may actually become legal!)
7461
func_name: function_name
7462
{ $$ = list_make1(makeString($1)); }
7463
| relation_name indirection
7464
{ $$ = check_func_name(lcons(makeString($1), $2)); }
7473
A_Const *n = makeNode(A_Const);
7474
n->val.type = T_Integer;
7475
n->val.val.ival = $1;
7480
A_Const *n = makeNode(A_Const);
7481
n->val.type = T_Float;
7482
n->val.val.str = $1;
7487
A_Const *n = makeNode(A_Const);
7488
n->val.type = T_String;
7489
n->val.val.str = $1;
7494
A_Const *n = makeNode(A_Const);
7495
n->val.type = T_BitString;
7496
n->val.val.str = $1;
7501
/* This is a bit constant per SQL99:
7502
* Without Feature F511, "BIT data type",
7503
* a <general literal> shall not be a
7504
* <bit string literal> or a <hex string literal>.
7506
A_Const *n = makeNode(A_Const);
7507
n->val.type = T_BitString;
7508
n->val.val.str = $1;
7511
| ConstTypename Sconst
7513
A_Const *n = makeNode(A_Const);
7515
n->val.type = T_String;
7516
n->val.val.str = $2;
7519
| ConstInterval Sconst opt_interval
7521
A_Const *n = makeNode(A_Const);
7523
n->val.type = T_String;
7524
n->val.val.str = $2;
7525
/* precision is not specified, but fields may be... */
7526
if ($3 != INTERVAL_FULL_RANGE)
7527
n->typename->typmod = INTERVAL_TYPMOD(INTERVAL_FULL_PRECISION, $3);
7530
| ConstInterval '(' Iconst ')' Sconst opt_interval
7532
A_Const *n = makeNode(A_Const);
7534
n->val.type = T_String;
7535
n->val.val.str = $5;
7536
/* precision specified, and fields may be... */
7539
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7540
errmsg("INTERVAL(%d) precision must not be negative",
7542
if ($3 > MAX_INTERVAL_PRECISION)
7545
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
7546
errmsg("INTERVAL(%d) precision reduced to maximum allowed, %d",
7547
$3, MAX_INTERVAL_PRECISION)));
7548
$3 = MAX_INTERVAL_PRECISION;
7550
n->typename->typmod = INTERVAL_TYPMOD($3, $6);
7555
$$ = (Node *)makeBoolAConst(TRUE);
7559
$$ = (Node *)makeBoolAConst(FALSE);
7563
A_Const *n = makeNode(A_Const);
7564
n->val.type = T_Null;
7569
Iconst: ICONST { $$ = $1; };
7570
Sconst: SCONST { $$ = $1; };
7571
UserId: ColId { $$ = $1; };
7574
* Name classification hierarchy.
7576
* IDENT is the lexeme returned by the lexer for identifiers that match
7577
* no known keyword. In most cases, we can accept certain keywords as
7578
* names, not only IDENTs. We prefer to accept as many such keywords
7579
* as possible to minimize the impact of "reserved words" on programmers.
7580
* So, we divide names into several possible classes. The classification
7581
* is chosen in part to make keywords acceptable as names wherever possible.
7584
/* Column identifier --- names that can be column, table, etc names.
7586
ColId: IDENT { $$ = $1; }
7587
| unreserved_keyword { $$ = pstrdup($1); }
7588
| col_name_keyword { $$ = pstrdup($1); }
7591
/* Type identifier --- names that can be type names.
7593
type_name: IDENT { $$ = $1; }
7594
| unreserved_keyword { $$ = pstrdup($1); }
7597
/* Function identifier --- names that can be function names.
7601
| unreserved_keyword { $$ = pstrdup($1); }
7602
| func_name_keyword { $$ = pstrdup($1); }
7605
/* Column label --- allowed labels in "AS" clauses.
7606
* This presently includes *all* Postgres keywords.
7608
ColLabel: IDENT { $$ = $1; }
7609
| unreserved_keyword { $$ = pstrdup($1); }
7610
| col_name_keyword { $$ = pstrdup($1); }
7611
| func_name_keyword { $$ = pstrdup($1); }
7612
| reserved_keyword { $$ = pstrdup($1); }
7617
* Keyword classification lists. Generally, every keyword present in
7618
* the Postgres grammar should appear in exactly one of these lists.
7620
* Put a new keyword into the first list that it can go into without causing
7621
* shift or reduce conflicts. The earlier lists define "less reserved"
7622
* categories of keywords.
7625
/* "Unreserved" keywords --- available for use as any kind of name.
7818
/* Column identifier --- keywords that can be column, table, etc names.
7820
* Many of these keywords will in fact be recognized as type or function
7821
* names too; but they have special productions for the purpose, and so
7822
* can't be treated as "generic" type or function names.
7824
* The type names appearing here are not usable as function names
7825
* because they can be followed by '(' in typename productions, which
7826
* looks too much like a function call for an LR(1) parser.
7866
/* Function identifier --- keywords that can be function names.
7868
* Most of these are keywords that are used as operators in expressions;
7869
* in general such keywords can't be column names because they would be
7870
* ambiguous with variables, but they are unambiguous as function identifiers.
7872
* Do not include POSITION, SUBSTRING, etc here since they have explicit
7873
* productions in a_expr to support the goofy SQL9x argument syntax.
7874
* - thomas 2000-11-28
7899
/* Reserved keyword --- these keywords are usable only as a ColLabel.
7901
* Keywords appear here if they could not be distinguished from variable,
7902
* type, or function names in some contexts. Don't put things here unless
7979
SpecialRuleRelation:
7986
(errcode(ERRCODE_SYNTAX_ERROR),
7987
errmsg("OLD used in query that is not in a rule")));
7995
(errcode(ERRCODE_SYNTAX_ERROR),
7996
errmsg("NEW used in query that is not in a rule")));
8003
makeColumnRef(char *relname, List *indirection)
8006
* Generate a ColumnRef node, with an A_Indirection node added if there
8007
* is any subscripting in the specified indirection list. However,
8008
* any field selection at the start of the indirection list must be
8009
* transposed into the "fields" part of the ColumnRef node.
8011
ColumnRef *c = makeNode(ColumnRef);
8015
foreach(l, indirection)
8017
if (IsA(lfirst(l), A_Indices))
8019
A_Indirection *i = makeNode(A_Indirection);
8023
/* easy case - all indirection goes to A_Indirection */
8024
c->fields = list_make1(makeString(relname));
8025
i->indirection = indirection;
8029
/* got to split the list in two */
8030
i->indirection = list_copy_tail(indirection, nfields);
8031
indirection = list_truncate(indirection, nfields);
8032
c->fields = lcons(makeString(relname), indirection);
8034
i->arg = (Node *) c;
8039
/* No subscripting, so all indirection gets added to field list */
8040
c->fields = lcons(makeString(relname), indirection);
8045
makeTypeCast(Node *arg, TypeName *typename)
8048
* Simply generate a TypeCast node.
8050
* Earlier we would determine whether an A_Const would
8051
* be acceptable, however Domains require coerce_type()
8052
* to process them -- applying constraints as required.
8054
TypeCast *n = makeNode(TypeCast);
8056
n->typename = typename;
8061
makeStringConst(char *str, TypeName *typename)
8063
A_Const *n = makeNode(A_Const);
8065
n->val.type = T_String;
8066
n->val.val.str = str;
8067
n->typename = typename;
8073
makeIntConst(int val)
8075
A_Const *n = makeNode(A_Const);
8076
n->val.type = T_Integer;
8077
n->val.val.ival = val;
8078
n->typename = SystemTypeName("int4");
8084
makeFloatConst(char *str)
8086
A_Const *n = makeNode(A_Const);
8088
n->val.type = T_Float;
8089
n->val.val.str = str;
8090
n->typename = SystemTypeName("float8");
8096
makeAConst(Value *v)
8103
n = makeFloatConst(v->val.str);
8107
n = makeIntConst(v->val.ival);
8112
n = makeStringConst(v->val.str, NULL);
8120
* Create a DefElem node and set contents.
8121
* Could be moved to nodes/makefuncs.c if this is useful elsewhere.
8124
makeDefElem(char *name, Node *arg)
8126
DefElem *f = makeNode(DefElem);
8133
* Create an A_Const node and initialize to a boolean constant.
8136
makeBoolAConst(bool state)
8138
A_Const *n = makeNode(A_Const);
8139
n->val.type = T_String;
8140
n->val.val.str = (state? "t": "f");
8141
n->typename = SystemTypeName("bool");
8145
/* makeRowNullTest()
8146
* Generate separate operator nodes for a single row descriptor test.
8148
* Eventually this should be eliminated in favor of making the NullTest
8149
* node type capable of handling it directly.
8152
makeRowNullTest(NullTestType test, RowExpr *row)
8154
Node *result = NULL;
8157
foreach(arg, row->args)
8161
n = makeNode(NullTest);
8162
n->arg = (Expr *) lfirst(arg);
8163
n->nulltesttype = test;
8166
result = (Node *) n;
8167
else if (test == IS_NOT_NULL)
8168
result = (Node *) makeA_Expr(AEXPR_OR, NIL, result, (Node *)n);
8170
result = (Node *) makeA_Expr(AEXPR_AND, NIL, result, (Node *)n);
8175
/* zero-length rows? Generate constant TRUE or FALSE */
8176
result = (Node *) makeBoolAConst(test == IS_NULL);
8183
* Create and populate a FuncCall node to support the OVERLAPS operator.
8186
makeOverlaps(List *largs, List *rargs)
8188
FuncCall *n = makeNode(FuncCall);
8189
n->funcname = SystemFuncName("overlaps");
8190
if (list_length(largs) == 1)
8191
largs = lappend(largs, largs);
8192
else if (list_length(largs) != 2)
8194
(errcode(ERRCODE_SYNTAX_ERROR),
8195
errmsg("wrong number of parameters on left side of OVERLAPS expression")));
8196
if (list_length(rargs) == 1)
8197
rargs = lappend(rargs, rargs);
8198
else if (list_length(rargs) != 2)
8200
(errcode(ERRCODE_SYNTAX_ERROR),
8201
errmsg("wrong number of parameters on right side of OVERLAPS expression")));
8202
n->args = list_concat(largs, rargs);
8203
n->agg_star = FALSE;
8204
n->agg_distinct = FALSE;
8208
/* check_qualified_name --- check the result of qualified_name production
8210
* It's easiest to let the grammar production for qualified_name allow
8211
* subscripts and '*', which we then must reject here.
8214
check_qualified_name(List *names)
8220
if (!IsA(lfirst(i), String))
8221
yyerror("syntax error");
8222
else if (strcmp(strVal(lfirst(i)), "*") == 0)
8223
yyerror("syntax error");
8227
/* check_func_name --- check the result of func_name production
8229
* It's easiest to let the grammar production for func_name allow subscripts
8230
* and '*', which we then must reject here.
8233
check_func_name(List *names)
8239
if (!IsA(lfirst(i), String))
8240
yyerror("syntax error");
8241
else if (strcmp(strVal(lfirst(i)), "*") == 0)
8242
yyerror("syntax error");
8247
/* extractArgTypes()
8248
* Given a list of FunctionParameter nodes, extract a list of just the
8249
* argument types (TypeNames). Most of the productions using func_args
8250
* don't currently want the full FunctionParameter data, so we use this
8251
* rather than having two sets of productions.
8254
extractArgTypes(List *parameters)
8259
foreach(i, parameters)
8261
FunctionParameter *p = (FunctionParameter *) lfirst(i);
8263
result = lappend(result, p->argType);
8268
/* findLeftmostSelect()
8269
* Find the leftmost component SelectStmt in a set-operation parsetree.
8272
findLeftmostSelect(SelectStmt *node)
8274
while (node && node->op != SETOP_NONE)
8276
Assert(node && IsA(node, SelectStmt) && node->larg == NULL);
8280
/* insertSelectOptions()
8281
* Insert ORDER BY, etc into an already-constructed SelectStmt.
8283
* This routine is just to avoid duplicating code in SelectStmt productions.
8286
insertSelectOptions(SelectStmt *stmt,
8287
List *sortClause, List *forUpdate,
8288
Node *limitOffset, Node *limitCount)
8291
* Tests here are to reject constructs like
8292
* (SELECT foo ORDER BY bar) ORDER BY baz
8296
if (stmt->sortClause)
8298
(errcode(ERRCODE_SYNTAX_ERROR),
8299
errmsg("multiple ORDER BY clauses not allowed")));
8300
stmt->sortClause = sortClause;
8304
if (stmt->forUpdate)
8306
(errcode(ERRCODE_SYNTAX_ERROR),
8307
errmsg("multiple FOR UPDATE clauses not allowed")));
8308
stmt->forUpdate = forUpdate;
8312
if (stmt->limitOffset)
8314
(errcode(ERRCODE_SYNTAX_ERROR),
8315
errmsg("multiple OFFSET clauses not allowed")));
8316
stmt->limitOffset = limitOffset;
8320
if (stmt->limitCount)
8322
(errcode(ERRCODE_SYNTAX_ERROR),
8323
errmsg("multiple LIMIT clauses not allowed")));
8324
stmt->limitCount = limitCount;
8329
makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
8331
SelectStmt *n = makeNode(SelectStmt);
8335
n->larg = (SelectStmt *) larg;
8336
n->rarg = (SelectStmt *) rarg;
8341
* Build a properly-qualified reference to a built-in function.
8344
SystemFuncName(char *name)
8346
return list_make2(makeString("pg_catalog"), makeString(name));
8350
* Build a properly-qualified reference to a built-in type.
8352
* typmod is defaulted, but may be changed afterwards by caller.
8355
SystemTypeName(char *name)
8357
TypeName *n = makeNode(TypeName);
8359
n->names = list_make2(makeString("pg_catalog"), makeString(name));
8365
* Initialize to parse one query string
8370
QueryIsRule = FALSE;
8373
/* exprIsNullConstant()
8374
* Test whether an a_expr is a plain NULL constant or not.
8377
exprIsNullConstant(Node *arg)
8379
if (arg && IsA(arg, A_Const))
8381
A_Const *con = (A_Const *) arg;
8383
if (con->val.type == T_Null &&
8384
con->typename == NULL)
8391
* Handle negation of a numeric constant.
8393
* Formerly, we did this here because the optimizer couldn't cope with
8394
* indexquals that looked like "var = -4" --- it wants "var = const"
8395
* and a unary minus operator applied to a constant didn't qualify.
8396
* As of Postgres 7.0, that problem doesn't exist anymore because there
8397
* is a constant-subexpression simplifier in the optimizer. However,
8398
* there's still a good reason for doing this here, which is that we can
8399
* postpone committing to a particular internal representation for simple
8400
* negative constants. It's better to leave "-123.456" in string form
8401
* until we know what the desired type is.
8406
if (IsA(n, A_Const))
8408
A_Const *con = (A_Const *)n;
8410
if (con->val.type == T_Integer)
8412
con->val.val.ival = -con->val.val.ival;
8415
if (con->val.type == T_Float)
8417
doNegateFloat(&con->val);
8422
return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n);
8426
doNegateFloat(Value *v)
8428
char *oldval = v->val.str;
8430
Assert(IsA(v, Float));
8434
v->val.str = oldval+1; /* just strip the '-' */
8437
char *newval = (char *) palloc(strlen(oldval) + 2);
8440
strcpy(newval+1, oldval);
8441
v->val.str = newval;