Different databases implicitly type numeric literals differently,
- MySQL types
- PostgreSQL types
Which one of these is correct?
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.Sign up to join this community
Both are correct and compliant on storage from literals. There are two types of numeric literals in the spec's eyes,
<exact numeric literal>
<approximate numeric literals>floating point, triggered by the use of Scientific Notation (with
For exact numeric literals (ENL),
22) The declared type of an ENL is an implementation-defined exact numeric type whose scale is the number of
<digit>s to the right of the
<period>. There shall be an exact numeric type capable of representing the value of ENL exactly.
For approximate numeric literals (ANL),
23) The declared type of an
<approximate numeric literal>ANL is an implementation-defined approximate numeric type. The value of ANL shall not be greater than the maximum value nor less than the minimum value that can be represented by the approximate numeric types.
Meaning the type merely has to be able to hold the literal, the rest is left to the implementation.
Taken from the SQL 2011n spec