PostgreSQL列名称案例敏感吗?
我有一个DB表, Persons
在Postgres中由另一个具有列名称的团队say,“ first_name”
。现在,我正在尝试使用PG指挥官在此列名上查询此表。
select * from persons where first_Name="xyz";
它只是返回
错误:列“ first_name”不存在
我是在做愚蠢的事情还是我缺少这个问题的解决方法?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
标识符(包括列名称) 双引号被折叠为PostgreSQL中的较低情况。用 双引号创建的标识符 保留上层案例字母(和/或语法违规),必须在其余生中双重引用:
但是(没有双引号):
value (字符串文字/常数)包含在 单引号 中:
So,是YES ,PostgreSQL列名称(双引号时):
我的常规建议是专门使用合法的,低案例的名称,因此不需要双重引用。
系统目录,例如
pg_class
商店名称以案例敏感的方式 - 在双重引用时提供(显然没有封闭引号)或较低的效果。Identifiers (including column names) that are not double-quoted are folded to lower case in PostgreSQL. Identifiers created with double quotes retain upper case letters (and/or syntax violations) and have to be double-quoted for the rest of their life:
But (without double-quotes):
Values (string literals / constants) are enclosed in single quotes:
So, yes, PostgreSQL column names are case-sensitive (when double-quoted):
The manual on identifiers.
My standing advice is to use legal, lower-case names exclusively, so double-quoting is never required.
System catalogs like
pg_class
store names in case-sensitive fashion - as provided when double-quoted (without enclosing quotes, obviously), or lower-cased if not.引用
您也可以使用引用的标识符:
引用标识符使其对案例敏感,而未引用的名称总是折叠为较低的情况折叠到上箱)。例如,标识符
foo
,foo
和“ foo”
被PostgreSQL认为相同,但是“ foo” 和
“ foo”
与这三个和彼此不同。如果要编写便携式应用程序,建议您始终引用特定名称或永远不要引用它。
To quote the documentation:
You could also write it using quoted identifiers:
Quoting an identifier makes it case-sensitive, whereas unquoted names are always folded to lower case (unlike the SQL standard where unquoted names are folded to upper case). For example, the identifiers
FOO
,foo
, and"foo"
are considered the same by PostgreSQL, but"Foo"
and"FOO"
are different from these three and each other.If you want to write portable applications you are advised to always quote a particular name or never quote it.
混合案例或大写的列名必须在PostgreSQL中进行双重引用。因此,最好的惯例是遵循所有小型案例。
示例:
如您所见,如果该列包含一个上案例字符,则必须在引用它时始终引用它。
用PostgreSQL 17。测试
The column names which are mixed case or uppercase have to be double quoted in PostgresQL. So best convention will be to follow all small case with underscore.
Example:
As you can see, if the column contains an upper-case character, it must always be quoted when referencing it.
Tested with PostgreSQL 17.
如果使用JPA,我建议更改以较小架构,表格和列名称,您可以使用下一个结构来帮助您:
更改模式名称:
更改表名称:
更改列名:
if use JPA I recommend change to lowercase schema, table and column names, you can use next intructions for help you:
change schema name:
change table names:
change column names:
您可以尝试以大写字母命名的表和列命名。 (PostgreSQL)
You can try this example for table and column naming in capital letters. (postgresql)