我的程序:
docker build -t someimage .
我需要在Postgresql 11的另一个过程中获取输出参数vlaue。
CREATE PROCEDURE MyInsert(_sno integer, _eid integer, _sd date, _ed date, _sid integer, _status boolean)
LANGUAGE SQL
AS $BODY$
INSERT INTO app_for_leave(sno, eid, sd, ed, sid, status)
VALUES(_sno, _eid, _sd, _ed, _sid, _status);
$BODY$;
如何从另一个过程获取返回值。
答案 0 :(得分:2)
自然的事情是使用一个函数:
CREATE FUNCTION myinsert(
IN _sno integer,
IN _eid integer,
IN _sd date,
IN _ed date,
IN _sid integer,
IN _status boolean,
OUT _id bigint
) LANGUAGE sql
AS $BODY$
INSERT INTO app_for_leave(sno, eid, sd, ed, sid, status)
VALUES(_sno, _eid, _sd, _ed, _sid, _status)
RETURNING id;
$BODY$;
在PL / pgSQL代码中,您可以这样称呼它:
SELECT myinsert(1, 1, current_date, current_date, 1, FALSE)
INTO _id;
如果您坚持执行某个程序,则可以这样做:
CREATE PROCEDURE myinsert(
IN _sno integer,
IN _eid integer,
IN _sd date,
IN _ed date,
IN _sid integer,
IN _status boolean,
INOUT _id bigint
) LANGUAGE sql
AS $BODY$
INSERT INTO app_for_leave(sno, eid, sd, ed, sid, status)
VALUES(_sno, _eid, _sd, _ed, _sid, _status)
RETURNING id;
$BODY$;
并这样称呼它:
CALL myinsert(1, 1, current_date, current_date, 1, FALSE, _id);
请注意,为该过程定义一个OUT
参数是很自然的,但是PostgreSQL过程尚不支持OUT
参数。