Re: Oracle Decode Function

From: Chris Humphries <chumphries(at)devis(dot)com>
To: Marc Lavergne <mlavergne-pub(at)richlava(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Oracle Decode Function
Date: 2002-07-25 20:16:53
Message-ID: 15680.23733.858258.744912@metalico.drauku.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

if you find yourself using the decode statement, you are probably
doing something wrong. why have it, do you _need_ it?

if you are using it for display strings based on conditions,
you shouldnt be using a function to do this. it should be a table,
or something in the middle layer. try to keep the frame of mind of
letting the db do it's job of just managing data; middle layer for
doing something useful with the data and sending to the top layer
for presentation or formatted data that is meaningful there. It
is the right(tm) way to do things, and will make life alot easier :)

would be interested to hear a valid reason why you feel the need
to use decode(). seems that oracle gives you alot of functions and
abilities that allow dba's and programmers to be lazy, instead of
having a good db [relational] design (and that is more standards
compliant).

though like Tom Lane said, there is case, if you need it.
good luck!

-chris

Marc Lavergne writes:
> That would get ugly in a real hurry! Oracle does get around the issue of
> parameter datatypes by having automatic datatype conversions, more or
> less, everything becomes a varchar2. The only real attractants to
> implementing a DECODE() function is that it's one less thing to convert
> when migrating apps from Oracle and, unfortunately, this is also a piece
> of the SQL*Net compatibility that I'm looking into doing!
>
>
> Tom Lane wrote:
> > Marc Lavergne <mlavergne-pub(at)richlava(dot)com> writes:
> >
> >>If you're asking about whether a custom function can have vararg
> >>parameters, the answer appears to depend on the CREATE FUNCTION
> >>syntax.
> >
> >
> > Can't do it, though you could imagine creating a family of functions
> > of the same name and different numbers of parameters. Trying to
> > emulate DECODE this way would have a much worse problem: what's the
> > datatype of the parameters? (Or the result?)
> >
> > Use CASE; it does more than DECODE *and* is ANSI-standard.
> >
> > regards, tom lane
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
> >
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kangmo, Kim 2002-07-25 20:19:24 Re: tuple concurrently updated
Previous Message Marc Lavergne 2002-07-25 20:09:04 Re: Oracle Decode Function