pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedusing case to select 'which version to use'
3+ messages / 2 participants
[nested] [flat]
* using case to select 'which version to use'
@ 2009-08-20 15:17 Gerardo Herzig <gherzig@fmed.uba.ar>
0 siblings, 1 reply; 3+ messages in thread
From: Gerardo Herzig @ 2009-08-20 15:17 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: using case to select 'which version to use'
@ 2009-08-20 16:33 Rodrigo E. De León Plicet <rdeleonp@gmail.com>
parent: Gerardo Herzig <gherzig@fmed.uba.ar>
0 siblings, 1 reply; 3+ messages in thread
From: Rodrigo E. De León Plicet @ 2009-08-20 16:33 UTC (permalink / raw)
To: Gerardo Herzig <gherzig@fmed.uba.ar>; +Cc: pgsql-sql
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;
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: using case to select 'which version to use'
@ 2009-08-21 18:13 Gerardo Herzig <gherzig@fmed.uba.ar>
parent: Rodrigo E. De León Plicet <rdeleonp@gmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: Gerardo Herzig @ 2009-08-21 18:13 UTC (permalink / raw)
To: "Rodrigo E. De León Plicet" <rdeleonp@gmail.com>; +Cc: pgsql-sql
Rodrigo E. De León Plicet wrote:
> 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;
>
>
Well, looks like it will work. I think i found the right syntax now:
select foo.* from
(select case $4 when false then
get_oferta_from_a($1, $2, $3)
else
get_oferta_from_b($1, $2, $3)
end) as foo;
Thanks!
Gerardo
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2009-08-21 18:13 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-08-20 15:17 using case to select 'which version to use' Gerardo Herzig <gherzig@fmed.uba.ar>
2009-08-20 16:33 ` Rodrigo E. De León Plicet <rdeleonp@gmail.com>
2009-08-21 18:13 ` Gerardo Herzig <gherzig@fmed.uba.ar>
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