ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine

Lists: pgsql-hackers
From: "Dmitry Koterov" <dmitry(at)koterov(dot)ru>
To: pgsql-hackers(at)postgresql(dot)org
Subject: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-04 14:53:02
Message-ID: d7df81620812040653l45d61499g4c8f45475afe4e68@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello.

I can successfully ALTER a NON-EMPTY table (ct) which ROWTYPE is used as a
column type for another table (dt):

CREATE TABLE ct (id INTEGER);
CREATE TABLE dt (id INTEGER, c ct);

INSERT INTO dt VALUES(1, '(666)');
SELECT * FROM dt;
-- (1, '(666)')

ALTER TABLE ct ADD COLUMN n INTEGER;
SELECT * FROM dt;
-- (1, '(666,)')

You see, '(666,)' means that the new field is added successfully.

But, if I declare ct as a COMPOSITE type (not a table), it is not permitted
to ALTER this type (Postgres says that there are dependensies on ct).
Why?


From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: dmitry(at)koterov(dot)ru
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-05 13:08:01
Message-ID: b42b73150812050508k26ab3580rf7ec0333be166bd7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Dec 4, 2008 at 9:53 AM, Dmitry Koterov <dmitry(at)koterov(dot)ru> wrote:
> Hello.
>
> I can successfully ALTER a NON-EMPTY table (ct) which ROWTYPE is used as a
> column type for another table (dt):
>
> CREATE TABLE ct (id INTEGER);
> CREATE TABLE dt (id INTEGER, c ct);
>
> INSERT INTO dt VALUES(1, '(666)');
> SELECT * FROM dt;
> -- (1, '(666)')
>
> ALTER TABLE ct ADD COLUMN n INTEGER;
> SELECT * FROM dt;
> -- (1, '(666,)')
>
> You see, '(666,)' means that the new field is added successfully.
>
>
> But, if I declare ct as a COMPOSITE type (not a table), it is not permitted
> to ALTER this type (Postgres says that there are dependensies on ct).
> Why?

Because of this there is no reason to ever use 'create type'....always
use 'create table'. 'alter type' can't add/remove columns anyways.

merlin


From: "Dmitry Koterov" <dmitry(at)koterov(dot)ru>
To: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-07 20:49:24
Message-ID: d7df81620812071249g348a4743l7fbb0e9818121fb6@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Could you please say, if ALTER TYPE ... ADD COLUMN is planned for a future
PostgreSQL version?

On Fri, Dec 5, 2008 at 4:08 PM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:

> On Thu, Dec 4, 2008 at 9:53 AM, Dmitry Koterov <dmitry(at)koterov(dot)ru> wrote:
> > Hello.
> >
> > I can successfully ALTER a NON-EMPTY table (ct) which ROWTYPE is used as
> a
> > column type for another table (dt):
> >
> > CREATE TABLE ct (id INTEGER);
> > CREATE TABLE dt (id INTEGER, c ct);
> >
> > INSERT INTO dt VALUES(1, '(666)');
> > SELECT * FROM dt;
> > -- (1, '(666)')
> >
> > ALTER TABLE ct ADD COLUMN n INTEGER;
> > SELECT * FROM dt;
> > -- (1, '(666,)')
> >
> > You see, '(666,)' means that the new field is added successfully.
> >
> >
> > But, if I declare ct as a COMPOSITE type (not a table), it is not
> permitted
> > to ALTER this type (Postgres says that there are dependensies on ct).
> > Why?
>
> Because of this there is no reason to ever use 'create type'....always
> use 'create table'. 'alter type' can't add/remove columns anyways.
>
> merlin
>
> --
> 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: Bruce Momjian <bruce(at)momjian(dot)us>
To: dmitry(at)koterov(dot)ru
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-08 00:57:48
Message-ID: 200812080057.mB80vm420551@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Dmitry Koterov wrote:
> Could you please say, if ALTER TYPE ... ADD COLUMN is planned for a future
> PostgreSQL version?

It is not currently on the TODO list.

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

