Home > Blockchain >  Issue during inserting data in sql database
Issue during inserting data in sql database

Time:06-09

I am trying to insert some data into SQL database using a python script, but I am facing an error, I am not sure why. Here is what I am doing

create_query = """INSERT INTO bcmdb.bcmdbuser.Groups (ParentGroupID, ChildGroupID, DirectChild) 
                           VALUES (100, ?, 0) """
record = (id_s)
cursor.execute(create_query, record)
conn.commit()

I am using "pypyodbc" to connect to database and its working fine, the issue this code produce is

TypeError: Params must be in a list, tuple or Row.

In cursor.execute(create_query, record) line specifically.

Any idea will be really appreciated.

CodePudding user response:

That's a problem with one-valued tuples in Python. They must have a trailing comma. Try like this:

create_query = """INSERT INTO bcmdb.bcmdbuser.Groups (ParentGroupID, ChildGroupID, DirectChild) 
                           VALUES (100, ?, 0) """
record = (id_s,)
cursor.execute(create_query, record)
conn.commit()
  • Related