From: | valgog <valgog(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Execute |
Date: | 2008-02-08 18:07:47 |
Message-ID: | c123da57-e477-4740-b369-a2dfedcef50b@j20g2000hsi.googlegroups.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Feb 5, 9:11 am, "Дикий неадекватный кальмар"
<dima(dot)petchon(dot)(dot)(dot)(at)gmail(dot)com> wrote:
> is there a way to catch error returned by EXECUTE statement?
>
> declare stmt character varying;
> begin
> stmt=crate user||'some_name'||' with password '''||'somepassword';
> execute stmt;
>
> end;
>
> here i need to know, actually to handle some errors, like user already
> exists, or not enough privileges for creating users.
CREATE OR REPLACE FUNCTION test_exec(p_username text, p_password text)
RETURNS text AS
$BODY$declare
stmt character varying;
begin
stmt = $S$create user $S$ || p_username || $S$ with password '$S$ ||
p_password || $S$'$S$;
execute stmt;
return 'OK';
exception
when others then
raise WARNING 'Exception in % %', SQLSTATE, SQLERRM;
return SQLSTATE || ': ' || SQLERRM;
end; $BODY$
LANGUAGE 'plpgsql' VOLATILE;
select test_exec('neadekwatnzj', 'kaljmar');
select test_exec('neadekwatnzj', 'kaljmar');
select test_exec('neadekwatnzj', 'kaljmar');
From | Date | Subject | |
---|---|---|---|
Next Message | luca.ciciriello | 2008-02-08 18:33:16 | Re: hyperthreading and pqlib |
Previous Message | valgog | 2008-02-08 17:53:40 | Trouble with Mixed UTF-8 and Latin1 data |