Re: Syntax on BEFORE Trigger - Cascade?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: David Barbour <dbarbour(at)istation(dot)com>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Syntax on BEFORE Trigger - Cascade?
Date: 2024-06-13 14:25:25
Message-ID: CAKFQuwZMAvk_HLQgZ5yWULbsVZt7bH6sooKnaGSP3we5vm+dDw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thursday, June 13, 2024, David Barbour <dbarbour(at)istation(dot)com> 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2024-06-13 14:38:01 Re: TOAST Table / Dead Tuples / Free Pages
Previous Message Tom Lane 2024-06-13 14:23:07 Re: Syntax on BEFORE Trigger - Cascade?