Re: Read-only attributes

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Klatt <mdklatt(at)ou(dot)edu>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Read-only attributes
Date: 2002-02-18 20:53:41
Message-ID: 13607.1014065621@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Michael Klatt <mdklatt(at)ou(dot)edu> writes:
> I have a table where one of the attributes is the time a row was inserted:
> 'updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP'.

> Is there a way to define this attribute so that a user cannot override the
> default value? I have tried this constraint, but it fails for any INSERT:
> 'updated ... CHECK (updated = CURRENT_TIMESTAMP)'.

No, but if you used a trigger rather than a default value, you could
force the field value to be always the time of insert.

You should, however, consider carefully whether that is *really* what
you want: there's no way to bypass a trigger. Among other things,
dumping and reloading such a table would cause all the rows to acquire
the time of load.

A probably cleaner solution is not to give the untrusted users direct
write access on the table at all. Give them write access on a view, and
let the INSERT rewrite rule for the view enforce the desired behavior.

regards, tom lane

In response to

Responses

  • 7.2 upgrade at 2002-02-20 22:05:52 from Tuna Chatterjee

Browse pgsql-novice by date

  From Date Subject
Next Message knut.suebert 2002-02-18 21:23:42 Re: what does opaque mean in create function?
Previous Message Pam Wampler 2002-02-18 18:34:30 what does opaque mean in create function?