如何将整数转换为字符串并获取字符串的长度

coa*_*ala 3 postgresql type-conversion

在我的数据库中有一个last_id类型的字段integer.该表包含多行.假设最大值last_id是104050.现在我想知道这个整数的长度.

由于这是不可能的,我试图将其转换为字符串.

SELECT to_char(MAX(last_id),'99') FROM xxxx
Run Code Online (Sandbox Code Playgroud)

我希望这会产生10与type = text,但它返回## type = text.之后我会用SELECT char_length(to_char(MAX(last_id),'99')) FROM xxx哪个应该返回2 ......

这里出了什么问题?

Erw*_*ter 11

演员integer价值text:

SELECT length(max(last_id)::text) FROM xxx
Run Code Online (Sandbox Code Playgroud)