postgresql 如何使用 psql 执行 *.sql 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23991871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 00:43:43  来源:igfitidea点击:

How to execute *.sql file using psql

postgresqlpsql

提问by Vivek S.

I have created an index.sqlfile which contains index creating script for 95 table

我创建了一个index.sql包含索引创建脚本的文件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 scriptto a file called index.sqlI need to run the entire script at a time, is it possible to execute the index.sqlfile using psql

我已将所有表合并index creating script到一个名为index.sql我需要一次运行整个脚本的index.sql文件中,是否可以使用psql

回答by Sney

Is that what u mean?

这就是你的意思吗?

\i e:/myFolder/index.sql;

回答by Vivek S.

Following script worked for me,

以下脚本对我有用,

psql -U postgres -d mydb -a -f "D:\index.sql" -- Absolute path to .sql file


-U, -a, -f

-U, -a, -f