Psycopg2 DictCursor returns 没有

Psycopg2 DictCursor returns nothing

我的查询是:

query = '''
    SELECT * from table
    where id IN (SELECT ext_id from table2
            where title= %s and year = %s)
'''

接下来我使用

cursor = conn.cursor(cursor_factory=pg.extras.DictCursor)
cursor.execute(query, (title, year))
result = cursor.fetchall()

它returns[],即什么都没有

但是如果我设置 cursor = conn.cursor() 相同的查询 returns 某些行!出了什么问题?为什么我不能使用 DictCursor?

在我的代码中不要使用 pg.extras.DictCursor.

我使用 psycopg2.extras.DictCursor

我写下:

import psycopg2
import psycopg2.extras

cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)

然后我就可以使用密钥访问内容了。

试一试,告诉我。