Skip to content
Discussion options

You must be logged in to vote

hi -

take a look at "Casting JSON Elements to other types" at https://docs.sqlalchemy.org/en/20/core/type_basics.html#sqlalchemy.types.JSON . basically struct["key"] can be any JSON, and in the case of MySQL, it's working by accident. the correct, platform agnostic way to compare an element in a json struct as a string to a string is to use as_string(); otherwise SQLAlchemy doesn't know what kind of comparison you want to do:

query = session.query(Person.id).filter(
    Person.message["name"].as_string() == "Bob"
)

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@vba34520
Comment options

@zzzeek
Comment options

Answer selected by vba34520
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datatypes things to do with database types, like VARCHAR and others json things to do with JSON
2 participants