Re: Howto prevent write based on date - Mailing list pgsql-general

From Franco Bruno Borghesi
Subject Re: Howto prevent write based on date
Date
Msg-id e13c14ec05050507183cf41b4e@mail.gmail.com
Whole thread Raw
In response to Howto prevent write based on date  (Fmiser <fmiser@gmail.com>)
Responses Re: Howto prevent write based on date
List pgsql-general
You could write a trigger like this:


CREATE OR REPLACE FUNCTION checkDate() RETURNS TRIGGER LANGUAGE 'plpgsql' AS ' DECLARElimitDate DATE DEFAULT current_date-''1 year''::INTERVAL; BEGINIF (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 :)


2005/5/4, Fmiser <fmiser@gmail.com>:
I'm a newbie to database admin, but I'm not afraid to try - but this one
has me stumped.

I'm using SQL-Ledger as a front end to postgresql 7.4.2. on (mostly)
Debian Testing, i386.

My fiscal year is over and I would _like_ to prevent any changes to the
data from last year.

I looked/searched in the manual, but I don't even know what to call what
it is that I'm trying to do!

"lock" has another meaning for databases. :)

"Write" seems to bring up lots of user-related stuff.

So, I'm hoping one of you geniuses can tell me where to look, what to
look for, or how to do it. *smile*

Thanks!

               Philip, wanabe-admin

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

               http://archives.postgresql.org

pgsql-general by date:

Previous
From: "Jeff Eckermann"
Date:
Subject: Re: Howto prevent write based on date
Next
From: Peter Wilson
Date:
Subject: Re: postgresql replication