On Thu, 21 Oct 2004, Tom Lane wrote:
> > 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.
The problem in the reported case was that the default value was a string
and pg infered that the default value should be a varchar(2) because that
was the column type. The problem I assume is only when the type is unknown
for pg, for values with a known type I hope that is the type that is used.
The typecast to the column type should be added on when we use the default
value and not before.
Maybe one could come up with some method to give the default value the
most general type. For a string we could give it the type text, for a
number we could give it say the smallest int type that fits it (when it is
an integer).
If one have a default value like '2' it would get the type text but that
would still work even if the column is a int column, wouldn't it?
I assume here that we must give the default value a real type. Values of
type unknown are hard to handle.
--
/Dennis Björklund