简体   繁体   English

在 PSQL 中忽略大小写的 AS 语句

[英]AS statement ignoring cases in PSQL

We are using the Node Postgres client to run some queries on our database, like:我们正在使用 Node Postgres 客户端在我们的数据库上运行一些查询,例如:

await client.query('SELECT A.date_time AS dateTime FROM A')

the problem is that returned value for the row comes as:问题是该行的返回值如下:

Expected:{
  dateTime: '2009-06-16 11:00:00'
}

Received: {
  datetime: '2009-06-16 11:00:00'
}

is this a bug or are we missing a configuration somewhere?这是一个错误还是我们在某处缺少配置?

SQL is case sensitive, but everything that is not a string literal or a quoted identifier is case folded . SQL 区分大小写,但不是字符串文字或带引号的标识符的所有内容都是case folded The SQL standard prescribes case folding to upper case, but PostgreSQL folds to lower case. SQL 标准规定外壳折叠为大写,但 PostgreSQL 折叠为小写。

If you want case to be preserved in an identifier like dateTime , you have to surround it with double quotes: "dateTime"如果您希望将大小写保留在诸如dateTime之类的标识符中,则必须用双引号将其括起来: "dateTime"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM