0

If I create a new schema on the current database (management), why does it complain about cross-database references?

management=# create schema mgschema;
CREATE SCHEMA

management=# alter table clients add column task_id int null references mgschema.tasks.id;
ERROR:  cross-database references are not implemented: "mgschema.tasks.id"

2 Answers 2

1
alter table clients add column task_id int null references mgschema.tasks.id;

The REFERENCES syntax in not correct, you should use:

REFERENCES reftable [ ( refcolumn ) ]
Sign up to request clarification or add additional context in comments.

Comments

1

A simple references only expects a table name. The foreign key will then automatically point to the primary key of that table, e.g.

alter table clients add column task_id int null references mgschema.tasks;

Another alternative is to to specify the table and columns, but not with a single identifier:

alter table clients add column task_id int null references mgschema.tasks (id);

The second format is needed if the target table has multiple unique constraints.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.