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
已提問 2 個月前檢視次數 429 次
2 個答案
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
已回答 2 個月前
profile picture
專家
已審閱 2 個月前
  • 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
已回答 2 個月前
profile picture
專家
已審閱 2 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南