Re: How to *really* quit psql?

Поиск
Список
Период
Сортировка
От Fabien COELHO
Тема Re: How to *really* quit psql?
Дата
Msg-id 90298ea-cc54-bed0-a9c1-62abc1579663@mines-paristech.fr
обсуждение исходный текст
Ответ на Re: How to *really* quit psql?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Hello Tom,

>>   - when the current script is included from something,
>>     you quit the current script and proceed after the \i of next -f, BAD
>
>> 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?

The use case is psql scripts which update or cleanup an application 
schema. For security, some of these scripts check for conditions (eg, we 
are not in production, the application schema is in the expected version, 
whatever…) and should abort if the conditions are not okay. As checking 
for the conditions requires a few lines of code and is always the same, a 
simple approach is to include another script which does the check and 
aborts the run if necessary, eg:

```sql
-- this script should not run in "prod"!
\ir not_in_prod.sql
-- should have aborted if it is a "prod" version.
DROP TABLE AllMyUsers CASCADE;
DROP TABLE QuiteImportantData CASCADE;
```

> It has no way of knowing what the next -f option is or what the user 
> intended.

The intention of the user who wrote the script is to abort in some cases, 
to avoid damaging the database contents.

-- 
Fabien.

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Andres Freund
Дата:
Сообщение: Re: More efficient build farm animal wakeup?
Следующее
От: Fabien COELHO
Дата:
Сообщение: Re: How to *really* quit psql?