Skip site navigation (1) Skip section navigation (2)

patch: array_ndims

From: "Robert Haas" <robertmhaas(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: patch: array_ndims
Date: 2008-10-11 02:37:20
Message-ID: 603c8f070810101937n776c1e7cvd6a12345b0bbda28@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackers
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

Attachment: array_to_set.sql
Description: application/octet-stream (1.2 KB)
Attachment: array_ndims-v1.patch
Description: text/x-diff (3.6 KB)

Responses

pgsql-hackers by date

Next:From: Joshua TolleyDate: 2008-10-11 03:27:22
Subject: Re: \ef should probably append semicolons
Previous:From: Robert HaasDate: 2008-10-11 01:26:41
Subject: Re: The Axe list

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group