public inbox for [email protected]  
help / color / mirror / Atom feed
From: Greg Sabino Mullane <[email protected]>
To: Runxi Yu <[email protected]>
Cc: [email protected]
Subject: Re: Automatic deletion of orphaned rows
Date: Wed, 22 Jan 2025 10:11:26 -0500
Message-ID: <CAKAnmmLd9okDxM79MMomOvjLECm3zZfqbeUGY0RORCPwzTSqQw@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

On Wed, Jan 22, 2025 at 2:00 AM Runxi Yu <[email protected]> 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


view thread (2+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Automatic deletion of orphaned rows
  In-Reply-To: <CAKAnmmLd9okDxM79MMomOvjLECm3zZfqbeUGY0RORCPwzTSqQw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox