我是postgresql的初学者,我想在sql中创建一个过程。 我创建了一个将记录插入表中的函数,它返回id。 但是有一些问题,除了输出参数之外,我不想要任何结果。
CREATE OR REPLACE FUNCTION public."InsertVideo"
(
OUT out_scope_id integer,
IN in_youtubeidvideo varchar[],
IN in_title varchar,
IN in_rating double precision,
IN in_viewcount integer
)
RETURNS integer AS
$$
DECLARE
id INTEGER;
INSERT INTO Video
(
YoutubeIdVideo,
Title,
Rating,
ViewCount,
DataAdded,
ConvertedFlag,
SchedulingFlag
)
VALUES
(
in_youtubeidvideo,
in_title,
in_rating,
in_viewcount,
now(),
false,
false
);
SELECT id := CURRVAL(pg_get_serial_sequence('public.video','IDVideo'));
RETURN id;
$$
LANGUAGE 'sql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER;
答案 0 :(得分:0)
SQL函数不能使用变量,因此您不需要它们。将其更改为:
CREATE OR REPLACE FUNCTION public."InsertVideo" (
IN in_youtubeidvideo varchar[],
IN in_title varchar,
IN in_rating double precision,
IN in_viewcount integer
) RETURNS integer AS $$
INSERT INTO Video (
YoutubeIdVideo,
Title,
Rating,
ViewCount,
DataAdded,
ConvertedFlag,
SchedulingFlag
) VALUES (
in_youtubeidvideo,
in_title,
in_rating,
in_viewcount,
now(),
false,
false
);
SELECT CURRVAL(pg_get_serial_sequence('public.video','IDVideo'));
$$ LANGUAGE 'sql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;