我有这个代码
CREATE OR REPLACE FUNCTION test_func( str CHARACTER VARYING ) RETURNS CHARACTER VARYING
AS $$
BEGIN
str := CAST(str AS INTEGER);
IF str > 4 THEN
RETURN 'YES';
ELSE
RETURN 'NO';
END IF;
END;
$$
LANGUAGE plpgsql;
然后,当调用这个函数SELECT test_func('9')
返回错误: operator does not exist: character varying > integer
为什么会这样?为什么str
不转换为INTEGER
?