How to find out if there is more data after a query using LIMIT?

I use LIMIT and OFFSET in InfluxQL queries to handle pagination.

For example, when measuring with three rows.

 > SELECT *::field FROM i2QYtZBVSnuXjLhQhuAV6w; name: i2QYtZBVSnuXjLhQhuAV6w time hello ---- ----- 2018-02-23T18:00:00Z 1000 2018-02-23T18:30:00Z 1200 2018-02-23T19:00:00Z 990 

Suppose I read the lines one by one using LIMIT and OFFSET :

 > SELECT *::field FROM i2QYtZBVSnuXjLhQhuAV6w LIMIT 1; name: i2QYtZBVSnuXjLhQhuAV6w time hello ---- ----- 2018-02-23T18:00:00Z 1000 > SELECT *::field FROM i2QYtZBVSnuXjLhQhuAV6w LIMIT 1 OFFSET 1; name: i2QYtZBVSnuXjLhQhuAV6w time hello ---- ----- 2018-02-23T18:30:00Z 1200 > SELECT *::field FROM i2QYtZBVSnuXjLhQhuAV6w LIMIT 1 OFFSET 2; name: i2QYtZBVSnuXjLhQhuAV6w time hello ---- ----- 2018-02-23T19:00:00Z 990 

Is there any way to find out that after that there is no more data without performing an additional request?

EDIT: My use case generates a β€œnext page token” for a user-oriented REST API. I would like to avoid giving the user a token that just returns an empty set of strings.

+5
source share
1 answer

To avoid an additional query, you can always make a query to the database using limit as (limit + 1).

Example: set the limit to 6 if the actual limit is 5, and give the marker of the next page only if there are 6 rows in the result set. Also, return data for only 5 rows to the client.

+1
source

Source: https://habr.com/ru/post/1275553/


All Articles