looping over a small record set over and over in a function - Mailing list pgsql-general

From Ivan Sergio Borgonovo
Subject looping over a small record set over and over in a function
Date
Msg-id 20090619202320.244657e0@dawn.webthatworks.it
Whole thread Raw
Responses Re: looping over a small record set over and over in a function  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Re: looping over a small record set over and over in a function  (Craig Ringer <craig@postnewspapers.com.au>)
List 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


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: FYI: Load times for a largish DB in 8.2 vs. 8.3 vs. 8.4
Next
From: leif@crysberg.dk
Date:
Subject: Re: Invalid statement name (null) in line ## - what am I doing wrong ?