【发布时间】:2021-12-28 19:54:28
【问题描述】:
我已经建立了一个 postgresql 数据库。我运行以下代码来获取表的“状态”列中的唯一值(这些是代表 FIPS 数字的字符串):
import psycopg2 as ps
con = ps.connect("dbname=example_db user=user password=password")
cursor = con.cursor()
cursor.execute('SELECT DISTINCT(%s) FROM example_table', ('state',))
results = cursor.fetchall()
这会返回:
results
('state',)
如果我在 PGAdmin4 中运行相同的查询,我会得到:
example_db=# SELECT DISTINCT state FROM example_table;
state
-------
06
(1 row)
我想使用 psycopg2 获取不同的值(在本例中为 06)。我需要改变什么?
【问题讨论】:
标签: postgresql psycopg2