python - 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
解决方案
推荐阅读
- c - 对 C 中的“按引用传递”以及何时使用 & 或 * 感到困惑
- swift - Swift:URL(fileURLWithPath:) 根本不返回任何值,甚至不返回 nil
- assembly - 在 Linux x86 程序集(64 位)中打印 argv[0]
- reactjs - 使用 withStyles() 和 compose() 和 Redux/Firebase/Material UI 导出组件
- python - 迭代并将元素添加到包含多个字典的列表
- python - 为什么(在 Python 中)random.randint 比 random.random 慢得多?
- python - 获取重新创建对象所需的导入
- nginx - .Net 核心 X-Forwarded-Proto 标头未正确传递给 Nginx
- microsoft-cognitive - Python [w/Azure 开发人员帐户] 中的“HTTPError: 429 Client Error: Too Many Requests for url”
- javascript - Vue 在加载后使用 v-for 渲染计算属性