Reputation: 63
I have a table with x columns and i need drop 4 of them, but before i need transform these columns into varchar in json format.
Example
how is now
car
-----------------------------
id name color year HP
-- ------ ------ ---- ---
1 porche green 2014 350
the result i need after drop 3 columns and create detail column
car
--------------------------------------------------
id name detail
-- ------ -------------------------------------
1 porche {color: 'green', year: 2014, HP: 350}
--------------------------------------------------
How can i achieve this in update script?
Thanks
Upvotes: 0
Views: 125
Reputation: 39457
How about creating a temporary table using concatenations and then renaming it:
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;
Upvotes: 2