Unqualified table names fail to resolve against attached databases
Author: Golliath82prCreated Apr 7, 2026Updated Sep 29, 2026
LabelsATTACH
Summary
When a table exists only in an attached database, unqualified references fail with "no such table" in all operations. SQLite resolves unqualified table names by searching: temp → main → attached databases. Turso only searches main.
Reproduction
ATTACH '' AS aux;
CREATE TABLE aux.users(id INTEGER PRIMARY KEY, name TEXT);
INSERT INTO aux.users VALUES(1, 'Alice');
INSERT INTO aux.users VALUES(2, 'Bob');
-- All fail in Turso with "no such table: users", all succeed in SQLite:
SELECT * FROM users ORDER BY id;
INSERT INTO users VALUES(3, 'Carol');
UPDATE users SET name = 'ALICE' WHERE id = 1;
DELETE FROM users WHERE id = 2;
SELECT (SELECT COUNT(*) FROM users);CREATE VIEW on attached DB can't reference own tables unqualified
ATTACH '' AS aux;
CREATE TABLE aux.products(id INTEGER PRIMARY KEY, name TEXT, price REAL);
INSERT INTO aux.products VALUES(1, 'Widget', 10.0);
-- Qualified works:
CREATE VIEW aux.v1 AS SELECT * FROM aux.products WHERE price > 12; -- OK
-- Unqualified fails:
CREATE VIEW aux.v2 AS SELECT * FROM products WHERE price <= 12;
-- Turso: Parse error: no such table: products
-- SQLite: succeedsControls (working correctly)
SELECT * FROM aux.users(qualified) → works in bothSELECT * FROM main_table(table in main) → works in both- Table exists in both main and aux → main wins in both (correct)
Root Cause
core/translate/emitter/mod.rs:222-224 — resolve_database_id():
} else {
// Unqualified table name - use main database
Ok(0) // ← Always returns main, never searches attached databases
}Fix: When db_name is None, check main first, then iterate attached databases to find the table:
} else {
let table_name = normalize_ident(qualified_name.name.as_str());
if self.with_schema(MAIN_DB_ID, |s| s.get_table(&table_name).is_some() || s.get_view(&table_name).is_some()) {
return Ok(MAIN_DB_ID);
}
for (db_id, _db) in self.attached_databases.read().iter() {
if self.with_schema(db_id, |s| s.get_table(&table_name).is_some() || s.get_view(&table_name).is_some()) {
return Ok(db_id);
}
}
Ok(0) // default to main for downstream error
}Version: v0.5.3, commit 09c149a
Source: tursodatabase/turso