This may be premature, postgres 9.4 is still in beta. I've been experimenting with the jsonb type. I am not having any luck passing a jsonb type to a plv8 function, it comes in as type string. I was wondering if I was doing it wrong?
create or replace function jt ( o json ) returns integer language plv8 immutable
AS $function$
plv8.elog(INFO, 'type is ', typeof o);
plv8.elog(INFO, 'argument is ', o);
plv8.elog(INFO, 'member is ', o['member']);
$function$;
create or replace function jt ( o jsonb ) returns integer language plv8 immutable
AS $function$
plv8.elog(INFO, 'type is ', typeof o);
plv8.elog(INFO, 'argument is ', o);
plv8.elog(INFO, 'member is ', o['member']);
$function$;
then, when I run using json:
psql=# select jt('{"member":"test"}'::json);
INFO: type is object
INFO: argument is [object Object]
INFO: member is test
but, when I run with jsonb:
psql=# select jt('{"member":"test"}'::jsonb);
INFO: type is string
INFO: argument is {"member": "test"}
INFO: member is undefined
-g
PL/V8 will need to add support for JSONB before this works how you expect.
In the mean time you can still pass plain
json
; just cast thejsonb
tojson
.News since ~2015
plv8 project changed after 2014, as this comment of the project's sponsor and main contributor, JerrySievert, in 2017:
The last revision history show some clues about JSONb starting date:
in 2015-05-26 (version 1.4.4 ) "Add jsonb type coercion in function boundary".
in 2019-03-23 (version 2.3.10) "add direct jsonb conversion option", "add memory context for jsonb conversion".
The suggestion is to use JSONB with plv8 version 2.3.10 or later... Still, for older versions of plv8, Jarry confirmed that almost everything will be fine: