I am using PostgreSQL ver 8.4 and have written the following custom grouping function:
CREATE OR REPLACE FUNCTION custom_group(integer)
RETURNS TABLE (
grp INTEGER,
entry_date DATE,
col1 REAL,
col2 REAL,
col3 REAL,
col4 REAL,
col5 INTEGER,
col6 INTEGER) AS
$BODY$
SELECT ceil(rank() OVER (ORDER BY entry_date) / $1)::int as grp
,entry_date, col1, col2, col3, col4, col5, col6
FROM table_foo
ORDER BY 1;
$BODY$ LANGUAGE SQL;
When I try to import the function into using psql, I get the following error:
Final statement returns bigint instead of integer
I don't understand the error message, especially since I am expecting a RECORD (well table) type back.
What is causing the error, and how do I fix this?
[[Edit]]
I changed grp data type to BIGINT as suggested in the comments, however I got the same error. Details:
ERROR: return type mismatch in function declared to return record
DETAIL: Final statement returns integer instead of bigint at column 1.
CONTEXT: SQL function "custom_group"
ceil()returns abigintand you definedgrpasint. Try changinggrptobigintin return table definition.\df ceilcommand in psql. Wasn't the initial error messageFinal statement returns bigint instead of integerfollowed by a column number? If it was, please copy-paste the entire message. There's no reason to assume that the problem was at column 1.Final statement returns integer instead of bigint at column 1BTW, this was AFTER I had changed grp data type to BIGINT.