Re: NAB : insert into select distinct => when used on null, distinct causes loss of type knowledge - Mailing list pgsql-general
From Tom Lane
Subject Re: NAB : insert into select distinct => when used on null, distinct causes loss of type knowledge
Date
Msg-id 12269.1093383056@sss.pgh.pa.us
Whole thread Raw
In response to NAB : insert into select distinct => when used on null, distinct causes loss of type knowledge  (Frank van Vugt <ftm.van.vugt@foxi.nl>)
Responses Re: NAB : insert into select distinct => when used on null, distinct causes loss of type knowledge  (Frank van Vugt <ftm.van.vugt@foxi.nl>)
List pgsql-general
Frank van Vugt <ftm.van.vugt@foxi.nl> writes:
> So it seems distinct applied to the second column causes it to lose knowledge
> on its type.

No, because it never had any: NULL is typeless (type UNKNOWN, to the
parser).  In the straight INSERT this doesn't matter because we don't
have to resolve the type until we get up to the INSERT, and then we know
we want to insert into the value column.  But to do a DISTINCT, the
parser has to assign datatypes to all the columns (to determine the
comparison rules).  The default assumption for an UNKNOWN constant is
type TEXT.  This is chosen based on the assumption that when someone
writes
    select distinct 'foo';
they are probably expecting the system to treat 'foo' as a TEXT literal.

            regards, tom lane

pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: How is this possible? (more on deadlocks)
Next
From: "Christine Desmuke"
Date:
Subject: Gentoo for production DB server?