Re: failed Delete after Insert in a transaction

From: "Alex Bolenok" <abolen(at)chat(dot)ru>
To: "Andrew Snow" <als(at)fl(dot)net(dot)au>
Cc: "pgsql-general" <pgsql-general(at)postgresql(dot)org>
Subject: Re: failed Delete after Insert in a transaction
Date: 2000-07-23 16:07:48
Message-ID: 003101bff4c0$29527070$df02a8c0@artey.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Why won't PostgreSQL let me do this?
>
> db=# begin;
> BEGIN
> db=# insert into foo (name) values ('hmmm');
> INSERT 22288 1
> db=# delete from foo where name='hmmm';
> ERROR: triggered data change violation on relation "foo"
> db=# abort;
>
> The table foo is defined like this:
>
> CREATE TABLE foo (
> ID serial PRIMARY KEY,
> Name text NOT NULL
> );
>
>
> I can't work out what I am doing wrong!
>
>
> Note, there is another table that REFERENCES this table, but as you can
see
> in the example transaction above, I don't touch any other tables. Also
note
> that it works fine outside of a transaction.
>
> I am running postgresql 7.02 on FreeBSD 3.4-STABLE.
>
>
> Thanks
>
>
> Andrew

You should commit transaction before changing any foreign key that was
affected by this transaction.

So if you really want to delete the row you have just inserted (I wonder why
:) you should write your own FOREIGN KEY triggers. It implies performance
loss, but allows you to do everything you want over the referenced fields.

Alex Bolenok.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jan Wieck 2000-07-23 17:33:01 Re: failed Delete after Insert in a transaction
Previous Message Andrew Snow 2000-07-23 13:51:45 failed Delete after Insert in a transaction