Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'!=' and '<>' operators in postgresql

According to postgresql manual != means the same as <>. In reality, it doesn't seems to be the case:

psql=> select 1 where 1!=-1;
ERROR:  operator does not exist: integer !=- integer
LINE 1: select 1 where 1!=-1;
                        ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
psql=> select 1 where 1<>-1;
 ?column? 
----------
        1
(1 row)

Is this a bug or this is an expected behavior that wasn't covered by the manual?

like image 531
rin Avatar asked May 12 '26 09:05

rin


1 Answers

You need to write a space so that postgres knows, that it's a != operator and not !=-:

select 1 != -1;

Or you can put it in parentheses:

select 1!=(-1);
like image 140
Andronicus Avatar answered May 15 '26 06:05

Andronicus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!