Re: [GENERAL] json aggregation question

2017-02-28 Thread Yasin Sari
Hi Chris, Maybe there is an another better solution; 1. sending values into jsonb_array_elements to getting elements (lateral join) 2. distinct to eliminate duplicates 3. regexp_replace to remove malformed Array literals 4. Casting into text array SELECT count(distinct tags ), string_to_array(r

[GENERAL] json aggregation question

2017-02-28 Thread Chris Withers
Hi All, Given the following table: |#createtablething (id serial,tags jsonb);#\d thing Table"public.thing"Column|Type |Modifiers +-+id |integer |notnulldefaultnextval('thing_id_seq'::regclass)tags |jsonb || ...and the follo

Re: [GENERAL] json aggregation question

2017-02-28 Thread Paul Jungwirth
On 02/28/2017 08:21 AM, Chris Withers wrote: How can I aggregate the results of a query that equates to "show me the number of matching rows and the set of |tag1| value that have a |tag2| value of |t2val1|? ...but I really want: |count |tag1 ---+-2|["val1","val2","va

Re: [GENERAL] json aggregation question

2017-02-28 Thread Chris Withers
Thanks, this is closer, but regex really scares me for something like this... On 28/02/2017 17:19, Yasin Sari wrote: Hi Chris, Maybe there is an another better solution; 1. sending values into jsonb_array_elements to getting elements (lateral join) 2. distinct to eliminate duplicates 3. reg

[GENERAL] json aggregation question

2017-02-28 Thread Chris Withers
Hi All, Given the following table: |#createtablething (id serial,tags jsonb);#\d thing Table"public.thing"Column|Type |Modifiers +-+id |integer |notnulldefaultnextval('thing_id_seq'::regclass)tags |jsonb || ...and the follo