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 1gYtvO-0004Zj-Gz for pgsql-general@arkaria.postgresql.org; Mon, 17 Dec 2018 14:31:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gYtvN-0000mp-9c for pgsql-general@arkaria.postgresql.org; Mon, 17 Dec 2018 14:31:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYtvN-0000mi-1e for pgsql-general@lists.postgresql.org; Mon, 17 Dec 2018 14:31:13 +0000 Received: from mailout11.t-online.de ([194.25.134.85]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYtvK-0007DQ-JS for pgsql-general@lists.postgresql.org; Mon, 17 Dec 2018 14:31:12 +0000 Received: from fwd28.aul.t-online.de (fwd28.aul.t-online.de [172.20.26.133]) by mailout11.t-online.de (Postfix) with SMTP id A68D14240A35 for ; Mon, 17 Dec 2018 15:31:09 +0100 (CET) Received: from musicman.homeip.net (TvX0fmZCQhkv1V4DuiJdOWTHCxfkK1dNL2bHs7WMcG9zBzUBXxTG6ETHI1PnDmOw7t@[91.7.16.218]) by fwd28.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1gYtvF-0Gt8Eq0; Mon, 17 Dec 2018 15:31:05 +0100 Received: (qmail 28995 invoked by uid 0); 17 Dec 2018 14:31:04 -0000 Received: from 192.168.75.32 by amadeus4 (envelope-from , uid 82) with qmail-scanner-1.24 (sophos: 5.38.0/3.69.2/5.43. localrules: ???. Clear:RC:1(192.168.75.32):. Processed in 0.082059 secs); 17 Dec 2018 14:31:04 -0000 Received: from unknown (HELO noten19) (192.168.75.32) by amadeus4.local with SMTP; 17 Dec 2018 14:31:04 -0000 Received: (qmail 23841 invoked by uid 1000); 17 Dec 2018 14:31:03 -0000 Date: 17 Dec 2018 14:31:03 -0000 From: hamann.w@t-online.de Subject: Re: conditionally terminate psql script To: pgsql-general@lists.postgresql.org Message-Id: X-Mailer: TkMail 4.0beta9 Content-type: text/plain; charset=utf-8 In-Reply-To: <2c2417d2-9a81-73e7-23d5-a10436e4a2ff@postgrespro.ru> Content-Transfer-Encoding: quoted-printable X-Qmail-Scanner-1.24: added fake MIME-Version header MIME-Version: 1.0 X-ID: TvX0fmZCQhkv1V4DuiJdOWTHCxfkK1dNL2bHs7WMcG9zBzUBXxTG6ETHI1PnDmOw7t X-TOI-MSGID: eac63cef-d944-4834-81b7-f78dd6d824e2 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, many thanks, I will give it a try tomorrow Best regards Wolfgang >> = >> On 17.12.2018 16:07, hamann.w@t-online.de wrote: >> > Hi, many thanks -- too bad I am still using 9.3 >> = >> In this case you can try ON_ERROR_STOP psql variable. >> Something like this: >> = >> \set ON_ERROR_STOP on >> = >> do $$ >> declare >> =C2=A0=C2=A0=C2=A0 total bigint; >> begin >> =C2=A0=C2=A0=C2=A0 select count(*) into total from pg_class where 1=3D= 1; >> =C2=A0=C2=A0=C2=A0 if total =3D 0 then >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 raise exception 'Nothing f= ound.'; >> =C2=A0=C2=A0=C2=A0 end if; >> = >> =C2=A0=C2=A0=C2=A0 raise notice '% records found.', total; >> end; >> $$ language plpgsql; >> = >> \echo Continue execution... >> = >> ----- >> Pavel Luzanov >> Postgres Professional: http://www.postgrespro.com >> The Russian Postgres Company >> = >> = >> =