Re: dblink: add polymorphic functions. - Mailing list pgsql-hackers

From Corey Huinker
Subject Re: dblink: add polymorphic functions.
Date
Msg-id CADkLM=er4LDi_WcbB8bMNpHROPKF18-uCRA2=-whiK6M1Co95g@mail.gmail.com
Whole thread Raw
In response to Re: dblink: add polymorphic functions.  (Joe Conway <mail@joeconway.com>)
List pgsql-hackers


On Mon, Jul 6, 2015 at 10:08 AM, Joe Conway <mail@joeconway.com> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/06/2015 12:39 AM, Michael Paquier wrote:
>> Yeah, particularly the use of first_optarg makes things harder
>> to follow in the code with this patch. A C wrapper has the
>> disadvantage to decentralize the argument checks to many places
>> making the flow harder to follow hence using
>> get_fn_expr_argtype() with PG_NARGS would be the way to go, at
>> least to me. This way, you can easily find how many arguments
>> there are, and which value is assigned to which variable before
>> moving on to the real processing.
>
> Just to be clear I mean that: if (PG_NARGS() == 5) { if
> (get_fn_expr_argtype(fcinfo->flinfo, 1) == TYPEOID) var =
> PG_GETARG_BOOL(1) [...]

Actually, I had in mind something like:
8<---------------------
int    i;
int    numargs;
int   *argtypes;

numargs = PG_NARGS();
argtypes = palloc(numargs * sizeof(int));
for (i = 0; i < numargs; i++)
    argtypes[i] = get_fn_expr_argtype(fcinfo->flinfo, i);

if ((numargs == 4 || numargs == 5) &&
    argtypes[0] == TEXTOID &&
    argtypes[1] == TEXTOID &&
    argtypes[2] == INT4OID &&
    argtypes[3] == BOOLOID)
{
    [...]
}
else if  ((numargs == 3 || numargs == 4) &&
    argtypes[0] == TEXTOID &&
    argtypes[1] == INT4OID &&
    argtypes[2] == BOOLOID)
{
    [...]
8<---------------------
etc.

If the highest number of arguments is always checked first, the
pattern is not ambiguous even with the extra anyelement.


Utterly reasonable and do-able. I'll get to work on that soonish, pending resolution of other's concerns. 

pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: Re: RFC: replace pg_stat_activity.waiting with something more descriptive
Next
From: Joe Conway
Date:
Subject: Re: dblink: add polymorphic functions.