psycopg2 存储数据库使用

import psycopg2

conn = psycopg2.connect(database="postgres", user="postgres", password="123456", host="127.0.0.1", port="5432")
cur = conn.cursor()
list = ['宝鸡新闻','地方政策','一带一路','十三五规划','高层讲话','智慧城市','招商引资','宏观经济环境','高科技产业','工业制造与工业4.0','互联网+','行业新闻']

for i in list:
cur.execute("SELECT id from bjzs_big_data.baoji_catalog where name = '{}'".format(i))
rows = cur.fetchall()
print(rows) #[(11,)]读到的是这样
print(rows[0][0]) #11 读到的是这个
conn.close()
原文地址:https://www.cnblogs.com/yuanjia8888/p/9935993.html