简体   繁体   中英

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)

add on the begining of sqltest.sql the command \\timing ando you will see the time of each command

for example 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; 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;

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;

Use the a psql command parameter:

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

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

And place \\timing on at the top of your script

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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