Jvb plv8 stored procedure

This may be premature, postgres 9.4 is still in beta. I experimented with jsonb type. I will not be able to pass the jsonb type to the plv8 function, it enters as a type string. I was wondering if I am doing this 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 jsonb:

psql=# select jt('{"member":"test"}'::jsonb);
INFO:  type is  string
INFO:  argument is  {"member": "test"}
INFO:  member is  undefined

-g

+4
source share
1 answer

PL / V8 will need to add JSONB support before it works as you expect.

At the same time, you can still go plain json; just type jsonbin json.

+5
source

All Articles