PostgreSQL 函数数字类型错误
PostgreSQL function numeric type error
我正在尝试在 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.
我真的不知道那是什么意思,但我认为除了 CAST
之外我不需要做任何其他事情来更改 type
。
我的函数是:
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() AS float) AS percent_total
FROM psa_pop_view
WHERE psa_card =
GROUP BY psa_grade_name
ORDER BY psa_grade_name;
END;
$$
LANGUAGE plpgsql;
我想用 numeric(5, 4)
替换 float
。
a create or 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() AS float) AS percent_total
FROM psa_pop_view
WHERE psa_card =
GROUP BY psa_grade_name
ORDER BY psa_grade_name;
END;
$$
LANGUAGE plpgsql;
我正在尝试在 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.
我真的不知道那是什么意思,但我认为除了 CAST
之外我不需要做任何其他事情来更改 type
。
我的函数是:
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() AS float) AS percent_total
FROM psa_pop_view
WHERE psa_card =
GROUP BY psa_grade_name
ORDER BY psa_grade_name;
END;
$$
LANGUAGE plpgsql;
我想用 numeric(5, 4)
替换 float
。
a create or 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() AS float) AS percent_total
FROM psa_pop_view
WHERE psa_card =
GROUP BY psa_grade_name
ORDER BY psa_grade_name;
END;
$$
LANGUAGE plpgsql;