Skip to content

fix(sql): reject duplicate unqualified names in CTAS, CREATE VIEW, and SELECT INTO#22290

Open
kumarUjjawal wants to merge 1 commit into
apache:mainfrom
kumarUjjawal:fix/sql_duplicate_unqualified_table
Open

fix(sql): reject duplicate unqualified names in CTAS, CREATE VIEW, and SELECT INTO#22290
kumarUjjawal wants to merge 1 commit into
apache:mainfrom
kumarUjjawal:fix/sql_duplicate_unqualified_table

Conversation

@kumarUjjawal
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

CREATE TABLE AS, CREATE VIEW, and SELECT INTO can persist only plain
column names.

Before this change, a query like a self join could produce qualified output
columns such as x.column1 and y.column1, which are valid while planning.
But when the table or view was created, those qualifiers were dropped and the
stored schema became column1, column1, ... with duplicates.

That meant the create step succeeded, but the created table or view failed
later when the user tried to read from it. The object existed in the catalog
but was not usable.

This PR fixes that by rejecting these cases during planning, before the table
or view is created.

What changes are included in this PR?

This PR adds a shared SQL planner check that validates the final output schema
has unique unqualified column names.

It applies that check to:

  • CREATE TABLE AS
  • CREATE VIEW
  • SELECT INTO

The check runs after the final projection or aliasing step, so it validates the
actual names that would be stored.

This PR also adds sqllogictest coverage for the duplicate-column self-join case
for all three flows.

Are these changes tested?

Yes

Are there any user-facing changes?

Invalid CREATE TABLE AS, CREATE VIEW, and SELECT INTO statements that
would create an object with duplicate unqualified column names now fail early
during planning with a schema error, instead of succeeding and creating an
unreadable table or view.

No API Changes

@github-actions github-actions Bot added sql SQL Planner sqllogictest SQL Logic Tests (.slt) labels May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CREATE TABLE AS not checking column unicity

1 participant