Search Postgresql Archives

Concatenating NULL with JSONB value return NULL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux