Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute *.sql file using psql

Tags:

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

like image 459
Vivek S. Avatar asked Jun 02 '14 09:06

Vivek S.


People also ask

How do I run a DDL script in PostgreSQL?

To run DDL in the form of an SQL script, you should use psql , the same command you use to connect to the server interactively. I recommend using ON_ERROR_STOP=1 and -1 , so it runs the DDL in a single transaction and aborts on any error.


1 Answers

Is this what you mean?

\i e:/myFolder/index.sql; 
like image 70
Sney Avatar answered Sep 23 '22 04:09

Sney