Search Postgresql Archives

Re: Looping through arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Remember to vote!

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux