问题
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?
回答1:
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;
回答2:
double quotes are required if you include capital letters in your table name in postgres
to avoid the requirements name your table "a"
回答3:
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.
回答4:
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.
回答5:
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 :)
来源:https://stackoverflow.com/questions/6331504/omitting-the-double-quote-to-do-query-on-postgresql