Re: How to count the number of items in an Array?
От | Andre Lopes |
---|---|
Тема | Re: How to count the number of items in an Array? |
Дата | |
Msg-id | 18f98e681002210746j5840cf1cie04bc9c65075a023@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: How to count the number of items in an Array? (Andreas Kretschmer <akretschmer@spamfence.net>) |
Список | pgsql-general |
Hi,
Thanks for the reply.
I have done it in this way:
[code]
FOR vDISTRITOS_NA_TABELA IN
SELECT array[id_distrito] FROM am_newsletter_distritos
WHERE email = pEMAIL and id_website_recolha = pID_WEBSITE_RECOLHA
LOOP
vDISTRITOS_NA_TABELA_CONST := vDISTRITOS_NA_TABELA_CONST || vDISTRITOS_NA_TABELA;
END LOOP;
SELECT array[id_distrito] FROM am_newsletter_distritos
WHERE email = pEMAIL and id_website_recolha = pID_WEBSITE_RECOLHA
LOOP
vDISTRITOS_NA_TABELA_CONST := vDISTRITOS_NA_TABELA_CONST || vDISTRITOS_NA_TABELA;
END LOOP;
[/code]
Best Regards,
On Sun, Feb 21, 2010 at 3:25 PM, Andreas Kretschmer <akretschmer@spamfence.net> wrote:
> One more time, thanks for the reply. I'am using postgre 8.3. I think I don'tSure.
> have the array_agg(), there is another way of doing it?
The doc contains an example for a user-defined aggregate-function:
http://www.postgresql.org/docs/8.4/interactive/xaggr.html
It works with versions prior 8.4.
test=*# CREATE AGGREGATE array_accum (anyelement)
test-# (
test(# sfunc = array_append,
test(# stype = anyarray,
test(# initcond = '{}'
test(# );
CREATE AGGREGATE
Zeit: 44,645 ms
test=*# select array_accum(a) from foo;
array_accum
-------------{1,3,5,7}
(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°
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
В списке pgsql-general по дате отправления: