> 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 
from test;

 > I was wondering if it is possible to accept a variable number
 > of parameters (array??).

If you're asking about whether a custom function can have vararg 
parameters, the answer appears to depend on the CREATE FUNCTION syntax. 
I've never used them personally, but the PG_FUNCTION_ARGS and 
PG_GETARG_xxx(#) macros (/src/includes/fmgr.h) available for compiled 
functions would appear to support variable length argument lists. The 
problem is that I couldn't pin down a CREATE FUNCTION that provided the 
same vararg functionality. Hopefully somebody can answer this conclusively.

If it can't be done using custom functions, it should be implementable 
"internally" using the same concepts used to support the IN() function 
so maybe take a look in /src/backend/parser/parse_func.c for a start.


Edwin S. Ramirez wrote:
> 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 checked our extensive FAQ?
> 
> http://www.postgresql.org/users-lounge/docs/faq.html
> 



---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to