I have a file make_partition.sql
like:
CREATE INDEX my_nice_index ON mytable (ts);
CREATE TABLE mytable_2017_10 AS SELECT * FROM mytable WHERE date_trunc('month', ts) = '2017-10-01';
CREATE TABLE mytable_2017_11 AS SELECT * FROM mytable WHERE date_trunc('month', ts) = '2017-11-01';
I run it in the background using screen
and then the command:
psql postgresql://usr:pw@host.com:5432/db_name -f make_partition.sql
And detach from the screen. It completes, but then it appears that only the first query was run. I've tested this a few times with the same result.
How can I get it to run them all? Do I have to put them in a procedure like this? How to run multiple SQL queries?