如何使用或正确返回PostgreSQL函数中的值?

如何使用或正确返回PostgreSQL函数中的值?,sql,postgresql,function,plpgsql,Sql,Postgresql,Function,Plpgsql,如何在父函数中使用res?不要同时指定OUT和函数返回: CREATE OR REPLACE FUNCTION data.second( a numeric, b numeric, c numeric OUT res numeric ) RETURNS numeric AS $BODY$ BEGIN res = a + b; END; $BODY$; 如果要使用函数的返回,请使用select into VAR,EXPERFORM将只执行函数,丢弃其输出: t=# CREATE OR REP

如何在父函数中使用res?

不要同时指定OUT和函数返回:

CREATE OR REPLACE FUNCTION data.second(
a numeric,
b numeric,
c numeric
OUT res numeric
)
RETURNS numeric
AS $BODY$
BEGIN
  res = a + b;
END;
$BODY$;
如果要使用函数的返回,请使用select into VAR,EXPERFORM将只执行函数,丢弃其输出:

t=# CREATE OR REPLACE FUNCTION data.second(
a numeric,
b numeric,
c numeric,
OUT res numeric
)
AS $BODY$
DECLARE
BEGIN
res = a + b;
END;
$BODY$ language plpgsql;
CREATE FUNCTION
最后:

t=# CREATE OR REPLACE FUNCTION data.first() returns text
AS $BODY$
DECLARE
res numeric;
BEGIN
SELECT data.second(5,3,4) INTO res;
IF(res > 5)THEN
  raise info 'second returned %',res;
END IF;
RETURN 'here is the return';
END;
$BODY$ language plpgsql;
CREATE FUNCTION

试着发布一些非原始代码的东西,比如对你尝试/阅读的内容的描述、你被卡住的地方、错误消息等。另外,请在将来格式化你的代码。我想要实现的基本上是;能够检查第二个函数的返回值,并根据第二个函数的结果执行条件第一个函数。我已尝试从data.second中选择*作为dat,但Im getting query并没有结果数据的目标。抱歉,没有格式化的代码在这种情况下,谷歌搜索错误消息将提供信息,请尝试从那里开始。查看执行和选择。。。并找到变量,如plpgsql手册中所述。
t=# CREATE OR REPLACE FUNCTION data.first() returns text
AS $BODY$
DECLARE
res numeric;
BEGIN
SELECT data.second(5,3,4) INTO res;
IF(res > 5)THEN
  raise info 'second returned %',res;
END IF;
RETURN 'here is the return';
END;
$BODY$ language plpgsql;
CREATE FUNCTION
t=# select * from data.first();
INFO:  second returned 8
       first
--------------------
 here is the return
(1 row)