launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
13.52k stars 1.28k forks source link

Use `UNION ALL` instead of `UNION` in nullable check #3605

Open Suficio opened 4 days ago

Suficio commented 4 days ago

Instead of generating nullable query using VALUES, use UNION ALL syntax.

Current query:

SELECT NOT attnotnull FROM (
  VALUES
    ( $1::int4, $2::int4, $3::int2 ),
    ( $3::int4, $4::int4, $5::int2 ),
) AS col(idx, table_id, col_idx) ...

Becomes:

SELECT NOT attnotnull FROM (
  ( SELECT $1::int4 AS idx, $2::int4 AS table_id, $3::int2 AS col_idx )
  UNION ALL ( SELECT $1::int4, $2::int4, $3::int2 )
) AS col ...

This change allows better support for databases that support a pgwire interface but with limited SQL syntax. In particular, timeseries databases such as QuestDB and kdb are unsupported.

abonander commented 6 hours ago

I'm not against merging this, but for the record I consider this a database bug.