Computing (disjoint) union of range - Mailing list pgsql-general

From Rémi Cura
Subject Computing (disjoint) union of range
Date
Msg-id CAJvUf_thbJjNSj9LUjgntzfCsToeSS5cxdV+bfxibN2pUh2M3Q@mail.gmail.com
Whole thread Raw
List pgsql-general
Hello Dear list,

this is more a plpgsql dev. issue.

I wrote a plpgsql function to compute union of time range taht works :

[1,4]U[3,8]U[12,14]U[16,18] ---> [1,8]U[12,14]U[16,18]

It works on multiple rows.

My issue is a design issue :
I want to work on set of row and return set of row.
I am aware I could take as input/output array of range but I don't want (memory/casting cost).

Currently the function takes a cursor on a table and output a setof record.

I would like that the function can blend in multiple subqueries smoothly, as

WITH (
first query to get range),
(query computing union
),
(query using computed union
) etc.

Currently I have to execute 2 sql statment :

create cursor on ranges;

WITH (function to compute union)
,
(query...)

The only kind of function taking set of record as input I know of is aggregate function, but it returns only one row and the output of union can take multiple row.

Any insight would be greatly appreciated.

Cheers,

Rémi-C


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Risk of set system wise statement_timeout
Next
From: "Andrew G. Saushkin"
Date:
Subject: Qury plan for sql function with security definer