Re: data integrity and inserts - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: data integrity and inserts
Date
Msg-id 20041201205955.GA2831@wolff.to
Whole thread Raw
In response to Re: data integrity and inserts  (Scott Frankel <leknarf@pacbell.net>)
List pgsql-general
On Wed, Dec 01, 2004 at 10:48:40 -0800,
  Scott Frankel <leknarf@pacbell.net> wrote:
>
> 1.
> CREATE TABLE names (the_id SERIAL PRIMARY KEY, the_name text);
> CREATE UNIQUE INDEX uidx_thename ON names(the_name);
>
>     vs.
>
> 2.
> CREATE TABLE names (the_id SERIAL PRIMARY KEY, the_name text UNIQUE);
>
>
> Is the UNIQUE constraint in the second solution merely short-hand for
> the explicit
> index declaration of the first solution?  Or is there a functional
> difference between
> them that I should choose between?

Currently the only way to enforce a UNIQUE constraint is by using an index.
So there isn't really much difference between the two. However, I think
using the UNIQUE constraint provides better meaning than using an index
for people who might look at your definitions later.

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Displaying more than six digits from a real number
Next
From: Joachim Zobel
Date:
Subject: Re: createlang plperl fails with 8.0 beta5