2017-10-20 135 views
1

在我的表中,我有一个名为facebook的列,其中的数组类型为text []。例如:Postgres按数组值排序

{{total_count,26861},{comment_count,94},{comment_plugin_count,0},{share_count,26631},{reaction_count,136}} 

我用我的数据库,数据表,当我试图通过Facebook来我的表进行排序我有这样的:

enter image description here

这是不对的。所以我试图从这个数组中只获取total_count作为数值。现在我有这样的:

regexp_matches(array_to_string(facebook, ' '), '(\d+).*') 

但这返回数组,例如:

enter image description here

所以我增加::数字

regexp_matches(array_to_string(facebook, ' '), '(\d+).*')::numeric 

,但我出现错误:

cannot cast type text[] to numeric

任何想法如何解决它?

+1

@ lad2025它是如此简单...非常感谢! –

+0

当然,我发布它作为答案:) – lad2025

回答

1

cannot cast type text[] to numeric

你需要转换为numeric[]

regexp_matches(array_to_string(facebook, ' '), '(\d+).*')::numeric[] 
+1

就是这样!现在它的工作。 –

+0

@DanielKoczuła请考虑接受我的回答[接受答案如何工作?](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235):) – lad2025