>
>
> On Fri, Dec 5, 2008 at 4:08 PM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
>
> > On Thu, Dec 4, 2008 at 9:53 AM, Dmitry Koterov <dmitry(at)koterov(dot)ru> wrote:
> > > Hello.
> > >
> > > I can successfully ALTER a NON-EMPTY table (ct) which ROWTYPE is used as
> > a
> > > column type for another table (dt):
> > >
> > > CREATE TABLE ct (id INTEGER);
> > > CREATE TABLE dt (id INTEGER, c ct);
> > >
> > > INSERT INTO dt VALUES(1, '(666)');
> > > SELECT * FROM dt;
> > > -- (1, '(666)')
> > >
> > > ALTER TABLE ct ADD COLUMN n INTEGER;
> > > SELECT * FROM dt;
> > > -- (1, '(666,)')
> > >
> > > You see, '(666,)' means that the new field is added successfully.
> > >
> > >
> > > But, if I declare ct as a COMPOSITE type (not a table), it is not
> > permitted
> > > to ALTER this type (Postgres says that there are dependensies on ct).
> > > Why?
> >
> > Because of this there is no reason to ever use 'create type'....always
> > use 'create table'. 'alter type' can't add/remove columns anyways.
> >
> > merlin
> >
> > --
> > 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
> >

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: "Robert Haas" <robertmhaas(at)gmail(dot)com>
To: "Bruce Momjian" <bruce(at)momjian(dot)us>
Cc: dmitry(at)koterov(dot)ru, "Merlin Moncure" <mmoncure(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-08 03:17:05
Message-ID: 603c8f070812071917l130c37afw5b8caa897e901280@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Dec 7, 2008 at 7:57 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> Dmitry Koterov wrote:
>> Could you please say, if ALTER TYPE ... ADD COLUMN is planned for a future
>> PostgreSQL version?
>
> It is not currently on the TODO list.

Perhaps we could add it? It's been complained about more than once in
this space.

...Robert


From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Robert Haas" <robertmhaas(at)gmail(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, dmitry(at)koterov(dot)ru, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-08 12:53:48
Message-ID: b42b73150812080453x13276086n7a662cf04b3b4259@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Dec 7, 2008 at 10:17 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> On Sun, Dec 7, 2008 at 7:57 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
>> Dmitry Koterov wrote:
>>> Could you please say, if ALTER TYPE ... ADD COLUMN is planned for a future
>>> PostgreSQL version?
>>
>> It is not currently on the TODO list.
>
> Perhaps we could add it? It's been complained about more than once in
> this space.

Well, new features that have a perfectly acceptable and usable
workaround typically have a fairly low priority of fixing :-)

Since tables are basically types, I'm not sure what the difference is
between tables and composite types (meaning, why do we have the
composite type syntax at all?) I'm not sure if this came up during
the design discussion or not.

merlin


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, dmitry(at)koterov(dot)ru, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-08 13:01:02
Message-ID: 493D1A8E.5090606@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Merlin Moncure wrote:
> On Sun, Dec 7, 2008 at 10:17 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>
>> On Sun, Dec 7, 2008 at 7:57 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
>>
>>> Dmitry Koterov wrote:
>>>
>>>> Could you please say, if ALTER TYPE ... ADD COLUMN is planned for a future
>>>> PostgreSQL version?
>>>>
>>> It is not currently on the TODO list.
>>>
>> Perhaps we could add it? It's been complained about more than once in
>> this space.
>>
>
> Well, new features that have a perfectly acceptable and usable
> workaround typically have a fairly low priority of fixing :-)
>
> Since tables are basically types, I'm not sure what the difference is
> between tables and composite types (meaning, why do we have the
> composite type syntax at all?) I'm not sure if this came up during
> the design discussion or not.
>
>
>

Your "workaround" involves have a redundant table that you don't ever
intend to populate.

cheers

andrew


From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Andrew Dunstan" <andrew(at)dunslane(dot)net>
Cc: "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, dmitry(at)koterov(dot)ru, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-08 14:17:08
Message-ID: b42b73150812080617k567597eftfee9bd4d5c8fac94@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Dec 8, 2008 at 8:01 AM, Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:
> Merlin Moncure wrote:
>> Well, new features that have a perfectly acceptable and usable
>> workaround typically have a fairly low priority of fixing :-)
>>
>> Since tables are basically types, I'm not sure what the difference is
>> between tables and composite types (meaning, why do we have the
>> composite type syntax at all?) I'm not sure if this came up during
>> the design discussion or not.
>
> Your "workaround" involves have a redundant table that you don't ever intend
> to populate.

