Someone on IRC a while ago was complaining that there was no way to specify an interval for pg_sleep, so I made one. Patch against today's HEAD attached.
Usage: SELECT pg_sleep(interval '2 minutes'); I would add this to the next commitfest but I seem to be unable to log in with my community account (I can log in to the wiki). Help appreciated.
*** a/doc/src/sgml/func.sgml --- b/doc/src/sgml/func.sgml *************** *** 7537,7550 **** SELECT TIMESTAMP 'now'; -- incorrect for use with DEFAULT </indexterm> <para> ! The following function is available to delay execution of the server process: <synopsis> pg_sleep(<replaceable>seconds</replaceable>) </synopsis> <function>pg_sleep</function> makes the current session's process ! sleep until <replaceable>seconds</replaceable> seconds have elapsed. <replaceable>seconds</replaceable> is a value of type <type>double precision</>, so fractional-second delays can be specified. For example: --- 7537,7552 ---- </indexterm> <para> ! The following functions are available to delay execution of the server process: <synopsis> pg_sleep(<replaceable>seconds</replaceable>) + pg_sleep(<replaceable>interval</replaceable>) </synopsis> <function>pg_sleep</function> makes the current session's process ! sleep until <replaceable>seconds</replaceable> seconds (or the specified ! <replaceable>interval</replaceable>) have elapsed. <replaceable>seconds</replaceable> is a value of type <type>double precision</>, so fractional-second delays can be specified. For example: *** a/src/include/catalog/pg_proc.h --- b/src/include/catalog/pg_proc.h *************** *** 3017,3022 **** DATA(insert OID = 2625 ( pg_ls_dir PGNSP PGUID 12 1 1000 0 0 f f f f t t v 1 0 --- 3017,3024 ---- DESCR("list all files in a directory"); DATA(insert OID = 2626 ( pg_sleep PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "701" _null_ _null_ _null_ _null_ pg_sleep _null_ _null_ _null_ )); DESCR("sleep for the specified time in seconds"); + DATA(insert OID = 3179 ( pg_sleep PGNSP PGUID 14 1 0 0 0 f f f f t f v 1 0 2278 "1186" _null_ _null_ _null_ _null_ "select pg_sleep(extract(epoch from now() + $1) - extract(epoch from now()))" _null_ _null_ _null_ )); + DESCR("sleep for the specified interval"); DATA(insert OID = 2971 ( text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "16" _null_ _null_ _null_ _null_ booltext _null_ _null_ _null_ )); DESCR("convert boolean to text");
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers