Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 0C90C4765BA for ; Mon, 14 Oct 2002 11:15:04 -0400 (EDT) Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net [194.217.242.85]) by postgresql.org (Postfix) with ESMTP id 79F76476461 for ; Mon, 14 Oct 2002 11:15:02 -0400 (EDT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-35.mail.demon.net with esmtp (Exim 3.36 #2) id 1816vy-0006B9-0U; Mon, 14 Oct 2002 16:15:06 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 77C59172DA; Mon, 14 Oct 2002 16:05:55 +0100 (BST) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id D8F40172D9; Mon, 14 Oct 2002 16:05:54 +0100 (BST) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton Organization: Archonet Ltd To: Heiko Stoermer , pgsql-sql@postgresql.org Subject: Re: Stored procedure returning row or resultset Date: Mon, 14 Oct 2002 16:05:03 +0100 User-Agent: KMail/1.4.3 References: <200210141622.54638.heiko.stoermer@login-solutions.de> In-Reply-To: <200210141622.54638.heiko.stoermer@login-solutions.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200210141605.04208.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/148 X-Sequence-Number: 9865 On Monday 14 Oct 2002 3:22 pm, Heiko Stoermer wrote: > Hello, > > I'm trying to achieve the following with pl/pgsql in postgres 7.2: > > I need a stored procedure proc() that calculates values for some fields > a =3D f1() > b =3D a + f2() > c =3D b + f3() > and returns the tuple (a,b,c) as a rowtype, Move to 7.3beta and use table functions, or look at returning a cursor from= a=20 function. See the online docs for details. > I know of course that I could write out > SELECT > (f1()) AS a > (f1() + f()) AS b > (f1() + f2() + f3()) AS c ... > in plain SQL and create a view on that, but the problem is that f1(), f2(= ), > f3() are complex and expensive computations that I want to run only once. > In the example I would call f1() three times, which is inacceptable. Have you looked at marking f1() etc cachable? This means Postgresql will on= ly=20 call the function once for each parameter-set. Only works for functions lik= e: square_root(number) and not next_random_number() --=20 Richard Huxton