[GENERAL] Concatenating NULL with JSONB value return NULL

Поиск
Список
Период
Сортировка
От Jong-won Choi
Тема [GENERAL] Concatenating NULL with JSONB value return NULL
Дата
Msg-id 0e13e561-a5aa-d040-1d43-60ca3cb50075@ticketsquad.com
обсуждение исходный текст
Ответы Re: [GENERAL] Concatenating NULL with JSONB value return NULL
Список pgsql-general
PostgreSQL 9.6.1

Hi

I have a NULL-able JSONB type column and want to perform upsert,
concatenating with the existing value.

The query looks like (campaigns and facts columns are JSONB type, in the
below) :

INSERT INTO Fan  (oid, campaigns, facts)  VALUES (189,'{"campaign-id":
"12345"}','{"attended": false}') ON CONFLICT (oid)
DO UPDATE SET campaigns = EXCLUDED.campaigns, facts = fan.facts ||
EXCLUDED.facts RETURNING *;

And this does not work when the existing JSONB type column has NULL
value. For example:

select NULL::JSONB || '{"A": "b"}'::JSONB;

I would expect the above returns '{"A": "b"}', but PostgreSQL does not
work as I expected.

What's the best way to make concatenating with NULL returns the
right-hand side value?
(One way I can think of is, giving a default value of '{}' instead of
NULL, but I'd like to know any alternatives)


Thanks

- Jong-won


В списке pgsql-general по дате отправления:

Предыдущее
От: Torsten Förtsch
Дата:
Сообщение: [GENERAL] streaming replication protocol in Perl?
Следующее
От: John R Pierce
Дата:
Сообщение: Re: [GENERAL] Concatenating NULL with JSONB value return NULL