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

Pri*_*iya 3 windows postgresql batch-file

我正在尝试在 PostgreSQL 的单个事务中运行多个 SQL 文件。在 Linux 环境中,这实际上可以通过使用此处文档来实现:

psql -U postgres -h localhost -d mydatabase << files
BEGIN;
\i file1.sql
\i file2.sql
commit;
files
Run Code Online (Sandbox Code Playgroud)

但我无法在 Windows 环境中实现相同的目标。

小智 7

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

\i file1.sql
\i file2.sql
Run Code Online (Sandbox Code Playgroud)

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

psql -U postgres -h localhost -d mydatabase --single-transaction -f the_script.sql
Run Code Online (Sandbox Code Playgroud)