From: | Hubert Lubaczewski <hubert(dot)lubaczewski(at)eo(dot)pl> |
---|---|
To: | "Bjorn T Johansen" <btj(at)havleik(dot)no> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Updating an emty table? |
Date: | 2003-06-25 08:49:45 |
Message-ID: | 20030625104945.3b38bc90.hubert.lubaczewski@eo.pl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, 25 Jun 2003 10:40:16 +0200 (CEST)
"Bjorn T Johansen" <btj(at)havleik(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Sven Köhler | 2003-06-25 08:57:42 | [BUG?] table inhiritance violates primary key |
Previous Message | Jean-Christophe ARNU (JX) | 2003-06-25 08:40:35 | pg_statistic_relid_att_index |