CREATE USER from within function

From: Michal Taborsky <michal(at)taborsky(dot)cz>
To: pgsql-general(at)postgresql(dot)org
Subject: CREATE USER from within function
Date: 2003-04-09 14:43:43
Message-ID: 3E94319F.8080907@taborsky.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I am facing a problem. I am unable to call CREATE USER from within a
PL/PgSQL function. I am using Postgres 7.3.2.

The function looks like this (it is more complex in fact, but even if
stripped to this, it does not work anyway):

CREATE OR REPLACE FUNCTION
usr_createAccount(integer, name, text, text, bool, bool)
RETURNS bool AS '
BEGIN
CREATE USER $2 WITH PASSWORD $3 NOCREATEDB CREATEUSER IN GROUP "all",
"super";
RETURN true;
END;
' LANGUAGE 'plpgsql';

I keep getting this:

akcent=# select usr_createAccount(3, 'username', 'somepassword', 'cs',
true, false);
WARNING: Error occurred while executing PL/pgSQL function usr_createaccount
WARNING: line 2 at SQL statement
ERROR: parser: parse error at or near "$1" at character 14

I am a bit confused by this error, because there is no "$1" string in
this function. I tried to do a CREATE USER in transaction, because I
suspected it to be the problem, but it worked just fine. Does anyone see
something which I don't ? What am I doing wrong ?

Thanks,
Michal

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2003-04-09 14:56:14 Re: CREATE USER from within function
Previous Message scott.marlowe 2003-04-09 14:43:36 Re: Cross database reference (databases are on the same