File tree Expand file tree Collapse file tree 3 files changed +67
-1
lines changed
Expand file tree Collapse file tree 3 files changed +67
-1
lines changed Original file line number Diff line number Diff line change 4646$$ LANGUAGE plpgsql;
4747
4848
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+
4983CREATE OPERATOR - > (
5084 FUNCTION= eql_v1." ->" ,
5185 LEFTARG= eql_v1_encrypted,
5286 RIGHTARG= text
5387);
5488
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 44SELECT create_table_with_encrypted();
55SELECT seed_encrypted_json();
66
7+
78--
89-- The -> operator returns an encrypted matching the selector
910DO $$
5152 END;
5253$$ LANGUAGE plpgsql;
5354
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)
7676 IMMUTABLE STRICT PARALLEL SAFE
7777AS $$
7878 BEGIN
79-
8079 IF val ? ' a' THEN
8180 RETURN (val- >> ' a' )::boolean ;
8281 END IF;
You can’t perform that action at this time.
0 commit comments