我有一个包含 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}
--------------------------------------------------
如何在更新脚本中实现此目的?
谢谢
如何使用串联创建一个临时表,然后重命名它:
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;