Re: dblink: add polymorphic functions.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Corey Huinker <corey(dot)huinker(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: dblink: add polymorphic functions.
Date: 2015-07-06 14:35:24
Message-ID: 26572.1436193324@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Joe Conway <mail(at)joeconway(dot)com> writes:
> 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 set of allowed argument-type combinations is so easily enumerable,
I don't understand why this is being done at all. Create a separate SQL
function for each combination. You can still let the called C functions
call a common implementation routine if that's helpful.

However, this might all be moot in view of Merlin's objection. It is
definitely completely uncool to have both of these:

> public | dblink | SETOF anyelement | text, anyelement | normal
> public | dblink | SETOF record | text, boolean | normal

It's quite unclear which one will get called for cases like, say, second
argument is a domain over boolean. And even if the second arg is just a
boolean, maybe the user wanted the first case --- how will he get that
behavior, if so? These need to have different names, and that might well
help resolve the implementation-level issue...

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Merlin Moncure 2015-07-06 14:37:45 Re: dblink: add polymorphic functions.
Previous Message Stephen Frost 2015-07-06 14:22:22 Re: more RLS oversights