Hello,
I would like to implement a function similar to the Decode function in
Oracle. I was wondering if it is possible to accept a variable number
of parameters (array??).
Thanks,
Edwin S. Ramirez
---(end of broadcast)---
TIP 5: Have you
I would like to implement a function similar to the Decode function in
Oracle.
Take a look at the CASE WHEN ... THEN functionality. For example:
Oracle:
select decode(col1,'abc',1,'xyz',2,0) from test;
Postgresql:
select case when col1 = 'abc' then 1 when col1 = 'xyz' then 2 else 0 end
Marc Lavergne [EMAIL PROTECTED] 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
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
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
would be interested to hear a valid reason why you feel the need
to use decode().
Just let me start by saying that this is NOT for me (see the original
email in thread)! Personally, I have no trouble using CASE. However, if
I want to create an Oracle-compatibilty layer, I have to implement