Omitting the double quote to do query on PostgreSQL

PostgresqlDouble Quotes

Postgresql Problem Overview


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?

Postgresql Solutions


Solution 1 - Postgresql

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;

Solution 2 - Postgresql

double quotes are required if you include capital letters in your table name in postgres

to avoid the requirements name your table "a"

Solution 3 - Postgresql

Postgresql has some particular behaviour in regard to quoting and case sentivity: it folds every non-quoted identifier to lower case (also at creation time) and then works case-sensitively.

Double quotes in identifiers are only needed when the identifier (table name, column name, etc) was defined (at schema creation time) with uppercase letters (some or all) and between double quotes.

In that case (which I advice against), when you use that identifier, you must type it in the same way: case sensitively (type upper/lower case letter exactly as defined) and between double quotes.

In other cases, you can use non-quoted identifiers and work always case-insensitively.

Solution 4 - Postgresql

Don't use upper case letter in your table name or it's column name, if you are using such thing then the postgres will required double quote for accessing it.

Solution 5 - Postgresql

Please see the detailed description of what is happening here.

The PostgreSQL server table names are case-sensitive, but forced to be lower-case by default: when you type CREATE TABLE AAA, it will become CREATE TABLE aaa before the query execution.

Double-quoted names keep their case as it was, so after CREATE TABLE "AaA" you get the table AaA and have to write it double-quoted again and again.

Have no idea why did they do so :)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionzfmView Question on Stackoverflow
Solution 1 - PostgresqlSteve PrenticeView Answer on Stackoverflow
Solution 2 - PostgresqlDavid ChanView Answer on Stackoverflow
Solution 3 - PostgresqlleonbloyView Answer on Stackoverflow
Solution 4 - PostgresqlSandyView Answer on Stackoverflow
Solution 5 - PostgresqlKaratheodoryView Answer on Stackoverflow