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 50200D1B52F for ; Thu, 30 Oct 2003 09:04:04 +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 14472-03 for ; Thu, 30 Oct 2003 05:03:35 -0400 (AST) Received: from smtp011.mail.yahoo.com (smtp011.mail.yahoo.com [216.136.173.31]) by svr1.postgresql.org (Postfix) with SMTP id A4899D1B559 for ; Thu, 30 Oct 2003 05:03:32 -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 09:03:33 -0000 Message-ID: <007c01c39ec4$5af992f0$7502a8c0@hdsc.com> Reply-To: "Kumar" From: "Kumar" To: "psql" Subject: Using UNION inside a cursor Date: Thu, 30 Oct 2003 14:23:48 +0530 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_006F_01C39EF1.6F161150" 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.7 tagged_above=0.0 required=5.0 tests=HTML_40_50, UPPERCASE_25_50 X-Spam-Level: * X-Archive-Number: 200310/393 X-Sequence-Number: 15793 This is a multi-part message in MIME format. ------=_NextPart_000_006F_01C39EF1.6F161150 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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 ------=_NextPart_000_006F_01C39EF1.6F161150 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Dear Friends,
 
I am working on Postgresql 7.3.4 on RH Linux Server 7.3= .=20
 
I have problem in executing the following=20 procedure
 
CREATE OR REPLACE FUNCTION list_history()
 = =20 RETURNS refcursor=20 AS
'DECLARE
 ref   REFCURSOR;
BEGIN
 O= PEN=20 ref FOR
 (SELECT  * FROM history  WHERE obs_typ= e =3D=20 \'AA\' )
 UNION
 (SELECT  *=20 FROM  history  WHERE   obs_type =3D=20 \'TA\');
 
 RETURN ref;
END;'
  LANGUAGE 'plpg= sql'=20 VOLATILE;
 
While executing this I got the following error
 
WARNING:  plpgsql: ERROR during compile of=20 list_history near line 5
ERROR:  syntax error at "("
 
While I execute the following code it is working fine a= nd=20 fetches values.
 (SELECT  * FROM history  = WHERE=20 obs_type =3D \'AA\' )
 UNION
 (SELECT  *=20 FROM  history  WHERE   obs_type =3D=20 \'TA\');
 
Where I am wrong. Please shed some light,
 
Regards
Kumar

------=_NextPart_000_006F_01C39EF1.6F161150--