foreign keys to foreign tables

From: Rick Otten <rottenwindfish(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: foreign keys to foreign tables
Date: 2015-06-22 16:04:31
Message-ID: CAMAYy4KvrM=d_vKYHODzUThX789oAufzv2EYDONPMmWmva8j1w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello pgsql-general,

I'd like to set up a foreign key constraint to a foreign table from a local
table.

ie, I have a column in a local table that I'd like to ensure has a value in
the foreign table.

alter mytable
add column some_column_id uuid references myforeigntable(some_column_id)
;

Unfortunately I get a "not a table" error when I try this.

ERROR: referenced relation "myforeigntable" is not a table

I'm thinking I'll have to write a function that checks for existance of the
ids in the foreign table, and then put a CHECK constraint on using that
function, but I thought I'd as first if there was a better way.

Thanks.

--
Rick Otten
rottenwindfish(at)gmail(dot)com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2015-06-22 16:06:51 Re: Re: pg_dump 8.4.9 failing after upgrade to openssl-1.0.1e-30.el6_6.11.x86_64 on redhat linux
Previous Message Tom Lane 2015-06-22 15:45:15 Re: Re: pg_dump 8.4.9 failing after upgrade to openssl-1.0.1e-30.el6_6.11.x86_64 on redhat linux