0

I have values in my column in postgres and I need help to transform in properly as part of my etl

Sample data

    Amount
$1,000.00
$3.000,00
$200.000,00
$1,234,567.40

as you can see the first and last row are properly formatted. This is what I have done so far

 SELECT
        amount,
        CAST(LEFT(amount, strpos(amount, '.')-1) || ',' || SUBSTRING(amount,(strpos(amount, '.')+1),3) || '.' || SUBSTRING(amount,(strpos(amount, ',')-1),2) AS varchar) AS Formattedstring1
        
    FROM AmountTAable

I am not getting the correct result like

  Amount
$1,000.00
$3,000.00
$200,000.00
$1,234,567.40

Please help with the correct format, thank you

1 Answer 1

1

can you try the following:

select cast(Replace(Replace(Replace(Amount,',',''),'.',''),'$','')::decimal(18,2)/100 as money) as Amount
from t

Example fiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.