PostgreSQL将带逗号的字符串转换为整数

Aar*_*der 8 postgresql

我想将具有逗号整数的"字符变化"类型的列转换为常规整数列.

我想支持从'1'到'10,000,000'的数字.

我尝试使用:to_number(fieldname,'999G999G999'),但只有在格​​式与字符串的确切长度匹配时才有效.

有没有办法做到这一点支持从'1'到'10,000,000'?

vol*_*ron 18

select replace(fieldname,',','')::numeric ;
Run Code Online (Sandbox Code Playgroud)

要按照您最初尝试的方式进行,不建议:

select to_number( fieldname,
                  regexp_replace( replace(fieldname,',','G') , '[0-9]' ,'9','g')
                );
Run Code Online (Sandbox Code Playgroud)

内部替换将逗号更改为G.外部替换将数字更改为9.这不是十进制数或负数.