exception handling in plpgsql

From: Roberto Assis <rezende_assis(at)yahoo(dot)com(dot)br>
To: pgsql-novice(at)postgresql(dot)org
Subject: exception handling in plpgsql
Date: 2006-05-25 22:25:37
Message-ID: 20060525222537.43418.qmail@web51812.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hello folks, supose I already have an user called bob, with this function below I was expecting to see something like this:
-------------------------------------------------------------------------------
SELECT my_create_user('bob','bobpass');
ERROR: <Some string like XXXXX>:<Some text>
-------------------------------------------------------------------------------
If I try to make another user bob.
But instead the function doesn't compile.
Reading the manual it seemed that this should work.
-------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION my_create_user(text,text)
RETURNS int AS $$
DECLARE
login ALIAS FOR $1;
passwd ALIAS FOR $2;
answer int;
BEGIN
BEGIN
EXECUTE 'CREATE USER '||login||' NOCREATEUSER NOCREATEDB ENCRYPTED PASSWORD '||QUOTE_LITERAL(passwd);
EXCEPTION
WHEN OTHERS THEN RAISE EXCEPTION 'ERROR: % : %.',SQLSTATE,SQLERRM;
END;
RETURN answer;
END;
$$ LANGUAGE plpgsql;
-------------------------------------------------------------------------------



---------------------------------
Navegue com o Yahoo! Acesso Grátis, assista aos jogos do Brasil na Copa e ganhe prêmios de hora em hora.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Fuhr 2006-05-25 22:42:15 Re: exception handling in plpgsql
Previous Message operationsengineer1 2006-05-25 21:56:51 Re: SQL Question - S/B Good...