python操作postgresql数据库

复制代码
import psycopg2
conn = psycopg2.connect(database="baoxin", user="odoo", password="odoo", host="127.0.0.1", port="5432")
cur = conn.cursor()
cur.execute("CREATE TABLE test(id serial PRIMARY KEY, num integer,data varchar);")
cur.execute("SELECT * FROM product_category;")
rows = cur.fetchall()        # all rows in table
print(rows)
for i in rows:
    print(i)
conn.commit()
cur.close()
conn.close()
复制代码

 

posted @   屌丝IT男  阅读(1767)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示