Re: SQL advice needed - Mailing list pgsql-general

From David Johnston
Subject Re: SQL advice needed
Date
Msg-id 1395089644378-5796436.post@n5.nabble.com
Whole thread Raw
In response to SQL advice needed  (Torsten Förtsch <torsten.foertsch@gmx.net>)
List pgsql-general
Torsten Förtsch wrote
> Hi,
>
> I have a volatile function that returns multiple rows. It may also
> return nothing. Now, I want to write an SQL statement that calls this
> function until it returns an empty result set and returns all the rows.
>
> What's the best (or at least a working) way to achieve what I want?
>
> I can do it in plpgsql. But that would mean to accumulate the complete
> result in memory first, right? I need to avoid that.

You are describing procedural logic.  If you need intermediate steps before
"returns all the rows" then either those intermediate steps stay in memory
OR you stick them on a table somewhere and, when your procedure is done,
send back a cursor over that, possibly temporary, table.

I don't think abusing WITH/RECURSIVE is going to be viable.

You should also consider whether you can do what you need using set-logic
(i.e., pure SQL).  At worse it will be a learning exercise and a performance
comparator.

David J.




--
View this message in context: http://postgresql.1045698.n5.nabble.com/SQL-advice-needed-tp5796431p5796436.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: SQL advice needed
Next
From: Torsten Förtsch
Date:
Subject: Re: SQL advice needed