I have a table invoice_lines with line_description column (text, utf8). The rows are inserted by PHP code (utf8). Recently i've found the following problem:
When I run
SELECT * FROM invoice_lines
WHERE line_description ilike '%1 X Hired 1100 (LTR). Derby Road, Burton _________%'
or
SELECT * FROM invoice_lines
WHERE line_description ilike '%1 X Hired 1100 (LTR). Derby Road, Burton %'
postgres returns 81 rows with line_description like "1 X Hired 1100 (LTR). Derby Road, Burton On Trent, Staffordshire - 4 days @ £2.95 per week (05/08/2015 - 08/08/2015). Grade: Mixed Municipal Waste" (dates from 2015 to 2016)
But when I run this:
SELECT * FROM invoice_lines
WHERE line_description ilike '%1 X Hired 1100 (LTR). Derby Road, Burton On Trent%'
or
SELECT * FROM invoice_lines
WHERE line_description ilike '%1 X Hired 1100 (LTR). Derby Road, Burton O%'
postgres returns 0 rows.
When I try to get only 1 row with exact value, it also returns 0:
SELECT * FROM invoice_lines
WHERE line_description = '1 X Hired 1100 (LTR). Derby Road, Burton On Trent, Staffordshire - 4 days @ £2.95 per week (05/08/2015 - 08/08/2015). Grade: Mixed Municipal Waste'
It looks like characters starting from "On Trent, Staffordshire" are different, but the code that inserted these lines was used for millions of other records that can be found by similar queries.
Please can you tell me why this is happening?
If you have something to try, ask me in a comment section and i'll tell you the results

