Re: duplicates

From: Jean-Luc Lachance <jllachan(at)sympatico(dot)ca>
To: Michael Paesold <mpaesold(at)gmx(dot)at>
Cc: Tsirkin Evgeny <tsurkin(at)mail(dot)jct(dot)ac(dot)il>, pgsql-admin(at)postgresql(dot)org
Subject: Re: duplicates
Date: 2004-09-06 14:36:21
Message-ID: 413C75E5.7090406@sympatico.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

If the reccord you are inserting do not depend on data in the record you
want to delete, why not simply use a trigger?

Before insert delete the record with the same key!

Michael Paesold wrote:

> Tsirkin Evgeny wrote:
>
>
>
>>one moer question ,how did you tested it?
>>
>>
>>>I have tested this here. I don't really know if this is just the case
>
> with
>
>>>Best Regards,
>>>Michael Paesold
>
>
> First I created the your schedule table. Then I opened two psql sessions...
>
> Session A Session B
>
> BEGIN;
> SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
> DELETE FROM schedule WHERE studentid = 1;
> INSERT INTO schedule VALUES (1, 1, 0, 0);
>
> BEGIN;
> SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
> DELETE FROM schedule WHERE studentid = 1;
> -- if there existed records for this delete,
> -- session B will now wait for session A to
> -- commit/rollback and error out on commit;
> -- otherwise no error
>
>
> COMMIT;
> INSERT INTO schedule VALUES (1, 1, 0, 0);
> COMMIT;
>
>
> You can also try and rollback the first transaction etc.
>
> Again, what really helps is:
> ALTER TABLE schedule ADD CONSTRAINT uniq_schedule UNIQUE (studentid,
> groupid);
>
> Best Regards,
> Michael Paesold
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Tsirkin Evgeny 2004-09-06 16:47:53 SELECT waiting
Previous Message Andrei Bintintan 2004-09-06 14:03:02 How to rename a constraint/trigger??