Problems with using function input paramaters

From: stan <stanb(at)panix(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Problems with using function input paramaters
Date: 2019-08-31 14:05:10
Message-ID: 20190831140510.GB23660@panix.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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?

--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin

Responses

Browse pgsql-general by date

  From Date Subject
Next Message stan 2019-08-31 14:24:56 Re: Problems with using function input paramaters
Previous Message Francisco Olarte 2019-08-31 08:11:38 Re: SQL equivalint of #incude directive ?