I maintain a website where users post interesting links, and other users leave replies under the said links. I want to delete aged link entries under which no one replied.
The postgresql database is like so: there's a table called
links_link, and another one called
links_publicreply has a column called
answer_to, which is a foreign key to
links_link. I only want to delete aged rows in
links_link which do NOT have a related entry in
What would the queries be? Something like the following?
DELETE FROM links_link WHERE id NOT IN links_publicreply AND "submitted_on" < now() - interval('1 day');
I don't want to run into foreign key violations.