From: David Johnston <polobo@yahoo.com>
To: 'JORGE MALDONADO' <jorgemal1960@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Query execution based on a condition
Date: Sat, 29 Dec 2012 14:23:35 -0500
Message-ID: <00a101cde5f9$ff5461f0$fdfd25d0$@yahoo.com> (raw)
In-Reply-To: <CAAY=A79=a3jPonSK9pHvVvS6QAFQdLZdKWAkkQj+bVdPB-GCNw@mail.gmail.com>
References: <CAAY=A79=a3jPonSK9pHvVvS6QAFQdLZdKWAkkQj+bVdPB-GCNw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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.
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: polobo@yahoo.com, jorgemal1960@gmail.com
Subject: Re: Query execution based on a condition
In-Reply-To: <00a101cde5f9$ff5461f0$fdfd25d0$@yahoo.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