5

The documentation tells me LIKE and NOT LIKE are used in SQL to search if cells contain/starts/ends with certain characters.

I'm trying to use this in PostgreSQL which tells me the operator does not exist. My query:

SELECT * FROM "City"."models" 
WHERE (("City"."models".identifier NOT LIKE'%$%') 
AND
     (("City"."models".id LIKE '%2%') 
     OR 
     ("City"."models".id LIKE '%1%'))) 

ORDER BY "City"."models".town_id ASC LIMIT 10

Column types:

identifier->uuid
id->int
town_id->int

Where is my mistake?

6
  • Show us some sample data, preferably in a SQLFiddle and also post your query there Commented Oct 7, 2015 at 8:07
  • you should really post the complete error message. Commented Oct 7, 2015 at 8:07
  • My guess is "identifier" and "id" are not strings. LIKE won't work with numeric values. Commented Oct 7, 2015 at 8:12
  • 1
    LIKE is not applicable to integers, you'll have to use something like CAST(id as VARCHAR) LIKE '%2%' etc. But that looks weird in general, why do you want to filter integers like text? Commented Oct 7, 2015 at 8:12
  • it looks weird and i'm sure the error message tells him exactly that int does not work with LIKE Commented Oct 7, 2015 at 8:14

1 Answer 1

4

Try this:

SELECT * FROM "City"."models" 
WHERE (("City"."models".identifier::varchar NOT LIKE'%$%') 
AND
     (("City"."models".id::varchar LIKE '%2%') 
     OR 
     ("City"."models".id::varchar LIKE '%1%'))) 

ORDER BY "City"."models".town_id ASC LIMIT 10
Sign up to request clarification or add additional context in comments.

Comments

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.