Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow running DML queries with execute_code() #115

Open
trymzet opened this issue Aug 28, 2023 · 0 comments
Open

Allow running DML queries with execute_code() #115

trymzet opened this issue Aug 28, 2023 · 0 comments

Comments

@trymzet
Copy link

trymzet commented Aug 28, 2023

It requires explicitly committing the transaction. Below simplified snippet worked for me; this functionality could be added eg. as a commit param to execute_code()?

adapter = DbtProject().adapter
with adapter.connection_named("__x__"):
    conn = adapter.connections.get_thread_connection()
    cursor = conn.handle.cursor()
    try:
        cursor.execute(sql)
        conn.handle.commit()
    except:
        conn.transaction_open = False

I found this algorithm in https://github.com/dbt-labs/dbt-core/blob/1.5.latest/core/dbt/adapters/sql/impl.py#L222-L241C42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant