Re: foreign key pointing to diff schema?

From: gherzig(at)fmed(dot)uba(dot)ar
To: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: foreign key pointing to diff schema?
Date: 2007-08-10 22:37:56
Message-ID: 19678.190.55.64.163.1186785476.squirrel@www.webmail.fmed.uba.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> On 8/10/07, gherzig(at)fmed(dot)uba(dot)ar <gherzig(at)fmed(dot)uba(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message hubert depesz lubaczewski 2007-08-10 22:59:53 Re: Best Fit SQL query statement
Previous Message Scott Marlowe 2007-08-10 22:23:51 Re: foreign key pointing to diff schema?