如何从PL / pgSQL函数返回表?

时间:2017-05-19 07:09:13

标签: plpgsql

CREATE OR REPLACE FUNCTION my_function(user_id integer) 
     RETURNS TABLE(id integer, firstname character varying, lastname character varying) 
AS $$
DECLARE
    ids INTEGER[];
BEGIN
     ids := ARRAY[1,2];
     RETURN QUERY
         SELECT users.id, users.firstname, users.lastname
         FROM public.users
         WHERE users.id = ANY(ids);
END;
$$ LANGUAGE plpgsql;


select * from my_function(1);

0 个答案:

没有答案