Re: Question: unique on multiple columns

From: Arjen van der Meijden <acm(at)tweakers(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Question: unique on multiple columns
Date: 2003-02-05 14:00:39
Message-ID: 001d01c2cd1e$fa0352f0$3ac15e91@acm
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

How about a unique index.

Create unique index table_col2_col3_unique ON table (col2, col3);

> -----Oorspronkelijk bericht-----
> Van: pgsql-general-owner(at)postgresql(dot)org
> [mailto:pgsql-general-owner(at)postgresql(dot)org] Namens roverr
> Verzonden: woensdag 5 februari 2003 12:47
> Aan: pgsql-general(at)postgresql(dot)org
> Onderwerp: [GENERAL] Question: unique on multiple columns
>
>
> 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?
>
> I have a table as follows:
> col 1: id, type serial, primary key
> col 2: host_id, type integer, foreign key to hosts table
> col 3: data_time, type timestamp
> col 4 - 9 data that is unique to col 2 and 3
>
> I wish to have a constraint such that the combination
> of the host_id entry in col 2 and each data_time entry
> in col 3 must be unique.
> My thoughts are to calculate a new column based on
> col 2 and 3 and force that to be unique. Is this
> the correct approach or is my table layout hopelessly
> flawed?
>
> Thanks in advance,
> Gary
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
http://www.postgresql.org/users-lounge/docs/faq.html

In response to

Browse pgsql-general by date

  From Date Subject
Next Message will trillich 2003-02-05 14:07:13 how to do this -- subqueries?
Previous Message Martin Marques 2003-02-05 12:43:31 Re: 7.3.1 BREAKS COMPATIBILITY with the latest PHP4 (due to