domain gets cast to a text type

From: Igor Stassiy <istassiy(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: domain gets cast to a text type
Date: 2015-02-13 15:14:16
Message-ID: CAKVOjex6jAC9_OipEEqQgPPh+-pJ2CpCBAnpC1aQQjbP9+NSMQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-general by date

  From Date Subject
Next Message pinker 2015-02-13 15:24:04 Re: infinite recursion detected in rules for relation
Previous Message Bald, Glenn 2015-02-13 14:58:26 Re: Unknown error while running <> postgresql_installer_dc46cfee2c\getlocales.exe