diff --git a/backend/executor.go b/backend/executor.go index dd578f3..6f7ec30 100644 --- a/backend/executor.go +++ b/backend/executor.go @@ -170,9 +170,12 @@ func (b *DuckBuilder) executeQuery(ctx *sql.Context, n sql.Node, conn *stdsql.Co ) // Translate the MySQL query to a DuckDB query - switch n.(type) { + switch n := n.(type) { case *plan.ShowTables: duckSQL = ctx.Query() + case *plan.ResolvedTable: + // SQLGlot cannot translate MySQL's `TABLE t` into DuckDB's `FROM t` - it produces `"table" AS t` instead. + duckSQL = `FROM ` + catalog.ConnectIdentifiersANSI(n.Database().Name(), n.Name()) default: duckSQL, err = transpiler.TranslateWithSQLGlot(ctx.Query()) } diff --git a/test/bats/mysql/table_statement.bats b/test/bats/mysql/table_statement.bats new file mode 100644 index 0000000..cf224b7 --- /dev/null +++ b/test/bats/mysql/table_statement.bats @@ -0,0 +1,28 @@ +#!/usr/bin/env bats +bats_require_minimum_version 1.5.0 + +load helper + +setup_file() { + mysql_exec_stdin <<-'EOF' + CREATE DATABASE table_statement_test; + USE table_statement_test; + CREATE TABLE t (id INT, name VARCHAR(255)); + INSERT INTO t VALUES (1, 'test1'), (2, 'test2'); +EOF +} + +teardown_file() { + mysql_exec_stdin <<-'EOF' + DROP DATABASE IF EXISTS table_statement_test; +EOF +} + +@test "TABLE statement should return all rows from the table" { + run -0 mysql_exec_stdin <<-'EOF' + USE table_statement_test; + TABLE t; +EOF + [ "${lines[0]}" = "1 test1" ] + [ "${lines[1]}" = "2 test2" ] +}