在Windows上的PostgreSQL的单个事务中运行多个SQL文件

问题描述 投票:0回答:1

我试图在PostgreSQL的单个事务中运行多个SQL文件。在Linux环境中,实际上可以通过使用here-document实现:

psql -U postgres -h localhost -d mydatabase << files
BEGIN;
\i file1.sql
\i file2.sql
commit;
files

但我无法在Windows环境中实现相同的功能。

windows postgresql batch-file
1个回答
2
投票

将所有内容放在一个文件中,例如

\i file1.sql
\i file2.sql

然后使用-f参数调用psql。要强制单个事务使用--single-transaction

psql -U postgres -h localhost -d mydatabase --single-transaction -f the_script.sql
© www.soinside.com 2019 - 2024. All rights reserved.