Meegh
Meegh

Reputation: 39

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)

Upvotes: 0

Views: 3771

Answers (2)

Anthony Sotolongo
Anthony Sotolongo

Reputation: 1648

add at the beginning of ´sqltest.sql´ the command ´\timing´ and you will see the time of each command

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

Or if you want all time from the begining of the script until end, add some command to script at the beginning: 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;

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;

Upvotes: 1

Clodoaldo Neto
Clodoaldo Neto

Reputation: 125204

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

Upvotes: 0

Related Questions