【问题标题】:Postgres query with uppercase letters in Column name列名中带有大写字母的 Postgres 查询
【发布时间】:2021-08-13 10:16:49
【问题描述】:

我搜索并遵循了各种在线指南,但是没有成功使用以下查询,虽然没有给出错误,但它没有得到预期的结果。

table gBInfo:
(columns) id,userId, fromGB, fromGBId      

table User:
(columns) id, firstName, lastName

查询:

select "id", "firstName", "fromGB" 
from "User" join "gBInfo"
on 'User.id' = 'gBInfo.userId';

如何让这个查询工作,在列名和表名中使用大写字母。

【问题讨论】:

标签: sql postgresql quoted-identifier


【解决方案1】:

单引号用于字符串常量,而不是标识符。并且多部分标识符的每一部分都需要单独引用:

select "id", "firstName", "fromGB" 
from "User" 
  join "gBInfo" on "User".id = "gBInfo"."userId";

条件'User.id' = 'gBInfo.userId' 只是将字符串值User.id 与字符串值gBInfo.userId 进行比较,这显然不相等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-17
    • 1970-01-01
    • 1970-01-01
    • 2013-09-24
    • 2014-11-28
    • 2017-04-16
    相关资源
    最近更新 更多