Considering
=> 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 need an insert statement for entries
that skips pasting if either entry_id
already exists or the reference element does not exist. The first is easy to do:
INSERT INTO entries VALUES (1, 2, 'references two') ON CONFLICT (entry_id) DO NOTHING;
Can I also check for the presence of a foreign key here?
source share