简体   繁体   English

列名中带有大写字母的 Postgres 查询

[英]Postgres query with uppercase letters in Column name

I searched and followed various online guide however am not successful with the following query, which while doesnt give errors, it does not get the expected results.我搜索并遵循了各种在线指南,但是没有成功使用以下查询,虽然没有给出错误,但没有得到预期的结果。

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

table User:
(columns) id, firstName, lastName

query:询问:

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

What do I get this query to work, with uppercase letters in column and table names.我如何让这个查询工作,在列名和表名中使用大写字母。

Single quotes are for string constants, not for identifiers.单引号用于字符串常量,而不是标识符。 And each part of a multi-part identifier needs to be quoted separately:并且多部分标识符的每个部分都需要单独引用:

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

The condition 'User.id' = 'gBInfo.userId' simply compares the string value User.id with the string value gBInfo.userId which are obviously never equal.条件'User.id' = 'gBInfo.userId'只是将字符串值User.id与字符串值gBInfo.userId进行比较,这显然不相等。

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

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