Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o6vLK-0008SI-E9 for pgsql-general@arkaria.postgresql.org; Thu, 30 Jun 2022 14:40:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o6vLJ-0003cE-4W for pgsql-general@arkaria.postgresql.org; Thu, 30 Jun 2022 14:40:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o6vLH-0003c5-Ix for pgsql-general@lists.postgresql.org; Thu, 30 Jun 2022 14:40:28 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o6vL8-0003KP-P2 for pgsql-general@postgresql.org; Thu, 30 Jun 2022 14:40:27 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 4D1C55C00FF; Thu, 30 Jun 2022 10:40:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 30 Jun 2022 10:40:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1656600015; x= 1656686415; bh=KudFEMza9PfEcV2lPx/XbZpu8YvjnR2o47OUPEnKoMQ=; b=K 4rlkLc5ph6xvUzPZy4jtvuIos2wJMTGOn5aTdsYmVMZl0YW1cvU7qUT/gZ8ZJ7sl OXmpBZdwITXShe7Sswrc1hEiqKr43IHlz1sZ/6RTIJDgk98d/MKdaS3zCqyoxi4t cDLjTNz9yIsLLtkOclx2skrUPji2boCP7bHQ+YzexDsfEAs2D6cZcPgFsyA+PFQ6 AvwZua/o8mUQIXwV9mHfDreqMQKKM/aCPuRPgCLdb1cnuH8Hc/KSr86xzt+wgXog fTSQyCEv3O8lhUeymd4OAupDGLu5nmvYjhJYoDP3q2/GyWk/0KigYCnnfL35PjsU q7A+TGMRpqvRVoh45w9gA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1656600015; x=1656686415; bh=K udFEMza9PfEcV2lPx/XbZpu8YvjnR2o47OUPEnKoMQ=; b=cmir8JClIizxW27oY mwPcOpOgcz+gdPycu3DJ2zXw3ibJsU46nkPygEnXpDhhIH7fi6HbN8+Pk0zNsJTq vfT2iqHweveCoRY+88FxGnlJjDpZAJAaZvCyjVibu9m3CAFfygzCj9BzJ7bEHJif vdYyMCkbKolhl+niinupuReWS2qGOHZAs5/2E86EB5mWpKFH+wi9iItKMOTaHAOI 40lCEongoS7xkGNwCuXwzcwqhqplJamwCfeSqs0ZPOTOKJToNEEP2gd2SRB/rGYZ 2V/qnkHnRd0tHI6brErPR/7QiDBndUDitCpUuWF2QfVEBJhBzwrCGJb8Kgmol9Te LjyAQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudehuddgjeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeelkeegjefhkeetheefudevteehiedvudehkeduleet fedvffeuhedtvdegtdeffeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhi rghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 30 Jun 2022 10:40:14 -0400 (EDT) Message-ID: Date: Thu, 30 Jun 2022 07:40:13 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: Function inside query status Content-Language: en-US To: Rama Krishnan , Postgres General References: From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/29/22 23:57, Rama Krishnan wrote: > Hi All, > > > Is it possible to check the query execution status inside the function. > > > >  created or replace function data_purge() returns void as$$ > Declare > Begin > Drop table test_old; > Create table test_old as select * from sales where bill_date -interval '1 year'; > > Delete table sales where sales_id in (select sales_id from test_old; 1) You are not actually declaring anything so the Declare is not needed. 2) You have three queries in the function do you want to check them all or some subset? 3) What exactly are checking for? 4) Have you looked at?: https://www.postgresql.org/docs/current/plpgsql-statements.html#PLPGSQL-STATEMENTS-DIAGNOSTICS and https://www.postgresql.org/docs/current/plpgsql-control-structures.html#PLPGSQL-EXCEPTION-DIAGNOSTICS > > End; > $$ language plpgsql; > > > -- Adrian Klaver adrian.klaver@aklaver.com