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 15F3FD1B4E5 for ; Thu, 30 Oct 2003 09:26:58 +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 16521-08 for ; Thu, 30 Oct 2003 05:26:28 -0400 (AST) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by svr1.postgresql.org (Postfix) with SMTP id 930B2D1B500 for ; Thu, 30 Oct 2003 05:26:24 -0400 (AST) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Thu Oct 30 10:26:19 2003 +0100 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id KAA22447; Thu, 30 Oct 2003 10:26:18 +0100 (MET) From: Christoph Haller Message-Id: <200310300926.KAA04661@rodos> Subject: Re: Using UNION inside a cursor To: sgnerd@yahoo.com.sg ("Kumar") Date: Thu, 30 Oct 2003 10:26:17 MET Cc: pgsql-sql@postgresql.org In-Reply-To: <007c01c39ec4$5af992f0$7502a8c0@hdsc.com>; from "Kumar" at Oct 30, 103 10:11 am X-Mailer: Elm [revision: 212.4] X-Virus-Scanned: by amavisd-new at postgresql.org X-Amavis-Alert: BAD HEADER Non-encoded 8-bit data (char 9C hex) in message header 'Received' Received: \234by rodos.fzk.de... ^ X-Archive-Number: 200310/394 X-Sequence-Number: 15794 > > 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