Re: Using OLD on INSERT

Поиск
Список
Период
Сортировка
От Terry Lee Tucker
Тема Re: Using OLD on INSERT
Дата
Msg-id 200401220947.56292.terry@esc1.com
обсуждение исходный текст
Ответ на Re: Using OLD on INSERT  (Terry Lee Tucker <terry@esc1.com>)
Список pgsql-novice
After looking at this again, I see that my answer doesn't help you. We use the
same trigger code on INSERT OR UPDATE. According to the online docs I have:
OLD
 Data type RECORD; variable holding the old database row for UPDATE/DELETE
operations in ROW level triggers.

OLD is only available for UPDATE/DELETE. As for workarounds, I don't know of
any.

On Thursday 22 January 2004 09:26 am, Terry Lee Tucker wrote:
> 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)

--
Quote: 36
"War is an ugly thing, but not the ugliest of things. The person who
 has nothing for which he is willing to fight, nothing which is more
 important than his own personal safety, is a miserable creature and
 has no chance of being free unless made and kept so by the exertions
 of better men than himself."

 --John Stuart Mill

 Work: 1-336-372-6812
 Cell: 1-336-363-4719
email: terry@esc1.com

В списке pgsql-novice по дате отправления:

Предыдущее
От: Terry Lee Tucker
Дата:
Сообщение: Re: Using OLD on INSERT
Следующее
От: "Marcus Andree S. Magalhaes"
Дата:
Сообщение: Re: Using OLD on INSERT