Apache DataFusion SQL Query Engine
Add doc for EXTRACT, date_part (#1991)
Yang Jiang1d49dc9e5ff7
diff --git a/docs/source/user-guide/sql/datafusion-functions.md b/docs/source/user-guide/sql/datafusion-functions.mdindex aa8001270e..0c50208fd5 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 valuesNote 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.mdindex 0df14e58a8..a8ecc5e71e 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