Redundant how? Since tables and types exist in the same namespace
(can't have table and type in the same schema with the same name), a
table is just a type with storage. If that's a big deal, remove the
insert priv...

I like to keep the table based types I use in a special schema, like
'types' anyways.

merlin


From: "Robert Haas" <robertmhaas(at)gmail(dot)com>
To: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, dmitry(at)koterov(dot)ru, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-08 14:49:00
Message-ID: 603c8f070812080649y29f8946fref9f46a7232a8489@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> Well, new features that have a perfectly acceptable and usable
> workaround typically have a fairly low priority of fixing :-)

Putting something in the TODO list doesn't make it a priority. But it
indicates that it's something that the community would like to see
fixed, if anyone is interested in doing the work. There is a lot more
consensus for this item than many that have been added to the TODO
list in the past.

...Robert


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, dmitry(at)koterov(dot)ru, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-10 11:36:23
Message-ID: 200812101136.mBABaO805042@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas wrote:
> > Well, new features that have a perfectly acceptable and usable
> > workaround typically have a fairly low priority of fixing :-)
>
> Putting something in the TODO list doesn't make it a priority. But it
> indicates that it's something that the community would like to see
> fixed, if anyone is interested in doing the work. There is a lot more
> consensus for this item than many that have been added to the TODO
> list in the past.

OK, so what should the TODO item be?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: "Robert Haas" <robertmhaas(at)gmail(dot)com>
To: "Bruce Momjian" <bruce(at)momjian(dot)us>
Cc: "Merlin Moncure" <mmoncure(at)gmail(dot)com>, dmitry(at)koterov(dot)ru, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-10 12:44:56
Message-ID: 603c8f070812100444i4bf1d416se0dccbf2c02ba724@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Allow ALTER TYPE to add, rename, change the type of, and drop columns?

...Robert

On Wed, Dec 10, 2008 at 6:36 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> Robert Haas wrote:
>> > Well, new features that have a perfectly acceptable and usable
>> > workaround typically have a fairly low priority of fixing :-)
>>
>> Putting something in the TODO list doesn't make it a priority. But it
>> indicates that it's something that the community would like to see
>> fixed, if anyone is interested in doing the work. There is a lot more
>> consensus for this item than many that have been added to the TODO
>> list in the past.
>
> OK, so what should the TODO item be?
>
> --
> Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
> EnterpriseDB http://enterprisedb.com
>
> + If your life is a hard drive, Christ can be your backup. +
>


From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Robert Haas" <robertmhaas(at)gmail(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, dmitry(at)koterov(dot)ru, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-10 12:59:42
Message-ID: b42b73150812100459s21ff5284s92e3077485111468@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>> Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
>> OK, so what should the TODO item be?
On Wed, Dec 10, 2008 at 7:44 AM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> Allow ALTER TYPE to add, rename, change the type of, and drop columns?

That's probably the consensus view. Personally, I think creating
composite types through 'create type as' was a mistake...we probably
should have gone through create table instead with some special syntax
for storage-less tables aka composite types.

Even if I'm right though, I don't think that mistake can be taken
back, so all that functionality needs to be reimplemented in create
type somehow.

merlin


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, dmitry(at)koterov(dot)ru, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-10 13:00:01
Message-ID: 200812101300.mBAD01f11814@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas wrote:
> Allow ALTER TYPE to add, rename, change the type of, and drop columns?

That seems kind of vague because my first reaction is that a type
doesn't have columns, but you are talking about composite types, right?

I have added this TODO item:

Allow ALTER TYPE on composite types to perform operations similar to
ALTER TABLE

* http://archives.postgresql.org/pgsql-hackers/2008-12/msg00245.php

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

