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>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Using UNION inside a cursor
Date: 2003-10-31 03:46:51
Message-ID: 007001c39f62$a44088d0$7502a8c0@hdsc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)sss(dot)pgh(dot)pa(dot)us>
To: "Christoph Haller" <ch(at)rodos(dot)fzk(dot)de>
Cc: ""Kumar"" <sgnerd(at)yahoo(dot)com(dot)sg>; <pgsql-sql(at)postgresql(dot)org>
Sent: Thursday, October 30, 2003 8:50 PM
Subject: Re: [SQL] Using UNION inside a cursor

> Christoph Haller <ch(at)rodos(dot)fzk(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jan Wieck 2003-10-31 04:00:54 Re: 7.4 and 7.3.5 showstopper
Previous Message Tomasz Myrta 2003-10-30 19:14:13 Re: strange postgresql failure