Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 从jsonb字符串列表postgres中获取第一个元素_Postgresql_Spring Data Jpa_Postgresql 9.6 - Fatal编程技术网

Postgresql 从jsonb字符串列表postgres中获取第一个元素

Postgresql 从jsonb字符串列表postgres中获取第一个元素,postgresql,spring-data-jpa,postgresql-9.6,Postgresql,Spring Data Jpa,Postgresql 9.6,我有一个列表,它作为jsonb存储在我的表中,需要一个本机查询来从这个jsonb列获取第一个元素 尝试使用jsonb_数组_元素_文本,但无法使其正常工作 select col from tbl; 返回: [“abc”、“def”、“etc”] 我需要一个只返回abc的查询。您可以使用选择数组第n个元素的: select col ->> 0 as first_element from tbl; 请注意,与Postgres原生数组不同,JSON数组中的第一个元素具有索引0

我有一个列表,它作为jsonb存储在我的表中,需要一个本机查询来从这个jsonb列获取第一个元素

尝试使用jsonb_数组_元素_文本,但无法使其正常工作

select col from tbl;
返回:

[“abc”、“def”、“etc”]
我需要一个只返回abc的查询。您可以使用选择数组第n个元素的:

select col ->> 0 as first_element
from tbl;
请注意,与Postgres原生数组不同,JSON数组中的第一个元素具有索引
0