This is an automated email from the ASF dual-hosted git repository.

yjshen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new 1d49dc9  Add doc for EXTRACT, date_part (#1991)
1d49dc9 is described below

commit 1d49dc9e5ff7b81226cb8f59e89e977ce2af1435
Author: Yang Jiang <[email protected]>
AuthorDate: Wed Mar 16 12:14:16 2022 +0800

    Add doc for EXTRACT, date_part (#1991)
    
    * add doc for EXTRACT, date_part
    
    * add
    
    * prettier
    
    * fix comment
---
 docs/source/user-guide/sql/datafusion-functions.md | 22 ++++++++++++++++++++++
 docs/source/user-guide/sql/sql_status.md           |  1 +
 2 files changed, 23 insertions(+)

diff --git a/docs/source/user-guide/sql/datafusion-functions.md 
b/docs/source/user-guide/sql/datafusion-functions.md
index aa80012..0c50208 100644
--- a/docs/source/user-guide/sql/datafusion-functions.md
+++ b/docs/source/user-guide/sql/datafusion-functions.md
@@ -84,3 +84,25 @@ Note that `CAST(.. AS Timestamp)` converts to Timestamps 
with Nanosecond resolut
 - Other Timestamp() columns or values
 
 Note that `CAST(.. AS Timestamp)` converts to Timestamps with Nanosecond 
resolution; this function is the only way to convert/cast to seconds resolution.
+
+## `EXTRACT, date_part`
+
+`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, Data32, or Data64. 
`field` is an identifier that selects what field to extract from the source 
value.
+  The `extract` function returns values of type u32.
+  - `year` :`EXTRACT(year FROM to_timestamp('2020-09-08T12:00:00+00:00')) -> 
2020`
+  - `month`:`EXTRACT(month FROM to_timestamp('2020-09-08T12:00:00+00:00')) -> 
9`
+  - `week` :`EXTRACT(week FROM to_timestamp('2020-09-08T12:00:00+00:00')) -> 
23`
+  - `day`: `EXTRACT(day FROM to_timestamp('2020-09-08T12:00:00+00:00')) -> 8`
+  - `hour`: `EXTRACT(hour FROM to_timestamp('2020-09-08T12:00:00+00:00')) -> 
12`
+  - `minute`: `EXTRACT(minute FROM to_timestamp('2020-09-08T12:01:00+00:00')) 
-> 1`
+  - `second`: `EXTRACT(second FROM to_timestamp('2020-09-08T12:00:03+00:00')) 
-> 3`
+
+`date_part('field', source)`
+
+- The `date_part` function is modeled on the postgres equivalent to the 
SQL-standard function `extract`.
+  Note that here the field parameter needs to be a string value, not a name.
+  The valid field names for `date_part` are the same as for `extract`.
+  - `date_part('second', to_timestamp('2020-09-08T12:00:12+00:00')) -> 12`
diff --git a/docs/source/user-guide/sql/sql_status.md 
b/docs/source/user-guide/sql/sql_status.md
index 0df14e5..a8ecc5e 100644
--- a/docs/source/user-guide/sql/sql_status.md
+++ b/docs/source/user-guide/sql/sql_status.md
@@ -84,6 +84,7 @@
     - [x] 
[to_timestamp_millis](docs/user-guide/book/sql/datafusion-functions.html#to_timestamp_millis)
     - [x] 
[to_timestamp_micros](docs/user-guide/book/sql/datafusion-functions.html#to_timestamp_micros)
     - [x] 
[to_timestamp_seconds](docs/user-guide/book/sql/datafusion-functions.html#to_timestamp_seconds)
+    - [x] [extract, 
date_part](docs/user-guide/book/sql/datafusion-functions.html#`EXTRACT, 
date_part`)
 - nested functions
   - [x] Array of columns
 - [x] Schema Queries

Reply via email to