From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alexander Stanier <alexander.stanier@egsgroup.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Referential Integrity
Date: Mon, 10 Feb 2003 07:54:56 -0800 (PST)
Message-ID: <20030210074318.C97908-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <5191.1044889792@sss.pgh.pa.us>
On Mon, 10 Feb 2003, Tom Lane wrote:
> "Alexander Stanier" <alexander.stanier@egsgroup.com> writes:
> > [ expected ON DELETE CASCADE doesn't seem to happen in this context: ]
>
> > CREATE FUNCTION test() RETURNS INT4 AS '
> > DECLARE
> > v_return INTEGER;
> > BEGIN
> > DELETE FROM alex
> > WHERE aid =3D ''1''
> > AND bid =3D ''1'';
>
> > INSERT INTO alex (aid,bid,itemdesc)
> > VALUES (''1'',''1'',''OneOne'');
>
> > INSERT INTO alexette (aid,bid,vcode)
> > VALUES (''1'',''1'',''V'');
>
> > RETURN 0;
> > END;
> > ' LANGUAGE 'plpgsql';
>
> The cascaded deletes will be implemented at end of statement --- which
> I believe is always taken to be the end of the current interactive
> statement, ie, the "SELECT test()" you typed. So they haven't happened
> yet at the time the function tries to do the inserts.
>
> This is probably a bug, but IIRC, it's not entirely obvious what to do
> instead. I seem to recall some inconclusive discussions in pgsql-hackers
> about designing a better rule for when to fire the RI actions. Check
> the list archives for details.
Yeah, I don't think we came to a conclusion. Looking at SQL99, the
"correct" behavior seems to be that the actions occur as part of the
actual delete or update action so that effectively at the "same" point in
time the dependant rows are changed, using (I think) 14.14 and 14.20 as a
guide. This is significantly different from what we do AFAICT though. :(
(For example, I'm not sure if 14.14 implies that after triggers from the
statement inside the function to occur as part of that statement rather
than after the function ends)
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, tgl@sss.pgh.pa.us, alexander.stanier@egsgroup.com
Subject: Re: Referential Integrity
In-Reply-To: <20030210074318.C97908-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