Skip to content

Commit 465e881

Browse files
committed
Update REPL to support multi-statement queries
1 parent 1397f9b commit 465e881

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

crates/duckdb/examples/repl.rs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -132,28 +132,14 @@ impl SqlRepl {
132132
}
133133

134134
fn execute_sql(&self, sql: &str) -> DuckResult<()> {
135-
// Check if it's a statement that returns results
136-
let sql_upper = sql.trim().to_uppercase();
137-
let is_query = sql_upper.starts_with("SELECT")
138-
|| sql_upper.starts_with("FROM")
139-
|| sql_upper.starts_with("SHOW")
140-
|| sql_upper.starts_with("DESCRIBE")
141-
|| sql_upper.starts_with("EXPLAIN")
142-
|| sql_upper.starts_with("PRAGMA")
143-
|| sql_upper.starts_with("WITH");
144-
145-
if is_query {
146-
let mut stmt = self.conn.prepare(sql)?;
147-
let rbs: Vec<RecordBatch> = stmt.query_arrow([])?.collect();
148-
149-
if rbs.is_empty() || rbs[0].num_rows() == 0 {
150-
println!("No results returned.");
151-
} else {
152-
self.print_records(&rbs);
153-
}
154-
} else {
155-
// Execute non-query statements
156-
self.conn.execute_batch(sql)?;
135+
let mut stmt = self.conn.prepare(sql)?;
136+
let rbs: Vec<RecordBatch> = stmt.query_arrow([])?.collect();
137+
138+
// NOTE: When executing multi-statement queries (e.g., "SELECT 1; SELECT 2;"),
139+
// only the result from the final statement will be displayed. This differs from
140+
// the DuckDB CLI which shows results from all statements.
141+
if !rbs.is_empty() && rbs[0].num_rows() > 0 {
142+
self.print_records(&rbs);
157143
}
158144

159145
Ok(())

0 commit comments

Comments
 (0)