tursodatabase/turso

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

Open

#5,912 opened on 2026年3月12日

GitHub で見る
 (3 comments) (0 reactions) (1 assignee)Rust (1,001 forks)github user discovery
compatibilitygood first issueparser

Repository metrics

Stars
 (19,103 stars)
PR merge metrics
 (PR metrics pending)

説明

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.

コントリビューターガイド