Numeric Conversions: PostgreSQL
You can convert between numeric values and their string
representations using the following functions, where
number
can be any numeric type:
TO_CHAR(number
,format
) TO_NUMBER(string
,format
)
PostgreSQL’s number format elements closely follow Oracle’s. They are listed in Table 1-10.
Table 1-10. PostgreSQL’s numeric format elements
Element | Description |
---|---|
| Prefix: dollar sign
( |
| Location of comma.
Consider |
| Location of period.
Consider |
| Significant digit. Leading zeros. |
| Significant digit. Leading blanks. |
| Prefix: returns zero as blanks. |
| Location of ISO currency symbol. |
| Location of decimal point. |
| Suffix: use scientific notation. |
| Prefix: removes leading/trailing blanks. |
| Location of group separator. |
| Location of local currency symbol. |
| Suffix: trailing minus
( |
| Suffix: angle brackets
( |
| Roman numerals, upper- or lowercase. Output-only. |
| Prefix: leading plus
( |
| Prefix: use minimum
number of characters (text-minimum). Output-only. |
| Specifies location of
Euro symbol ( |
| Multiplies the number to
the left of the |
| Use hexadecimal notation.
Output-only. Precede with |
Get SQL Pocket Guide, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.