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

From Tom Lane
Subject Re: DISTINCT with NULLs and INT fields
Date
Msg-id 21699.1135802789@sss.pgh.pa.us
Whole thread Raw
In response to Re: DISTINCT with NULLs and INT fields  ("George Pavlov" <gpavlov@mynewplace.com>)
List pgsql-sql
"George Pavlov" <gpavlov@mynewplace.com> 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','4');
> INSERT 0 1
> test=# insert into foo values ('oh','no');
> ERROR:  invalid input syntax for integer: "no"

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 we eventually resolve as varchar or int.)

The other case you mentioned is one where we are going out on a limb a
bit:
INSERT INTO foo SELECT NULL, NULL;

In this case we allow the SELECT to not force a type choice, so that the
INSERT sees the raw untyped values, but I think that this query is
probably illegal per spec --- I believe the spec requires a SELECT to
deliver well-defined data types.  Too lazy to go look up chapter and
verse at the moment.
        regards, tom lane


pgsql-sql by date:

Previous
From: "George Pavlov"
Date:
Subject: Re: DISTINCT with NULLs and INT fields
Next
From: "George Pavlov"
Date:
Subject: Re: DISTINCT with NULLs and INT fields