Search Postgresql Archives

Re: Execute

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Feb 5, 9:11 am, "Дикий неадекватный кальмар"
<dima.petchon...@xxxxxxxxx> 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');

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux