-
Notifications
You must be signed in to change notification settings - Fork 0
/
pg_etag--unpackaged--1.0.sql
66 lines (57 loc) · 2.18 KB
/
pg_etag--unpackaged--1.0.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
CREATE OR REPLACE FUNCTION pg_etag_state(BYTEA, text)
RETURNS BYTEA
AS 'pg_etag', 'pg_etag_state'
LANGUAGE C IMMUTABLE STRICT;
COMMENT ON FUNCTION pg_etag_state(BYTEA, text) IS 'State function for etag_agg(text) aggregate.';
CREATE OR REPLACE FUNCTION pg_etag_state(BYTEA, BYTEA)
RETURNS BYTEA
AS 'pg_etag', 'pg_etag_state_b'
LANGUAGE C IMMUTABLE STRICT;
COMMENT ON FUNCTION pg_etag_state(BYTEA, BYTEA) IS 'State function for etag_agg(text) aggregate.';
CREATE OR REPLACE FUNCTION pg_etag_final(BYTEA)
RETURNS text
AS 'pg_etag', 'pg_etag_final'
LANGUAGE C IMMUTABLE STRICT;
COMMENT ON FUNCTION pg_etag_final(text) IS 'Finalize function for etag_agg(text) aggregate.';
DROP AGGREGATE IF EXISTS etag_agg(text);
CREATE AGGREGATE etag_agg(text) (
SFUNC = pg_etag_state,
STYPE = BYTEA,
INITCOND = '',
FINALFUNC = pg_etag_final
);
COMMENT ON AGGREGATE etag_agg(text) IS 'ETag BLAKE2 aggregate function.';
DROP AGGREGATE IF EXISTS etag_agg(BYTEA);
CREATE AGGREGATE etag_agg(BYTEA) (
SFUNC = pg_etag_state,
STYPE = BYTEA,
INITCOND = '',
FINALFUNC = pg_etag_final
);
COMMENT ON AGGREGATE etag_agg(BYTEA) IS 'ETag BLAKE2 aggregate function.';
CREATE OR REPLACE FUNCTION etag(text)
RETURNS text
AS 'pg_etag', 'pg_etag_single'
LANGUAGE C IMMUTABLE STRICT;
COMMENT ON FUNCTION etag(text) IS 'Non aggregate (single input) ETag BLAKE2 function.';
CREATE OR REPLACE FUNCTION etag(BYTEA)
RETURNS text
AS 'pg_etag', 'pg_etag_single_b'
LANGUAGE C IMMUTABLE STRICT;
COMMENT ON FUNCTION etag(BYTEA) IS 'Non aggregate (single input) ETag BLAKE2 function.';
CREATE OR REPLACE FUNCTION blake2(text, integer default 64)
RETURNS text
AS 'pg_etag', 'pg_blake2_single'
LANGUAGE C IMMUTABLE STRICT;
COMMENT ON FUNCTION blake2(text, integer) IS 'Non aggregate (single input) BLAKE2 function.';
CREATE OR REPLACE FUNCTION blake2(BYTEA, integer default 64)
RETURNS text
AS 'pg_etag', 'pg_blake2_single_b'
LANGUAGE C IMMUTABLE STRICT;
COMMENT ON FUNCTION blake2(BYTEA, integer) IS 'Non aggregate (single input) BLAKE2 function.';
CREATE OR REPLACE FUNCTION public.etag(id oid)
RETURNS text
AS $$
SELECT etag_agg("data") FROM (SELECT l."data" from pg_largeobject l WHERE l.loid=id ORDER BY l.pageno ASC) t;
$$
LANGUAGE sql VOLATILE strict;