search

Home  >  Q&A  >  body text

python - Get just inserted data id in sqlalchemy?

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?

迷茫迷茫2730 days ago1154

reply all(2)I'll reply

  • phpcn_u1582

    phpcn_u15822017-06-12 09:27:12

    q.lastrowid

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-06-12 09:27:12

    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

    reply
    0
  • Cancelreply