如何使用Python操纵Postgres数据库

Posted 书山有路勤为径,学海无涯苦作舟

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用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], " "

print "Operation done successfully";
conn.close()










以上是关于如何使用Python操纵Postgres数据库的主要内容,如果未能解决你的问题,请参考以下文章