Split String Into Multiple Records - Mailing list pgsql-sql

From Aaron Bono
Subject Split String Into Multiple Records
Date
Msg-id bf05e51c0704211647r21a6b529u75c8f13d4cfecaf4@mail.gmail.com
Whole thread Raw
Responses Re: Split String Into Multiple Records  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Is there a good way to split a string into multiple records?<br /><br />Here is what I am trying to do...<br /><br />I
havea table "branch" with a column "branch_num" which has a comma delimited list of numbers - the users weren't
supposedto do this but they did and now I have to fix it.  We want to create a new table "branch_area" and move this
commadelimited list into this new table as multiple records before dropping the "branch_num" from the "branch" table.
<br/><br />branch {<br />    branch_id bigserial primary key,<br />    branch_num varchar(255)<br />}<br /><br
/>branch_area{<br />    branch_area_id bigserial primary key,<br />    branch_id bigint foreign key to branch,<br />   
branch_numvarchar(10) <br />}<br /><br />I want to migrate the data something like this:<br /><br />insert into
branch_area<br/>(branch_id, branch_num)<br />select<br />    branch_id,<br />    -- This is the part I need help with
->split branch.branch_num on ',' <br />from branch<br />;<br /><br />Is there a good way (or alternative way) to do
this?<br/><br />Thanks!<br clear="all" /><br />-- <br
/>==================================================================<br/>   Aaron Bono<br />   Aranya Software
Technologies,Inc. <br />   <a href="http://www.aranya.com">http://www.aranya.com</a><br />   <a
href="http://codeelixir.com">http://codeelixir.com</a><br
/>================================================================== 

pgsql-sql by date:

Previous
From: Steve Crawford
Date:
Subject: Re: Question on interval
Next
From: Tom Lane
Date:
Subject: Re: Split String Into Multiple Records