Re: Oracle Decode Function

Поиск
Список
Период
Сортировка
От Marc Lavergne
Тема Re: Oracle Decode Function
Дата
Msg-id 3D4004BB.4010402@richlava.com
обсуждение исходный текст
Ответ на Oracle Decode Function  (ramirez@idconcepts.org (Edwin S. Ramirez))
Ответы Re: Oracle Decode Function  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Oracle Decode Function  ("Christopher Kings-Lynne" <chriskl@familyhealth.com.au>)
Список pgsql-hackers
 > 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
> 




В списке pgsql-hackers по дате отправления:

Предыдущее
От: "John Liu"
Дата:
Сообщение: why?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: bug in COPY