如何计数一个表中的postgresql的条款数? [英] How to count the number of terms in a table with postgresql?
本文介绍了如何计数一个表中的postgresql的条款数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
alldp
charcter varraying
alldp charcter varraying
"K409,K358,K353,L059,R100,L050,K610,K352,K429,C181,D129,K565,T8558,K560,K402,A045,K661,I841,I848,Z433"
$ b b
我可以算。这里是20.
I can count them. here is 20.
但是如果我想在Postgres中写一个语句来获取20,我该怎么办?
But if I want to write a statement in Postgres to get 20, how should I do?
推荐答案
您可以将字符串拆分为数组,然后计算结果数组中的元素:
You can split the string into an array and then count the elements in the resulting array:
select array_length(string_to_array(the_column, ','), 1)
from the_table;
但是你应该考虑修改你的数据模型。在列中存储逗号分隔值几乎总是一个坏主意。
But you should really consider fixing your data model. Storing comma separated values in a column is almost always a bad idea.
这篇关于如何计数一个表中的postgresql的条款数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文