psycopg2でクエリを実行するのに最適なパターンはどれですか?
これです:
# get_connection is a function that returns a connection to the db.
with get_connection() as conn:
with conn.cursor() as cursor:
cursor.execute("SELECT * FROM test_table")
or simply this:
with get_connection() as conn:
cursor = conn.cursor()
cursor.execute("SELECT * FROM test_table")