This post is a part of the project #100PostgreSQLFunctions, which aims to explain the meaning of 100 PostgreSQL functions and how to use them. For the full list of functions click here.
EXTRACT is a function to retrieve subfields of a value, which has to be one of the following datatypes: date, timestamp or interval. By parenthesis, we need to specify the subfield to extract, and from which value we want to get it.
Examples:
SELECT
EXTRACT(month from '2/20/2019'::date);
date_part
-----------
2
(1 row)
SELECT
EXTRACT(second from '2/20/2019 12:5:34'::timestamp);
date_part
-----------
34
(1 row)
SELECT
EXTRACT(day from '6 years 5 months 4 days'::interval);
date_part
-----------
4
(1 row)
No comments:
Post a Comment