Re: Updating an emty table?

From: "Bjorn T Johansen" <btj(at)havleik(dot)no>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Updating an emty table?
Date: 2003-06-25 09:00:55
Message-ID: 48875.193.212.14.12.1056531655.squirrel@www.havleik.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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(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
>

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sven Köhler 2003-06-25 09:06:23 Re: [BUG?] table inhiritance violates primary key
Previous Message Sven Köhler 2003-06-25 08:57:42 [BUG?] table inhiritance violates primary key