python - sqlalchemy 中的数组过滤
问题描述
我想以这种方式过滤我的数组字段:我有数组 my_array {'one', 'two', 'three'} 并且我想按值列表过滤数据 ['one', 'two']。因此,如果我的数组中有“一”和“二”,那么我会得到这些数据。我试图用 sqlalchemy 'contains' 来实现这一点。
result = session.query(Alert).filter(Alert.tag_list.contains(tag_list)).filter(
Alert.date_create >= datetime.datetime.utcnow() - datetime.timedelta(minutes=c.ALERT_TIME_LIVE)).order_by(Alert.person_id).limit(
per_page).offset((page - 1) * per_page).all()
我的数据库类型from sqlalchemy.dialects.postgresql import ARRAY
和tag_list = Column(ARRAY(String(50), dimensions=1))
. 但是当我尝试完成我的查询时,即使我的数组中存在两个标签,我也会收到空列表。
在此处输入图像描述
在我的图片中我有标签'test',但是当使用'contains(['test','test1'])'它返回[]。
解决方案
推荐阅读
- php - SQLite没有插入到PHP中的表中
- python - 查找 Primes 时收到“TypeError:'int' object is not callable”错误?
- wordpress - 修改woocommerce客户邮箱
- javascript - 将两个 div 放入一个 div 然后使用 justify 内容后出现随机空白
- c++ - 将 std::string 转换为/从枚举类的正确方法
- python - 如何在 Python 3 中将 utf-8 文本文件转换为 Json 对象
- mongodb - 我可以从 MAP 的键创建 Mongoose 虚拟对象吗?
- python - 无法使用 pip 安装某些 Python 模块
- ocr - 识别游戏库存屏幕截图中的项目和数量
- http - Power Automate 通过 SP HTTPS 发送电子邮件不发送到特定地址