TO_CHAR

Syntax

TO_CHAR
(
  value IN { smallint | int | bigint | real | double precision | numeric | text | timestamp | timestamptz }
  [, fmt IN text]
)
RETURNS text

Overview

The TO_CHAR function converts a number, date, timestamp, or string value to a string according to the format model (fmt) specified.

If no format model is provided, each data type is converted to a string according to its default output format.

For numeric types, integers, floating point numbers, and numeric values are converted according to the format.

Dates and timestamps are converted to the specified format (e.g., 'YYYY-MM-DD', 'HH24:MI:SS').

Parameter

Parameter
Description

value

smallint | int | bigint | real | double precision | numeric | text | timestamp | timestamptz The target value to convert. This can be numbers, dates, timestamps, or string values. For text type, the fmt argument is not available, and you must use the mouth Returns the received string as is.

fmt

text type; It is a format model that specifies the output format. For example, numbers can be specified as ‘FM9999’, and dates/times can be specified as ‘YYYY-MM-DD HH24:MI:SS’.

For supported format models, refer to the PG official documentationarrow-up-right.

Example

Last updated