0

I have a snowflake table and I am using the Snowflake Python Connector to insert value into it. Since I have a lot of data I am using a python generator object to insert value into my table.

conn = snowflake.connector.connect(...)
with conn.cursor() as write_cur:
    write_cur.executemany("INSERT INTO TABLE_1 VALUES (%s, %s)",
                          generator_data)

but this seems to throw an error that generator has no attribute len() . Is there anyway I can use an iterator to insert values into a snowflake table.

3
  • 1
    can u pls add your generator_data code Commented Mar 4, 2022 at 5:49
  • It will be a big code, you can consider something like this for now ((x,y) for x,y in zip(random.sample(range(1, 10000000), 30000000),random.sample(range(1, 10000000), 30000000))) Commented Mar 4, 2022 at 6:00
  • 1
    executemany function expecting an iterable that has a length Commented Mar 4, 2022 at 7:38

1 Answer 1

1

If possible don't do this - individual inserts are slow.

Instead batch collect all the values to insert, and then in one INSERT bring in all the rows.

But let's talk about the code in the question: There's nothing to iterate through. For cursor() to iterate, first you need results out of somewhere to iterate through.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.