Thanks to visit codestin.com
Credit goes to github.com

Skip to content

columns not in aggregate function and group by #3200

@YuxiLing

Description

@YuxiLing

What happened?

PRQL compiler version:0.9.2

I found some related discussions in #2057. But some databases (such as Postgres, DuckDB, and Clickhouse) do not support a select clause to include a column that is not used in an aggregate function without a group by clause.

Error message from duckdb: Binder Error: column c0 must appear in the GROUP BY clause or be used in an aggregate function. Either add it to the GROUP BY list, or use "ANY_VALUE(c0)" if the exact value of "c0" is not important.

PRQL input

prql target:sql.duckdb
from tb1
sort {c0}
aggregate {new_col = min c1}

SQL output

WITH table_0 AS (
  SELECT
    MIN(c1) AS new_col,
    c0
  FROM
    tb1
)
SELECT
  new_col
FROM
  table_0

Expected SQL output

WITH table_0 AS (
  SELECT
    MIN(c1) AS new_col
  FROM
    tb1
)
SELECT
  new_col
FROM
  table_0

MVCE confirmation

  • Minimal example
  • New issue

Anything else?

No response

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