Re: [GENERAL] do delete/insert instead of update if name changes
От | Teodor Cimpoesu |
---|---|
Тема | Re: [GENERAL] do delete/insert instead of update if name changes |
Дата | |
Msg-id | 37D17291.EA89B22D@digiro.net обсуждение исходный текст |
Ответ на | do delete/insert instead of update if name changes ("amy cheng" <amycq@hotmail.com>) |
Список | 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@digiro.net,+(401)-330.47.28 official home page ~ http://www.digiro.net/ Internet web page ~ http://internet.digiro.net/
В списке pgsql-general по дате отправления: