Re: Typed tables

Lists: pgsql-hackers
From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Typed tables
Date: 2009-11-05 17:24:43
Message-ID: 1257441883.11856.15.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I'm planning to work on typed tables support. The idea is that you
create a table out of a composite type (as opposed to the other way
around, which is currently done automatically).

CREATE TYPE persons_type AS (name text, bdate date);

CREATE TABLE persons OF persons_type;

Or the fancy version:

CREATE TABLE persons OF persons_type ( PRIMARY KEY (name) );

This is useful in conjunction with PL/Proxy and similar RPC-type setups.
On the frontend/proxy instances you only create the type, and the
backend instances you create the storage for the type, and the database
system would give you a little support keeping them in sync. Think
interface and implementation.

We have all the necessary bits available in the PostgreSQL system
already; they just need to be wired together a little differently for
this feature. The CREATE TABLE / OF command would use some parts of the
LIKE and/or INHERITS logic to make a copy of the composite type's
structure, and then we'd probably need a new column in pg_class to store
the relationship of the table to its type.

One thing I'm not sure of is whether to keep the implicit row type in
that case. That is, would the above command sequence still create a
"persons" type? We could keep that so as to preserve the property "a
table always has a row type of the same name", or we could skip it in
that case, so if you create a typed table in this sense, you need to use
the type that you created yourself beforehand.

Thoughts?


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2009-11-05 17:38:52
Message-ID: 24814.1257442732@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> One thing I'm not sure of is whether to keep the implicit row type in
> that case. That is, would the above command sequence still create a
> "persons" type?

Are you intending that the table and the original composite type are
independent, or are still tied together --- ie, does ALTER TABLE ADD
COLUMN or similar affect the composite type?

If not, you *must* have a rowtype that is associated with the table.

regards, tom lane


From: James Pye <lists(at)jwp(dot)name>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2009-11-05 18:41:39
Message-ID: A9FD974D-CA9A-45F1-9195-531B3D472488@jwp.name
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Nov 5, 2009, at 10:24 AM, Peter Eisentraut wrote:
> One thing I'm not sure of is whether to keep the implicit row type in
> that case. That is, would the above command sequence still create a
> "persons" type? We could keep that so as to preserve the property "a
> table always has a row type of the same name"

+1 for keeping it.

> Thoughts?

Any plans to allow the specification of multiple types to define the
table?

"CREATE TABLE employee OF employee_data_type, persons_data_type;"


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2009-11-05 20:47:51
Message-ID: 1257454071.11856.22.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On tor, 2009-11-05 at 12:38 -0500, Tom Lane wrote:
> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> > One thing I'm not sure of is whether to keep the implicit row type in
> > that case. That is, would the above command sequence still create a
> > "persons" type?
>
> Are you intending that the table and the original composite type are
> independent, or are still tied together --- ie, does ALTER TABLE ADD
> COLUMN or similar affect the composite type?

They need to stay tied together. But it's to be determined whether
ALTER TABLE ADD COLUMN would work on those tables or whether there would
be some kind of ALTER TYPE.


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: James Pye <lists(at)jwp(dot)name>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2009-11-05 20:50:27
Message-ID: 1257454227.11856.25.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On tor, 2009-11-05 at 11:41 -0700, James Pye wrote:
> Any plans to allow the specification of multiple types to define the
> table?
>
> "CREATE TABLE employee OF employee_data_type, persons_data_type;"

Not really, but it does open up interesting possibilities, if we just
allow composite types to participate in inheritance relationships.
Think abstract base class. That's pretty much the idea. Come to think
of it, that's how the SQL standard defined inheritance. Sounds
interesting. And might actually be simpler to implement.


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2009-11-05 21:55:43
Message-ID: b42b73150911051355p12747d17hb4c75476c97adfe1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Nov 5, 2009 at 12:24 PM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> I'm planning to work on typed tables support.  The idea is that you
> create a table out of a composite type (as opposed to the other way
> around, which is currently done automatically).
>
> CREATE TYPE persons_type AS (name text, bdate date);
>
> CREATE TABLE persons OF persons_type;
>
> Or the fancy version:
>
> CREATE TABLE persons OF persons_type ( PRIMARY KEY (name) );

I use composite types (via tables) all the time but I never use
'create type as'...because by doing so you lose the ability to alter
the type with 'alter table'.

Am I correct that I could use your idea to make this possible (albeit
quite ugly) by:

create type foo(a text, b text);
create table foo of foo;
alter table foo add column c text;
drop table foo; -- does this drop the type as well??

