Re: double quotes around table and column names - Mailing list pgsql-general

From Mike Mascari
Subject Re: double quotes around table and column names
Date
Msg-id 3DDC964D.9070405@mascari.com
Whole thread Raw
In response to double quotes around table and column names  ("Thomas T. Thai" <tom@minnesota.com>)
List 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@mascari.com




pgsql-general by date:

Previous
From: Christoph Dalitz
Date:
Subject: Re: is the sqlca.sqlabc value unique for each response type
Next
From: "Erwan DUROSELLE"
Date:
Subject: Rép. : double quotes around table and column names