Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with having count(distinct ...) #416

Open
nickgieschen opened this issue Aug 23, 2024 · 0 comments
Open

Problem with having count(distinct ...) #416

nickgieschen opened this issue Aug 23, 2024 · 0 comments

Comments

@nickgieschen
Copy link

Describe the bug

Runs successfully on PG

Error: πŸ”¨ Not supported πŸ”¨ : The query you ran generated an AST which parts have not been read by the query planner. This means that those parts could be ignored:

    ⇨ .having.type ("binary")
    ⇨ .having.left.type ("call")
    ⇨ .having.left.function.name ("count")
    ⇨ .having.left.function ({"name":"count"})
    ⇨ .having.left.distinct ("distinct")
    ⇨ .having.left.args[0].type ("ref")
    ⇨ .having.left.args[0].table.name ("TrackGenres")
    ⇨ .having.left.args[0].table ({"name":"TrackGenres"})
    ⇨ .having.left.args[0].name ("genreId")
    ⇨ .having.left.args ([{"type":"ref","table":{"name":"TrackGenres"},"name":"genreId"}])
    ⇨ .having.left ({"type":"call","function":{"name":"count"},"distinct":"distinct","args":[{"type":"ref","table":{"name":"TrackGenres"},"name":"genreId"}]})
    ⇨ .having.right.type ("integer")
    ⇨ .having.right.value (1)
    ⇨ .having.right ({"type":"integer","value":1})
    ⇨ .having.op ("=")
    ⇨ .having ({"type":"binary","left":{"type":"call","function":{"name":"count"},"distinct":"distinct","args":[{"type":"ref","table":{"name":"TrackGenres"},"name":"genreId"}]},"right":{"type":"integer","value":1},"op":"="})

πŸ‘‰ pg-mem is work-in-progress, and it would seem that you've hit one of its limits.

*️⃣ Failed SQL statement: select distinct on ("position", "trackId") "Tracks"."id" as "trackId", "Tracks"."title", "Tracks"."duration", "Tracks"."bpm", "PlaylistTracks"."trackId" as "playlistTrackId", "PlaylistTracks"."position" as "position", coalesce(json_agg(json_build_object('id', "Composers"."id", 'name', "Composers"."name"))) as "composers" from "Tracks" left join "PlaylistTracks" on "Tracks"."id" = "PlaylistTracks"."trackId" left join "TrackComposers" on "Tracks"."id" = "TrackComposers"."trackId" left join "Composers" on "TrackComposers"."composerId" = "Composers"."id" inner join "TrackGenres" on "Tracks"."id" = "TrackGenres"."trackId" inner join "Genres" on "TrackGenres"."genreId" = "Genres"."id" where "Tracks"."isMain" is true and ("Genres"."id" in ('1000') or "Genres"."parentId" in ('1000')) group by "Tracks"."id", "playlistTrackId", "PlaylistTracks"."position" having count(distinct "TrackGenres"."genreId") = 1 order by "position" asc, "trackId";

πŸ‘‰ You can file an issue at https://github.com/oguimbal/pg-mem along with a way to reproduce this error (if you can), and  the stacktrace:


    at StatementExec.checkAstCoverage (/Users/nick/dev/my-projects/soundmarket/node_modules/pg-mem/src/execution/statement-exec.ts:171:31)
    at /Users/nick/dev/my-projects/soundmarket/node_modules/pg-mem/src/execution/statement-exec.ts:217:34
    at pushExecutionCtx (/Users/nick/dev/my-projects/soundmarket/node_modules/pg-mem/src/utils.ts:404:16)
    at /Users/nick/dev/my-projects/soundmarket/node_modules/pg-mem/src/execution/statement-exec.ts:196:54
    at StatementExec.niceErrors (/Users/nick/dev/my-projects/soundmarket/node_modules/pg-mem/src/execution/statement-exec.ts:226:20)
    at StatementExec.executeStatement (/Users/nick/dev/my-projects/soundmarket/node_modules/pg-mem/src/execution/statement-exec.ts:196:21)
    at Bound.doExecute (/Users/nick/dev/my-projects/soundmarket/node_modules/pg-mem/src/schema/prepared.ts:248:25)
    at doExecute.next (<anonymous>)
    at Bound.executeAll (/Users/nick/dev/my-projects/soundmarket/node_modules/pg-mem/src/schema/prepared.ts:226:30)
    at DbSchema.query (/Users/nick/dev/my-projects/soundmarket/node_modules/pg-mem/src/schema/schema.ts:65:14)

To Reproduce

Sql is above

pg-mem version

3.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant