UNIQUE INDEX unaware of transactions

From: Hannu Krosing <hannu(at)tm(dot)ee>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: UNIQUE INDEX unaware of transactions
Date: 2001-06-15 13:48:31
Message-ID: 3B2A122F.2D027253@tm.ee
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


It seems that our current way of enforcing uniqueness knows nothing
about transactions ;(

when you

create table t(
i int4 primary key
);"""

and then run the following query

begin;
delete from t where i=1;
insert into t(i) values(1);
end;

in a loop from two parallel processes in a loop then one of them will
almost instantaneously err out with

ERROR: Cannot insert a duplicate key into unique index t_pkey

I guess this can be classified as a bug, but I'm not sure how easy it
is to fix it.

-------------
Hannu

I tested it with the followiong python script

#!/usr/bin/python

sql_reinsert_item = """\
begin;
delete from t where i=1;
insert into t(i) values(1);
end;
"""

def main():
import _pg
con = _pg.connect('test')
for i in range(500):
print '%d. update' % (i+1)
con.query(sql_reinsert_item)

if __name__=='__main__':
main()

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2001-06-15 13:56:45 Re: [PATCH] indexability of << operator for inet/cidr
Previous Message Dip 2001-06-15 13:46:22 Postgres Internals