select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

FUNCTIONS / DATE/TIME FUNCTIONS AND OPERATORS

Get timestamp subfield; see Section 9.9.1

Signatures & examples

extract ( field from timestamp ) → numeric
Get timestamp subfield; see Section 9.9.1
extract(hour from timestamp '2001-02-16 20:38:40') → 20
extract ( field from interval ) → numeric
Get interval subfield; see Section 9.9.1
extract(month from interval '2 years 3 months') → 3
EXTRACT(field FROM source)
The extract function retrieves subfields such as year or hour from date/time values. source must be a value expression of type timestamp, date, time, or interval. (Timestamps and times can be with or without time zone.) field is an identifier or string that selects what field to extract from the source value. Not all fields are valid for every input data type; for example, fields smaller than a day cannot be extracted from a date, while fields of a day or more cannot be extracted from a time. The extract function returns values of type numeric.
Version history 3
  1. PG 18 → 19changed
  2. PG 13 → 14changed
  3. PG 12 → 13changed

Definition snapshot: 2026-09-14T13:14:25.684213+00:00@99e6866c · English manual source