postgre 数据库 python操作
2015-01-28 12:13
127 查看
1. python connect postgre
https://wiki.postgresql.org/wiki/Using_psycopg2_with_PostgreSQL Using psycopg2 with PostgreSQL
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)
相关文章推荐
- python操作postgre数据库
- Python数据库操作手册
- Python学习笔记十(pymssql数据库操作)
- 使用Python操作MSSQL数据库.
- python+mysql 操作数据库出现的中文编码问题
- python中cursor操作数据库
- 使用 python 操作 access 数据库
- Python Sqlite3数据库相关操作
- python学习之数据库操作(mysql_ubuntu版)
- python 数据库blob数据操作
- Python 3.x之数据库框架Sqlalchemy操作SQlite(续)
- MySQLdb for Python使用指南/Python的数据库操作
- [Python]MySQLdb for Python使用指南/Python的数据库操作
- python 数据库操作
- [Python]MySQLdb for Python使用指南/Python的数据库操作
- [Python]MySQLdb for Python使用指南/Python的数据库操作
- MySQLdb for Python使用指南/Python的数据库操作
- 学习python 第三季:编写简单简单连接数据库并执行查询操作
- 【问题】如何在Python中操作数据库
- 使用Python 2.7 CURD 操作非关系型数据库MongoDB