String 如何在postgresql中获取字符串列的字符串长度

String 如何在postgresql中获取字符串列的字符串长度,string,postgresql,String,Postgresql,给定一个文本/字符串列的输入,我想计算列中字符串的长度,以及每个长度的计数 例如,带有字符串的列: 'Ant' 'Cat' 'Dog' 'Human' '' NULL 'A human' 将提供: 0 : 1 3 : 3 5 : 1 7 : 1 注意:空字符串未计为0字符串,但已被忽略。length() select length(col), count(*) from t where col is not null group by length(col) order by length(

给定一个文本/字符串列的输入,我想计算列中字符串的长度,以及每个长度的计数

例如,带有字符串的列:

'Ant'
'Cat'
'Dog'
'Human'
''
NULL
'A human'
将提供:

0 : 1
3 : 3
5 : 1
7 : 1
注意:空字符串未计为0字符串,但已被忽略。

length()

select length(col), count(*)
from t
where col is not null
group by length(col)
order by length(col);

谢谢,现在试试这个