From: Aaron Bono <postgresql@aranya.com>
To: Lista PostgreSQL SQL <pgsql-sql@postgresql.org>
Subject: Split String Into Multiple Records
Date: Sat, 21 Apr 2007 18:47:20 -0500
Message-ID: <bf05e51c0704211647r21a6b529u75c8f13d4cfecaf4@mail.gmail.com> (raw)
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.comhttp://codeelixir.com
==================================================================
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: postgresql@aranya.com
Subject: Re: Split String Into Multiple Records
In-Reply-To: <bf05e51c0704211647r21a6b529u75c8f13d4cfecaf4@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox