SQLAlchemy JSON列-如何执行包含查询 [英] Sqlalchemy json column - how to preform a contains query
本文介绍了SQLAlchemy JSON列-如何执行包含查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在mysql(5.7.12)中具有下表:
I have the following table in mysql(5.7.12):
class Story(db.Model):
sections_ids = Column(JSON, nullable=False, default=[])
sections_ids 基本上是整数[1、2,...,n]的列表. 我需要获取sections_ids包含X的所有行. 我尝试了以下方法:
sections_ids is basicly a list of integers [1, 2, ...,n]. I need to get all rows where sections_ids contains X. I tried the following:
stories = session.query(Story).filter(
X in Story.sections_ids
).all()
但是它抛出:
NotImplementedError: Operator 'contains' is not supported on this expression
推荐答案
As you're searching an array at the top level, you do not need to give path.
这篇关于SQLAlchemy JSON列-如何执行包含查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文