Skip to content

Commit 3043efd

Browse files
authored
feat: support current_catalog sys function (#18037)
1 parent bd664bb commit 3043efd

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

e2e_test/batch/basic/func.slt.part

+5
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@ select count(current_database());
317317
----
318318
1
319319

320+
query I
321+
select count(current_catalog);
322+
----
323+
1
324+
320325
query T
321326
select regexp_match('abc', 'bc');
322327
----

src/frontend/src/binder/expr/function/builtin_scalar.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ impl Binder {
129129
)
130130
}
131131

132+
// `CURRENT_DATABASE` is the name of the database you are currently connected to.
133+
// `CURRENT_CATALOG` is a synonym for `CURRENT_DATABASE`.
134+
fn current_database() -> Handle {
135+
guard_by_len(
136+
0,
137+
raw(|binder, _inputs| Ok(ExprImpl::literal_varchar(binder.db_name.clone()))),
138+
)
139+
}
140+
132141
// XXX: can we unify this with FUNC_SIG_MAP?
133142
// For raw_call here, it seems unnecessary to declare it again here.
134143
// For some functions, we have validation logic here. Is it still useful now?
@@ -410,9 +419,8 @@ impl Binder {
410419
Ok(ExprImpl::literal_varchar(v))
411420
})),
412421
),
413-
("current_database", guard_by_len(0, raw(|binder, _inputs| {
414-
Ok(ExprImpl::literal_varchar(binder.db_name.clone()))
415-
}))),
422+
("current_catalog", current_database()),
423+
("current_database", current_database()),
416424
("current_schema", guard_by_len(0, raw(|binder, _inputs| {
417425
return Ok(binder
418426
.first_valid_schema()

src/frontend/src/binder/expr/function/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const SYS_FUNCTION_WITHOUT_ARGS: &[&str] = &[
4343
"user",
4444
"current_user",
4545
"current_role",
46+
"current_catalog",
4647
"current_schema",
4748
"current_timestamp",
4849
];

0 commit comments

Comments
 (0)