Re: Arrays - selecting (and not removing) duplicates...

Поиск
Список
Период
Сортировка
От Pól Ua Laoínecháin
Тема Re: Arrays - selecting (and not removing) duplicates...
Дата
Msg-id CAF4RT5StDJy_9+UFy2nGazsajJp46dyDNL4GyDvc7H+w=o_jWQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Arrays - selecting (and not removing) duplicates...  (hubert depesz lubaczewski <depesz@depesz.com>)
Ответы Re: Arrays - selecting (and not removing) duplicates...  (Pól Ua Laoínecháin <linehanp@tcd.ie>)
Список pgsql-general
Hi Hubert, and thanks for your input!

> > I was just wondering if there is some (already written) function out
> > there that will drop this functionality into my lap?

> #v+
> create function array_dups(ANYARRAY) returns ANYARRAY as $$
>     select array( select i from unnest($1) i group by i having count(*) > 1 );
> $$ language sql;
> #v-

I'm a bit of a novice with PostgreSQL functions I'm afraid.

I can call your function this way:

SELECT ARRAY_DUPS(ARRAY[1, 2, 3, 4, 4]) AS dups;

and the answer is

dups
{4}

as I would expect. I can also do this:

SELECT ARRAY[1,3,4,1, 5,6,5, 67]  AS my_nums;
answer is
my_nums
array{1,3,4,1,5,6,5,67}

But, when I do this:

SELECT ARRAY_DUPS(SELECT ARRAY[1,3,4,1, 5,6,5, 67])

I get an error:

ERROR: syntax error at or near "SELECT" LINE 1:
SELECT ARRAY_DUPS(SELECT ARRAY[1,3,4,1, 5,6,5, 67])


I want to "feed" the result of a query into your function - is there
something special I have to do for this?

TIA and rgs,


Pól...

> depesz



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

Предыдущее
От: hubert depesz lubaczewski
Дата:
Сообщение: Re: Pg stuck at 100% cpu, for multiple days
Следующее
От: hubert depesz lubaczewski
Дата:
Сообщение: Re: Can we get rid of repeated queries from pg_dump?