Omitting the double quote to do query on PostgreSQL

zfm picture zfm · Jun 13, 2011 · Viewed 46k times · Source

Simple question, is there any way to omit the double quote in PostgreSQL?

Here is an example, giving select * from A;, I will retrieve ERROR: relation "a" does not exist, and I would have to give select * from "A"; to get the real result.

Is there any way not to do the second and instead do the first on PostgreSQL?

Answer

Steve Prentice picture Steve Prentice · Jun 13, 2011

Your problem with this query started when you created your table. When you create your table, don't use quotes.

Use this:

CREATE TABLE a ( ... );

Not this:

CREATE TABLE "A" ( ... );

The latter will make it so that you always have to quote it later. The former makes it a normal name and you can use SELECT * FROM a; or SELECT * FROM A;

If you can't just recreate your table, use the ALTER TABLE syntax:

ALTER TABLE "A" RENAME TO a;