Re: Query execution based on a condition - Mailing list pgsql-sql

From David Johnston
Subject Re: Query execution based on a condition
Date
Msg-id 00a101cde5f9$ff5461f0$fdfd25d0$@yahoo.com
Whole thread Raw
In response to Query execution based on a condition  (JORGE MALDONADO <jorgemal1960@gmail.com>)
List pgsql-sql

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.

 

pgsql-sql by date:

Previous
From: JORGE MALDONADO
Date:
Subject: Query execution based on a condition
Next
From: msi77
Date:
Subject: Re: Query execution based on a condition