Deal with new line character “\n” in Sqlite database using Python?

后端 未结 2 1919
深忆病人
深忆病人 2021-01-28 15:00

I have a Sqlite database named test.db, which contains two tables with structures like this:

Table1: ID INTEGER PRIMARY KEY AUTOINCREMENT, Name varchar(500), Color varch

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-28 15:38

    Use the replace() SQL function:

    cur.execute("SELECT Color, Smell FROM Table1, Table2 "
                "WHERE replace(Table1.Name, '\n', '') = Table2.Name") 
    

    You can update your whole Table Name column to remove the newline characters altogether:

    cur.execute("UPDATE Table1 SET Name = replace(Name, '\n', '') "
                "WHERE Name like '%\n%'")
    

提交回复
热议问题