patternsqlMajor
Source several files at once with psql
Viewed 0 times
oncesourcewithseveralpsqlfiles
Problem
I want to execute several sql scripts sequentially with
psql as a single transaction to set up my database schema. What is the best way to do this? In the past I know I had a master script that I ran psql against that included the other files however I don't remember the syntax of this script.Solution
Your script could look like this:
Or you could do something like this:
BEGIN;
\i file1.sql
\i file2.sql
COMMIT;Or you could do something like this:
cat file1.sql file2.sql | psql -1 -f -Code Snippets
BEGIN;
\i file1.sql
\i file2.sql
COMMIT;cat file1.sql file2.sql | psql -1 -f -Context
StackExchange Database Administrators Q#3334, answer score: 40
Revisions (0)
No revisions yet.