1 SELECT string_agg(trim(tdata::text, '"'), ', ') from jsonb_array_elements(CAST('[1 , 2]' as jsonb)) tdata
1SELECT
2 ID
3 ,(
4 SELECT string_agg(trim(JsonString::text, '"'), ', ')
5 FROM jsonb_array_elements(JsonData->'Name') JsonString
6 ) AS StringArray
7FROM tbl_TestJsonArray;
8
1
2
3
4
5 SELECT info ->> 'customer' AS customer,
6 info -> 'items' ->> 'product' AS product
7FROM orders
8WHERE CAST ( info -> 'items' ->> 'qty' AS INTEGER) = 2
1-- Give me params.name (text) from the events table
2select params->>'name' from events;
3
4-- Find only events with a specific name
5select * from events where params->>'name' = 'Click Button';
6
7-- Give me the first index of a JSON array
8select params->ids->0 from events;
9
10-- Find users where preferences.beta is true (boolean)
11-- This requires type casting preferences->'beta' from json to boolean
12select preferences->'beta' from users where (preferences->>'beta')::boolean is true;