Thread: Problem with transaction

Problem with transaction

From
Alexander Haväng
Date:
Hi :)

I'm kinda new with SQL, and kinda new with postgres, but I'm having trouble
with a simple transaction that works just fine on Informix so it should
work here on postgres too unless I'm messing it up somehow.

This is my table
CREATE TABLE hosts (
       hid SERIAL PRIMARY KEY,
       name VARCHAR(40) NOT NULL UNIQUE,
       hostname VARCHAR(255) NOT NULL
);

This is my psql session:
filterlogic=> begin;
BEGIN
filterlogic=> insert into hosts (name, hostname) VALUES ('sun', 'www.sun.com');
INSERT 403520 1
filterlogic=> delete from hosts where name='sun';
ERROR:  triggered data change violation on relation "hosts"
ERROR:  triggered data change violation on relation "hosts"

If I do a commit before the delete, it works just fine.
Why is this, and what can I do to get around this?

Regards,
Eel