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.
>   
I have a similar use case (for images and xml files), I use the wine 
name and vintage (easier for the user if ever they look for a particular 
image in the file system and want to use it outside my app) and primary 
key (just to make sure that it is unique), but in my case I can do it 
after having flush'ed.
> 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 
Based on Michael's post you can keep partial portability by manually 
getting it using the Sequence.

I was intriged and wanted to figure out how to get at the sequence 
defined in the model.

Is the following really the only way to get at it?  I am using 
ORM/declarative.

seq = sa.Sequence(l.__table__.c.langid.default.name)

nextid = engine.execute(seq)

Werner


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