diff --git a/e2e_test/batch/basic/func.slt.part b/e2e_test/batch/basic/func.slt.part index ebcce5ceb6a4..b5c68f86d623 100644 --- a/e2e_test/batch/basic/func.slt.part +++ b/e2e_test/batch/basic/func.slt.part @@ -317,6 +317,11 @@ select count(current_database()); ---- 1 +query I +select count(current_catalog); +---- +1 + query T select regexp_match('abc', 'bc'); ---- diff --git a/src/frontend/src/binder/expr/function/builtin_scalar.rs b/src/frontend/src/binder/expr/function/builtin_scalar.rs index ed10b808b8bd..824f08cf36b7 100644 --- a/src/frontend/src/binder/expr/function/builtin_scalar.rs +++ b/src/frontend/src/binder/expr/function/builtin_scalar.rs @@ -129,6 +129,15 @@ impl Binder { ) } + // `CURRENT_DATABASE` is the name of the database you are currently connected to. + // `CURRENT_CATALOG` is a synonym for `CURRENT_DATABASE`. + fn current_database() -> Handle { + guard_by_len( + 0, + raw(|binder, _inputs| Ok(ExprImpl::literal_varchar(binder.db_name.clone()))), + ) + } + // XXX: can we unify this with FUNC_SIG_MAP? // For raw_call here, it seems unnecessary to declare it again here. // For some functions, we have validation logic here. Is it still useful now? @@ -410,9 +419,8 @@ impl Binder { Ok(ExprImpl::literal_varchar(v)) })), ), - ("current_database", guard_by_len(0, raw(|binder, _inputs| { - Ok(ExprImpl::literal_varchar(binder.db_name.clone())) - }))), + ("current_catalog", current_database()), + ("current_database", current_database()), ("current_schema", guard_by_len(0, raw(|binder, _inputs| { return Ok(binder .first_valid_schema() diff --git a/src/frontend/src/binder/expr/function/mod.rs b/src/frontend/src/binder/expr/function/mod.rs index a8cabf9bcc68..17738f4dbd5b 100644 --- a/src/frontend/src/binder/expr/function/mod.rs +++ b/src/frontend/src/binder/expr/function/mod.rs @@ -43,6 +43,7 @@ const SYS_FUNCTION_WITHOUT_ARGS: &[&str] = &[ "user", "current_user", "current_role", + "current_catalog", "current_schema", "current_timestamp", ];