postgres=# create table kunden (id int primary key, name text);
CREATE TABLE
postgres=# create table kontakte (id int primary key, name text);
CREATE TABLE
postgres=# create table telefon(kunde int references kunden, kontakte int references kontakte, nummer text);
CREATE TABLE
postgres=# insert into kunden values (1, 'kunde1');
INSERT 0 1
postgres=# insert into kontakte values (1, 'kontakt1');
INSERT 0 1
postgres=# insert into telefon values (1, null, '123');
INSERT 0 1
postgres=# insert into telefon values (null, 1, '456');
INSERT 0 1
postgres=# create table telefon(kunde int references kunden, kontakte int references kontakte, nummer text, check(case when kunde is null then 1 else 0 end + case when kontakte is null then 1 else 0 end = 1));
CREATE TABLE
postgres=# insert into telefon values (1, null, '123');
INSERT 0 1
postgres=# insert into telefon values (null, 1, '456');
INSERT 0 1
postgres=# insert into telefon values (null, null, '456');
ERROR: new row for relation "telefon" violates check constraint "telefon_check"
DETAIL: Failing row contains (null, null, 456).
postgres=# insert into telefon values (1, 1, '456');
ERROR: new row for relation "telefon" violates check constraint "telefon_check"
DETAIL: Failing row contains (1, 1, 456).
postgres=#