Hi,

I am running into something

I am using MySQL but am moving to Postgress so I'm looking for something 
compatible with the two.

I have to generate an unique number for each record created into a column 
separate from the Id, call it SerialNumber

I have found the Sequence object.

Say I make the following class:


class Order(Base):
        __tablename__   =  'product'
        Id                              = Column(Integer, primary_Key=True)
        SerialNr                        = Column(Integer, 
Sequence('SerialNumber'))


after the create_all()

CreateSequence('SerialNumber')

All fine.

Now I need to import data from the current production system. This data already 
has Serialnumbers generated.

What should I do to make this work? Do I need the sequence created after the 
Import and set the Start value to the last imported SerialNumber+1 ?
I would prefer creating the sequence before the import and "Update" the 
Sequence after the import.

I can also "Drop" and Recreate after the import. The Import will be done 
several times during the test period. After the code is in production, I'll 
never ever need to modify the seqence anymore.
Adding another table with just one column and setting SerialNr as a ForeignKey 
might be a solution too (As SerialNr will also be a coded as a 4 character 
string which needs to be in the database for compatability reasons)
I prefer the sequence though.

My real code is much more complex, the above example class is simplified. In 
fact Order is a polymorphic base table and the sequence Column is in the 
polymorphic "child" tables only where Orders are in fact Items to be produced. 
The simplified version above is just to make things clear. 

Martijn

-- 
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.

Reply via email to