Re: Trigger for modification timestamp column
От | Pavel Stehule |
---|---|
Тема | Re: Trigger for modification timestamp column |
Дата | |
Msg-id | AANLkTimtcJJStjaOkN-bCaUgKKEFv64Y18FzZSojwj8n@mail.gmail.com обсуждение исходный текст |
Ответ на | Trigger for modification timestamp column (Johan Andersson <warb@mail.com>) |
Список | pgsql-general |
2010/7/7 Johan Andersson <warb@mail.com>: > > 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? sorry - it isn't possible - you cannot do it. You need one column more for information if value is modified or not. Regards Pavel Stehule > > 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. > > > -- > Sent via pgsql-general mailing list (pgsql-general@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-general >
В списке pgsql-general по дате отправления: