Michael Bayer wrote:

>dischdennis wrote:
>  
>
>>what is the easiest way to find out the last insert id? (MySQL 5)
>>
>>supplast =
>>select([func.last_insert_id()],app_schema.SupplierTable.c.pr_supplier_ID
>>    
>>
>>>0).execute().fetchone()[0]
>>>      
>>>
>>does not work for some reason
>>
>>
>>Dennis
>>    
>>
>
>result = table.insert().execute(**kwargs)
>
>id = result.last_inserted_ids()[0]
>
># or, more mysql specific, but works with straight text SQL as well
>
>id = result.cursor.lastrowid
>
>
I would like to do that using the mapper, but...
In a PostgreSQL DB I have two tables Anag and User linked by Anag.c.id 
== User.c.anag_id
Anag.c.id is a serial type, after inserted the Anag row, I want to find 
the last id to insert it into the User table.
I tried this code using the command 
select([func.max(Anag.c.id)]).execute().fetchone()[0]
to have the last id, but it doesn't returns the last id but the previous 
one.

           anag = Anag(
                name    = 'pippo',
                address = 'rue cinc',
                )
            session.save(anag)
            session.flush()
            user = User(
                anag_id = 
select([func.max(Anag.c.id)]).execute().fetchone()[0]
                )

jo



--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to