首页 > 数据库技术 > 详细

postgre 数据库 python操作

时间:2015-01-28 12:57:03      阅读:252      评论:0      收藏:0      [点我收藏+]

1. python connect postgre

https://wiki.postgresql.org/wiki/Using_psycopg2_with_PostgreSQL          Using psycopg2 with PostgreSQL

import psycopg2
import pprint


# get a connection, if a connect cannot be made an exception will be raised here conn = psycopg2.connect("dbname=‘db1‘ user=‘postgres‘ host=‘localhost‘ password=‘123‘")# conn.cursor will return a cursor object, you can use this cursor to perform queries cursor = conn.cursor() # execute Query cursor.execute("SELECT * FROM department") # retrieve the records from the database records = cursor.fetchall() #records = cursor.fetchone() # print out the records using pretty print pprint.pprint(records)

 

postgre 数据库 python操作

原文:http://www.cnblogs.com/phoenix13suns/p/4255474.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!