[英]Postgres query cannot find rows based on column value
I want to select rows based on a column value.我想 select 行基于列值。 I know for a fact the column value exists.
我知道列值确实存在。 The first query returns 100 rows from the
listing
table.第一个查询从
listing
表中返回 100 行。 The second query, which looks for listings.OriginatingSystemName
= 'mfrmls` returns nothing.查找
listings.OriginatingSystemName
= 'mfrmls` 的第二个查询不返回任何内容。 Why?为什么?
(Removing the quotes or using double quotes does not work). (删除引号或使用双引号不起作用)。
I am using pgAdmin4 to run these queries.我正在使用 pgAdmin4 来运行这些查询。
first query:第一个查询:
select * from listing limit 100;
second query:第二个查询:
select * from listing where 'listing.OriginatingSystemName' = 'mfrmls'
This produces a 'column does not exist' error:这会产生“列不存在”错误:
select * from listing where OriginatingSystemName = 'mfrmls'
The correct syntax is to just write the column name in your WHERE statement:正确的语法是只在 WHERE 语句中写入列名:
SELECT * FROM listings WHERE "OriginatingSystemName" = 'mfrmls';
To elaborate further:进一步阐述:
What your original query is doing is selecting every row in the listings table where the text string 'listings.OriginatingSystemName' is equal to this other text string 'mfrmls'.您的原始查询正在做的是选择列表表中的每一行,其中文本字符串“listings.OriginatingSystemName”等于其他文本字符串“mfrmls”。 It is not actually grabbing the value from the column you want.
它实际上并没有从您想要的列中获取值。 No row in the table satisfies your where statement because your where statement is always false.
表中没有一行满足你的 where 语句,因为你的 where 语句总是错误的。 Therefore, no rows are returned but the query was a success.
因此,没有返回任何行,但查询成功。
We need to implement the double quotes when dealing with case-sensitive identifiers.在处理区分大小写的标识符时,我们需要实现双引号。 Here is some helpful documentation .
这里有一些有用的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.