Re: proposal: searching in array function - array_position - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: proposal: searching in array function - array_position
Date
Msg-id CAFj8pRDZQxpNdLAdGDbBzZgX6H5C+n23hkMiNE=osLC9cpV+JA@mail.gmail.com
Whole thread Raw
In response to Re: proposal: searching in array function - array_position  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
Responses Re: proposal: searching in array function - array_position
List pgsql-hackers


2015-01-16 17:57 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com>:
On 1/16/15 3:39 AM, Pavel Stehule wrote:
I am proposing a simple function, that returns a position of element in array.

Yes please!

FUNCTION array_position(anyarray, anyelement) RETURNS int

That won't work on a multi-dimensional array. Ideally it needs to accept a slice or an element and return the specifier for the slice.

It is question, what is a result - probably, there can be a multidimensional variant, where result will be a array

array_position([1,2,3],2) --> 2
array_position([[1,2],[2,3],[3,4]], [2,3]) --> 2 /* 2nd parameter should to have N-1 dimension of first parameter */
array_position_md([1,2,3],2) --> [2]
array_position_md([[1,2],[2,3],[3,4]], 2) --> [2,1]

another question is how to solve more than one occurrence on one value - probably two sets of functions - first returns first occurrence of value, second returns set of occurrence
 

This wouldn't be so bad if we had an easier way to extract subsets of an array, but even that is really ugly because whatever you extract keeps the original number of dimensions.

Implementation is simple (plpgsql code)

This would actually be written in C though, yes? Otherwise it's not really any better than just doing an extension...

Sure, I expect a C implementation

Pavel
 
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: speedup tidbitmap patch: cache page
Next
From: Andres Freund
Date:
Subject: Re: speedup tidbitmap patch: cache page