【问题标题】:sqlite, how replace a value from CSV saved in a columnsqlite,如何从保存在列中的CSV替换值
【发布时间】:2019-08-13 11:32:38
【问题描述】:

我的 android 应用程序中有一个表,其中有一列名为 tags,该列可以包含一个或多个逗号分隔值,例如:

test1,test,test2

现在我想重命名整个表中的这些值之一,我有以下查询:

update mytable
set 
    tags = replace (tags, ',test,',',XXX,') // rename test with XXX
where
    tags like '%,test,%' 

只要值在逗号之间,就可以正常工作。

如果我的值位于 csv 的开头或结尾,或者是 csv 中的唯一值,我该如何实现这一点。

【问题讨论】:

    标签: android sqlite csv replace rename


    【解决方案1】:

    您需要在列的开头和结尾附加逗号并对其进行操作:

    update mytable
    set 
        tags = trim(replace(',' || tags || ',', ',test,', ',XXX,'), ',')
    where
        ',' || tags || ',' like '%,test,%';
    

    demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-25
      • 2021-11-28
      • 2018-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-07
      相关资源
      最近更新 更多