I have created an index.sql
file which contains index creating script for 95 table
for example
DROP INDEX IF EXISTS gtab03_vrctrlid_idx cascade;
CREATE UNIQUE INDEX gtab03_vrctrlid_idx ON gtab03 USING btree (vrctrlid);
I have consolidated all table's index creating script
to a file called index.sql
I need to run the entire script at a time, is it possible to execute the index.sql
file using psql
Vivek S.Vivek S.
asked Jun 2, 2014 at 9:59
2 Answers 2
Is this what you mean?
\i e:/myFolder/index.sql;
Sue Mynott
1,3271 gold badge10 silver badges14 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Anthony Petrillo
; should not be included because this is a psql command and not SQL.
Matt
That doesn't work for me - parameter
\i
is not known in psql.Following script worked for me,
psql -U postgres -d mydb -a -f "D:\index.sql" -- Absolute path to .sql file
answered Jun 2, 2014 at 10:07
2 Comments
vaughan
Obviously...but for the good of the community it is easier if they can run the command as it is provided, without having to go digging into the reference to check what this non-obvious flag does. I see you added it, good on you.
Matt
You can also "pipe" it, e.g.
psql -U postgres -d mydb < D:\index.sql
lang-sql
information_schema
and a loop overEXECUTE format(...)
, rather than writing out all the statements manually. Search dba.se for examples.