PostgreSQL Bugs

Collected from the PG bugs email list.

Bug ID16519
PG Version10.12
OSUbuntu 18.04
Opened2020-06-30 16:20:03+00
Reported byMarianne B. Wiese
StatusNew

Body of first available message related to this bug follows.

The following bug has been logged on the website:

Bug reference:      16519
Logged by:          Marianne B. Wiese
Email address:      (redacted)
PostgreSQL version: 10.12
Operating system:   Ubuntu 18.04
Description:        

The documentation says: 
This command sets the current user identifier of the current SQL session to
be role_name. The role name can be written as either an identifier or a
string literal. After SET ROLE, permissions checking for SQL commands is
carried out as though the named role were the one that had logged in
originally.

However, the loop in below function gives me an error:
[22023] ERROR: role "inuser" does not exist Where: SQL statement "SET
SESSION ROLE TO InUser" PL/pgSQL function change_user(name) line 8 at SQL
statement.

I can only make it work with string literals, as in the commented out
section.

CREATE OR REPLACE FUNCTION public.change_user(InUser name) RETURNS void AS
$$
    DECLARE
    r RECORD;
    BEGIN
        FOR r IN SELECT role FROM public.editors
            LOOP
                IF ( InUser = r.role ) THEN
                    SET SESSION ROLE TO InUser;
                end if;
            END LOOP;
/*        IF ( InUser = 'mbw@geus.dk' ) THEN
            SET SESSION ROLE TO 'mbw@geus.dk';
        ELSEIF ( InUser = 'joth@geus.dk') THEN
            SET SESSION ROLE TO 'joth@geus.dk';
        ELSE raise invalid_role_specification using message = 'authenticator
can not be || ' + InUser;
        END IF;
*/
    END
$$ LANGUAGE plpgsql;

Messages

DateAuthorSubject
2020-06-30 16:20:03+00PG Bug reporting formBUG #16519: SET SESSION ROLE in plpgsql requires string literal.
2020-06-30 16:39:03+00"David G(dot) Johnston"Re: BUG #16519: SET SESSION ROLE in plpgsql requires string literal.
2020-06-30 17:18:57+00Tom LaneRe: BUG #16519: SET SESSION ROLE in plpgsql requires string literal.
2020-06-30 17:50:18+00"David G(dot) Johnston"Re: BUG #16519: SET SESSION ROLE in plpgsql requires string literal.
2020-07-01 09:26:00+00"Marianne B(dot) Wiese"Re: BUG #16519: SET SESSION ROLE in plpgsql requires string literal.