Skip to content

Commit 55f4a91

Browse files
aeberhartclaude
andcommitted
Analytics on saved queries: valid subquery alias on Oracle and SQL Server
Oracle does not allow AS before a subquery alias, and on SQL Server with a SCHEMA= URL setting the schema prefix ended up on the alias (as dbo."T"). Only real tables get the schema prefix now, and Oracle gets the alias without AS. Refs #539 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 597e530 commit 55f4a91

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎dashjoin-core/src/main/java/org/dashjoin/service/SQLDatabase.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,11 +689,13 @@ else if (likeIsCaseSensitive()) {
689689
}
690690
}
691691

692-
String subselect = info == null ? "" : "(" + info.query + ") as ";
692+
// a subquery alias takes no schema prefix, and Oracle does not allow AS before it
693+
String from = info == null ? schema() + q(s.name)
694+
: "(" + info.query + ")" + (url.startsWith("jdbc:oracle:") ? " " : " as ") + q(s.name);
693695
// SQL Server has no LIMIT, use TOP
694696
boolean top = url.startsWith("jdbc:sqlserver") || url.startsWith("jdbc:jtds:");
695-
String select = "select " + (top ? "top 1000 " : "") + String.join(", ", project) + " from "