How to query on a JSON-type field with SQLAlchemy?

This is just a simple example.

field = [[1,12,6], [2,12,8]]

I think about storing this in a json-typed field with SQLAlchemy in sqlite3 database.

But how can I query on this with SQLAlchemy (not SQL)?

  • rows where len(field) is 3
  • rows wehre field[1][2] is not 12
  • rows wehre len(field[*]) is not 3

Is it even possible?

Maybe it would be easier to implent this with a classical many-to-many table (incl. a link-table) instead of json-field.

Source: json

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.