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-21 14:58:41
Message-ID: 15501.1098370721@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Troels Arvin <troels(at)arvin(dot)dk> writes:
> On Wed, 20 Oct 2004 14:07:29 -0400, Tom Lane wrote:
>> Hmm. What's going on here is that the stored default expression is
>> actually of the form
>> ('TODO'::varchar)::varchar(2)

> Would it be possible to check the compatibility of a default value for
> the associated column?

I think that would introduce as many problems as it would fix. AFAICS
the only way to make such a check is to evaluate the expression and see
what happens. There are significant cases in which this is a bad idea
--- consider "default nextval('seq')". I think people would be
justifiably upset if we changed the state of their sequences just
through installing such a default.

Another issue: consider a column definition like
foo integer not null
The default (NULL) is explicitly not a legal value for the column.
But this is not wrong, nor even bad practice. The intent may be to
force users to explicitly supply a value in all cases. Suppose that
you want to force that, but you want it to be okay to explicitly supply
NULL --- then you can't use "not null", so AFAICS the only way is to
specify a default value that will fail if used. This works:

regression=# create table t1(f1 int default 'please supply a value'::text::int);
CREATE TABLE
regression=# insert into t1 default values;
ERROR: invalid input syntax for integer: "please supply a value"
regression=#

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Dennis Bjorklund 2004-10-21 17:12:06 Re: [HACKERS] BUG #1290: Default value and ALTER...TYPE
Previous Message Federico Fissore 2004-10-21 07:32:16 Re: bug 1201

Browse pgsql-hackers by date

  From Date Subject
Next Message Dennis Bjorklund 2004-10-21 15:01:52 Re: timestamp with time zone a la sql99
Previous Message Tom Lane 2004-10-21 14:29:07 Re: timestamp with time zone a la sql99