News for hackers. Stuff that matters.
Re:SQL: The difference between WHERE and HAVING by dragonwriter on Tuesday December 14, 2021 @03:21PM (#29557011)
> There isn't even an operator included in ANSI SQL to let us convert null boolean values into false, because for some reason bits and bools are two different things

“bit” is not a standard SQL type at all, it's an SQL server proprietary 1-bit numeric type. boolean is an standard SQL type, but SQL Server doesn't support it as a storage type or consistently elsewhere (it does exist, annoyingly, in some contexts, but is limited in where it or expressions producing it can appear, which—not any limitation of standard SQL—is the source of your problem.)

> and you can't just say COALESCE(x = y, false)

In something that supports standard SQL in the relevant parts, like Postgres, yes, you absolutely can.

In SQL Server, you have to do something clumsy like:

  CASE
    WHEN x=y THEN 1
    ELSE 0
  END
But that is “SQL Server is broken and barely supports booleans even as intermediate values” not “standard SQL is broken”.

There are plenty of valid criticisms of standard SQL around NULLs, but the particular brokenness of SQL Server’s handling of booleans is not one of them.

Re:SQL: The difference between WHERE and HAVING by Pxtl on Tuesday December 14, 2021 @04:37PM (#29558237)
AFAIK MySQL and Oracle have the same flaws.
Re:SQL: The difference between WHERE and HAVING by dragonwriter on Tuesday December 14, 2021 @05:33PM (#29559048)
MySQL and Oracle also lack standard boolean support while allowing true boolean values as results in certain positions, AFAIK, yes, although some versions of MySQL use “Boolean” as an alias for tinyint(1) and even more support TRUE and FALSE (without quotes) as aliases for 1 and 0, which confuses the issue a bit.

SQLite has a similar problem, averts the practical because it doesn't use booleans natively internally in which they apply, instead natively using 0 and 1 (with TRUE and FALSE as aliases) and then converting to boolean in the narrow set of boolean contexts. This means that can use COALESCE as described (and, generally, SQLite will behave as you would expect with real Boolean support, even though it doesn't actually have it.)

DB2, from what I can find, supports BOOLEAN from v11.1.

In any case, the problem here is not a standard SQL problem, even if it is a problem of several popular SQL implementations.