Skip to content

Aggregation can't handle Empty Embed #4582

@mertcorumlu

Description

@mertcorumlu

Environment

  • PostgreSQL version: 17.6.1
  • PostgREST version: 13.0.7
  • Operating system: Macos 15.6.1

Description of issue

I'm trying to count items in each group, but also want to filter by a nested embedding which is not a part of the group by or select.

There is something similar which allows filtering by an embed without actually selecting them using Empty Embed, this does not work once I add an aggregate function.

Altough this works just fine:
http://localhost:8080/select=group_column, id.count()

For this one I'm getting error:
http://localhost:8080/select=group_column,child(nested_child()),id.count()&child.nested_child.id=eq.1

{
    "code": "42703",
    "details": null,
    "hint": null,
    "message": "column \"child\" does not exist"
}

But without grouping this one works fine again:
http://localhost:8080/select=group_column,child(nested_child())&child.nested_child().id=eq.1

One solution that one can do is of course:
http://localhost:8080/select=group_column,child(nested_child(id)),id.count()&child.nested_child.id=eq.1

but this adds a new group by dimension child.nested_child.id, which I don't want to have.

I think the expected behavior here with the definition of Empty Embed is that PostgREST should just join the Embeds for filtering but ignore them in select and group by clauses, which it fails to do right now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    aggregatesRelated to aggregate functionalityembeddingresource embedding

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions