Re: jsonb_set() strictness considered harmful to data
| От | Christoph Moench-Tegeder |
|---|---|
| Тема | Re: jsonb_set() strictness considered harmful to data |
| Дата | |
| Msg-id | 20191018215018.GB56427@elch.exwg.net обсуждение исходный текст |
| Ответ на | jsonb_set() strictness considered harmful to data (Ariadne Conill <ariadne@dereferenced.org>) |
| Ответы |
Re: jsonb_set() strictness considered harmful to data
Re: jsonb_set() strictness considered harmful to data |
| Список | pgsql-general |
## Ariadne Conill (ariadne@dereferenced.org):
> update users set info=jsonb_set(info, '{bar}', info->'foo');
>
> Typically, this works nicely, except for cases where evaluating
> info->'foo' results in an SQL null being returned. When that happens,
> jsonb_set() returns an SQL null, which then results in data loss.[3]
So why don't you use the facilities of SQL to make sure to only
touch the rows which match the prerequisites?
UPDATE users SET info = jsonb_set(info, '{bar}', info->'foo')
WHERE info->'foo' IS NOT NULL;
No special wrappers required.
Regards,
Christoph
--
Spare Space
В списке pgsql-general по дате отправления: