Re: [HACKERS] array_length(anyarray)

2014-01-21 Thread Marko Tiikkaja
On 1/21/14, 6:42 PM, Robert Haas wrote: On Sun, Jan 19, 2014 at 1:41 AM, Pavel Stehule wrote: It can be problem on my side - some strange combination of mime type. I seen this issue before. I will recheck it tomorrow from other computer. Doesn't matter anyway. Patch needing to strip trailing

Re: [HACKERS] array_length(anyarray)

2014-01-21 Thread Robert Haas
On Sun, Jan 19, 2014 at 1:41 AM, Pavel Stehule wrote: > 2014/1/19 Marko Tiikkaja >> On 1/19/14, 12:21 AM, Pavel Stehule wrote: >>> I checked it and I got a small issue >>> >>> bash-4.1$ patch -p1 < cardinality.patch >>> (Stripping trailing CRs from patch.) >>> >>> not sure about source of this pr

Re: [HACKERS] array_length(anyarray)

2014-01-20 Thread Dean Rasheed
On 20 January 2014 13:47, Marko Tiikkaja wrote: > On 1/20/14 2:29 PM, Dean Rasheed wrote: >> >> I think this is ready for committer > > > Thanks! > >> ... although I would also like to see >> >> the doc changes to make the table of array function descriptions a bit >> more explicit about corner ca

Re: [HACKERS] array_length(anyarray)

2014-01-20 Thread Marko Tiikkaja
On 1/20/14 2:29 PM, Dean Rasheed wrote: I think this is ready for committer Thanks! ... although I would also like to see the doc changes to make the table of array function descriptions a bit more explicit about corner cases. Hmm. I completely missed the fact that unnest() already uses a

Re: [HACKERS] array_length(anyarray)

2014-01-20 Thread Dean Rasheed
On 19 January 2014 11:43, Marko Tiikkaja wrote: > New version attached, without the doc change. > This looks good to me. - applies cleanly. - compiles with no warnings. - passes a sensible set of new regression tests. - implements the agreed behaviour, per SQL spec. - I can't think of any c

Re: [HACKERS] array_length(anyarray)

2014-01-19 Thread Marko Tiikkaja
On 1/19/14, 2:12 PM, Dean Rasheed wrote: That might seem overly pedantic, but it's quite annoying when API documentation doesn't fully specify the behaviour, and you're forced to use trial-and-error to find out how the functions behave. For what it's worth, I was thinking the same thing when I

Re: [HACKERS] array_length(anyarray)

2014-01-19 Thread Dean Rasheed
On 19 January 2014 11:43, Marko Tiikkaja wrote: > > > On 1/19/14, 9:12 AM, Dean Rasheed wrote: >> >> On 18 January 2014 03:07, Marko Tiikkaja wrote: >>> >>> Here's the patch as promised. Thoughts? >>> >> >> A couple of points: >> >> The answer for empty (zero dimensional) arrays is wrong --- you

Re: [HACKERS] array_length(anyarray)

2014-01-19 Thread Marko Tiikkaja
On 1/19/14, 9:12 AM, Dean Rasheed wrote: On 18 January 2014 03:07, Marko Tiikkaja wrote: Here's the patch as promised. Thoughts? A couple of points: The answer for empty (zero dimensional) arrays is wrong --- you need special case handling for this case to return 0. How embarrassing.

Re: [HACKERS] array_length(anyarray)

2014-01-19 Thread Dean Rasheed
On 18 January 2014 03:07, Marko Tiikkaja wrote: > On 1/12/14, 5:53 AM, I wrote: >> >> On 1/9/14, 2:57 PM, Dean Rasheed wrote: >>> >>> How it should behave for multi-dimensional arrays is less clear, but >>> I'd argue that it should return the total number of elements, i.e. >>> cardinality('{{1,2},

Re: [HACKERS] array_length(anyarray)

2014-01-18 Thread Pavel Stehule
2014/1/19 Marko Tiikkaja > On 1/19/14, 12:21 AM, Pavel Stehule wrote: > >> I checked it and I got a small issue >> >> bash-4.1$ patch -p1 < cardinality.patch >> (Stripping trailing CRs from patch.) >> >> not sure about source of this problem. >> > > I can't reproduce the problem. In fact, I don'

Re: [HACKERS] array_length(anyarray)

2014-01-18 Thread Marko Tiikkaja
On 1/19/14, 12:21 AM, Pavel Stehule wrote: I checked it and I got a small issue bash-4.1$ patch -p1 < cardinality.patch (Stripping trailing CRs from patch.) not sure about source of this problem. I can't reproduce the problem. In fact, I don't see a single CR byte in the patch file on my di

Re: [HACKERS] array_length(anyarray)

2014-01-18 Thread Pavel Stehule
Hello I checked it and I got a small issue bash-4.1$ patch -p1 < cardinality.patch (Stripping trailing CRs from patch.) patching file doc/src/sgml/array.sgml (Stripping trailing CRs from patch.) patching file doc/src/sgml/func.sgml (Stripping trailing CRs from patch.) patching file src/backend/ut

Re: [HACKERS] array_length(anyarray)

2014-01-17 Thread Marko Tiikkaja
On 1/12/14, 5:53 AM, I wrote: On 1/9/14, 2:57 PM, Dean Rasheed wrote: How it should behave for multi-dimensional arrays is less clear, but I'd argue that it should return the total number of elements, i.e. cardinality('{{1,2},{3,4}}'::int[][]) = 4. That would make it consistent with the choices

Re: [HACKERS] array_length(anyarray)

2014-01-11 Thread Pavel Stehule
2014/1/12 Marko Tiikkaja > On 1/9/14, 2:57 PM, Dean Rasheed wrote: > >> Yes, this should just return the number of elements, and 0 for an empty >> array. >> >> How it should behave for multi-dimensional arrays is less clear, but >> I'd argue that it should return the total number of elements, i.e

Re: [HACKERS] array_length(anyarray)

2014-01-11 Thread Marko Tiikkaja
On 1/9/14, 2:57 PM, Dean Rasheed wrote: Yes, this should just return the number of elements, and 0 for an empty array. How it should behave for multi-dimensional arrays is less clear, but I'd argue that it should return the total number of elements, i.e. cardinality('{{1,2},{3,4}}'::int[][]) = 4

Re: [HACKERS] array_length(anyarray)

2014-01-11 Thread Florian Pflug
On Jan10, 2014, at 15:10 , Merlin Moncure wrote: > On Fri, Jan 10, 2014 at 6:00 AM, Florian Pflug wrote: >> On Jan10, 2014, at 11:00 , Merlin Moncure wrote: >>> On Fri, Jan 10, 2014 at 3:52 AM, Marko Tiikkaja wrote: On 1/10/14, 10:41 AM, Merlin Moncure wrote: > > What's needed for

Re: [HACKERS] array_length(anyarray)

2014-01-10 Thread Merlin Moncure
On Fri, Jan 10, 2014 at 6:00 AM, Florian Pflug wrote: > On Jan10, 2014, at 11:00 , Merlin Moncure wrote: >> On Fri, Jan 10, 2014 at 3:52 AM, Marko Tiikkaja wrote: >>> On 1/10/14, 10:41 AM, Merlin Moncure wrote: What's needed for better iteration support (IMO) is a function that do

Re: [HACKERS] array_length(anyarray)

2014-01-10 Thread Florian Pflug
On Jan10, 2014, at 11:00 , Merlin Moncure wrote: > On Fri, Jan 10, 2014 at 3:52 AM, Marko Tiikkaja wrote: >> On 1/10/14, 10:41 AM, Merlin Moncure wrote: >>> >>> What's needed for better iteration support (IMO) >>> is a function that does what unnest does but returns an array on >>> indexes (one

Re: [HACKERS] array_length(anyarray)

2014-01-10 Thread Merlin Moncure
On Fri, Jan 10, 2014 at 3:52 AM, Marko Tiikkaja wrote: > On 1/10/14, 10:41 AM, Merlin Moncure wrote: >> >> What's needed for better iteration support (IMO) >> is a function that does what unnest does but returns an array on >> indexes (one per dimsension) -- a generalization of the >> _pg_expandar

Re: [HACKERS] array_length(anyarray)

2014-01-10 Thread Marko Tiikkaja
On 1/10/14, 10:41 AM, Merlin Moncure wrote: What's needed for better iteration support (IMO) is a function that does what unnest does but returns an array on indexes (one per dimsension) -- a generalization of the _pg_expandarray function. Lets' say 'unnest_dims'. So unnest_dims('{{1,2},{3,4}

Re: [HACKERS] array_length(anyarray)

2014-01-10 Thread Merlin Moncure
On Fri, Jan 10, 2014 at 2:04 AM, Dean Rasheed wrote: > On 10 January 2014 00:36, Marko Tiikkaja wrote: >> On 1/10/14, 1:20 AM, Merlin Moncure wrote: >>> >>> I'm piling on: it's not clear at all to me why you've special cased >>> this to lower_bound=1. First of all, there are other reasons to che

Re: [HACKERS] array_length(anyarray)

2014-01-10 Thread Marko Tiikkaja
On 1/10/14, 9:04 AM, Dean Rasheed wrote: On 10 January 2014 00:36, Marko Tiikkaja wrote: Can you point me to some examples? The example I see all the time is code like if array_length(nodes, 1) < 5 then ... do something ... then you realise (or not as the case may be) that this doesn

Re: [HACKERS] array_length(anyarray)

2014-01-10 Thread Dean Rasheed
On 10 January 2014 00:36, Marko Tiikkaja wrote: > On 1/10/14, 1:20 AM, Merlin Moncure wrote: >> >> I'm piling on: it's not clear at all to me why you've special cased >> this to lower_bound=1. First of all, there are other reasons to check >> length than iteration. > Yes, I agree. A length funct

Re: [HACKERS] array_length(anyarray)

2014-01-09 Thread Marko Tiikkaja
On 1/10/14, 1:20 AM, Merlin Moncure wrote: I'm piling on: it's not clear at all to me why you've special cased this to lower_bound=1. First of all, there are other reasons to check length than iteration. Can you point me to some examples? the server API function should implement as many reas

Re: [HACKERS] array_length(anyarray)

2014-01-09 Thread Merlin Moncure
On Thu, Jan 9, 2014 at 11:08 AM, Marko Tiikkaja wrote: > On 1/9/14 5:44 PM, Florian Pflug wrote: >> >> On Jan9, 2014, at 14:57 , Dean Rasheed wrote: >>> >>> On 19 December 2013 08:05, Pavel Stehule wrote: length should be irrelevant to fact so array starts from 1, 0 or anything >>

Re: [HACKERS] array_length(anyarray)

2014-01-09 Thread Florian Pflug
On Jan9, 2014, at 23:26 , Jim Nasby wrote: > On 1/9/14, 11:08 AM, Marko Tiikkaja wrote: >> On 1/9/14 5:44 PM, Florian Pflug wrote: >>> On Jan9, 2014, at 14:57 , Dean Rasheed wrote: On 19 December 2013 08:05, Pavel Stehule wrote: > length should be irrelevant to fact so array starts from

Re: [HACKERS] array_length(anyarray)

2014-01-09 Thread Jim Nasby
On 1/9/14, 11:08 AM, Marko Tiikkaja wrote: On 1/9/14 5:44 PM, Florian Pflug wrote: On Jan9, 2014, at 14:57 , Dean Rasheed wrote: On 19 December 2013 08:05, Pavel Stehule wrote: length should be irrelevant to fact so array starts from 1, 0 or anything else Yes, this should just return the n

Re: [HACKERS] array_length(anyarray)

2014-01-09 Thread Marko Tiikkaja
On 1/9/14 5:44 PM, Florian Pflug wrote: On Jan9, 2014, at 14:57 , Dean Rasheed wrote: On 19 December 2013 08:05, Pavel Stehule wrote: length should be irrelevant to fact so array starts from 1, 0 or anything else Yes, this should just return the number of elements, and 0 for an empty array.

Re: [HACKERS] array_length(anyarray)

2014-01-09 Thread Florian Pflug
On Jan9, 2014, at 14:57 , Dean Rasheed wrote: > On 19 December 2013 08:05, Pavel Stehule wrote: >> length should be irrelevant to fact so array starts from 1, 0 or anything >> else > > Yes, this should just return the number of elements, and 0 for an empty array. +1. Anything that complains abo

Re: [HACKERS] array_length(anyarray)

2014-01-09 Thread Dean Rasheed
On 19 December 2013 08:05, Pavel Stehule wrote: > > > > 2013/12/19 David Fetter >> >> On Wed, Dec 18, 2013 at 09:27:54PM +0100, Marko Tiikkaja wrote: >> > Hi, >> > >> > Attached is a patch to add support for array_length(anyarray), which >> > only works for one-dimensional arrays, returns 0 for e

Re: [HACKERS] array_length(anyarray)

2013-12-19 Thread Pavel Stehule
2013/12/19 David Fetter > On Wed, Dec 18, 2013 at 09:27:54PM +0100, Marko Tiikkaja wrote: > > Hi, > > > > Attached is a patch to add support for array_length(anyarray), which > > only works for one-dimensional arrays, returns 0 for empty arrays > > and complains if the array's lower bound isn't 1

Re: [HACKERS] array_length(anyarray)

2013-12-19 Thread David Fetter
On Wed, Dec 18, 2013 at 09:27:54PM +0100, Marko Tiikkaja wrote: > Hi, > > Attached is a patch to add support for array_length(anyarray), which > only works for one-dimensional arrays, returns 0 for empty arrays > and complains if the array's lower bound isn't 1. In other words, > does the right t

Re: [HACKERS] array_length(anyarray)

2013-12-18 Thread Marko Tiikkaja
On 12/19/13, 12:01 AM, David Johnston wrote: Marko Tiikkaja-4 wrote On 2013-12-18 22:32, Andrew Dunstan wrote: You're not really free to assume it - you'll need an exception handler for the other-than-1 case, or your code might blow up. This seems to be codifying a bad pattern, which should be

Re: [HACKERS] array_length(anyarray)

2013-12-18 Thread David Johnston
Marko Tiikkaja-4 wrote > On 2013-12-18 22:32, Andrew Dunstan wrote: >> You're not really free to assume it - you'll need an exception handler >> for the other-than-1 case, or your code might blow up. >> >> This seems to be codifying a bad pattern, which should be using >> array_lower() and array_up

Re: [HACKERS] array_length(anyarray)

2013-12-18 Thread Marko Tiikkaja
On 2013-12-18 22:32, Andrew Dunstan wrote: You're not really free to assume it - you'll need an exception handler for the other-than-1 case, or your code might blow up. This seems to be codifying a bad pattern, which should be using array_lower() and array_upper() instead. That's the entire po

Re: [HACKERS] array_length(anyarray)

2013-12-18 Thread Andrew Dunstan
On 12/18/2013 04:19 PM, Marko Tiikkaja wrote: On 2013-12-18 22:13, Andrew Dunstan wrote: On 12/18/2013 03:27 PM, Marko Tiikkaja wrote: Attached is a patch to add support for array_length(anyarray), which only works for one-dimensional arrays, returns 0 for empty arrays and complains if the arr

Re: [HACKERS] array_length(anyarray)

2013-12-18 Thread Marko Tiikkaja
On 2013-12-18 22:19, I wrote: On 2013-12-18 22:13, Andrew Dunstan wrote: On 12/18/2013 03:27 PM, Marko Tiikkaja wrote: Attached is a patch to add support for array_length(anyarray), which only works for one-dimensional arrays, returns 0 for empty arrays and complains if the array's lower bound

Re: [HACKERS] array_length(anyarray)

2013-12-18 Thread Marko Tiikkaja
On 2013-12-18 22:13, Andrew Dunstan wrote: On 12/18/2013 03:27 PM, Marko Tiikkaja wrote: Attached is a patch to add support for array_length(anyarray), which only works for one-dimensional arrays, returns 0 for empty arrays and complains if the array's lower bound isn't 1. In other words, does

Re: [HACKERS] array_length(anyarray)

2013-12-18 Thread Andrew Dunstan
On 12/18/2013 03:27 PM, Marko Tiikkaja wrote: Hi, Attached is a patch to add support for array_length(anyarray), which only works for one-dimensional arrays, returns 0 for empty arrays and complains if the array's lower bound isn't 1. In other words, does the right thing when used with the

Re: [HACKERS] array_length()

2008-11-12 Thread Peter Eisentraut
Robert Haas wrote: Hmm, ISTM that cardinality() is implemented here in the manner previously rejected for array_length()... The objection was that basic functionality should not be implemented in SQL. If we want to disallow all compatibility functions implemented in SQL as well, we have more

Re: [HACKERS] array_length()

2008-11-12 Thread Robert Haas
Hmm, ISTM that cardinality() is implemented here in the manner previously rejected for array_length()... ...Robert On Wed, Nov 12, 2008 at 8:13 AM, Peter Eisentraut <[EMAIL PROTECTED]> wrote: > Robert Haas wrote: >> >> Updated version attached, this time without the compiler warning. > > I have c

Re: [HACKERS] array_length()

2008-11-12 Thread Peter Eisentraut
Robert Haas wrote: Updated version attached, this time without the compiler warning. I have committed something based on this. The issue of empty arrays will need a separate solution. -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription:

Re: [HACKERS] array_length()

2008-11-09 Thread Decibel!
On Nov 5, 2008, at 7:00 AM, Peter Eisentraut wrote: There is a tiny problem with this implementation: It returns null for an empty array, not zero. This is because array_lower and/or array_upper return null for an empty array, which makes sense for those cases. We could fix this by putting

Re: [HACKERS] array_length()

2008-11-07 Thread Robert Haas
Updated version attached, this time without the compiler warning. Sorry for the sloppy work. ...Robert Index: doc/src/sgml/array.sgml === RCS file: /projects/cvsroot/pgsql/doc/src/sgml/array.sgml,v retrieving revision 1.67 diff -c -r

Re: [HACKERS] array_length()

2008-11-06 Thread Robert Haas
> Hmm... the problem is that an empty array is really zero-dimensional. > So for what values of the second argument ought we to return 0? > > It certainly seems inconsistent to say that array_length({}, 6) = 0 > and array_length({1}, 6) is null. Ugh. I meant rather: It certainly seems inconsiste

Re: [HACKERS] array_length()

2008-11-06 Thread Robert Haas
>> There is a tiny problem with this implementation: It returns null for an >> empty array, not zero. This is because array_lower and/or array_upper >> return null for an empty array, which makes sense for those cases. We >> could fix this by putting a coalesce around the expression, but since >>

Re: [HACKERS] array_length()

2008-11-05 Thread Tom Lane
Peter Eisentraut <[EMAIL PROTECTED]> writes: > There is a tiny problem with this implementation: It returns null for an > empty array, not zero. This is because array_lower and/or array_upper > return null for an empty array, which makes sense for those cases. We > could fix this by putting a

Re: [HACKERS] array_length()

2008-11-05 Thread Pavel Stehule
2008/11/5 Peter Eisentraut <[EMAIL PROTECTED]>: > Pavel Stehule wrote: >> >> Hello >> >> 2008/11/5 Peter Eisentraut <[EMAIL PROTECTED]>: >>> >>> Decibel! wrote: ISTM it'd be useful to have an array_length function (since I just wrote one for work ;), so here's a patch. Note that I do

Re: [HACKERS] array_length()

2008-11-05 Thread Peter Eisentraut
Pavel Stehule wrote: Hello 2008/11/5 Peter Eisentraut <[EMAIL PROTECTED]>: Decibel! wrote: ISTM it'd be useful to have an array_length function (since I just wrote one for work ;), so here's a patch. Note that I don't have the docs toolchain setup, so I wasn't able to test the doc patches. Th

Re: [HACKERS] array_length()

2008-11-05 Thread Pavel Stehule
Hello 2008/11/5 Peter Eisentraut <[EMAIL PROTECTED]>: > Decibel! wrote: >> >> ISTM it'd be useful to have an array_length function (since I just wrote >> one for work ;), so here's a patch. Note that I don't have the docs >> toolchain setup, so I wasn't able to test the doc patches. > > There is a

Re: [HACKERS] array_length()

2008-11-05 Thread Peter Eisentraut
Decibel! wrote: ISTM it'd be useful to have an array_length function (since I just wrote one for work ;), so here's a patch. Note that I don't have the docs toolchain setup, so I wasn't able to test the doc patches. There is a tiny problem with this implementation: It returns null for an empt