Skip to content

Commit

Permalink
Add today alias for current_date (#8423)
Browse files Browse the repository at this point in the history
* fix conflict

* add md

* add test

* add test

* addr comments

* Update datafusion/sqllogictest/test_files/timestamps.slt

Co-authored-by: Alex Huang <[email protected]>

---------

Co-authored-by: zhongjingxiong <[email protected]>
Co-authored-by: Alex Huang <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2023
1 parent 95ba48b commit 1154274
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion datafusion/expr/src/built_in_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ impl BuiltinScalarFunction {

// time/date functions
BuiltinScalarFunction::Now => &["now"],
BuiltinScalarFunction::CurrentDate => &["current_date"],
BuiltinScalarFunction::CurrentDate => &["current_date", "today"],
BuiltinScalarFunction::CurrentTime => &["current_time"],
BuiltinScalarFunction::DateBin => &["date_bin"],
BuiltinScalarFunction::DateTrunc => &["date_trunc", "datetrunc"],
Expand Down
24 changes: 24 additions & 0 deletions datafusion/sqllogictest/test_files/timestamps.slt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ statement ok
create table ts_data_secs as select arrow_cast(ts / 1000000000, 'Timestamp(Second, None)') as ts, value from ts_data;


##########
## Current date Tests
##########

query B
select cast(now() as date) = current_date();
----
true

query B
select now() = current_date();
----
false

query B
select current_date() = today();
----
true

query B
select cast(now() as date) = today();
----
true


##########
## Timestamp Handling Tests
Expand Down
9 changes: 9 additions & 0 deletions docs/source/user-guide/sql/scalar_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,7 @@ regexp_replace(str, regexp, replacement, flags)
- [datepart](#datepart)
- [extract](#extract)
- [to_timestamp](#to_timestamp)
- [today](#today)
- [to_timestamp_millis](#to_timestamp_millis)
- [to_timestamp_micros](#to_timestamp_micros)
- [to_timestamp_seconds](#to_timestamp_seconds)
Expand Down Expand Up @@ -1308,6 +1309,14 @@ no matter when in the query plan the function executes.
current_date()
```

#### Aliases

- today

### `today`

_Alias of [current_date](#current_date)._

### `current_time`

Returns the current UTC time.
Expand Down

0 comments on commit 1154274

Please sign in to comment.