Search Postgresql Archives

Re: Help with trigger

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux