PostgreSQL 列名是否区分大小写? [英] Are PostgreSQL column names case-sensitive?

查看:35
本文介绍了PostgreSQL 列名是否区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 db 表,表示 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 中被折叠为小写.使用双引号创建并因此保留大写字母(和/或其他语法违规)的列名称必须在其余生中使用双引号:

Identifiers (including column names) that are not double-quoted are folded to lowercase in PostgreSQL. Column names that were created with double-quotes and thereby retained uppercase letters (and/or other syntax violations) have to be double-quoted for the rest of their life:

"first_Name"

(字符串文字/常量)括在单引号中:

Values (string literals / constants) are enclosed in single quotes:

'xyz'

所以,,PostgreSQL 列名是区分大小写的(双引号时):

So, yes, PostgreSQL column names are case-sensitive (when double-quoted):

SELECT * FROM persons WHERE "first_Name" = 'xyz';

在此处阅读有关标识符的手册.

我的长期建议是只使用合法的小写名称,这样就不需要双引号了.

My standing advice is to use legal, lower-case names exclusively so double-quoting is not needed.

这篇关于PostgreSQL 列名是否区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