Skip to content

jsonb accessors return with metadata #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions src/encrypted/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,13 @@ AS $$
END;
$$ LANGUAGE plpgsql;


CREATE FUNCTION eql_v2.meta_data(val eql_v2_encrypted)
RETURNS jsonb
IMMUTABLE STRICT PARALLEL SAFE
AS $$
BEGIN
RETURN eql_v2.meta_data(val.data);
END;
$$ LANGUAGE plpgsql;

8 changes: 6 additions & 2 deletions src/operators/->.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ CREATE FUNCTION eql_v2."->"(e eql_v2_encrypted, selector text)
IMMUTABLE STRICT PARALLEL SAFE
AS $$
DECLARE
meta jsonb;
sv eql_v2_encrypted[];
found eql_v2_encrypted;
found jsonb;
BEGIN

IF e IS NULL THEN
RETURN NULL;
END IF;

-- Column identifier and version
meta := eql_v2.meta_data(e);

sv := eql_v2.ste_vec(e);

FOR idx IN 1..array_length(sv, 1) LOOP
Expand All @@ -41,7 +45,7 @@ AS $$
END IF;
END LOOP;

RETURN found;
RETURN (meta || found)::eql_v2_encrypted;
END;
$$ LANGUAGE plpgsql;

Expand Down
17 changes: 17 additions & 0 deletions src/operators/->_test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,20 @@ DO $$
END;
$$ LANGUAGE plpgsql;


--
-- Field accessor returns column metadata
--
DO $$
DECLARE
result jsonb;
BEGIN
PERFORM seed_encrypted_json();

SELECT e->'2517068c0d1f9d4d41d2c666211f785e'::text FROM encrypted LIMIT 1 INTO result;

ASSERT result ? 'i';
ASSERT result ? 'v';

END;
$$ LANGUAGE plpgsql;