Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fnli4-0003xT-Ms for pgsql-docs@arkaria.postgresql.org; Thu, 09 Aug 2018 14:14:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fnli2-0002R7-Hi for pgsql-docs@arkaria.postgresql.org; Thu, 09 Aug 2018 14:14:38 +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 1fnli2-0002Qt-8a for pgsql-docs@lists.postgresql.org; Thu, 09 Aug 2018 14:14:38 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fnlhz-0002lu-JC for pgsql-docs@lists.postgresql.org; Thu, 09 Aug 2018 14:14:37 +0000 Received: from bruce by momjian.us with local (Exim 4.84_2) (envelope-from ) id 1fnlhx-0003nV-GF; Thu, 09 Aug 2018 10:14:33 -0400 Date: Thu, 9 Aug 2018 10:14:33 -0400 From: Bruce Momjian To: Morgan Owens Cc: Nick Farmer , pgsql-docs@lists.postgresql.org Subject: Re: Parameter types are inferred from context of first use only. Message-ID: <20180809141433.GA2876@momjian.us> References: <153233728858.1404.15268121695358514937@wrigleys.postgresql.org> <20180808172444.GC2611@momjian.us> <424fb120-8761-89e3-b538-fcc78d95aae9@varteg.nz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <424fb120-8761-89e3-b538-fcc78d95aae9@varteg.nz> User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Aug 9, 2018 at 12:18:27PM +1200, Morgan Owens wrote: > 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". Great, patch applied through 9.3. I also changed "used" to "referenced": https://git.postgresql.org/pg/commitdiff/b284262e40424daa1c546ad76f365b31304d7944 -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + As you are, so once was I. As I am, so you will be. + + Ancient Roman grave inscription +