P
P
Pavel2018-10-02 03:38:58
PostgreSQL
Pavel, 2018-10-02 03:38:58

How to make an array selection in a JSON field?

Right now the query is only looking in the first element of the array, but I need to iterate over the entire array in a JSON field

attr = Column(db.JSON)

unit.attr = [
  {'name': 'name1', 'date': '01.01.2018'},
  {'name': 'name2', 'date': '01.01.2015'}
]


query = query.filter(Unit.attr[0]['date'].cast(db.String).cast(db.Date).between(date_begin, date_end))

How to specify it in the code?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question