我想从数据库中获得一张表,但要包含字段名称,以便我可以在例如Pandas的列标题中使用它们,而我不必事先知道所有字段名称
所以如果我的数据库看起来像
table test1
a | b | c
---+---+---
1 | 2 | 3
1 | 2 | 3
1 | 2 | 3
1 | 2 | 3
1 | 2 | 3
我该怎么办
import psycopg2 as pq
cn = pq.connect('dbname=mydb user=me')
cr = cn.cursor()
cr.execute('SELECT * FROM test1;')
tmp = cr.fetchall()
tmp
这样的tmp显示
[('a','b','c'),(1,2,3),(1,2,3),(1,2,3),(1,2,3),(1,2,3)]
谢谢
Cats萌萌
慕勒3428872
慕妹3146593
相关分类