Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fnfoE-0002r5-K9 for pgsql-docs@arkaria.postgresql.org; Thu, 09 Aug 2018 07:56:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fnfoB-0007P1-TC for pgsql-docs@arkaria.postgresql.org; Thu, 09 Aug 2018 07:56:35 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fnYf4-0003Lg-Re for pgsql-docs@lists.postgresql.org; Thu, 09 Aug 2018 00:18:42 +0000 Received: from esmtp06.digiweb.net.nz ([202.174.114.135]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fnYey-0001Cr-NO for pgsql-docs@lists.postgresql.org; Thu, 09 Aug 2018 00:18:39 +0000 Received: from localhost (localhost [127.0.0.1]) by esmtp06.digiweb.net.nz (Postfix) with ESMTP id 5CC09C01D8; Thu, 9 Aug 2018 12:18:31 +1200 (NZST) Received: from esmtp06.digiweb.net.nz ([202.174.114.135]) by localhost (dwl-chc-mscan02.digiweb.net.nz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id unjN8xzCPd-c; Thu, 9 Aug 2018 12:18:30 +1200 (NZST) Received: from smtpauth.digiweb.net.nz (smtpauth.digiweb.net.nz [202.174.115.156]) by esmtp06.digiweb.net.nz (Postfix) with ESMTPS id E78EEC021B; Thu, 9 Aug 2018 12:18:27 +1200 (NZST) Received: by smtpauth.digiweb.net.nz (Postfix, from userid 65534) id E320110006; Thu, 9 Aug 2018 12:18:27 +1200 (NZST) Received: from [192.168.1.69] (222-153-157-200-fibre.sparkbb.co.nz [222.153.157.200]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: packrat@varteg.nz) by smtpauth.digiweb.net.nz (Postfix) with ESMTPSA id BC36610000; Thu, 9 Aug 2018 12:18:27 +1200 (NZST) Subject: Re: Parameter types are inferred from context of first use only. To: Nick Farmer , pgsql-docs@lists.postgresql.org References: <153233728858.1404.15268121695358514937@wrigleys.postgresql.org> <20180808172444.GC2611@momjian.us> From: Morgan Owens Message-ID: <424fb120-8761-89e3-b538-fcc78d95aae9@varteg.nz> Date: Thu, 9 Aug 2018 12:18:27 +1200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180808172444.GC2611@momjian.us> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2018-08-09 05:24, Bruce Momjian wrote: > On Mon, Jul 23, 2018 at 09:14:48AM +0000, PG Doc comments form wrote: >> The following documentation comment has been logged on the website: >> >> Page: https://www.postgresql.org/docs/10/static/sql-prepare.html >> Description: >> >> Background can be found on the bugs list (pgsql-bug #15289). It was >> explained that when a prepared statement parameter needs to have its type >> inferred then, should the parameter be used more than once, only the first >> use is considered. (The example in that report is that the type of $1 can be >> inferred from "($1 = col) or ($1 is null)" but not from "($1 is null) or ($1 >> = col)".) >> >> The documentation as it stands says only that the parameter's type is >> inferred from the context in which it is used. The "first use only" proviso >> is not mentioned (hence "context" isn't so broad as to consist of all of the >> expressions in which the parameter appears). > > I have developed the attached patch to cover what you found. > That says it for me. The third mention of context doesn't need anything because it's referring specifically to the (single) use of $2 in the example. I have to presume the type inference happens before any structural changes that might change the meaning of "first occurrence". Nick