sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Composition for paging ?

Open benoitdupont opened this issue 1 year ago • 0 comments

What do you want to change?

Hello, my use case is the following:

I've a request with many WHERE clauses, invoked from a webservice with paging parameters (offset and limit).

The webservice call will triggers 2 database queries:

  1. The full request that will return results
  2. The COUNT request, to get all the objects in database with the same WHERE clauses (but without the offset/limit parameters), which return only an integer.

Is there a way to "reuse" the defined request in sqlc (so I'll need somehow to parametrize the SELECT clause) and then have only one query instead of to ?

-> I can do it programmatically but then I load objects "for nothing" when I count the items. -> The other solution is to duplicate the queries, which I also want to avoid if I can for an easier maintenance

WDYT ? Perhaps it's already possible but I didn't find it in the documentation.

I tried with a (it's PostgreSQL) CASE WHEN in the select clause, but it doesn't works because the count(*) and the records doesn't have the same type ([42804] ERROR: CASE types record and bigint cannot be matched)

What database engines need to be changed?

No response

What programming language backends need to be changed?

No response

benoitdupont avatar Jun 03 '24 08:06 benoitdupont