X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3E011529A3 for ; Tue, 19 Jul 2005 12:19:12 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 55451-02 for ; Tue, 19 Jul 2005 15:19:09 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 675B452995 for ; Tue, 19 Jul 2005 12:19:08 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j6JFJ6m3024676; Tue, 19 Jul 2005 11:19:06 -0400 (EDT) To: Richard Huxton Cc: ilejn@yandex.ru, pgsql-general@postgresql.org Subject: Re: Old question - failed to find conversion function from In-reply-to: <42DD0BB4.6050108@archonet.com> References: <42DCC1E9.2060300@aeccom.com> <42DCCCCE.000006.04382@mfront8.yandex.ru> <42DCDE07.4020906@archonet.com> <42DCEFEE.000005.12199@mfront8.yandex.ru> <42DD0BB4.6050108@archonet.com> Comments: In-reply-to Richard Huxton message dated "Tue, 19 Jul 2005 15:18:28 +0100" Date: Tue, 19 Jul 2005 11:19:06 -0400 Message-ID: <24675.1121786346@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200507/773 X-Sequence-Number: 80871 Richard Huxton writes: > [* Actually, I think NULLs are typed in SQL, which means you should be > able to get type violations. ] I'm pretty sure the entire construct is illegal per a strict reading of the SQL spec --- the spec only allows NULL to appear in contexts where a datatype can be assigned to it immediately. Per spec you'd have to write this as select 1 where 5 in (select cast(null as integer)); In the spec, NULL is not a general , it's a , and those are only allowed as the immediate argument of a CAST(), the immediate column value of an INSERT or UPDATE, and one or two other very circumscribed cases. SQL99 section 6.4 is very clear about what they intend: 2) The declared type DT of a NS is determined by the context in which NS appears. NS is effectively replaced by CAST ( NS AS DT ). NOTE 70 - In every such context, NS is uniquely associated with some expression or site of declared type DT, which thereby becomes the declared type of NS. PG's ability to infer a type for a NULL constant goes well beyond what the spec allows --- but it does have limits. regards, tom lane