1

How can create an function (Stored Procedure / Stored Function) that select all column in the table in PgAdmin? That same same like this.

CREATE OR REPLACE FUNCTION GetAllUsers(IN userno integer)
  RETURNS TABLE(all column) AS
$BODY$
BEGIN 

    RETURN QUERY    
        SELECT  *
        FROM Users W 
        WHERE w.UserNo = GetAllUsers.userno;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100
  ROWS 1000;
ALTER FUNCTION GetAllUsers(integer)
  OWNER TO postgres;

1 Answer 1

3

You can use returns setof users instead of returns table (...)

You also don't need an expensive PL/pgSQL function for that. A plain SQL function is enough:

CREATE OR REPLACE FUNCTION getallusers(p_userno integer)
  RETURNS setof users
$BODY$
   SELECT *
   FROM users 
   WHERE userno = p_userno;
$BODY$
  LANGUAGE sql VOLATILE
  COST 100
  ROWS 1000;
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.