BUG #13768: JSONB concat

Lists: pgsql-bugs
From: awasarax(at)yandex(dot)ru
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #13768: JSONB concat
Date: 2015-11-11 11:50:02
Message-ID: 20151111115002.2643.11338@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 13768
Logged by: Roman
Email address: awasarax(at)yandex(dot)ru
PostgreSQL version: 9.5beta1
Operating system: Windows (7, Server 2008 r2)
Description:

if "d" is null then return = null
else
return <> null

CREATE OR REPLACE FUNCTION userfunc(jsonb)
RETURNS jsonb AS
$BODY$
DECLARE
r jsonb = null;
d jsonb = null;
BEGIN
SELECT to_json(users.*) INTO r FROM users WHERE ///////;
RETURN r||d; -- return null
END;
$BODY$
LANGUAGE plpgsql VOLATILE;


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: awasarax(at)yandex(dot)ru
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #13768: JSONB concat
Date: 2015-11-11 16:18:35
Message-ID: 30495.1447258715@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

awasarax(at)yandex(dot)ru writes:
> if "d" is null then return = null
> else
> return <> null

> CREATE OR REPLACE FUNCTION userfunc(jsonb)
> RETURNS jsonb AS
> $BODY$
> DECLARE
> r jsonb = null;
> d jsonb = null;
> BEGIN
> SELECT to_json(users.*) INTO r FROM users WHERE ///////;
> RETURN r||d; -- return null
> END;
> $BODY$
> LANGUAGE plpgsql VOLATILE;

I see nothing particularly wrong here. There is long-established
precedent, eg, 'foo'::text || NULL is null too. It makes sense
if you consider that NULL means "unknown".

regards, tom lane