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@fetter.org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778
Remember to vote!