Re: conditionally terminate psql script

From: Torsten Förtsch <tfoertsch123(at)gmail(dot)com>
To: hamann(dot)w(at)t-online(dot)de
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: conditionally terminate psql script
Date: 2018-12-19 01:25:49
Message-ID: CAKkG4_myzqwmHOcMRkBeJnR3HeMkbAo-u9E3AMCUSi+2Mx9CXQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Dec 17, 2018 at 2:07 PM <hamann(dot)w(at)t-online(dot)de> wrote:

> many thanks -- too bad I am still using 9.3
>
>
not sure if it has been mentioned in the thread so far. But according to
the docs, 9.3 psql does support the \gset command. So you should be able to
do something like this:

select case when exists (select 1 from pg_namespace where nspname='tf')
then '\echo schema tf exists \\ \q'
else '\echo schema does not exist -- creating ...'
end as cmd\gset
:cmd

create schema tf;
create table tf.i(i int);

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Condor 2018-12-19 08:12:04 Re: Format an Update with calculation
Previous Message David G. Johnston 2018-12-18 21:47:46 Re: conditionally terminate psql script