Results 1 to 2 of 2
  1. #1
    Join Date
    May 2009

    Unanswered: Creating roles inside stored functions

    When I try to create a role/user inside a stored function passing a function parameter to the role/user name it is interpreted literally, how can I make the create role command recognize the value inside the variable? ex:

    CREATE OR REPLACE FUNCTION work_management.proc_createuser(p_username character varying)
    RETURNS void AS

    CREATE USER p_username

    COST 100;
    ALTER FUNCTION work_management.proc_createuser(character varying) OWNER TO root;


    if I use the function as follow :

    select work_management.proc_createuser('testuser');

    an user named 'p_username' is created.

    is there some way to work arround this?

    thanks in advance.

  2. #2
    Join Date
    Nov 2003
    Provided Answers: 8
    You will need to build up a string containing the correct statement and then use EXECUTE to run it:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts