Re: array_length(anyarray)
От | Dean Rasheed |
---|---|
Тема | Re: array_length(anyarray) |
Дата | |
Msg-id | CAEZATCWuf1y7e=JUiVxgG1cE3cJqxQBEmWJC641Vn_uXdva+jw@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: array_length(anyarray) (Marko Tiikkaja <marko@joh.to>) |
Ответы |
Re: array_length(anyarray)
|
Список | pgsql-hackers |
On 18 January 2014 03:07, Marko Tiikkaja <marko@joh.to> 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},{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 ordinals in the range >>> [1, cardinality]. >> >> >> Ignoring my proposal, this seems like the most reasonable option. I'll >> send an updated patch along these lines. > > > 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. In fact why not simply use ArrayGetNItems()? In the docs, in the table of array functions, I think it would probably be useful to make the entry for array_length say "see also cardinality", otherwise people might just stop reading there. I suspect that in over 90% of cases, cardinality will be the more appropriate function to use rather than array_length. Regards, Dean
В списке pgsql-hackers по дате отправления: