我有一个包含x列的表,我需要删除其中的4个,但在我需要将这些列转换为json格式的varchar之前。
实施例
现在怎么样?
car
-----------------------------
id name color year HP
-- ------ ------ ---- ---
1 porche green 2014 350
删除3列后我需要的结果并创建详细列
car
--------------------------------------------------
id name detail
-- ------ -------------------------------------
1 porche {color: 'green', year: 2014, HP: 350}
--------------------------------------------------
如何在更新脚本中实现此目的?
由于
答案 0 :(得分:2)
如何使用连接创建临时表,然后重命名它:
create table your_table_new as
select
id, name, '{color: ''' || color || ''', year: ' || year || ', HP: ' || HP || '}' as detail
from your_table;
drop table your_table;
rename your_table_new to your_table;