pip install psycopg2 psycopg2-binary
#!/usr/bin/python
import psycopg2
conn = psycopg2.connect(database="test", user="postgres", password="postgres", host="10.200.22.110", port="5432")
print "Opened database successfully"
cur = conn.cursor()
cur.execute("SELECT id, name from test")
rows = cur.fetchall()
for row in rows:
print "ID = ", row[0]
print "NAME = ", row[1], "\n"
print "Operation done successfully";
conn.close()
原文地址:https://www.cnblogs.com/EikiXu/p/9698787.html
时间: 2024-10-11 18:27:01