Hi Tom,
I need the parentheses, because the where condition is different for the 1
and 2 nd query . Moreover my actual use includes a 'Limit' clause also. so
the parentheses is needed.
I have tried with execute but it showed error.
But I have managed to fix the problem like this.
OPEN ref FOR SELECT * FROM
(SELECT * FROM history WHERE obs_type =3D \'AA\' )
UNION
(SELECT * FROM history WHERE obs_type =3D \'TA\') as foo;
Regards
Kumar
----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Christoph Haller" <ch@rodos.fzk.de>
Cc: ""Kumar"" <sgnerd@yahoo.com.sg>; <pgsql-sql@postgresql.org>
Sent: Thursday, October 30, 2003 8:50 PM
Subject: Re: [SQL] Using UNION inside a cursor
> Christoph Haller <ch@rodos.fzk.de> writes:
> >> OPEN ref FOR
> >> (SELECT * FROM history WHERE obs_type =3D \'AA\' )
> >> UNION
> >> (SELECT * FROM history WHERE obs_type =3D \'TA\');
>
> > My suspicion is the plpgsql parser doesn't accept the opening
> > parenthesis.
>
> Yeah. Looking at the plpgsql grammar, it expects the token after FOR to
> be either SELECT or EXECUTE. This example demonstrates that that code
> is wrong, so I'll fix it for 7.4. But in the meantime, why don't you
> just leave out the parentheses?
>
> regards, tom lane