News for hackers. Stuff that matters.
Re:Postgres 15 improves UNIQUE and NULL by magicalhippo on Monday July 11, 2022 @08:51AM (#32055507)
> these comparisons don't evaluate to false, they evaluate to NULL

In the databases I've used, such as MSSQL[1], they evaluate to UNKNOWN.

[1]: https://docs.microsoft.com/en-us/sql/t-sql/language-elements...

Re:Postgres 15 improves UNIQUE and NULL by bfgoodrich on Monday July 11, 2022 @01:11PM (#32058816)
The document you link uses unknown as a synonym for null. If you inserted the result of such a comparison into a table, the value inserted would be NULL.
Re:Postgres 15 improves UNIQUE and NULL by magicalhippo on Monday July 11, 2022 @03:55PM (#32060952)
I'm self-taught, could you show how to insert the result of such a comparison into a table in mssql? I can only think of using CASE or similar, which would mean no direct conversion.
Re:Postgres 15 improves UNIQUE and NULL by orf on Monday July 11, 2022 @06:02PM (#32062590)
insert into table (c) values (null != null)
Re:Postgres 15 improves UNIQUE and NULL by magicalhippo on Monday July 11, 2022 @08:00PM (#32063854)
Can you provide a complete working example? I'm just getting "incorrect syntax near !" with both mssql and sqlanywhere.

    create table #nulltest (a bit null);
    insert into #nulltest(a) values (0),(1);
    insert into #nulltest(a) values (null != null);
Re:Postgres 15 improves UNIQUE and NULL by distalzou on Monday July 11, 2022 @10:48PM (#32064992)
Some SQL dialects don't recognize != and use <> instead
Re:Postgres 15 improves UNIQUE and NULL by magicalhippo on Monday July 11, 2022 @11:50PM (#32065386)
True, I'll blame vacation mode for not catching that one.

However, that doesn't change things, I can't get any of these to parse:

    insert into #nulltest(a) values (1 <> 0);
    insert into #nulltest(a) values (null <> null);
    insert into #nulltest(a) values (true and true);
    insert into #nulltest(a) values (null and null);
So my question remains, how do you insert an UNKNOWN?

The point of me asking is that it was my belief contrary to what was suggested, UNKNOWN is not the same as NULL and, crucially, does not evaluate as NULL.

Re:Postgres 15 improves UNIQUE and NULL by ratsmack on Monday July 11, 2022 @03:36PM (#32060724)
It's good to see that everyone agrees on the definition of NULL.
Re:Postgres 15 improves UNIQUE and NULL by DaiPlusPlus on Monday July 11, 2022 @04:01PM (#32061028)
Yes: a billion-dollar mistake.
Re:Postgres 15 improves UNIQUE and NULL by bazoom42 on Monday July 11, 2022 @05:07PM (#32061862)
This is s misunderstandig of Hoares “billion dollar mistake”. The mistake was not the existence of nulls, the mistake was type systems where every reference could be null.

Sql does not have this problem.

Re:Postgres 15 improves UNIQUE and NULL by lmm on Monday July 11, 2022 @09:26PM (#32064461)
SQL absolutely does have that problem. You have no way of enforcing or checking that an expression is supposed to be non-NULL; at best you get an error at runtime when you try to insert it into a given column, which is usually far too late.
Re:Postgres 15 improves UNIQUE and NULL by anamexis on Tuesday July 12, 2022 @09:32AM (#32069645)
This is only a problem insofar as any data constraint is a problem.
Re:Postgres 15 improves UNIQUE and NULL by lmm on Tuesday July 12, 2022 @05:53PM (#32076173)
No, it's a specific problem of SQL that you can apply constraints to stored or quasistored columns but not to expressions. In a real typed language every expression has a type.
Re:Postgres 15 improves UNIQUE and NULL by erichocean on Monday July 11, 2022 @04:46PM (#32061590)
And with RDBMSs, a multi-trillion dollar success!