Skip to content

groupedLimit generates invalid SQL on Postgres when using offset in relation filters #149

Description

@jeffersoncardoso

Hi, I’ve found an issue when using sequelize-dataloader with Postgres.

When I add a limit and offset to a relation filter (for example when paginating nested associations), the generated SQL looks like this:

ORDER BY "id" ASC LIMIT ARRAY[11,1];

Postgres throws the following error:

argument of LIMIT must be type bigint, not type integer[]

This happens because internally groupedLimit builds the limit value as an array ([limit, offset]), which maps to the MySQL syntax LIMIT limit, offset. That’s valid in MySQL, but not in Postgres. Postgres requires the syntax LIMIT x OFFSET y.

It looks like this library relies on the undocumented groupedLimit behavior in Sequelize. From what I could find, it’s not clear whether this is a limitation in Sequelize itself (only working properly with MySQL syntax) or if it should also work with Postgres.

Could you clarify whether this limitation is expected at the Sequelize level, or if it’s something that could/should be resolved in this library? Any guidance on how to best support offsets per group on Postgres would be greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions