On May 17, 2009, at 9:40 AM, paniq303 wrote:
> As an example: three records are created, with ids 1, 2 and 3. Now the > record with id 3 is being deleted. We create a new record, and this > record will get id 3 again, instead of id 4. In this way, there can be > confusion between the old and the new record with id 3. > > If the primary key has been declared as AUTOINCREMENT, new id's will > never correlate with previously deleted ones. This makes tracking an > item much easier, for both relating records in other tables, and > external routines dealing with undo/redo and diff'ing databases. > > Without this feature, I can't use SQLAlchemy. It would cause more > trouble than it solves. also, not to detract from my acceptance of a proper patch in this regard, but the use case you describe above would be better handled using GUIDs for primary keys instead of arbitrarily generated integers, particularly since you mention use cases like diffing databases and such. a GUID that is deterministically generated from other data in the row would is ideal since running the same data into different databases produces the same primary keys in all cases. Randomly generated GUIDs are more portable than sequence generated integers too. I'm using deterministic GUIDs in my current project. An example generating from two columns to be inserted "col1" and "col2": import uuid namespace = uuid.uuid5(uuid.NAMESPACE_URL, "my_database") def get_guid(ctx): params = ctx.parameters['col1'], ctx.parameters['col2'] return str(uuid.uuid5(namespace, str(params))) t = Table('mytable', metadata, Column('id', String, default=get_guid, primary_key=True)) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---