Postgres: foreign key to foreign table

百般思念 提交于 2019-12-10 14:11:50

问题


I have a foreign table, for example:

CREATE FOREIGN TABLE film (
    id          varchar(40) NOT NULL,
    title       varchar(40) NOT NULL,
    did         integer NOT NULL,
    date_prod   date,
    kind        varchar(10),
    len         interval hour to minute
)
SERVER film_server;

with id as the primary key for that table (set in the remote database). I would like to have a local table reference the foreign table, and set a foreign key constraint on the local table -- for example:

CREATE TABLE actor (
    id          varchar(40) NOT NULL,
    name       varchar(40) NOT NULL,
    film_id       varchar(40) NOT NULL,
)

ALTER TABLE actor ADD CONSTRAINT actor_film_fkey FOREIGN KEY (film_id) 
    REFERENCES film(id);

However, when I try to add the foreign key constraint, I get the error:

ERROR:  referenced relation "film" is not a table

Is it possible to add a foreign key constraint to a foreign table?


回答1:


It's no possible create index on foreign tables.

CREATE INDEX idx_film ON film (id);

This is the error:

ERROR: cannot create index on foreign table



来源:https://stackoverflow.com/questions/37380738/postgres-foreign-key-to-foreign-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!