简体   繁体   English

为什么两个表都在同一个数据库中时,Postgres告诉我跨数据库引用不可用?

[英]Why does Postgres tell me that cross database references are not available when both tables are on the same database?

Here's the SQL: 这是SQL:

CREATE TABLESPACE fnord1 location '/tmp/fnord1';
CREATE TABLESPACE fnord2 location '/tmp/fnord2';

CREATE SCHEMA IF NOT EXISTS fnord;

DROP TABLE IF EXISTS fnord.shea;
DROP TABLE IF EXISTS fnord.wilson;

CREATE TABLE fnord.shea (
    id  text not null,

    CONSTRAINT fnord_shea_id PRIMARY KEY (id) USING INDEX TABLESPACE fnord2
) TABLESPACE fnord1;

CREATE TABLE fnord.wilson (
    thing       text not null,
    shea_id     bigserial not null,

    CONSTRAINT fnord_wilson_id PRIMARY KEY (thing, shea_id) USING INDEX TABLESPACE fnord2,
    CONSTRAINT fnord_wilson_shea_fkey FOREIGN KEY (shea_id) REFERENCES fnord.shea.id
) TABLESPACE fnord1;

This fails because of the foreign key statement, with 由于外键声明,此操作失败,带有

ERROR: cross-database references are not implemented: "fnord.shea.id" 错误:跨数据库引用未实现:“ fnord.shea.id”

But... these are in the same database, are they not? 但是...这些都在同一个数据库中,不是吗? If not, what's the right way to get them in the same database? 如果不是,将它们放入同一数据库的正确方法是什么?

Use schema.table_name(column_name) : 使用schema.table_name(column_name)

CONSTRAINT fnord_wilson_shea_fkey FOREIGN KEY (shea_id) REFERENCES fnord.shea.id

to

CONSTRAINT fnord_wilson_shea_fkey FOREIGN KEY (shea_id) REFERENCES fnord.shea(id)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM