I'm storing Nesting JSON down as jsonb, but I have no idea how to select nested json with an uncertain value.

e.g.:

{
    "facebook": {
        "openid": "123456789",
        "access_token": "6EFD26B0A868E3BB387E78851E42943F"
    }
}

I know the value of openid but access_token is uncertain.

I tried the following but it raises an error.

cls.query.filter(User.auth["facebook"]["openid"].astext == openid).first()
share|improve this question
    
I believe SQLAlchemy does not have JSONB specific expressions yet and you might need to write the selection as raw SQL. – Mikko Ohtamaa Jul 3 '15 at 5:35
2  
dict = {"facebook": {"openid": "123456789"}} user = cls.query.filter(User.auth.contains(dict)).first() it takes effect – Nightsuki Jul 12 '15 at 7:20
    
JSONB operators: docs.sqlalchemy.org/en/latest/dialects/… – dukebody Oct 12 '15 at 12:50
    
@Nightsuki thanks a lot, you are my life saver! BTW I guess u r nozomi fans? – Dicky Tsang Mar 27 at 9:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.