2014-12-05 28 views
1

我收到错误,json_each函数不存在。我正在使用postgresql 9.3。我不知道什么是错的。请在这里帮助我。函数json_each不存在

select * 
from json_each((
    select ed.result 
    from externaldata ed 
    inner join 
    application a 
    on a.id = ed.application_id 

)) 
limit 1; 

内部循环查询返回:

" { "RespuestaSVC89":{ 
    "Header":{ 
     "Transaccion":"EXPE", 
     "Servicio":"92", 
     "CodigoRetorno":"00", 
     "NumeroOperacion":"201409147001616", 
     "CodigoModelo":"13852901" 
    }, 
    "meta":{ 
     "billa":"EXPE", 
     "numo":"52", 
     "Retorno":"01", 
     "Operacion":"2014091470", 
    } 
    } 
}" 

所以它应该工作,但不知何故不工作

确切的错误信息是:

ERROR: function json_each(text) does not exist 
LINE 2: from json_each((
      ^
HINT: No function matches the given name and argument types. You might need to add explicit type casts. 
********** Error ********** 

ERROR: function json_each(text) does not exist 
SQL state: 42883 
Hint: No function matches the given name and argument types. You might need to add explicit type casts. 
Character: 15 
+0

请发布**完全**错误信息(使用复制粘贴) – 2014-12-05 19:36:06

+0

什么数据类型是ed.result?它是文本还是json?尝试将其转换为json – 2014-12-05 21:00:24

+0

@a_horse_with_no_name我发布了它。 – Billa 2014-12-07 02:16:34

回答

3

的错误消息指出没有json_each(文本)函数存在,但是我知道有一个json_each(json)函数存在。关键是铸造ed.result以JSON数据类型,像这样:

select * 
from json_each((
    select ed.result::json 
    from externaldata ed 
    inner join 
    application a 
    on a.id = ed.application_id 

)) 
limit 1; 

你可能会考虑ed.result列是类型JSON(在实际的表),而不是类型的文本,如果你的数据确实是所有的有效JSON。当9.4出现时,您几乎肯定会想要使用jsonb数据类型来利用该数据类型带来的性能和空间优势。

+0

当我运行此查询时出现以下错误: 错误:子查询返回多于一行作为表达式 **********错误**** ****** – Billa 2014-12-08 10:48:37

+0

您是使用这个确切的SQL或其他东西。我无法理解这将发生在这个确切的SQL ..这是SQL包装在更多的SQL?你能给我们一个完整的SQL返回这个错误的例子吗? – 2017-06-05 14:17:55