Re: double quotes around table and column names

From: Mike Mascari <mascarm(at)mascari(dot)com>
To: "Thomas T(dot) Thai" <tom(at)minnesota(dot)com>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: double quotes around table and column names
Date: 2002-11-21 08:16:13
Message-ID: 3DDC964D.9070405@mascari.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thomas T. Thai wrote:
> What is the suggested way of using double quotes around table and column
> names? Is there a standard or suggested usage?

I would avoid using double quotes entirely, if possible. If you
use double quotes on mixed-case table and column names, you must
be sure to always use double quotes. I'd use all lowercase,
unquoted names. Unquoted names get folded into lowercase, so
even if you quoted the lowercase name, the queries would still work:

Examples:

---- QUOTED NAMES ----

> CREATE TABLE "Foo" ("Key" integer);
CREATE
> SELECT * FROM Foo;
ERROR: Relation "foo" does not exist
> SELECT * FROM "Foo";
key
-----
(0 rows)

---- UNQUOTED NAMES ----

> CREATE TABLE Foo (Key integer);
CREATE
> SELECT * FROM Foo;
key
-----
(0 rows)

> SELECT * FROM foo;
key
-----
(0 rows)

> SELECT * FROM "Foo";
ERROR: Relation "Foo" does not exist
> SELECT * FROM "foo";
key
-----
(0 rows)

So you might as well be consistent and do a:

CREATE TABLE foo (key integer);

Hope that helps,

Mike Mascari
mascarm(at)mascari(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Erwan DUROSELLE 2002-11-21 09:40:40 Rp. : double quotes around table and column names
Previous Message Christoph Dalitz 2002-11-21 08:13:18 Re: is the sqlca.sqlabc value unique for each response type