Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tp20g-0000zZ-Su for pgsql-sql@arkaria.postgresql.org; Sat, 29 Dec 2012 19:23:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Tp20g-0006jM-BQ for pgsql-sql@arkaria.postgresql.org; Sat, 29 Dec 2012 19:23:54 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tp20e-0006hu-E9 for pgsql-sql@postgresql.org; Sat, 29 Dec 2012 19:23:52 +0000 Received: from nm12-vm0.bullet.mail.bf1.yahoo.com ([98.139.213.140]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tp20Z-0003Vl-04 for pgsql-sql@postgresql.org; Sat, 29 Dec 2012 19:23:51 +0000 Received: from [98.139.212.151] by nm12.bullet.mail.bf1.yahoo.com with NNFMP; 29 Dec 2012 19:23:45 -0000 Received: from [76.13.13.45] by tm8.bullet.mail.bf1.yahoo.com with NNFMP; 29 Dec 2012 19:23:45 -0000 Received: from [127.0.0.1] by smtp106.prem.mail.ac4.yahoo.com with NNFMP; 29 Dec 2012 19:23:45 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1356809025; bh=iyfRtdh0I1lS3H62dDJBFkW2ptCROBr0RS/bzx6rK4s=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:X-Mailer:Thread-Index:Content-Language; b=C1pE3eTqXWPSEcO24gUwwk4vIqQ4+/dlUmcMmOicVcEFA6dQ/msE/xXVZzSCn8wuYG2KdGcJQUqAd0VAQfUtrq9QXBSCYKzd6KuiS7QyGAJHrPqPPBssQvB+0PTmQ4b4BDahsO0tfbxt+OICfwcibg7eKeSJ4PJLx+fYYq8w270= X-Yahoo-Newman-Id: 480658.64833.bm@smtp106.prem.mail.ac4.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: wOoS5HoVM1kLJPKD_HVRJSN4e_bhSHwLa6F7Xa300MdRR34 67ZUfLcQVbzPTQYTY70ulmnhsNfrOCSQn9lcf4u9ANkVzXzdIim6MjZ_88bJ MARtosHmb66GhMVxEbiWjAkghVrIs3FVThhpWngq5hHPg7tdvOKtT3VNVBcq xYUMvwd45pFSdlfvUS5zDEZmMnJr_4GmkwQwDVYi_yt6a4a23KkwpN6dQONj DfI_N_TXCJt7hNZgGXhv.bLF1EleNpHCg2VDedi6lLIiA3exEmEsGpSQsja9 qNkITIwhZw_9wKXK3LYkRIZE9.scUeZTlhl9TjwXWyCnRlC6ePlcqDag6BGZ 0QTWPK5te42GCJTnAF7bh8tfVjz4NuLmOkggeBuodLrzem4fLOZw05aDEFxe NRjCsEaJ6qmckqkWdCduUaG9Ub..PtJuzeVCwxDppij6NUE522SMKt9MM_Mj 9hCQ- X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from WolfDog (polobo@24.93.28.86 with login) by smtp106.prem.mail.ac4.yahoo.com with SMTP; 29 Dec 2012 11:23:45 -0800 PST From: "David Johnston" To: "'JORGE MALDONADO'" , References: In-Reply-To: Subject: Re: Query execution based on a condition Date: Sat, 29 Dec 2012 14:23:35 -0500 Message-ID: <00a101cde5f9$ff5461f0$fdfd25d0$@yahoo.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_00A2_01CDE5D0.167FE090" X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQHoZoKevm3sDHNpesCRNTqpmO39BZf7JoCw Content-Language: en-us X-Pg-Spam-Score: 0.7 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org This is a multipart message in MIME format. ------=_NextPart_000_00A2_01CDE5D0.167FE090 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of JORGE MALDONADO Sent: Saturday, December 29, 2012 2:06 PM To: pgsql-sql@postgresql.org Subject: [SQL] Query execution based on a condition I have a query similar to the one shown below but, depending on the value of a field, only the first SELECT statement shoud execute and the other 3 should be ignored. Is there a way to achieve this situation? SELECT fields FROM tblTable WHERE condition UNION SELECT fields FROM tblTable WHERE condition UNION SELECT fields FROM tblTable WHERE condition UNION SELECT fields FROM tblTable WHERE condition Respectfully, Jorge Maldonado Not using pure SQL. pl/pgsql provides you access to conditionals and flow control so you should be able to create a function to do precisely what you need. David J. ------=_NextPart_000_00A2_01CDE5D0.167FE090 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

From:= = pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] = On Behalf Of JORGE MALDONADO
Sent: Saturday, December = 29, 2012 2:06 PM
To: = pgsql-sql@postgresql.org
Subject: [SQL] Query execution based = on a condition

 

I = have a query similar to the one shown below but, depending on the value = of a field, only the first SELECT statement shoud execute and the other = 3 should be ignored. Is there a way to achieve this = situation?

 

SELECT fields FROM tblTable WHERE = condition

UNION

SELECT fields FROM tblTable WHERE = condition

UNION

SELECT fields FROM tblTable WHERE = condition

UNION

SELECT fields FROM tblTable WHERE = condition

 

Respectfully,

Jorge Maldonado

 

 

Not using pure SQL.  pl/pgsql provides you access to = conditionals and flow control so you should be able to create a function = to do precisely what you need.

 

David J.

 

------=_NextPart_000_00A2_01CDE5D0.167FE090--