![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a trigger that sets an expires column to last_access+expiry::interval if expires IS NULL or if the expires value isn't being set or changed. IF NEW.expires IS NULL OR NEW.expires = OLD.expires THEN NEW.expires = NEW.last_access+NEW.expiry:interval; END IF; The problem here is OLD doesn't exist on the first INSERT which throws an error. It seems PL/pgSQL doesn't have C's short-circuit booleans. a) Is there a way around this? b) is there a 'right' way to determine if a column is being changed? Paul (total PL/pgSQL newbie) |
#3
| |||
| |||
|
|
We check the value of TG_OP as in: IF TG_OP = ''UPDATE'' THEN Code that address OLD and NEW here; ELSE Code that addresses only NEW here. END IF; On Thursday 22 January 2004 08:29 am, Paul Makepeace wrote: I have a trigger that sets an expires column to last_access+expiry::interval if expires IS NULL or if the expires value isn't being set or changed. IF NEW.expires IS NULL OR NEW.expires = OLD.expires THEN NEW.expires = NEW.last_access+NEW.expiry:interval; END IF; The problem here is OLD doesn't exist on the first INSERT which throws an error. It seems PL/pgSQL doesn't have C's short-circuit booleans. a) Is there a way around this? b) is there a 'right' way to determine if a column is being changed? Paul (total PL/pgSQL newbie) |
#4
| |||
| |||
|
|
I have a trigger that sets an expires column to last_access+expiry::interval if expires IS NULL or if the expires value isn't being set or changed. IF NEW.expires IS NULL OR NEW.expires = OLD.expires THEN NEW.expires = NEW.last_access+NEW.expiry:interval; END IF; The problem here is OLD doesn't exist on the first INSERT which throws an error. It seems PL/pgSQL doesn't have C's short-circuit booleans. a) Is there a way around this? b) is there a 'right' way to determine if a column is being changed? Paul (total PL/pgSQL newbie) -- Paul Makepeace ................................ http://paulm.com/ecademy "If I had new shoes, then he wouldn't sing Halleighluha." -- http://paulm.com/toys/surrealism/ ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your message can get through to the mailing list cleanly |
![]() |
| Thread Tools | |
| Display Modes | |
| |