tursodatabase/turso

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

Open

#5 912 ouverte le 12 mars 2026

Voir sur GitHub
 (3 commentaires) (0 réactions) (1 assigné)Rust (1 001 forks)github user discovery
compatibilitygood first issueparser

Métriques du dépôt

Stars
 (19 103 stars)
Métriques de merge PR
 (Métriques PR en attente)

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.

Guide contributeur