Skip to content

Conversation

@RS2007
Copy link
Contributor

@RS2007 RS2007 commented Oct 13, 2025

turso>  WITH t AS (SELECT 1), t AS (SELECT 2) SELECT * FROM x;
  × Parse error: duplicate WITH table name: t

@RS2007 RS2007 requested a review from jussisaurio as a code owner October 13, 2025 20:07
@RS2007 RS2007 changed the title Throw an error in case duplicate CTE names Throw an error in case duplicate CTE names are found Oct 16, 2025
}

let mut ctes_as_subqueries = vec![];
let mut ctes_as_subqueries: Vec<JoinedTable> = vec![];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally there would be a test for this in one of the .test suites.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup looks like there is one here: https://chromium.googlesource.com/external/github.com/sqlite/sqlite/%2B/refs/heads/new-dbconfig-options/test/with1.test

do_catchsql_test 3.2 {
CREATE TABLE t2(x INTEGER);
WITH tmp(a) AS (SELECT * FROM t1),
tmp(a) AS (SELECT * FROM t1)
SELECT * FROM tmp;
} {1 {duplicate WITH table name: tmp}}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that's SQLite, I meant, ideally it would be in one of the test suites that Turso runs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, added a test to the select.test file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! The only think I see is that this fix is slightly more permissive than SQLite, because it allows things like this:

with t as (select 1), t as (select 1) select 1;

whereas SQLite does not. Personally I think this is fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PThorpe92 I don't have merge rights, but this PR looks good to me.

Copy link
Collaborator

@PThorpe92 PThorpe92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but as @LeMikaelF mentioned, can you add a regression test for the exact query this fixes? similar to this:

# https://github.com/tursodatabase/turso/issues/3667 regression test

can be in the same file testing/select.test

@RS2007
Copy link
Contributor Author

RS2007 commented Oct 17, 2025

Looks good, but as @LeMikaelF mentioned, can you add a regression test for the exact query this fixes? similar to this:

# https://github.com/tursodatabase/turso/issues/3667 regression test

can be in the same file testing/select.test

Sure, the actual chromium repos seem to have this in a with1.test file, should I keep it that way, or just append it to select.test ?

@RS2007 RS2007 requested a review from penberg as a code owner October 18, 2025 04:39
@RS2007 RS2007 requested a review from LeMikaelF October 18, 2025 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants