繁体   English   中英

psql运行sql文件结果

[英]psql run sql file result

当我运行命令时:

psql -h localhost -p 5432 -U meee -d my_db -f sqltest.sql

它显示:

CREATE VIEW
ALTER TABLE

但是我希望它像pgadmin一样显示给我(例如:查询已在45毫秒内成功执行,但未返回任何结果)

在sqltest.sql的开头添加命令\\ timing,然后您会看到每个命令的时间

例如script.sql: \\timing select 2 ; select 1; create table tablax(i int); \\timing select 2 ; select 1; create table tablax(i int);

或者,如果您希望从脚本的开始一直到结束都需要,请在开始时向scritp添加一些命令: create temp table tab (time1 time,time2 time); insert into tab (time1) select now()::time; create temp table tab (time1 time,time2 time); insert into tab (time1) select now()::time;

最后: update tab set time2=now()::time; select time2-time1 as time_Elapsed from tab; update tab set time2=now()::time; select time2-time1 as time_Elapsed from tab;

例如:

create temp table tab (time1 time,time2 time);

insert into tab (time1) select now()::time;

...您的脚本代码

... update tab set time2=now()::time; select time2-time1 as time_Elapsed from tab; update tab set time2=now()::time; select time2-time1 as time_Elapsed from tab;

使用a psql的命令参数:

psql -h localhost -p 5432 -U meee -d my_db -af sqltest.sql

https://www.postgresql.org/docs/current/static/app-psql.html

并将\\timing on脚本的顶部

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM