Re: Using UNION inside a cursor

From: "Kumar" <sgnerd(at)yahoo(dot)com(dot)sg>
To: "Christoph Haller" <ch(at)rodos(dot)fzk(dot)de>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Using UNION inside a cursor
Date: 2003-10-30 10:49:21
Message-ID: 00d601c39ed3$7da18010$7502a8c0@hdsc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi Christoph Haller,

Thanks you very much. It worked.

----- Original Message -----
From: "Christoph Haller" <ch(at)rodos(dot)fzk(dot)de>
To: ""Kumar"" <sgnerd(at)yahoo(dot)com(dot)sg>
Cc: <pgsql-sql(at)postgresql(dot)org>
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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tomasz Myrta 2003-10-30 11:32:57 strange postgresql failure
Previous Message Christoph Haller 2003-10-30 10:26:17 Re: Using UNION inside a cursor