[Python] write_database(..., engine="adbc") with autocommit=False

Discussão em 'Python' iniciado por Stack, Setembro 10, 2025.

  1. Stack

    Stack Membro Participativo

    In polars, I would like to use pl.write_database multiple times with engine="adbc" in the same session and then commit all at the end with conn.commit(), i.e. do a manual commit.

    import adbc_driver_postgresql.dbapi as pg_dbapi
    import polars as pl

    conn = pg_dbapi.connect("postgresql://username:password@host:port/database")

    df = pl.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})

    df.write_database(
    "public.table1",
    connection=conn,
    engine="adbc",
    )

    df.transpose().write_database(
    "public.table2",
    connection=conn,
    engine="adbc",
    )

    conn.commit()


    The reason behind this is to ensure that either both dfs are written to the database or none are. However, the dfs are written immediately into the database one after the other. In the adbc docs, it is said:


    By default, connections are expected to operate in autocommit mode; that is, queries take effect immediately upon execution. This can be disabled in favor of manual commit/rollback calls, but not all implementations will support this.
    ​

    Is it supported to disable autocommit somehow in python? Maybe this can be done in adbc_driver_postgresql.dbapi.connect, maybe with the conn_kwargs parameter? conn_kwargs={"autocommit": False} didn't work.

    Continue reading...

Compartilhe esta Página