Re: [SQL] DISTINCT with NULLs and INT fields

2005-12-28 Thread Tom Lane
"George Pavlov" <[EMAIL PROTECTED]> writes: > the interesting thing here is that 4::int gets into a text > field whereas 4::text does not get into an integer field. seems to me > like there is an implicit int-to-text cast (without a symmetrical > text-to-int one) Yeah, there is. You can easily se

Re: [SQL] DISTINCT with NULLs and INT fields

2005-12-28 Thread George Pavlov
> > test=# insert into foo values (4::int,4::int); > > INSERT 0 1 > > test=# insert into foo values (4::text,4::text); > > ERROR: column "b" is of type integer but expression is of type text > > HINT: You will need to rewrite or cast the expression. > > test=# insert into foo values (cast(4 as

Re: [SQL] DISTINCT with NULLs and INT fields

2005-12-28 Thread Alvaro Herrera
George Pavlov wrote: > test=# insert into foo values (4::int,4::int); > INSERT 0 1 > test=# insert into foo values (4::text,4::text); > ERROR: column "b" is of type integer but expression is of type text > HINT: You will need to rewrite or cast the expression. > test=# insert into foo values (ca

Re: [SQL] DISTINCT with NULLs and INT fields

2005-12-28 Thread George Pavlov
> Sure, but in this example the required type of the value is clear from > immediate context (ie, the INSERT). This is one of the cases where > the SQL spec requires a bare NULL to be accepted. (BTW, 'no' and '4' > in this example are *not* values of type text; they are > untyped literals which

Re: [SQL] DISTINCT with NULLs and INT fields

2005-12-28 Thread Tom Lane
"George Pavlov" <[EMAIL PROTECTED]> writes: > indeed! but, wait, doesn't our favorite dbms do some implicit casting > too? continuing with my table foo (a varchar, b int): > test=# delete from foo; > DELETE 2 > test=# insert into foo values (4,4); > INSERT 0 1 > test=# insert into foo values ('4',

Re: [SQL] DISTINCT with NULLs and INT fields

2005-12-28 Thread George Pavlov
> "Better" is in the eye of the beholder. sorry for the value-laden term. "laxer" is more appropriate, of course! the funny thing is that had they cast the NULLs to TEXT it would have failed there too (they do not do implicit TEXT to INT). > It surprises me not at all that > Microsoft would be

Re: [SQL] DISTINCT with NULLs and INT fields

2005-12-28 Thread Tom Lane
"George Pavlov" <[EMAIL PROTECTED]> writes: > What does The SQL Standard say about this one? > insert into foo (a, b) select distinct null, null from bar; > -- ERROR: column "b" is of type integer but expression is of type text According to the SQL spec that query is illegal on its face --- the

[SQL] DISTINCT with NULLs and INT fields

2005-12-28 Thread George Pavlov
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 w