From: | Torsten Förtsch <torsten(dot)foertsch(at)gmx(dot)net> |
---|---|
To: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
Cc: | PostgreSQL General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: SQL advice needed |
Date: | 2014-03-17 21:20:14 |
Message-ID: | 5327670E.8040907@gmx.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 17/03/14 21:42, Merlin Moncure wrote:
>> I can do it in plpgsql. But that would mean to accumulate the complete
>> > result in memory first, right? I need to avoid that.
> I would test that assumption. This is better handled in loop IMO.
>
> LOOP
> RETURN QUERY SELECT * FROM xx();
> IF NOT found
> THEN
> RETURN;
> END IF;
> END LOOP;
At least according to the manual it is stored in memory:
<cite>
Note: The current implementation of RETURN NEXT and RETURN QUERY stores
the entire result set before returning from the function, as discussed
above. That means that if a PL/pgSQL function produces a very large
result set, performance might be poor: data will be written to disk to
avoid memory exhaustion, but the function itself will not return until
the entire result set has been generated. A future version of PL/pgSQL
might allow users to define set-returning functions that do not have
this limitation. Currently, the point at which data begins being written
to disk is controlled by the work_mem configuration variable.
Administrators who have sufficient memory to store larger result sets in
memory should consider increasing this parameter.
</cite>
I didn't test that, though.
Torsten
From | Date | Subject | |
---|---|---|---|
Next Message | Merlin Moncure | 2014-03-17 21:30:47 | Re: SQL advice needed |
Previous Message | David Johnston | 2014-03-17 20:54:04 | Re: SQL advice needed |