Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: unique constraint on 2 columns


  • From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
  • To: Jonathan Vanasco <postgres(at)2xlp(dot)com>
  • Cc: pgsql general <pgsql-general(at)postgresql(dot)org>
  • Subject: Re: unique constraint on 2 columns
  • Date: Fri, 20 Apr 2007 17:58:31 -0400
  • Message-id: <22899(dot)1177106311(at)sss(dot)pgh(dot)pa(dot)us>

Jonathan Vanasco <postgres(at)2xlp(dot)com> writes:
> Given:
> 	create table test_a (
> 		id serial ,
> 		name_1 varchar(32) ,
> 		name_2 varchar(32)
> 	);

> I need name_1 and name_2 to both be unique so that:
> 	name_1 never appears in name_1 or name_2
> 	name_2 never appears in name_2 or name_1

I think you should consider redesigning your table layout.  Whatever
kluge you come up with to enforce that is not going to be better than
changing the layout.  You should put all the names into one unique
column and devise a different representation for whatever the
name_1 vs name_2 relationship is supposed to be.

			regards, tom lane



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group