X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 2B68BD1D1C3 for ; Wed, 11 Feb 2004 23:46:19 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 66262-01 for ; Wed, 11 Feb 2004 19:46:17 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id AC250D1B897 for ; Wed, 11 Feb 2004 19:46:16 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i1BNkG1a021476 for ; Wed, 11 Feb 2004 23:46:16 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i1BNYrDO019618 for pgsql-sql@postgresql.org; Wed, 11 Feb 2004 23:34:53 GMT From: "Greg Patnude" X-Newsgroups: comp.databases.postgresql.sql Subject: Re: Unique Constraint with foreign Key Date: Wed, 11 Feb 2004 15:33:50 -0800 Organization: Hub.Org Networking Services Lines: 51 Message-ID: References: <64366.138.88.163.115.1076432616.squirrel@physics.gmu.edu> <20040210201521.GA13737@wolff.to> X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/170 X-Sequence-Number: 16860 Pleas also note that the referenced column in the foreign table either needs to be the PRIMARY KEY or have a unique constraint on it or maybe it just requires an index on it -- I'm not sure but I discovered that if the column in the foreign table (containing the REFERENCED key...) is NOT the primary key column -- the REFERENCES a(x) will faill unless a.x is specified as 'UNIQUE' -- as in the following example: create table a ( y integer not null primary key default nextval('nexta_seq'), x varchar not null UNIQUE ); create table b ( z integer not null PRIMARY KEY default nextval('nextbz_seq'), x varchar NOT NULL REFERENCES a(x), ); -- Greg Patnude / The Digital Demention 2916 East Upper Hayden Lake Road Hayden Lake, ID 83835 (208) 762-0762 "Bruno Wolff III" wrote in message news:20040210201521.GA13737@wolff.to... > On Tue, Feb 10, 2004 at 12:03:36 -0500, > mohan@physics.gmu.edu wrote: > > Hi all i am using postgres and torque > > I have a column x in Table A of type varchar and NOT NULL. I want to > > impose a unique key constraint on that table and column y is the primary > > key. > > I have another Table B with column x. can i make this column x as a > > foreign key on column x in table A. > > Yes. The reference will need to specify column x, since the primary key > column (y) will be the default. > > > or Can i have varchar types of size 50 as primary keys in Postgres. > > Yes. But unless the 50 character limit comes from a business rule, you > might want to use the type 'text'. > > ---------------------------(end of broadcast)--------------------------- > TIP 7: don't forget to increase your free space map settings >