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

后端 未结 2 1880
深忆病人
深忆病人 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:33

    The first thing you should do is fix your tables so that the data is correct for your application. It looks like you have data like Apple\n in your table's name column.

    Run this query to fix your table:

    UPDATE Table1 SET Name = rtrim(Name,'\n')
    

    That will remove all \n from the right side of the value of the Name column in each row, and then update that row.

    Edit: @Martijn's answer will allow your query to work (assuming you don't have the same problem with Table2.Name), but you should really fix the data in your tables so that you don't have to remember to do these workarounds everytime.

提交回复
热议问题