-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpubLib04-aggregate.sql
More file actions
39 lines (32 loc) · 1.1 KB
/
pubLib04-aggregate.sql
File metadata and controls
39 lines (32 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
CREATE or replace FUNCTION stragg_prefix(prefix text, s text[], sep text default ',') RETURNS text AS $f$
SELECT string_agg(x,sep) FROM ( select prefix||(unnest(s)) ) t(x)
$f$ LANGUAGE SQL IMMUTABLE;
DROP AGGREGATE IF EXISTS array_agg_cat(anycompatiblearray) CASCADE;
CREATE AGGREGATE array_agg_cat(anycompatiblearray) (
SFUNC=array_cat,
STYPE=anycompatiblearray,
INITCOND='{}'
);
-- -- -- -- -- -- -- -- -- -- --
-- Depends on pubLib01-array.sql
DROP AGGREGATE IF EXISTS array_agg_cat_distinct(anyarray);
CREATE or replace AGGREGATE array_agg_cat_distinct(anyarray) (
SFUNC=array_cat_distinct,
STYPE=anyarray,
INITCOND='{}'
);
-- -- -- -- -- -- -- -- -- -- --
-- ! Depends on pubLib03-json.sql
DROP AGGREGATE IF EXISTS jsonb_summable_aggmerge(jsonb) CASCADE;
CREATE AGGREGATE jsonb_summable_aggmerge(jsonb) ( -- important!
SFUNC=jsonb_summable_merge,
STYPE=jsonb,
INITCOND=NULL
);
/* DROP AGGREGATE IF EXISTS jsonb_summable_aggmerge(jsonb[]) CASCADE;
CREATE AGGREGATE jsonb_summable_aggmerge(jsonb[]) ( -- low use
SFUNC=jsonb_summable_merge,
STYPE=jsonb[],
INITCOND='{}' -- test with null
);
*/