Re: Enforcing serial uniqueness?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Steven Brown <swbrown(at)ucsd(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Enforcing serial uniqueness?
Date: 2006-03-22 09:28:44
Message-ID: 20060322092844.GB29954@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message William ZHANG 2006-03-22 10:29:38 Re: back slash separated values
Previous Message Gavin Hamill 2006-03-22 09:25:04 pg 8.1.3 on AIX