do delete/insert instead of update if name changes - Mailing list pgsql-general

From amy cheng
Subject do delete/insert instead of update if name changes
Date
Msg-id 19990831160114.25350.qmail@hotmail.com
Whole thread Raw
List pgsql-general
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.

Thanks !!!!!

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

pgsql-general by date:

Previous
From: Marzullo Laurent
Date:
Subject: PostgreSQL table data structure generator...
Next
From: Mark Dalphin
Date:
Subject: How to display user-defined functions?