From: stan <stanb@panix.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Problems with using function input paramaters
Date: Sat, 31 Aug 2019 10:24:56 -0400
Message-ID: <20190831142456.GA6061@panix.com> (raw)
In-Reply-To: <20190831140510.GB23660@panix.com>
References: <20190831140510.GB23660@panix.com>
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-ex...
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: stanb@panix.com
Subject: Re: Problems with using function input paramaters
In-Reply-To: <20190831142456.GA6061@panix.com>
References: <20190831140510.GB23660@panix.com> <20190831142456.GA6061@panix.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox