json - 在 Postgres 中查询 JSON 错误 : function json_extract_path_text(text, 文本)不存在

标签 json postgresql

我正在尝试根据对包含 Postgres 最新版本 (9.3.4) 中的 JSON 的 text 列的查询设置 View ,但我收到一个错误找不到任何讨论。

假设该表名为 table1 并且特定列 json_data 具有类似于

{"item1": "value1", "item2": "value2", "item3": 3, "item4": 4, "item5": 5}

这是我的查询:

SELECT 
json_extract_path_text((table1.json_data)::text, 
('item1'::character varying)::text) AS item1
FROM
table1

我得到的错误是

ERROR:  function json_extract_path_text(text, text) does not exist
LINE 2: json_extract_path_text((table1.json_data)...
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

我不知道如何解决这个问题。 (此外,我有一个类似的 View ,它在特定表中的类似 text 列上使用相同的语法完全可以正常工作。)

最佳答案

由于 table1.json_data 已经是文本,您需要将其转换为 json。您也不需要指定表名,因为它在 FROM 子句中。

SELECT json_extract_path_text(json_data::json,'item1') AS item1 FROM table1;

关于json - 在 Postgres 中查询 JSON 错误 : function json_extract_path_text(text, 文本)不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24235856/

相关文章:

json - 使用 JQ 删除具有某些键值对的父元素

json - 在 dart 中访问 json 元素

javascript - 将变量传递给不同的函数

postgresql - Knex 迁移不起作用,怎么了?

c++ - 使用 PostgreSQL RETURNING .. INTO 子句将插入的值返回到变量中

python - 如何在Django中内连接4个表?

javascript - 使用 AppleScript 和 JSON 解析数据时出错

sql - 使用sql检测循环

sql - PostgreSQL:选择所有字段,过滤一些

javascript - 从php返回json到ajax