has_more()
The has_more() function returns a boolean value indicating whether there are additional results available beyond the current page. It provides a convenient way to determine if more pages exist without having to check if the next page token is empty.
Elements
AS alias-
Required aliasing for the boolean result in the query response. The alias determines the field name in the response object.
Features
- Continuation Check
-
Provides a simple boolean indicator that can be used in user interfaces to show or hide "load more" or pagination controls.
- Works with All Paging Methods
-
Can be used with both token-based pagination and traditional offset/limit pagination.
- Zero Additional Fetch
-
Determines if more results exist without requiring an extra query to attempt to fetch the next page.
Examples
SELECT * AS products, has_more() AS moreAvailable
FROM products
LIMIT 10
SELECT * AS products,
next_page_token() AS nextPageToken,
has_more() AS hasMore
FROM products
OFFSET page_token_offset(:pageToken)
LIMIT 10
SELECT * AS products, has_more() AS moreProducts
FROM products
WHERE category = :category
ORDER BY price ASC
OFFSET :startFrom LIMIT :pageSize
SELECT * AS products, has_more() AS hasMoreProducts
FROM products
LIMIT 20
Usage Flow
-
Include in Query: Add the function to your SELECT clause with an alias:
SELECT * AS products, has_more() AS moreAvailable -
Response Structure: Define a response type including the boolean field:
public record ProductsResponse(List<Product> products, boolean moreAvailable) {} -
Client Logic: Use the boolean to control pagination UI:
if (response.moreAvailable()) { // Show "Load More" button or next page control } else { // Hide pagination controls - we're at the end }
Notes
-
The
has_more()function must have an alias specified withAS -
The function returns
trueif there are more results beyond the current page,falseif the current page contains the last results -
When used with
LIMIT, it checks if there are more thanLIMITresults matching the query -
The function is particularly useful for infinite scrolling or "load more" UI patterns
-
The function can be used alongside
next_page_token()to provide both a boolean indicator and a token for the next page
Related Features
-
next_page_token() function - Generates tokens for subsequent page requests
-
page_token_offset() function - Uses a token to determine offset position
-
Pagination - Complete guide to pagination approaches
-
LIMIT clause - Controls page size and works with has_more()