Re: How to count elements in an array?

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: How to count elements in an array?
Дата
Msg-id 3AA46D11.885E1483@agliodbs.com
обсуждение исходный текст
Ответ на How to count elements in an array?  (Grant <grant@conprojan.com.au>)
Список pgsql-sql
Grant,
The only way I know to enumarate arrays is procedural.  This is a good
reason to stay away from arrays except in buffer and temporary tables
(aside from the fact that array columns violate the relational principle
of atomicity).
The following sample procedure, paraphrased from Bruce Momjian's book
(which you should buy, hint, hint) illustrates enumerating an array of
INT4 values:

CREATE FUNCTION count_array ( INT4[] ) RETURNS INT2
AS '
DECLARE array_loop INT2;array_col ALIAS FOR $1;
BEGINarray_loop := 1;WHILE array_col[array_loop]  LOOP    array_loop = array_loop + 1;END LOOP;array_loop := array_loop
-1RETURN array_loop;
 
END;'
LANGUAGE 'plpgsql';

                -Josh
-- 
______AGLIO DATABASE SOLUTIONS___________________________                                       Josh Berkus  Complete
informationtechnology      josh@agliodbs.com   and data management solutions       (415) 565-7293  for law firms, small
businesses      fax  621-2533   and non-profit organizations.       San Francisco
 


В списке pgsql-sql по дате отправления:

Предыдущее
От: Josh Berkus
Дата:
Сообщение: No Documentation for to_char(INTERVAL, mask)
Следующее
От: Grant
Дата:
Сообщение: Re: No Documentation for to_char(INTERVAL, mask)