遇到某些场景,字段是用逗号隔开的,比如a表这个grid_code,需要拆分成多行

简单例子

– 将逗号分隔的字符串转为多行, 可直接执行sql
SELECT unnest(string_to_array('4513,4564,555',',')) as a1;

解决问题

SELECT unnest(string_to_array(grid_code,',')) AS grid_code FROM red_armbands_activity
效果:

如果其他字段也需要展示,直接在select后面加上就可以, 比如id
SELECT id, unnest(string_to_array(grid_code,',')) AS grid_code FROM red_armbands_activity