X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id CCBC2D1B8B1 for ; Thu, 28 Aug 2003 01:04:07 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 92762-01 for ; Wed, 27 Aug 2003 22:03:40 -0300 (ADT) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id 9C2BAD1B52C for ; Wed, 27 Aug 2003 22:03:35 -0300 (ADT) Received: from [206.19.64.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.0.6) with ESMTP-TLS id 51561; Wed, 27 Aug 2003 17:19:54 -0700 Message-ID: <3F4D54AE.3030604@joeconway.com> Date: Wed, 27 Aug 2003 18:02:38 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Kumar Cc: psql Subject: Re: How to return a record set from function. References: <006901c36c6b$65ab2000$7502a8c0@hdsc.com> In-Reply-To: <006901c36c6b$65ab2000$7502a8c0@hdsc.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/321 X-Sequence-Number: 14937 Kumar wrote: > Create table t1 (c1 int, c2 varchar, c3 varchar); > > Create or Replace function sel_t1 () returns setof records as ' > select c1, c2, c3 from t1; ' Language SQL; > > It was fine and created a function. while i execute it as > > select sel_t1; > > I got the following error. > > ERROR: Cannot display a value of type RECORD I see three problems. 1) you need parenthesis on the function call, i.e. "sel_t1()" as compared with "sel_t1" 2) when returning setof record, the "sel_t1()" must be in the FROM clause of the statement 3) when the function is declared as returning "record" as compared to a named complex type such as "t1", you need to include a column definition list in the SQL statement So, putting it all together, try something like this: SELECT f1, f2, f3 FROM sel_t1() AS (f1 int, f2 varchar, f3 varchar); See: http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=xfunc-tablefunctions.html and http://techdocs.postgresql.org/guides/SetReturningFunctions HTH, Joe