Hi,
you might not be able to run this code, but maybe you know why is there a type conversion with domain and the concept might apply to other examples as well. I have the following code:
CREATE FUNCTION get_key_jsonb(key text, j jsonb) RETURNS text
LANGUAGE plv8 IMMUTABLE STRICT
AS $$
plv8.elog(NOTICE, typeof j);
return "ok";
$$;
CREATE FUNCTION valid_jsonb(j jsonb) RETURNS boolean
LANGUAGE plv8 IMMUTABLE STRICT
AS $$
return true;
$$;
select get_key_jsonb('ok', '{"ok": true}'::jsonb);
prints object, however if we create a domain for the type
CREATE DOMAIN plv8.jsonb AS jsonb
CONSTRAINT jsonb_check CHECK (valid_jsonb(VALUE));
and replace function input type
DROP FUNCTION get_key_jsonb(text, jsonb);
CREATE FUNCTION get_key_jsonb(key text, j plv8.jsonb) RETURNS text
LANGUAGE plv8 IMMUTABLE STRICT
AS $$
plv8.elog(NOTICE, typeof j);
return "ok";
$$;
select get_key_jsonb('ok', '{"ok": true}'::jsonb);
prints string
So there is some conversion of the original type 'jsonb' to 'text' when passed to v8 depending on whether the function argument is defined via a domain. Do you have an idea why is this the case? Is this the expected behaviour?
-Igor