DISTINCT with NULLs and INT fields - Mailing list pgsql-sql

From George Pavlov
Subject DISTINCT with NULLs and INT fields
Date
Msg-id CCB89282FCE1024EA3DCE687A96A5164039EC532@ehost010-6.exch010.intermedia.net
Whole thread Raw
Responses Re: DISTINCT with NULLs and INT fields  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
What does The SQL Standard say about this one?

create table foo (a varchar, b int);

insert into foo (a, b) select null, null from bar;
-- no problem

insert into foo (a, b) select distinct null, null from bar;
-- ERROR:  column "b" is of type integer but expression is of type text
-- HINT:  You will need to rewrite or cast the expression.

It seems that applying DISTINCT makes the NULL be of type TEXT... I just
tried the exact same thing in Ms. SQL Server 2005 and it works with no
errors. Looks like SQL Server makes the NULLs be INTs, but is probably
better at doing the implicit conversion from INT. Any thoughts on what
the "correct" behavior should be here?

George


pgsql-sql by date:

Previous
From: Don Croata
Date:
Subject: Re: Cursors and recursion
Next
From: Tom Lane
Date:
Subject: Re: DISTINCT with NULLs and INT fields