using worker_spi as pattern

From: Jeremy Finzel <finzelj(at)gmail(dot)com>
To: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: using worker_spi as pattern
Date: 2018-03-08 21:29:52
Message-ID: CAMa1XUgiBvoamp+E21xHpwNGfduBAF=8p4Tbvz+Vby_o5G2=Sg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello - I have compiled and installed the extension worker_spi. I also
launched the process via SELECT worker_spi_launch(1);

I see this in pg_stat_activity:
WITH deleted AS (DELETE FROM schema1.counted WHERE type = 'delta' RETURNING
value), total AS (SELECT coalesce(sum(value), 0) as sum FROM deleted)
UPDATE schema1.counted SET value = counted.value + total.sum FROM total
WHERE type = 'total' RETURNING counted.value

However, I'm not sure what I am supposed to do next? The docs at the top
of the module say:

To see it working, insert an initial value
* with "total" type and some initial value; then insert some other rows
with
* "delta" type. Delta rows will be deleted by this worker and their values
* aggregated into the total.

However, this raises many questions for me:

- Insert a value into what table? I see the process referring to an
object that doesn't exist in my database - schema1.counted
- What is "total" type? I don't see any type with this name in the
database
- Same question for "delta" type

I am trying to use this extension as a pattern for my own background
worker, but just trying to understand it.

Thanks!
Jeremy

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2018-03-08 22:46:13 Re: [HACKERS] MERGE SQL Statement for PG11
Previous Message David Fetter 2018-03-08 21:12:40 Re: Implementing SQL ASSERTION