Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between != and <> operators?

Tags:

postgresql

I don't like not knowing this as there may be situations when I need to use one instead of the other. It seems in most cases they produce the same results but I am taking a guess they have subtle difference, maybe to do with NULL values or one does strict comparisons like the extra = in PHP does.

Thanks

like image 534
Kevin Orriss Avatar asked Jun 05 '14 12:06

Kevin Orriss


2 Answers

From the manual:

Note: The != operator is converted to <> in the parser stage. It is not possible to implement != and <> operators that do different things.

So no, there is no difference between the two.

like image 180
harmic Avatar answered Oct 18 '22 04:10

harmic


<> is the standard SQL operator meaning "not equal". Many databases, including postgresql, supports != as a synonym for <>.

They're exactly the same in postgresql. See also the documentation.

Note though, that postgresql allows you to implement your own types and overload operators for those types, so ultimately it depends on the datatypes involved what the != and <> operator actually does, but <> and != can never do different things.

like image 7
nos Avatar answered Oct 18 '22 02:10

nos