Search code examples
pythonamazon-web-servicesamazon-s3jython

Error to Insert data into a AWS S3 database table using Python


I am trying to insert data into a AWS S3 database table using Python. I am getting optional second argument must be a list or tuple in error, for some reason, my data isn't getting inserted into the database. the code is below,

    import boto3
    s3 = boto3.resource('s3')
    bucket = s3.Bucket('testing')
    cursor = context.cursor()
    sql_data = [0,2,3,4,5,6]
    for x in sql_data:
        print(x)
        query =  "INSERT INTO items (id) VALUES (%s);"""
        cursor.execute(query, sql_data)
        #or
        #cursor.execute(query, x)

when i write / REPLACE ABOVE QUERY WITH below query it works but i want insert data from array.

"""insert into items (id) values (1)"""
"""insert into items (id) values (2)"""
"""insert into items (id) values (3)"""

I am getting optional second argument must be a list or tuple ERROR


Solution

  • Your syntax is wrong. Replace %s with ?