Andre Lopes <lopes80andre@gmail.com> wrote:
> Hi,
>
> I have googled, but I can't find how to count the number of items in an Array
> in Plpgsql.
>
> Someone can give me a clue on that?
Sure, you can use array_upper() - array_lower():
Zeit: 0,205 ms
test=*# select array_upper(array[1,2,3],1) - array_lower(array[1,2,3],1);
?column?
----------
2
(1 Zeile)
or:
test=*# select array_upper(array[1,2,3],1) - array_lower(array[1,2,3],1) + 1;
?column?
----------
3
(1 Zeile)
Or, if your array starts with the first element, simple:
test=*# select array_upper(array[1,2,3,NULL,5],1);
array_upper
-------------
5
(1 Zeile)
Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°