News for hackers. Stuff that matters.
Re:Null Values in SQL Queries by SigmundA on Monday February 03, 2020 @10:40AM (#22225064)
No I am tired of this WHERE (a = b) or (a IS NULL AND b IS NULL)

Null should equal null like in every other programming language even SQL group by do null equals null which is even more inconsistent.

Re:Null Values in SQL Queries by jeltz on Monday February 03, 2020 @06:38PM (#22230613)
It is quite wordy but the SQL solution for this is "WHERE a IS NOT DISTINCT FROM b".

https://modern-sql.com/feature/is-distinct-from

Re:Null Values in SQL Queries by progval on Monday February 03, 2020 @05:02PM (#22229724)
> Null should equal null like in every other programming language

Think of SQL's NULL like it's a NaN.

Re:Null Values in SQL Queries by WorldMaker on Monday February 03, 2020 @01:08PM (#22227024)
Something to petition ANSI about.

(Microsoft's SQL Server still defaults to the non-ANSI NULL behavior where a = b when both are NULL, and that's something that still pings on checklists of SQL Server if it follows ANSI standards. SQL Server is kind enough to let you enable/disable the behavior, and likely that would persist even after the default switches to meet the standard as the docs assure will happen "in some future version".)

Re:Null Values in SQL Queries by zvrba on Tuesday February 04, 2020 @03:05AM (#22233395)
Actually I find this a very practical behavior. It allows me to have NULLs in columns participating in UNIQUE indexes. At least with indexes, it's very intuitive and useful.
Re:Null Values in SQL Queries by Tactic on Monday February 03, 2020 @12:36PM (#22226564)
My preference would be a flag that you can set per connection.

NULL = Undefined or No Data. Whereas a blank field can, in and of itself, be data. It may indicated something is intentionally left blank.

But for those times where you want to consider them the same, it would be nice to have a setting.

(Note that I admit the possibility that this may exist already, like most my great ideas.)

Re:Null Values in SQL Queries by SigmundA on Monday February 03, 2020 @12:45PM (#22226687)
In MSSQL you have SET ANSI_NULLS OFF to do this.
Re:Null Values in SQL Queries by bloomer on Monday February 03, 2020 @10:54AM (#22225243)
NULL is similar to floating point NaN (aka not a number) which also has the same comparison operation NaN != NaN.
Re:Null Values in SQL Queries by stetrain on Monday February 03, 2020 @10:42AM (#22225088)
Sounds like a disaster when trying to correlate Ids/keys between tables.
Re:Null Values in SQL Queries by mumblemumble on Monday February 03, 2020 @10:54AM (#22225240)
Letting null equal null might work okay for a WHERE clause, but it turn JOINing into a terrible muddle. And I don't want null to behave different ways in different clauses.
Re:Null Values in SQL Queries by SigmundA on Monday February 03, 2020 @12:37PM (#22226569)
Already behaves differently in GROUP BY, UNION, DISTINCT and PARTITION.
Re:Null Values in SQL Queries by trts on Monday February 03, 2020 @11:08AM (#22225414)
where coalesce(a, '') = coalesce(b, '')
Re:Null Values in SQL Queries by SigmundA on Monday February 03, 2020 @12:00PM (#22226082)
Normally can't use an index as every value has to be coalesced before comparison.
Re:Null Values in SQL Queries by danaliv on Monday February 03, 2020 @10:55PM (#22232236)
You can index the results of functions (or other expressions) in at least some databases. PostgreSQL can do this, for example.

  CREATE INDEX idx ON tbl (coalesce(col, ''))
Combining this with UNIQUE can make for some neat tricks.