使用 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")