pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Thiemo Kellner <thiemo@gelassene-pferde.biz>
To: PostgreSQL General <pgsql-general@lists.postgresql.org>
Subject: Re: Use of ?get diagnostics'?
Date: Sun, 22 Sep 2019 12:24:29 -0700
Message-ID: <3bd52383-1711-0240-eab8-db645e8e619d@aklaver.com> (raw)
In-Reply-To: <20190922183304.Horde.3Br7o_R17F7ZB9s9Qp6HweH@webmail.gelassene-pferde.biz>
References: <20190921075700.Horde.7M0WmarMSSL6-CZvUSrg4Dg@webmail.gelassene-pferde.biz>
	<875zlmoyg5.fsf@news-spur.riddles.org.uk>
	<20190922183304.Horde.3Br7o_R17F7ZB9s9Qp6HweH@webmail.gelassene-pferde.biz>

On 9/22/19 11:33 AM, Thiemo Kellner wrote:
> Hi Andrew
> 
>> Paste sites are for IRC, on the mailing list you should always attach
>> the necessary details to your message.
> 
> Ok, I was under the impression that paste site were preferable to 
> attachments which generates traffic not everyone is interested in.
> 
>>  Thiemo>   the following exception was thrown:
>>  Thiemo> SQLSTATE: 42703
>>  Thiemo> column "row_count" does not exist
>>
>> line 44 of your paste:  V_TEXT := V_TEXT || ROW_COUNT || ' row.';
>>
>> should be V_ROW_COUNT, I suspect. Likewise line 46.
> 
> You are perfectly right and now I feel a bit stupid. Many thanks!
> 
> Maybe others had the same idea, but it would help me, if the exception 
> contained a line where the error was found. Though, I am not quite sure 
> whether this is just due to my error handling in the function.

It should:

create table diag_test(id integer);

insert into diag_test values (1), (2);

CREATE OR REPLACE FUNCTION public.get_diag_test()
  RETURNS void
  LANGUAGE plpgsql
AS $function$
DECLARE
     V_ROW_COUNT  BIGINT DEFAULT 0;
     V_TEXT text;
BEGIN

     PERFORM * FROM diag_test;
     get current diagnostics V_ROW_COUNT = ROW_COUNT;
     V_TEXT := ROW_COUNT || ' row.';
END;
$function$

test=# select get_diag_test();
ERROR:  column "row_count" does not exist
LINE 1: SELECT ROW_COUNT || ' row.'
                ^
QUERY:  SELECT ROW_COUNT || ' row.'
CONTEXT:  PL/pgSQL function get_diag_test() line 9 at assignment

To get above I believe you will need to use GET CURRENT DIAGNOSTICS 
PG_CONTEXT:

https://www.postgresql.org/docs/11/plpgsql-statements.html#PLPGSQL-STATEMENTS-DIAGNOSTICS

and example:

https://www.postgresql.org/docs/11/plpgsql-control-structures.html#PLPGSQL-CALL-STACK


> 
> Kind regards
> 
> Thiemo
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (6+ messages)  latest in thread

Message-ID: <3bd52383-1711-0240-eab8-db645e8e619d@aklaver.com>
Permalink:  ../3bd52383-1711-0240-eab8-db645e8e619d@aklaver.com/
Also on:    postgresql.org/message-id/3bd52383-1711-0240-eab8-db645e8e619d@aklaver.com

 · 

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-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, thiemo@gelassene-pferde.biz
  Subject: Re: Use of ?get diagnostics'?
  In-Reply-To: <3bd52383-1711-0240-eab8-db645e8e619d@aklaver.com>
  References: <20190921075700.Horde.7M0WmarMSSL6-CZvUSrg4Dg@webmail.gelassene-pferde.biz> <875zlmoyg5.fsf@news-spur.riddles.org.uk> <20190922183304.Horde.3Br7o_R17F7ZB9s9Qp6HweH@webmail.gelassene-pferde.biz> <3bd52383-1711-0240-eab8-db645e8e619d@aklaver.com>

* 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