From: | Susan Cassidy <scassidy(at)stbernard(dot)com> |
---|---|
To: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Trigger for modification timestamp column |
Date: | 2010-07-07 16:43:36 |
Message-ID: | 3A51F387FE0CC74D80FA60C146987F250191AA72FE14@oc-exchange1.stbernard.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Can't you check it using something like this:
IF OLD.modified = NEW.modified THEN
NEW.modified = NOW();
END IF;
RETURN NEW;
Susan
-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Johan Andersson
Sent: Wednesday, July 07, 2010 6:49 AM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] Trigger for modification timestamp column
Hello!
I am trying to write a trigger for updating a modification column and am
having some trouble getting it to behave as I want.
The trigger should set the column to the supplied value if it is set in the
UPDATE statement and to the current timestamp [NOW()] if it is not. The
problem is that I don't know how to check if the column is set or not. I can
check the column's value for NULL but that doesn't work if I want the column
to accept NULL values (meaning "unmodified").
I would like something like:
CREATE FUNCTION update_modified()
RETURNS TRIGGER AS $$
BEGIN
IF NOT isset(NEW.modified) THEN
NEW.modified = NOW();
END IF;
RETURN NEW;
END;
$$ LANGUAGE 'plpgsql';
Does anyone know how to do this?
Thanks in advance!
/ Johan
--
View this message in context: http://old.nabble.com/Trigger-for-modification-timestamp-column-tp29096359p29096359.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2010-07-07 16:59:16 | Re: Trigger for modification timestamp column |
Previous Message | Pavel Stehule | 2010-07-07 15:54:15 | Re: Trigger for modification timestamp column |