Re: Using UNION inside a cursor - Mailing list pgsql-sql

From Kumar
Subject Re: Using UNION inside a cursor
Date
Msg-id 007001c39f62$a44088d0$7502a8c0@hdsc.com
Whole thread Raw
In response to Re: Using UNION inside a cursor  (Christoph Haller <ch@rodos.fzk.de>)
List pgsql-sql
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



pgsql-sql by date:

Previous
From: Jan Wieck
Date:
Subject: 7.4 and 7.3.5 showstopper (was: Re: Bug in Rule+Foreing key constrain?)
Next
From: Jan Wieck
Date:
Subject: Re: 7.4 and 7.3.5 showstopper