From sgnerd@yahoo.com.sg Wed Aug 27 07:19:12 2003 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 BA660D1B91E for ; Wed, 27 Aug 2003 04:19:12 -0300 (ADT) 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 20625-08 for ; Wed, 27 Aug 2003 04:18:43 -0300 (ADT) Received: from smtp014.mail.yahoo.com (smtp014.mail.yahoo.com [216.136.173.58]) by svr1.postgresql.org (Postfix) with SMTP id 54927D1B954 for ; Wed, 27 Aug 2003 04:18:41 -0300 (ADT) Received: from ptil-138-190-chn.primus-india.net (HELO IVESIA67) (sgnerd@203.196.190.138 with login) by smtp.mail.vip.sc5.yahoo.com with SMTP; 27 Aug 2003 07:18:41 -0000 Message-ID: <006901c36c6b$65ab2000$7502a8c0@hdsc.com> Reply-To: "Kumar" From: "Kumar" To: "psql" Subject: How to return a record set from function. Date: Wed, 27 Aug 2003 12:48:15 +0530 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0066_01C36C99.7BA62CF0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.2 tagged_above=0.0 required=5.0 tests=HTML_50_60, HTML_FONT_COLOR_BLUE X-Spam-Level: X-Archive-Number: 200308/316 X-Sequence-Number: 14932 This is a multi-part message in MIME format. ------=_NextPart_000_0066_01C36C99.7BA62CF0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Dear Friends, I am newbie to Postgres. I am running 7.3.4 on Linux 7.3. I am using Pgadmi= n tool. I need to return the table rows via record set. 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;=20 I got the following error. ERROR: Cannot display a value of type RECORD How to solve this. Please help. Kumar ------=_NextPart_000_0066_01C36C99.7BA62CF0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Dear Friends,
 
I am newbie to Postgres. I= am running=20 7.3.4 on Linux 7.3. I am using Pgadmin tool. I need to return the table row= s via=20 record set.
 
Create table t1 (c1 int, c= 2 varchar,=20 c3 varchar);
 
Create or Replace function= sel_t1 ()=20 returns setof records as '
select c1, c2, c3 from=20 t1;
' Language SQL;
 
It was fine and created a = function.=20 while i execute it as
 
select sel_t1;
 
 I got the following= =20 error.
 
ERROR:  Cannot displa= y a value=20 of type RECORD
 
How to solve this. Please= =20 help.
 
Kumar
<= /HTML> ------=_NextPart_000_0066_01C36C99.7BA62CF0-- From dev@archonet.com Wed Aug 27 13:50:44 2003 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 DF3A4D1B550 for ; Wed, 27 Aug 2003 10:50:44 -0300 (ADT) 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 04819-02 for ; Wed, 27 Aug 2003 10:50:16 -0300 (ADT) Received: from anchor-post-34.mail.demon.net (anchor-post-34.mail.demon.net [194.217.242.92]) by svr1.postgresql.org (Postfix) with ESMTP id 290F4D1B52C for ; Wed, 27 Aug 2003 10:50:12 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-34.mail.demon.net with esmtp (Exim 3.35 #1) id 19s0gh-0003Rg-0Y; Wed, 27 Aug 2003 14:50:15 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id B04EA163E4; Wed, 27 Aug 2003 14:50:13 +0100 (BST) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 0D220163D7; Wed, 27 Aug 2003 14:50:13 +0100 (BST) From: Richard Huxton To: "Kumar" , "psql" Subject: Re: How to return a record set from function. Date: Wed, 27 Aug 2003 14:50:12 +0100 User-Agent: KMail/1.5 References: <006901c36c6b$65ab2000$7502a8c0@hdsc.com> In-Reply-To: <006901c36c6b$65ab2000$7502a8c0@hdsc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200308271450.12485.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/327 X-Sequence-Number: 14943 On Wednesday 27 August 2003 08:18, Kumar wrote: > Dear Friends, > > I am newbie to Postgres. I am running 7.3.4 on Linux 7.3. I am using > Pgadmin tool. I need to return the table rows via record set. > > 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 You probably want to return "setof t1" and then do: SELECT * FROM sel_t1(); -- Richard Huxton Archonet Ltd From sszabo@megazone.bigpanda.com Wed Aug 27 15:11:50 2003 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 36445D1B52C for ; Wed, 27 Aug 2003 12:11:50 -0300 (ADT) 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 28151-09 for ; Wed, 27 Aug 2003 12:11:19 -0300 (ADT) Received: from megazone.bigpanda.com (45.mufb.snfc.sffca01r18.dsl.att.net [12.103.249.45]) by svr1.postgresql.org (Postfix) with ESMTP id 8B117D1B8E3 for ; Wed, 27 Aug 2003 12:11:15 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 200D5D61A; Wed, 27 Aug 2003 08:11:13 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 0DAE25C0E; Wed, 27 Aug 2003 08:11:13 -0700 (PDT) Date: Wed, 27 Aug 2003 08:11:12 -0700 (PDT) From: Stephan Szabo To: Kumar Cc: psql Subject: Re: How to return a record set from function. In-Reply-To: <006901c36c6b$65ab2000$7502a8c0@hdsc.com> Message-ID: <20030827080844.D68510-100000@megazone.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/325 X-Sequence-Number: 14941 On Wed, 27 Aug 2003, Kumar wrote: > Dear Friends, > > I am newbie to Postgres. I am running 7.3.4 on Linux 7.3. I am using > Pgadmin tool. I need to return the table rows via record set. > > Create table t1 (c1 int, c2 varchar, c3 varchar); > > Create or Replace function sel_t1 () returns setof records as ' Why not setof t1? > select c1, c2, c3 from t1; > ' Language SQL; > > It was fine and created a function. while i execute it as > > select sel_t1; You probably want select * from sel_t1() as tab(c1 int, c2 varchar, c3 varchar) (if you return setof record) or select * from sel_t1(); (if you return setof t1) From mail@joeconway.com Thu Aug 28 01:04:07 2003 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