Skip site navigation (1) Skip section navigation (2)

Re: аггрегатор по аггрегаторам

From: Sergey Burladyan <eshkinkot(at)gmail(dot)com>
To: "Dmitry E(dot) Oboukhov" <unera(at)debian(dot)org>
Cc: pgsql-ru-general(at)postgresql(dot)org
Subject: Re: аггрегатор по аггрегаторам
Date: 2012-04-13 14:06:15
Message-ID: 87zkafbuaw.fsf@seb.koffice.internal (view raw or flat)
Thread:
Lists: pgsql-ru-general
"Dmitry E. Oboukhov" <unera(at)debian(dot)org> writes:

> например:
>
>  select * FROM (VALUES (ARRAY[1,2,3,3,4]), (ARRAY[1,2,2,3,4])) t;
>    column1   
> -------------
>  {1,2,3,3,4}
>  {1,2,2,3,4}
> (2 rows)
>
>
>  WITH "a" AS (select * FROM (VALUES (ARRAY[1,2,3,3,4]), (ARRAY[1,2,2,3,4])) t )
>     SELECT array_agg(unnest(column1)) FROM "a";
>
> ERROR:  set-valued function called in context that cannot accept a set

Нужно больше уровней вложенности:
WITH "a" AS (select * FROM (VALUES (ARRAY[1,2,3,3,4]), (ARRAY[1,2,2,3,4])) t )
    SELECT array_agg(n) from (select unnest(column1) as n FROM "a") as x;

> И второй вопрос:
>
> допустим имеется массив:
>
> {1,2,3,3,4,1,2,2,3,4}
>
> Как можно посчитать число уникальных элементов в нем?
>
> SELECT COUNT(DISTINCT unnest(ARRAY[1,2,3,3,4,1,2,2,3,4]))
>
> дает ту же ошибку

SELECT COUNT(DISTINCT n) from (select unnest(ARRAY[1,2,3,3,4,1,2,2,3,4])) as x(n);

--
Sergey Burladyan

In response to

pgsql-ru-general by date

Next:From: vladsDate: 2012-04-25 00:59:08
Subject: Остатки товара.
Previous:From: Sergey KonoplevDate: 2012-04-13 13:42:19
Subject: Re: [pgsql-ru-general] аггрегатор по а

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group