简体   繁体   English

Postgres 查询无法根据列值找到行

[英]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.

相关问题 Postgres 根据列值将行转置为列 - Postgres Transpose Rows to Columns Based on Column Value MySQL查询基于子字符串left()和max()列值查找行 - Mysql query to find rows based on substring left() and column max() value Postgres 查询不同列值行的结果 - Postgres Query Result of Rows with Different Column Value 如何根据列的值查找连续的行? - How to find consecutive rows based on the value of a column? 根据postgres中的主键更新具有多个值的多行列 - Updating column of multiple rows with multiple value based on primary keys in postgres 基于两个不同行的 Postgres 查询 select 值 - Postgres Query to select value based on two different rows Postgres查询将具有相同列值的多行组合成一行 - Postgres query to combine multiple rows with same value of a column into a single row Postgres SQL 查询以从列中查找值的计数 - Postgres SQL query to find the count of a value from a column 当列值相同时,如何在 postgres 中合并行,并根据合并的行对另一列求和? - How can I combine rows in postgres when a column value is the same, and sum another column based on the combined rows? 根据另一列的值提取一列的所有行(SQL 查询) - Extract all rows of a column based on the value of another column (SQL query)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM