Skip to content

Add alias to KeySet pagination Key #1612

@norberttech

Description

@norberttech

Currently when using keyset pagination we might get to the edge case where key might be ambiguous column.

This might happen when we join tables, both have id column but in the select we expose only one of them:

SELECT
 a.id as id
FROM table_a a
LEFT JOIN table_b b ON a.sub_id = b.sub_id
WHERE id > :id_previous
ORDER BY id

In this case postgresql will complain that id is ambiguous.

The solution is to add alias to key, so the column will be used in the WHERE/ORDER BY part of the query and alias is going to be used to take last value from previous results.

Alternatively we could dynamically add an alias to the query and then remove it once we retrieve the value from last row of previous batch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions