[sqlalchemy] Re: Creating something with a unique, random key

2009-05-24 Thread Iwan
Adrian, On May 22, 7:45 pm, Adrian von Bidder wrote: > I guess you just have to query for your string to see if it's unique.   > Performance-wise it shouldn't make a difference, and in Python, I usually > find a simple if even nicer than a try-except block. Yup, thanks, that is what we are doin

[sqlalchemy] Re: Creating something with a unique, random key

2009-05-24 Thread Iwan
Michael, On May 22, 6:03 pm, "Michael Bayer" wrote: > have you considered using some more industrial strength "randomness", like > GUIDs generated from the current timestamp or similar ?    the python uuid > module works very well for this. That's probably the direction I'd go - just wanted to

[sqlalchemy] Re: Creating something with a unique, random key

2009-05-22 Thread Adrian von Bidder
On Friday 22 May 2009 12.01:05 Iwan wrote: > Naïvely, I thought you'd create an X, flush it, and then catch any > IntegrityError's thrown. [...] I know that PostgreSQL can't continue in a transaction after an error, you have to roll back the transaction. I don't know what the SQL standard says

[sqlalchemy] Re: Creating something with a unique, random key

2009-05-22 Thread Michael Bayer
Iwan wrote: > > Hi there, > > I am working with SqlAlchemy for the first time (coming from > SqlObject), and I fear I may not understand it as well as I thought I > did... > > I have a class (X), persisted with SA which contains a key (X.key) > which is a randomly generated string of fixed length.