How to paginate Redshift Data API statement results using Boto3?

0

Hi,

I'm trying to use the the pagination functionality of the Redshift Data API (using boto3): https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift-data/paginator/GetStatementResult.html

However, I cannot seem to get this to work - I'm expecting a 'NextToken' to be returned in the response, but I never receive this.

I have example code that runs a SQL query to return 2000 rows, and then I'm limiting the RS Data API to return just one row per page (for testing purposes).

You can see from my screenshots below that despite the response stating there are 2000 total rows, it never provides a 'NextToken' to get the next page of resultss

Am I doing something wrong, or is this likely a bug?

Enter image description here

Enter image description here

cgddrd
asked a month ago414 views
2 Answers
0

Hi good morning,

Thanks for sending your questions regarding pagination and Redshift Data API using boto3. The boto3 for Redshift Data API supports the following methods: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift-data.html

The method get_paginator () can be used to paginate the results and specifically to the pagination of the method get_statement_result, you can set only MaxItems per page in the configuration (PageSize is not supported).

I've reproduced the scenario using Redshift sample data available in database sample_data_dev and I'm getting the same scenario when using MaxItems.

To help you with some alternatives you can do the following:

Regarding the method get_paginator and the iterator using the paginator for Redshift Data API, I will analyze and revert back as soon as I have more info. Meanwhile, I hope the alternatives I've provided helps to achieve the goals of your development.

AWS
answered a month ago
profile picture
EXPERT
reviewed a month ago
  • Thanks for your help. Are you able to confirm the conditions under which Redshift will automatically paginate results?

0

Hi good morning,

Regarding the method get_statement_result (https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift-data/client/get_statement_result.html)), the Redshift Data API will automatically split the results and return a NextToken automatically based on system internal conditions (query result size, etc). In this API, you can't configure a limit of rows per page (e.g. MaxItems or PageSize). However, as mentioned, the system will split the result automatically based on internal conditions.

AWS
answered a month ago
profile picture
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions