Re: [SQL] Problems with NEW.* in triggers

2003-11-08 Thread Jamie Lawrence
On Tue, 04 Nov 2003, Tom Lane wrote: > Jamie Lawrence <[EMAIL PROTECTED]> writes: > > I don't understand why moddate isn't getting set to now() in the above. > > Josh fingered the problem there --- you need a BEFORE trigger if you > want to affect the data that will be stored. I had missed that

Re: [SQL] Problems with NEW.* in triggers

2003-11-04 Thread Tom Lane
Jamie Lawrence <[EMAIL PROTECTED]> writes: > I don't understand why moddate isn't getting set to now() in the above. Josh fingered the problem there --- you need a BEFORE trigger if you want to affect the data that will be stored. I had missed that little mistake :-( rega

Re: [SQL] Problems with NEW.* in triggers

2003-11-04 Thread Jamie Lawrence
On Tue, 04 Nov 2003, Tom Lane wrote: > Jamie Lawrence <[EMAIL PROTECTED]> writes: > > I had thought that if moddate isn't included in an insert or update, > > that it would be null in the NEW context, > > No, it would be whatever the value to be assigned to the column would > be, if the trigger w

Re: [SQL] Problems with NEW.* in triggers

2003-11-04 Thread Josh Berkus
Jamie, > Any thoughts on what I'm doing wrong?? Yes. If you want to modify the new data, you need to use a BEFORE trigger. AFTER triggers can't modify NEW, just read it. -- -Josh Berkus Aglio Database Solutions San Francisco ---(end of broadcast)--

Re: [SQL] Problems with NEW.* in triggers

2003-11-04 Thread Tom Lane
Jamie Lawrence <[EMAIL PROTECTED]> writes: > I had thought that if moddate isn't included in an insert or update, > that it would be null in the NEW context, No, it would be whatever the value to be assigned to the column would be, if the trigger were not present. In particular, during an UPDATE

[SQL] Problems with NEW.* in triggers

2003-11-04 Thread Jamie Lawrence
Hi folks - I'm having a problem with what looks like it should be trivial. For the function create or replace function timestamp_fn() returns opaque as ' begin NEW.moddate := coalesce(NEW.moddate, now()); return NEW; end ' language 'plpgsql'; on an after insert