File tree 3 files changed +67
-1
lines changed
3 files changed +67
-1
lines changed Original file line number Diff line number Diff line change 46
46
$$ LANGUAGE plpgsql;
47
47
48
48
49
+ --
50
+
51
+
52
+ DROP OPERATOR IF EXISTS - > (eql_v1_encrypted, integer );
53
+
54
+ DROP FUNCTION IF EXISTS eql_v1." ->" (e eql_v1_encrypted, selector integer );
55
+
56
+ CREATE FUNCTION eql_v1 ." ->" (e eql_v1_encrypted, selector integer )
57
+ RETURNS eql_v1_encrypted
58
+ IMMUTABLE STRICT PARALLEL SAFE
59
+ AS $$
60
+ DECLARE
61
+ sv eql_v1_encrypted[];
62
+ found eql_v1_encrypted;
63
+ BEGIN
64
+ IF NOT eql_v1 .is_ste_vec_array (e) THEN
65
+ RETURN NULL ;
66
+ END IF;
67
+
68
+ sv := eql_v1 .ste_vec (e);
69
+
70
+ -- PostgreSQL arrays are 1-based
71
+ -- JSONB arrays are 0-based and so the selector is 0-based
72
+ FOR idx IN 1 ..array_length(sv, 1 ) LOOP
73
+ if (idx- 1 ) = selector THEN
74
+ found := sv[idx];
75
+ END IF;
76
+ END LOOP;
77
+
78
+ RETURN found;
79
+ END;
80
+ $$ LANGUAGE plpgsql;
81
+
82
+
49
83
CREATE OPERATOR - > (
50
84
FUNCTION= eql_v1." ->" ,
51
85
LEFTARG= eql_v1_encrypted,
52
86
RIGHTARG= text
53
87
);
54
88
89
+
90
+ CREATE OPERATOR - > (
91
+ FUNCTION= eql_v1." ->" ,
92
+ LEFTARG= eql_v1_encrypted,
93
+ RIGHTARG= integer
94
+ );
95
+
Original file line number Diff line number Diff line change 4
4
SELECT create_table_with_encrypted();
5
5
SELECT seed_encrypted_json();
6
6
7
+
7
8
--
8
9
-- The -> operator returns an encrypted matching the selector
9
10
DO $$
51
52
END;
52
53
$$ LANGUAGE plpgsql;
53
54
55
+
56
+
57
+ --
58
+ -- encrypted returned from -> operator expression called via eql_v1.ciphertext
59
+ --
60
+ DO $$
61
+ DECLARE
62
+ result eql_v1_encrypted;
63
+ BEGIN
64
+
65
+ PERFORM truncate_table_with_encrypted();
66
+ PERFORM seed_encrypted(get_array_ste_vec()::eql_v1_encrypted);
67
+
68
+ PERFORM assert_result(
69
+ ' -> operator with integer returns array' ,
70
+ ' SELECT eql_v1.jsonb_path_query_first(e, ' ' f510853730e1c3dbd31b86963f029dd5' ' )->0 as e FROM encrypted' );
71
+
72
+ PERFORM assert_count(
73
+ ' -> operator with integer returns array' ,
74
+ ' SELECT eql_v1.jsonb_path_query_first(e, ' ' f510853730e1c3dbd31b86963f029dd5' ' )->0 as e FROM encrypted' ,
75
+ 1 );
76
+
77
+ END;
78
+ $$ LANGUAGE plpgsql;
79
+
Original file line number Diff line number Diff line change @@ -76,7 +76,6 @@ CREATE FUNCTION eql_v1.is_ste_vec_array(val jsonb)
76
76
IMMUTABLE STRICT PARALLEL SAFE
77
77
AS $$
78
78
BEGIN
79
-
80
79
IF val ? ' a' THEN
81
80
RETURN (val- >> ' a' )::boolean ;
82
81
END IF;
You can’t perform that action at this time.
0 commit comments