From: Tom Lane <tgl@sss.pgh.pa.us>
To: Gerald Britton <gerald.britton@gmail.com>
Cc: Andrew Gierth <andrew@tao11.riddles.org.uk>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Are PostgreSQL functions that return sets or tables evaluated lazily or eagerly?
Date: Sun, 05 Jan 2020 17:46:06 -0500
Message-ID: <28321.1578264366@sss.pgh.pa.us> (raw)
In-Reply-To: <CAPxRSnaAJbTYQrYrvtcczhQDTWxd+WXKXYbu1NwynC3FSJFW=A@mail.gmail.com>
References: <CAPxRSnZa3PvNR9tz0wdMa1ioB0-GZxGi7VCuwzrNAfreea7e2w@mail.gmail.com>
<87ftgwklbx.fsf@news-spur.riddles.org.uk>
<CAPxRSnaAJbTYQrYrvtcczhQDTWxd+WXKXYbu1NwynC3FSJFW=A@mail.gmail.com>
Gerald Britton <gerald.britton@gmail.com> writes:
> Back to where I started in my top post: I became interested in this due to
> the doc note on returning a cursor and that it can be an efficient way to
> handle large result sets. I suppose that implies lazy evaluation. Does
> that mean that if I need plpgsql for a function for he language's power yet
> want the results to be returned lazily, a cursor is the (only?) way to go?
Nope. The docs' reference to a cursor only suggests that if you can
express the function's result as a single SQL query, then opening a
cursor for that query and returning the cursor name will work. But
if you need plpgsql to express the computation, that's not a terribly
helpful suggestion.
If you'd like to see some actual movement on the missing feature about
lazy evaluation in FROM, you could help test/review the pending patch
about it:
https://commitfest.postgresql.org/26/2372/
However, that still is only half of the problem, because you also need
a PL that is prepared to cooperate, which I don't believe plpgsql is.
I think (might be wrong) that a plpython function using "yield" can
be made to compute its results lazily.
regards, tom lane
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: tgl@sss.pgh.pa.us, gerald.britton@gmail.com, andrew@tao11.riddles.org.uk
Subject: Re: Are PostgreSQL functions that return sets or tables evaluated lazily or eagerly?
In-Reply-To: <28321.1578264366@sss.pgh.pa.us>
References: <CAPxRSnZa3PvNR9tz0wdMa1ioB0-GZxGi7VCuwzrNAfreea7e2w@mail.gmail.com> <87ftgwklbx.fsf@news-spur.riddles.org.uk> <CAPxRSnaAJbTYQrYrvtcczhQDTWxd+WXKXYbu1NwynC3FSJFW=A@mail.gmail.com> <28321.1578264366@sss.pgh.pa.us>
* 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