From: Tom Lane <tgl@sss.pgh.pa.us>
To: George Pavlov <gpavlov@mynewplace.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: DISTINCT with NULLs and INT fields
Date: Wed, 28 Dec 2005 15:46:29 -0500
Message-ID: <21699.1135802789@sss.pgh.pa.us> (raw)
In-Reply-To: <CCB89282FCE1024EA3DCE687A96A5164039EC5AD@ehost010-6.exch010.intermedia.net>
References: <CCB89282FCE1024EA3DCE687A96A5164039EC5AD@ehost010-6.exch010.intermedia.net>
"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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, gpavlov@mynewplace.com
Subject: Re: DISTINCT with NULLs and INT fields
In-Reply-To: <21699.1135802789@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox