Thread: RE: [GENERAL] FW: inheritance of functions

RE: [GENERAL] FW: inheritance of functions

From
Andrzej Mazurkiewicz
Date:
Hello.
Here is an example of my problem:

ccbslin2:~/lipa$ psql -c "drop database archimp0;" template1
DESTROYDB
ccbslin2:~/lipa$ psql -c "create database archimp0;" template1
CREATEDB
ccbslin2:~/lipa$ psql -f funinh1.sql archimp0
BEGIN WORK;
BEGIN
CREATE TABLE A (
        liczba float
);
CREATE
COMMIT WORK;
END

BEGIN WORK;
BEGIN
CREATE FUNCTION suma (A) RETURNS float
        AS 'SELECT $1.liczba AS suma;' LANGUAGE 'sql';
CREATE
COMMIT WORK;
END

BEGIN WORK;
BEGIN
CREATE TABLE B (
        liczwym float
) INHERITS (A)
;
CREATE
COMMIT WORK;
END

BEGIN WORK;
BEGIN
INSERT INTO A (liczba) VALUES (1.56);
INSERT 71414 1
COMMIT WORK;
END

BEGIN WORK;
BEGIN
INSERT INTO B (liczba, liczwym) VALUES (2.5, 3.2);
INSERT 71415 1
COMMIT WORK;
END

select liczba, suma(A) from A;
liczba|suma
------+----
  1.56|1.56
(1 row)

select liczba, suma(A) from A*;
liczba|suma
------+----
  1.56|1.56
   2.5| 2.5
(2 rows)


select liczba, suma(B) from B;
ERROR:  Functions on sets are not yet supported


EOF

----------------------------------------------------------------------------
--------------------------------------

After invoking psql:


archimp0=> select * from pg_proc where proname = 'suma';
proname|proowner|prolang|proisinh|proistrusted|proiscachable|pronargs|proret
set|prorettype|
proargtypes|probyte_pct|properbyte_cpu|propercall_cpu|proouti
n_ratio|prosrc                   |probin
-------+--------+-------+--------+------------+-------------+--------+------
---+----------+-------------------+-----------+--------------+--------------
+--------------+-------------------------+------
suma   |     302|     14|f       |t           |f            |       1|f
|       701|71393 0 0 0 0 0 0 0|        100|             0|             0|
100|SELECT $1.liczba AS suma;|-
(1 row)

archimp0=>

I am looking for working example !!!!!

Regards,
Andrzej Mazurkiewicz
> -----Original Message-----
> From:    Aaron J. Seigo [SMTP:aaron@gtv.ca]
> Sent:    27 paYdziernika 1999 17:39
> To:    Andrzej Mazurkiewicz; 'pgsql-general@hub.org'
> Subject:    Re: [GENERAL] FW: inheritance of functions
>
> hi...
>
> > >  Postgres automatically allows the created table to inherit functions
> on
> > > tables above it in the inheritance hierarchy.
> > > create table A (
> > > .
> > > .
> > > );
> > >
> > > create function F ...
> > >
> > > create table B (
> > > ..
> > > ) inherits (A);
> > >
> > > Now I assume that I can somehow use function F on table B
>
> you would be able to use function F on table B even if it didn't inherit
> A.
>
> however, if you construct rules, triggers, etc... on table A, these should
> be
> inherited by table B.
>
> the manual is, as far as my experience has led me to believe, referring to
> functions "bound" (for lack of a better word) to the parent table....
>
> --
> Aaron J. Seigo
> Sys Admin