1

I have a table with a column named "settings" with type jsonb (nullable) with following pattern:

[
  {
     att1: "test"
     "start": 2019-02-01 00:00:00
     "end": 2019-02-20 00:00:00
  },
  {
     att1: "test2"
     "start": 2019-03-01 00:00:00
     "end": 2019-03-15 00:00:00
  }
]

Example of a table:

id,settings
1,"[{"end": "2019-02-01 00:00:00"},{"2019-02-05 00:00:00"}]"
2,"[{"end" : '2019-02-20 00:00:00'}]"

I want find all the records that have "end" field within the array jsonb that is above specific timestamp

e.g I expect to get record 2 if I query "end" > "2019-02-19 00:00:00"..

Please advise!

1 Answer 1

1

You can try this code:

SELECT *
FROM test_table tt
WHERE exists(
          SELECT *
          FROM jsonb_array_elements(tt.settings) AS settings
          WHERE (settings ->> 'start') > '2019-02-19 00:00:00'
        );
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.