开发者

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 simil开发者_如何转开发ar 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.


Try the IS (NOT) DISTINCT FROM operator.


Apparently it's possible in postgresql (see dan04's). The query below would work in SQL Server and other DBMSs where that syntax isn't available.

You can simulate by doing:

WHERE (column1 is NULL and column2 is NULL) 
      OR column1 = column2


To add to @Derek's answer:

In MySQL you can use the <=> operator to the same effect:

SELECT * FROM table1 WHERE column1 <=> column2
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