- Newest
- Most votes
- Most comments
As you my already know, Redshift Data API is asynchronous, and you get the unique identifier of the SQL statement after running using ‘execute_statement’.
I tested this with a stored procedure test_sp2 that you can find in the below documentation [+] https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_PROCEDURE.html Stored procedure being test_sp2(f1 IN int, f2 INOUT varchar(256), out_var OUT varchar(256)) It has both INOUT and OUT parameters
Used below to execute the stored procedure response = client.execute_statement( ClusterIdentifier=‘<clustername>’, Database='<databasename’>, DbUser=‘user’1, Sql= 'call test_sp2(2,'2019')', StatementName='testsql' )
You can get ID with the below statement
IDval=response['Id']
print(IDval)
<ID value> — id value is returned
Once you have confirmed that the stored procedure is completed, you can use ‘get_statement_result’ to fetch the temporarily cached result of an SQL statement
response_result = client.get_statement_result(
... Id=‘<ID value from previous step>’
... )
This response would contain results of the SQL statement. To retrieve the results, you can try below
print(response_result['Records'])
[[{'stringValue': '2019+2019+2019+2019'}, {'stringValue': '2'}]]
These would be the INOUT/OUT parameters of the stored procedure. To fetch them individually, we can use print(response_result['Records'][0][1]) and print(response_result['Records'][0][1])
Relevant content
- Accepted Answerasked 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 5 months ago