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 1gYsyi-0001lm-LM for pgsql-general@arkaria.postgresql.org; Mon, 17 Dec 2018 13:30:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gYsyh-0001hI-6b for pgsql-general@arkaria.postgresql.org; Mon, 17 Dec 2018 13:30:35 +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 1gYsyg-0001gk-OW for pgsql-general@lists.postgresql.org; Mon, 17 Dec 2018 13:30:34 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gYsyZ-0005U5-DC for pgsql-general@lists.postgresql.org; Mon, 17 Dec 2018 13:30:33 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 5B67021D32A4 for ; Mon, 17 Dec 2018 16:30:25 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.27.175] (gw.postgrespro.ru [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 344FE21D3281 for ; Mon, 17 Dec 2018 16:30:25 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1545053425; bh=3mY8g6UQtfAdN0CDY2tedi0VpvB377UF3SCTLPmj76M=; h=Subject:To:References:From:Date:In-Reply-To; b=iJtFW28vjW+0JPuXAFkfIVQuJYLz5YnjMV8NPSwx8y9zJcBq/T0hDdFmcZRrl9q3X tf6UN11ZGCrtXuT2KNJxPeXKPgWgWv4E+PI92JcQFTzUjeYvwPlHTxYbfHGkF1+88t c3/sZDzq23H8/vTAsc55LZRVC1lViuEUMIFxIZ/4= Subject: Re: conditionally terminate psql script To: pgsql-general@lists.postgresql.org References: From: Pavel Luzanov Message-ID: <2c2417d2-9a81-73e7-23d5-a10436e4a2ff@postgrespro.ru> Date: Mon, 17 Dec 2018 16:30:25 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: ru-RU List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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     total bigint; begin     select count(*) into total from pg_class where 1=1;     if total = 0 then         raise exception 'Nothing found.';     end if;     raise notice '% records found.', total; end; $$ language plpgsql; \echo Continue execution... ----- Pavel Luzanov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company