Skip site navigation (1) Skip section navigation (2)

Making OFF unreserved

From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Making OFF unreserved
Date: 2010-10-22 07:43:22
Message-ID: 4CC1409A.8060002@enterprisedb.com (view raw or flat)
Thread:
Lists: pgsql-hackers
OFF is a reserved keyword. It's not a reserved keyword in the SQL spec, 
and it's not hard to see people using off as a variable or column name, 
so it would be nice to relax that. To make things worse, OFFSET is also 
a reserved keyword, which would be the other natural name for a variable 
or column that stores an offset of some sort.

I bumped into this because we have a test case in the EDB regression 
suite that uses 'off' as a PL/pgSQL variable name. It used to work 
before 9.0, because PL/pgSQL variable names were replaced with $n-style 
parameter markers before handing off the query to the backend parser. 
It's a problem with all keywords in general, but 'off' seems like a 
likely variable name in real applications, and there was no ambiguity 
with it.

Looking at the grammar, OFF is only used here:

 > opt_boolean:
 >     TRUE_P        { $$ = "true"; }
 >     | FALSE_P    { $$ = "false"; }
 >     | ON        { $$ = "on"; }
 >     | OFF        { $$ = "off"; }
 >         ;

And opt_boolean in turn is used in the following places:

 > var_value:    opt_boolean
 >         { $$ = makeStringConst($1, @1); }
 >     | ColId_or_Sconst
 >         { $$ = makeStringConst($1, @1); }
 >     | NumericOnly
 >         { $$ = makeAConst($1, @1); }
 >     ;
 > ...
 > copy_generic_opt_arg:
 >     opt_boolean        { $$ = (Node *) makeString($1); }
 >     | ColId_or_Sconst    { $$ = (Node *) makeString($1); }
 > ...
 > copy_generic_opt_arg_list_item:
 >     opt_boolean        { $$ = (Node *) makeString($1); }
 >     | ColId_or_Sconst    { $$ = (Node *) makeString($1); }
 >     ;
 > ...
 > explain_option_arg:
 >     opt_boolean        { $$ = (Node *) makeString($1); }
 >     | ColId_or_Sconst    { $$ = (Node *) makeString($1); }

Note that ColId is also accepted alongside opt_boolean in all of those 
with the same action, so if we just remove OFF from opt_boolean rule and 
make it unreserved, nothing changes.

ECPG uses OFF as a keyword in its "SET autocommit = [ON | OFF]" rule, so 
we have to retain it as an unreserved keyword, or make it an 
ecpg-specific keyword in the ecpg grammar. But I don't know how to do 
that, and it feels like a good idea to keep it in the unreserved keyword 
list anyway, so I propose the attached patch.

Any objections? Any objections to backpatching to 9.0, where the 
PL/pgSQL variable handling was changed?

-- 
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com

Attachment: make-off-unreserved-1.patch
Description: text/x-diff (1.4 KB)

Responses

pgsql-hackers by date

Next:From: Dimitri FontaineDate: 2010-10-22 07:47:04
Subject: Re: Extensions, this time with a patch
Previous:From: Heikki LinnakangasDate: 2010-10-22 05:50:14
Subject: Re: crash in plancache with subtransactions

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group