Using python sqlalchemy to execute raw queries with WITH statement

前端 未结 2 1423
北海茫月
北海茫月 2021-01-27 03:05

I\'m trying to insert values into a Postgres11 database with raw sqlalchemy text() queries. The following SQL query works correctly when I run it through psql-clien

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-27 03:47

    I had a similar issue and the following code helped me. Without the conn.execute("COMMIT;") part, I was not able to see all my changes reflected in my database.

    with self.engine.begin() as conn:
        conn.execute(sql_query)
        conn.execute("COMMIT;")
    

提交回复
热议问题