The mysql insert statement in flask reported an error: 1241, 'Operand should contain 1 column (s)

The code in

view.py is as follows:

.
c_location = request.form.getlist ("centering location")

    connection = db.engine.connect()
    mysql = text(
        "INSERT INTO livingexpenses_coal (c_location) values (:m);"
    )
    result = connection.execute(mysql,m=c_location)

.

now an error has been reported:
sqlalchemy.exc.OperationalError: (_ mysql_exceptions.OperationalError) (1241, "Operand should contain 1 column (s)") [SQL: "INSERT INTO livingexpenses_coal (c_location) values (% s);"] [parameters: (["1asdfeld," 5"])] (Background on this error at: http://sqlalche.me/e/e3q8)

that is, c_location is now an array and cannot input values, but the normal sql statement can use:
INSERT INTO table name (column name, column name) VALUES (column value, column value), (column value); to insert multiple data at one time. Please tell me how to modify my code. Thank you very much.


c_location since it is an array, you should take a single element as the SQL parameter, such as

    connection = db.engine.connect()
    mysql = text(
        "INSERT INTO livingexpenses_coal (c_location) values (:m);"
    )
    result = connection.execute(mysql,m=c_location[0])

or format the entire array (if possible), such as

    connection = db.engine.connect()
    mysql = text(
        "INSERT INTO livingexpenses_coal (c_location) values (:m);"
    )
    result = connection.execute(mysql,m=';'.join(c_location))
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2bd54-2baad.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2bd54-2baad.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?