2

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?

  • enter image description here

  • enter image description here

If you have something to try, ask me in a comment section and i'll tell you the results

1 Answer 1

4

My guess is that ' On Trent' is not what it looks like. It is hard to figure out the actual problem. The most likely culprit is the pace between "Burton" and "Trent":

So, see if these work:

WHERE line_description ilike '%1 X Hired 1100 (LTR). Derby Road, Burton_O%'
WHERE line_description ilike '%1 X Hired 1100 (LTR). Derby Road, Burton%O%'

Otherwise it might be the "O".

Sign up to request clarification or add additional context in comments.

3 Comments

Burton_O% returned 0 rows, Burton%O% returned 81 rows, then i tried: WHERE line_description ilike '%1 X Hired 1100 (LTR). Derby Road, Burton%On Trent, Staffordshire%' and it returned 81 rows, so you was right about the space, but what's wrong with it??
@alex23 . . . Perhaps there are two spaces. Try __ and ___ for the separator, to see how many characters are there.
yes, you are right, 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' with 2 spaces after Burton found the row. Thank you Gordon!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.