Test data attached. Perhaps I'm doing something else wrong? -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm.session import Session
from sqlalchemy.schema import Column from sqlalchemy.types import Integer from sqlalchemy.dialects.postgresql import JSONB Base = declarative_base() class Foo(Base): __tablename__ = 'foo' id = Column(Integer, primary_key=True) data = Column(JSONB) database_url = "postgresql://brian@10.0.1.10:5432/test" e = create_engine(database_url, echo=True) Base.metadata.create_all(e) sess = Session(e) # Insert data user1 = Foo(id=1, data={'key1': ['a', 'b', 'c'], 'key2': ['d', 'e', 'f']}) user2 = Foo(id=2, data={'key1': ['g', 'h', 'i'], 'key2': ['j', 'k', 'l']}) user3 = Foo(id=3, data={'key1': ['m', 'n', 'o'], 'key2': ['p', 'q', 'r']}) sess.add_all([user1, user2, user3]) sess.commit() # Tests # stmt1 = sess.query(Foo).filter(Foo.data['key1'].has_key('a')).all() # stmt2 = sess.query(Foo).filter(Foo.data['key1'].cast(JSONB).has_key('a')).all()