Re: psql question: aborting a "script"

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: psql question: aborting a "script"
Дата
Msg-id 56E81E63.6080100@aklaver.com
обсуждение исходный текст
Ответ на psql question: aborting a "script"  (John McKown <john.archie.mckown@gmail.com>)
Ответы Re: psql question: aborting a "script"  (John McKown <john.archie.mckown@gmail.com>)
Список pgsql-general
On 03/15/2016 07:33 AM, John McKown wrote:
> I'm likely abusing the psql program. What I have is an awk program which
> reads a file and produces a number of INSERT INTO commands. I then feed
> these commands into psql to execute them. Yes, a Perl program would be a
> better idea. Anyway, sometimes the commands are rejected due to some
> problem, such as duplicate primary key. What I wish is that the psql
> command had a switch, or control command, which would say "exit from
> psql if anything fails". To me, this is like the BASH "set -e" command
> for a shell script. Does this sound like a useful addition. Or am I just
> missing where it already exists?

Would this help?:

http://www.postgresql.org/docs/9.5/interactive/app-psql.html
"-1
--single-transaction

     When psql executes a script, adding this option wraps BEGIN/COMMIT
around the script to execute it as a single transaction. This ensures
that either all the commands complete successfully, or no changes are
applied.

     If the script itself uses BEGIN, COMMIT, or ROLLBACK, this option
will not have the desired effects. Also, if the script contains any
command that cannot be executed inside a transaction block, specifying
this option will cause that command (and hence the whole transaction) to
fail.
"
>
> --
> A fail-safe circuit will destroy others. -- Klipstein
>
> Maranatha! <><
> John McKown


--
Adrian Klaver
adrian.klaver@aklaver.com


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

Предыдущее
От: John McKown
Дата:
Сообщение: psql question: aborting a "script"
Следующее
От: John McKown
Дата:
Сообщение: Re: psql question: aborting a "script"