From: | "Richard Huxton" <dev(at)archonet(dot)com> |
---|---|
To: | <fabrizio(dot)ermini(at)sysdat(dot)it>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: need hint for a trigger... |
Date: | 2001-03-16 12:02:10 |
Message-ID: | 005f01c0ae10$f150fba0$1001a8c0@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
From: <fabrizio(dot)ermini(at)sysdat(dot)it>
> Hi all. I have to write a trigger and I have never did it before, so if
> there is someone who could give me a start, I will be very grateful...
>
> I have two tables that I want to keep "partially" synced, i.e.:
[snip]
> I would like that when a record gets changed in table1, the same
> changes reflect on the correspondent record in table2. Eventual
> changes made on the first 3 fields of table2 should be overwritten,
> leaving the other fields untouched.
>
> I was presuming this could be done with a trigger on UPDATE on
> table1, but I don't know how to write it... I know the first reply that I
> can expect is RTFM, but if a gentle soul has the time to write an
> example...
You presume right. A rule might prove more efficient (can't tell from your
example), but a trigger will work just fine.
Check the developer's docs at
http://www.postgresql.org/devel-corner/docs/programmer/
Also try http://techdocs.postgresql.org and look in PostgeSQL Notes for the
Automating Processes chapter - there are examples there (logging changes is
very similar to what you want).
Also see http://www.brasileiro.net/postgres for the brand new plpgsql
cookbook which has several examples already and should be growing all the
time.
Try adapting one of the examples you find, and if you have problems post the
code and table definitions back to the list.
One tip I can give is to build the function and trigger in a text-editor
then execute it with psql -f <file> - makes debugging much easier.
If you have any comments on any of the documentation, please let the
relevant author know, most of this stuff is brand new.
- Richard Huxton
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Meskes | 2001-03-16 13:02:57 | Re: embedded sql pointer to structure question |
Previous Message | Feite Brekeveld | 2001-03-16 11:58:06 | embedded sql pointer to structure question |