[SQL] Updating jsonb rows - Mailing list pgsql-sql

From Michael Moore
Subject [SQL] Updating jsonb rows
Date
Msg-id CACpWLjMwg7NaygNKkUzZObuH_tyKRkqfrGkSUVs7h2H4PjPRCw@mail.gmail.com
Whole thread Raw
Responses Re: [SQL] Updating jsonb rows  ("David G. Johnston" <david.g.johnston@gmail.com>)
List 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

pgsql-sql by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: [SQL] Always getting back a row, even with no results
Next
From: "David G. Johnston"
Date:
Subject: Re: [SQL] Updating jsonb rows