I'm looking for "interpreting string as decimal" function in PostgreSQL without inserting the decimal manually. The result should be the same as below but without string manipulation:
SELECT COALESCE(NULLIF(left('123456789', -3), ''), '0') || '.' || right('123456789', 3);
-- Should be 123456.789
SELECT COALESCE(NULLIF(left('123', -3), ''), '0') || '.' || right('123', 3);
-- Should be 0.123
I'm also accepting simpler / faster solutions if there is no built-in way in PostgreSQL.
I skipped the cast to decimal
in the example.