Search Postgresql Archives

Re: Howto prevent write based on date

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

 



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 :)

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.

--
  Richard Huxton
  Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
     subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your
     message can get through to the mailing list cleanly

[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