>
> ...Robert
>
> On Wed, Dec 10, 2008 at 6:36 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> > Robert Haas wrote:
> >> > Well, new features that have a perfectly acceptable and usable
> >> > workaround typically have a fairly low priority of fixing :-)
> >>
> >> Putting something in the TODO list doesn't make it a priority. But it
> >> indicates that it's something that the community would like to see
> >> fixed, if anyone is interested in doing the work. There is a lot more
> >> consensus for this item than many that have been added to the TODO
> >> list in the past.
> >
> > OK, so what should the TODO item be?
> >
> > --
> > Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
> > EnterpriseDB http://enterprisedb.com
> >
> > + If your life is a hard drive, Christ can be your backup. +
> >

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Alvaro Herrera" <alvherre(at)commandprompt(dot)com>
Cc: "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, dmitry(at)koterov(dot)ru, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-10 14:23:11
Message-ID: b42b73150812100623t54405b1eif18e4d6aab5c8c7c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Dec 10, 2008 at 9:05 AM, Alvaro Herrera
<alvherre(at)commandprompt(dot)com> wrote:
> Merlin Moncure escribió:
>> >> Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
>> >> OK, so what should the TODO item be?
>> On Wed, Dec 10, 2008 at 7:44 AM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>> > Allow ALTER TYPE to add, rename, change the type of, and drop columns?
>>
>> That's probably the consensus view. Personally, I think creating
>> composite types through 'create type as' was a mistake...we probably
>> should have gone through create table instead with some special syntax
>> for storage-less tables aka composite types.
>
> I disagree that CREATE TABLE should be (or should have been) used to
> create types. Someday we might need to expand the work we do for that
> case in a different direction than tables, and we would be stuck.

But, tables _are_ types, particularly in relational parlance. In
fact, postgresql's older, more relational terms (tuples and such) are
coming from that perspective, although I admit that's mostly
irrelevant now. I think we are more stuck now, having to re-implement
many things alter table does in 'alter type (as)???'. It's a mess.
What if we want to add check constraints to composite types?

> Also, for tables we create files, we generate statistics, we compute
> relfrozenxid, we call vacuum on, and so on and so forth. We do none of
> these things on types.

Those things are what come with 'storage' so if you are defining a
type with no storage mechanism you could possibly skip those things.

> In fact, types are not in pg_class at all.

incorrect!! composite types are in pg_class (relkind='c'). That
actually knida confirms what I'm saying, composite types were added in
a confusing overlay over the 'create type' command, which is something
completely different. create type means two completely different
things depending on a minor grammar change...gah! :-)

I still stand by by statement...create table should have allowed you
to create a composite type as we do it with create type as today...and
(perhaps) storage (relfrozenxid etc.) could be added or removed with
alter table.

merlin


From: "Robert Haas" <robertmhaas(at)gmail(dot)com>
To: "Bruce Momjian" <bruce(at)momjian(dot)us>
Cc: "Merlin Moncure" <mmoncure(at)gmail(dot)com>, dmitry(at)koterov(dot)ru, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-10 14:24:35
Message-ID: 603c8f070812100624j1858ee35o3d8498df6a288ce6@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Dec 10, 2008 at 8:00 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> Robert Haas wrote:
>> Allow ALTER TYPE to add, rename, change the type of, and drop columns?
>
> That seems kind of vague because my first reaction is that a type
> doesn't have columns, but you are talking about composite types, right?

Right.

> I have added this TODO item:
>
> Allow ALTER TYPE on composite types to perform operations similar to
> ALTER TABLE
>
> * http://archives.postgresql.org/pgsql-hackers/2008-12/msg00245.php

Sounds good.

