On Wed, Jan 22, 2025 at 2:00 AM Runxi Yu <m...@runxiyu.org> wrote: > I therefore propose a feature, to be able to specify in a table schema > that a row should be deleted if orphaned. >
I think you mean "childless" rows, as "orphaned" has a different meaning traditionally. When and how would this deletion take place? And why not just run the delete yourself? It would help to show us exactly the behavior you want. Here's some sample tables we can use: create table parent( id int primary key ); create table kid( refid int references parent(id) ); insert into parent values (1),(2),(3); insert into kid values (1); -- remove any rows non-referenced rows (aka childless) delete from parent where not exists (select 1 from kid where refid=parent.id ); select * from parent; id ---- 1 Cheers, Greg -- Crunchy Data - https://www.crunchydata.com Enterprise Postgres Software Products & Tech Support