Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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 '
  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];
    return array[$1];
  end if;
' 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.



Attachment: poly-plpgsql.01.patch
Description: text/plain (10.4 KB)


pgsql-patches by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group