tursodatabase/turso

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

Open

#5.912 aberto em 12 de mar. de 2026

Ver no GitHub
 (3 comments) (0 reactions) (1 assignee)Rust (1.001 forks)github user discovery
compatibilitygood first issueparser

Métricas do repositório

Stars
 (19.103 stars)
Métricas de merge de PR
 (Métricas PR pendentes)

Description

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.

Guia do colaborador