Using python sqlalchemy to execute raw queries with WITH statement

前端 未结 2 1385
北海茫月
北海茫月 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;")
    
    0 讨论(0)
  • 2021-01-27 03:53

    My question got answered on github.

    The solution is to wrap the execute in a transaction context:

    with engine.begin() as conn:
       conn.execute("whatever")
    
    0 讨论(0)
提交回复
热议问题