diff --git a/jOOQ/src/main/java/org/jooq/conf/Settings.java b/jOOQ/src/main/java/org/jooq/conf/Settings.java index acc923a5de..b15fdead55 100644 --- a/jOOQ/src/main/java/org/jooq/conf/Settings.java +++ b/jOOQ/src/main/java/org/jooq/conf/Settings.java @@ -77,6 +77,8 @@ public class Settings protected Boolean renderOrderByRownumberForEmulatedPagination = true; @XmlElement(defaultValue = "true") protected Boolean renderOutputForSQLServerReturningClause = true; + @XmlElement(defaultValue = "false") + protected Boolean renderParenthesisAroundSetOperationQueries = false; @XmlElement(defaultValue = "true") protected Boolean fetchTriggerValuesAfterSQLServerOutput = true; @XmlElement(defaultValue = "false") @@ -641,6 +643,37 @@ public class Settings this.renderOutputForSQLServerReturningClause = value; } + /** + * Whether queries combined with set operators (e.g. UNION and UNION ALL) should always be surrounded by a parenthesis pair. + *
+ * By default (i.e. when this setting is set to false jOOQ will only render parenthesis pairs around queries combined with set operators when required.
+ * This is for example the case when set operators are nested, when non-associative operators like EXCEPT are used, or when the queries are rendered as derived tables.
+ *
+ * When this setting is set to true the queries combined with set operators will always be surrounded by a parenthesis pair.
+ *
+ * For details, see https://github.com/jOOQ/jOOQ/issues/3676 and https://github.com/jOOQ/jOOQ/issues/9751.
+ *
+ * @return
+ * possible object is
+ * {@link Boolean }
+ *
+ */
+ public Boolean isRenderParenthesisAroundSetOperationQueries() {
+ return renderParenthesisAroundSetOperationQueries;
+ }
+
+ /**
+ * Sets the value of the renderParenthesisAroundSetOperationQueries property.
+ *
+ * @param value
+ * allowed object is
+ * {@link Boolean }
+ *
+ */
+ public void setRenderParenthesisAroundSetOperationQueries(Boolean value) {
+ this.renderParenthesisAroundSetOperationQueries = value;
+ }
+
/**
* Fetch trigger values after SQL Server OUTPUT clause.
*
@@ -2080,6 +2113,11 @@ public class Settings
return this;
}
+ public Settings withRenderParenthesisAroundSetOperationQueries(Boolean value) {
+ setRenderParenthesisAroundSetOperationQueries(value);
+ return this;
+ }
+
public Settings withFetchTriggerValuesAfterSQLServerOutput(Boolean value) {
setFetchTriggerValuesAfterSQLServerOutput(value);
return this;
@@ -2621,6 +2659,7 @@ public class Settings
builder.append("renderScalarSubqueriesForStoredFunctions", renderScalarSubqueriesForStoredFunctions);
builder.append("renderOrderByRownumberForEmulatedPagination", renderOrderByRownumberForEmulatedPagination);
builder.append("renderOutputForSQLServerReturningClause", renderOutputForSQLServerReturningClause);
+ builder.append("renderParenthesisAroundSetOperationQueries", renderParenthesisAroundSetOperationQueries);
builder.append("fetchTriggerValuesAfterSQLServerOutput", fetchTriggerValuesAfterSQLServerOutput);
builder.append("transformTableListsToAnsiJoin", transformTableListsToAnsiJoin);
builder.append("backslashEscaping", backslashEscaping);
@@ -2859,6 +2898,15 @@ public class Settings
return false;
}
}
+ if (renderParenthesisAroundSetOperationQueries == null) {
+ if (other.renderParenthesisAroundSetOperationQueries!= null) {
+ return false;
+ }
+ } else {
+ if (!renderParenthesisAroundSetOperationQueries.equals(other.renderParenthesisAroundSetOperationQueries)) {
+ return false;
+ }
+ }
if (fetchTriggerValuesAfterSQLServerOutput == null) {
if (other.fetchTriggerValuesAfterSQLServerOutput!= null) {
return false;
@@ -3459,6 +3507,7 @@ public class Settings
result = ((prime*result)+((renderScalarSubqueriesForStoredFunctions == null)? 0 :renderScalarSubqueriesForStoredFunctions.hashCode()));
result = ((prime*result)+((renderOrderByRownumberForEmulatedPagination == null)? 0 :renderOrderByRownumberForEmulatedPagination.hashCode()));
result = ((prime*result)+((renderOutputForSQLServerReturningClause == null)? 0 :renderOutputForSQLServerReturningClause.hashCode()));
+ result = ((prime*result)+((renderParenthesisAroundSetOperationQueries == null)? 0 :renderParenthesisAroundSetOperationQueries.hashCode()));
result = ((prime*result)+((fetchTriggerValuesAfterSQLServerOutput == null)? 0 :fetchTriggerValuesAfterSQLServerOutput.hashCode()));
result = ((prime*result)+((transformTableListsToAnsiJoin == null)? 0 :transformTableListsToAnsiJoin.hashCode()));
result = ((prime*result)+((backslashEscaping == null)? 0 :backslashEscaping.hashCode()));
diff --git a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java
index 67013be90c..bc5c137622 100644
--- a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java
+++ b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java
@@ -1140,6 +1140,7 @@ final class SelectQueryImpl