diff --git a/contrib/pg_background/Makefile b/contrib/pg_background/Makefile index c4e717d..085fbff 100644 --- a/contrib/pg_background/Makefile +++ b/contrib/pg_background/Makefile @@ -6,6 +6,8 @@ OBJS = pg_background.o EXTENSION = pg_background DATA = pg_background--1.0.sql +REGRESS = pg_background + ifdef USE_PGXS PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) diff --git a/contrib/pg_background/expected/pg_background.out b/contrib/pg_background/expected/pg_background.out new file mode 100644 index 0000000..dbc344e --- /dev/null +++ b/contrib/pg_background/expected/pg_background.out @@ -0,0 +1,26 @@ +CREATE EXTENSION pg_background; +--run 5 workers which wait about 1 second +CREATE TABLE input as SELECT x FROM generate_series(1,5,1) x ORDER BY x DESC; +CREATE TABLE output(place int,value int); +CREATE sequence s start 1; +CREATE TABLE handles as SELECT pg_background_launch('select pg_sleep('||x||'); insert into output values (nextval(''s''),'||x||');') h FROM input; +SELECT (SELECT * FROM pg_background_result(h) as (x text) limit 1) FROM handles; + x +---------- + SELECT 1 + SELECT 1 + SELECT 1 + SELECT 1 + SELECT 1 +(5 rows) + +SELECT * FROM output ORDER BY place; + place | value +-------+------- + 1 | 1 + 2 | 2 + 3 | 3 + 4 | 4 + 5 | 5 +(5 rows) + diff --git a/contrib/pg_background/sql/pg_background.sql b/contrib/pg_background/sql/pg_background.sql new file mode 100644 index 0000000..d7cbd44 --- /dev/null +++ b/contrib/pg_background/sql/pg_background.sql @@ -0,0 +1,9 @@ +CREATE EXTENSION pg_background; + +--run 5 workers which wait about 1 second +CREATE TABLE input as SELECT x FROM generate_series(1,5,1) x ORDER BY x DESC; +CREATE TABLE output(place int,value int); +CREATE sequence s start 1; +CREATE TABLE handles as SELECT pg_background_launch('select pg_sleep('||x||'); insert into output values (nextval(''s''),'||x||');') h FROM input; +SELECT (SELECT * FROM pg_background_result(h) as (x text) limit 1) FROM handles; +SELECT * FROM output ORDER BY place;