1

In MySQL the below query is executing properly.

SELECT * FROM <Table-name> WHERE (Table.ID LIKE '1%')

But when I try to execute the above query in Postgres, I get the following exception

"org.postgresql.util.PSQLException: ERROR: operator does not exist: integer ~~ unknown Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts".

If I convert the same query

SELECT * 
FROM <Table-name> 
WHERE CAST(Table.ID as TEXT) LIKE '1%' 

This gets executed directly in Postgres DB. But I need some query which implicitly type cast in DB, which allows me to execute the MySQL query without any exception. Because I remember there is a way for integer to boolean implicit type cast.

Thanks in advance.

3
  • Welcome to StackOverflow: if you post code, XML or data samples, please highlight those lines in the text editor and click on the "code samples" button ( { } ) on the editor toolbar to nicely format and syntax highlight it! Commented Feb 17, 2012 at 9:25
  • As far as I can tell implicit casts were removed in PostgreSQL 8.3. What version are you on? Commented Feb 17, 2012 at 9:42
  • 1
    It those are really numbers, searching with LIKE does not make sense. If those aren't "real" numbers than store them in a varchar column. Commented Feb 17, 2012 at 11:10

1 Answer 1

2

If you search this site with [postgresql] explicit type casts you will get enough information to solve your problem.

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.