Unique constraints and indexes.

From: Steve Rogerson <steve(dot)pg(at)yewtc(dot)demon(dot)co(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Unique constraints and indexes.
Date: 2016-01-05 17:13:37
Message-ID: 568BF9C1.20203@yewtc.demon.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Is this a bug? I create a "unique" index, directly but it doesn't add a unique
constraint. Add a unique constraint and it adds the index and the constraint.
(pg version 9.4.5 on fedora 22, but also occurs in other versions).
Functionally I can't see a difference.

mydb=# create table test_table ( f1 bigint, f2 bigint);
CREATE TABLE
mydb=# create unique index test_table_un on test_table (f1, f2);
CREATE INDEX
mydb=# \d test_table
Table "public.test_table"
Column | Type | Modifiers
--------+--------+-----------
f1 | bigint |
f2 | bigint |
Indexes:
"test_table_un" UNIQUE, btree (f1, f2)

mydb=# select conindid, contype, conname from pg_constraint where conname like
'test_table%';
conindid | contype | conname
----------+---------+---------
(0 rows)

-- --------------------------------------------------------------------------
mydb=# drop table test_table;
DROP TABLE
mydb=# create table test_table ( f1 bigint, f2 bigint);
CREATE TABLE
mydb=# alter table test_table add constraint test_table_un unique (f1,f2);
ALTER TABLE
mydb=# \d test_table
Table "public.test_table"
Column | Type | Modifiers
--------+--------+-----------
f1 | bigint |
f2 | bigint |
Indexes:
"test_table_un" UNIQUE CONSTRAINT, btree (f1, f2)

mydb=# select conindid, contype, conname from pg_constraint where conname like
'test_table%';
conindid | contype | conname
----------+---------+---------------
4284073 | u | test_table_un
(1 row)

mydb=#

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Greg Sabino Mullane 2016-01-05 17:15:20 Re: Code of Conduct: Is it time?
Previous Message Adrian Klaver 2016-01-05 17:09:33 Re: [SQL] plv8 installation problem