CREATE FUNCTION Test_Extract_Text(tm_id1 int4, tm_subid1 int4, tm_id2 int4, tm_subid2 int4)
RETURNS Table
AS $$
BEGIN
RETURN QUERY SELECT * FROM dat_extract_text inner join dat_replace_text on dat_extract_text.Id=dat_replace_text.subid ;
END;
$$ LANGUAGE plpgsql;
ERROR: syntax error at or near "AS" LINE 3: AS $$
为什么呢?如何解决?
答案 0 :(得分:1)
您需要提供包含RETURNS TABLE
子句like described in the manual here的列定义列表:
CREATE FUNCTION Test_Extract_Text(
tm_id1 int4, tm_subid1 int4, tm_id2 int4, tm_subid2 int4)
RETURNS TABLE (col1 type1, col2 type2, ...) AS
$$
BEGIN
RETURN QUERY
SELECT *
FROM dat_extract_text e
JOIN dat_replace_text r ON e.Id = r.subid;
END
$$ LANGUAGE plpgsql;
虽然允许使用SELECT *
,但您也应在此处提供列表。否则,对其中一个表格的每次更改都会破坏该功能。