pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #15109: Unhelpful error message on type mismatch
3+ messages / 3 participants
[nested] [flat]

* BUG #15109: Unhelpful error message on type mismatch
@ 2018-03-13 20:46 PG Bug reporting form <noreply@postgresql.org>
  2018-03-13 21:17 ` Re: BUG #15109: Unhelpful error message on type mismatch David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: PG Bug reporting form @ 2018-03-13 20:46 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: rep.dot.nop@gmail.com

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.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #15109: Unhelpful error message on type mismatch
  2018-03-13 20:46 BUG #15109: Unhelpful error message on type mismatch PG Bug reporting form <noreply@postgresql.org>
@ 2018-03-13 21:17 ` David G. Johnston <david.g.johnston@gmail.com>
  2018-03-13 22:36   ` Re: BUG #15109: Unhelpful error message on type mismatch Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: David G. Johnston @ 2018-03-13 21:17 UTC (permalink / raw)
  To: rep.dot.nop@gmail.com; pgsql-bugs@lists.postgresql.org

On Tue, Mar 13, 2018 at 1:46 PM, PG Bug reporting form <
noreply@postgresql.org> wrote:

> 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?):
>

​Once you understand the error you will see it is indeed on line 12, count
them including the line with the starting $$

The error itself comes up not because of the "SELECT 1" but because of
"row.i" being passed into jsonb_build_object('foo', $#) - in one pass row.i
is text then the next invocation of the now-cached function-plan it is a
bigint.  That row.i changes types is allowed by design - its this specific
usage of row.i that is problematic.

Parameters don't have names, just numbers, so finding a name to pass back
is definitely non-trivial.

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)
>

As noted above, since that isn't where the actual error is occurring a
suggestion like this is even not helpful since you not only want a better
error message but you want something that is not inherently an error (i.e.,
polymorphic record types) to become one just so push the error message
further up the procedure.  That isn't acceptable.  And tracing from the
statement retrieving "row.i" back to those two statements that set row is
likely impossible.​

In short - this isn't a bug report so this isn't the right list for the
discussion (that would be -general), and while the frustration is real the
proposed alternatives do not seem realistic.

David J.
​

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #15109: Unhelpful error message on type mismatch
  2018-03-13 20:46 BUG #15109: Unhelpful error message on type mismatch PG Bug reporting form <noreply@postgresql.org>
  2018-03-13 21:17 ` Re: BUG #15109: Unhelpful error message on type mismatch David G. Johnston <david.g.johnston@gmail.com>
@ 2018-03-13 22:36   ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2018-03-13 22:36 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: rep.dot.nop@gmail.com; pgsql-bugs@lists.postgresql.org

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Tue, Mar 13, 2018 at 1:46 PM, PG Bug reporting form <
> noreply@postgresql.org> wrote:
>> 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

> In short - this isn't a bug report so this isn't the right list for the
> discussion (that would be -general), and while the frustration is real the
> proposed alternatives do not seem realistic.

Ideally, of course, we'd like to not see this error at all, at least not
in the context of plpgsql --- it should auto-replan affected statements
when a record column changes type.  That's been on the to-do list for a
long time, though, and hasn't gotten done.  When it does get done it's
unlikely to be something we'd risk back-patching.

So you could call this a bug if you want, but when it does get fixed
it'll be treated as a new feature instead.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2018-03-13 22:36 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-03-13 20:46 BUG #15109: Unhelpful error message on type mismatch PG Bug reporting form <noreply@postgresql.org>
2018-03-13 21:17 ` David G. Johnston <david.g.johnston@gmail.com>
2018-03-13 22:36   ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox