Skip to content

Commit 8cbb324

Browse files
committed
fix view
1 parent fe02f11 commit 8cbb324

File tree

1 file changed

+9
-6
lines changed
  • src/query/sql/src/planner/binder

1 file changed

+9
-6
lines changed

src/query/sql/src/planner/binder/table.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,26 @@ impl<'a> Binder {
150150
let tokens = tokenize_sql(query.as_str())?;
151151
let backtrace = Backtrace::new();
152152
let (stmt, _) = parse_sql(&tokens, Dialect::PostgreSQL, &backtrace)?;
153-
153+
// For view, we need use a new context to bind it.
154+
let new_bind_context =
155+
BindContext::with_parent(Box::new(bind_context.clone()));
154156
if let Statement::Query(query) = &stmt {
155-
let (s_expr, mut bind_context) =
156-
self.bind_query(bind_context, query).await?;
157+
let (s_expr, mut new_bind_context) =
158+
self.bind_query(&new_bind_context, query).await?;
157159
if let Some(alias) = alias {
158160
// view maybe has alias, e.g. select v1.col1 from v as v1;
159-
bind_context.apply_table_alias(alias, &self.name_resolution_ctx)?;
161+
new_bind_context
162+
.apply_table_alias(alias, &self.name_resolution_ctx)?;
160163
} else {
161164
// e.g. select v0.c0 from v0;
162-
for column in bind_context.columns.iter_mut() {
165+
for column in new_bind_context.columns.iter_mut() {
163166
column.database_name = None;
164167
column.table_name = Some(
165168
normalize_identifier(table, &self.name_resolution_ctx).name,
166169
);
167170
}
168171
}
169-
Ok((s_expr, bind_context))
172+
Ok((s_expr, new_bind_context))
170173
} else {
171174
Err(ErrorCode::Internal(format!(
172175
"Invalid VIEW object: {}",

0 commit comments

Comments
 (0)