[英]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.