Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to place a trigger on a field instead of entire row

Status
Not open for further replies.

SkyHigh

Technical User
May 30, 2002
309
CA
Hi

The subject says it all, or is there any other way to implement this functionality in postgres, has anyone done it

Thanks for your help
Brenda
 
Let me explain a little bit to what I am trying to do here, I have a table with 12 columns and I want to archive a record before update when the value of a particular field in a record changes.

Any help would be appreciated.
Regards
Brenda
 
Well, the answer is no and yes. Meaning: triggers are run on tables, not rows or fields, but that is really not a problem. You can't have a change on any particular column of a row, without it affecting the table. So, just write a function that checks for the old value of the column for any row, and if the value changes, then perform your archiving for that row. Now, set a BEFORE UPDATE (or BEFORE DELETE OR UPDATE) trigger on that table to call this function. Thus, whenever any row is updated, your function will check for a new value in that column, and if there is a new value, it will perform your backup.

See:



-------------------------------------------

Big Brother: "War is Peace" -- Big Business: "Trust is Suspicion"
(
 
Thanks Rycamor, its really appreciated, I will try to write one, if stuck, then I will post it, see if you can help then.

The stuff you sent is indeed very helpful.
Thanks once again
Brenda
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top