Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bUWNG-0000OE-Hy for pgsql-bugs@arkaria.postgresql.org; Tue, 02 Aug 2016 09:52:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bUWNG-0005O7-52 for pgsql-bugs@arkaria.postgresql.org; Tue, 02 Aug 2016 09:52:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bUWNE-0005Lx-VV for pgsql-bugs@postgresql.org; Tue, 02 Aug 2016 09:52:33 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bUWNB-00078Q-FK for pgsql-bugs@postgresql.org; Tue, 02 Aug 2016 09:52:32 +0000 Received: from localhost ([127.0.0.1]:26591 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.84 (FreeBSD)) (envelope-from ) id 1bUWN9-000C23-3z; Tue, 02 Aug 2016 09:52:27 +0000 From: Andrew Gierth To: Jordan Gigov Cc: "David G. Johnston" , "pgsql-bugs\@postgresql.org" Subject: Re: BUG #14268: NULL parameter conversion In-Reply-To: (Jordan Gigov's message of "Tue, 2 Aug 2016 11:58:46 +0300") Message-ID: <874m73ilqd.fsf@news-spur.riddles.org.uk> References: <20160728133007.1423.60398@wrigleys.postgresql.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (berkeley-unix) Date: Tue, 02 Aug 2016 10:52:26 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -3.1 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org >>>>> "Jordan" =3D=3D Jordan Gigov writes: Jordan> While I don't plan on spending 180=E2=82=AC for the active ISO 9075 Jordan> specifications, I did find a working draft of 9075-2 where Jordan> under section 6.13 in the general rules it Jordan> says: Jordan> "If the specifies NULL, then the result of CS is Jordan> the null value and no further General Rules of this Subclause Jordan> are applied." "specifies NULL" is not the same thing as "has the null value" (see 2c). By "specifies NULL" it means that the is an which is a (which is the literal token NULL). The effect of this is that CAST(NULL AS T) works for any type T and returns the null value of that type. (The spec only allows the typeless literal NULL in contexts from which a type can be inferred for it.) Nothing about this supports the idea that an expression of _known_ type that simply happens to have the value NULL can be converted to some other type. For example, a which happens to have the null value satisfies general rule 2c, but in order to get that far it must first satisfy all of the syntax rules, including syntax rule 6 which specifies which data types are convertible. What this means is that if x is some value (column, parameter, whatever) which happens to be null (and its type is known, since in the spec the type of all value expressions are known), then CAST(x AS T) is valid and returns the null value of type T if and only if the type of x is convertible to T. More to the point, where the type of parameter x is both known and not assignable to the column C, then the statement insert into T(C) values (x); needs to generate an error _before the value of x is known_. Note also that in pg it is legal to pass parameters of "unknown" type such that their actual expected type is deduced from context; if one sends a Parse for insert into T(C) values ($1); without specifying a known type oid for $1, then it will be deduced as being of the type of T.C, and if the passed value is in fact the null value then no conversion error will occur. --=20 Andrew (irc:RhodiumToad) --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs