'SQLAlchemy - Insert with returning

please how can i do in SQLAlchemy "Returninig value". In cx_Oralce i resolved like this and its working. a need value from column ID_PROCESS.

import cx_Oracle

self.conn = cx_Oracle.connect(connection_string, encoding="UTF-8", nencoding="UTF-8")

cursor = self.conn.cursor()
newest_id_wrapper = cursor.var(cx_Oracle.NATIVE_INT)
sql = f"""INSERT INTO {self.db_processesTable} (STR_PROCESS_NAME, USR_KDO, DAT_KDY_START, CIS_STAV)  values (:db_processName, :login, sysdate, 1) returning ID_PROCESS into :idProcess"""
var = {"db_processName": self.db_processName,
       "login": os.getlogin(),
       "idProcess": newest_id_wrapper}
cursor.execute(sql, var)
self.idProcess = newest_id_wrapper.getvalue()[0]
self.conn.commit()
cursor.close()

Thanks a lot! :) John



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source