Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iC7TL-0007aG-CM for pgsql-general@arkaria.postgresql.org; Sun, 22 Sep 2019 19:24:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iC7TJ-0005v7-O4 for pgsql-general@arkaria.postgresql.org; Sun, 22 Sep 2019 19:24:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iC7TI-0005uv-41 for pgsql-general@lists.postgresql.org; Sun, 22 Sep 2019 19:24:37 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iC7TE-0001Yc-Ls for pgsql-general@lists.postgresql.org; Sun, 22 Sep 2019 19:24:35 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 356D420241; Sun, 22 Sep 2019 15:24:31 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Sun, 22 Sep 2019 15:24:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=y dmYK/lWnkKh+65kVHjdoa5OICnWFLq0CSJWUVSEc04=; b=0s5S1U9rGZJzG64GC 33l1106t7vZ69l79WAdq4PPgvhmDqyRk7/tLQNS/VdNYPOC0NDwDXTr0mSVWShrb nIaDD8yAcQjO9f7TbXSz5og48s8W1KbGWECQxE/aw8v8oBIGwiYZfYpbvhuA6nMX L7NunDfSeD00y2LPQeTP7kPCVEoXRQomzfHZeg6C9PxR+xn+Zazmgk5y7AH1hlHr JP73KPxAKVebr+wyII8mgzE29/yFakMcfDB1VXjWN44C99W6cRKSnDNOVXthFk8m yo4XADYj48cp2avfUnff9VZMGOgSF4He6JYLmaZJOPAk+G7I0s6cq0A5ZxKy49yk 1NNUw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=ydmYK/lWnkKh+65kVHjdoa5OICnWFLq0CSJWUVSEc 04=; b=caGC+74VSwEhYn4m74jCISedPsVin8vv+//0YYQ2cpM8ouK+dyD/IgQt7 FQYKvvkgQbMIe5LHhT08okCi++EIsG7DJtfCmhmr5St1JIQK5ym9aOR70hUN3y2A ihG2YGAqvGHdEqKAlYDgRdFV/gbSlmLoYsskMpdRaDFRTodxjRG2okFX6RSNnpOb SF+ToquL+ygZV4ZHmhGGt6yPWmisDzjlh26FHxyyweKxjHwETfqdMOWnpb5cK0U0 SdtbLDxjQtz6kGrFrZKUcUhGn/moHFFcIlUrZOt6wZac0KqYOoPRsR2OVzdM06wz pwqsilpzfurFVc7KFajzB4WP5L52A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdeigddufeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgnecukfhppedujeegrddv uddrjeekrdduieeknecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrg hvvghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.3] (174-21-78-168.tukw.qwest.net [174.21.78.168]) by mail.messagingengine.com (Postfix) with ESMTPA id 6CF8FD6005D; Sun, 22 Sep 2019 15:24:30 -0400 (EDT) Subject: Re: Use of ?get diagnostics'? To: Thiemo Kellner , PostgreSQL General References: <20190921075700.Horde.7M0WmarMSSL6-CZvUSrg4Dg@webmail.gelassene-pferde.biz> <875zlmoyg5.fsf@news-spur.riddles.org.uk> <20190922183304.Horde.3Br7o_R17F7ZB9s9Qp6HweH@webmail.gelassene-pferde.biz> From: Adrian Klaver Message-ID: <3bd52383-1711-0240-eab8-db645e8e619d@aklaver.com> Date: Sun, 22 Sep 2019 12:24:29 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20190922183304.Horde.3Br7o_R17F7ZB9s9Qp6HweH@webmail.gelassene-pferde.biz> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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