Postgres: foreign key for foreign table

I have an external 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 the identifier as the primary key for this table (installed in the remote database). I would like the local table to reference the foreign table and set the foreign key constraint in 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 a foreign key constraint, I get an error:

ERROR:  referenced relation "film" is not a table

Can I add a foreign key constraint to a foreign table?

+5
source share
1 answer

Unable to create index for foreign tables.

CREATE INDEX idx_film ON film (id);

This is mistake:

ERROR: unable to create index for external table

0
source

All Articles