Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 38C789F96CD for ; Fri, 10 Aug 2007 19:36:03 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 89471-08 for ; Fri, 10 Aug 2007 19:35:56 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mail.fmed.uba.ar (mail.fmed.uba.ar [157.92.152.1]) by postgresql.org (Postfix) with ESMTP id 06D059F9671 for ; Fri, 10 Aug 2007 19:35:30 -0300 (ADT) Received: from www.webmail.fmed.uba.ar (localhost [127.0.0.1]) by mail.fmed.uba.ar (Postfix) with ESMTP id 18CCEAA54A; Fri, 10 Aug 2007 19:37:56 -0300 (ART) Received: from 190.55.64.163 (SquirrelMail authenticated user gherzig) by www.webmail.fmed.uba.ar with HTTP; Fri, 10 Aug 2007 19:37:56 -0300 (ART) Message-ID: <19678.190.55.64.163.1186785476.squirrel@www.webmail.fmed.uba.ar> In-Reply-To: References: <23920.190.55.64.163.1186784101.squirrel@www.webmail.fmed.uba.ar> Date: Fri, 10 Aug 2007 19:37:56 -0300 (ART) Subject: Re: foreign key pointing to diff schema? From: gherzig@fmed.uba.ar To: "Scott Marlowe" Cc: pgsql-sql@postgresql.org User-Agent: SquirrelMail/1.4.10a MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/89 X-Sequence-Number: 29027 > On 8/10/07, gherzig@fmed.uba.ar wrote: >> Hi all. Can i make a FK who points a table in a different schema? Or >> this >> is implemented via a trigger by my own? > > Sure. just prefix the table name with the schemaname and a . > > create schema abc; > alter user me set search_path='abc', 'public'; > create table z1 (id int primary key); > \d z1 > Table "abc.z1" > Column | Type | Modifiers > --------+---------+----------- > id | integer | not null > Indexes: > "z1_pkey" PRIMARY KEY, btree (id) > > (Note the abc.z1 there) > create schema test3; > create table test3.z2 (id int primary key, z1id int references > abc.z1(id)); > \d test3.z2 > Table "test3.z2" > Column | Type | Modifiers > --------+---------+----------- > id | integer | not null > z1id | integer | > Indexes: > "z2_pkey" PRIMARY KEY, btree (id) > Foreign-key constraints: > "z2_z1id_fkey" FOREIGN KEY (z1id) REFERENCES z1(id) > > > basically, schemas are just distinct name spaces. > Im sory, that was just a matter of trying and see, isnt? I guess i need a beer :) Thanks for the example and the explanation! Gerardo