From: | will trillich <will(at)serensoft(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Question: unique on multiple columns |
Date: | 2003-02-05 14:09:13 |
Message-ID: | 20030205140913.GB26366@mail.serensoft.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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?
>
> 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?
you can
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 );
i don't understand your cols 4-9, tho. is this what you're
looking for?
--
There are 10 kinds of people:
ones that get binary, and ones that don't.
will(at)serensoft(dot)com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!
Looking for a firewall? Do you think smoothwall sucks? You're
probably right... Try the folks at http://clarkconnect.org/ !
From | Date | Subject | |
---|---|---|---|
Next Message | RobertD.Stewart | 2003-02-05 14:34:31 | Re: Functions and triggers can anyone help |
Previous Message | will trillich | 2003-02-05 14:07:13 | how to do this -- subqueries? |