diff --git a/saturated_int--0.0.1.sql b/saturated_int--0.0.1.sql index 422eb75..58a0e8f 100644 --- a/saturated_int--0.0.1.sql +++ b/saturated_int--0.0.1.sql @@ -8,11 +8,21 @@ RETURNS cstring AS 'int4out' LANGUAGE internal IMMUTABLE STRICT PARALLEL SAFE; +CREATE FUNCTION sat_int4_recv(internal) +RETURNS saturated_int +AS 'int4recv' +LANGUAGE internal IMMUTABLE PARALLEL SAFE; + +CREATE FUNCTION sat_int4_send(saturated_int) +RETURNS bytea +AS 'int4send' +LANGUAGE internal IMMUTABLE PARALLEL SAFE; + CREATE TYPE saturated_int ( input = sat_int4_in, output = sat_int4_out, - -- receive = ..., - -- send = ..., + receive = sat_int4_recv, + send = sat_int4_send, like = integer, category = 'N' ); diff --git a/test/expected/002_saturated_int_agg.out b/test/expected/002_saturated_int_agg.out new file mode 100644 index 0000000..2b2810d --- /dev/null +++ b/test/expected/002_saturated_int_agg.out @@ -0,0 +1,21 @@ +CREATE TABLE sat_agg (id1 saturated_int, id2 saturated_int); +INSERT INTO sat_agg +SELECT i, 1 FROM pg_catalog.generate_series(2147483645::bigint, 2147483650::bigint) g(i); +SELECT * FROM sat_agg; + id1 | id2 +------------+----- + 2147483645 | 1 + 2147483646 | 1 + 2147483647 | 1 + 2147483647 | 1 + 2147483647 | 1 + 2147483647 | 1 +(6 rows) + +-- Test aggregate functions +SELECT sum(id1), sum(id2) FROM sat_agg; + sum | sum +------------+----- + 2147483647 | 6 +(1 row) + diff --git a/test/sql/002_saturated_int_agg.sql b/test/sql/002_saturated_int_agg.sql new file mode 100644 index 0000000..e38e424 --- /dev/null +++ b/test/sql/002_saturated_int_agg.sql @@ -0,0 +1,9 @@ +CREATE TABLE sat_agg (id1 saturated_int, id2 saturated_int); + +INSERT INTO sat_agg +SELECT i, 1 FROM pg_catalog.generate_series(2147483645::bigint, 2147483650::bigint) g(i); + +SELECT * FROM sat_agg; + +-- Test aggregate functions +SELECT sum(id1), sum(id2) FROM sat_agg;