From: Ezequiel Tolnay <mail@etolnay.com.ar>
To: pgsql-sql@postgresql.org
Subject: Re: Calling a stored procedure from another stored procedure...
Date: Thu, 05 May 2005 13:55:51 +1000
Message-ID: <d5c5eq$28gi$2@news.hub.org> (raw)
In-Reply-To: <d5a0pk$5qj$1@ikaria.belnet.be>
References: <d5a0pk$5qj$1@ikaria.belnet.be>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mail@etolnay.com.ar
Subject: Re: Calling a stored procedure from another stored procedure...
In-Reply-To: <d5c5eq$28gi$2@news.hub.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox