if its of any value, databases like MySQL and SQLIte do not give you any way to get at an auto-generated ID without actually INSERTing a row. Only databases that support sequences, i.e. postgres, firebird, and oracle, give you a built in way to get IDs without using INSERT.
On May 23, 2009, at 8:25 AM, Adrian von Bidder wrote: > On Friday 22 May 2009 23.00:05 Werner F. Bruhin wrote: >> What do you want to do with the autoincrement column? Often these >> are >> used for primary keys, which in turn get used as foreign keys. > > I want to use the id as filename; the table will cache some info > that comes > from the file. Using it as a filename directly has several > advantages: > * I don't have to care about a unique filename, since the db already > takes > care of that. > * I don't have to create an additional column with the filename. > > Obviously, I can just first create the file with a temp filename, > but I'd > like to avoid this additional step if it's possible. Less code == > fewer > bugs. And I hoped that using the id from the beginning would be > easily > possible. > > Right now, I'm undecided if I should just drop portability and fetch > the > next value from the mytable_id_seq that postgres has generated for > me with > the autoincrement columns (from what I understand, even if I declare > the > column autoincrement, if I set the id manually it will Just Work(tm) > like it > should or if I should go the temporary filename route. I'm leaning > towards > the former because I probably will drop portability at some point in > any > case, since PostgreSQL just has too many cool features waiting to be > used > :-) > > (And no, I'm not going to use blobs and store the file as a large > object in > the db. Relational databases are not made for this, and besides it > makes > the db harder to maintain because db dumps get huge or the blobs > have to be > backed up separately, and debugging is harder because I can't use > shell > tools to get at the file data.) > > (So you see, I'm not trying to build foreign keys by hand or any > such thing. > I actually know relational databases quite well, it's just my > knowledge of > SQLAlchemy and Python which is lacking.) > > thanks > -- vbi > > -- > Alle Wirksamkeit ist stärker am Mittelpunkt als gegen die > Peripherie zu. Raum zwischen Mars und Jupiter. > -- Goethe, Maximen und Reflektionen, Nr. 1336 > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
