Re: Calling a stored procedure from another stored procedure...

From: Ezequiel Tolnay <mail(at)etolnay(dot)com(dot)ar>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Calling a stored procedure from another stored procedure...
Date: 2005-05-05 03:55:51
Message-ID: d5c5eq$28gi$2@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Kretschmer 2005-05-05 06:50:29 Re: [despammed] accessing multiple database
Previous Message mohammad izwan ibrahim 2005-05-05 02:47:12 accessing multiple database