pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedQuery execution based on a condition
4+ messages / 4 participants
[nested] [flat]
* Query execution based on a condition
@ 2012-12-29 19:05 JORGE MALDONADO <jorgemal1960@gmail.com>
2012-12-29 19:23 ` Re: Query execution based on a condition David Johnston <polobo@yahoo.com>
2012-12-29 19:36 ` Re: Query execution based on a condition msi77 <msi77@yandex.ru>
2012-12-29 19:46 ` Re: Query execution based on a condition Adrian Klaver <adrian.klaver@gmail.com>
0 siblings, 3 replies; 4+ messages in thread
From: JORGE MALDONADO @ 2012-12-29 19:05 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Query execution based on a condition
2012-12-29 19:05 Query execution based on a condition JORGE MALDONADO <jorgemal1960@gmail.com>
@ 2012-12-29 19:23 ` David Johnston <polobo@yahoo.com>
2 siblings, 0 replies; 4+ messages in thread
From: David Johnston @ 2012-12-29 19:23 UTC (permalink / raw)
To: 'JORGE MALDONADO' <jorgemal1960@gmail.com>; 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.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Query execution based on a condition
2012-12-29 19:05 Query execution based on a condition JORGE MALDONADO <jorgemal1960@gmail.com>
@ 2012-12-29 19:36 ` msi77 <msi77@yandex.ru>
2 siblings, 0 replies; 4+ messages in thread
From: msi77 @ 2012-12-29 19:36 UTC (permalink / raw)
To: JORGE MALDONADO <jorgemal1960@gmail.com>; +Cc: pgsql-sql
Change the conditions of other 3 queries, so those shall give empty row sets depending on your value.
29.12.2012, 23:06, "JORGE MALDONADO" <jorgemal1960@gmail.com>:
> 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
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Query execution based on a condition
2012-12-29 19:05 Query execution based on a condition JORGE MALDONADO <jorgemal1960@gmail.com>
@ 2012-12-29 19:46 ` Adrian Klaver <adrian.klaver@gmail.com>
2 siblings, 0 replies; 4+ messages in thread
From: Adrian Klaver @ 2012-12-29 19:46 UTC (permalink / raw)
To: JORGE MALDONADO <jorgemal1960@gmail.com>; +Cc: pgsql-sql
On 12/29/2012 11:05 AM, JORGE MALDONADO wrote:
> 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?
Probably so, but is hard to be specific without more information. In a
particular the condition/field being tested and values being tested for.
> Respectfully,
> Jorge Maldonado
--
Adrian Klaver
adrian.klaver@gmail.com
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2012-12-29 19:46 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-12-29 19:05 Query execution based on a condition JORGE MALDONADO <jorgemal1960@gmail.com>
2012-12-29 19:23 ` David Johnston <polobo@yahoo.com>
2012-12-29 19:36 ` msi77 <msi77@yandex.ru>
2012-12-29 19:46 ` Adrian Klaver <adrian.klaver@gmail.com>
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