PostgreSQL函数数值类型错误
我试图在PostgreSQL中创建一个存储过程。当我使用float时,该函数起作用,但当我尝试将float更改为numeric时,会出现错误:PostgreSQL函数数值类型错误,sql,postgresql,ddl,stored-functions,Sql,Postgresql,Ddl,Stored Functions,我试图在PostgreSQL中创建一个存储过程。当我使用float时,该函数起作用,但当我尝试将float更改为numeric时,会出现错误: ERROR: cannot change return type of existing function SQL state: 42P13 Detail: Row type defined by OUT parameters is different. Hint: Use DROP FUNCTION percent_grades(text) first
ERROR: cannot change return type of existing function
SQL state: 42P13
Detail: Row type defined by OUT parameters is different.
Hint: Use DROP FUNCTION percent_grades(text) first.
我真的不知道这意味着什么,但我不认为我需要做任何事情以外的演员改变类型
我的职能是:
CREATE OR REPLACE FUNCTION percent_grades(text)
RETURNS TABLE(grade text, percent float)
AS
$$
DECLARE percent_total float;
BEGIN
RETURN QUERY
SELECT psa_grade_name,
SUM(psa_amount) / CAST(total_cards($1) AS float) AS percent_total
FROM psa_pop_view
WHERE psa_card = $1
GROUP BY psa_grade_name
ORDER BY psa_grade_name;
END;
$$
LANGUAGE plpgsql;
我想用numeric5,4替换浮点数。create或replace语句不能更改函数的签名。如错误所述,必须首先删除函数:
DROP FUNCTION percent_grades(text);
然后用正确的签名重新创建:
CREATE OR REPLACE FUNCTION percent_grades(text)
RETURNS TABLE(grade text, percent numeric(5,4))
AS
$$
DECLARE percent_total float;
BEGIN
RETURN QUERY
SELECT psa_grade_name,
SUM(psa_amount) / CAST(total_cards($1) AS float) AS percent_total
FROM psa_pop_view
WHERE psa_card = $1
GROUP BY psa_grade_name
ORDER BY psa_grade_name;
END;
$$
LANGUAGE plpgsql;