Re: polymorphic arguments and return type for PL/pgSQL

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: polymorphic arguments and return type for PL/pgSQL
Date: 2003-06-30 13:59:21
Message-ID: 4334.1056981561@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

Joe Conway <mail(at)joeconway(dot)com> writes:
> The attached patch enables PL/pgSQL functions (but not triggers) to
> accept and return polymorphic types. It is careful to return false from
> func_up_to_date() if any of the polymorphic types change from
> call-to-call.

I don't think you can usefully do it that way. Suppose the same
function is being invoked in two places in a query, with two different
actual argument types at the two spots. Won't this setup result in
dropping and rebuilding the function cache twice per row? You've really
got to arrange for there to be a separate function cache entry for each
set of argument types --- in other words, the actual arg types have to
be part of the cache key. (It might be time to change the cache lookup
into a hashtable instead of a simple linear list search...)

> It also falls back to the pg_proc declared types if the
> caller didn't setup the FuncExpr node.

This will result in "plpgsql functions cannot return type anyarray"
which is at best misleading. It'd be better to have a specific error
message, say "could not determine actual return type for polymorphic
function %s".

regards, tom lane

In response to

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Serguei Mokhov 2003-06-30 14:13:19 Re: pgAdmin3 translation request into Russian
Previous Message Jean-Michel POURE 2003-06-30 13:48:01 Re: Translation request of pgAdmin3 into Czech