Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

SQL: sqllogictest query returns NULL instead of an error

Aperta
#7,352 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
go, sql
Ambito
databases

Direzione di ricerca

Start by comparing the behavior of NULLIF and division by zero in the SQL evaluation path, using the simplified SELECT NULLIF ( - CAST ( NULL AS REAL ), 1/0) repro. The issue points to changes around commits cbb4109 and 43a111b, associated with #6633 and #6666; trace those changes and add a regression test. Done means the query returns an error rather than null.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug sql-coverage

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}
Lingua principale
Go
Stelle
1.6k
Fork
84
Merge medio
10h
PR unite (30g)
125

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di superdb/super

Tutte le issue di superdb/super

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.