X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 7B5ABD1B511 for ; Fri, 31 Oct 2003 03:57:04 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 93963-10 for ; Thu, 30 Oct 2003 23:56:37 -0400 (AST) Received: from smtp015.mail.yahoo.com (smtp015.mail.yahoo.com [216.136.173.59]) by svr1.postgresql.org (Postfix) with SMTP id 9A308D1B53A for ; Thu, 30 Oct 2003 23:56:32 -0400 (AST) Received: from ptil-138-190-chn.primus-india.net (HELO IVESIA67) (sgnerd@203.196.190.138 with login) by smtp.mail.vip.sc5.yahoo.com with SMTP; 31 Oct 2003 03:56:36 -0000 Message-ID: <007001c39f62$a44088d0$7502a8c0@hdsc.com> Reply-To: "Kumar" From: "Kumar" To: "Christoph Haller" , "Tom Lane" Cc: References: <200310300926.KAA04661@rodos> <28146.1067527227@sss.pgh.pa.us> Subject: Re: Using UNION inside a cursor Date: Fri, 31 Oct 2003 09:16:51 +0530 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.6 tagged_above=0.0 required=5.0 tests=BAYES_30, QUOTED_EMAIL_TEXT, REFERENCES, WEIRD_QUOTING X-Spam-Level: X-Archive-Number: 200310/408 X-Sequence-Number: 15808 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" To: "Christoph Haller" Cc: ""Kumar"" ; Sent: Thursday, October 30, 2003 8:50 PM Subject: Re: [SQL] Using UNION inside a cursor > Christoph Haller 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