PostgreSQL列名称区分大小写吗? [英] Are PostgreSQL column names case-sensitive?
问题描述
我在Postgres中有一个数据库表,例如persons
,由另一个列名称为"first_Name"
的团队提供.现在,我正在尝试使用PG命令,在此列名上查询该表.
I have a db table say, persons
in Postgres handed down by another team that has a column name say, "first_Name"
. Now am trying to use PG commander to query this table on this column-name.
select * from persons where first_Name="xyz";
它只是返回
错误:列"first_Name"不存在
ERROR: column "first_Name" does not exist
不确定我是否在做愚蠢的事情,或者是否有解决此问题的解决方法?
Not sure if I am doing something silly or is there a workaround to this problem that I am missing?
推荐答案
所有未加双引号的标识符(包括列名)在PostgreSQL中被折叠为小写.用双引号创建的列名并因此保留了大写字母(和/或其他语法冲突),必须在余下的时间将双引号引起来:("first_Name"
)
All identifiers (including column names) that are not double-quoted are folded to lower case in PostgreSQL. Column names that were created with double-quotes and thereby retained upper-case letters (and/or other syntax violations) have to be double-quoted for the rest of their life: ("first_Name"
)
因此,是,PostgreSQL列名称区分大小写:
So, yes, PostgreSQL column names are case-sensitive:
SELECT * FROM persons WHERE "first_Name" = 'xyz';
还要修复'xyz'
周围错误的双引号. 值(字符串文字)放在单引号中.
Also fix the incorrect double-quotes around 'xyz'
. Values (string literals) are enclosed in single quotes.
我的长期建议是仅使用合法的小写名称,因此不需要双引号.
My standing advice is to use legal, lower-case names exclusively so double-quoting is not needed.
这篇关于PostgreSQL列名称区分大小写吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!