pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Magnus Sjöstrand <mange@NO-SPAMORAMA.mjaunet.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: How do I access the current row from a trigger?
Date: Wed, 3 Jul 2002 16:43:26 -0700 (PDT)
Message-ID: <20020703164001.X11710-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <3D22B59E.2000503@NO-SPAMORAMA.mjaunet.org>


On Wed, 3 Jul 2002, [ISO-8859-1] Magnus Sjöstrand wrote:

> Hi,
>
> I have a table as:
> create table sections (
>      id           serial not null primary key,
>      parent_id    references sections(id)
> );
>
> there is only one row where the parent_id is NULL, and that is the root
> section, all others refers to a section. Now I want to create a trigger,
> so that whenever I delete a section I can delete all sections that has
> the deleted section as parent, which in turn will run the triggers for
> the deleted sections. Thus I will be able to clear an entire branch with
> only one SQL command from the client.

How about just adding ON DELETE CASCADE to the references constraint?

But that doesn't answer the general question about access, so...

> is there any way to do this in PostgreSQL? I couldn't find a way of
> refering to the current row in a trigger in the postgresql reference.

I believe it's somewhat dependant on the procedural language used
to define the trigger function.  In plpgsql, you should be able to use OLD
and NEW to get column values like OLD.id in the case of an after delete
trigger.







view thread (2+ messages)

Message-ID: <20020703164001.X11710-100000@megazone23.bigpanda.com>
Permalink:  ../20020703164001.X11710-100000@megazone23.bigpanda.com/
Also on:    postgresql.org/message-id/20020703164001.X11710-100000@megazone23.bigpanda.com

 · 

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: pgsql-sql@postgresql.org
  Cc: sszabo@megazone23.bigpanda.com, mange@NO-SPAMORAMA.mjaunet.org
  Subject: Re: How do I access the current row from a trigger?
  In-Reply-To: <20020703164001.X11710-100000@megazone23.bigpanda.com>

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

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