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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With