Skip to content

Instantly share code, notes, and snippets.

@x4m
Last active December 7, 2016 16:07
Show Gist options
  • Save x4m/d64884d5f69b17238e06096396acde23 to your computer and use it in GitHub Desktop.
Save x4m/d64884d5f69b17238e06096396acde23 to your computer and use it in GitHub Desktop.
\timing
create extension if not exists pg_background;
create table input as select round(random()*20) x from generate_series(1,5,1);
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment