Re: Question: unique on multiple columns

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Question: unique on multiple columns
Date: 2003-02-05 16:53:09
Message-ID: 20030205165309.GB2542@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Feb 05, 2003 at 08:09:13 -0600,
will trillich <will(at)serensoft(dot)com> wrote:
> On Wed, Feb 05, 2003 at 06:46:35AM -0500, roverr wrote:
> > I'm running postgresql 7.2.1.
> > Is there a way to specify a constraint such that the combination
> > of two columns in a table is unique?
>
> create table something (
> a int4,
> b varchar(20),
> c timestamp
> );
> create unique index on something ( a, c );
> create unique index on something ( b, c, a );

While that will work, I think the following format is a little better.
create table something (
a int4,
b varchar(20),
c timestamp,
unique(a,c),
unique(b,c,a)
);

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Berend Tober 2003-02-05 17:15:07 How start using schemas for existing database
Previous Message Marcelo Pereira 2003-02-05 16:45:56 7.3 - Documentation (PDF version)