Unix Technical Forum

exception handling in plpgsql

This is a discussion on exception handling in plpgsql within the pgsql Novice forums, part of the PostgreSQL category; --> Hello folks, supose I already have an user called bob, with this function below I was expecting to see ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 10:54 PM
Roberto Assis
 
Posts: n/a
Default exception handling in plpgsql

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 10:54 PM
Michael Fuhr
 
Posts: n/a
Default Re: exception handling in plpgsql

On Thu, May 25, 2006 at 10:25:37PM +0000, Roberto Assis wrote:
> 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.


What's the exact error you get? What version of PostgreSQL are you
using? SQLSTATE and SQLERRM are available only since 8.1.

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:59 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com