我在PostgreSQL中有一个表,其中一列是包含名为directors的nconst的字符串。字符串的格式为nm00386378,nm97284993,我需要将每个字符串转换为一个数组,例如:{"nm00386378","nm97284993"}我尝试了以下代码,但我认为它只是将字符串转换为一个值数组:alter table crew_text alter directors drop default, alter directors type text[] using array[directors], alter directors set default '{}';我得到了数组值的{"nm00386378,nm97284993"},但我希望{"nm00386378","nm97284993"}。 最佳答案 像这样使用string_to_array():alter table crew_text alter directors drop default, alter directors type text[] using string_to_array(directors, ','), alter directors set default '{}';分贝小提琴here只在需要时使用正则表达式函数。这些更强大,但也更棘手,实质上更昂贵。
09-25 17:30