Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql function: Final statement returns bigint instead of integer

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"
like image 409
Homunculus Reticulli Avatar asked May 12 '12 12:05

Homunculus Reticulli


1 Answers

After the edit you are now getting a different error. You should get this new error because you explicitly cast column 1 to int and declared it to be bigint. My guess is that your original problem was col5 or col6 in table_foo is a bigint.

like image 75
kgrittn Avatar answered Oct 23 '22 21:10

kgrittn