Code Monkey home page Code Monkey logo

Comments (3)

ahuang11 avatar ahuang11 commented on May 29, 2024

I think if you try SnowflakeConnector it should work (anything under the context manager should be executed as a transaction):


            from prefect_snowflake.credentials import SnowflakeCredentials
            from prefect_snowflake.database import SnowflakeConnector
            snowflake_credentials = SnowflakeCredentials(
                account="account",
                user="user",
                password="password",
            )
            snowflake_connector = SnowflakeConnector(
                database="database",
                warehouse="warehouse",
                schema="schema",
                credentials=snowflake_credentials
            )
            with snowflake_connector.get_connection() as connection:
                ...

https://docs.snowflake.com/en/user-guide/python-connector-example.html#using-context-manager-to-connect-and-control-transactions

from prefect-snowflake.

ahuang11 avatar ahuang11 commented on May 29, 2024

Perhaps something like this should rollback create and insert:

            from prefect_snowflake.database import SnowflakeConnector
            with SnowflakeConnector.load("BLOCK_NAME") as conn:
                conn.execute(
                    "CREATE TABLE IF NOT EXISTS customers (name varchar, address varchar);"
                )
                conn.execute_many(
                    "INSERT INTO customers (name, address) VALUES (%(name)s, %(address)s);",
                    seq_of_parameters=[
                        {"name": "Ford", "address": "Highway 42"},
                        {"name": "Unknown", "address": "Space"},
                        {"name": "Me", "address": "Myway 88"},
                    ],
                )
                raise
                result = conn.fetch_one(
                    "SELECT * FROM customers WHERE address = %(address)s",
                    parameters={"address": "Space"}
                )
                print(result)

from prefect-snowflake.

Bada-S avatar Bada-S commented on May 29, 2024

Closing issue with comment- will just use the SnowflakeConnector to accomplish this

from prefect-snowflake.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.