这个函数定义如下: 我是从这一篇blog 上看来的:https://blog.interlinked.org/tutorials/postgresql.html
- create or replace function jmember (j json, key text )
- RETURNS text
- LANGUAGE plv8
- IMMUTABLE
- AS $function$
- var ej = JSON.parse(j);
- if (typeof ej != 'object')
- return NULL;
- return JSON.stringify(ej[key]);
- $function$;
复制代码
The jmember function allows us to parse and read the JSON string and returns the member identified by key: select jmember(data, 'title') from jsontest; jmember----------------- "right"(1 row) Andrew also shows how to build an index to speed up access times in his post. 这个函数我不能成功执行 报错如下:
点击(此处)折叠或打开
- postgres=# select jmember(data, 'title') from jsontest;
- ERROR: SyntaxError: Unexpected token o
- DETAIL: undefined() LINE 0: [object Object
|