patch: array_ndims
After reading Josh Berkus's email suggesting that the intagg module be
dropped, I was wondering what would be required to create a array
enumerator (variously called unnest, unroll, array_enum, and, as
contemplated by the TODO list, array_to_set). Pavel Stehule's
generate_subscripts function provides most of what is needed -
however, you need to know the number of dimensions in the array, and
it appears we don't have a function to provide that information, at
least not in a straightforward fashion. That seems like a pretty
useful thing to have anyway, so here's a patch to add it.
If you apply it, you can then used the attached PL/pgsql
implementation of array_to_set(). I am sure that it would be better
and more efficient to implement this directly in C, but as no one has
gotten around to that yet this might be kind of handy. It might even
be worth adding to the docs, though I'm not sure exactly where.
rhaas=# SELECT * FROM array_to_set(ARRAY[1,2,3,4]);
array_to_set
--------------
1
2
3
4
(4 rows)
rhaas=# SELECT * FROM array_to_set(ARRAY[[1,2,3,4]]);
array_to_set
--------------
1
2
3
4
(4 rows)
rhaas=# SELECT * FROM array_to_set(ARRAY[[[1,2,3,4]]]);
array_to_set
--------------
1
2
3
4
(4 rows)
rhaas=# SELECT * FROM array_to_set(ARRAY[[[[1,2,3,4]]]]);
array_to_set
--------------
1
2
3
4
(4 rows)
rhaas=# SELECT * FROM array_to_set(ARRAY[[[[[1,2,3,4]]]]]);
array_to_set
--------------
1
2
3
4
(4 rows)
rhaas=# SELECT * FROM array_to_set(ARRAY[[[[[[1,2,3,4]]]]]]);
array_to_set
--------------
1
2
3
4
(4 rows)
...Robert
Hello
we talked about these features, but these functionality is solved with
UNNEST operator
http://farrago.sourceforge.net/design/CollectionTypes.html - so if you
like this functionality (I believe, so want it), please implement
UNNEST operator.
Regards
Pavel Stehule
http://www.ibm.com/developerworks/db2/library/techarticle/dm-0710arocena/index.html
2008/10/11 Robert Haas <robertmhaas@gmail.com>:
Show quoted text
After reading Josh Berkus's email suggesting that the intagg module be
dropped, I was wondering what would be required to create a array
enumerator (variously called unnest, unroll, array_enum, and, as
contemplated by the TODO list, array_to_set). Pavel Stehule's
generate_subscripts function provides most of what is needed -
however, you need to know the number of dimensions in the array, and
it appears we don't have a function to provide that information, at
least not in a straightforward fashion. That seems like a pretty
useful thing to have anyway, so here's a patch to add it.If you apply it, you can then used the attached PL/pgsql
implementation of array_to_set(). I am sure that it would be better
and more efficient to implement this directly in C, but as no one has
gotten around to that yet this might be kind of handy. It might even
be worth adding to the docs, though I'm not sure exactly where.rhaas=# SELECT * FROM array_to_set(ARRAY[1,2,3,4]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[1,2,3,4]]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[[1,2,3,4]]]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[[[1,2,3,4]]]]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[[[[1,2,3,4]]]]]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[[[[[1,2,3,4]]]]]]);
array_to_set
--------------
1
2
3
4
(4 rows)...Robert
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
There's nothing in that functionality that contemplates
multi-dimensional arrays. Since we have multi-dimensional arrays,
oughtn't we provide the basic functions to deal with them?
array_ndims has got to be at least as useful as array_dims (which
returns an difficult-to-parse chunk of text).
...Robert
Show quoted text
On Sat, Oct 11, 2008 at 2:29 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
Hello
we talked about these features, but these functionality is solved with
UNNEST operator
http://farrago.sourceforge.net/design/CollectionTypes.html - so if you
like this functionality (I believe, so want it), please implement
UNNEST operator.Regards
Pavel Stehulehttp://www.ibm.com/developerworks/db2/library/techarticle/dm-0710arocena/index.html
2008/10/11 Robert Haas <robertmhaas@gmail.com>:
After reading Josh Berkus's email suggesting that the intagg module be
dropped, I was wondering what would be required to create a array
enumerator (variously called unnest, unroll, array_enum, and, as
contemplated by the TODO list, array_to_set). Pavel Stehule's
generate_subscripts function provides most of what is needed -
however, you need to know the number of dimensions in the array, and
it appears we don't have a function to provide that information, at
least not in a straightforward fashion. That seems like a pretty
useful thing to have anyway, so here's a patch to add it.If you apply it, you can then used the attached PL/pgsql
implementation of array_to_set(). I am sure that it would be better
and more efficient to implement this directly in C, but as no one has
gotten around to that yet this might be kind of handy. It might even
be worth adding to the docs, though I'm not sure exactly where.rhaas=# SELECT * FROM array_to_set(ARRAY[1,2,3,4]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[1,2,3,4]]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[[1,2,3,4]]]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[[[1,2,3,4]]]]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[[[[1,2,3,4]]]]]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[[[[[1,2,3,4]]]]]]);
array_to_set
--------------
1
2
3
4
(4 rows)...Robert
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
To put that another way, there are other potential uses of this
function. For example, how would you suggest that someone do this?
CREATE TABLE foo (
id serial,
bar int[],
CHECK (array_ndims(bar) = 3)
);
You can hack something together, but it's not particularly nice.
...Robert
Show quoted text
On Sat, Oct 11, 2008 at 7:53 AM, Robert Haas <robertmhaas@gmail.com> wrote:
There's nothing in that functionality that contemplates
multi-dimensional arrays. Since we have multi-dimensional arrays,
oughtn't we provide the basic functions to deal with them?
array_ndims has got to be at least as useful as array_dims (which
returns an difficult-to-parse chunk of text)....Robert
On Sat, Oct 11, 2008 at 2:29 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
Hello
we talked about these features, but these functionality is solved with
UNNEST operator
http://farrago.sourceforge.net/design/CollectionTypes.html - so if you
like this functionality (I believe, so want it), please implement
UNNEST operator.Regards
Pavel Stehulehttp://www.ibm.com/developerworks/db2/library/techarticle/dm-0710arocena/index.html
2008/10/11 Robert Haas <robertmhaas@gmail.com>:
After reading Josh Berkus's email suggesting that the intagg module be
dropped, I was wondering what would be required to create a array
enumerator (variously called unnest, unroll, array_enum, and, as
contemplated by the TODO list, array_to_set). Pavel Stehule's
generate_subscripts function provides most of what is needed -
however, you need to know the number of dimensions in the array, and
it appears we don't have a function to provide that information, at
least not in a straightforward fashion. That seems like a pretty
useful thing to have anyway, so here's a patch to add it.If you apply it, you can then used the attached PL/pgsql
implementation of array_to_set(). I am sure that it would be better
and more efficient to implement this directly in C, but as no one has
gotten around to that yet this might be kind of handy. It might even
be worth adding to the docs, though I'm not sure exactly where.rhaas=# SELECT * FROM array_to_set(ARRAY[1,2,3,4]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[1,2,3,4]]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[[1,2,3,4]]]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[[[1,2,3,4]]]]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[[[[1,2,3,4]]]]]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[[[[[1,2,3,4]]]]]]);
array_to_set
--------------
1
2
3
4
(4 rows)...Robert
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
2008/10/11 Robert Haas <robertmhaas@gmail.com>:
There's nothing in that functionality that contemplates
multi-dimensional arrays. Since we have multi-dimensional arrays,
oughtn't we provide the basic functions to deal with them?
array_ndims has got to be at least as useful as array_dims (which
returns an difficult-to-parse chunk of text).
I am sorry, It was noise from me. I don't thing so array_ndims is
dificult parsered, but it's boondoggle. So some variants as
array_ndims should be usefull.
Regards
Pavel Stehule
Show quoted text
...Robert
On Sat, Oct 11, 2008 at 2:29 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
Hello
we talked about these features, but these functionality is solved with
UNNEST operator
http://farrago.sourceforge.net/design/CollectionTypes.html - so if you
like this functionality (I believe, so want it), please implement
UNNEST operator.Regards
Pavel Stehulehttp://www.ibm.com/developerworks/db2/library/techarticle/dm-0710arocena/index.html
2008/10/11 Robert Haas <robertmhaas@gmail.com>:
After reading Josh Berkus's email suggesting that the intagg module be
dropped, I was wondering what would be required to create a array
enumerator (variously called unnest, unroll, array_enum, and, as
contemplated by the TODO list, array_to_set). Pavel Stehule's
generate_subscripts function provides most of what is needed -
however, you need to know the number of dimensions in the array, and
it appears we don't have a function to provide that information, at
least not in a straightforward fashion. That seems like a pretty
useful thing to have anyway, so here's a patch to add it.If you apply it, you can then used the attached PL/pgsql
implementation of array_to_set(). I am sure that it would be better
and more efficient to implement this directly in C, but as no one has
gotten around to that yet this might be kind of handy. It might even
be worth adding to the docs, though I'm not sure exactly where.rhaas=# SELECT * FROM array_to_set(ARRAY[1,2,3,4]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[1,2,3,4]]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[[1,2,3,4]]]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[[[1,2,3,4]]]]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[[[[1,2,3,4]]]]]);
array_to_set
--------------
1
2
3
4
(4 rows)rhaas=# SELECT * FROM array_to_set(ARRAY[[[[[[1,2,3,4]]]]]]);
array_to_set
--------------
1
2
3
4
(4 rows)...Robert
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Robert Haas wrote:
After reading Josh Berkus's email suggesting that the intagg module be
dropped, I was wondering what would be required to create a array
enumerator (variously called unnest, unroll, array_enum, and, as
contemplated by the TODO list, array_to_set). Pavel Stehule's
generate_subscripts function provides most of what is needed -
however, you need to know the number of dimensions in the array, and
it appears we don't have a function to provide that information, at
least not in a straightforward fashion. That seems like a pretty
useful thing to have anyway, so here's a patch to add it.
I have committed your array_ndims function with the addition of a small
regression test, and I changed the return type to integer because that
is what the rest of the array functions use for dimension information as
well.