pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
table returning function for each row in other resultset
2+ messages / 2 participants
[nested] [flat]

* table returning function for each row in other resultset
@ 2021-02-03 15:01  Niels Jespersen <NJN@dst.dk>
  0 siblings, 1 reply; 2+ messages in thread

From: Niels Jespersen @ 2021-02-03 15:01 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

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); 

returns 

1,2021-01-04,2021-01-31,84.848485
1,2021-02-01,2021-02-06,18.181818

So far, so good. 

Now, what I want is to run the function on the resultset from above and get 

1,2021-01-04,2021-01-31,84.848485
1,2021-02-01,2021-02-06,18.181818
2,2021-03-17,2021-03-31,63.818182
2,2021-04-01,2021-04-30,127.636364
2,2021-05-01,2021-05-11,46.8

How can I accomplish this, please. 

Regards Niels Jespersen







^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: table returning function for each row in other resultset
@ 2021-02-03 15:07  David G. Johnston <david.g.johnston@gmail.com>
  parent: Niels Jespersen <NJN@dst.dk>
  0 siblings, 0 replies; 2+ messages in thread

From: David G. Johnston @ 2021-02-03 15:07 UTC (permalink / raw)
  To: Niels Jespersen <NJN@dst.dk>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

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.

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2021-02-03 15:07 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-02-03 15:01 table returning function for each row in other resultset Niels Jespersen <NJN@dst.dk>
2021-02-03 15:07 ` David G. Johnston <david.g.johnston@gmail.com>

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