Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 362575b

Browse files
author
Thomas G. Lockhart
committed
Enable more flexible syntax for the SET command. Now allows single floats,
single integers, and lists of names, without surrounding them with quotes. Remove all tokens which are defined as operators from ColID and ColLabel to avoid precedence confusion. Thanks to Tom Lane for catching this.
1 parent b68d9c4 commit 362575b

File tree

1 file changed

+94
-24
lines changed

1 file changed

+94
-24
lines changed

src/backend/parser/gram.y

Lines changed: 94 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.164 2000/03/27 17:12:06 thomas Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.165 2000/03/30 06:02:36 thomas Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -297,7 +297,8 @@ static void doNegateFloat(Value *v);
297297
COALESCE, COLLATE, COLUMN, COMMIT,
298298
CONSTRAINT, CONSTRAINTS, CREATE, CROSS, CURRENT, CURRENT_DATE,
299299
CURRENT_TIME, CURRENT_TIMESTAMP, CURRENT_USER, CURSOR,
300-
DAY_P, DEC, DECIMAL, DECLARE, DEFAULT, DELETE, DESC, DISTINCT, DOUBLE, DROP,
300+
DAY_P, DEC, DECIMAL, DECLARE, DEFAULT, DELETE, DESC,
301+
DISTINCT, DOUBLE, DROP,
301302
ELSE, END_TRANS, EXCEPT, EXECUTE, EXISTS, EXTRACT,
302303
FALSE_P, FETCH, FLOAT, FOR, FOREIGN, FROM, FULL,
303304
GLOBAL, GRANT, GROUP, HAVING, HOUR_P,
@@ -712,8 +713,71 @@ opt_level: READ COMMITTED { $$ = "committed"; }
712713
| SERIALIZABLE { $$ = "serializable"; }
713714
;
714715

715-
var_value: Sconst { $$ = $1; }
716-
| DEFAULT { $$ = NULL; }
716+
var_value: Sconst
717+
{
718+
/* Plain old string (pointer to char) */
719+
$$ = $1;
720+
}
721+
| FCONST
722+
{
723+
/* Floating pumeric argument?
724+
* This recently changed to preserve "stringiness" until here,
725+
* so we don't have any work to do at all. Nice.
726+
* - thomas 2000-03-29
727+
*/
728+
$$ = $1;
729+
}
730+
| Iconst
731+
{
732+
char *result;
733+
char buf[64];
734+
735+
/* Integer pumeric argument?
736+
*/
737+
if (sprintf(buf, "%d", $1) != 1)
738+
{
739+
result = pstrdup(buf);
740+
}
741+
else
742+
elog(ERROR, "Unable to convert constant to string (internal error)");
743+
744+
$$ = result;
745+
}
746+
| name_list
747+
{
748+
List *n;
749+
int llen, slen = 0;
750+
char *result;
751+
752+
llen = length($1);
753+
754+
/* List of words? Then concatenate together */
755+
if (llen < 1)
756+
elog(ERROR, "SET must have at least one argument");
757+
758+
foreach (n, $1)
759+
{
760+
Value *p = (Value *) lfirst(n);
761+
Assert(IsA(p, String));
762+
/* keep track of room for string and trailing comma */
763+
slen += (strlen(p->val.str) + 1);
764+
}
765+
result = palloc(slen + 1);
766+
*result = '\0';
767+
foreach (n, $1)
768+
{
769+
Value *p = (Value *) lfirst(n);
770+
strcat(result, p->val.str);
771+
strcat(result, ",");
772+
}
773+
/* remove the trailing comma from the last element */
774+
*(result+strlen(result)-1) = '\0';
775+
$$ = result;
776+
}
777+
| DEFAULT
778+
{
779+
$$ = NULL;
780+
}
717781
;
718782

719783
zone_value: Sconst { $$ = $1; }
@@ -1609,9 +1673,9 @@ TriggerFuncArgs: TriggerFuncArg
16091673

16101674
TriggerFuncArg: ICONST
16111675
{
1612-
char *s = (char *) palloc(64);
1613-
sprintf (s, "%d", $1);
1614-
$$ = s;
1676+
char buf[64];
1677+
sprintf (buf, "%d", $1);
1678+
$$ = pstrdup(buf);
16151679
}
16161680
| FCONST { $$ = $1; }
16171681
| Sconst { $$ = $1; }
@@ -3396,7 +3460,7 @@ opt_select_limit: LIMIT select_limit_value ',' select_offset_value
33963460
{ $$ = lappend(lappend(NIL, NULL), NULL); }
33973461
;
33983462

3399-
select_limit_value: Iconst
3463+
select_limit_value: Iconst
34003464
{
34013465
Const *n = makeNode(Const);
34023466

@@ -5236,6 +5300,15 @@ UserId: IDENT { $$ = $1; };
52365300
* some of these keywords will have to be removed from this
52375301
* list due to shift/reduce conflicts in yacc. If so, move
52385302
* down to the ColLabel entity. - thomas 1997-11-06
5303+
* These show up as operators, ans will screw up the parsing if
5304+
* allowed as identifiers or labels.
5305+
* Thanks to Tom Lane for pointing this out. - thomas 2000-03-29
5306+
| BETWEEN { $$ = "between"; }
5307+
| IN { $$ = "in"; }
5308+
| IS { $$ = "is"; }
5309+
| ISNULL { $$ = "isnull"; }
5310+
| NOTNULL { $$ = "notnull"; }
5311+
| OVERLAPS { $$ = "overlaps"; }
52395312
*/
52405313
ColId: IDENT { $$ = $1; }
52415314
| datetime { $$ = $1; }
@@ -5249,7 +5322,6 @@ ColId: IDENT { $$ = $1; }
52495322
| BACKWARD { $$ = "backward"; }
52505323
| BEFORE { $$ = "before"; }
52515324
| BEGIN_TRANS { $$ = "begin"; }
5252-
| BETWEEN { $$ = "between"; }
52535325
| BY { $$ = "by"; }
52545326
| CACHE { $$ = "cache"; }
52555327
| CASCADE { $$ = "cascade"; }
@@ -5281,16 +5353,13 @@ ColId: IDENT { $$ = $1; }
52815353
| GRANT { $$ = "grant"; }
52825354
| HANDLER { $$ = "handler"; }
52835355
| IMMEDIATE { $$ = "immediate"; }
5284-
| IN { $$ = "in"; }
52855356
| INCREMENT { $$ = "increment"; }
52865357
| INDEX { $$ = "index"; }
52875358
| INHERITS { $$ = "inherits"; }
52885359
| INSENSITIVE { $$ = "insensitive"; }
52895360
| INSERT { $$ = "insert"; }
52905361
| INSTEAD { $$ = "instead"; }
52915362
| INTERVAL { $$ = "interval"; }
5292-
| IS { $$ = "is"; }
5293-
| ISNULL { $$ = "isnull"; }
52945363
| ISOLATION { $$ = "isolation"; }
52955364
| KEY { $$ = "key"; }
52965365
| LANGUAGE { $$ = "language"; }
@@ -5309,13 +5378,11 @@ ColId: IDENT { $$ = $1; }
53095378
| NOCREATEUSER { $$ = "nocreateuser"; }
53105379
| NOTHING { $$ = "nothing"; }
53115380
| NOTIFY { $$ = "notify"; }
5312-
| NOTNULL { $$ = "notnull"; }
53135381
| OF { $$ = "of"; }
53145382
| OIDS { $$ = "oids"; }
53155383
| ONLY { $$ = "only"; }
53165384
| OPERATOR { $$ = "operator"; }
53175385
| OPTION { $$ = "option"; }
5318-
| OVERLAPS { $$ = "overlaps"; }
53195386
| PARTIAL { $$ = "partial"; }
53205387
| PASSWORD { $$ = "password"; }
53215388
| PENDANT { $$ = "pendant"; }
@@ -5375,12 +5442,23 @@ ColId: IDENT { $$ = $1; }
53755442
* Add other keywords to this list. Note that they appear here
53765443
* rather than in ColId if there was a shift/reduce conflict
53775444
* when used as a full identifier. - thomas 1997-11-06
5445+
* These show up as operators, ans will screw up the parsing if
5446+
* allowed as identifiers or labels.
5447+
* Thanks to Tom Lane for pointing this out. - thomas 2000-03-29
5448+
| ALL { $$ = "all"; }
5449+
| ANY { $$ = "any"; }
5450+
| EXCEPT { $$ = "except"; }
5451+
| INTERSECT { $$ = "intersect"; }
5452+
| LIKE { $$ = "like"; }
5453+
| NOT { $$ = "not"; }
5454+
| NULLIF { $$ = "nullif"; }
5455+
| NULL_P { $$ = "null_p"; }
5456+
| OR { $$ = "or"; }
5457+
| UNION { $$ = "union"; }
53785458
*/
53795459
ColLabel: ColId { $$ = $1; }
53805460
| ABORT_TRANS { $$ = "abort"; }
5381-
| ALL { $$ = "all"; }
53825461
| ANALYZE { $$ = "analyze"; }
5383-
| ANY { $$ = "any"; }
53845462
| ASC { $$ = "asc"; }
53855463
| BINARY { $$ = "binary"; }
53865464
| BIT { $$ = "bit"; }
@@ -5411,7 +5489,6 @@ ColLabel: ColId { $$ = $1; }
54115489
| DO { $$ = "do"; }
54125490
| ELSE { $$ = "else"; }
54135491
| END_TRANS { $$ = "end"; }
5414-
| EXCEPT { $$ = "except"; }
54155492
| EXISTS { $$ = "exists"; }
54165493
| EXPLAIN { $$ = "explain"; }
54175494
| EXTEND { $$ = "extend"; }
@@ -5427,12 +5504,10 @@ ColLabel: ColId { $$ = $1; }
54275504
| HAVING { $$ = "having"; }
54285505
| INITIALLY { $$ = "initially"; }
54295506
| INNER_P { $$ = "inner"; }
5430-
| INTERSECT { $$ = "intersect"; }
54315507
| INTO { $$ = "into"; }
54325508
| JOIN { $$ = "join"; }
54335509
| LEADING { $$ = "leading"; }
54345510
| LEFT { $$ = "left"; }
5435-
| LIKE { $$ = "like"; }
54365511
| LISTEN { $$ = "listen"; }
54375512
| LOAD { $$ = "load"; }
54385513
| LOCAL { $$ = "local"; }
@@ -5442,13 +5517,9 @@ ColLabel: ColId { $$ = $1; }
54425517
| NCHAR { $$ = "nchar"; }
54435518
| NEW { $$ = "new"; }
54445519
| NONE { $$ = "none"; }
5445-
| NOT { $$ = "not"; }
5446-
| NULLIF { $$ = "nullif"; }
5447-
| NULL_P { $$ = "null_p"; }
54485520
| NUMERIC { $$ = "numeric"; }
54495521
| OFFSET { $$ = "offset"; }
54505522
| ON { $$ = "on"; }
5451-
| OR { $$ = "or"; }
54525523
| ORDER { $$ = "order"; }
54535524
| OUTER_P { $$ = "outer"; }
54545525
| POSITION { $$ = "position"; }
@@ -5470,7 +5541,6 @@ ColLabel: ColId { $$ = $1; }
54705541
| TRANSACTION { $$ = "transaction"; }
54715542
| TRIM { $$ = "trim"; }
54725543
| TRUE_P { $$ = "true"; }
5473-
| UNION { $$ = "union"; }
54745544
| UNIQUE { $$ = "unique"; }
54755545
| USER { $$ = "user"; }
54765546
| USING { $$ = "using"; }

0 commit comments

Comments
 (0)