Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id F088E9F9725 for ; Fri, 10 Aug 2007 19:23:56 -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 86760-03 for ; Fri, 10 Aug 2007 19:23:49 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from rv-out-0910.google.com (rv-out-0910.google.com [209.85.198.191]) by postgresql.org (Postfix) with ESMTP id 7177D9F96EA for ; Fri, 10 Aug 2007 19:23:53 -0300 (ADT) Received: by rv-out-0910.google.com with SMTP id f1so682204rvb for ; Fri, 10 Aug 2007 15:23:52 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=f36nyLXhlEbpK8LQ2eXQ9K7KUDWAuSzsgfK5c0746TxnQy2HyGeytxP6gvlV5wK062I3cLVLlB2aWmWAslOXjms8QWL7F00i1WeBsQdIy3EZrzFqbPXbfydbUWg//1xtzkOJ0PIzvcoLFYmQH51+zeqVI42+Mqmr9O/HiDzsmfw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=s4vhQU/bc1grxCIdjuQj3qxmYlEsU2wohduLJMnRg9hqT1RhDBYSTOQ/Bkr1l1eyUZUcITNhlMvZJepmR/GuYavNOaCRbBxiv+KTfIGmmumTiKHf30snYSdvYLTGxZP/jW9K0JZqwkk2yCiuMfjHD3U84gHuQFwMmm5TtV6fT2M= Received: by 10.141.197.18 with SMTP id z18mr1232686rvp.1186784631796; Fri, 10 Aug 2007 15:23:51 -0700 (PDT) Received: by 10.141.98.12 with HTTP; Fri, 10 Aug 2007 15:23:51 -0700 (PDT) Message-ID: Date: Fri, 10 Aug 2007 17:23:51 -0500 From: "Scott Marlowe" To: "gherzig@fmed.uba.ar" Subject: Re: foreign key pointing to diff schema? Cc: pgsql-sql@postgresql.org In-Reply-To: <23920.190.55.64.163.1186784101.squirrel@www.webmail.fmed.uba.ar> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <23920.190.55.64.163.1186784101.squirrel@www.webmail.fmed.uba.ar> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/88 X-Sequence-Number: 29026 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.