Is there a good way to split a string into multiple records?

Here is what I am trying to do...

I have a table "branch" with a column "branch_num" which has a comma
delimited list of numbers - the users weren't supposed to do this but they
did and now I have to fix it.  We want to create a new table "branch_area"
and move this comma delimited list into this new table as multiple records
before dropping the "branch_num" from the "branch" table.

branch {
   branch_id bigserial primary key,
   branch_num varchar(255)
}

branch_area {
   branch_area_id bigserial primary key,
   branch_id bigint foreign key to branch,
   branch_num varchar(10)
}

I want to migrate the data something like this:

insert into branch_area
(branch_id, branch_num)
select
   branch_id,
   -- This is the part I need help with -> split branch.branch_num on ','
from branch
;

Is there a good way (or alternative way) to do this?

Thanks!

--
==================================================================
  Aaron Bono
  Aranya Software Technologies, Inc.
  http://www.aranya.com
  http://codeelixir.com
==================================================================

Reply via email to