array_remove(anyarray, anyarray)
array_remove(anyarray, anyarray)
От:
Jim Nasby <Jim.Nasby@BlueTreble.com>
Дата:
Recently I had need of removing occurrences of a number of values from an array. Obviously I could have nested array_remove() call or wrapped the whole thing in a SELECT unnest(), but that seems rather silly and inefficient. Any one have objections to changing array_replace_internal() to make search and repalace arrays instead of Datums? -- Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX Experts in Analytics, Data Architecture and PostgreSQL Data in Trouble? Get it in Treble! http://BlueTreble.com
BEGINNER HACKERS: array_remove(anyarray, anyarray)
От:
Jim Nasby <Jim.Nasby@BlueTreble.com>
Дата:
On 12/10/15 6:25 PM, Jim Nasby wrote: > Recently I had need of removing occurrences of a number of values from > an array. Obviously I could have nested array_remove() call or wrapped > the whole thing in a SELECT unnest(), but that seems rather silly and > inefficient. > > Any one have objections to changing array_replace_internal() to make > search and replace arrays instead of Datums? Seeing none... let's see if someone wants to tackle this. The goal is to modify array_replace_internal() (in src/backend/utils/adt/arrayfuncs.c) so that two of it's arguments (search and replace) can be arrays. I believe the best way to do that would be to add bool search_isarray and bool replace_isarray arguments, and have array_replace_internal() act accordingly if those are true. The expected behavior when search_isarray is true would be to search for a group of elements that completely match the search array. When replace_isarray is true, then any replacements into *array would be the elements from replace, growing or shrinking the array as necessary. The user visible array_remove and array_replace functions will need to check the data type of their inputs using get_fn_expr_argtype(). You can find examples of that in arrayfuncs.c. A complete patch will also need regression tests (src/test/regress/sql/arrays.sql) and tweaks to the documentation for those functions (doc/src/sgml/func.sgml). -- Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX Experts in Analytics, Data Architecture and PostgreSQL Data in Trouble? Get it in Treble! http://BlueTreble.com