Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i454Q-0006cF-Jt for pgsql-general@arkaria.postgresql.org; Sat, 31 Aug 2019 15:13:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i454N-0001qt-5E for pgsql-general@arkaria.postgresql.org; Sat, 31 Aug 2019 15:13:39 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1i454M-0001oJ-S5 for pgsql-general@lists.postgresql.org; Sat, 31 Aug 2019 15:13:38 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i454J-0001Lz-Qc for pgsql-general@lists.postgresql.org; Sat, 31 Aug 2019 15:13:37 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x7VFDUgT023261; Sat, 31 Aug 2019 11:13:30 -0400 From: Tom Lane To: "David G. Johnston" cc: stan , "pgsql-generallists.postgresql.org" Subject: Re: Problems with using function input paramaters In-reply-to: References: <20190831140510.GB23660@panix.com> Comments: In-reply-to "David G. Johnston" message dated "Sat, 31 Aug 2019 07:45:25 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <23259.1567264410.1@sss.pgh.pa.us> Date: Sat, 31 Aug 2019 11:13:30 -0400 Message-ID: <23260.1567264410@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "David G. Johnston" writes: > On Sat, Aug 31, 2019 at 7:05 AM stan wrote: >> CURRENT_DATE) - interval ' $1 >> month - 1 >> ' day as date) > ($1 || ' month')::interval -- should work FWIW, I tend to prefer doing it with interval arithmetic, like this: $1 * '1 month'::interval - '1 day'::interval It's faster (not enormously so, but measurably) thanks to not having to construct and then parse a text string. To my mind it's easier to reason about, too, and a bit safer. regards, tom lane