postgres=# SELECT to_number('123456789', '999999999') AS just_digits; just_digits ------------- 123456789 (1 row) postgres=#