我正在使用python、psycopg2和postgresql。想办法吗 按名称直接引用列。参见下面的示例。你知道吗
TABLE testtable
testcolumn1 | testcolumn2 | testcolumn3
------------+-------------+------------
horse | cow | goat
simple | code | test
cant | figure | this
conn = psycopg2.connect("dbname='test' user='me' password='pass'")
cursor = conn.cursor()
cursor.execute("select * from testtable")
cursor_rows = cursor.fetchall()
for row in cursor_rows:
print(row['testcolumn2'])
# the result of the loop should be
cow
code
figure
有没有这样的方法可以直接引用列名?你知道吗
谢谢你的帮助
尝试使用
Documentation here. There is also support for named tuples.
相关问题 更多 >
编程相关推荐