Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between decimal and numeric data type in postgresql

what is the difference between decimal data type and numeric datatype in postgresql ? I do not find any difference in manual.

like image 946
App Work Avatar asked Nov 04 '22 04:11

App Work


2 Answers

There is no difference in PostgreSQL. Per documentation:

The types decimal and numeric are equivalent. Both types are part of the SQL standard.

like image 78
Erwin Brandstetter Avatar answered Dec 14 '22 17:12

Erwin Brandstetter


Quoted from: https://www.postgresql.org/message-id/[email protected]

There isn't any difference, in Postgres. There are two type names because the SQL standard requires us to accept both names. In a quick look in the standard it appears that the only difference is this:

     17)NUMERIC specifies the data type exact numeric, with the decimal
        precision and scale specified by the <precision> and <scale>.

     18)DECIMAL specifies the data type exact numeric, with the decimal
        scale specified by the <scale> and the implementation-defined
        decimal precision equal to or greater than the value of the
        specified <precision>.

ie, for DECIMAL the implementation is allowed to allow more digits than requested to the left of the decimal point. Postgres doesn't exercise that freedom so there's no difference between these types for us.

      regards, tom lane
like image 33
geoyws Avatar answered Dec 14 '22 15:12

geoyws