![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
CREATE RULE person_email_update AS ON UPDATE TO person_email DO INSTEAD ( UPDATE email_address SET end_at = CURRENT_TIMESTAMP WHERE NEW.contact_email <> OLD.contact_email |
|
AND person_id = OLD.id AND end_at IS NULL ; INSERT INTO email_address (email_address, person_id) SELECT NEW.contact_email, OLD.id WHERE NEW.contact_email <> OLD.contact_email ; |
|
star t_at |
#3
| ||||
| ||||
|
|
On Wed, 21 Apr 2010 05:07:35 +0000, KM wrote: CREATE RULE person_email_update AS ON UPDATE TO person_email DO INSTEAD ( UPDATE email_address SET end_at = CURRENT_TIMESTAMP WHERE NEW.contact_email <> OLD.contact_email What does this condition mean, exactly? |
|
If I am not mistaken, neither of these two identifiers (NEW.contact_email, OLD.contact_email) identifies a column in the email_address table? |
|
AND person_id = OLD.id AND end_at IS NULL ; INSERT INTO email_address (email_address, person_id) SELECT NEW.contact_email, OLD.id WHERE NEW.contact_email <> OLD.contact_email ; Where are you selecting this from? |
|
The rule creates but I am not at all clear as to what should it do? I tried modifying things myself but it didn't make much sense: |
#4
| |||
| |||
|
|
The rule's first UPDATE did what I expected by setting end_at, but the new row for email_address 'two' did not appear. It's as if the rule stopped at that UPDATE and discarded the INSERT and the update of person.mtime. |
#5
| |||
| |||
|
|
From 'thin air', same as if you "SELECT 2 + 2 WHERE TRUE;" at a psql prompt. |
![]() |
| Thread Tools | |
| Display Modes | |
| |