2

I am using Python SNowflake Connector 2.4.1 to connect Python to Snowflake getting following error

"Binding Parameter Must Be list While Using Python Snowflake Connector"

I am Binding Sample_JSON String Containing JSON to SQL Query String Using Qmark , The Table Column is VARIANT type in Snowflake

Sample_JSON="{\"ABC\":\"VALUE\"}"
snowflake.connector.paramstyle='qmark'
ctx = snowflake.connector.connect(
    user='something.com',,
      account=  'something',
    authenticator='externalbrowser'
    )

cs = ctx.cursor()

try:
       
cs.execute("INSERT INTO TABLE (JOSN) VALUES(?)",(Sample_JSON) )

finally:
    cs.close()
ctx.close()

1 Answer 1

2

looking at this execute many example

# A list of lists
sequence_of_parameters1 = [ ['Smith', 'Ann'], ['Jones', 'Ed'] ]
# A tuple of tuples
sequence_of_parameters2 = ( ('Cho', 'Kim'), ('Cooper', 'Pat') )

stmt2 = "insert into testy (v1, v2) values (?, ?)"
cs.executemany(stmt2, sequence_of_parameters1)
cs.executemany(stmt2, sequence_of_parameters2)

it would imply your code should be:

cs.execute("INSERT INTO TABLE (JOSN) VALUES(?)",( (Sample_JSON) ) )

or:

cs.execute("INSERT INTO TABLE (JOSN) VALUES(?)",[ [Sample_JSON] ] )
Sign up to request clarification or add additional context in comments.

1 Comment

Hi @Simeon Pilgrim thanks for answer the second option worked for me cs.execute("INSERT INTO TABLE (JOSN) VALUES(?)",[ [Sample_JSON] ] ) , thanks gain for your timely help

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.