prql icon indicating copy to clipboard operation
prql copied to clipboard

Grouping breaks `select * except`

Open syko opened this issue 7 months ago • 2 comments

What happened?

A small issue where if a select !{...} is followed by a group, the exclude (...) bit goes missing from the SQL output. Regression since v0.10.1.

A workaround is to move the select after the group.

Encountered using bigquery but seems to be an issue in all dialects where SELECT * EXCLUDE is otherwise supported.

PRQL input

prql target:sql.bigquery

from foo
select !{a, b}
group {c} (
  sort {-d}
  take 1
)

SQL output

WITH table_0 AS (
  SELECT
    *,
    ROW_NUMBER() OVER (
      PARTITION BY c
      ORDER BY
        d DESC
    ) AS _expr_0
  FROM
    foo
)
SELECT
  *
EXCEPT
  (_expr_0)
FROM
  table_0
WHERE
  _expr_0 <= 1

-- Generated by PRQL compiler version:0.11.1 (https://prql-lang.org)

Expected SQL output

WITH table_0 AS (
  SELECT
    *,
    ROW_NUMBER() OVER (
      PARTITION BY c
      ORDER BY
        d DESC
    ) AS _expr_0
  FROM
    foo
)
SELECT
  *
EXCEPT
  (_expr_0, a, b)
FROM
  table_0
WHERE
  _expr_0 <= 1

-- Generated by PRQL compiler version:0.11.1 (https://prql-lang.org)

MVCE confirmation

  • [X] Minimal example
  • [X] New issue

Anything else?

No response

syko avatar Jan 02 '24 13:01 syko

Agree, thanks for the report @syko

max-sixty avatar Jan 02 '24 19:01 max-sixty

Introduced by https://github.com/PRQL/prql/pull/3826

PrettyWood avatar Jan 03 '24 00:01 PrettyWood