Given
=> select * from referenced;
referenced_id | name
---------------+-------
1 | one
2 | two
3 | three
and
=> select * from entries;
entry_id | referenced_id | name
----------+---------------+------------------
1 | 3 | references three
where referenced_id
and entry_id
are primary keys.
I want an insert statement for entries
that skips insertion if either the entry_id
already exists or the referenced item does not exist. The first is easily done:
INSERT INTO entries
VALUES (1, 2, 'references two')
ON CONFLICT (entry_id) DO NOTHING;
Is it possible to check for the existence of the foreign key here too?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…