0

I wish to query a valid json placed in a column of type TEXT(not JSON).

E.g. I wish to something like that:

records = db_session.query(Resource).filter(
              Resources.data["lastname"] == "Doe"
          ).all()

What should I do if the data column is of type TEXT?

1 Answer 1

1

You can cast the column to JSON (or JSONB if you are using PostgreSQL) to enable JSON operations:

records = db_session.query(Resource).filter(
              db.cast(Resources.data, db.JSON)["lastname"] == "Doe"
          ).all()

alternatively, use the column's cast method:

records = db_session.query(Resource).filter(
              Resources.data.cast(db.JSON)["lastname"] == "Doe"
          ).all()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.