-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Keyset pagination #141
Comments
Yes. An example: query {
articles (
order_by: published_date_desc,
limit: 10,
where: { published_date: { _lt: previous_value } }
) {
id
title
published_date
}
} You can use multiple columns too if published_date is not unique. query {
articles (
order_by: [published_date_desc, id_desc],
limit: 10,
where: { published_date: { _lt: last_item_published_date } id: { _lt: last_item_id } }
) {
id
title
published_date
}
} |
Thanks for the response. How does that What I'm looking for is actually row-level comparison across columns. For a more complicated example, consider a table that has three columns: SELECT pk, user, seen
FROM accesses
WHERE (user, seen, pk) > (
SELECT user, seen, pk
FROM accesses
WHERE pk = 12345
)
ORDER BY user, seen, pk
LIMIT 100 The A row comparison like this: WHERE (user, pk) > ('bob', 456) Would be logically equivalent to WHERE user > 'bob' OR user = 'bob' AND pk > 456 Not just WHERE user > 'bob' and pk > 456 For further background on keyset pagination (and comparison with other pagination techniques), here's a few links: https://use-the-index-luke.com/no-offset |
Oh ! Right. This can be expressed in {
_or: [
{user: {_gt: "bob" }},
{user: {_eq: "bob"}, pk: { _gt: 456}}
]
}
There is no way to currently express comparisons like these Does this work? |
Yes that is workable. Obviously not terribly beautiful, but workable. AFA a nice syntax, I wonder if you already have some precedent for syntax that calls PG functions? The expression Also embedded in my previous example was a subquery. Does Hasura support subqueries, such that if we figured out the function call syntax my whole use case of looking up the ordered field values for the particular pk would be possible? |
We don't plan to add subqueries or function call syntax as of now. It'll be hard to reason about and enforce access control rules. You can still do the cursor based pagination as follows: Create a view which gives us ordering information: CREATE VIEW accesses_cursor AS
SELECT
l.pk as "access_id",
r.pk as "after"
FROM
accesses l
JOIN
accesses r
ON
((l.user, l.seen, l.pk) > (r.user, r.seen, r.pk)); Now we add what we call an query paginated_accesses {
accesses (
order_by: [user_asc, seen_asc, pk_asc]
where: {cursor: {after: {_eq: 12345}}}
limit: 100
){
pk
user
seen
}
}
SELECT
pk
user
seen
FROM
accesses a
WHERE
EXISTS (
SELECT 1 FROM accesses_cursor c
WHERE c.access_id = a.pk AND c.after = 12345
)
ORDER BY (user, seen, pk) |
Thanks. I'll have to take some time to digest that, thank you for your feedback. |
@rikinsk should we add this to docs? |
Expanded in #3498 |
GitOrigin-RevId: 015f131219112f12c94aad20a865b1d7efd64248
Does Hasura support Keyset pagination? It's basically cursor pagination, where the identifier for the last item in the sorted list is serialized and sent to the client so that the client can ask for another page starting from that spot.
The text was updated successfully, but these errors were encountered: