X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3980E3A4D26 for ; Sun, 23 Jan 2005 19:00:42 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21586-10 for ; Sun, 23 Jan 2005 19:00:30 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 5DFAA3A4B2D for ; Sun, 23 Jan 2005 19:00:30 +0000 (GMT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id j0NJ0Q2i011070 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 23 Jan 2005 12:00:28 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id j0NJ0Pls018463; Sun, 23 Jan 2005 12:00:26 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id j0NJ0Pfp018462; Sun, 23 Jan 2005 12:00:25 -0700 (MST) (envelope-from mfuhr) Date: Sun, 23 Jan 2005 12:00:25 -0700 From: Michael Fuhr To: =?iso-8859-1?Q?K=D6PFERL?= Robert Cc: pgsql-sql@postgresql.org Subject: Re: returning a record from PL/pgSQL Message-ID: <20050123190024.GA18329@winnie.fuhr.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.003 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/202 X-Sequence-Number: 19990 On Fri, Jan 21, 2005 at 12:41:09PM +0100, KÖPFERL Robert wrote: > > I just tried hard to return > a single record fromout a plpgsql-function. While the (otherwise excelent) > documentation didn't give me an answer, I found out that this works: > > select into ret false, balance, balance; > return ret; > > while ret is a composite type. > > This construction however tastes not good to me. Is there a nicer way? In the "Declarations" section of the PL/pgSQL documentation, under "Row Types," is the following: The individual fields of the row value are accessed using the usual dot notation, for example rowvar.field. and under "RETURN" in the "Control Structures" section is this: To return a composite (row) value, you must write a record or row variable as the expression. So you could to the following: ret.field1 := value1; ret.field2 := value2; ret.field3 := value3; RETURN ret; Internally, however, each expression in the above assignments would be evaluated using a SELECT statement, so whether this code is "nicer" than what you wrote depends on what you mean by "nice." -- Michael Fuhr http://www.fuhr.org/~mfuhr/