Re: BUG #5620: PostgreSQL won't accept the word "user" as a valid column name - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #5620: PostgreSQL won't accept the word "user" as a valid column name
Date
Msg-id 7024.1281791740@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #5620: PostgreSQL won't accept the word "user" as a valid column name  (Stefan Kaltenbrunner <stefan@kaltenbrunner.cc>)
List pgsql-bugs
Stefan Kaltenbrunner <stefan@kaltenbrunner.cc> writes:
> On 08/14/2010 02:14 AM, Samuel Marinov wrote:
>> ERROR:  syntax error at or near "user"
>> LINE 1: create table ftp (user varchar, password varchar);

> not sure why you consider this a bug - but "user" is a reserved word in
> PostgreSQL and the SQL-Standard (see
> http://www.postgresql.org/docs/9.0/static/sql-keywords-appendix.html) so
> you would have to quote the keyword like:

> create table ftp ("user" varchar, password varchar);

> in your code - but I would advise against using reserved words at all
> because you will end up having to quote them all over the place in each
> and every query.

Yeah.  The reason it's reserved is that per spec, USER is equivalent to
CURRENT_USER, ie it's a built-in function that returns the current login
name.  So anytime you forgot and wrote
    select user from ...
instead of
    select "user" from ...
it would still work and you'd get mysteriously wrong output.  You
don't want to go there.

            regards, tom lane

pgsql-bugs by date:

Previous
From: Stefan Kaltenbrunner
Date:
Subject: Re: BUG #5620: PostgreSQL won't accept the word "user" as a valid column name
Next
From: Tom Lane
Date:
Subject: Re: BUG #5608: array_agg() consumes too much memory