Re: How to *really* quit psql?

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: How to *really* quit psql?
Date: 2022-11-20 08:01:59
Message-ID: 92bd89a6-79cf-6d6b-de93-8cb7a45c7bb3@mines-paristech.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hello David,

>>> Question: is there any way to really abort a psql script from an
>>> included file?
>>
>> Under what circumstances would it be appropriate for a script to take
>> it on itself to decide that? It has no way of knowing what the next -f
>> option is or what the user intended.
>
> Can we add an exit code argument to the \quit meta-command that could be
> set to non-zero and, combined with ON_ERROR_STOP, produces the desired
> effect of aborting everything just like an error under ON_ERROR_STOP does
> (which is the workaround here I suppose, but an ugly one that involves the
> server).

I like the simple idea of adding an optional exit status argument to
\quit. I'm unsure whether "ON_ERROR_STOP" should or should not change the
behavior, or whether it should just exit(n) with \quit n.

Note that using quit to abort a psql script is already used when loading
extensions to prevent them to be run directly by psql:

-- from some sql files in "contrib/pg_stat_statements/":
\echo Use "ALTER EXTENSION pg_stat_statements UPDATE TO '1.10'" to load this file. \quit

But the same trick would fail if the guard is reach with an include.

--
Fabien.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michail Nikolaev 2022-11-20 13:45:13 Re: Slow standby snapshot
Previous Message Fabien COELHO 2022-11-20 07:54:53 Re: How to *really* quit psql?