×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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

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

(OP)
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

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

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:

http://www.postgresql.org/idocs/index.php?sql-createtrigger.html

http://www.ca.postgresql.org/docs/aw_pgsql_book/node162.html

http://www.postgresql.org/idocs/index.php?programmer-pl.html

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

Big Brother: "War is Peace" -- Big Business: "Trust is Suspicion"
(http://www.cl.cam.ac.uk/~rja14/tcpa-faq.html)

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

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close