小编Bon*_*Fir的帖子

在 postgresql 中的外表上创建外键

我需要我的表,另外一个是在不同的数据库(比如表链接logsdevice数据库和表accountsuser分贝,无论是同一台服务器上)。因此,使用外部数据包装器我创建了一个外部表(我通过select * from accounts;device成功运行的db 中运行来检查它)。

但是我仍然无法从devicedb创建到外表的外键

CREATE TABLE public.logs
(
  id bigint NOT NULL DEFAULT nextval('logs'::regclass),
  ...
  account_id bigint,
  ...

  CONSTRAINT logs_account_id_fkey FOREIGN KEY (account_id)
      REFERENCES public.accounts (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION

)
Run Code Online (Sandbox Code Playgroud)

错误信息是

ERROR:  referenced relation "accounts" is not a table
********** Error **********

ERROR: referenced relation "accounts" is not a table
SQL state: 42809
Run Code Online (Sandbox Code Playgroud)

postgresql foreign-key postgresql-fdw

5
推荐指数
1
解决办法
3504
查看次数

标签 统计

foreign-key ×1

postgresql ×1

postgresql-fdw ×1