pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedforeign key pointing to diff schema?
3+ messages / 2 participants
[nested] [flat]
* foreign key pointing to diff schema?
@ 2007-08-10 22:15 gherzig@fmed.uba.ar
2007-08-10 22:23 ` Re: foreign key pointing to diff schema? Scott Marlowe <scott.marlowe@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: gherzig@fmed.uba.ar @ 2007-08-10 22:15 UTC (permalink / raw)
To: pgsql-sql
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?
Thanks!
Gerardo
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: foreign key pointing to diff schema?
2007-08-10 22:15 foreign key pointing to diff schema? gherzig@fmed.uba.ar
@ 2007-08-10 22:23 ` Scott Marlowe <scott.marlowe@gmail.com>
2007-08-10 22:37 ` Re: foreign key pointing to diff schema? gherzig@fmed.uba.ar
0 siblings, 1 reply; 3+ messages in thread
From: Scott Marlowe @ 2007-08-10 22:23 UTC (permalink / raw)
To: gherzig@fmed.uba.ar <gherzig@fmed.uba.ar>; +Cc: 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 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.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: foreign key pointing to diff schema?
2007-08-10 22:15 foreign key pointing to diff schema? gherzig@fmed.uba.ar
2007-08-10 22:23 ` Re: foreign key pointing to diff schema? Scott Marlowe <scott.marlowe@gmail.com>
@ 2007-08-10 22:37 ` gherzig@fmed.uba.ar
0 siblings, 0 replies; 3+ messages in thread
From: gherzig@fmed.uba.ar @ 2007-08-10 22:37 UTC (permalink / raw)
To: Scott Marlowe <scott.marlowe@gmail.com>; +Cc: 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 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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2007-08-10 22:37 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-08-10 22:15 foreign key pointing to diff schema? gherzig@fmed.uba.ar
2007-08-10 22:23 ` Scott Marlowe <scott.marlowe@gmail.com>
2007-08-10 22:37 ` gherzig@fmed.uba.ar
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