postgres=# SELECT to_number('00123456789', '00999999999') AS leading_zeroes; leading_zeroes ---------------- 123456789 (1 row) postgres=#