[SQL] Updating jsonb rows
От | Michael Moore |
---|---|
Тема | [SQL] Updating jsonb rows |
Дата | |
Msg-id | CACpWLjMwg7NaygNKkUzZObuH_tyKRkqfrGkSUVs7h2H4PjPRCw@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: [SQL] Updating jsonb rows
|
Список | 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 по дате отправления: