Re: Array_agg and dimensions in Array
От | Alexey Bashtanov |
---|---|
Тема | Re: Array_agg and dimensions in Array |
Дата | |
Msg-id | e06a5c6e-a92e-f5e2-46a7-4e8652d6a245@imap.cc обсуждение исходный текст |
Ответ на | Array_agg and dimensions in Array (Mike Martin <redtux1@gmail.com>) |
Список | pgsql-general |
Hi Mike,
alexey@[local]/alexey=# create aggregate array_cat_agg(anyarray) (SFUNC = array_cat, STYPE = anyarray, COMBINEFUNC = array_cat, PARALLEL = SAFE);
CREATE AGGREGATE
And use it like this:
alexey@[local]/alexey=# select grp, array_cat_agg(array['--foo', bar || '=' || baz]) from (values ('g1', 'a', 'b'), ('g1', 'c', 'd'), ('g2', 'e', 'f')) _ (grp, bar, baz) group by grp;
┌─────┬───────────────────────┐
│ grp │ array_cat_agg │
├─────┼───────────────────────┤
│ g2 │ {--foo,e=f} │
│ g1 │ {--foo,a=b,--foo,c=d} │
└─────┴───────────────────────┘
(2 rows)
Is that what you need?
Best, Alex
I have come across a problem which I cant seem to solve in a nice wayYou can create a custom aggregate function like this:
Basically I have a (small) table of tags
What I need to is combine two concatenated fields with a literal value as an array element.
alexey@[local]/alexey=# create aggregate array_cat_agg(anyarray) (SFUNC = array_cat, STYPE = anyarray, COMBINEFUNC = array_cat, PARALLEL = SAFE);
CREATE AGGREGATE
And use it like this:
alexey@[local]/alexey=# select grp, array_cat_agg(array['--foo', bar || '=' || baz]) from (values ('g1', 'a', 'b'), ('g1', 'c', 'd'), ('g2', 'e', 'f')) _ (grp, bar, baz) group by grp;
┌─────┬───────────────────────┐
│ grp │ array_cat_agg │
├─────┼───────────────────────┤
│ g2 │ {--foo,e=f} │
│ g1 │ {--foo,a=b,--foo,c=d} │
└─────┴───────────────────────┘
(2 rows)
Is that what you need?
Best, Alex
В списке pgsql-general по дате отправления: