Re: array_length(anyarray)
От | Dean Rasheed |
---|---|
Тема | Re: array_length(anyarray) |
Дата | |
Msg-id | CAEZATCWKyM0qpi+kimKr1s5MNaoT07j_t6Qe7VNWEx8k=AQfqA@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: array_length(anyarray) (Pavel Stehule <pavel.stehule@gmail.com>) |
Ответы |
Re: array_length(anyarray)
Re: array_length(anyarray) |
Список | pgsql-hackers |
On 19 December 2013 08:05, Pavel Stehule <pavel.stehule@gmail.com> wrote: > > > > 2013/12/19 David Fetter <david@fetter.org> >> >> 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 thing when used with the arrays people use 99% of the >> > time. >> >> +1 for adding this. > > > +1 > I think that having 2 functions called array_length() that each behave differently for empty arrays would just lead to confusion. The SQL standard defines a function called cardinality() that returns the number of elements of a collection (array or multiset), so why don't we call it that? > 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. 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 we've already made for unnest() and ordinality:- cardinality(foo) = (select count(*) from unnest(foo)).- unnest with ordinality would always result in ordinalsin the range [1, cardinality]. Regards, Dean
В списке pgsql-hackers по дате отправления: