Php Postgres-从数组中选择元素

Php Postgres-从数组中选择元素,php,sql,postgresql,postgresql-9.3,Php,Sql,Postgresql,Postgresql 9.3,在我的表中,我有一个名为facebook的列,名为type text[]。例如,一行是: {{total_count,26861},{comment_count,94},{comment_plugin_count,0},{share_count,26631},{reaction_count,136}} 现在我尝试只选择总计数。我尝试了所有的方法,结果是: SELECT json_each(to_json(facebook))->>'total_count' AS total_cou

在我的表中,我有一个名为facebook的列,名为type text[]。例如,一行是:

{{total_count,26861},{comment_count,94},{comment_plugin_count,0},{share_count,26631},{reaction_count,136}}
现在我尝试只选择总计数。我尝试了所有的方法,结果是:

SELECT json_each(to_json(facebook))->>'total_count' AS total_count"
但我有一个错误: 运算符不存在:记录->>未知\n行1:

有什么想法吗

//编辑

现在我有了这个

$select = "WITH fejs AS ( select json_array_elements(to_json(facebook)) e FROM $table ), arr AS ( select e->1 as total_count FROM fejs WHERE e->>0 = 'total_count') SELECT ".implode(", ", SSP::pluckas($columns))."
         , count(*) OVER() AS full_count
         FROM $table             
         $where
         $order
         $limit";

是否有一种方法可以将total_count添加到订单中?

您在facebook属性中有文本数组数组,因此to_json也将其转换为多维数组,因此您需要操作数组,例如:

t=# with t(facebook) as (values('{{total_count,26861},{comment_count,94},{comment_plugin_count,0},{share_count,26631},{reaction_count,136}}'::text[]))
, arr as (select json_array_elements(to_json(facebook)) e from t)
select e->1 as total_count from arr where e->>0 = 'total_count';
 total_count
-------------
 "26861"
(1 row)