-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbigintarray--0.0.1.sql
87 lines (71 loc) · 2.03 KB
/
bigintarray--0.0.1.sql
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
CREATE OR REPLACE FUNCTION bigintarray_length(a bigint[]) RETURNS integer
LANGUAGE SQL
IMMUTABLE
RETURN array_length(a, 1);
CREATE OPERATOR # (
RIGHTARG = bigint[],
PROCEDURE = bigintarray_length
);
CREATE OR REPLACE FUNCTION bigintarray_intersect(a bigint[], b bigint[]) RETURNS bigint[]
LANGUAGE SQL
IMMUTABLE
RETURN ARRAY(SELECT UNNEST($1) INTERSECT SELECT UNNEST($2));
CREATE OPERATOR & (
LEFTARG = bigint[],
RIGHTARG = bigint[],
PROCEDURE = bigintarray_intersect
);
CREATE OR REPLACE FUNCTION bigintarray_union(a bigint[], b bigint[]) RETURNS bigint[]
LANGUAGE SQL
IMMUTABLE
RETURN ARRAY(SELECT UNNEST($1) UNION SELECT UNNEST($2));
CREATE OR REPLACE FUNCTION bigintarray_union_one(a bigint[], b bigint) RETURNS bigint[]
LANGUAGE SQL
IMMUTABLE
RETURN bigintarray_union(a, Array[b]::bigint[]);
CREATE OPERATOR | (
LEFTARG = bigint[],
RIGHTARG = bigint,
PROCEDURE = bigintarray_union_one
);
CREATE OPERATOR | (
LEFTARG = bigint[],
RIGHTARG = bigint[],
PROCEDURE = bigintarray_union
);
CREATE OR REPLACE FUNCTION bigintarray_except(a bigint[], b bigint[]) RETURNS bigint[]
LANGUAGE SQL
IMMUTABLE
RETURN ARRAY(SELECT UNNEST($1) EXCEPT SELECT UNNEST($2));
CREATE OPERATOR - (
LEFTARG = bigint[],
RIGHTARG = bigint[],
PROCEDURE = bigintarray_except
);
CREATE OR REPLACE FUNCTION bigintarray_except_one(a bigint[], b bigint) RETURNS bigint[]
LANGUAGE SQL
IMMUTABLE
RETURN bigintarray_except(a, Array[b]);
CREATE OPERATOR - (
LEFTARG = bigint[],
RIGHTARG = bigint,
PROCEDURE = bigintarray_except_one
);
CREATE OR REPLACE FUNCTION bigintarray_concat_one(a bigint[], b bigint) RETURNS bigint[]
LANGUAGE SQL
IMMUTABLE
RETURN array_cat(a, Array[b]);
CREATE OPERATOR + (
LEFTARG = bigint[],
RIGHTARG = bigint,
PROCEDURE = bigintarray_concat_one
);
CREATE OR REPLACE FUNCTION bigintarray_concat(a bigint[], b bigint[]) RETURNS bigint[]
LANGUAGE SQL
IMMUTABLE
RETURN array_cat(a, b);
CREATE OPERATOR + (
LEFTARG = bigint[],
RIGHTARG = bigint[],
PROCEDURE = bigintarray_concat
);