0

Is there an equivalent of the DB2 function decimal(numeric expression, precision, scale) in PostgreSQL? Or how would I do this functionality in PostgreSQL?

The DECIMAL function returns a decimal representation of a character-string. The value of this second argument specifies the precision of the result. The scale value specifies the scale of the result (not sure what that means?).

Paul White
95.3k30 gold badges439 silver badges689 bronze badges
asked Sep 4, 2018 at 6:44
0

1 Answer 1

1

Seems like that is a different way of writing a cast:

select cast('3.1415926535897932384626433832795' as decimal(12,4)) as pi

returns:

 pi
--------
 3.1416

And

select cast('3.1415926535897932384626433832795' as decimal(12,6)) as pi

returns:

 pi
----------
 3.141593
answered Sep 4, 2018 at 8:03
1
  • 1
    You can also use the :: casting operator (in my view, that is a bit more readable). Also, just for the completeness, numeric is a synonym for decimal (or the other way around, if you like). Commented Sep 4, 2018 at 8:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.