Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support cast function date #12738

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
jetjinser marked this conversation as resolved.
Show resolved Hide resolved

query error unexpected arguments number
select date();
jetjinser marked this conversation as resolved.
Show resolved Hide resolved
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