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

Skip to content

Support FILTER/WHERE and ORDER BY in aggregate expressions in Postgres dialect #4703

Closed
@matobet

Description

@matobet

SQLDelight Version

2.0.0

SQLDelight Dialect

Postgres

Describe the Bug

The following query does not compile:

selectArticles:
SELECT articles.id, slug, title, description, body, users.username, users.bio, users.image, createdAt, updatedAt
     , COALESCE (array_agg (DISTINCT tag ORDER BY tag) FILTER (WHERE tag IS NOT NULL), '{}') AS articleTags
FROM articles
LEFT JOIN tags ON articles.id = tags.article_id
JOIN users ON articles.author_id = users.id
GROUP BY articles.id, users.id;

:generateMainSqlDelightInterface fails with:

Compiling with dialect app.cash.sqldelight.dialects.postgresql.PostgreSqlDialect

/home/matobet/projects/kotlin/ktor-arrow-example/src/main/sqldelight/io/github/nomisrev/sqldelight/Articles.sq: (44, 41): '(', ')', '.', <binary like operator real>, <jsona binary operator real>, <jsonb binary operator real>, BETWEEN or IN expected, got 'ORDER'
43    SELECT articles.id, slug, title, description, body, users.username, users.bio, users.image, createdAt, updatedAt
44         , COALESCE (array_agg (DISTINCT tag ORDER BY tag) FILTER (WHERE tag IS NOT NULL), '{}') AS articleTags
                                               ^^^^^
45    FROM articles
46    LEFT JOIN tags ON articles.id = tags.article_id
47    JOIN users ON articles.author_id = users.id
48    GROUP BY articles.id, users.id

whereas the equivalent query works fine in Postgres.

Ideally the whole specification of aggregate expressions would be supported.

Stacktrace

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions