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

fix(binder): bind CTE only when schema_name is empty #3173

Merged
merged 1 commit into from
Jun 13, 2022
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
12 changes: 11 additions & 1 deletion e2e_test/batch/cte.slt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,18 @@ with cte1 as (select v3, v4 from t2), cte2 as (select v3 from cte1) select v3 fr
3
1

query II
with t1 as (values(100, 200)) select * from t1;
----
100 200

query II
with t1 as (values(100, 200)) select * from public.t1;
----
1 2

statement ok
drop table t1;

statement ok
drop table t2;
drop table t2;
5 changes: 4 additions & 1 deletion src/frontend/src/binder/relation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@ impl Binder {
match table_factor {
TableFactor::Table { name, alias, args } => {
if args.is_empty() {
let has_schema_name = name.0.len() > 1;
let (schema_name, table_name) = Self::resolve_table_name(name)?;
if let Some(bound_query) = self.cte_to_relation.get(&table_name) {
if !has_schema_name
&& let Some(bound_query) = self.cte_to_relation.get(&table_name)
{
let (query, alias) = bound_query.clone();
self.bind_context(
query
Expand Down