Skip to content

Instantly share code, notes, and snippets.

@Suor
Created December 7, 2016 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Suor/2623bb8ef65a63972fd21af3713ede90 to your computer and use it in GitHub Desktop.
Save Suor/2623bb8ef65a63972fd21af3713ede90 to your computer and use it in GitHub Desktop.
-- Возвращает уникальные элементы массива, порядок не сохраняет
create or replace function array_uniq(anyarray) returns anyarray as $$
select array(select distinct unnest($1))
$$ language sql immutable strict;
-- Аггрегирующая функция для конкатенации массивов
create aggregate array_concat (
sfunc = array_cat,
basetype = anyarray,
stype = anyarray,
initcond = '{}'
);
-- Аггрегирующая функция для конкатенации массивов с сохранением только уникальных элементов, порядок не сохраняется
create aggregate array_concat_uniq (
sfunc = array_cat,
finalfunc = array_uniq,
basetype = anyarray,
stype = anyarray,
initcond = '{}'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment