Re: Oracle Decode Function

From: Marc Lavergne <mlavergne-pub(at)richlava(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Oracle Decode Function
Date: 2002-07-26 15:11:44
Message-ID: 3D4166B0.3060904@richlava.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2002-07-26 15:16:46 Re: solaris 9?
Previous Message Tom Lane 2002-07-26 15:09:29 Re: SET LOCAL again