Is there any chance to implement polymorphic calls in PostgreSQL?
Consider the following definitions:

create table base_table (x integer, y integer);
create table derived_table (z integer) inherits (base_table);
create function volume(r base_table) returns integer as $$ begin return r.x*r.y; end; $$ language plpgsql strict stable; create function volume(r derived_table) returns integer as $$ begin return r.x*r.y*r.z; end; $$ language plpgsql strict stable;
insert into base_table values (1,2);
insert into derived_table values (3,4,5);

postgres=# select * from base_table;
 x | y
---+---
 1 | 2
 3 | 4
(2 rows)

postgres=# select volume(r) from base_table r;
 volume
--------
      2
     12
(2 rows)

postgres=# select volume(r) from only base_table r union all select volume(r_1) from only derived_table r_1;
 volume
--------
      2
     60
(2 rows)


Execution plans of first and second queries are very similar.
The difference is that type of r_1 in first query is "base_table".
It is obvious that query should return fixed set of columns, so

    select * from base_table;

can not return "z" column.
But passing direved_table type instead of base_table type to volume() function for record belonging to derived_table seems to be possible and not contradicting something, isn't it?


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to