Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id EC9E39FB7D9 for ; Fri, 3 Aug 2007 04:24:26 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 81978-04 for ; Fri, 3 Aug 2007 04:24:21 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.172]) by postgresql.org (Postfix) with ESMTP id 0F87C9FB488 for ; Fri, 3 Aug 2007 04:24:22 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id a2so482891ugf for ; Fri, 03 Aug 2007 00:24:21 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=AcVCJXZnolV8W2UG3qBnisec0WtUuMLhdavxxfw2/egAhYwwfHGdJSVcER8lmp6NPyjy+ETqlqoiZeqwZP1a3uLQTh1bPFgTA9h8CrVf21R/f0g4tYVa4trAbGQP63ht8PZ79zCYuHzl4mIH4/yYk4O2LZ9u7OPvM3LISpOQZf4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=szzMjRVSZNHMgV0oO6qFC7rlya5IoFd6YMqYqy2UyrIa9UdDhJoI7+hXg9UNvjoOAsk1Df5LCDcbIVRMCnoVaFz6U1ydJYls6CeuMZmW9LVYuXkxZ3ZJI3l/SwpagLuIaGsWNkOOW45Zx5tA6q5N6Bt1cvKy1gyvfT/DeqASxBo= Received: by 10.67.19.11 with SMTP id w11mr2711849ugi.1186125861315; Fri, 03 Aug 2007 00:24:21 -0700 (PDT) Received: from ?192.168.10.68? ( [62.57.108.235]) by mx.google.com with ESMTPS id l40sm1601236ugc.2007.08.03.00.24.20 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 03 Aug 2007 00:24:20 -0700 (PDT) Message-ID: <46B2D823.7020700@gmail.com> Date: Fri, 03 Aug 2007 09:24:19 +0200 From: =?ISO-8859-1?Q?Dani_Casta=F1os?= User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 CC: pgsql-sql@postgresql.org Subject: Re: Foreign Key inter databases References: <46B203BD.1000102@gmail.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/18 X-Sequence-Number: 28956 Josh Tolley escribió: > On 8/2/07, Dani Castaños wrote: > >> Hi all! >> >> Is it possible to have a foreign key where referenced table is in >> another database? >> >> Thank you in advance >> >> ---------------------------(end of broadcast)--------------------------- >> TIP 1: if posting/reading through Usenet, please send an appropriate >> subscribe-nomail command to majordomo@postgresql.org so that your >> message can get through to the mailing list cleanly >> >> > > Unless you use things like dblink to make two separate databases think > they're one database, you really can't do anything where one database > depends on another. Your best bet, if you can have both data sets on > the same machine, is to stick them in two separate schemas, and then > you can have foreign keys on a table in one schema referencing a table > in another schema. That's (in part) what schemas are for in the first > place -- to separate logically distinct data sets while allowing > accesses between the two when necessary. > > If for whatever reason having all the data on one machine isn't > possible, you can try using dbi-link or dblink to create links between > the two databases and do foreign keys that way, but I've never used > either, so that might not work/make sense/be possible, etc. > > -Josh > Thanks Josh! I use dblinks for queries, but I'm pretty sure you can't use it in constraints definitions. My situation is that I have one main database and many customer's databases. In main database there is a languages table, and customers databases must use the language_id. Then, I don't want to create languages table in each customer db, that's the reason why i was trying to do a foreign key from customer db to main db.