Unexpected error in grant/revoke script - Mailing list pgsql-general

From Webb Sprague
Subject Unexpected error in grant/revoke script
Date
Msg-id b11ea23c0803141000i15f497edj53c950f81fd2fc9f@mail.gmail.com
Whole thread Raw
Responses Re: Unexpected error in grant/revoke script  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Unexpected error in grant/revoke script  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
List pgsql-general
Hi all,

I have the following function:

create function new_student (text) returns text as $$
        declare
                wtf integer := 1;
        begin
        execute 'create schema ' || $1;
        execute 'create role ' || $1 || 'LOGIN';
        execute 'revoke all on schema public from ' || $1;
        execute 'grant select on schema public to ' || $1;
        execute 'grant all on schema ' || $1 || ' to ' || $1 || '
with grant option';
        return $1;
end;
$$ language plpgsql
;

When I run this with select new_student('foobar'), I get the following
error message

oregon=# \i new_student.sql
CREATE FUNCTION
oregon=# select new_student('foobar');
ERROR:  role "foobar" does not exist
CONTEXT:  SQL statement "revoke all on schema public from foobar"
PL/pgSQL function "new_student" line 6 at EXECUTE statement

However, I can run the following from the command line just fine:
# create role foobar login;
# revoke all on schema public from foobar;

Can anyone explain and help me fix?  TIA.

pgsql-general by date:

Previous
From: "Dave Page"
Date:
Subject: Re: postgre vs MySQL
Next
From: "Webb Sprague"
Date:
Subject: Unexpected message in grant/revoke script