Sample Header Ad - 728x90

PostgreSQL: running SQL statements in parallel in a SQL script

1 vote
1 answer
1998 views
I use a for loop in a script to compute geometries according to values in a series, and insert the results into a table (t1). Is there a way to rewrite the loop below using parallelism? What approach to use? I found many docs on how PostgreSQL runs queries in parallel, but hardy anything on how I could perform such task in my case. Is it even possible using SQL? or should I rely on other languages like Python, and execute the SQL queries from there? DO $$ DECLARE lims int[]; lim int; BEGIN SELECT ARRAY(SELECT generate_series(60, 300, 60)) INTO lims; CREATE TABLE t1( lim integer, the_geom geometry(polygon, 4326), ); FOREACH lim IN ARRAY lims LOOP WITH conv_hull AS ( SELECT ST_ConcaveHull(...I use lim here...) AS conv_hull ) INSERT INTO t1 (lim, the_geom) SELECT lim, ST_SetSRID(conv_hull.ST_ConcaveHull, 4326) FROM conv_hull; END LOOP; END $$;
Asked by Marc (13 rep)
Oct 27, 2021, 06:36 PM
Last activity: Jul 1, 2024, 09:05 AM