Re: Question: unique on multiple columns

Will Trillich <will@serensoft.com>

From: will trillich <will@serensoft.com>
To: pgsql-general@postgresql.org
Date: 2003-02-05T14:09:13Z
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@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/ !