boto3 icon indicating copy to clipboard operation
boto3 copied to clipboard

boto3.client('redshift-data') don't work with pg_last_query_id()

Open dburtsev opened this issue 2 years ago • 3 comments

Describe the bug

Amazon Redshift maintains insert execution steps for INSERT queries in STL_INSERT system table. We can query this table to get rows inserted in the last insert statement. boto3.client('redshift-data') return None after insert.

Expected Behavior

We should get the number of rows inserted in the last insert statement.

Current Behavior

Return None

Reproduction Steps

import boto3

def ExecuteNonQuery(Boto3Client,ClusterIdentifier,Database,DbUser,Sql): rows = 0 Response1 = Boto3Client.execute_statement(ClusterIdentifier=ClusterIdentifier,Database=Database,DbUser=DbUser,Sql=Sql) Response2 = Boto3Client.describe_statement(Id=Response1['Id']) while Response2['Status'] in ['PICKED', 'STARTED', 'SUBMITTED']: Response2 = Boto3Client.describe_statement(Id=Response1['Id']) if Response2['Status'] != 'FINISHED': print("Expect FINISHED got " + Response2['Status']) raise ValueError("Expect FINISHED got " + Response2['Status'] + ' ' + Response2['Error']) Response1 = Boto3Client.execute_statement(ClusterIdentifier=ClusterIdentifier,Database=Database,DbUser=DbUser,Sql='select sum(rows) as inserted_rows from stl_insert where query=pg_last_query_id();') Response2 = Boto3Client.describe_statement(Id=Response1['Id']) while Response2['Status'] in ['PICKED', 'STARTED', 'SUBMITTED']: Response2 = Boto3Client.describe_statement(Id=Response1['Id']) Response3 = sql_client.get_statement_result(Id=Response1['Id']) rows = Response3['Records'][0][0].get('longValue') print(Response3['Records']) return rows

CREATE TABLE dev.test10 (id INTEGER IDENTITY, strng VARCHAR(256));

sql_client = boto3.client('redshift-data', region_name = 'us-east-1') sql = "INSERT INTO dev.test10 (strng) VALUES ('abc2'),('qwe2');" ClusterIdentifier = 'abc' Database = 'xyz' DbUser = 'qwe' i = ExecuteNonQuery(sql_client,ClusterIdentifier,Database,DbUser,sql) print(i)

Possible Solution

No response

Additional Information/Context

No response

SDK version used

1.9.86

Environment details (OS name and version, etc.)

Windows 10

dburtsev avatar Aug 05 '22 16:08 dburtsev

Hi @dburtsev thanks for reaching out. It looks like you're using a pretty old version of boto3 - the latest version is 1.24.46. If you update then it might address issues like this that are related to service APIs. If you update and are still seeing the issue could you share your debug logs (with any sensitive info redacted) by adding boto3.set_stream_logger('') to your script?

tim-finnigan avatar Aug 05 '22 16:08 tim-finnigan

Python 3.9.7 pip show boto3 -> Version: 1.24.28

The same result.

dburtsev avatar Aug 05 '22 17:08 dburtsev

@tim-finnigan boto3.set_stream_logger adde stream_logger.txt d

dburtsev avatar Aug 08 '22 17:08 dburtsev

Closing this and will follow up here on service API issue: https://github.com/aws/aws-sdk/issues/322

tim-finnigan avatar Aug 15 '22 16:08 tim-finnigan