Skip to content

append with null columns leads to runtime SQL error UNION types x and y cannot be matched #5341

@Fanaen

Description

@Fanaen

What happened?

  • Doing an append in postgres with null columns on one side.
  • prqlc outputs a query that leads to runtime failure UNION types integer and text cannot be matched.

PRQL input

prql target:sql.postgres

from invoices | select { an_id = invoice_id, a_date = null } | take 2
append (from employees | select { an_id = null, a_date = birth_date } | take 2)

SQL output

WITH table_0 AS (
  SELECT
    NULL AS an_id,
    birth_date AS a_date
  FROM
    employees
  LIMIT
    2
)
SELECT
  *
FROM
  (
    SELECT
      invoice_id AS an_id,
      NULL AS a_date
    FROM
      invoices
    LIMIT
      2
  ) AS table_1
UNION
ALL
SELECT
  *
FROM
  table_0

Expected SQL output

(
  SELECT
    invoice_id AS some_id,
    NULL AS some_date
  FROM
    invoices
  LIMIT
    2
)
UNION
ALL (
  SELECT
    NULL AS some_id,
    birth_date AS some_date
  FROM
    employees
  LIMIT
    2
)

MVCE confirmation

  • Minimal example
  • New issue

Anything else?

The SQL output works in the PRQL playground.
It seems some engines struggle to infer types with those SELECT * FROM in the way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugInvalid compiler output or panic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions