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
--
Sent via pgsql-general mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general