PostgreSQL 的 JSON 类型 returns 空
PostgreSQL's JSON type returns null
我在technologies
列中有如下记录:
[{"id":1,"name":"PHP"},{"id":2,"name":"Laravel"}]
当我 运行 查询时:
SELECT technologies->>'name' AS name FROM technologies;
它总是 returns 空,尽管记录就在那里。
我正在使用 Postgres 9.3
那里有一个 json 元素的数组,因此您需要先获取所需的数组元素:(technologies -> 0)->>'name'
或 (technologies -> 1)->>'name'
您还可以使用函数 json_array_elements
将元素转换为行:
select json_array_elements(technologies)->>'name'
from technologies;
我在technologies
列中有如下记录:
[{"id":1,"name":"PHP"},{"id":2,"name":"Laravel"}]
当我 运行 查询时:
SELECT technologies->>'name' AS name FROM technologies;
它总是 returns 空,尽管记录就在那里。
我正在使用 Postgres 9.3
那里有一个 json 元素的数组,因此您需要先获取所需的数组元素:(technologies -> 0)->>'name'
或 (technologies -> 1)->>'name'
您还可以使用函数 json_array_elements
将元素转换为行:
select json_array_elements(technologies)->>'name'
from technologies;