Skip to content

Commit

Permalink
feat: support cast function date (#12738)
Browse files Browse the repository at this point in the history
  • Loading branch information
jetjinser authored Oct 10, 2023
1 parent fb12bba commit 88a8a37
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
40 changes: 40 additions & 0 deletions e2e_test/batch/functions/cast.slt.part
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
statement ok
create table dt (a date, b varchar);

statement ok
insert into dt values (date('2020-01-23'), '1990-12-19');

query TT
select
date(b)
from
dt
except
select
cast(b as date)
from dt
except
select
b::date
from dt;
----

statement ok
drop table dt;

query T
select date('2030-03-30');
----
2030-03-30

query error
select date('2000-13-03');

query error
select date('00-00-33');

query error cannot cast type "integer" to "date" in Explicit context
select date(1);

query error unexpected arguments number
select date();
6 changes: 6 additions & 0 deletions src/frontend/src/binder/expr/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,12 @@ impl Binder {
("pg_sleep_for", raw_call(ExprType::PgSleepFor)),
// TODO: implement pg_sleep_until
// ("pg_sleep_until", raw_call(ExprType::PgSleepUntil)),

// cast functions
// only functions required by the existing PostgreSQL tool are implemented
("date", guard_by_len(1, raw(|_binder, inputs| {
inputs[0].clone().cast_explicit(DataType::Date).map_err(Into::into)
}))),
]
.into_iter()
.collect()
Expand Down

0 comments on commit 88a8a37

Please sign in to comment.