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-21 14:58:41
Message-ID: 15501.1098370721@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-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

pgsql-hackers by date

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

pgsql-bugs by date

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

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