省略双引号在 PostgreSQL 上进行查询
简单的问题,有没有办法在PostgreSQL中省略双引号?
这是一个示例,给出select * from A;
,我将检索ERROR:关系“a”不存在
,并且我必须给出select *从“A”;
得到真正的结果。
有没有办法在 PostgreSQL 上不执行第二个操作而执行第一个操作?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当您创建表时,此查询的问题就开始了。创建表格时,请勿使用引号。
使用这个:
不是这个:
后者会做到这一点,这样你以后就必须引用它。前者使其成为普通名称,您可以使用
SELECT * FROM a;
或SELECT * FROM A;
如果您不能重新创建表,请使用
>ALTER TABLE
语法:Your problem with this query started when you created your table. When you create your table, don't use quotes.
Use this:
Not this:
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;
orSELECT * FROM A;
If you can't just recreate your table, use the
ALTER TABLE
syntax:如果您在 postgres 中的表名称中包含大写字母,则需要使用双引号
以避免将表命名为“a”的要求
double quotes are required if you include capital letters in your table name in postgres
to avoid the requirements name your table "a"
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.
不要在表名或其列名中使用大写字母,如果您使用这样的东西,那么 postgres 将需要双引号来访问它。
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.
请在此处查看所发生情况的详细描述。
PostgreSQL 服务器表名区分大小写,但默认情况下强制为小写:当您输入
CREATE TABLE AAA
时,查询前会变成CREATE TABLE aaa
执行。双引号名称保持其原来的大小写,因此在
CREATE TABLE "AaA"
之后,您将获得表AaA
并且必须一次又一次地用双引号将其写入。不知道他们为什么这样做:)
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 becomeCREATE TABLE aaa
before the query execution.Double-quoted names keep their case as it was, so after
CREATE TABLE "AaA"
you get the tableAaA
and have to write it double-quoted again and again.Have no idea why did they do so :)