documenting alternative syntax that's supported for DATE_ADD, DATE_SUB

this is related to issue https://github.com/ClickHouse/ClickHouse/issues/25815 

i'm adding examples for:
date_add(date, INTERVAL value unit) and date_sub(date, INTERVAL value unit) 

both are covered with a test from e3c09e9703/tests/queries/0_stateless/02160_special_functions.sql (L33) ; i think it's worth documenting them as the syntax is familiar to MySQL users [ https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-add ]
This commit is contained in:
Paweł Kudzia 2024-04-15 08:50:01 +02:00 committed by GitHub
parent e3c09e9703
commit 210efe1621
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1902,6 +1902,12 @@ If the addition results in a value outside the bounds of the data type, the resu
date_add(unit, value, date)
```
Alternative syntax:
``` sql
date_add(date, INTERVAL value unit)
```
Aliases: `dateAdd`, `DATE_ADD`.
**Arguments**
@ -1941,6 +1947,20 @@ Result:
└───────────────────────────────────────────────┘
```
```sql
SELECT date_add(toDate('2018-01-01'), INTERVAL 3 YEAR);
```
Result:
```text
┌─plus(toDate('2018-01-01'), toIntervalYear(3))─┐
│ 2021-01-01 │
└───────────────────────────────────────────────┘
```
**See Also**
- [addDate](#addDate)
@ -1957,6 +1977,13 @@ If the subtraction results in a value outside the bounds of the data type, the r
date_sub(unit, value, date)
```
Alternative syntax:
``` sql
date_sub(date, INTERVAL value unit)
```
Aliases: `dateSub`, `DATE_SUB`.
**Arguments**
@ -1997,6 +2024,19 @@ Result:
└────────────────────────────────────────────────┘
```
``` sql
SELECT date_sub(toDate('2018-01-01'), INTERVAL 3 YEAR);
```
Result:
``` text
┌─minus(toDate('2018-01-01'), toIntervalYear(3))─┐
│ 2015-01-01 │
└────────────────────────────────────────────────┘
```
**See Also**
- [subDate](#subDate)