Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions sql/000-ore.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ CREATE FUNCTION compare_ore_64_8_v1_term(a ore_64_8_v1_term, b ore_64_8_v1_term)
indicator smallint := 0;
BEGIN
IF a IS NULL AND b IS NULL THEN
RETURN 0;
RETURN NULL;
END IF;

IF a IS NULL THEN
RETURN -1;
RETURN NULL;
END IF;

IF b IS NULL THEN
RETURN 1;
RETURN NULL;
END IF;

IF bit_length(a.bytes) != bit_length(b.bytes) THEN
Expand Down Expand Up @@ -239,13 +239,27 @@ RETURNS integer AS $$
DECLARE
cmp_result integer;
BEGIN
IF (array_length(a, 1) = 0 OR a IS NULL) AND (array_length(b, 1) = 0 OR b IS NULL) THEN
IF a IS NULL AND b IS NULL THEN
RETURN NULL;
END IF;

IF a IS NULL THEN
RETURN NULL;
END IF;

IF b IS NULL THEN
RETURN NULL;
END IF;

IF (array_length(a, 1) = 0) AND (array_length(b, 1) = 0) THEN
RETURN 0;
END IF;
IF array_length(a, 1) = 0 OR a IS NULL THEN

IF array_length(a, 1) = 0 THEN
RETURN -1;
END IF;
IF array_length(b, 1) = 0 OR a IS NULL THEN

IF array_length(b, 1) = 0 THEN
RETURN 1;
END IF;

Expand Down
9 changes: 7 additions & 2 deletions tests/operators-ore.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ CREATE TABLE users
TRUNCATE TABLE users;


TRUNCATE TABLE users;

-- User with "LOW" value
INSERT INTO users (name_encrypted) VALUES (
'{
Expand All @@ -30,6 +28,9 @@ INSERT INTO users (name_encrypted) VALUES (
}'::jsonb
);

INSERT INTO users (name_encrypted) VALUES (NULL);


-- ORE eq < OPERATORS
DO $$
DECLARE
Expand Down Expand Up @@ -57,6 +58,10 @@ DO $$
-- SANITY CHECK
ASSERT (SELECT EXISTS (SELECT id FROM users WHERE cs_ore_64_8_v1(name_encrypted) < cs_ore_64_8_v1(ore_json)));

-- ignore null
ASSERT (SELECT (SELECT COUNT(*) FROM (SELECT id FROM users WHERE cs_ore_64_8_v1(name_encrypted) < cs_ore_64_8_v1(ore_json)) as count) = 1);


ASSERT (SELECT EXISTS (
SELECT id FROM users WHERE name_encrypted < ore_cs_encrypted::jsonb
));
Expand Down