Checking for resultset in Python DB API
2020-11-06 (Friday)
(Warning: Only tested with psycopg2) Sometimes you want to execute an SQL query but don’t know whether it will return a resultset in advance. An example would be a psql-like interface where the user can type arbitrary queries (DQL, DML, or DDL) or a very generic interface class. Calling fetchone() or fetchall() raises a ProgrammingError when there is no resultset. We could catch that, but that’s not elegant. Parsing the query to determine whether it should return a resultset is not feasible.