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
--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general