From: Pavel Luzanov <p.luzanov@postgrespro.ru>
To: pgsql-general@lists.postgresql.org
Subject: Re: conditionally terminate psql script
Date: Mon, 17 Dec 2018 16:30:25 +0300
Message-ID: <2c2417d2-9a81-73e7-23d5-a10436e4a2ff@postgrespro.ru> (raw)
In-Reply-To: <wolfgang-1181217140722.A0520644@noten19.local>
References: <wolfgang-1181217140722.A0520644@noten19.local>
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
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: p.luzanov@postgrespro.ru
Subject: Re: conditionally terminate psql script
In-Reply-To: <2c2417d2-9a81-73e7-23d5-a10436e4a2ff@postgrespro.ru>
References: <wolfgang-1181217140722.A0520644@noten19.local> <2c2417d2-9a81-73e7-23d5-a10436e4a2ff@postgrespro.ru>
* 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