Thread: Accessing function parameters within double quotes

Accessing function parameters within double quotes

From
"John Duffy"
Date:
Hi
 
No matter what value of parameter I call the function below with, the value of $2 is always 2 within the addition operation. Is $2 inaccessible within the double quotes? If so how do I amend the function to get it to work?
 
CREATE FUNCTION get_data(DATE, INTEGER) RETURNS SETOF data AS '
DECLARE
    row    data%ROWTYPE;
BEGIN
    FOR row IN
        SELECT * FROM data
        WHERE startdate >= $1
        AND startdate <= $1 + interval ''$2 months''   
    LOOP
        RETURN NEXT row;
    END LOOP;
END;
' LANGUAGE 'plpgsql';
 
Regards
 
John Duffy