Skip to content
Advertisement

Extract fields from postgres jsonb column

I have a postgres table with jsonb column, which has the value as follows:

here payload column is a jsonb datatype, I want to write a postgres query to fetch name1 from commissionEvents where name4 = apple.

So my result will be like:

enter image description here

Since I was new to this jsonb, can anyone please suggest me some solution for it.

Advertisement

Answer

You need to unnest all array elements, then you can apply a WHERE condition on that to filter out those with the desired name.

Online example: https://rextester.com/XWHG26387

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement