首页 > 代码库 > postgre 数据库 python操作
postgre 数据库 python操作
1. python connect postgre
https://wiki.postgresql.org/wiki/Using_psycopg2_with_PostgreSQL Using psycopg2 with PostgreSQL
import psycopg2import pprint
# get a connection, if a connect cannot be made an exception will be raised hereconn = psycopg2.connect("dbname=‘db1‘ user=‘postgres‘ host=‘localhost‘ password=‘123‘")# conn.cursor will return a cursor object, you can use this cursor to perform queriescursor = conn.cursor()# execute Querycursor.execute("SELECT * FROM department")# retrieve the records from the databaserecords = cursor.fetchall()#records = cursor.fetchone()# print out the records using pretty printpprint.pprint(records)
postgre 数据库 python操作
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。