Oracle decode Function in Postgres

Started by Amin Schoeibover 22 years ago6 messagesgeneral
Jump to latest
#1Amin Schoeib
aschoeib@4tek.de

Hi,
Like I see there is no equivalent to the Oracle decode Function
In Postgres.Is there maybe somebody who wrote decode as a
Function?

Schoeib

4Tek Gesellschaft für angewandte Informationstechnologien mbH
Schoeib Amin
Tel. +49 (0) 69 697688-132
Fax. +49 (0) 69 697688-111
http://www.4tek.de

#2Csaba Nagy
nagy@ecircle-ag.com
In reply to: Amin Schoeib (#1)
Re: Oracle decode Function in Postgres

Of course there is an equivalent: the case construct.
There is some nice documentation about the available functions and
operators at:
http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=functions.html
and specifically for CASE:
http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=functions-conditional.html#AEN9698
You might also find useful to know that the NVL oracle function's
parallel in postgres is COALESCE.

HTH,
Csaba.

Show quoted text

On Wed, 2003-09-03 at 11:00, Amin Schoeib wrote:

Hi,
Like I see there is no equivalent to the Oracle decode Function
In Postgres.Is there maybe somebody who wrote decode as a
Function?

Schoeib

4Tek Gesellschaft für angewandte Informationstechnologien mbH
Schoeib Amin
Tel. +49 (0) 69 697688-132
Fax. +49 (0) 69 697688-111
http://www.4tek.de

#3Amin Schoeib
aschoeib@4tek.de
In reply to: Csaba Nagy (#2)
Re: Oracle decode Function in Postgres

I read about that but, is there maybe somebody who wrote
A decode function so that you can export Oracle code with decode
Easily to Postgres.
I ask for that cause I am a beginner in PGPLSQL.

Thanxx

Schoeib

-----Ursprüngliche Nachricht-----
Von: Csaba Nagy [mailto:nagy@ecircle-ag.com]
Gesendet: Mittwoch, 3. September 2003 11:37
An: Amin Schoeib
Cc: Postgres general mailing list
Betreff: Re: [GENERAL] Oracle decode Function in Postgres

Of course there is an equivalent: the case construct.
There is some nice documentation about the available functions and operators at: http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=functions.html
and specifically for CASE: http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=functions-conditional.html#AEN9698
You might also find useful to know that the NVL oracle function's parallel in postgres is COALESCE.

HTH,
Csaba.

Show quoted text

On Wed, 2003-09-03 at 11:00, Amin Schoeib wrote:

Hi,
Like I see there is no equivalent to the Oracle decode Function
In Postgres.Is there maybe somebody who wrote decode as a
Function?

Schoeib

4Tek Gesellschaft für angewandte Informationstechnologien mbH Schoeib
Amin Tel. +49 (0) 69 697688-132
Fax. +49 (0) 69 697688-111
http://www.4tek.de

#4Csaba Nagy
nagy@ecircle-ag.com
In reply to: Amin Schoeib (#3)
Re: Oracle decode Function in Postgres

Somebody asked recently on this list the exact same style of question
about NVL, receiving the exact same style of answer, having the same
objection :)
Search in the archive (in the lat month or so) for "nvl" in the subject
to see some answers.

Cheers,
Csaba.

Show quoted text

On Wed, 2003-09-03 at 12:25, Amin Schoeib wrote:

I read about that but, is there maybe somebody who wrote
A decode function so that you can export Oracle code with decode
Easily to Postgres.
I ask for that cause I am a beginner in PGPLSQL.

Thanxx

Schoeib

-----Ursprüngliche Nachricht-----
Von: Csaba Nagy [mailto:nagy@ecircle-ag.com]
Gesendet: Mittwoch, 3. September 2003 11:37
An: Amin Schoeib
Cc: Postgres general mailing list
Betreff: Re: [GENERAL] Oracle decode Function in Postgres

Of course there is an equivalent: the case construct.
There is some nice documentation about the available functions and operators at: http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=functions.html
and specifically for CASE: http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=functions-conditional.html#AEN9698
You might also find useful to know that the NVL oracle function's parallel in postgres is COALESCE.

HTH,
Csaba.

On Wed, 2003-09-03 at 11:00, Amin Schoeib wrote:

Hi,
Like I see there is no equivalent to the Oracle decode Function
In Postgres.Is there maybe somebody who wrote decode as a
Function?

Schoeib

4Tek Gesellschaft für angewandte Informationstechnologien mbH Schoeib
Amin Tel. +49 (0) 69 697688-132
Fax. +49 (0) 69 697688-111
http://www.4tek.de

#5Jeff Eckermann
jeff_eckermann@yahoo.com
In reply to: Amin Schoeib (#1)
Re: Oracle decode Function in Postgres
--- Amin Schoeib <aschoeib@4tek.de> wrote:

Hi,
Like I see there is no equivalent to the Oracle
decode Function
In Postgres.Is there maybe somebody who wrote decode
as a
Function?

The problem for any such body is that there is no one
function possible in PostgreSQL that will cover all of
the possible use cases of "decode" in Oracle. As I
understand things, "decode" takes a variable number of
arguments, for a variety of datatypes. In PostgreSQL
you would need to create a separate "decode" function
for every distinct set of arguments (number and
datatypes) that you are likely to encounter. That
would be a lot of work for a generalized case.

You may be best served by searching your code for
usage of "decode", and writing only those versions
that you need. The coding for each one would be
trivial, using "case" constructions.

Schoeib

4Tek Gesellschaft f���r angewandte
Informationstechnologien mbH
Schoeib Amin
Tel. +49 (0) 69 697688-132
Fax. +49 (0) 69 697688-111
http://www.4tek.de

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

#6Terry Yapt
pgsql@technovell.com
In reply to: Amin Schoeib (#3)
Re: Oracle decode Function in Postgres

I read about that but, is there maybe somebody who wrote
A decode function so that you can export Oracle code with decode
Easily to Postgres.
I ask for that cause I am a beginner in PGPLSQL.

Perhaps you want to accommodate your Oracle code to the new Oracle 9i
features. And that features supports CASE statement too:

http://www.oracle-base.com/Articles/9i/Case9i.asp