From: | Michael Moore <michaeljmoore(at)gmail(dot)com> |
---|---|
To: | postgres list <pgsql-sql(at)postgresql(dot)org> |
Subject: | Updating jsonb rows |
Date: | 2017-08-12 01:08:39 |
Message-ID: | CACpWLjMwg7NaygNKkUzZObuH_tyKRkqfrGkSUVs7h2H4PjPRCw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
this ...
DO
$BODY$
declare
j_final_rslt jsonb;
begin
select jsonb_agg(row_to_json(alias)) from
(select prompt_seq, attribute_name from tfinal_rslt limit 2) alias
into j_final_rslt;
raise notice 'j_final_rslt BEFORE %',j_final_rslt;
select jsonb_set(j_final_rslt, '{0,prompt_seq}','99',true) into
j_final_rslt;
raise notice 'j_final_rslt AFTER %',j_final_rslt;
end;
$BODY$
gives the result:
BEFORE [{"prompt_seq": *150*, "attribute_name": "InsuredTimeframe"},
{"prompt_seq": 1200, "attribute_name": "DriverOccupation"}]
AFTER [{"prompt_seq": *99*, "attribute_name": "InsuredTimeframe"},
{"prompt_seq": 1200, "attribute_name": "DriverOccupation"}]
How could I change this to ALSO change the attribute_name on the 2nd record
to "ABC". The AFTER result would ideally look like:
AFTER [{"prompt_seq": 99, "attribute_name": "InsuredTimeframe"},
{"prompt_seq": 1200, "attribute_name": "ABC"}]
tia, Mike
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2017-08-12 01:18:32 | Re: Updating jsonb rows |
Previous Message | David G. Johnston | 2017-08-11 15:43:27 | Re: Always getting back a row, even with no results |