Re: Help with trigger - Mailing list pgsql-general

From Gary Chambers
Subject Re: Help with trigger
Date
Msg-id alpine.OSX.2.01.1012271626130.303@www.clipper.local
Whole thread Raw
In response to Re: Help with trigger  (Michael Satterwhite <michael@weblore.com>)
List 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 by date:

Previous
From: Michael Satterwhite
Date:
Subject: Re: Help with trigger
Next
From: Guillaume Lelarge
Date:
Subject: Re: Help with trigger