pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: rep.dot.nop@gmail.com
Subject: BUG #15109: Unhelpful error message on type mismatch
Date: Tue, 13 Mar 2018 20:46:34 +0000
Message-ID: <152097399497.1223.8046666575875924842@wrigleys.postgresql.org> (raw)

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.



view thread (3+ messages)  latest in thread

Message-ID: <152097399497.1223.8046666575875924842@wrigleys.postgresql.org>
Permalink:  ../152097399497.1223.8046666575875924842@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/152097399497.1223.8046666575875924842@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, rep.dot.nop@gmail.com
  Subject: Re: BUG #15109: Unhelpful error message on type mismatch
  In-Reply-To: <152097399497.1223.8046666575875924842@wrigleys.postgresql.org>
  References: <152097399497.1223.8046666575875924842@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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