looping over a small record set over and over in a function

From: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: looping over a small record set over and over in a function
Date: 2009-06-19 18:23:20
Message-ID: 20090619202320.244657e0@dawn.webthatworks.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


I've a record set on which I have to loop several times.
The function should return the same record set + one more computed
field.
Something that in could look like:

foreach(row) {
// compute stuff
if(...) {
}
// place stuff in field[N+1] of the row
}
if(some condition) {
//
}
foreach(row) {
// compute stuff
if(...) {
}
// place stuff in a field[N+1] of the row
}
if(some condition) {
//
}
...

actually return row + computed field.

in pgplsql

where each loop depends on the result of the previous.
The dataset is very small.

If I could easily load all the dataset into an array, loop through
it and then just update the computed field it would be nice... but
how?
Is it really worth to load the whole record set in an array, loop
over etc... in spite of eg. building a temp table with the same
structure of the input record set + 1 field, loop over the table
etc... what about all the UPDATEs involved to change field N+1 of
the temp table? Will be they expensive?

thanks

--
Ivan Sergio Borgonovo
http://www.webthatworks.it

Responses

Browse pgsql-general by date

  From Date Subject
Next Message leif 2009-06-19 18:42:59 Re: Invalid statement name (null) in line ## - what am I doing wrong ?
Previous Message Tom Lane 2009-06-19 18:17:49 Re: FYI: Load times for a largish DB in 8.2 vs. 8.3 vs. 8.4