pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rodrigo E. De León Plicet <rdeleonp@gmail.com>
To: Gerardo Herzig <gherzig@fmed.uba.ar>
Cc: pgsql-sql@postgresql.org
Subject: Re: using case to select 'which version to use'
Date: Thu, 20 Aug 2009 11:33:14 -0500
Message-ID: <a55915760908200933p5740cb21i4fcb37f1ea8eb242@mail.gmail.com> (raw)
In-Reply-To: <4A8D6912.60207@fmed.uba.ar>
References: <4A8D6912.60207@fmed.uba.ar>

On Thu, Aug 20, 2009 at 10:17 AM, Gerardo Herzig<gherzig@fmed.uba.ar> wrote:
> Hi all. I have 2 functions , which returns the same columns, but with
> tottaly different logics. I want to wrap it with a third function, who
> will receive a boolean argument to decide wich sub-function have to use.
>
> I want to use case, so i dont have to use pl/pgsql.
>
> This is a non-working example:
>
>
> CREATE OR REPLACE FUNCTION get_oferta(varchar, varchar, varchar, bool,
> OUT cod varchar , OUT description varchar)
> returns setof record
> security definer
> as
> $$
> select  * from case $4 when true then
>    (select * from get_oferta_from_a($1, $2, $3))
> else
>    (select * from get_oferta_from_b($1, $2, $3))
> end;
> $$ language sql;
>
> Can i use case for a case like this?
>
> Thanks!
> Gerardo

Try:

SELECT *
FROM get_oferta_from_a ($1, $2, $3)
WHERE $4
UNION ALL
SELECT *
FROM get_oferta_from_b ($1, $2, $3)
WHERE NOT $4;



view thread (3+ messages)  latest in thread

Message-ID: <a55915760908200933p5740cb21i4fcb37f1ea8eb242@mail.gmail.com>
Permalink:  ../a55915760908200933p5740cb21i4fcb37f1ea8eb242@mail.gmail.com/
Also on:    postgresql.org/message-id/a55915760908200933p5740cb21i4fcb37f1ea8eb242@mail.gmail.com

 · 

reply

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: rdeleonp@gmail.com, gherzig@fmed.uba.ar
  Subject: Re: using case to select 'which version to use'
  In-Reply-To: <a55915760908200933p5740cb21i4fcb37f1ea8eb242@mail.gmail.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