Re: Help with trigger

Поиск
Список
Период
Сортировка
От Gary Chambers
Тема Re: Help with trigger
Дата
Msg-id alpine.OSX.2.01.1012271626130.303@www.clipper.local
обсуждение исходный текст
Ответ на Re: Help with trigger  (Michael Satterwhite <michael@weblore.com>)
Список pgsql-general
Michael,

>>> I'm new to PostgreSQL, but have worked with other databases. I'm trying
>>> to write a trigger to default a timestamp column to a fixed interval
>>> before another. The test setup is as follows:

Try this pg_dump of a working example:

CREATE FUNCTION t_listing_startdate() RETURNS trigger
     LANGUAGE plpgsql
     AS $$
begin
     if new.d2 is null then
         new.d2 := new.d1 - interval '7 day';
     end if;
     return new;
end;
$$;

CREATE TABLE t (
     d1 timestamp without time zone,
     d2 timestamp without time zone
);

CREATE TRIGGER t_listing_startdate
     BEFORE INSERT OR UPDATE ON t
     FOR EACH ROW
     EXECUTE PROCEDURE t_listing_startdate();

-- Gary Chambers

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

Предыдущее
От: Michael Satterwhite
Дата:
Сообщение: Re: Help with trigger
Следующее
От: Guillaume Lelarge
Дата:
Сообщение: Re: Help with trigger