polymorphic arguments and return type for PL/pgSQL

From: Joe Conway <mail(at)joeconway(dot)com>
To: "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: polymorphic arguments and return type for PL/pgSQL
Date: 2003-06-30 06:05:52
Message-ID: 3EFFD340.7000009@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

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. It also falls back to the pg_proc declared types if the
caller didn't setup the FuncExpr node.

Here is an example that I can add to the plpgsql regression test if desired:

CREATE OR REPLACE FUNCTION tst(anyelement) returns anyarray as '
begin
if $1 is of (int2, int4, int8, float4, float8, numeric) then
return array[$1 * 2];
elsif $1 is of (text) then
return array[$1 || $1];
else
return array[$1];
end if;
end;
' language 'plpgsql';

create table plpgsql(f1 int, f2 float8, f3 text, f4 oid);
insert into plpgsql values(1, 1.1, 'a', 1);
insert into plpgsql values(2, 2.2, 'b', 2);
regression=# SELECT tst(f1), tst(f2), tst(f3), tst(f4) from plpgsql;
tst | tst | tst | tst
-----+-------+------+-----
{2} | {2.2} | {aa} | {1}
{4} | {4.4} | {bb} | {2}
(2 rows)

If there are no objections, please apply.

Thanks,

Joe

Attachment Content-Type Size
poly-plpgsql.01.patch text/plain 10.4 KB

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message sumit 2003-06-30 10:04:11 Patch for adding DATACUBE operator
Previous Message Srikanth M 2003-06-30 04:16:31 Urgent : Regarding Code Submission