depended on table types

Lists: pgsql-hackers
From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: depended on table types
Date: 2005-03-17 22:34:22
Message-ID: 423A05EE.5060805@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Is one supposed to be able to alter the type of a table whose definition
has been used A composite in another table? Somewhat surprisingly to
me, the following test did not produce an error:

create table a( x text, y int);
create table b( z a);
insert into b values('(\'aaa\',3)');
select * from b;
alter table a add column q timestamp not null;
select * from b;

cheers

andrew


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: depended on table types
Date: 2005-03-17 22:51:25
Message-ID: 28155.1111099885@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> Is one supposed to be able to alter the type of a table whose definition
> has been used A composite in another table?

If the alter is of a kind that we can support, yes.

> Somewhat surprisingly to
> me, the following test did not produce an error:

> create table a( x text, y int);
> create table b( z a);
> insert into b values('(\'aaa\',3)');
> select * from b;
> alter table a add column q timestamp not null;
> select * from b;

This variant fails:

d=# alter table a add column qq timestamp default now() not null;
ERROR: cannot alter table "a" because column "b"."z" uses its rowtype

If you're unhappy about the "not null" part, the long and short of that
is that rowtypes don't carry along table constraints (yet), so it's
legal for b.z.q to show as null.

regards, tom lane