如何修改现有函数以返回表sd_users中的所有行?
CREATE OR REPLACE FUNCTION getusers()
RETURNS sd_users AS
$BODY$
DECLARE
groups sd_users;
BEGIN
SELECT * INTO groups FROM sd_users;
RETURN groups;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION getusers()
OWNER TO postgres;
调用功能代码:
SELECT getusers()
此代码仅返回第一条记录,如何使其返回所有记录?
答案 0 :(得分:3)
您正在寻找setof
。它可以是普通的SQL而不是plpgsql
create or replace function getusers()
returns setof sd_users as $body$
select * from sd_users;
$body$ language sql stable