From: | David Fetter <david(at)fetter(dot)org> |
---|---|
To: | robert(at)webtent(dot)com |
Cc: | PostgreSQL <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Looping through arrays |
Date: | 2005-11-04 05:18:46 |
Message-ID: | 20051104051846.GA22736@fetter.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, Nov 03, 2005 at 06:15:08PM -0500, Robert Fitzpatrick wrote:
> I have a field with 'AA-BB-CC-DD' and I want to pull those four
> values into an array and then loop through the array inserting
> records into a table for each element. Can you someone point me to
> an example of this in pl/pgsql?
You can do it in SQL, at least in 8.0 and later :)
INSERT INTO bar(blurf)
SELECT (string_to_array('AA-BB-CC-DD','-'))[s.i] AS "foo"
FROM generate_series(
array_lower(string_to_array('AA-BB-CC-DD','-'),1),
array_upper(string_to_array('AA-BB-CC-DD','-'),1)
) AS s(i);
Cheers,
D
--
David Fetter david(at)fetter(dot)org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778
Remember to vote!
From | Date | Subject | |
---|---|---|---|
Next Message | MaXX | 2005-11-04 06:44:08 | Re: Changing ids conflicting with serial values? |
Previous Message | Robert Treat | 2005-11-04 05:07:18 | Re: rh7.3 binaries |