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 1i44JS-0003W4-42 for pgsql-general@arkaria.postgresql.org; Sat, 31 Aug 2019 14:25:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i44JP-0003U9-IW for pgsql-general@arkaria.postgresql.org; Sat, 31 Aug 2019 14:25:07 +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 1i44JP-0003QR-8k for pgsql-general@lists.postgresql.org; Sat, 31 Aug 2019 14:25:07 +0000 Received: from mailbackend.panix.com ([166.84.1.89]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i44JH-0000rm-GG for pgsql-general@lists.postgresql.org; Sat, 31 Aug 2019 14:25:06 +0000 Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mailbackend.panix.com (Postfix) with ESMTP id 46LJX90d5Gz1HbS for ; Sat, 31 Aug 2019 10:24:56 -0400 (EDT) Received: by panix2.panix.com (Postfix, from userid 17622) id 46LJX86BDwz1ZVM; Sat, 31 Aug 2019 10:24:56 -0400 (EDT) Date: Sat, 31 Aug 2019 10:24:56 -0400 From: stan To: pgsql-general@lists.postgresql.org Subject: Re: Problems with using function input paramaters Message-ID: <20190831142456.GA6061@panix.com> References: <20190831140510.GB23660@panix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190831140510.GB23660@panix.com> X-Editor: gVim User-Agent: Mutt/1.12.1 (2019-06-15) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Aug 31, 2019 at 10:05:10AM -0400, stan wrote: > I have been chasing a bug for a bit now. I even wound up completely rewriting the > function, which in the end turns out to be a good thing, as it is much cleaner and > easy to read. > > I now believe that the bug is in how I am using an input parameter to the > function. Here is the function deceleration: > > CREATE FUNCTION > return_previous_month_start_and_end( > integer) > RETURNS interval_dates AS $$ > > Here is one of the places I am using it: > > > my_year := ( select > cast(extract(year from > cast(date_trunc('month', > CURRENT_DATE) - interval ' $1 > month - 1 ' day as date) > ) as integer) > ) ; > This prints the correct value BTW: > > RAISE notice 'Called with %', $1 ; > > Nay thoughts as to what I am doing wrong? > BTW, this article https://dba.stackexchange.com/questions/159424/how-to-use-function-parameters-in-dynamic-sql-with-execute seems to imply that I can use the $1 syntax in a string, but others refer to using the COALESCE functionality, but I am uncertain exactly how to use this here. -- "They that would give up essential liberty for temporary safety deserve neither liberty nor safety." -- Benjamin Franklin