Copilot commented on code in PR #2804: URL: https://github.com/apache/doris-website/pull/2804#discussion_r2308952299
########## versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md: ########## @@ -7,39 +7,100 @@ ## Description -The `extract` function is used to extract a specified part of a date or time value, such as the year, month, day, hour, minute, second, etc. This function is commonly used to extract specific time components from a datetime field for calculation, comparison, or display. +The `EXTRACT` function is used to extract specific time components from date or time values, such as year, month, week, day, hour, minute, second, etc. This function can precisely obtain specific parts of a datetime. + +This function behaves mostly consistently with the [extract function](https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_extract) in MySQL. The difference is that Doris currently does not support combined unit inputs, such as: + +```sql +mysql> SELECT EXTRACT(YEAR_MONTH FROM '2019-07-02 01:02:03'); + -> 201907 +``` ## Syntax -`EXTRACT(<unit> FROM <datetime>)` +`EXTRACT(<unit> FROM <date_or_time_expr>)` ## Parameters | Parameter | Description | | -- | -- | -| `unit` | The unit to extract from the DATETIME. Possible values are year, month, day, hour, minute, second, or microsecond | -| `datetime` | The argument is a valid date expression | +| `unit` | Extract the value of a specified unit from DATETIME. The unit can be year, month, week, day, hour, minute, second, or microsecond | +| `datetime_or_time_expr` | A valid date expression that supports date/datetime types and strings in date-time format. For specific datetime and date formats, please refer to [cast to datetime](../../../../../../docs/sql-manual/basic-element/sql-data-types/conversion/datetime-conversion) and [cast to date](../../../../../../docs/sql-manual/basic-element/sql-data-types/conversion/datetime-conversion)) | ## Return Value -The return value is the extracted part of the date or time (such as an integer), depending on the unit being extracted. +Returns the extracted part of the date or time, of type INT, depending on the extracted unit. + +The value range for the week unit is 0-53, calculated as follows: + +- Sunday is the first day of the week. +- The week containing the first Sunday of the year is week 1. +- Dates before the first Sunday belong to week 0. + +When the unit is year, month, day, hour, minute, second, microsecond, it returns the corresponding unit value in the datetime. + +When the unit is quarter, January-March returns 1, April-June returns 2, July-September returns 3, October-December returns 4. + +Special cases: + +If <date_or_time_expr> is NULL, returns NULL. +If <unit> is an unsupported unit, an error is reported. ## Examples ```sql + +---Extract year, month, day, hour, minute, second, microsecond time components from datetime select extract(year from '2022-09-22 17:01:30') as year, extract(month from '2022-09-22 17:01:30') as month, extract(day from '2022-09-22 17:01:30') as day, extract(hour from '2022-09-22 17:01:30') as hour, extract(minute from '2022-09-22 17:01:30') as minute, extract(second from '2022-09-22 17:01:30') as second, -extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; -``` +extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetime(6))) as microsecond; Review Comment: The cast function uses 'datetime(6)' but should use 'datetimev2(6)' to be consistent with Doris syntax for datetime with microsecond precision. ```suggestion extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
