Skip to content

Commit

Permalink
Add more tests and binary convertion functions
Browse files Browse the repository at this point in the history
  • Loading branch information
za-arthur committed Jan 19, 2024
1 parent 9cec7dd commit fefa228
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
14 changes: 12 additions & 2 deletions saturated_int--0.0.1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
Expand Down
21 changes: 21 additions & 0 deletions test/expected/002_saturated_int_agg.out
Original file line number Diff line number Diff line change
@@ -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)

9 changes: 9 additions & 0 deletions test/sql/002_saturated_int_agg.sql
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit fefa228

Please sign in to comment.