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

Re: Typed tables

From: Andrew Chernow <ac(at)esilo(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2010-01-12 14:36:33
Message-ID: 4B4C88F1.1050207@esilo.com (view raw or flat)
Thread:
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/

In response to

pgsql-hackers by date

Next:From: Tom LaneDate: 2010-01-12 14:39:50
Subject: Re: Streaming replication status
Previous:From: Peter EisentrautDate: 2010-01-12 14:35:29
Subject: Re: pg_dump sort order for functions

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