这可能为时过早,postgres 9.4仍处于测试阶段。我一直在试验jsonb类型。我没有运气将jsonb类型传递给plv8函数,它以类型字符串形式出现。我想知道我做错了吗?
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$;
然后,当我使用json运行时:
psql=# select jt('{"member":"test"}'::json);
INFO: type is object
INFO: argument is [object Object]
INFO: member is test
但是,当我用jsonb运行时:
psql=# select jt('{"member":"test"}'::jsonb);
INFO: type is string
INFO: argument is {"member": "test"}
INFO: member is undefined
-g
答案 0 :(得分:5)
PL / V8需要在此之前添加对JSONB的支持。
同时你仍然可以通过普通json
;只需将jsonb
投射到json
。