merlin


From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2009-11-05 23:31:33
Message-ID: 4AF36055.1040701@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Merlin Moncure wrote:
> On Thu, Nov 5, 2009 at 12:24 PM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
>> I'm planning to work on typed tables support. The idea is that you
>> create a table out of a composite type (as opposed to the other way
>> around, which is currently done automatically).
>>
>> CREATE TYPE persons_type AS (name text, bdate date);
>>
>> CREATE TABLE persons OF persons_type;
>>
>> Or the fancy version:
>>
>> CREATE TABLE persons OF persons_type ( PRIMARY KEY (name) );
>
> I use composite types (via tables) all the time but I never use
> 'create type as'...because by doing so you lose the ability to alter
> the type with 'alter table'.
>
> Am I correct that I could use your idea to make this possible (albeit
> quite ugly) by:
>
> create type foo(a text, b text);
> create table foo of foo;
> alter table foo add column c text;
> drop table foo; -- does this drop the type as well??

That seems weird. Seems we should forbid that, and have an ALTER TYPE
command instead. I guess that means that we have to somehow memorize
that the type and the table are distinct. Also, if you create a type and
a table from it, pg_dump still needs to dump the CREATE TYPE command,
not just CREATE TABLE.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com


From: Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: James Pye <lists(at)jwp(dot)name>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2009-11-06 00:19:35
Message-ID: 20091106091935.98DA.52131E4D@oss.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:

> On tor, 2009-11-05 at 11:41 -0700, James Pye wrote:
> > "CREATE TABLE employee OF employee_data_type, persons_data_type;"
>
> Not really, but it does open up interesting possibilities, if we just
> allow composite types to participate in inheritance relationships.
> Think abstract base class. That's pretty much the idea. Come to think
> of it, that's how the SQL standard defined inheritance. Sounds
> interesting. And might actually be simpler to implement.

Do you want to tightly bind the table with the underlying type?
In other words, do you think "copying column definitions" is not enough?

Like:
CREATE TABLE employee (LIKE employee_data_type, LIKE persons_data_type);
or
CREATE TABLE employee () INHERITS (employee_data_type, persons_data_type);

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center


From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2009-11-08 21:17:47
Message-ID: 1257715067.5363.16.camel@ebony
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 2009-11-05 at 19:24 +0200, Peter Eisentraut wrote:

> This is useful in conjunction with PL/Proxy and similar RPC-type
> setups. On the frontend/proxy instances you only create the type, and
> the backend instances you create the storage for the type, and the
> database system would give you a little support keeping them in sync.
> Think interface and implementation.

Not sure I see why this is good. Why is issuing CREATE TYPE so much
easier than using CREATE TABLE? Is it worth the extra syntax and code to
support it? Can we do anything additional as a result of this? Is this
required by the standard or are we going past the standard?

--
Simon Riggs www.2ndQuadrant.com


From: Tatsuo Ishii <ishii(at)postgresql(dot)org>
To: simon(at)2ndQuadrant(dot)com
Cc: peter_e(at)gmx(dot)net, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2009-11-09 02:42:09
Message-ID: 20091109.114209.21908966.t-ishii@sraoss.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> > This is useful in conjunction with PL/Proxy and similar RPC-type
> > setups. On the frontend/proxy instances you only create the type, and
> > the backend instances you create the storage for the type, and the
> > database system would give you a little support keeping them in sync.
> > Think interface and implementation.
>
> Not sure I see why this is good. Why is issuing CREATE TYPE so much
> easier than using CREATE TABLE? Is it worth the extra syntax and code to
> support it? Can we do anything additional as a result of this? Is this
> required by the standard or are we going past the standard?

+1. I'd like to hear from Peter why this is neccessary in the first
place.
--
Tatsuo Ishii
SRA OSS, Inc. Japan


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Simon Riggs <simon(at)2ndQuadrant(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2009-11-09 10:15:31
Message-ID: 1257761731.12918.7.camel@fsopti579.F-Secure.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, 2009-11-08 at 21:17 +0000, Simon Riggs wrote:
> Not sure I see why this is good. Why is issuing CREATE TYPE so much
> easier than using CREATE TABLE? Is it worth the extra syntax and code to
> support it? Can we do anything additional as a result of this?

These are tools to improve database design in particular situations.
Nobody really *needs* this, but then again, you don't really need CREATE
TYPE for composite types in the first place. Using CREATE TABLE instead
of CREATE TYPE creates a bunch of extra things you don't need. For
example, files are created, VACUUM and ANALYZE have to keep checking the
table, backup tools think they have to back up the table, and you have
to check that no one actually inserts anything into the table.

> Is this required by the standard or are we going past the standard?

This is part of the SQL standard.


From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2009-11-09 23:37:11
Message-ID: 1257809831.5363.222.camel@ebony
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, 2009-11-09 at 12:15 +0200, Peter Eisentraut wrote:

> > Is this required by the standard or are we going past the standard?
>
> This is part of the SQL standard.

+1

--
Simon Riggs www.2ndQuadrant.com


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2010-01-10 22:34:25
Message-ID: 1263162865.25062.2.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On tor, 2009-11-05 at 19:24 +0200, Peter Eisentraut wrote:
> I'm planning to work on typed tables support. The idea is that you
> create a table out of a composite type (as opposed to the other way
> around, which is currently done automatically).
>
> CREATE TYPE persons_type AS (name text, bdate date);
>
> CREATE TABLE persons OF persons_type;
>
> Or the fancy version:
>
> CREATE TABLE persons OF persons_type ( PRIMARY KEY (name) );

And here is the first patch for that. The feature is complete as far as
I had wanted it. I would like to add ALTER TYPE support, but that can
come as a separate patch.

Attachment Content-Type Size
typed-tables.patch text/x-patch 44.0 KB

From: Josh Berkus <josh(at)agliodbs(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-10 23:27:53
Message-ID: 4B4A6279.3020501@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 1/10/10 2:34 PM, Peter Eisentraut wrote:
> On tor, 2009-11-05 at 19:24 +0200, Peter Eisentraut wrote:
>> I'm planning to work on typed tables support. The idea is that you
>> create a table out of a composite type (as opposed to the other way
>> around, which is currently done automatically).

Nice. Can we come up with a better name for the feature, though?
"Composite Type Tables"? "Type-Table Inheritance"?

--Josh Berkus


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2010-01-11 07:00:02
Message-ID: 1263193202.4609.2.camel@fsopti579.F-Secure.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On sön, 2010-01-10 at 15:27 -0800, Josh Berkus wrote:
> On 1/10/10 2:34 PM, Peter Eisentraut wrote:
> > On tor, 2009-11-05 at 19:24 +0200, Peter Eisentraut wrote:
> >> I'm planning to work on typed tables support. The idea is that you
> >> create a table out of a composite type (as opposed to the other way
> >> around, which is currently done automatically).
>
> Nice. Can we come up with a better name for the feature, though?
> "Composite Type Tables"? "Type-Table Inheritance"?

"Typed tables" is the official SQL standard name for the feature, and
it's also used in DB2 documentation. So I kind of would prefer to keep
it.


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2010-01-11 14:00:09
Message-ID: b42b73151001110600x436a0492uc32904d740424083@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Nov 9, 2009 at 5:15 AM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> On Sun, 2009-11-08 at 21:17 +0000, Simon Riggs wrote:
>> Not sure I see why this is good. Why is issuing CREATE TYPE so much
>> easier than using CREATE TABLE? Is it worth the extra syntax and code to
>> support it? Can we do anything additional as a result of this?
>
> These are tools to improve database design in particular situations.
> Nobody really *needs* this, but then again, you don't really need CREATE
> TYPE for composite types in the first place.  Using CREATE TABLE instead
> of CREATE TYPE creates a bunch of extra things you don't need.  For
> example, files are created, VACUUM and ANALYZE have to keep checking the
> table, backup tools think they have to back up the table, and you have
> to check that no one actually inserts anything into the table.

you also get the ability to alter the type though, which at present
outweighs the disadvantages in most cases (IMO).

I happen to be a fan of your proposal...mainly because it highlights
the highly under-appreciated composite type handling of the database.
I especially am excited about getting 'ALTER TYPE' in the future :-).
Do you think that we will ever able to apply constraints to composite
type that will be enforced on a cast?

merlin


From: Josh Berkus <josh(at)agliodbs(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-11 18:49:55
Message-ID: 4B4B72D3.1040407@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter,

> "Typed tables" is the official SQL standard name for the feature, and
> it's also used in DB2 documentation. So I kind of would prefer to keep
> it.

Sorry, I missed the SQL standard part in the thread. Ignore the noise.

Oh, and BTW, +1 on accepting this, pending patch quality and all that.

--Josh Berkus


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-11 20:02:03
Message-ID: 4B4B83BB.3060307@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut wrote:
> On tor, 2009-11-05 at 19:24 +0200, Peter Eisentraut wrote:
>> I'm planning to work on typed tables support. The idea is that you
>> create a table out of a composite type (as opposed to the other way
>> around, which is currently done automatically).
>>
>> CREATE TYPE persons_type AS (name text, bdate date);
>>
>> CREATE TABLE persons OF persons_type;
>>
>> Or the fancy version:
>>
>> CREATE TABLE persons OF persons_type ( PRIMARY KEY (name) );
>
> And here is the first patch for that. The feature is complete as far as
> I had wanted it. I would like to add ALTER TYPE support, but that can
> come as a separate patch.

+1

ISTM that the ultimate would be a 'create table (...._) without storage'
(or some'm) and make 'create type' an alternate syntax for SQL
conformance. For various reasons, we've internally adopted using create
table for all composites and use a c-like naming convenstion of
appending _t to such beasts.

I'll just throw a little meat into the pack wolves....constraints....?

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


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2010-01-11 22:16:47
Message-ID: 1263248207.26354.3.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On mån, 2010-01-11 at 15:02 -0500, Andrew Chernow wrote:
> ISTM that the ultimate would be a 'create table (...._) without storage'
> (or some'm) and make 'create type' an alternate syntax for SQL
> conformance.

I don't really understand the purpose of that.

> For various reasons, we've internally adopted using create
> table for all composites and use a c-like naming convenstion of
> appending _t to such beasts.

Yes, I have a similar convention.


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 00:27:58
Message-ID: 4B4BC20E.5010005@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut wrote:
> On mån, 2010-01-11 at 15:02 -0500, Andrew Chernow wrote:
>> ISTM that the ultimate would be a 'create table (...._) without storage'
>> (or some'm) and make 'create type' an alternate syntax for SQL
>> conformance.
>
> I don't really understand the purpose of that.
>

What is the point of CREATE TYPE name AS () syntax? Why would one use create
type when there is create table? Does it provide additional functionality I am
unaware of or does it exist for comformance reasons?

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


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2010-01-12 09:28:41
Message-ID: 1263288521.14170.1.camel@fsopti579.F-Secure.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On mån, 2010-01-11 at 19:27 -0500, Andrew Chernow wrote:
> Peter Eisentraut wrote:
> > On mån, 2010-01-11 at 15:02 -0500, Andrew Chernow wrote:
> >> ISTM that the ultimate would be a 'create table (...._) without storage'
> >> (or some'm) and make 'create type' an alternate syntax for SQL
> >> conformance.
> >
> > I don't really understand the purpose of that.
> >
>
> What is the point of CREATE TYPE name AS () syntax? Why would one use create
> type when there is create table? Does it provide additional functionality I am
> unaware of or does it exist for comformance reasons?

Well, that is a very deep question. ;-) I suppose a concise answer
would be that types are for passing data around between functions, and
tables are for storing data on disk.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Andrew Chernow <ac(at)esilo(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2010-01-12 09:34:54
Message-ID: 162867791001120134g2e9cd3cxf6de55e1b51fa545@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2010/1/12 Peter Eisentraut <peter_e(at)gmx(dot)net>:
> On mån, 2010-01-11 at 19:27 -0500, Andrew Chernow wrote:
>> Peter Eisentraut wrote:
>> > On mån, 2010-01-11 at 15:02 -0500, Andrew Chernow wrote:
>> >> ISTM that the ultimate would be a 'create table (...._) without storage'
>> >> (or some'm) and make 'create type' an alternate syntax for SQL
>> >> conformance.
>> >
>> > I don't really understand the purpose of that.
>> >
>>
>> What is the point of CREATE TYPE name AS () syntax?  Why would one use create
>> type when there is create table?  Does it provide additional functionality I am
>> unaware of or does it exist for comformance reasons?
>
> Well, that is a very deep question. ;-)  I suppose a concise answer
> would be that types are for passing data around between functions, and
> tables are for storing data on disk.

it should help only for "small" tables. It's looks well, but it can be
very slow and very memory expensive for bigger tables. I thing, we
need some QUERY->cursor translation mechanism. Memory based solution
(with arrays) is better than nothing, but it cannot be for all.

Pavel

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


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 13:05:01
Message-ID: 4B4C737D.2080404@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut wrote:
> On mån, 2010-01-11 at 19:27 -0500, Andrew Chernow wrote:
>> Peter Eisentraut wrote:
>>> On mån, 2010-01-11 at 15:02 -0500, Andrew Chernow wrote:
>>>> ISTM that the ultimate would be a 'create table (...._) without storage'
>>>> (or some'm) and make 'create type' an alternate syntax for SQL
>>>> conformance.
>>> I don't really understand the purpose of that.
>>>
>> What is the point of CREATE TYPE name AS () syntax? Why would one use create
>> type when there is create table? Does it provide additional functionality I am
>> unaware of or does it exist for comformance reasons?
>
> Well, that is a very deep question. ;-) I suppose a concise answer
> would be that types are for passing data around between functions, and
> tables are for storing data on disk.
>
>

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.

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


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2010-01-12 13:53:51
Message-ID: 1263304431.14170.6.camel@fsopti579.F-Secure.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

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.


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Andrew Chernow <ac(at)esilo(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2010-01-12 14:00:39
Message-ID: 4B4C8087.8010202@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
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.
>
>
>

What is the point of this discussion? We're not going to remove the
facility for composite types, regardless of whether or not some people
regard them as unnecessary. And "a name that better suits the task" is
not to be sneered at anyway.

cheers

andrew


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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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/


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2010-01-12 14:43:53
Message-ID: 4B4C8AA9.5030700@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>
> What is the point of this discussion? We're not going to remove the
> facility for composite types, regardless of whether or not some people
> regard them as unnecessary. And "a name that better suits the task" is
> not to be sneered at anyway.
>

I never asked for anything to be removed nor do I sneer :) Honestly, I
was only trying to understand why it existed.

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


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Andrew Chernow <ac(at)esilo(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2010-01-12 14:54:24
Message-ID: b42b73151001120654k5d6f8bcci7a3c3a95cdb65524@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jan 12, 2010 at 9:00 AM, Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:
> What is the point of this discussion? We're not going to remove the facility
> for composite types, regardless of whether or not some people regard them as
> unnecessary. And "a name that better suits the task" is not to be sneered at
> anyway.

nobody is arguing to remove the create type syntax. I suppose in
hindsight more thought might have been given to the overlap w/create
table. Also you have to admit that having both 'create type' and
'create type as' which do completely different things is pretty
awkward. in addition, we have 'create table' which gives us three
different methods of creating types, each with their own nuance and
advantages. please understand, I'm not griping: the postgresql type
system is wonderful...there's nothing else quite like it out there.

The questions I am posing are this:
*) should 'create type as' get an 'alter'? ( I think most would think so)
*) if so, how do you distinguish between the composite and non
composite version? How would this command look?
*) should we be able to define check constraints on composite types
(presumably, enforced on a cast)?
*) should 'create type as' should be walled off with 'create table'
handling most cases of type creation? (previously would have said yes,
but with typed table enhancement, probably not)

merlin

merlin


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Andrew Chernow <ac(at)esilo(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2010-01-12 15:54:57
Message-ID: 1263311697.16658.2.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On tis, 2010-01-12 at 09:54 -0500, Merlin Moncure wrote:
> *) should 'create type as' get an 'alter'? ( I think most would think so)

Working on that right now ...

> *) if so, how do you distinguish between the composite and non
> composite version? How would this command look?

I'm only dealing with the composite types right now, and the syntax is
ALTER TYPE name ADD/DROP ATTRIBUTE name, per SQL standard.

> *) should we be able to define check constraints on composite types
> (presumably, enforced on a cast)?

That could be an interesting feature addition. It'd basically be the
composite-type version of domains.

> *) should 'create type as' should be walled off with 'create table'
> handling most cases of type creation? (previously would have said yes,
> but with typed table enhancement, probably not)

This might be a matter of taste, but also note that these interfaces are
prescribed by the SQL standard, so if you have them, they should do the
things the spec says.


From: Joe Conway <mail(at)joeconway(dot)com>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Typed tables
Date: 2010-01-12 17:58:42
Message-ID: 4B4CB852.8030200@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 01/12/2010 06:43 AM, Andrew Chernow wrote:
>>
>> What is the point of this discussion? We're not going to remove the
>> facility for composite types, regardless of whether or not some people
>> regard them as unnecessary. And "a name that better suits the task" is
>> not to be sneered at anyway.
>>
>
> I never asked for anything to be removed nor do I sneer :) Honestly, I
> was only trying to understand why it existed.

It exists because once upon a time when SRFs were first created, and you
were using a function returning SETOF RECORD, you would either have to
enumerate every column definition in your query, or create a "dummy"
table that had the right columns/types to match your return tuple.

That solution was generally viewed as grotty -- the former is a lot of
typing and clutter, and the latter creates a table with the only purpose
being to get the needed composite type created. Therefore we added the
ability to skip the table creation and just produce the needed composite
type.

HTH

Joe