2

How to modify existing function to return all rows from table 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;

Invoke the function code:

  SELECT getusers()

This code returns only first record, how to make it to return all records?

1 Answer 1

3

You are looking for setof. And it can be plain SQL in instead of plpgsql

create or replace function getusers()
returns setof sd_users as $body$
    select * from sd_users;
$body$ language sql stable
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.