Re: foreign key pointing to diff schema? - Mailing list pgsql-sql

From Scott Marlowe
Subject Re: foreign key pointing to diff schema?
Date
Msg-id dcc563d10708101523y6621f875w430bb1be0ff273f5@mail.gmail.com
Whole thread Raw
In response to foreign key pointing to diff schema?  (gherzig@fmed.uba.ar)
Responses Re: foreign key pointing to diff schema?  (gherzig@fmed.uba.ar)
List pgsql-sql
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 nullz1id   | 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.


pgsql-sql by date:

Previous
From: gherzig@fmed.uba.ar
Date:
Subject: foreign key pointing to diff schema?
Next
From: gherzig@fmed.uba.ar
Date:
Subject: Re: foreign key pointing to diff schema?