From: Kumar <sgnerd@yahoo.com.sg>
To: Christoph Haller <ch@rodos.fzk.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-sql@postgresql.org
Subject: Re: Using UNION inside a cursor
Date: Fri, 31 Oct 2003 09:16:51 +0530
Message-ID: <007001c39f62$a44088d0$7502a8c0@hdsc.com> (raw)
References: <200310300926.KAA04661@rodos>
<28146.1067527227@sss.pgh.pa.us>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: sgnerd@yahoo.com.sg, ch@rodos.fzk.de, tgl@sss.pgh.pa.us
Subject: Re: Using UNION inside a cursor
In-Reply-To: <007001c39f62$a44088d0$7502a8c0@hdsc.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox