Let's say if I execute the following command.
insert into hello (username) values ('me')
and I ran like
cursor.fetchall()
I get the following error
psycopg2.ProgrammingError: no results to fetch
How can I detect whether to call fetchall() or not without checking the query is "insert" or "select"?
Thanks.
cursor.execute("insert into hello (username) values ('me')")
? – Impartibleinsert
orselect
or something else) has got this far into the code without knowing what type of query it is. Where is the SQL being entered? Are you protecting against SQL Injection? I strongly suggest that the code should be aware of the type of query being handled and have different code paths for handlinginserts
vsselects
, ideally using a known set of queries - possibly stored procedures - and apart from the case where a select query returns no description this question shouldn't be an issue. – Parity