PRQL / prql

PRQL is a modern language for transforming data — a simple, powerful, pipelined SQL replacement
https://prql-lang.org
Apache License 2.0
9.98k stars 218 forks source link

append is buggy with a bit of logic in tables #4947

Open PrettyWood opened 1 month ago

PrettyWood commented 1 month ago

What happened?

Still working on a query builder to convert transformation steps into SQL via PRQL We have an issue with append that doesn't seem to work well with basic tables I'm more than happy to help on debugging this

PRQL input

from `albums`
select { `album_id`, `title` }
sort {+`album_id`}
take 2
append (
  from `albums`
  select { `album_id`, `title` }
  sort {-`album_id`}
  take 2
)

SQL output

fails

Expected SQL output

WITH table_0 AS (
  SELECT
    album_id,
    title
  FROM
    albums
  ORDER BY
    album_id DESC
  LIMIT
    2
)
SELECT
  *
FROM
  (
    SELECT
      album_id,
      title
    FROM
      albums
    ORDER BY
      album_id
    LIMIT
      2
  ) AS table_1
UNION
ALL
SELECT
  *
FROM
  table_0

MVCE confirmation

Anything else?

No response

PrettyWood commented 1 month ago

It may be the same bug as https://github.com/PRQL/prql/issues/4063. I'll start digging