Search code examples
sqlpostgresqlsqlitecomparison-operators

Is there a PostgreSQL equivalent of SQLite's IS operator?


In SQLite, IS is a binary operator that behaves exactly like = except when one or both of the operands are NULL. In the case where both operands are NULL, the IS operator evaluates to TRUE. In the case where one operand is NULL, but not the other, the IS operand evaluates to FALSE.

I was looking for a similar operator in PostgreSQL, but I could not find one. Is there an equivalent of SQLite's IS operator in PostgreSQL? If not, what is the best/least-complicated work-around?

To clarify, SELECT column1 IS column2 ... is allowed in SQLite, but PostgreSQL raises a syntax error.


Solution

  • Try the IS (NOT) DISTINCT FROM operator.