tursodatabase/turso

CTE with same name as table rejects schema-qualified reference as circular

Open

#5912 aperta il 12 mar 2026

Vedi su GitHub
 (3 commenti) (0 reazioni) (1 assegnatario)Rust (1001 fork)github user discovery
compatibilitygood first issueparser

Metriche repository

Star
 (19.103 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

Description

When a CTE has the same name as an existing table, the CTE body should be able to reference the original table using a schema-qualified name (main.t1). Turso incorrectly reports a circular reference.

Reproducer

CREATE TABLE t1(a INTEGER);
INSERT INTO t1 VALUES(1),(2),(3);

WITH t1 AS (SELECT a * 10 AS a FROM main.t1)
SELECT * FROM t1 ORDER BY a;
-- Turso: "circular reference: t1"
-- SQLite: 10, 20, 30

-- Works: CTE with different name
WITH cte AS (SELECT a * 10 AS a FROM main.t1)
SELECT * FROM cte ORDER BY a;
-- Both: 10, 20, 30

Per SQLite documentation: Schema-qualified table references should bypass CTE name resolution.


This issue brought to you by Mikaël and Claude Code.

Guida contributor