Re: data integrity and inserts

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Scott Frankel <leknarf(at)pacbell(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: data integrity and inserts
Date: 2004-12-01 20:59:55
Message-ID: 20041201205955.GA2831@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Dec 01, 2004 at 10:48:40 -0800,
Scott Frankel <leknarf(at)pacbell(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-12-01 21:00:05 Re: createlang plperl fails with 8.0 beta5
Previous Message Joachim Zobel 2004-12-01 20:40:32 Re: createlang plperl fails with 8.0 beta5