如何使用Python操纵Postgres数据库

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()

猜你喜欢

转载自www.cnblogs.com/EikiXu/p/9698787.html
今日推荐