On 11/29/2015 10:50 AM, Sami Pietilä wrote: > Hi, > > I have postgresql database with "records" table. There is "id" > (bigserial unique primary key) column. I need to insert a row in such a > way that I get id from newly inserted row. > > ins = records.insert() > results = conn.execute(ins) > > I was unable to find a code example of how to add "RETURNING" > functionality to records.insert() and how to find the id from the results.
Please refer to the SQL Expression Language Tutorial, specifically the last paragraph in this section: http://docs.sqlalchemy.org/en/rel_1_0/core/tutorial.html#executing Using the search box on the side of the documentation with the search term "returning", you'll get more links that describe both implicit and explicit use of RETURNING: http://docs.sqlalchemy.org/en/rel_1_0/core/connections.html?highlight=inserted_primary_key#sqlalchemy.engine.ResultProxy.inserted_primary_key http://docs.sqlalchemy.org/en/rel_1_0/core/dml.html#sqlalchemy.sql.expression.Insert.returning http://docs.sqlalchemy.org/en/rel_1_0/dialects/postgresql.html#insert-update-returning > > Thanks > > -- > You received this message because you are subscribed to the Google > Groups "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to sqlalchemy+unsubscr...@googlegroups.com > <mailto:sqlalchemy+unsubscr...@googlegroups.com>. > To post to this group, send email to sqlalchemy@googlegroups.com > <mailto:sqlalchemy@googlegroups.com>. > Visit this group at http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.