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.