I'm developing a really long script. I'd like to break the script into smaller, more manageable scripts and include each sql file in a master file, then just execute the master file.
example: master.sql
contents (I don't know the syntax to use):
file1.sql
file2.sql
file3.sql
I've found several tutorials about using psql -f
in the command-line and \i
to include these files, but the preference here is to avoid the terminal and use a GUI to manage my database and execute the master.sql
script.
Is this possible in any postgres admin GUI? Presumably it's not in pgAdmin.
Best Answer
A
psql
scriptA psql script can index multiple files, let's assume
01_mydb.psql
, is in the current working directory, and you have a directory01
that has the files01_schema.sql
and02_types.sql
.01_mydb.psql
may look like this.Or however you want to structure it. If things get more complex and need more order, add more subdirectories
Then you would just either..
01
, something like./01/10_tables.psql
01_mydb.sql
I'll show the second method using
find
,Using
find
to generate a master-load script.Let's go ahead and create that structure.
Here is the commands we use to create it.,
Now you can use
find
to generate a load scriptNow just run
master.psql
;