Search code examples
sqlpostgresqlsql-like

PostgreSQL query, LIKE operator


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?


Solution

  • 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