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

Re: BUG #1290: Default value and ALTER...TYPE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Troels Arvin" <troels(at)arvin(dot)dk>
Cc: pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #1290: Default value and ALTER...TYPE
Date: 2004-10-20 18:07:29
Message-ID: 7718.1098295649@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-hackers
"PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org> writes:
> troels=# create table lookat_feature(
> troels(#   feature_id char(4),
> troels(#   status varchar(2) default 'TODO'
> troels(# );
> CREATE TABLE
> troels=# alter table lookat_feature
> troels-#   alter column status type varchar(4);
> ALTER TABLE
> troels=# insert into lookat_feature (feature_id) values('B034');
> ERROR:  value too long for type character varying(2)

Hmm.  What's going on here is that the stored default expression is
actually of the form
	('TODO'::varchar)::varchar(2)
where you don't see the coercion to varchar(2) in \d becayuse ruleutils.c
doesn't show implicit casts.  After the ALTER COLUMN it's of the form
	(('TODO'::varchar)::varchar(2))::varchar(4)
which of course will give an error when used.

Possibly we should make ALTER COLUMN strip any implicit coercions that
appear at the top level of the default expression before it adds on the
implicit coercion to the new column datatype.  I am not sure that this
is a good idea, however; it seems like it might alter the semantics in
unexpected ways.  (The default expression could potentially come through
differently than an actually stored value of the column would do.)

The alternative would seem to be decreeing that this is not a bug.

Comments anyone?

			regards, tom lane

In response to

Responses

pgsql-hackers by date

Next:From: Rod TaylorDate: 2004-10-20 18:17:49
Subject: Re: [HACKERS] BUG #1290: Default value and ALTER...TYPE
Previous:From: Tom LaneDate: 2004-10-20 17:32:02
Subject: Re: -HEAD contrib/dblink regress failure on SPARC/Solaris 8

pgsql-bugs by date

Next:From: Rod TaylorDate: 2004-10-20 18:17:49
Subject: Re: [HACKERS] BUG #1290: Default value and ALTER...TYPE
Previous:From: PostgreSQL Bugs ListDate: 2004-10-20 17:01:37
Subject: BUG #1290: Default value and ALTER...TYPE

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