Re: Question: unique on multiple columns

Поиск
Список
Период
Сортировка
От will trillich
Тема Re: Question: unique on multiple columns
Дата
Msg-id 20030205140913.GB26366@mail.serensoft.com
обсуждение исходный текст
Ответ на Question: unique on multiple columns  (roverr <roverr@dogpound.is-a-geek.org>)
Ответы Re: Question: unique on multiple columns  (roverr <roverr@dogpound.is-a-geek.org>)
Re: Question: unique on multiple columns  (Bruno Wolff III <bruno@wolff.to>)
Список 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@serensoft.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/ !

В списке pgsql-general по дате отправления:

Предыдущее
От: will trillich
Дата:
Сообщение: how to do this -- subqueries?
Следующее
От: "Nigel J. Andrews"
Дата:
Сообщение: Re: Functions and triggers can anyone help