Limiting/disallowing changes of certain columns

From: Melvin Call <melvincall979(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Limiting/disallowing changes of certain columns
Date: 2013-11-11 21:55:59
Message-ID: CADGQN57ti+UVgb5UwavAWc6HMZzaLTLhvYZfz90R3Ty3pZKKWA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello all,

I am creating a data model that contains time-dependent data. I only need a
snapshot solution, where we capture the initial state of all fields in the
record, and we then store subsequent changes as a new row in a child table.
What I am looking at is creating a primary table that contains the fields
we do not need to track, or do not want to allow changes to, and a child
table that contains the ones we do need to track. My question regards the
columns in the parent table that we want to disallow changes to, or once
they have been changed to a certain value to prevent further changes. An
example would be an isvalid Boolean. Once a record has been marked invalid
(perhaps it was created by mistake), we do not want it to accidentally be
marked valid but we want to preserve it and any history associated with it.
Other cases would be the initial creation timestamp or the initial creation
person.

I'm assuming that I can create a BEFORE trigger that will prevent the
changes (and probably even return a custom error), but is that the only
and/or best way to handle such a case?

Sorry I can't be more specific than that, but this is still just a lot of
scribbling on a blackboard at this point. However, since I know we are
going to have to preserve some historical information I am thinking ahead
on the best way to handle the situation.

Thanks,
Melvin

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Grittner 2013-11-11 22:18:18 Re: Clang 3.3 Analyzer Results
Previous Message Jeff Janes 2013-11-11 21:32:49 Re: Clone database using rsync?