首页 > 解决方案 > python:psycopg2:当列只有唯一值时如何查找行

问题描述

python在RealDictRow中搜索匹配

from cursor.fetchall()并使用cursor_factory=RealDictCursor,我得到以下数据

data = [RealDictRow([('id', 1921),
              ('rt', 1),
              ('state', 1)]),
 RealDictRow([('id', 1927),
              ('rt', 2),
              ('state', 0)]),
 RealDictRow([('id', 1928),
              ('rt', 3),
              ('state', 0)]),

我知道 rt 列值是唯一的

现在如何获取行when rt=1

并且在搜索rt=10不存在时也返回 None

标签: pythonpsycopg2

解决方案


推荐阅读