GNU/Linux Desktop Survival Guide
by Graham Williams |
|||||
PostgreSQL Python Access |
20200819
import psycopg2 conn = psycopg2.connect(host='test', database='kayon', user='kayon', password='secret') cur = conn.cursor() cmd = 'SELECT * FROM iris LIMIT 5' print(cmd) cur.execute(cmd) rows = cur.fetchall() for row in rows: print(row[0], row[1], row[2], row[3], row[4]) cur.close() conn.close() |