3

I have a set of queries in my queries.sql file which I am feeding to psql for execution. But I don't want them to run instantly one after the other: I would like to set some sort of delay - I was looking at \watch and query buffer but I am not so sure how to proceed. I would prefer not to write PG_SLEEP after each of my queries.

2
  • why do you want a delay after the queries? how do you want the delay to look so as not to sleep? Mar 4, 2017 at 23:41
  • 1
    Write a Python or Perl script with your list of queries and have it loop over them, sleeping after each execution. Mar 5, 2017 at 11:18

1 Answer 1

1

\watch executes the query buffer (one statement). It doesn't loop through different statements.

\set title "EVAN SAYS HAI"
SELECT 'HELLO WORLD' AS "Evan Greets the Plebs";
\watch

Now move that window over to your fifth monitor and when the boss comes by pretend like you're waiting for it to change.

If you want to put a delay in between query executions, make a spool as @Craig Ringer said in the comments

Write a Python or Perl script with your list of queries and have it loop over them, sleeping after each execution. – Craig Ringer Mar 5 at 11:18

You can do it one line or whatever too..

echo -e "SELECT 1;\nSELECT 2;\nSELECT 3;" |
  perl -pe'$|=1; sleep 1;' |
  psql -d foo;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.