0

I am trying to demonstrate the difference between how ruby and and postgres treat null equality.

For example, in ruby, I run nil == nil and get true. I want to try to run the same type of query in postgres and show that null = null is false, but not sure how to structure it.

Alternatively show that null = null is true and null != null is also true.

2
  • This is not Postgresql feature, but SQL standard one: there are lot of SO answers about NULL = NULL. Commented Apr 5, 2019 at 14:34
  • Wiki: en.wikipedia.org/wiki/… Commented Apr 5, 2019 at 14:35

2 Answers 2

3
select null = null;
 ?column?
----------

(1 row)

It is not false, nor true, but undefined.

Sign up to request clarification or add additional context in comments.

1 Comment

Or, more understandably, (NULL = NULL) IS NULL.
1

Almost any evaluation against a null in postgres will return a null (short of some functions like concat()). To return a boolean when evaluating a null you have to use IS NULL

This will return True: SELECT NULL IS NULL

This will return False: SELECT NULL IS NOT NULL

Comments

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.