这可能为时过早,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