How to execute 'set session role' from plpgsql function? - Mailing list pgsql-general

From Олег Василенко
Subject How to execute 'set session role' from plpgsql function?
Date
Msg-id E1KUiqP-000Ojd-00.pulp-mail-ru@f182.mail.ru
Whole thread Raw
Responses Re: How to execute 'set session role' from plpgsql function?
List pgsql-general
Hi,everybody!

I wish to have a function with code above, but compiller generate
syntactic error at the line "SET SESSION ROLE wishedrole;".

How to pass the wishedrole value to the structure?

CREATE OR REPLACE FUNCTION f_switch_role(INOUT text,INOUT boolean) AS
 $BODY$
 DECLARE
   wishedrole ALIAS FOR $1;
   resetrole ALIAS FOR $2;
 BEGIN
   if resetrole=true then
            RESET ROLE;
            RETURN;
   end if;

>>>>ERROR OCURS AT THE NEXT LINE <<<<<<
   SET SESSION ROLE wishedrole;
   RETURN;

 END;
 $BODY$
 LANGUAGE 'plpgsql' VOLATILE



pgsql-general by date:

Previous
From: "David Wilson"
Date:
Subject: Re: What's size of your PostgreSQL Database?
Next
From: Dale
Date:
Subject: Re: can't get UPDATE ... RETURNING ... INTO ... to compile successfully