pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Patrik Kudo <kudo@partitur.se>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] "quoting" column names
Date: Tue, 13 Jul 1999 10:08:21 -0400
Message-ID: <22436.931874901@sss.pgh.pa.us> (raw)
In-Reply-To: <378B2DEC.84B1514A@partitur.se>

Patrik Kudo <kudo@partitur.se> writes:
> create table login (userid text, when datetime);
> select when from login where userid = 'xxxx';
> In 6.5 I have to do:
> select "when" from login where userid = 'xxxx';

Right ... WHEN is a keyword in CASE expressions, which didn't use to
be implemented but are now.

> My question now is, should I always quote column names, just in case,
> or should I only quote column names that are "almost reserved"?

In theory you should only have to worry about keywords that are
reserved in SQL92 but that Postgres hasn't gotten around to implementing
yet.  That's a fairly short list, I think, but I do not have the
details handy.  (Anyone?)

Quoting every column name in sight would make your SQL pretty unreadable
(pg_dump now does it by default ... try reading pg_dump commands :-().
Also, if you have a reserved word as a column name, you won't be able
to access the table at all using tools that don't quote column names.
Better to rename your columns if you get burnt by this.

			regards, tom lane



view thread (4+ messages)  latest in thread

Message-ID: <22436.931874901@sss.pgh.pa.us>
Permalink:  ../22436.931874901@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/22436.931874901@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, kudo@partitur.se
  Subject: Re: [SQL] "quoting" column names
  In-Reply-To: <22436.931874901@sss.pgh.pa.us>
  References: <378B2DEC.84B1514A@partitur.se> <22436.931874901@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox