geekcomputers / Python

My Python Examples
http://www.thegeekblog.co.uk
MIT License
31.03k stars 12.17k forks source link

Database pymysql #1263

Open VishalYewale opened 3 years ago

VishalYewale commented 3 years ago

How to add multiple values in single coloum in table like ddmmyyyy with different variables ??

RedPlumDragon commented 3 years ago

@VishalYewale I don't get what you mean.

RohanGupta404 commented 3 years ago

I think you can try to convert a list into a string and add it to the database, after that when you go to retrieve the data, convert the string back to list.

Inserting value into the table

valueToInsert = str(["first", "second", "third"]) mycursor.execute(f"INSERT INTO TableName ColumnName VALUES {valueToInsert}")

Getting value from the table

mycursor.execute("SELECT ColumnName FROM TableName") valueFromTable = mycursor.fetchone()