Обсуждение: double quotes around table and column names

Поиск
Список
Период
Сортировка

double quotes around table and column names

От
"Thomas T. Thai"
Дата:
What is the suggested way of using double quotes around table and column
names? Is there a standard or suggested usage?


Re: double quotes around table and column names

От
Mike Mascari
Дата:
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