I'm trying to write a function in postgreSQL 9.5 that takes a date as a parameter. My table has a column called inception_date, and I want the function to return all rows from the table where inception_date is greater than the date provided as the variable. Below is my function:
CREATE OR REPLACE FUNCTION somefunc(date) RETURNS setof table AS
$BODY$
DECLARE variable ALIAS FOR $1;
BEGIN
RETURN QUERY SELECT * FROM table WHERE inception_date > variable;
END;
$BODY$
LANGUAGE 'plpgsql';
SELECT somefunc('2014-07-02');
I haven't been able to find any info saying dates are handled differently in posgreSQL functions than other datatypes, but this function doesn't display any output, while the query
SELECT * FROM table WHERE inception_date > '2014-07-02';
returns 15 rows. Does anyone know what might be going wrong here?
SELECT somefunc('2014-07-02');andSELECT * FROM table WHERE inception_date > '2014-07-02';is not identical because the function returns the single column of therecordtype when query returns individual columns. How does you checking the result?inception_date?