Re: [GENERAL] do delete/insert instead of update if name changes

From: Teodor Cimpoesu <teo(at)digiro(dot)net>
To:
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] do delete/insert instead of update if name changes
Date: 1999-09-04 19:27:13
Message-ID: 37D17291.EA89B22D@digiro.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

amy cheng wrote:
>
> hi, all experts there,
>
> I'm studying the example in postgresql-6.5.1/src/pl/plpgsql/test.
> I do not understand why we need "do delete/insert instead of update if name
> changes". Is it ONLY for the test, or, there is some
> reason for doing that in practical use?
>
> I cut/paste part of it below.
>
iirc, slotname is the primary key, and an update on a primary key might
be a "bad thing"
- e.g. I dunno if when changing only the key field, the index is updated
automagically -
so maybe a proper INSERT statement is the right way to do it.

> amy
> ########################################
> -- ************************************************************
> -- * BEFORE UPDATE on PHone
> -- * - do delete/insert instead of update if name changes
> -- ************************************************************
> create function tg_phone_bu() returns opaque as '
> begin
> if new.slotname != old.slotname then
> delete from PHone where slotname = old.slotname;
> insert into PHone (
> slotname,
> comment,
> slotlink
> ) values (
> new.slotname,
> new.comment,
> new.slotlink
> );
> return null;
> end if;
> return new;
> end;
> ' language 'plpgsql';
>
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
>
> ************

--
CIMPOESU Teodor, Web Programmer

@ DIGICOM S.A. Bucharest, Romania
@ Internet, site development
@ teo(at)digiro(dot)net,+(401)-330.47.28

official home page ~ http://www.digiro.net/
Internet web page ~ http://internet.digiro.net/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Paul 1999-09-05 01:10:02
Previous Message Ing. Arturo de la Torre 1999-09-04 13:31:59 help with connection to Web server