Re: Oracle Decode Function

Поиск
Список
Период
Сортировка
От Marc Lavergne
Тема Re: Oracle Decode Function
Дата
Msg-id 3D4166B0.3060904@richlava.com
обсуждение исходный текст
Ответ на Re: Oracle Decode Function  ("Christopher Kings-Lynne" <chriskl@familyhealth.com.au>)
Ответы Re: Oracle Decode Function  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
> contrib/fulltextindex/fti.c uses variable numbers of arguments...

I see the code, but maybe I don't SEE the code. I'm only on my second 
cup of coffee so I may be missing something but I am not betting any 
money in it :) Fulltextindex appears to work because it's called within 
a trigger but I don't think you can get the parser not to complain about 
arguments when your function is not called internally by the trigger 
manager. Here's my fat-free proof of concept:

-- -----------------------------------------------
-- /tmp/varargs.c

#include "postgre.h"
#include "fmgr.h"

PG_FUNCTION_INFO_V1(varargs);

Datum varargs(PG_FUNCTION_ARGS)
{  int32 v_0 = PG_GETARG_INT32(0);  int32 v_1 = PG_GETARG_INT32(1);
  PG_RETURN_INT32(v_0 + v_1);
}

-- -----------------------------------------------

gcc -Wall -L. -D_REENTRANT -fPIC -shared 
-I/home/postgre/postgresql-7.2/src/include -o /tmp/varargs.so /tmp/varargs.c

-- -----------------------------------------------
-- verify it works with arg defs

create function varargs(int4, int4) returns int4 as  '/tmp/varargs.so'  language 'C';

-- -----------------------------------------------

select varargs(1,2);
 varargs
---------       3
(1 row)

-- -----------------------------------------------
-- verify the failure without arg defs

drop function varargs(int4 int4);
create function varargs() returns int4 as  '/tmp/varargs.so'  language 'C';

-- -----------------------------------------------

select varargs(1,2);

ERROR:  Function 'varargs(int4, int4)' does not exist        Unable to identify a function that satisfies the given
argument
 
types        You may need to add explicit typecasts

-- -----------------------------------------------


Christopher Kings-Lynne wrote:
>>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.
> 
> 
> contrib/fulltextindex/fti.c uses variable numbers of arguments...
> 
> Chris
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
> http://archives.postgresql.org
> 




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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: SET LOCAL again
Следующее
От: Tom Lane
Дата:
Сообщение: Re: solaris 9?