friartuck
friartuck

Reputation: 3121

Postgres query on nested JSONB field

Hey I have a table with a JSONB field. I want to run a query (table scan), which find all records where a nested element lifecycle.time is equal to "100". I "lifecycle:{time:"100"}

Looking at documentation like this https://kb.objectrocket.com/postgresql/how-to-query-a-postgres-jsonb-column-1433 shows no example of querying on a JSONB fild.

Thanks

Upvotes: 0

Views: 107

Answers (1)

user330315
user330315

Reputation:

You haven't provided much details, but as far as I can tell, you want something like this:

select *
from the_table
where the_column -> 'lifecycle' ->> 'time' = '100'

Or a bit shorter:

select *
from the_table
where the_column @> '{"lifecycle": {"time": "100"}}';

Upvotes: 1

Related Questions