From: | "Aaron Bono" <postgresql(at)aranya(dot)com> |
---|---|
To: | "Lista PostgreSQL SQL" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Split String Into Multiple Records |
Date: | 2007-04-21 23:47:20 |
Message-ID: | bf05e51c0704211647r21a6b529u75c8f13d4cfecaf4@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
==================================================================
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2007-04-22 02:13:32 | Re: Split String Into Multiple Records |
Previous Message | Richard Doust | 2007-04-21 16:03:18 | Regular Expression Data Type |