If you’re using the native JSON or JSONB types in PostgreSQL, SQLAlchemy has 
some extra support for that type:

http://docs.sqlalchemy.org/en/rel_1_0/dialects/postgresql.html#sqlalchemy.dialects.postgresql.JSONB

Simon

> On 15 Mar 2016, at 20:57, Christopher Lee <[email protected]> wrote:
> 
> Are you referring to the sqlalchemy-utils JSONType 
> (https://github.com/kvesteri/sqlalchemy-utils)?  It doesn't look like it 
> supports querying at all, only saving Python dicts directly.
> 
> If you are using PostgreSQL and the native Json type, you might want to check 
> out:
> https://www.compose.io/articles/using-json-extensions-in-postgresql-from-python-2/
>  
> 
> On Tue, Mar 15, 2016 at 9:50 AM, 'Boncheff' via sqlalchemy 
> <[email protected]> wrote:
> We have a DB model that contains a 'foo' field which is JSONType
> 
> Inside this we store the following data:
> 
> foo =>    [{"apps": ["test_app"]}, {"tags": ["test_tag1", "test_tag2"]}]
> 
> My question is, how can I, using session.query, select all items that have a 
> test_tag_1 as a tag inside the foo column?
> 
> I tried 
> session.query(MyModel).filter(MyModel.foo[0]['tags'].in_('test_tag1')).all() 
> but this results in 
> 
> *** NotImplementedError: Operator 'getitem' is not supported on this 
> expression
> 
> Is what I am trying to achieve even possible?
> 
> -- 
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
> 
> 
> -- 
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to