On Dec 6, 2:26 pm, John W Higgins <[email protected]> wrote:
> On Mon, Dec 6, 2010 at 1:37 PM, Jim Morris <[email protected]> wrote:
> > Hi,
>
> > WRT this bug entry
> >http://code.google.com/p/ruby-sequel/issues/detail?id=317
>
> > I thought a primary key with multiple columns is more like an index
> > not a constraint.
>
> Primary Keys are always a constraint. They fall within the family of Unique
> Keys.
>
> However, most implementations will setup both the constraint and an index
> because clearly one is normally interested in both.
Correct. For PostgreSQL, the psql CLI tool shows you the index and
not the constraint, but if you attempt to drop the index, it will
complain that the constraint exists. If you drop the constraint, it
implicitly drops the index:
sequel_test=# CREATE TABLE a(a integer primary key);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"a_pkey" for table "a"
CREATE TABLE
sequel_test=# \d a
Table "public.a"
Column | Type | Modifiers
--------+---------+-----------
a | integer | not null
Indexes:
"a_pkey" PRIMARY KEY, btree (a)
sequel_test=# DROP INDEX a_pkey;
ERROR: cannot drop index a_pkey because constraint a_pkey on table a
requires it
HINT: You can drop constraint a_pkey on table a instead.
sequel_test=# ALTER TABLE a DROP CONSTRAINT a_pkey;
ALTER TABLE
sequel_test=# \d a
Table "public.a"
Column | Type | Modifiers
--------+---------+-----------
a | integer | not null
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.