Closed avneeshn closed 11 months ago
Hi @avneeshn, are you familiar with the Cursor.rowcount
property? I believe this may be what you're looking for. After executing a UPDATE
or CREATE
statement, Cusor.rowcount
will provide the number of rows produced by the last call to execute()
. Cursor.fetch__
methods return the result set returned from statement execution. Given CREATE
and UPDATE
statements do not produce a result set, raising an exception is the expected behavior per the DB-API spec
Thanks for the comment and quick-response @Brooke-white. So, we are developing an SQL client for our users to run queries. So we have no way of knowing in advance if it is a DML/DDL statement, or SELECT query. That is why we are using cursor.fetchall()
everytime.
Regarding your approach regarding Cusor.rowcount
, I believe this property will be non-zero for both an UPDATE
query and a SELECT
query. Do you know how can we use this property (or another approach) to identify whether a call to cursor.fetchall()
needs to be made or not?
I'd recommend adding try/catch logic around the call to fetchall()
, where the catch statement catches redshift_connector.ProgrammingError
Driver version
2.0.913
Redshift version
PostgreSQL 8.0.2 on i686-pc-linux-gnu
Client Operating System
Linux
Python version
3.8
Table schema
Problem description
cursor.fetchall()
while executing SQL DML statements.cursor.fetchall()
while executing SQL DML statements. For eg: Run:Output:
P.S. the same issue occurs for an UPDATE query.
Python Driver trace logs
Reproduction code