且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将数据从另一表的一列拆分为三列?的SQL

更新时间:2022-12-11 19:06:23

有很多方法可以做到这一点. 一种方法是使用 string_to_array 函数:

There is many ways to do this. One way is using the string_to_array function:

INSERT INTO hobbies (id, hobby1, hobby2, hobby3) 
SELECT id,hobbies_array[1],hobbies_array[2],hobbies_array[3] FROM 
  (
    SELECT id,string_to_array(hobbies,',') AS hobbies_array 
    FROM inf
  ) AS foo;