Eu tenho o seguinte código, que gera o erro:
ERRO: não há nenhuma restrição exclusiva correspondente às chaves fornecidas para a tabela referenciada "pessoa"
DROP TABLE IF EXISTS person;
CREATE TABLE person (
sn serial PRIMARY KEY,
id int NOT NULL,
modified timestamp,
name text
);
CREATE UNIQUE INDEX person_id_key ON person (id) WHERE modified IS NULL;
DROP TABLE IF EXISTS account;
CREATE TABLE account (
id int NOT NULL REFERENCES person(id),
name text
);
Existe um índice exclusivo para id
:
Table "public.person"
Column | Type | Collation | Nullable | Default
----------+-----------------------------+-----------+----------+------------------------------------
sn | integer | | not null | nextval('person_sn_seq'::regclass)
id | integer | | not null |
modified | timestamp without time zone | | |
name | text | | |
Indexes:
"person_pkey" PRIMARY KEY, btree (sn)
"person_id_key" UNIQUE, btree (id) WHERE modified IS NULL
Por que não é suficiente para a chave estrangeira?