Proposal: generate_iterator functions - Mailing list pgsql-hackers

From Pavel Stehule
Subject Proposal: generate_iterator functions
Date
Msg-id 162867790710172220n1ab51d83kc9392f0ed6178cdb@mail.gmail.com
Whole thread Raw
Responses Re: Proposal: generate_iterator functions
List pgsql-hackers
Hello

this function can help with array's iteration.

create function generate_iterator(anyarray)
returns setof integer
as $$
select i from generate_series(array_lower($1,1),                                      array_upper($1,1)) g(i)
$$ language sql;

-- multidimensional
create function generate_iterator(anyarray, integer)
returns setof integer
as $$
select generate_series(array_lower($1,$2),                                     array_upper($1,$2)) g(i)
$$ language sql;

It can be internal function, not only shortcut for generate_series

sample:

create function array_sort(anyarray)
returns anyarray
as $$
select array(select $1[i] from generate_iterator($1) order by 1)
$$ language sql;


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: max_prepared_transactions default ... why 5?
Next
From: Bruce Momjian
Date:
Subject: Re: Release notes introductory text