Re: Create user or role from inside a function?

From: "Dan" <ml(at)mutox(dot)org>
To: "Andreas Kretschmer" <akretschmer(at)spamfence(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Create user or role from inside a function?
Date: 2006-09-01 11:52:12
Message-ID: 56553.203.143.226.132.1157111532.squirrel@secure.x32i.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

thanks!

I actually came to a similar solution after Roman's post.

Thanks all for the replies!

> Dan <ml(at)mutox(dot)org> schrieb:
>
>> Hey,
>>
>> I am running PostgreSQL 8.1.4 and I want to create a user from inside a
>> function. Is this possible in 8.1?
>>
>> Ive found quite a few references on google using EXECUTE, but this seems
>> relevant to earlier versions, not 8.1.
>>
>> I have a function like this:
>>
>> CREATE FUNCTION user_create (un varchar, uid bigint, pw varchar) RETURNS
>> VARCHAR LANGUAGE plpgsql AS '
>> BEGIN
>> EXECUTE "CREATE USER " || un || " WITH PASSWORD " || pw;
>>
>> RETURN un;
>> END
>> ';
>
> This works:
>
>
> CREATE or replace function user_create (un varchar, uid bigint, pw
> varchar) RETURNS VARCHAR AS $$
> BEGIN
> EXECUTE 'create user ' || un || ' with password ' ||
> quote_literal(pw);
> return $1;
> end;
> $$ language plpgsql;
>
>
> Andreas
> --
> Really, I'm not out to destroy Microsoft. That will just be a completely
> unintentional side effect. (Linus Torvalds)
> "If I was god, I would recompile penguin with --enable-fly." (unknow)
> Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dan 2006-09-01 11:53:46 Re: Create user or role from inside a function?
Previous Message Karsten Hilbert 2006-09-01 11:26:25 Re: Create user or role from inside a function?