我有一个 Postgresql 函数,其中只有一个 SELECT 语句:
CREATE OR REPLACE FUNCTION fun_test()
RETURNS INTEGER AS $$
DECLARE size INTEGER;
BEGIN
SELECT COUNT(*) INTO size FROM tab;
RETURN size;
END;
$$ LANGUAGE plpgsql STABLE;
当我调用函数时:
SELECT fun_test()
虽然结果是正确的,但也会有警告:
WARNING: A stable or volatile function is used as if it is immutable
HINT: The function should be declared as stable or volatile in create function statement.
I found in Postgresql document that STABLE is a appropriate selection for functions whose results depend on database lookups, parameter variables (such as the current time zone), etc. http://www.postgresql.org/docs/8.2/static/sql -createfunction.html
我的问题是警告来自哪里?看来我正在做文件要求做的事情。任何帮助表示赞赏。
编辑:
我正在使用 postgresql 服务器 8.2.15
整个故事:
CREATE TABLE algo.chengb_tmp
(
userid INT,
username varchar(100)
)
CREATE OR REPLACE FUNCTION algo.chengb_fun_test()
RETURNS INTEGER AS $$
DECLARE size INTEGER;
BEGIN
SELECT COUNT(*) INTO size FROM algo.chengb_tmp;
RETURN size;
END;
$$ LANGUAGE plpgsql STABLE;
SELECT algo.chengb_fun_test()
程