Обсуждение: psql -1 with multiple files?

Поиск
Список
Период
Сортировка

psql -1 with multiple files?

От
Jay Levitt
Дата:
Is there a way to load multiple .sql files in a single transaction? It looks
like "psql -f file1 -f file2" or "psql -f file*" was a WIP patch that never
happened, and from what I can tell, psql ignores the -1 parameter when
reading from STDIN, so I can't cat them together either:

$ cat > am_i_in_transaction.sql
set client_min_messages to debug;
abort;
set client_min_messages to debug;
^D

$ psql -1 -f am_i_in_transaction.sql
SET
ROLLBACK
SET
psql:am_i_in_transaction.sql:0: WARNING:  there is no transaction in progress

$ psql -1 < am_i_in_transaction.sql
SET
NOTICE:  there is no transaction in progress
ROLLBACK
SET

$ psql -1 -f am_i_in_transaction.sql -f am_i_in_transaction.sql
SET
ROLLBACK
SET
psql:am_i_in_transaction.sql:0: WARNING:  there is no transaction in progress

Re: psql -1 with multiple files?

От
Steve Crawford
Дата:
On 12/01/2011 02:01 PM, Jay Levitt wrote:
> Is there a way to load multiple .sql files in a single transaction? It
> looks like "psql -f file1 -f file2" or "psql -f file*" was a WIP patch
> that never happened, and from what I can tell, psql ignores the -1
> parameter when reading from STDIN, so I can't cat them together either:

 From the man-page, -1 works in conjunction with -f so you might try:

cat file1 file2 file3 | psql -1 -f - ...

Alternately, since -1 basically wraps your input in a BEGIN...your
statements...COMMIT you could do that yourself with a begin.sql and
commit.sql:

cat begin.sql file1.sql file2.sql ... commit.sql | psql ...

Cheers,
Steve


Re: psql -1 with multiple files?

От
Jay Levitt
Дата:
Steve Crawford wrote:
> On 12/01/2011 02:01 PM, Jay Levitt wrote:
>> Is there a way to load multiple .sql files in a single transaction?
> Alternately, since -1 basically wraps your input in a BEGIN...your
> statements...COMMIT you could do that yourself with a begin.sql and commit.sql:
>
> cat begin.sql file1.sql file2.sql ... commit.sql | psql ...

Man, can I not see the forest for the trees sometimes. Thanks.

Jay