This query returns the desired result:
Select * from media
This query returns 0:
select id from media where conc_title = 'origin of life'
conc_title has the type varchar and the entry is in the db.
these modifications don’t work either:
SELECT id FROM media WHERE TRIM(conc_title) = 'origin of life'
SELECT id FROM media WHERE conc_title LIKE '%origin of life%'
Doesn’t work for other conc_titles either. The result is the datatype without any rows.
3
Answers
Postgres does never return NULL in case no result was found.
In case no result for a given condition was found 0 is returned.
You can use coalesce in case you want to have values OR really NULL. This would make it more transparent as a human reader.
I suspect a case issue, try lowercasing the title before comparing it:
Note that this won’t use the index on
conc_title
if any, so to be used carefully depending on your dataset. Another approach could be to store the title lowercased already, perhaps in a separated column so that you keep the original case available. Thelike
operator also may do a fulltable scan depending on how it’s used, check with the dbms you’re using.I suggest
This approach helps if spaces are causing the mismatch. If this doesn’t resolve the issue, verify the data for hidden characters or mismatches in the
conc_title
values.