using worker_spi as pattern - Mailing list pgsql-hackers

From Jeremy Finzel
Subject using worker_spi as pattern
Date
Msg-id CAMa1XUgiBvoamp+E21xHpwNGfduBAF=8p4Tbvz+Vby_o5G2=Sg@mail.gmail.com
Whole thread Raw
Responses Re: using worker_spi as pattern  (Michael Paquier <michael@paquier.xyz>)
List 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

pgsql-hackers by date:

Previous
From: David Fetter
Date:
Subject: Re: Implementing SQL ASSERTION
Next
From: Peter Geoghegan
Date:
Subject: Re: [HACKERS] MERGE SQL Statement for PG11