From: | David Fetter <david(at)fetter(dot)org> |
---|---|
To: | amborodin(at)acm(dot)org |
Cc: | Robert Haas <robertmhaas(at)gmail(dot)com>, amul sul <sulamul(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: pg_background contrib module proposal |
Date: | 2016-12-20 23:55:36 |
Message-ID: | 20161220235536.GC22538@fetter.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Mon, Dec 19, 2016 at 09:30:32PM +0500, Andrew Borodin wrote:
> 2016-12-19 4:21 GMT+05:00 David Fetter <david(at)fetter(dot)org>:
> > Couldn't it sleep in increments smaller than a second? Like maybe
> > milliseconds? Also, it's probably cleaner (or at least more
> > comprehensible) to write something using format() and dollar quoting
> > than the line with the double 's.
>
> Right. Here's version which waits for half a second. I do not see how
> to path doubles via dollar sign, pg_background_launch() gets a string
> as a parameter, it's not EXCEUTE USING.
I see.
I find the following a little easier to follow, and the sleeps still
work even when very short.
Best,
David.
CREATE TABLE input AS
SELECT x, row_number() OVER (ORDER BY x) n
FROM
generate_series(0,.000005,0.000001) x
ORDER BY x DESC;
CREATE TABLE output(place int,value float);
CREATE TABLE handles AS
SELECT pg_background_launch(
format($$
SELECT pg_sleep(%s);
INSERT INTO output VALUES (%s, %s)
$$,
x, n, x
)
) h
FROM input;
--wait until everyone finishes
SELECT * FROM handles JOIN LATERAL pg_background_result(handles.h) AS (x TEXT) ON (true);
--output results
SELECT * FROM output ORDER BY place;
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com
Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate
From | Date | Subject | |
---|---|---|---|
Next Message | Simon Riggs | 2016-12-21 00:32:11 | Re: pg_background contrib module proposal |
Previous Message | David Fetter | 2016-12-20 23:29:12 | Re: pg_authid.rolpassword format (was Re: Password identifiers, protocol aging and SCRAM protocol) |