如何计数一个表中的postgresql的条款数?

编程入门 行业动态 更新时间:2024-10-21 19:01:49
本文介绍了如何计数一个表中的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的条款数?

本文发布于:2023-10-29 03:44:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538627.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条款   postgresql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!