在sqlite 中把列A的值转换成字符串存入列B
首先 sqlite 有一个cast 函数 ,可以强制转换类型,
其次 sqlite 不支持 update from 的写法。所以如果需要把筛选的结果存入某一列的话,可以采用
insert or replace 的方式
如
insert or replace
table1 (key,column1,column2)
select
table2 (key,column1,column2)
where
table1.key = table2.key
的形式
或者采用
update table1
set
column1 = (select column from table2 where table2.key = table1.key )
where table1.key = (select key from table2 where table2.key = table1.key)
的形式
第三 update 可以直接把列A的值赋值到列B,但是A列 和 B列的类型要一样 如
update table set A = B
就是把table中列B的值赋给列A。
本人最近所需要的就是类似于update table set A = B 的形式的操作,但是问题在于 列A为字符串,列B为长整型。本来以为需要cast做转换的。但是在多方实验之后发现可以直接拼接字符串。最后实现结果类似于
update table set A = ‘[’||B||']'
的形式
在sqlite 中 ,拼接字符串使用的是 || 符号。如果使用 + 的话,会默认把前后跟随的参数当作数字处理,如果是字符的话,默认为0