2023-01-18 (Wednesday)
Database PyPI Debian Ubuntu import Rows as named tuples PostgreSQL psycopg import psycopg import psycopg.rows
csr = db.cursor(row_factory=psycopg.rows.namedtuple_row) MySQL/MariaDB mysqlclient python3-mysqldb python3-mysqldb import MySQLdb MySQL/MariaDB mysql-connector n/a python3-mysql.connector import mysql.connector csr = db.cursor(named_tuple=True)
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.
2020-10-17 (Saturday)
Alphora-Style Database Diagramming