Repository: dbeaver/dbeaver
Issue: Probable regression, Postgresql sequence DDL uses Cache 0 and this is not a valid value

#### System information: 
- Ubuntu 18.04
- DBeaver CE 21.0.5
- Additional extensions: Non AFAIK

#### Connection specification:
- Database name and version: PostgreSQL 9.6
- Driver name: PostgreSQL JDBC Driver
- Do you use tunnels or proxies (SSH, SOCKS, etc)? No

#### Describe the problem you're observing:
The DDL suggested for a sequence sets optional attribute CACHE to 0 which is not valid in PostgreSQL.
This was reported and supposedly fixed a couple of years ago in #5156 .

#### Steps to reproduce, if exist:
Create a sequence in a PostgreSQL DB and check the DDL that DBeaver shows.

#### Include any warning/errors/backtraces from the logs
<!-- Please, find the short guide how to find logs here: https://github.com/dbeaver/dbeaver/wiki/Log-files -->


Changed files:
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreSequence.java

diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreSequence.java b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreSequence.java
index dd58352562..57c44bda18 100644
--- a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreSequence.java
+++ b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreSequence.java
@@ -253,13 +253,29 @@ public class PostgreSequence extends PostgreTableBase implements DBSSequence, DB
         AdditionalInfo info = getAdditionalInfo(monitor);
         StringBuilder sql = new StringBuilder()
             .append("-- DROP SEQUENCE ").append(getFullyQualifiedName(DBPEvaluationContext.DDL)).append(";\\n\\n")
-            .append("CREATE SEQUENCE ").append(getFullyQualifiedName(DBPEvaluationContext.DDL))
-            .append("\\n\\tINCREMENT BY ").append(info.getIncrementBy())
-            .append("\\n\\tMINVALUE ").append(info.getMinValue())
-            .append("\\n\\tMAXVALUE ").append(info.getMaxValue())
-            .append("\\n\\tSTART ").append(info.getStartValue())
-            .append("\\n\\tCACHE ").append(info.getCacheValue())
-            .append("\\n\\t").append(info.isCycled ? "" : "NO ").append("CYCLE;");
+            .append("CREATE SEQUENCE ").append(getFullyQualifiedName(DBPEvaluationContext.DDL));
+
+        if (info.getIncrementBy() > 0) {
+            sql.append("\\n\\tINCREMENT BY ").append(info.getIncrementBy());
+        }
+        if (info.getMinValue() > 0) {
+            sql.append("\\n\\tMINVALUE ").append(info.getMinValue());
+        } else {
+            sql.append("\\n\\tNO MINVALUE");
+        }
+        if (info.getMaxValue() > 0) {
+            sql.append("\\n\\tMAXVALUE ").append(info.getMaxValue());
+        } else {
+            sql.append("\\n\\tNO MAXVALUE");
+        }
+        if (info.getStartValue() > 0) {
+            sql.append("\\n\\tSTART ").append(info.getStartValue());
+        }
+        if (info.getCacheValue() > 0) {
+            sql.append("\\n\\tCACHE ").append(info.getCacheValue());
+            sql.append("\\n\\t").append(info.isCycled ? "" : "NO ").append("CYCLE");
+        }
+        sql.append(';');
 
 		if (!CommonUtils.isEmpty(getDescription())) {
 			sql.append("\\nCOMMENT ON SEQUENCE ").append(DBUtils.getQuotedIdentifier(this)).append(" IS ")