public inbox for [email protected]  
help / color / mirror / Atom feed
From: David G. Johnston <[email protected]>
To: David Barbour <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: Syntax on BEFORE Trigger - Cascade?
Date: Thu, 13 Jun 2024 07:25:25 -0700
Message-ID: <CAKFQuwZMAvk_HLQgZ5yWULbsVZt7bH6sooKnaGSP3we5vm+dDw@mail.gmail.com> (raw)
In-Reply-To: <CAEMHB2S2GAaxS9Fsisw=7ebYB=7AMb5_4QuGFHX5G8ZXYC5KVw@mail.gmail.com>
References: <CAEMHB2S2GAaxS9Fsisw=7ebYB=7AMb5_4QuGFHX5G8ZXYC5KVw@mail.gmail.com>

On Thursday, June 13, 2024, David Barbour <[email protected]> wrote:

>
> When a record in *import_job* is deleted, the child records (file
> records) in *import_file* need to be deleted first.
>
> The constraint in both Oracle and Postgres is similar (Postgres version):
> *ALTER TABLE IF EXISTS idev.import_file*
>
>
>
> *    ADD CONSTRAINT fk1_import_file FOREIGN KEY (import_job_oid)
> REFERENCES idev.import_job (oid) MATCH SIMPLE    ON UPDATE NO ACTION    ON
> DELETE CASCADE;*
>

This, by itself, should work.  If it isn’t, please provide a self-contained
test case demonstrating that fact so it can be investigated/explained.

What version are you running?


> There aren't any delete triggers for either table. Any idea why this isn't
> working? Does cascade function differently in Postgres?
>
>
Nope (to both)


>
> I've also tried creating a before trigger on import_job,
>

Why?


>
> but can't seem to get the right syntax for taking the oid from the psql
> delete picked up by the trigger.
>

Your broken attempt to do this is likely what is causing the error.


>
> Here is one of my (many) attempts (have tried describing, setting, using
> new.oid, old.oid, a bunch of stuff) and can't get this right either:
>

Delete only populates OLD.

David J.


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: Syntax on BEFORE Trigger - Cascade?
  In-Reply-To: <CAKFQuwZMAvk_HLQgZ5yWULbsVZt7bH6sooKnaGSP3we5vm+dDw@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