Re: [HACKERS] proposal: searching in array function - array_position

2015-03-22 Thread Pavel Stehule
2015-03-22 11:30 GMT+01:00 Dean Rasheed dean.a.rash...@gmail.com: On 22 March 2015 at 06:11, Pavel Stehule pavel.steh...@gmail.com wrote: Hi here is updated patch with array_position, array_positions implementation. It is based on committed code - so please, revert commit

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-22 Thread Dean Rasheed
On 22 March 2015 at 06:11, Pavel Stehule pavel.steh...@gmail.com wrote: Hi here is updated patch with array_position, array_positions implementation. It is based on committed code - so please, revert commit 13dbc7a824b3f905904cab51840d37f31a07a9ef and apply this patch I checked this and

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-22 Thread Pavel Stehule
Hi here is updated patch with array_position, array_positions implementation. It is based on committed code - so please, revert commit 13dbc7a824b3f905904cab51840d37f31a07a9ef and apply this patch Regards Pavel 2015-03-20 18:29 GMT+01:00 Alvaro Herrera alvhe...@2ndquadrant.com: Pavel

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-21 Thread Dean Rasheed
do you have any idea about name for this function? array_position is ok? +1 on array_position. It's possible at some point we'll actually want array_offset that does what it claims. +1 for array_position. -1 for keeping array_offset. I'm not convinced that there are sufficient use cases for

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-21 Thread Pavel Stehule
2015-03-21 0:27 GMT+01:00 Jim Nasby jim.na...@bluetreble.com: On 3/20/15 2:48 PM, Pavel Stehule wrote: 2015-03-20 18:47 GMT+01:00 Tom Lane t...@sss.pgh.pa.us mailto:t...@sss.pgh.pa.us: Alvaro Herrera alvhe...@2ndquadrant.com mailto:alvhe...@2ndquadrant.com writes: Pavel

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-20 Thread Jim Nasby
On 3/20/15 2:48 PM, Pavel Stehule wrote: 2015-03-20 18:47 GMT+01:00 Tom Lane t...@sss.pgh.pa.us mailto:t...@sss.pgh.pa.us: Alvaro Herrera alvhe...@2ndquadrant.com mailto:alvhe...@2ndquadrant.com writes: Pavel Stehule wrote: I am thinking, so it is ok - it returns a offset,

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-20 Thread Tom Lane
Alvaro Herrera alvhe...@2ndquadrant.com writes: Pavel Stehule wrote: I am thinking, so it is ok - it returns a offset, not position. So you can't use it as a subscript? That sounds unfriendly. Almost every function using this will be subtly broken. I concur; perhaps offset was the design

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-20 Thread Alvaro Herrera
Pavel Stehule wrote: 2015-03-20 17:49 GMT+01:00 Dean Rasheed dean.a.rash...@gmail.com: There's an issue when the array's lower bound isn't 1: select array_offset('[2:4]={1,2,3}'::int[], 1); array_offset -- 1 (1 row) whereas I would expect this to

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-20 Thread Pavel Stehule
2015-03-20 18:29 GMT+01:00 Alvaro Herrera alvhe...@2ndquadrant.com: Pavel Stehule wrote: 2015-03-20 17:49 GMT+01:00 Dean Rasheed dean.a.rash...@gmail.com: There's an issue when the array's lower bound isn't 1: select array_offset('[2:4]={1,2,3}'::int[], 1); array_offset

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-20 Thread Dean Rasheed
On 18 March 2015 at 19:03, Alvaro Herrera alvhe...@2ndquadrant.com wrote: Pushed after adding error checks there and fixing the docs to match. Please verify. There's an issue when the array's lower bound isn't 1: select array_offset('[2:4]={1,2,3}'::int[], 1); array_offset --

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-20 Thread Pavel Stehule
2015-03-20 17:49 GMT+01:00 Dean Rasheed dean.a.rash...@gmail.com: On 18 March 2015 at 19:03, Alvaro Herrera alvhe...@2ndquadrant.com wrote: Pushed after adding error checks there and fixing the docs to match. Please verify. There's an issue when the array's lower bound isn't 1: select

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-20 Thread Pavel Stehule
2015-03-20 18:47 GMT+01:00 Tom Lane t...@sss.pgh.pa.us: Alvaro Herrera alvhe...@2ndquadrant.com writes: Pavel Stehule wrote: I am thinking, so it is ok - it returns a offset, not position. So you can't use it as a subscript? That sounds unfriendly. Almost every function using this

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-19 Thread Pavel Stehule
2015-03-18 20:03 GMT+01:00 Alvaro Herrera alvhe...@2ndquadrant.com: Pavel Stehule wrote: 2015-03-18 12:41 GMT+01:00 Marko Tiikkaja ma...@joh.to: I am thinking, so this behave is correct (there is no other possible), but it is only corner case for this functionality - and if you are

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-19 Thread Alvaro Herrera
Pavel Stehule wrote: 2015-03-18 20:03 GMT+01:00 Alvaro Herrera alvhe...@2ndquadrant.com: Pushed after adding error checks there and fixing the docs to match. Please verify. it is looking well, thank you. Thanks for checking. small issue - there is not documented, so multidimensional

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-18 Thread Pavel Stehule
2015-03-18 3:45 GMT+01:00 Jim Nasby jim.na...@bluetreble.com: On 3/17/15 8:06 PM, Alvaro Herrera wrote: My main question regarding this patch is whether the behavior with MD arrays is useful at all. Suppose I give it this: alvherre=# select

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-18 Thread Pavel Stehule
2015-03-18 12:41 GMT+01:00 Marko Tiikkaja ma...@joh.to: On 3/18/15 12:27 PM, Pavel Stehule wrote: On 3/17/15 8:06 PM, Alvaro Herrera wrote: My main question regarding this patch is whether the behavior with MD arrays is useful at all. Suppose I give it this: alvherre=# select

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-18 Thread Marko Tiikkaja
On 3/18/15 12:27 PM, Pavel Stehule wrote: On 3/17/15 8:06 PM, Alvaro Herrera wrote: My main question regarding this patch is whether the behavior with MD arrays is useful at all. Suppose I give it this: alvherre=# select array_offset('{{{1,2},{3,4},{5,6}},{{2,3},{4,5},{6,7}}}', 3);

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-18 Thread Alvaro Herrera
Pavel Stehule wrote: 2015-03-18 12:41 GMT+01:00 Marko Tiikkaja ma...@joh.to: I am thinking, so this behave is correct (there is no other possible), but it is only corner case for this functionality - and if you are thinking, so better to disallow it, I am not against. My main focus is

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-17 Thread Alvaro Herrera
My main question regarding this patch is whether the behavior with MD arrays is useful at all. Suppose I give it this: alvherre=# select array_offset('{{{1,2},{3,4},{5,6}},{{2,3},{4,5},{6,7}}}', 3); array_offset -- 3 (1 fila) What can I do with the 3 value it returned?

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-17 Thread Jim Nasby
On 3/17/15 8:06 PM, Alvaro Herrera wrote: My main question regarding this patch is whether the behavior with MD arrays is useful at all. Suppose I give it this: alvherre=# select array_offset('{{{1,2},{3,4},{5,6}},{{2,3},{4,5},{6,7}}}', 3); array_offset -- 3 (1 fila)

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-12 Thread Jim Nasby
On 3/11/15 1:19 AM, Pavel Stehule wrote: 2015-03-11 2:57 GMT+01:00 Robert Haas robertmh...@gmail.com mailto:robertmh...@gmail.com: On Tue, Mar 10, 2015 at 5:53 PM, Jim Nasby jim.na...@bluetreble.com mailto:jim.na...@bluetreble.com wrote: I don't think we need both array_offset and

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-12 Thread Pavel Stehule
2015-03-11 22:50 GMT+01:00 Jim Nasby jim.na...@bluetreble.com: On 3/11/15 4:37 PM, Pavel Stehule wrote: + /* + * array_offset - returns the offset of a value in an array (array_offset and + * array_offset_start are wrappers for safe call (look on opr_sanity test) a + *

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-12 Thread Jim Nasby
On 3/10/15 9:30 AM, Robert Haas wrote: On Sat, Mar 7, 2015 at 1:06 PM, Petr Jelinek p...@2ndquadrant.com wrote: You still duplicate the type cache code, but many other array functions do that too so I will not hold that against you. (Maybe somebody should write separate patch that would put all

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-12 Thread Pavel Stehule
2015-03-10 16:53 GMT+01:00 Jim Nasby jim.na...@bluetreble.com: On 3/10/15 9:30 AM, Robert Haas wrote: On Sat, Mar 7, 2015 at 1:06 PM, Petr Jelinek p...@2ndquadrant.com wrote: You still duplicate the type cache code, but many other array functions do that too so I will not hold that

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-11 Thread Jim Nasby
On 3/11/15 1:29 AM, Pavel Stehule wrote: What is this comment supposed to mean? There is no 'width_array'... It is typo (I am sorry) - should be width_bucket(, array) http://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=e80252d424278abf65b624669c8e6b3fe8587cac The code is

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-11 Thread Pavel Stehule
2015-03-11 22:14 GMT+01:00 Jim Nasby jim.na...@bluetreble.com: On 3/11/15 1:29 AM, Pavel Stehule wrote: What is this comment supposed to mean? There is no 'width_array'... It is typo (I am sorry) - should be width_bucket(, array)

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-11 Thread Jim Nasby
On 3/11/15 4:37 PM, Pavel Stehule wrote: + /* + * array_offset - returns the offset of a value in an array (array_offset and + * array_offset_start are wrappers for safe call (look on opr_sanity test) a + * array_offset_common function. + * + * Returns NULL when value is not found. It

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-11 Thread Jim Nasby
On 3/10/15 5:25 PM, Tom Lane wrote: Jim Nasby jim.na...@bluetreble.com writes: That said, this pattern with fn_extra is repeated a lot, even just in the backend (not counting contrib or extensions). It would be nice if there was generic support for this. What do you mean by generic support?

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-11 Thread Pavel Stehule
2015-03-11 2:57 GMT+01:00 Robert Haas robertmh...@gmail.com: On Tue, Mar 10, 2015 at 5:53 PM, Jim Nasby jim.na...@bluetreble.com wrote: I don't think we need both array_offset and array_offset_start; can't both SQL functions just call one C function? Not if you want the opr_sanity tests

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-11 Thread Pavel Stehule
2015-03-10 22:53 GMT+01:00 Jim Nasby jim.na...@bluetreble.com: On 2/22/15 5:19 AM, Pavel Stehule wrote: 2015-02-22 3:00 GMT+01:00 Petr Jelinek p...@2ndquadrant.com mailto:p...@2ndquadrant.com: On 28/01/15 08:15, Pavel Stehule wrote: 2015-01-28 0:01 GMT+01:00 Jim Nasby

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-10 Thread Robert Haas
On Sat, Mar 7, 2015 at 1:06 PM, Petr Jelinek p...@2ndquadrant.com wrote: You still duplicate the type cache code, but many other array functions do that too so I will not hold that against you. (Maybe somebody should write separate patch that would put all that duplicate code into common

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-10 Thread Robert Haas
On Tue, Mar 10, 2015 at 5:53 PM, Jim Nasby jim.na...@bluetreble.com wrote: I don't think we need both array_offset and array_offset_start; can't both SQL functions just call one C function? Not if you want the opr_sanity tests to pass. (But I'm seriously starting to wonder if that's actually a

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-10 Thread Pavel Stehule
2015-03-10 19:50 GMT+01:00 Tom Lane t...@sss.pgh.pa.us: Pavel Stehule pavel.steh...@gmail.com writes: 2015-03-10 15:30 GMT+01:00 Robert Haas robertmh...@gmail.com: I am sure in agreement with the idea that it would be good to factor out the common typecache code (for setting up my_extra).

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-10 Thread Robert Haas
On Tue, Mar 10, 2015 at 3:43 PM, Pavel Stehule pavel.steh...@gmail.com wrote: I have not good feeling about it too. If we would to enhance this are, we probably need a specific flinfo field and flags to specify more precious the context of cached informations. my_extra should be reserved for

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-10 Thread Pavel Stehule
2015-03-10 15:30 GMT+01:00 Robert Haas robertmh...@gmail.com: On Sat, Mar 7, 2015 at 1:06 PM, Petr Jelinek p...@2ndquadrant.com wrote: You still duplicate the type cache code, but many other array functions do that too so I will not hold that against you. (Maybe somebody should write

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-10 Thread Tom Lane
Pavel Stehule pavel.steh...@gmail.com writes: 2015-03-10 15:30 GMT+01:00 Robert Haas robertmh...@gmail.com: I am sure in agreement with the idea that it would be good to factor out the common typecache code (for setting up my_extra). Any chance we get a preliminary patch that does that

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-10 Thread Jim Nasby
On 3/10/15 10:53 AM, Jim Nasby wrote: On 3/10/15 9:30 AM, Robert Haas wrote: On Sat, Mar 7, 2015 at 1:06 PM, Petr Jelinek p...@2ndquadrant.com wrote: You still duplicate the type cache code, but many other array functions do that too so I will not hold that against you. (Maybe somebody should

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-10 Thread Jim Nasby
On 3/10/15 2:43 PM, Pavel Stehule wrote: There is not all that much commonality; many functions don't bother to populate all of the ArrayMetaState fields because they don't need all of them. (The ones you quote don't, in fact.) You are either going to end up with a subroutine

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-10 Thread Tom Lane
Jim Nasby jim.na...@bluetreble.com writes: That said, this pattern with fn_extra is repeated a lot, even just in the backend (not counting contrib or extensions). It would be nice if there was generic support for this. What do you mean by generic support? Most of those functions are doing

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-10 Thread Jim Nasby
On 2/22/15 5:19 AM, Pavel Stehule wrote: 2015-02-22 3:00 GMT+01:00 Petr Jelinek p...@2ndquadrant.com mailto:p...@2ndquadrant.com: On 28/01/15 08:15, Pavel Stehule wrote: 2015-01-28 0:01 GMT+01:00 Jim Nasby jim.na...@bluetreble.com mailto:jim.na...@bluetreble.com

Re: [HACKERS] proposal: searching in array function - array_position

2015-03-07 Thread Petr Jelinek
On 22/02/15 12:19, Pavel Stehule wrote: 2015-02-22 3:00 GMT+01:00 Petr Jelinek p...@2ndquadrant.com mailto:p...@2ndquadrant.com: On 28/01/15 08:15, Pavel Stehule wrote: 2015-01-28 0:01 GMT+01:00 Jim Nasby jim.na...@bluetreble.com mailto:jim.na...@bluetreble.com:

Re: [HACKERS] proposal: searching in array function - array_position

2015-02-22 Thread Pavel Stehule
2015-02-22 3:00 GMT+01:00 Petr Jelinek p...@2ndquadrant.com: On 28/01/15 08:15, Pavel Stehule wrote: 2015-01-28 0:01 GMT+01:00 Jim Nasby jim.na...@bluetreble.com mailto:jim.na...@bluetreble.com: On 1/27/15 4:36 AM, Pavel Stehule wrote: It is only partially identical - I

Re: [HACKERS] proposal: searching in array function - array_position

2015-02-21 Thread Petr Jelinek
On 28/01/15 08:15, Pavel Stehule wrote: 2015-01-28 0:01 GMT+01:00 Jim Nasby jim.na...@bluetreble.com mailto:jim.na...@bluetreble.com: On 1/27/15 4:36 AM, Pavel Stehule wrote: It is only partially identical - I would to use cache for array_offset, but it is not necessary

Re: [HACKERS] proposal: searching in array function - array_position

2015-01-27 Thread Jim Nasby
On 1/27/15 4:36 AM, Pavel Stehule wrote: 2015-01-26 23:29 GMT+01:00 Jim Nasby jim.na...@bluetreble.com mailto:jim.na...@bluetreble.com: On 1/26/15 4:17 PM, Pavel Stehule wrote: Any way to reduce the code duplication between the array and non-array versions? Maybe factor out

Re: [HACKERS] proposal: searching in array function - array_position

2015-01-27 Thread Pavel Stehule
2015-01-26 23:29 GMT+01:00 Jim Nasby jim.na...@bluetreble.com: On 1/26/15 4:17 PM, Pavel Stehule wrote: Any way to reduce the code duplication between the array and non-array versions? Maybe factor out the operator caching code? I though about it - but there is different checks,

Re: [HACKERS] proposal: searching in array function - array_position

2015-01-27 Thread Pavel Stehule
2015-01-28 0:01 GMT+01:00 Jim Nasby jim.na...@bluetreble.com: On 1/27/15 4:36 AM, Pavel Stehule wrote: 2015-01-26 23:29 GMT+01:00 Jim Nasby jim.na...@bluetreble.com mailto: jim.na...@bluetreble.com: On 1/26/15 4:17 PM, Pavel Stehule wrote: Any way to reduce the code

Re: [HACKERS] proposal: searching in array function - array_position

2015-01-26 Thread Jim Nasby
On 1/24/15 2:48 AM, Pavel Stehule wrote: with array_offsets - returns a array of offsets + entryreturns a offset of first occurrence of some element in a array. It uses should be + entryreturns the offset of the first occurrence of some element in an array. It uses +

Re: [HACKERS] proposal: searching in array function - array_position

2015-01-26 Thread Pavel Stehule
2015-01-26 23:01 GMT+01:00 Jim Nasby jim.na...@bluetreble.com: On 1/24/15 2:48 AM, Pavel Stehule wrote: with array_offsets - returns a array of offsets + entryreturns a offset of first occurrence of some element in a array. It uses should be + entryreturns the offset of

Re: [HACKERS] proposal: searching in array function - array_position

2015-01-26 Thread Jim Nasby
On 1/26/15 4:17 PM, Pavel Stehule wrote: Any way to reduce the code duplication between the array and non-array versions? Maybe factor out the operator caching code? I though about it - but there is different checks, different result processing, different result type. I didn't find any

Re: [HACKERS] proposal: searching in array function - array_position

2015-01-24 Thread Pavel Stehule
Hi with array_offsets - returns a array of offsets Regards Pavel 2015-01-20 21:32 GMT+01:00 Jim Nasby jim.na...@bluetreble.com: On 1/20/15 11:12 AM, Pavel Stehule wrote: I am sending updated version - it allow third optional argument that specify where searching should to start. With it

Re: [HACKERS] proposal: searching in array function - array_position

2015-01-20 Thread Pavel Stehule
Hi I am sending updated version - it allow third optional argument that specify where searching should to start. With it is possible repeatably call this function. Regards Pavel 2015-01-17 23:43 GMT+01:00 Pavel Stehule pavel.steh...@gmail.com: Hi here is a proof concept of array_offset

Re: [HACKERS] proposal: searching in array function - array_position

2015-01-20 Thread Pavel Stehule
2015-01-20 21:32 GMT+01:00 Jim Nasby jim.na...@bluetreble.com: On 1/20/15 11:12 AM, Pavel Stehule wrote: I am sending updated version - it allow third optional argument that specify where searching should to start. With it is possible repeatably call this function. What happened to

Re: [HACKERS] proposal: searching in array function - array_position

2015-01-20 Thread Jim Nasby
On 1/20/15 11:12 AM, Pavel Stehule wrote: I am sending updated version - it allow third optional argument that specify where searching should to start. With it is possible repeatably call this function. What happened to returning an array of offsets? I think that would be both easier to use

Re: [HACKERS] proposal: searching in array function - array_position

2015-01-17 Thread Pavel Stehule
Hi here is a proof concept of array_offset function possible question: * used comparation = or IS NOT DISTINCT FROM In this initial proof concept I used IS NOT DISTINCT FROM operator - but my opinion is not strong in this question. Both has some advantages and disadvantages. Regards Pavel

Re: [HACKERS] proposal: searching in array function - array_position

2015-01-17 Thread Pavel Stehule
2015-01-16 17:57 GMT+01:00 Jim Nasby jim.na...@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

Re: [HACKERS] proposal: searching in array function - array_position

2015-01-16 Thread Jim Nasby
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

Re: [HACKERS] proposal: searching in array function - array_position

2015-01-16 Thread Pavel Stehule
2015-01-16 17:57 GMT+01:00 Jim Nasby jim.na...@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

Re: [HACKERS] proposal: searching in array function - array_position

2015-01-16 Thread Jim Nasby
On 1/16/15 11:16 AM, Pavel Stehule wrote: 2015-01-16 17:57 GMT+01:00 Jim Nasby jim.na...@bluetreble.com mailto:jim.na...@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!

Re: [HACKERS] proposal: searching in array function - array_position

2015-01-16 Thread Pavel Stehule
2015-01-16 18:37 GMT+01:00 Jim Nasby jim.na...@bluetreble.com: On 1/16/15 11:16 AM, Pavel Stehule wrote: 2015-01-16 17:57 GMT+01:00 Jim Nasby jim.na...@bluetreble.com mailto: jim.na...@bluetreble.com: On 1/16/15 3:39 AM, Pavel Stehule wrote: I am proposing a simple function,