Re: multi-table unique index - Mailing list pgsql-sql

From Michael A Nachbaur
Subject Re: multi-table unique index
Date
Msg-id 200306231134.11430.mike@nachbaur.com
Whole thread Raw
In response to Re: multi-table unique index  (Markus Bertheau <twanger@bluetwanger.de>)
Responses Re: multi-table unique index
List pgsql-sql
On Monday 23 June 2003 11:16 am, Markus Bertheau wrote:
> В Пнд, 23.06.2003, в 19:32, Michael A Nachbaur пишет:
> > Instead of using the "serial" datatype, you can set it to "int4 PRIMARY
> > KEY DEFAULT nextval(foo_type_id_seq)" and you can manually create the
> > sequence "foo_type_id_seq".
> >
> > This way all the tables share the same sequence.
>
> Yeah, but I want to force this behaviour. so that it cannot happen by
> accident when you insert records without relying on the sequence.

I believe that's what I recommended.  IIRC the "serial" datatype is simply a
shortcut to what I listed above.  This way, if you do not explicitly specify
an id for your record, it'll pull the default; which retrieves a new values
from the sequence.

If you want to ensure that a value is unique when a record is inserted, even
if the user explicitly specifies an ID values, you can create a unique
trigger on the tables, but this depends on what you want to do.


pgsql-sql by date:

Previous
From: Markus Bertheau
Date:
Subject: Re: multi-table unique index
Next
From: Markus Bertheau
Date:
Subject: Re: multi-table unique index