That helps... :)
I am guessing that since you are using an if statement, that PostgreSQL
doesn't support writing this using exceptions. (I know I have written
functions like this, trying to do an update first and if specific
exception occured I then do an insert...)
BTJ
> On Wed, 25 Jun 2003 10:40:16 +0200 (CEST)
> "Bjorn T Johansen" <btj@havleik.no> wrote:
>
>> have never written any stored proc for PostgreSQL yet, I need some
>> pointers on how to implement this...
>
> let's imagine:
>
> create table some_test (codename text, counter int4);
>
> # create or replace function addTest (text) returns int4 as '
> depesz'# declare
> depesz'# in_codename alias for $1;
> depesz'# reply int4;
> depesz'# begin
> depesz'# select counter into reply from some_test where codename =
> in_codename;
> depesz'# if found then
> depesz'# update some_test set counter = counter + 1 where codename =
> in_codename;
> depesz'# return reply + 1;
> depesz'# end if;
> depesz'# insert into some_test (codename, counter) values (in_codename,
> 1);
> depesz'# return 1;
> depesz'# end;
> depesz'# ' language 'plpgsql';
> CREATE FUNCTION
> # select addtest('depesz');
> addtest
> ---------
> 1
> (1 row)
>
> # select addtest('depesz');
> addtest
> ---------
> 2
> (1 row)
>
> # select addtest('depesz');
> addtest
> ---------
> 3
> (1 row)
>
> # select addtest('depeszx');
> addtest
> ---------
> 1
> (1 row)
>
> hope this helps.
>
> depesz
>