Hi community,
the test follows
@Test void testWithUnion2() {
// Per the standard WITH ... SELECT ... UNION is valid even without
parens.
final String sql = "with emp2 as (select * from emp union all select *
from emp)\n"
+ "select * from emp2\n"
+ "union\n"
+ "select * from emp2\n";
final String expected = "WITH `EMP2` AS (SELECT *\n"
+ "FROM `EMP`\n"
+ "UNION ALL\n"
+ "SELECT *\n"
+ "FROM `EMP`) (SELECT *\n"
+ "FROM `EMP2`\n"
+ "UNION\n"
+ "SELECT *\n"
+ "FROM `EMP2`)";
sql(sql).ok(expected);
}
when I change SqlPrettyWriter.config()
.withAlwaysUseParentheses(true)
to
.withAlwaysUseParentheses(false)
the test produces sql
WITH `EMP2` AS SELECT *
FROM `EMP`
UNION ALL
SELECT *
FROM `EMP` (SELECT *
FROM `EMP2`
UNION
SELECT *
FROM `EMP2`)
but the sql can't be parsed by calcite.
I find postgreSQL and BigQuery both need parentheses for the with item
query.
Should we always force the with item query to be wrapped by parentheses?