Re: Howto prevent write based on date

From: Fmiser <fmiser(at)gmail(dot)com>
To: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Howto prevent write based on date
Date: 2005-05-06 20:32:48
Message-ID: 20050506153248.42185b73.fmiser@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

rumor has it that Richard wrote:

> Franco Bruno Borghesi wrote:
> > You could write a trigger like this:
> >
> >
> > CREATE OR REPLACE FUNCTION checkDate() RETURNS TRIGGER LANGUAGE
> > 'plpgsql' AS ' DECLARE
> > limitDate DATE DEFAULT current_date-''1 year''::INTERVAL;
> > BEGIN
> > IF (OLD.date<=limitDate) THEN
> > RAISE EXCEPTION ''Cannot change record.'';
> > END IF;
> >
> > RETURN NEW;
> > END;
> > ';
> >
> > CREATE TRIGGER xxxx_tg1 BEFORE UPDATE OR DELETE ON xxxx FOR EACH ROW
> > EXECUTE PROCEDURE checkDate();
> >
> > This should do the job :)

I feel like I'm 1 meter tall and the wave on the beach are more than 3
meters high...

Thank you for the code.

It looks like it would need to be a part of any access to the database,
so I imagine I would have to figure out where to put it into the
front-end code. Is this correct?

> Franco's trigger function should do the job just fine, but speaking
> from experience you'll want to take further steps.
>
> Take a backup of the database, restore it to another system and also
> burn a copy to a CD.
>
> If the auditors come round it's simple to explain what you've done and
>
> demonstrate the data on the CD and backup system match. It also means
> that should any changes occur to your historical data despite your
> precautions you can prove that this happened.

Ahh, that is a good idea! A database dump is a part of my daily backup.

I guess I could also make a read-only copy of the year-end as a second
database on the same system. That could make it easy to keep an eye on
the main database so I (hopefully) spot any ripples that reach back to
last year.

Thanks for the help! Philip

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jonel Rienton 2005-05-06 20:34:06 Re: pg_ctl bug or feature?
Previous Message Joshua D. Drake 2005-05-06 20:12:25 pg_ctl bug or feature?