码迷,mamicode.com
首页 > 数据库 > 详细

postgre 数据库 python操作

时间:2015-01-28 13:00:13      阅读:172      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!