Re: Enforcing serial uniqueness? - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Enforcing serial uniqueness?
Date
Msg-id 20060322092844.GB29954@svana.org
Whole thread Raw
In response to Enforcing serial uniqueness?  (Steven Brown <swbrown@ucsd.edu>)
Responses Re: Enforcing serial uniqueness?  (Alban Hertroys <alban@magproductions.nl>)
Re: Enforcing serial uniqueness?  (Steven Brown <swbrown@ucsd.edu>)
List pgsql-general
On Tue, Mar 21, 2006 at 11:41:11PM -0800, Steven Brown wrote:
> I want to allow access to a table's rows without allowing that table to
> be damaged.  A problem I have is with my serial primary key 'id' field.
>  Although I can block its UPDATE, if users INSERT with an explicit 'id'
> higher than the sequence, future INSERTs will fail due to the values
> colliding.  Ditto if users modify the sequence (setval) to be lower than
> existing 'id' fields.  This is rather bad, as it prevents
> anyone/anything from INSERTing until fixed by manual intervention.

IIRC you can set the permissions on a sequence to allow nextval but not
setval.

Secondly, if you don't want people to be able to stuff with your ID
column, you could set a BEFORE INSERT trigger to overwrite whatever
they provide and a BEFORE UPDATE trigger to cancel any changes...

Have a nice dat,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

pgsql-general by date:

Previous
From: Gavin Hamill
Date:
Subject: pg 8.1.3 on AIX
Next
From: Alban Hertroys
Date:
Subject: Re: Enforcing serial uniqueness?