Skip to content

Commit d8207aa

Browse files
fix: FromItem alias must not shade an actual table (found before)
- fixes #2035 Signed-off-by: Andreas Reichel <andreas@manticore-projects.com>
1 parent e8bc446 commit d8207aa

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,9 +1330,6 @@ public void visit(UseStatement use) {
13301330

13311331
@Override
13321332
public <S> Void visit(ParenthesedFromItem parenthesis, S context) {
1333-
if (parenthesis.getAlias() != null) {
1334-
otherItemNames.add(parenthesis.getAlias().getName());
1335-
}
13361333
parenthesis.getFromItem().accept(this, context);
13371334
// support join keyword in fromItem
13381335
visitJoins(parenthesis.getJoins(), context);

src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,5 +497,17 @@ void testSubqueryAliasesIssue1987() throws JSQLParserException {
497497
assertThat(tables).containsExactlyInAnyOrder("a", "b");
498498
assertThat(tables).doesNotContain("a1");
499499
}
500+
501+
@Test
502+
void testSubqueryAliasesIssue2035() throws JSQLParserException {
503+
String sqlStr = "SELECT * FROM (SELECT * FROM A) AS A \n" +
504+
"JOIN B ON A.a = B.a \n" +
505+
"JOIN C ON A.a = C.a;";
506+
Set<String> tables = TablesNamesFinder.findTablesOrOtherSources(sqlStr);
507+
assertThat(tables).containsExactlyInAnyOrder("A", "B", "C");
508+
509+
tables = TablesNamesFinder.findTables(sqlStr);
510+
assertThat(tables).containsExactlyInAnyOrder("B", "C");
511+
}
500512
}
501513

0 commit comments

Comments
 (0)