Chinaunix

标题: 请帮我看个函数出错的问题 [打印本页]

作者: hmchzb19    时间: 2016-12-29 16:23
标题: 请帮我看个函数出错的问题
这个函数定义如下: 我是从这一篇blog 上看来的:https://blog.interlinked.org/tutorials/postgresql.html

  1. create or replace function jmember (j json, key text )
  2. RETURNS text
  3. LANGUAGE plv8
  4. IMMUTABLE
  5. AS $function$
  6.   var ej = JSON.parse(j);
  7.   if (typeof ej != 'object')
  8.         return NULL;
  9.   return JSON.stringify(ej[key]);
  10. $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








欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2