Esta página ainda não está disponível no idioma selecionado. Estamos trabalhando para adicionar mais opções de idiomas. Agradecemos sua compreensão.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

EXTRACT

Updated on 2024-09-03 GMT+08:00

EXTRACT(field FROM source)

The extract function retrieves subcolumns such as year or hour from date/time values. source must be a value expression of type timestamp, time, or interval. (Expressions of type date are cast to timestamp and can therefore be used as well.) field is an identifier or string that selects what column to extract from the source value. The extract function returns values of type double precision. The following are valid field names:

century

Century

The first century starts at 0001-01-01 00:00:00 AD. This definition applies to all Gregorian calendar countries. There is no century number 0. You go from -1 century to 1 century.

Example:

1
2
3
4
5
SELECT EXTRACT(century FROM TIMESTAMP '2000-12-16 12:21:13');
 date_part 
-----------
        20
(1 row)

day

  • For timestamp values, the day (of the month) column (1–31)
    1
    2
    3
    4
    5
    SELECT EXTRACT(day FROM TIMESTAMP '2001-02-16 20:38:40');
     date_part 
    -----------
            16
    (1 row)
    
  • For interval values, the number of days
    1
    2
    3
    4
    5
    SELECT EXTRACT(day FROM INTERVAL '40 days 1 minute');
     date_part 
    -----------
            40
    (1 row)
    

decade

Year column divided by 10

1
2
3
4
5
SELECT EXTRACT(decade FROM TIMESTAMP '2001-02-16 20:38:40');
 date_part 
-----------
       200
(1 row)

dow

Day of the week as Sunday(0) to Saturday (6)

1
2
3
4
5
SELECT EXTRACT(dow FROM TIMESTAMP '2001-02-16 20:38:40');
 date_part 
-----------
         5
(1 row)

doy

Day of the year (1–365 or 366)

1
2
3
4
5
SELECT EXTRACT(doy FROM TIMESTAMP '2001-02-16 20:38:40');
 date_part 
-----------
        47
(1 row)

epoch

  • For timestamp with time zone values, the number of seconds since 1970-01-01 00:00:00 UTC (can be negative);

    for date and timestamp values, the number of seconds since 1970-01-01 00:00:00 local time;

    for interval values, the total number of seconds in the interval.

    1
    2
    3
    4
    5
    SELECT EXTRACT(epoch FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40.12-08');
      date_part   
    --------------
     982384720.12
    (1 row)
    
    1
    2
    3
    4
    5
    SELECT EXTRACT(epoch FROM interval '5 days 3 hours');
     date_part 
    -----------
        442800
    (1 row)
    
  • Way to convert an epoch value back to a timestamp
    1
    2
    3
    4
    5
    SELECT TIMESTAMP WITH TIME ZONE 'epoch' + 982384720.12 * interval '1 second' AS RESULT;
              result          
    ---------------------------
     2001-02-17 12:38:40.12+08
    (1 row)
    

hour

Hour column (0–23)

1
2
3
4
5
SELECT EXTRACT(hour FROM TIMESTAMP '2001-02-16 20:38:40');
 date_part 
-----------
        20
(1 row)

isodow

Day of the week (1–7)

Monday is 1 and Sunday is 7.

NOTE:

This is identical to dow except for Sunday.

1
2
3
4
5
SELECT EXTRACT(isodow FROM TIMESTAMP '2001-02-18 20:38:40');
 date_part 
-----------
         7
(1 row)

isoyear

The ISO 8601 year that the date falls in (not applicable to intervals).

Each ISO year begins with the Monday of the week containing the 4th of January, so in early January or late December the ISO year may be different from the Gregorian year. See the week column for more information.

1
2
3
4
5
SELECT EXTRACT(isoyear FROM DATE '2006-01-01');
 date_part 
-----------
      2005
(1 row)
1
2
3
4
5
SELECT EXTRACT(isoyear FROM DATE '2006-01-02');
 date_part 
-----------
      2006
(1 row)

microseconds

The seconds column, including fractional parts, multiplied by 1,000,000

1
2
3
4
5
SELECT EXTRACT(microseconds FROM TIME '17:12:28.5');
 date_part 
-----------
  28500000
(1 row)

millennium

Millennium

Years in the 1900s are in the second millennium. The third millennium started from January 1, 2001.

1
2
3
4
5
SELECT EXTRACT(millennium FROM TIMESTAMP '2001-02-16 20:38:40');
 date_part 
-----------
         3
(1 row)

milliseconds

The seconds column, including fractional parts, multiplied by 1000. Note that this includes full seconds.

1
2
3
4
5
SELECT EXTRACT(milliseconds FROM TIME '17:12:28.5');
 date_part 
-----------
     28500
(1 row)

minute

Minutes column (0–59)

1
2
3
4
5
SELECT EXTRACT(minute FROM TIMESTAMP '2001-02-16 20:38:40');
 date_part 
-----------
        38
(1 row)

month

For timestamp values, the number of the month within the year (1–12);

1
2
3
4
5
SELECT EXTRACT(month FROM TIMESTAMP '2001-02-16 20:38:40');
 date_part 
-----------
         2
(1 row)

For interval values, the number of months, modulo 12 (0–11)

1
2
3
4
5
SELECT EXTRACT(month FROM interval '2 years 13 months');
 date_part 
-----------
         1
(1 row)

quarter

Quarter of the year (1–4) that the date is in

1
2
3
4
5
SELECT EXTRACT(quarter FROM TIMESTAMP '2001-02-16 20:38:40');
 date_part 
-----------
         1
(1 row)

second

Seconds column, including fractional parts (0–59)

1
2
3
4
5
SELECT EXTRACT(second FROM TIME '17:12:28.5');
 date_part 
-----------
      28.5
(1 row)

timezone

The time zone offset from UTC, measured in seconds. Positive values correspond to time zones east of UTC, negative values to zones west of UTC.

1
2
3
4
5
SELECT EXTRACT(timezone FROM TIMETZ '17:12:28');
 date_part
-----------
    0
(1 row)

timezone_hour

The hour component of the time zone offset

1
2
3
4
5
SELECT EXTRACT(timezone_hour FROM TIMETZ '17:12:28');
 date_part
-----------
       0
(1 row)

timezone_minute

The minute component of the time zone offset

1
2
3
4
5
SELECT EXTRACT(timezone_minute FROM TIMETZ '17:12:28');
 date_part
-----------
         0
(1 row)

week

The number of the week of the year that the day is in. By definition (ISO 8601), the first week of a year contains January 4 of that year. (The ISO-8601 week starts on Monday.) In other words, the first Thursday of a year is in week 1 of that year.

Because of this, it is possible for early January dates to be part of the 52nd or 53rd week of the previous year, and late December dates to be part of the 1st week of the next year. For example, 2005-01-01 is part of the 53rd week of year 2004, 2006-01-01 is part of the 52nd week of year 2005, and 2012-12-31 is part of the 1st week of year 2013. You are advised to use the columns isoyear and week together to ensure consistency.

1
2
3
4
5
SELECT EXTRACT(week FROM TIMESTAMP '2001-02-16 20:38:40');
 date_part 
-----------
         7
(1 row)

year

Year column

1
2
3
4
5
SELECT EXTRACT(year FROM TIMESTAMP '2001-02-16 20:38:40');
 date_part 
-----------
      2001
(1 row)

Usamos cookies para aprimorar nosso site e sua experiência. Ao continuar a navegar em nosso site, você aceita nossa política de cookies. Saiba mais

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback