How do I create a query which takes certain time to execute? I have configured statement_timeout=1000 in Postgres DB
I am accessing a DB table using a JDBC driver from a java application. JDBC driver will throw an exception if the statement times out. I have a logic that will get executed if the exception is thrown.
Now I want to test this functionality, is there a way to make a query not return the result within 1000 millsecs?
As @McNets suggests in his comment, this is really easy using the pg_sleep() function:
select pg_sleep(2);

will return after 2 seconds. And the resulting dataset will contain one row and one column too, so your test application can easily handle it (if it gets through the timeout).