...Robert


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, dmitry(at)koterov(dot)ru, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-10 14:37:52
Message-ID: 493FD440.5020206@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Merlin Moncure wrote:
> On Wed, Dec 10, 2008 at 9:05 AM, Alvaro Herrera
> <alvherre(at)commandprompt(dot)com> wrote:
>
>> Merlin Moncure escribió:
>>
>>>>> Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
>>>>> OK, so what should the TODO item be?
>>>>>
>>> On Wed, Dec 10, 2008 at 7:44 AM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>>>
>>>> Allow ALTER TYPE to add, rename, change the type of, and drop columns?
>>>>
>>> That's probably the consensus view. Personally, I think creating
>>> composite types through 'create type as' was a mistake...we probably
>>> should have gone through create table instead with some special syntax
>>> for storage-less tables aka composite types.
>>>
>> I disagree that CREATE TABLE should be (or should have been) used to
>> create types. Someday we might need to expand the work we do for that
>> case in a different direction than tables, and we would be stuck.
>>
>
> But, tables _are_ types, particularly in relational parlance. In
> fact, postgresql's older, more relational terms (tuples and such) are
> coming from that perspective, although I admit that's mostly
> irrelevant now. I think we are more stuck now, having to re-implement
> many things alter table does in 'alter type (as)???'. It's a mess.
> What if we want to add check constraints to composite types?
>
>
>> Also, for tables we create files, we generate statistics, we compute
>> relfrozenxid, we call vacuum on, and so on and so forth. We do none of
>> these things on types.
>>
>
> Those things are what come with 'storage' so if you are defining a
> type with no storage mechanism you could possibly skip those things.
>
>
>> In fact, types are not in pg_class at all.
>>
>
> incorrect!! composite types are in pg_class (relkind='c'). That
> actually knida confirms what I'm saying, composite types were added in
> a confusing overlay over the 'create type' command, which is something
> completely different. create type means two completely different
> things depending on a minor grammar change...gah! :-)
>
> I still stand by by statement...create table should have allowed you
> to create a composite type as we do it with create type as today...and
> (perhaps) storage (relfrozenxid etc.) could be added or removed with
> alter table.
>
>
>

This whole debate seems moot. We're not going to remove composite types
created with CREATE TYPE, so the rest is irrelevant. We don't have the
luxury of revisiting such decisions made many years ago, whether or not
you think they were good.

cheers

andrew


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, dmitry(at)koterov(dot)ru, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-10 14:39:53
Message-ID: 20081210143953.GC5503@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Merlin Moncure escribió:
> On Wed, Dec 10, 2008 at 9:05 AM, Alvaro Herrera
> <alvherre(at)commandprompt(dot)com> wrote:

> > I disagree that CREATE TABLE should be (or should have been) used to
> > create types. Someday we might need to expand the work we do for that
> > case in a different direction than tables, and we would be stuck.
>
> But, tables _are_ types, particularly in relational parlance.

Well, yeah, they are on relational. But here on Postgres, "tables are
types" is correct, but not the other way around. (And this is expressed
by "tables are in pg_class, types are on pg_type"; and tables "have" an
homonymous type.) The distinction is blurred by having composites in
pg_class too, of course. (I don't know the reason that they are. Maybe
they don't really need to. Maybe we could get away with having
pg_attribute entries with no corresponding pg_class entry.)

I'm not too sure about ALTER TYPE duplicating stuff. Perhaps they could
both be implemented by the same code underneath. Up to now, I haven't
seen much request for these features such as check constraints on
composites; perhaps that's the reason we don't have them.

> > In fact, types are not in pg_class at all.
>
> incorrect!! composite types are in pg_class (relkind='c'). That
> actually knida confirms what I'm saying, composite types were added in
> a confusing overlay over the 'create type' command, which is something
> completely different. create type means two completely different
> things depending on a minor grammar change...gah! :-)

Maybe the problem is not that they are created with CREATE TYPE, but
that they have a pg_class entry ;-)

> I still stand by by statement...create table should have allowed you
> to create a composite type as we do it with create type as today...and
> (perhaps) storage (relfrozenxid etc.) could be added or removed with
> alter table.

Well, these days we could probably have implemented this as CREATE TABLE
with a specific storage option. We didn't have that at the time.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, dmitry(at)koterov(dot)ru, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER composite type does not work, but ALTER TABLE which ROWTYPE is used as a type - works fine
Date: 2008-12-10 14:46:42
Message-ID: 493FD652.5030509@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan wrote:
>
> This whole debate seems moot. We're not going to remove composite types
> created with CREATE TYPE, so the rest is irrelevant. We don't have the
> luxury of revisiting such decisions made many years ago, whether or not
> you think they were good.
>
>

You can always fix something. It can be deprecated in favor of a
cleaner and more elagant method.

My two cents ... I never use CREATE TYPE AS, seems redundant and
limited. I use CREATE TABLE and just never insert any records.

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