Support for array_remove and array_replace functions
Hi,
following Gabriele's email regarding our previous patch on "Foreign
Key Arrays"[1]http://archives.postgresql.org/message-id/4FD8F422.40709%402ndQuadrant.it, I am sending a subset of that patch which includes only
two array functions which will be needed in that patch: array_remove
(limited to single-dimensional arrays) and array_replace.
The patch includes changes to the documentation.
Cheers,
Marco
[1]: http://archives.postgresql.org/message-id/4FD8F422.40709%402ndQuadrant.it
--
Marco Nenciarini - 2ndQuadrant Italy
PostgreSQL Training, Services and Support
marco.nenciarini@2ndQuadrant.it | www.2ndQuadrant.it
Attachments:
On Thu, Jun 14, 2012 at 4:41 AM, Marco Nenciarini <
marco.nenciarini@2ndquadrant.it> wrote:
Hi,
following Gabriele's email regarding our previous patch on "Foreign
Key Arrays"[1], I am sending a subset of that patch which includes only
two array functions which will be needed in that patch: array_remove
(limited to single-dimensional arrays) and array_replace.
The patch includes changes to the documentation.
Hi, I've been reviewing this patch.
Good documentation, and regression tests. The code looked fine but I didn't
care for the code duplication between array_replace and array_remove so I
merged those into a helper function, array_replace_internal(). Thoughts?
Other than that it all looks good to me.
Attachments:
array-functions_v2.patch.bz2application/x-bzip2; name=array-functions_v2.patch.bz2Download
BZh91AY&SY5� M "���s���?�������`~x=_j�7��T��������8}�s���^�w�������J:���D�i�?CM!�4�SjzF��i��h��4z��h ��0S�i�oQz4yh 4 h i���M � � &�D��?JoT���h���OQ� � �IS%<�z����M
3P A��@4 $ ���4e2����2$�F�������� bmL�o[�F
��� �dFBE�,X�F ��z~������[
���,��{+��V�ai��M�?����(�=���i�x�EP�B��U�1ED�h�+�*��X���-U@@`�0�'���#���{�6��&wC��dgi������JuM��m�YSy�����%S����AN�]3��.��sY$�T�;�P�&Pbr��A���gBj�'W������?M]���R�#"�h��(r�2�-�
��Q3���M!XX��Ft2hN�Mh��
��p����^�N��Y��0����"�}f+m��k��������� �@����Ud2HE���"���$�+`�(�b6-.��60"F{"��1���C������������o���,���!,~u@eH�dDeU�6P�6'�r�|���5��;U�(���������w��G1�&�������s��XH���=�M��M�?6����n���LYaZ��v�f����U�pt^9[J�r!����)�b����E�9 ��N�����
����M tL�I:�]w
��IK���|�l�U��M��_����5��+���B��ce�O�AC�}\�k��v� ���2�����qR:�7�,�8�M�9�E��u��3[����S����{���s���8�b�%�Z� |�����6)C+_=�3\���h
0Z�\ ���^i��������Q`���$��n8��-�] ��������a�&��kU�D�R��(�(`��#� y�v�����]gA�����+�K��+��.;��fI�l�n�Q�HD(���j ��������
(����Z 2�J�!��P�<�"Ns����7�0E� #1��L���=$�`�1K�m�aE�����|G�A ����������Q���Na��j�����*�M%�����\�J �b���Wq�VWZ�,A0E,�
N��x��1�]'h����q�d7!Rx�y����T��j��X�N�-nNYu�A�q_��[�2+)TQ����3x��g�����6�`A�����U�-����LdAt�+(i��#�Hx���d��*s���d.x���T��i����s;y��?4�����%%�����HD"���DyZ�/�xZ}Z������[9N��RT%��8|�����T���Y�}����#��f+�RD5V1h ��9g���B�mI 0�S@�D�*�66tt���.��h�
��<���=�'{v��X)�3Y��jP�����bcII(\s;B 8���$_`�X���3���@D��8�;31��l���vo|M�
��~@�lp����CD#&&/���DSb��M�G��@8���jOA��,:�k~-k��������F1f"��3���EUP���0Gh�3�[N�M����:}���
���00�%2�"���)�J��W�\@�46 �l�U�����P�����P�
��d����%[ ��, ����n�SR%k��'��,v��[8��kQaq�;s������ a�����kW���A��a����>ZM�F�;j]�t'���af�T��'5Z���^�$` G8l������#�������������6������a��H��oPJu�����~&0��@/�d���wq�<<��WZr��� HQ0�W��3r e�[j��E
�t#t��6���C#D�������[���yx�:��Y����3SlTcqo�:�m+���|�`4�E3��2IE���D�)B'�����������g��}��Zzvkj�u[���
��
�Z[�B��9�5�lE�����1GL �
������CZ+�����.�����idF���f��r� ������E�4��E�S�F���hu�a�d%R���o��v��z�:�������:��Q%�!����tt��
��P��E��<��#���M"�
l1]�P�Z�����,5zC���0C�����sD#V[�-,�/$�4F��":0���2$cVR���0)d�����9, ���wa��XB�? ���9�$2��+L��9�cWI����|hfl�2�!���
d�
�L���}����f��;\�lKm���{�<� �F� ����?e:���+��!8��c6�]�]%s�g~���("!8�p�.�,?,sk��D�H���J��`��-��4U�����>c��n�f8�l ��m�x�����1 �A�%; ��������d_���B|A�"R���H��\�-��T$�Af2�{%���9������S�w�+���~)��v�(h��� �a��XD!����
4`[��t����jg�KC�/VUy����t���$zS�`�!�r�~jd����vg��R]k���Z���h.a��);=�an�1O�wb����`mG����<���>����y����9k�Y^�7�W��3�r��r�H��M������[�����s�*iZI�m��� �JD���-��.��� -f���J��xb��H1�s���%������o��H�{I-�D%E� �s8=�X$.�$��"a�5zl7����u1.sF����`#o���uZ���m����@��J�0J��i�VS]�E�*��|��� ���<��a:�����w3�;;����k�U�6� ��D����l��8��73�yRk@��� ��L�R�(j���'�$@$S.{���9������N�����V�|�"^P+[�y��%�@`|NMO���v6�������=V�&k29"z �
����&���=Z�G��8�$v����-�]!���gI������2��G�����|��JB4����(��m*���`��������s������<��9���DA
Na>�i$�a�#'�C�4��o�Z2�,�����@5@,H�C�1XOX2@�z���*�AI r.�U �RS����Yy���`��L`X2��xMP��@��2 ����]�m��3�%Z�����<`��KCq&jX�Z&�0r����()KB���(=��XEl�W�X^2�Kz����V|$��G2fHR1X����8�B
�&�z
�I��Ec�~����^K�{�C\����dj��
�T�l�Wg���B�2FD���'$�I)#�����
]��u��Qu�SrxDA+`�S�^+xF��^5�iHp]O(�"��&��9"g� +�����l��.($* �W)�c�����5ER��o��N�b����B�6�7��#Q9�n�
�E��*������6����������8�����|������������{2�vI�d��S��!�|6�3��@�
��+M����];�E����@\���(Lf�U`��"D��<���[�J<M�F��Nv�L�m��`�'����\oX�K$[�/�L�T������l;�o\��Y@��,�����G!a�{�����`l����QG��$T�����2b���K
����� *���zd5n$%im�/�/Fw)������4C�Mu�
�2uM��'"������X��$���&�Tf%���/�)(F�C��1W��`��6�0����������X��lD���;f�� ��,@������F=q
�#�"
T�������A������\D��3����iER���j!"���`5�6�aS=�����1GPU�h�g��*�S\\����������.��c���������D/�X���3��#�&e�|��b � �R�d KR!R�V@ �"� �IB��CF7I�w
N��yW+%�?����^a���"����N$
p�@On 30/06/2012 04:16, Alex Hunsaker wrote:
Hi, I've been reviewing this patch.
Good documentation, and regression tests. The code looked fine but I
didn't care for the code duplication between array_replace and
array_remove so I merged those into a helper function,
array_replace_internal(). Thoughts?
It looks reasonable.
There was a typo in array_replace which was caught by regression tests.
I've fixed the typo and changed a comment in array_replace_internal.
Patch v3 attached.
Regards,
Marco
--
Marco Nenciarini - 2ndQuadrant Italy
PostgreSQL Training, Services and Support
marco.nenciarini@2ndQuadrant.it | www.2ndQuadrant.it
Attachments:
On Sat, Jun 30, 2012 at 3:28 PM, Marco Nenciarini
<marco.nenciarini@2ndquadrant.it> wrote:
On 30/06/2012 04:16, Alex Hunsaker wrote:
Hi, I've been reviewing this patch.
Good documentation, and regression tests. The code looked fine but I
didn't care for the code duplication between array_replace and
array_remove so I merged those into a helper function,
array_replace_internal(). Thoughts?It looks reasonable.
There was a typo in array_replace which was caught by regression tests.
I've fixed the typo and changed a comment in array_replace_internal.Patch v3 attached.
Looks good to me, marked ready for commiter.
Marco Nenciarini <marco.nenciarini@2ndquadrant.it> writes:
Patch v3 attached.
I'm looking at this patch now. The restriction of array_remove to
one-dimensional arrays seems a bit annoying. I see the difficulty:
if the input is multi-dimensional then removing some elements could
lead to a non-rectangular array, which isn't supported. However,
that could be dealt with by decreeing that the *result* is
one-dimensional and of the necessary length, regardless of the
dimensionality of the input.
I'm not actually certain whether that's a better definition or not.
But one less error case seems like generally a good thing.
Comments?
regards, tom lane
On Wed, Jul 11, 2012 at 9:54 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Marco Nenciarini <marco.nenciarini@2ndquadrant.it> writes:
Patch v3 attached.
I'm looking at this patch now. The restriction of array_remove to
one-dimensional arrays seems a bit annoying. I see the difficulty:
if the input is multi-dimensional then removing some elements could
lead to a non-rectangular array, which isn't supported. However,
that could be dealt with by decreeing that the *result* is
one-dimensional and of the necessary length, regardless of the
dimensionality of the input.
Makes sense to me. +1
The other option ISTM is to replace removed entries with NULL-- which
I don't really like.
Alex Hunsaker <badalex@gmail.com> writes:
On Wed, Jul 11, 2012 at 9:54 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
I'm looking at this patch now. The restriction of array_remove to
one-dimensional arrays seems a bit annoying. I see the difficulty:
if the input is multi-dimensional then removing some elements could
lead to a non-rectangular array, which isn't supported. However,
that could be dealt with by decreeing that the *result* is
one-dimensional and of the necessary length, regardless of the
dimensionality of the input.
Makes sense to me. +1
The other option ISTM is to replace removed entries with NULL-- which
I don't really like.
Well, you can do that with array_replace, so I don't see a need to
define array_remove that way.
regards, tom lane
On Jul 11, 2012, at 11:53 AM, Alex Hunsaker <badalex@gmail.com> wrote:
On Wed, Jul 11, 2012 at 9:54 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Marco Nenciarini <marco.nenciarini@2ndquadrant.it> writes:
Patch v3 attached.
I'm looking at this patch now. The restriction of array_remove to
one-dimensional arrays seems a bit annoying. I see the difficulty:
if the input is multi-dimensional then removing some elements could
lead to a non-rectangular array, which isn't supported. However,
that could be dealt with by decreeing that the *result* is
one-dimensional and of the necessary length, regardless of the
dimensionality of the input.Makes sense to me. +1
+1 from me, too.
...Robert
Marco Nenciarini <marco.nenciarini@2ndquadrant.it> writes:
Patch v3 attached.
Applied with mostly-but-not-entirely cosmetic adjustments.
I left array_remove throwing error for multi-dimensional arrays for
the moment, because I realized that changing the dimensionality as
I suggested would conflict with the optimization to return the original
array if there were no matches. I don't think we'd want the definition
to read "multidimensional arrays are changed to one dimension, but only
if at least one element is removed" --- that's getting a little too
weird. If anyone's really hot to make it work on multi-D arrays, we
could consider disabling that optimization; it's not clear to me that
it's worth a lot. But for now I'm willing to stick with the
throw-an-error approach.
regards, tom lane