X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id D4B92D1B51A for ; Thu, 30 Oct 2003 10:52:23 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 23495-06 for ; Thu, 30 Oct 2003 06:51:55 -0400 (AST) Received: from smtp012.mail.yahoo.com (smtp012.mail.yahoo.com [216.136.173.32]) by svr1.postgresql.org (Postfix) with SMTP id 0ED55D1B510 for ; Thu, 30 Oct 2003 06:51:52 -0400 (AST) 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; 30 Oct 2003 10:51:53 -0000 Message-ID: <00d601c39ed3$7da18010$7502a8c0@hdsc.com> Reply-To: "Kumar" From: "Kumar" To: "Christoph Haller" Cc: References: <200310300926.KAA04661@rodos> Subject: Re: Using UNION inside a cursor Date: Thu, 30 Oct 2003 16:19:21 +0530 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit 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=1.6 tagged_above=0.0 required=5.0 tests=BAYES_30, QUOTED_EMAIL_TEXT, REFERENCES, UPPERCASE_25_50, WEIRD_QUOTING X-Spam-Level: * X-Archive-Number: 200310/395 X-Sequence-Number: 15795 Hi Christoph Haller, Thanks you very much. It worked. ----- Original Message ----- From: "Christoph Haller" To: ""Kumar"" Cc: Sent: Thursday, October 30, 2003 3:56 PM Subject: Re: [SQL] Using UNION inside a cursor > > > > Dear Friends, > > > > I am working on Postgresql 7.3.4 on RH Linux Server 7.3.=20 > > > > I have problem in executing the following procedure > > > > CREATE OR REPLACE FUNCTION list_history() > > RETURNS refcursor AS > > 'DECLARE > > ref REFCURSOR; > > BEGIN > > OPEN ref FOR > > (SELECT * FROM history WHERE obs_type =3D \'AA\' ) > > UNION=20 > > (SELECT * FROM history WHERE obs_type =3D \'TA\'); > > > > RETURN ref; > > END;' > > LANGUAGE 'plpgsql' VOLATILE; > > > > While executing this I got the following error > > > > WARNING: plpgsql: ERROR during compile of list_history near line 5 > > ERROR: syntax error at "(" > > > > While I execute the following code it is working fine and fetches values. > > (SELECT * FROM history WHERE obs_type =3D \'AA\' ) > > UNION=20 > > (SELECT * FROM history WHERE obs_type =3D \'TA\'); > > > > Where I am wrong. Please shed some light, > > > > Regards > > Kumar > > > My suspicion is the plpgsql parser doesn't accept the opening > parenthesis. What happens on > > OPEN ref FOR SELECT * FROM ( > (SELECT * FROM history WHERE obs_type =3D \'AA\' ) > UNION=20 > (SELECT * FROM history WHERE obs_type =3D \'TA\') > ) ; > > Regards, Christoph