import psycopg conn = psycopg.connect("host=127.0.0.1 port=5432 user=tom password=pencil dbname=localdb") conn.autocommit = True with conn.cursor() as cur: cur.execute("INSERT INTO testtable VALUES (1)") print(cur.statusmessage) with conn.cursor() as cur: cur.execute("SELECT * FROM testtable") print(cur.fetchall()) with conn.cursor() as cur: cur.execute("SELECT * FROM testtable WHERE id = %s", [1]) print(cur.fetchall())