python - Get just inserted data id in sqlalchemy?
迷茫
迷茫 2017-06-12 09:25:12
0
2
1161
from sqlalchemy import text
conn=engine.connect();
s=text("insert into aws_rcsy(topic)values(:topic)");

q_insert=conn.execute(s,topic=topic);
conn.close();

How to get the id of the data just inserted?

ps:q_insert returns <sqlalchemy.engine.base.ResultProxy object at 0x...>
Can row data be obtained from q_insert?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
phpcn_u1582

q.lastrowid

仅有的幸福

The code copied has not been verified

rslt_id = conn.execute("INSERT INTO user (name, country_id) VALUES ('Homer', 123)
                        RETURNING id")

Reference stack-overflow

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template