Data Types
- Boolean Type
-
Boolean
- Numerical Types
-
- Integer
- smallint, int, bigint
- Numeric (aka Decimal)
- numeric(precision, scale) [Always specify precision and scale.]
- Floating Point
- real, double precision
Numeric and Floating Points offers -Infinity, Infinity, NaN
- Textual Types
-
- Character
- char(n)
- Character Varying
- varchar(n), varchar()
- Text
- Temporal Types
-
- Date
- Time Stamp Without Time Zone
- timestamp [Offers -Infinity and Infinity]
- Time Stamp With Time Zone
- timestamptz [Offers -Infinity and Infinity]
- Interval
- JSON Type
-
- JSON
- JSONB
You can use full type name or abbreviated type name. For instance, both character varying(10) and varchar(10) will work.
All data types may be casted to text.
Integers
| smallint | -32768 to +32767 |
| integer | -2147483648 to +2147483647 |
| bigint | -9223372036854775808 to +9223372036854775807 |
| -3 |
-2 |
-1 |
0 |
1 |
2 |
3 |
THOUSANDS |
HUNDREDS |
TENS |
ONES |
TENTH |
HUNDREDTH |
THOUSANDTH |
Rounding
- Locate place to round to. (Target)
- Is the number to the right [5,9]? If so, round up target. Iteratively round.
- Is the number to the right [0,4]? Zero out target.
- Retain zero to target for clarity
- Pad zeros if necessary.
Castability to Numeric (Precision, Scale)
- Round to Scale
- Result must be WITHIN absolute value of 10 (Precision - Scale)
Range of Real and Double Precision
| real | 4 bytes | precision of 6 decimal digits |
| double precision | 8 bytes | precision of 15 decimal digits |
| 2.22222E12 | 2.22222 × 1012 | All digits significant. |
| 2.222222E12 | 2.2222222 × 1012 | One digit dropped. |