Re: Looping through arrays

Поиск
Список
Период
Сортировка
От David Fetter
Тема Re: Looping through arrays
Дата
Msg-id 20051104051846.GA22736@fetter.org
обсуждение исходный текст
Ответ на Looping through arrays  (Robert Fitzpatrick <lists@webtent.net>)
Список 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@fetter.org http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!

В списке pgsql-general по дате отправления:

Предыдущее
От: Michael Fuhr
Дата:
Сообщение: Re: Looping through arrays
Следующее
От: Joe Conway
Дата:
Сообщение: Re: Looping through arrays