简体   繁体   English

psql运行sql文件结果

[英]psql run sql file result

When I run my command: 当我运行命令时:

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

it displays: 它显示:

CREATE VIEW
ALTER TABLE

However I want it to show me just like pgadmin show it (for exmpl: The query was executed successfully in 45 ms, but returns no results) 但是我希望它像pgadmin一样显示给我(例如:查询已在45毫秒内成功执行,但未返回任何结果)

add on the begining of sqltest.sql the command \\timing ando you will see the time of each command 在sqltest.sql的开头添加命令\\ timing,然后您会看到每个命令的时间

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

or if you want all time fromm the begining of de script until end, add some command to scritp at the begin: create temp table tab (time1 time,time2 time); insert into tab (time1) select now()::time; 或者,如果您希望从脚本的开始一直到结束都需要,请在开始时向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;

at the end: 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; update tab set time2=now()::time; select time2-time1 as time_Elapsed from tab;

for example: 例如:

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

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

... your script code ...您的脚本代码

... 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; update tab set time2=now()::time; select time2-time1 as time_Elapsed from tab;

Use the a psql command parameter: 使用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 https://www.postgresql.org/docs/current/static/app-psql.html

And place \\timing on at the top of your script 并将\\timing on脚本的顶部

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

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