The following bug has been logged on the website:
Bug reference: 15109
Logged by: Bernhard Reutner-Fischer
Email address: rep.dot.nop@gmail.com
PostgreSQL version: 10.3
Operating system: linux
Description:
Hi!
wishlist item:
---8<---
CREATE OR REPLACE FUNCTION xxx(flag boolean)
RETURNS JSONB LANGUAGE plpgsql AS
$$
DECLARE
row record;
BEGIN
IF flag = true THEN
SELECT 1::bigint AS i
INTO row;
ELSE
SELECT 1::text AS i
INTO row;
END IF;
RETURN JSONB_BUILD_OBJECT('foo', row.i);
END
$$;
select xxx(false);
select xxx(true);
---8<---
CREATE FUNCTION
xxx
--------------
{"foo": "1"}
(1 row)
psql:xxx.sql:19: ERROR: type of parameter 4 (bigint) does not match that
when preparing the plan (text)
CONTEXT: PL/pgSQL function xxx(boolean) line 12 at RETURN
Would be nice to give more context what "parameter 4" actually is, i.e. also
print the name or underline the exact line the error occurs in or the like
(and how comes we talk about line 12 and not 14?):
mockup:
psql:xxx.sql:19: ERROR: type of parameter 4 (1::bigint AS i) does not match
that when preparing the plan (1::text AS i)
or mockup:
psql:xxx.sql:19: ERROR: type of parameter at (1) does not match that when
preparing the plan at (2)
CONTEXT: PL/pgSQL function xxx(boolean) line 14 at (3)
7 IF flag = true THEN
8 SELECT 1::bigint AS i
----------------(1)-^
9 INTO row;
10 ELSE
11 SELECT 1::text AS i
----------------(2)-^
12 INTO row;
13 END IF;
14 RETURN JSONB_BUILD_OBJECT('foo', row.i);
-------------------------------------------(3)-^
Or the like.
This is of course not json-specific.