Skip to content

Commit 55007b6

Browse files
committed
feat: compare literal
1 parent 9f0895b commit 55007b6

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/encrypted/compare.sql

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
-- REQUIRE: src/schema.sql
2+
-- REQUIRE: src/encrypted/types.sql
3+
4+
--
5+
-- Compare two eql_v2_encrypted values as literal jsonb values
6+
-- Used as a fallback when no suitable search term is available
7+
--
8+
CREATE FUNCTION eql_v2.compare_literal(a eql_v2_encrypted, b eql_v2_encrypted)
9+
RETURNS integer
10+
IMMUTABLE STRICT PARALLEL SAFE
11+
AS $$
12+
DECLARE
13+
a_data jsonb;
14+
b_data jsonb;
15+
BEGIN
16+
17+
IF a IS NULL AND b IS NULL THEN
18+
RETURN 0;
19+
END IF;
20+
21+
IF a IS NULL THEN
22+
RETURN -1;
23+
END IF;
24+
25+
IF b IS NULL THEN
26+
RETURN 1;
27+
END IF;
28+
29+
a_data := a.data;
30+
b_data := b.data;
31+
32+
IF a_data < b_data THEN
33+
RETURN -1;
34+
END IF;
35+
36+
IF a_data > b_data THEN
37+
RETURN 1;
38+
END IF;
39+
40+
RETURN 0;
41+
END;
42+
$$ LANGUAGE plpgsql;

0 commit comments

Comments
 (0)