Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow duplicate table aliases in the table binder#14035

Merged
Mytherin merged 1 commit intoduckdb:featurefrom
Mytherin:duplicatealias
Sep 19, 2024
Merged

Allow duplicate table aliases in the table binder#14035
Mytherin merged 1 commit intoduckdb:featurefrom
Mytherin:duplicatealias

Conversation

@Mytherin
Copy link
Collaborator

This PR changes the way that we deal with duplicate table aliases in the binder. Previously, we would throw an exception when a duplicate binding was registered - which is the same behavior that Postgres has, i.e.:

select * from (select 42) t, (select 84) t;
-- Binder Error: Duplicate alias "t" in query!

This is not strictly necessary - however. A duplicate alias is only a problem if there is a conflict. For example, the following query has no ambiguity, and hence can be safely executed (and SQLite can execute it):

select count(*) from (select 42) t, (select 84) t;

After this PR - we can execute this query. Instead, an error is thrown when there is ambiguity when binding a column. For example, this throws an error:

select t.x from (select 42 x) t, (select 84 x) t;
-- Binder Error: Ambiguous reference to table "t" (duplicate alias "t", explicitly alias one of the tables using "AS my_alias")

But this now works, since there is no ambiguity:

D select t.x from (select 42 x) t, (select 84 y) t;
┌───────┐
│   x   │
│ int32 │
├───────┤
│    42 │
└───────┘

@Tishj
Copy link
Contributor

Tishj commented Sep 19, 2024

Correct me if I'm wrong, but doesn't this also solve the join behavior issue we have with Spark?
I remember us being more strict about bindings having to be unique and them only throwing when they duplicate bindings are referenced

@Mytherin
Copy link
Collaborator Author

That is certainly possible yeah

@Mytherin Mytherin merged commit 4fca9fd into duckdb:feature Sep 19, 2024
@Mytherin Mytherin deleted the duplicatealias branch December 8, 2024 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants