I'm working with a table of objects where all the objects have a unique rank value. When I add an object I need to query the table to get the last object in the rank index, then apply an incremented value to the new object to effectively put it last in the rank order. I need to eliminate the possibility of a race condition when two objects are added simultaneously. Naturally, this is done with table locks.
I'm using Django 1.0 and Postgresql 8.2.9. My question is: Is it sufficient to use the following code in my view before querying for the rank and creating the object? from django.db import connection cursor = connection.cursor() cursor.execute("LOCK TABLE mytable IN SHARE ROW EXCLUSIVE MODE") Is it safe to assume that a table lock applies to any cursors under a connection? I'm concerned that I'll use a cursor to create a table lock and then Django will use a different cursor to execute the queries and the lock will not apply to the separate cursor. I've looked around on Google for information relating to Django and table locks but was unable to find many people discussing the subject. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---