Hi there,

I'm accessing a postgres database and would like to use the
session.execute(Sequence('sequence_name')) syntax to get the next id
for a table without actually saving the table. This all works fine if
I know the sequence_name, but I was hoping to write generic code. Is
it possible, using sqlalchemy, to discover the name of the sequence on
a particular table. Basically, I'm looking for the equivalent of the
postgres expression

select pg_get_serial_sequence('table_name', 'column_name');

The best I've come up with so far is pretty ugly!:

rs = engine.execute("select nextval(pg_get_serial_sequence('" +
self.orm_table._sa_class_manager.mapper.local_table.name + "',
'id'))")

new_id = rs.fetchone()['nextval']

Is there a more alchemized way of getting the next value, or barring
that, is there a way I can get the table from the orm object a bit
more elegantly?

Thanks,
Dusty
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to