Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running multiple SQL files in a single transaction of PostgreSQL on Windows

I am trying to run multiple SQL files in a single transaction of PostgreSQL. In Linux environments this can actually be achieved by using here-document as:

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

But I am unable to achieve the same in Windows environment.

like image 331
Priya Avatar asked Dec 09 '25 17:12

Priya


1 Answers

Put everything in a one file, e.g.

\i file1.sql
\i file2.sql

Then call psql with the -f parameter. To force a single transaction use --single-transaction

psql -U postgres -h localhost -d mydatabase --single-transaction -f the_script.sql