Re: Porting Oracle Decode to Postgresql

From: MindTerm <mindterm(at)yahoo(dot)com>
To: Tod McQuillin <devin(at)spamcop(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Porting Oracle Decode to Postgresql
Date: 2001-11-22 09:54:57
Message-ID: 20011122095457.94397.qmail@web20210.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Dear Tod McQuillin,

Can perform the action as same as oracle in
postgresql ?

e.g.
Select decode_function( ... , ... , ..... ) from ..

I can write a plpgsql to simulate the nvl function
by using coalesce .

CREATE FUNCTION nvl( numeric, numeric ) RETURNS
varchar AS '
DECLARE
input_value ALIAS FOR $1;
else_value ALIAS FOR $2;
output_value numeric;
BEGIN
select coalesce( input_value, else_value ) into
output_value ;
return output_value ;
END;
' LANGUAGE 'plpgsql' ;

M.T.

--- Tod McQuillin <devin(at)spamcop(dot)net> wrote:
> On Thu, 22 Nov 2001, MindTerm wrote:
>
> > I am writing to ask how to port oracle's decode(
> ..)
> > function to postgresql ?
>
> The ANSI SQL version of decode is CASE.
>
> See
>
http://www.postgresql.org/idocs/index.php?functions-conditional.html
> for the full documentation, but basically, it works
> like this:
>
> Oracle:
> decode (value, 0, 'zero', 1, 'one', 'unknown')
>
> ANSI:
> CASE WHEN value=0 THEN 'zero' WHEN value=1 THEN
> 'one' ELSE 'unknown' END
>
> or
>
> CASE value WHEN 0 THEN 'zero' WHEN 1 THEN 'one' ELSE
> 'unknown' END
>
> --
> Tod McQuillin
>
>

__________________________________________________
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message MindTerm 2001-11-22 10:21:53 Re: Porting Oracle Decode to Postgresql
Previous Message Tod McQuillin 2001-11-22 09:47:50 Re: Porting Oracle Decode to Postgresql