I'm looking for some API design advice. The PostgreSQL developers are currently considering an extension of the PL/Python database access API [0]. This is, for better or worse, a lower-level custom Python database access API, but you can build DB-API on top of that.
We have added a few functions that extract metadata such as column names and types from a result set object (rv.colnames(), rv.coltypes(); think cursor.description). The question was what to do when there is no resulting row set, because the command was a utility command such as CREATE TABLE. Option 1 was that the functions should throw an exception, because the request is invalid. Option 2 was that the functions should return None. (This is what cursor.description is specified to do.) This was objected to because it would require extra checking for None. In addition to that, the question relative to option 1 in particular was how to detect whether a result row set exists, to avoid the exception-throwing calls. With option 2 you could check for is None, of course. There is an ongoing discussion [1] about which ones of these would be better style. So, in terms of code, which one of these is "better"? 1a. rv = plpy.execute("some SQL command") try: output(rv.colnames()) except SomeException: output("it's a utility command") 1b. rv = plpy.execute("some SQL command") if rv.has_rows(): # some currently nonexisting function to be added output(rv.colnames()) else: output("it's a utility command") 2. rv = plpy.execute("some SQL command") if rv.colnames() is not None: output(rv.colnames()) else: output("it's a utility command") [0] http://www.postgresql.org/docs/devel/static/plpython-database.html [1] http://archives.postgresql.org/message-id/cak6bcay4yrfjd3po_bcke4ukjjsplkbf+ad07jziau3n6cw...@mail.gmail.com _______________________________________________ DB-SIG maillist - DB-SIG@python.org http://mail.python.org/mailman/listinfo/db-sig