Skip to content

SQL: sqllogictest query returns NULL instead of an error #7352

Description

@philrz

super returns null here:

$ super -version &&
  super -c "SELECT DISTINCT + 31 + + NULLIF ( - CAST ( NULL AS REAL ), - + 93 + - 22 / CASE COUNT ( * ) WHEN - NULLIF ( + 11, - 22 * 52 + 20 / + COALESCE ( - COALESCE ( 0, - 31 / 65 ), - 8 ) ) THEN - COUNT ( * ) ELSE NULL END ) AS col1;"
Version: v0.3.0-419-gb57febcd1
{col1:null}

Whereas Postgres surfaces a "division by zero" error:

$ psql postgres -c "SELECT DISTINCT + 31 + + NULLIF ( - CAST ( NULL AS REAL ), - + 93 + - 22 / CASE COUNT ( * ) WHEN - NULLIF ( + 11, - 22 * 52 + 20 / + COALESCE ( - COALESCE ( 0, - 31 / 65 ), - 8 ) ) THEN - COUNT ( * ) ELSE NULL END ) AS col1;"
ERROR:  division by zero

Details

Repro is with super commit b57febc.

This is the same sqllogictest query studied in #6533. That issue's purpose was to point out how Postgres happens to fail quickly here by sniffing out the constant division by zero, whereas we surfaced an error("divide by zero") that was wrapped inside of other errors. At the time both systems were surfacing errors, so I'd not frame #6533 as a bug. However, as the repro above shows, since that time conditions have changed such that super is now returning a null value instead of any kind of error, so this seems more like a bug.

To walk the history from the original repro in #6533, the error("divide by zero") went away at commit cbb4109, which is associated with the removal of typed nulls via the merge of #6633.

$ super -version &&
  super -c "SELECT DISTINCT + 31 + + NULLIF ( - CAST ( NULL AS REAL ), - + 93 + - 22 / CASE COUNT ( * ) WHEN - NULLIF ( + 11, - 22 * 52 + 20 / + COALESCE ( - COALESCE ( 0, - 31 / 65 ), - 8 ) ) THEN - COUNT ( * ) ELSE NULL END ) AS col1;"
Version: v0.1.0-23-gcbb41094c
{col1:error({message:"type incompatible with unary '-' operator",on:error({message:"cannot cast to float32",on:null})})}

Then the result became straight null starting at commit 43a111b, which is associated with the merge of #6666.

$ super -version &&
  super -c "SELECT DISTINCT + 31 + + NULLIF ( - CAST ( NULL AS REAL ), - + 93 + - 22 / CASE COUNT ( * ) WHEN - NULLIF ( + 11, - 22 * 52 + 20 / + COALESCE ( - COALESCE ( 0, - 31 / 65 ), - 8 ) ) THEN - COUNT ( * ) ELSE NULL END ) AS col1;"
Version: v0.1.0-51-g43a111b6b
{col1:null}

It looks like similar symptoms can be shown by changes in the results of this simplified query at the same spots:

$ super -version && super -c "SELECT NULLIF ( - CAST ( NULL AS REAL ), 1/0)"
Version: v0.1.0-22-g1bced4402
{NULLIF:error("divide by zero")}

$ super -version && super -c "SELECT NULLIF ( - CAST ( NULL AS REAL ), 1/0)"
Version: v0.1.0-23-gcbb41094c
{NULLIF:error({message:"type incompatible with unary '-' operator",on:error({message:"cannot cast to float32",on:null})})}

$ super -version && super -c "SELECT NULLIF ( - CAST ( NULL AS REAL ), 1/0)"
Version: v0.1.0-51-g43a111b6b
{NULLIF:null}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions