Hi It seems like pg_sleep_until() has issues if used within a transaction, as it uses now() and not clock_timestamp(). Please find attached a patch that solves this issue.
For consistency reasons, I also modified pg_sleep_for() to also use clock_timestamp. Regards On Fri, Jan 31, 2014 at 2:12 AM, Vik Fearing <vik.fear...@dalibo.com> wrote: > On 01/30/2014 09:48 PM, Robert Haas wrote: > > On Thu, Oct 17, 2013 at 9:11 AM, Vik Fearing <vik.fear...@dalibo.com> > wrote: > >> On 10/17/2013 02:42 PM, Robert Haas wrote: > >>> On Thu, Oct 17, 2013 at 8:26 AM, Vik Fearing <vik.fear...@dalibo.com> > wrote: > >>>> On 10/17/2013 10:03 AM, Fabien COELHO wrote: > >>>>> My guess is that it won't be committed if there is a single "but it > >>>>> might break one code or surprise one user somewhere in the universe", > >>>>> but I wish I'll be proven wrong. IMO, "returned with feedback" on a 1 > >>>>> liner is really akin to "rejected". > >>>> I have attached here an entirely new patch (new documentation and > >>>> everything) that should please everyone. It no longer overloads > >>>> pg_sleep(double precision) but instead add two new functions: > >>>> > >>>> * pg_sleep_for(interval) > >>>> * pg_sleep_until(timestamp with time zone) > >>>> > >>>> Because it's no longer overloading the original pg_sleep, Robert's > >>>> ambiguity objection is no more. > >>>> > >>>> Also, I like how it reads aloud: SELECT pg_sleep_for('5 minutes'); > >>>> > >>>> If people like this, I'll reject the current patch and add this one to > >>>> the next commitfest. > >>> I find that naming relatively elegant. However, you've got to > >>> schema-qualify every function and operator used in the definitions, or > >>> you're creating a search-path security vulnerability. > >>> > >> Good catch. Updated patch attached. > > Committed. > > Thanks! > > -- > Vik > > > > -- > Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-hackers >
*** a/src/include/catalog/pg_proc.h --- b/src/include/catalog/pg_proc.h *************** *** 3034,3042 **** DATA(insert OID = 2625 ( pg_ls_dir PGNSP PGUID 12 1 1000 0 0 f f f f t t v 1 0 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 = 3935 ( pg_sleep_for PGNSP PGUID 14 1 0 0 0 f f f f t f v 1 0 2278 "1186" _null_ _null_ _null_ _null_ "select pg_catalog.pg_sleep(extract(epoch from pg_catalog.now() operator(pg_catalog.+) $1) operator(pg_catalog.-) extract(epoch from pg_catalog.now()))" _null_ _null_ _null_ )); DESCR("sleep for the specified interval"); ! DATA(insert OID = 3936 ( pg_sleep_until PGNSP PGUID 14 1 0 0 0 f f f f t f v 1 0 2278 "1184" _null_ _null_ _null_ _null_ "select pg_catalog.pg_sleep(extract(epoch from $1) operator(pg_catalog.-) extract(epoch from pg_catalog.now()))" _null_ _null_ _null_ )); DESCR("sleep until the specified time"); 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_ )); --- 3034,3042 ---- 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 = 3935 ( pg_sleep_for PGNSP PGUID 14 1 0 0 0 f f f f t f v 1 0 2278 "1186" _null_ _null_ _null_ _null_ "select pg_catalog.pg_sleep(extract(epoch from pg_catalog.clock_timestamp() operator(pg_catalog.+) $1) operator(pg_catalog.-) extract(epoch from pg_catalog.clock_timestamp()))" _null_ _null_ _null_ )); DESCR("sleep for the specified interval"); ! DATA(insert OID = 3936 ( pg_sleep_until PGNSP PGUID 14 1 0 0 0 f f f f t f v 1 0 2278 "1184" _null_ _null_ _null_ _null_ "select pg_catalog.pg_sleep(extract(epoch from $1) operator(pg_catalog.-) extract(epoch from pg_catalog.clock_timestamp()))" _null_ _null_ _null_ )); DESCR("sleep until the specified time"); 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_ ));
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers