Re: Create user or role from inside a function? - Mailing list pgsql-general

From Andreas Kretschmer
Subject Re: Create user or role from inside a function?
Date
Msg-id 20060901112221.GA4559@KanotixBox
Whole thread Raw
In response to Create user or role from inside a function?  ("Dan" <ml@mutox.org>)
Responses Re: Create user or role from inside a function?  ("Dan" <ml@mutox.org>)
List pgsql-general
Dan <ml@mutox.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°

pgsql-general by date:

Previous
From: Karsten Hilbert
Date:
Subject: Re: Create user or role from inside a function?
Next
From: "Dan"
Date:
Subject: Re: Create user or role from inside a function?