domain gets cast to a text type - Mailing list pgsql-general

From Igor Stassiy
Subject domain gets cast to a text type
Date
Msg-id CAKVOjex6jAC9_OipEEqQgPPh+-pJ2CpCBAnpC1aQQjbP9+NSMQ@mail.gmail.com
Whole thread Raw
List pgsql-general
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

pgsql-general by date:

Previous
From: "Bald, Glenn"
Date:
Subject: Re: Unknown error while running <> postgresql_installer_dc46cfee2c\getlocales.exe
Next
From: pinker
Date:
Subject: Re: infinite recursion detected in rules for relation