Re: Typed tables

Andrew Chernow <ac@esilo.com>

From: Andrew Chernow <ac@esilo.com>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-hackers@postgresql.org
Date: 2010-01-12T14:36:33Z
Lists: pgsql-hackers
Peter Eisentraut wrote:
> On tis, 2010-01-12 at 08:05 -0500, Andrew Chernow wrote:
>> In practice, tables can be used for passing data around or storing it on disk. 
>> So, I guess my question remains unanswered as to what the composite type offers 
>> that a table doesn't; other than a name that better suits the task.
> 
> The arguments of functions are types, not tables.  So you need types if
> you want to use functions.

really....

create table mytype_t (a int, b int);

create function mytype_func(t mytype_t) returns int as
$$
   select ($1).a + ($1).b;
$$ language sql;

select mytype_func((10, 10)::mytype_t);

  mytype_func
-------------
           20
(1 row)

A table is a record type (backend/util/adt/rowtypes.c) as is a 
composite.  One difference is pg_class.relkind is 'r' for relation vs. 
'c' for composite.

-- 
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/