Yay! I solved it. Thanks for making such a great module.
>> result =
>> meta.Session.execute(model.names_table.insert(postgres_returning=[model.names_table.c.id]),
>> [{'name': x} for x in names])
>> result.fetchall()
[(40,), (41,), (42,)]
On Thu, Apr 9, 2009 at 6:05 PM, Roy Hyunjin Han
<[email protected]> wrote:
> I'm trying to use SQLAlchemy's executemany syntax in PostgreSQL and
> get the last_inserted_ids().
> What is the recommended way to get these last_inserted_ids()?
>
> I know that I can access the id attribute for each model instance but
> there are hundreds of inserted rows and I would rather retrieve them
> all at once.
>
> Thanks,
> RHH
>
>
>
>>> names = ['ted', 'steve', 'mike']
>
>>> result = meta.Session.execute(model.names_table.insert(), [{'name': x} for
>>> x in names])
>
>>> result.last_inserted_ids()
> Traceback (most recent call last):
> File
> "/usr/lib/python2.5/site-packages/WebError-0.10.1-py2.5.egg/weberror/evalcontext.py",
> line 35, in exec_expr
> exec code in self.namespace, self.globs
> File "<web>", line 1, in <module>
> File
> "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/engine/base.py",
> line 1560, in last_inserted_ids
> return self.context.last_inserted_ids()
> File
> "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/engine/default.py",
> line 284, in last_inserted_ids
> return self._last_inserted_ids
> AttributeError: 'PGExecutionContext' object has no attribute
> '_last_inserted_ids'
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---