How to run postgres sql script from another script?

Based on the answer It is possible to reference another SQL file from SQL script, on PostgreSQL, you can include another SQL’s files just using the \i syntax. I just tested and is working good on PostgreSQL 9.6:

\i other_script.sql
SELECT * FROM table_1;
SELECT * FROM table_2;

By the @wildplasser comment:

psql -U postgres -h localhost -d postgres < "path to my main sql file"

From psql’s perspective the main_sql file is just stdin, and stdin has no “filename”. Use -f filename to submit a file with a name:

psql -U postgres -h localhost -d postgres -f filename.sql

How to run postgres sql script from another script?

Seems the same question as: How to import external sql scripts from a sql script in PostgreSQL?

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)