Re: [HACKERS] DEFAULT fixed

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: [HACKERS] DEFAULT fixed
Date: 1999-05-24 14:31:24
Message-ID: 199905241431.KAA21638@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> Actually, it's not as fixed as all that...
>
> create table foo1 (a char(5) default '', b int4);
> insert into foo1 (b) values (334);
> select * from foo1;
> a | b
> -----+---
> |334
> (1 row)
>
> Good, the basic case is fixed, but:
>
> create table foo2 (a char(5) default text '', b int4);
> insert into foo2 (b) values (334);
> select * from foo2;
> a| b
> -+--
> |16
> (1 row)
>
> Ooops.
>
> What you seem to have done is twiddle the handling of DEFAULT clauses
> so that the value stored for the default expression is pre-coerced to the
> column type. That's good as far as it goes, but it fails in cases where
> the stored value has to be of a different type.

Gee, I didn't know you could specify the type of the default. Look at
this:

create table kk( x char(20) default bpchar '');

This is going to bypass the coerce_type, so I think this would fail too.

> My guess is that what *really* ought to happen here is that
> transformInsertStmt should check the type of the value it's gotten from
> the default clause and apply coerce_type if necessary.

Again, in my example, it will not even get coerced.

> Unless someone can come up with a less artificial example than the one
> above, I'm inclined to leave it alone for 6.5. This is the same code
> area that will have to be redone to fix the INSERT ... SELECT problem
> I was chasing earlier today: coercion of the values produced by SELECT
> will have to wait until the tail end of transformInsertStmt, and we
> might as well make wrong-type default constants get fixed in the same
> place. So I'm not eager to write some throwaway code to patch a problem
> that no one is likely to see in practice. What's your feeling about it?

Yes, I think we will just wait on this one, and add it to our TODO list
for the next release. We still have some big items on the list.

--
Bruce Momjian | http://www.op.net/~candle
maillist(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 1999-05-24 14:31:38 Open 6.5 items
Previous Message Bruce Momjian 1999-05-24 14:24:31 Re: [HACKERS] DEFAULT fixed