pg icon indicating copy to clipboard operation
pg copied to clipboard

How to make where with "is" support for nulls

Open tpoxa opened this issue 5 years ago • 0 comments

I need to find rows where values may be null. I have two nullable fields with ,notnull tags.

.Where("role_id = ?role_id and user_id = ?user_id")

so either role_id or user_id may be null

As postgres documentation (https://www.postgresql.org/docs/8.1/functions-comparison.html) says we need to use "IS" for nulls...

Tip: Some applications may expect that expression = NULL returns true if expression evaluates to the null value. It is highly recommended that these applications be modified to comply with the SQL standard. However, if that cannot be done the transform_null_equals configuration variable is available. If it is enabled, PostgreSQL will convert x = NULL clauses to x IS NULL. This was the default behavior in PostgreSQL releases 6.5 through 7.1.

Is any solution in pg for this? Thank you.

tpoxa avatar Jun 11 '19 13:06 tpoxa