Re: [GENERAL] Unexpected error in grant/revoke script

2008-03-14 Thread A. Kretschmer
am  Fri, dem 14.03.2008, um 10:00:05 -0700 mailte Webb Sprague folgendes:
> 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';

Assume, $1 contains 'foobar', you create role 'foobarlogin' now. Insert
a space before 'LOGIN' -> ' LOGIN'.

Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Unexpected error in grant/revoke script

2008-03-14 Thread Tom Lane
"Webb Sprague" <[EMAIL PROTECTED]> writes:

> execute 'create role ' || $1 || 'LOGIN';

I think you're short one crucial space ...

regards, tom lane

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] Unexpected error in grant/revoke script

2008-03-14 Thread Webb Sprague
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.

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general