Re: Calling a stored procedure from another stored procedure... - Mailing list pgsql-sql

From Ezequiel Tolnay
Subject Re: Calling a stored procedure from another stored procedure...
Date
Msg-id d5c5eq$28gi$2@news.hub.org
Whole thread Raw
List pgsql-sql
Christophe Geers wrote:
> I came as far as getting the first returned result by performing a 
> SELECT INTO mytype function calculate_cost(...)...etc., which is normal 
> I guess since a SELECT INTO only returns a single row according to the 
> manual. However is there a way to loop / iterate all of the results?

SELECT INTO a variable will only get the first row of the returning 
rowset. To get the full rowset into a temporary table, you'll have to 
use INSERT INTO MYTEMPTABLE SELECT * FROM MYFUNCTION(), but working with 
temporary tables is never very pleasing in postgresql.

I recommmend you to iterate over the results by doing the following:

_t := 0;
FOR _myrecord IN SELECT * FROM myfunction(...)
LOOP  _t := _t + _myrecord.mycolumn;
END LOOP;

Cheers,

Ezequiel Tolnay


pgsql-sql by date:

Previous
From: "Ramakrishnan Muralidharan"
Date:
Subject: Re: Function or Field?
Next
From: Ezequiel Tolnay
Date:
Subject: Re: Trimming the cost of ORDER BY in a simple query