pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Scott Marlowe <scott.marlowe@gmail.com>
To: gherzig@fmed.uba.ar <gherzig@fmed.uba.ar>
Cc: pgsql-sql@postgresql.org
Subject: Re: foreign key pointing to diff schema?
Date: Fri, 10 Aug 2007 17:23:51 -0500
Message-ID: <dcc563d10708101523y6621f875w430bb1be0ff273f5@mail.gmail.com> (raw)
In-Reply-To: <23920.190.55.64.163.1186784101.squirrel@www.webmail.fmed.uba.ar>
References: <23920.190.55.64.163.1186784101.squirrel@www.webmail.fmed.uba.ar>

On 8/10/07, gherzig@fmed.uba.ar <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.



view thread (3+ messages)  latest in thread

Message-ID: <dcc563d10708101523y6621f875w430bb1be0ff273f5@mail.gmail.com>
Permalink:  ../dcc563d10708101523y6621f875w430bb1be0ff273f5@mail.gmail.com/
Also on:    postgresql.org/message-id/dcc563d10708101523y6621f875w430bb1be0ff273f5@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: scott.marlowe@gmail.com, gherzig@fmed.uba.ar
  Subject: Re: foreign key pointing to diff schema?
  In-Reply-To: <dcc563d10708101523y6621f875w430bb1be0ff273f5@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox