PostgreSQL的JSON类型返回null

时间:2015-09-06 08:14:34

标签: postgresql-9.3

我在technologies列中有以下记录:

[{"id":1,"name":"PHP"},{"id":2,"name":"Laravel"}]

当我运行查询时:

SELECT  technologies->>'name' AS name FROM technologies;

它始终返回null,尽管记录就在那里。

我正在使用Postgres 9.3

1 个答案:

答案 0 :(得分:2)

你有一个json元素数组,所以你需要先得到所需的数组元素:(technologies -> 0)->>'name'(technologies -> 1)->>'name'

您还可以使用函数json_array_elements将元素转换为行:

select json_array_elements(technologies)->>'name'
from technologies;