CREATE USER within function

From: Michal Taborsky <M(dot)Taborsky(at)sh(dot)cvut(dot)cz>
To: pgsql-general(at)postgresql(dot)org
Subject: CREATE USER within function
Date: 2003-04-07 15:16:25
Message-ID: b6s4oj$7c0$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs 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-bugs by date

  From Date Subject
Next Message Laura Moloney 2003-04-07 16:10:56 bug with dump sql to recreate view
Previous Message Robert John Shepherd 2003-04-07 14:25:38 Re: [BUGS] Rapid deteriation of performance (might be caused by tsearch?) in 7.3.2

Browse pgsql-general by date

  From Date Subject
Next Message Dennis Gearon 2003-04-07 15:18:12 Re: chron scripts and pgsql
Previous Message Tom Lane 2003-04-07 14:50:26 Re: possible time change issue - known problem?