domain gets cast to a text type

Поиск
Список
Период
Сортировка
От Igor Stassiy
Тема domain gets cast to a text type
Дата
Msg-id CAKVOjex6jAC9_OipEEqQgPPh+-pJ2CpCBAnpC1aQQjbP9+NSMQ@mail.gmail.com
обсуждение исходный текст
Список 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 по дате отправления:

Предыдущее
От: "Bald, Glenn"
Дата:
Сообщение: Re: Unknown error while running <> postgresql_installer_dc46cfee2c\getlocales.exe
Следующее
От: pinker
Дата:
Сообщение: Re: infinite recursion detected in rules for relation