dbTalk Databases Forums  

PostgreSQL Triggers referring to new / old rows

comp.databases comp.databases


Discuss PostgreSQL Triggers referring to new / old rows in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Uncle Sam
 
Posts: n/a

Default PostgreSQL Triggers referring to new / old rows - 10-28-2007 , 09:04 AM






I am using PostgreSQL server for my database project. I have two
tables in my schema A and B such that A contains records of employees
in an organization and B stores information about a two level
hierarchy - manager and employee. So B has as many rows for a manager
as there are employees who work under the manager. Each employee works
under one and only one manager.

Now manager and employee both are foreign keys referring to different
employee names (primary key) in relation A. Other relations contain
data that is decided by this hierarchy.

Now I want to create a trigger so that if an employee is promoted to
the post of a manager, the manager-employee row should be deleted from
relation B and the pertinent data in other relations should be updated
accordingly. I need the promoted employee's name to fetch this data
first. Since PostgreSQL does not supporting the "REFERENCING OLD ROW
AS..." clause, I cannot figure out how to refer to the employee that
is being promoted.

Is there any alternative to the REFERENCING... clause that will allow
me to get the employee's name and pass it as a parameter to the
function to be executed as an action of the trigger.

Thank you in advance.


Reply With Quote
  #2  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: PostgreSQL Triggers referring to new / old rows - 10-28-2007 , 09:58 AM








Uncle Sam wrote on 28.10.2007 16:04:
Quote:
Since PostgreSQL does not supporting the "REFERENCING OLD ROW
AS..." clause
It may not support the clause but you do have access to the old and new row:

http://www.postgresql.org/docs/8.2/s...l-trigger.html

Thomas


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.