On my database i keep a numbers in specific notation as varchar values. Is there any way to typecast this values into decimals with selected notation?
What i basically looking here should look like this:
SELECT to_integer_with_notation('d', '20')
int4
---------
13
One more example:
SELECT to_integer_with_notation('d3', '23')
int4
---------
302
Unfortunately, there is no built-in function for that in PostgreSQL, but can be written fairly easy:
Note: I used
numeric
as a return type, asint4
is not enough in many cases (with longer string input).Edit: Here is a sample reverse function, which can convert a
bigint
to its text representation within a custom base:Example usage: