From: Niels Jespersen <NJN@dst.dk>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: SV: table returning function for each row in other resultset
Date: Thu, 4 Feb 2021 05:31:12 +0000
Message-ID: <818de3ff1a9c4e0cbc2f83fb539b5fe9@dst.dk> (raw)
In-Reply-To: <CAKFQuwbh2sDFtfSupMz-f-3CFDCHaF1MzbaSCkJcNmAsAMG5Ug@mail.gmail.com>
References: <e87c1245eeaa4c4e872148e6762292c9@dst.dk>
<CAKFQuwbh2sDFtfSupMz-f-3CFDCHaF1MzbaSCkJcNmAsAMG5Ug@mail.gmail.com>
Fra: David G. Johnston <david.g.johnston@gmail.com>
Sendt: 3. februar 2021 16:08
>On Wed, Feb 3, 2021 at 8:01 AM Niels Jespersen <NJN@dst.dk> wrote:
>Hello all
>
>I have som data in a resultset. E.g:
>
>id date_begin date_end amount
>1 2021-01-04 2021-02-06 100
>2 2021-03-17 2021-05-11 234
>
>I have a table returning function that can take one row and split it into constituent monthpieces and distribute amount proportionally.
>
>select * from func(1, 2021-01-04, 2021-02-06, 100);
>[...]
>How can I accomplish this, please.
>
>Lateral Join.
>
>(not tested)
>SELECT *
>FROM resultset, func(id, date_begin, date_end, amount);
>
>David J.
Of course, yes. It works. My Oracle background isn't very helpful when it comes to including lateral joins in my thinking.
with res(id, date_begin, date_end, amount) as (select *
from (values (1::bigint, '2021-01-04'::date, '2021-02-06'::date, 100::numeric),
(2::bigint, '2021-03-17'::date, '2021-05-11'::date, 234::numeric)) a)
select r.id, m.date_start, m.date_end, m.amount
from res r,
month_parts_low_freq(r.id, r.date_begin, r.date_end, r.amount) m;
produces the expected result. Now I will see how it goes with about 150 million rows in input.
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: NJN@dst.dk, david.g.johnston@gmail.com
Subject: Re: table returning function for each row in other resultset
In-Reply-To: <818de3ff1a9c4e0cbc2f83fb539b5fe9@dst.dk>
References: <e87c1245eeaa4c4e872148e6762292c9@dst.dk> <CAKFQuwbh2sDFtfSupMz-f-3CFDCHaF1MzbaSCkJcNmAsAMG5Ug@mail.gmail.com> <818de3ff1a9c4e0cbc2f83fb539b5fe9@dst.dk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox