gpt4 book ai didi

postgresql - Postgres 按数组值排序

转载 作者:行者123 更新时间:2023-11-29 12:54:24 24 4
gpt4 key购买 nike

在我的表中,我有一个名为 facebook 的列,其类型为 text[],其中包含数组。例如:

{{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

所以我添加了::numeric

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

但是我收到一个错误:

cannot cast type text[] to numeric

有什么解决办法吗?

最佳答案

cannot cast type text[] to numeric

您需要转换为 numeric[]:

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

关于postgresql - Postgres 按数组值排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46856000/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com