我的 Postgres 查询无法正常工作

My Postgres query is not working properly

select * 
from data_adultdata 
where sex = 'Male' 

当我在 'Male' 之前没有给出 space 时,它 return 什么都没有:

select * 
from data_adultdata 
where the sex= ' Male' 

当我在“男性”之前给出 space 时,它 return 是正确的记录。

问题不在Postgres,而在数据,你可以简单的检查一下:

select length('Male') = length(title), length(' Male') = length(title) 
from data_adultdata 
limit 10;

当您尝试匹配字符串时,最好使用 Like 运算符:

SELECT * 
FROM data_adultdata 
WHERE sex LIKE '%Male' 

但是 Bear Brown 是对的,输入数据似乎有一个 space 的附加字符,这就是为什么你没有得到 'Male'