开发者

I can't fix this seemingly, simple, cast related, postgresql error

开发者 https://www.devze.com 2023-04-07 19:44 出处:网络
So, I have this query: SELECT count(*) AS count FROM table1 INNER JOIN \"some query\" WHERE \"some more query\"

So, I have this query:

SELECT count(*) AS count FROM table1 INNER JOIN "some query" 
WHERE "some more query" 
OR (table.smowid NOT LIKE (58)) OR "rest of query"

Sorry for the unclear code, the full query is quite big, but the problem is in the table.smowid NOT LIKE (58) part.

This is the error I get:

ERROR:  operator does not exist: integer !~~ integer
LINE 11: or ( (table.smowid) NOT LIKE (58))
                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

I unfortunately, don't know much about casts and types, but why is the DB complaining when it's going fro开发者_如何学编程m integer to integer? I tried CASTING by saying (CAST (table.smowid) AS INTEGER) NOT LIKE (58) but that didn't work, I also tried (table.smowid :: integer) NOT LIKE (58) but that also didn't work for some reason.

So, what should I do? Thanks for all the help.


you should cast them both to text or, better yet, have a smowis column with all the smowi values as text to save the overhead of casting each time.


NOT LIKE and its equivalent !~~ are definitely not integer operators. What are you trying to do with a pattern matching operators on integers?

There's a way to use it but you first have to cast (or format) the integers to text.

0

精彩评论

暂无评论...
验证码 换一张
取 消