postgresql 中的调用函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4310902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-20 00:25:18 来源:igfitidea点击:
call function in postgresql
提问by Pinsickle
I made a simple function as part of my homework but for the life of me I can't figure out how to call it and test it. Can anyone tell me how?
我做了一个简单的函数作为我作业的一部分,但对于我的生活,我无法弄清楚如何调用它和测试它。谁能告诉我怎么做?
-- Procedure
CREATE OR REPLACE FUNCTION addDoctor (
a INT,
b VARCHAR (20),
c VARCHAR (20)
) RETURNS VOID
LANGUAGE plpsql
AS $BODY$
BEGIN
INSERT INTO doctor
VALUES (a,b,c);
END;
$BODY$
回答by Xavier
CREATE or REPLACE FUNCTION analyzer(character varying, character varying)
RETURNS boolean AS
$BODY$
--
begin
--
execute 'analyze '||quote_ident()||'.'||quote_ident() ;
return 1 ;
--
end ;
$BODY$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER;
回答by Yevgeniy Afanasyev
if you need to call function just to check for exceptions that can occur there go perform:
如果您需要调用函数只是为了检查可能发生的异常,请执行:
PERFORM f_foo(i);
if you need a result, go select
如果您需要结果,请选择
SELECT function_name();