Trying ZODB, background in Relational: mimic auto_increment?

Jean-Paul Calderone exarkun at divmod.com
Thu Aug 14 11:13:32 EDT 2008


On Thu, 14 Aug 2008 16:41:57 +0200, Thomas Guettler <hv at tbz-pariv.de> wrote:
>auto increment:
>>Here's one way
>>
>>    class Sequence(Persistence):
>>        def __init__(self):
>>            self.current = 0
>>
>>        def next(self):
>>            self.current += 1
>>            return self.current
>>
>>    ticketSequence = Sequence()
>>
>>    class Ticket(Persistence):
>>        def __init__(self):
>>            self.id = ticketSequence.next()
>
>I am sorry, but this does not work if several threads or processes
>try to get a new id.
>
>Have a look at:
>http://www.zope.org/Documentation/Books/ZDG/current/Persistence.stx
>"Resolving Conflicts".
>
>BTW, that's one of the points why I switched from ZODB to Postgres.
>

I'm not sure why you say it doesn't work and then link to the documentation
which both explains why it works and how to handle the cases where a
conflict might cause it to sometimes not work (retry or manually resolve).

PostgreSQL is great and makes sequences easier than ZODB does (at least
as far as I can tell), but it's hardly _impossible_ to have a working
sequence in ZODB, and it's not even difficult, it's just not trivial.

Jean-Paul



More information about the Python-list mailing list