alim1990
alim1990

Reputation: 4972

Python and Snowflake error on insert with multiple binded variables

I need to insert data into a Snowflake table using Python connector. I used the following based on this link from Snowflake documentations:

cursor.execute("INSERT INTO survey_metadata(survey_metadata_id, survey_title, date_added, country_id, survey_types_id, survey_status, SECTOR_ABRV_ID,SURVEY_SIZE_BYTES, SURVEY_ROWS_NUMBER, SURVEY_COLS_NUMBER)"
                               "VALUES( %s, %s,%s, %s, %s, %s, %s, %s, %s, %s)", (nextval, filename, now, countries, sectors, survey_status, sectors,  survey_size_bytes,number_of_rows, number_of_columns))

sectors and other binded are variables whereas their values are set using a function executing some commands.

And I have received the following error:

ProgrammingError: 252004: Failed processing pyformat-parameters; 255001: Binding data in type (snowflakecursor) is not supported.

Any idea how to bind multiple variables in an INSERT query into Snowflake table?

Upvotes: 0

Views: 761

Answers (1)

alim1990
alim1990

Reputation: 4972

Apparently the main error was because I am getting the next value of a sequence before executing the insert query without looping over it to get the int itself instead of the whole tuple:

nextval = cursor.execute("SELECT AUTO_INCREMENT_ID_FOR_VARIANT_TABLE.nextval")

After doing this:

nextval = list(np.array(list(nextval)))
nextval = nextval[0][0]

The query worked.

Upvotes: 2

Related Questions