diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql/OSGI-INF/l10n/bundle.properties b/plugins/org.jkiss.dbeaver.ext.postgresql/OSGI-INF/l10n/bundle.properties index 775abfb4b0f0fda1ed6d803714e5fea3c33391df..a84d984aaa2356f1ec0c2c2324abd51b5adb52a0 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql/OSGI-INF/l10n/bundle.properties +++ b/plugins/org.jkiss.dbeaver.ext.postgresql/OSGI-INF/l10n/bundle.properties @@ -299,13 +299,15 @@ meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema.description.descriptio meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema.owner.name=Owner meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema.owner.description= meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.incrementBy.name=Increment By -meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.incrementBy.description= +meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.incrementBy.description=Increment value of the sequence meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.lastValue.name=Last Value -meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.lastValue.description= +meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.lastValue.description=The last sequence value written to disk.\nIf caching is used, this value can be greater than the last value handed out from the sequence.\nNull if the sequence has not been read from yet.\nAlso, if the current user does not have USAGE or SELECT privilege on the sequence, the value is null. meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.maxValue.name=Max Value -meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.maxValue.description= +meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.maxValue.description=Maximum value of the sequence meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.minValue.name=Min Value -meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.minValue.description= +meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.minValue.description=Minimum value of the sequence +meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.cycled.name=Cycled +meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSequence$AdditionalInfo.cycled.description= Whether the sequence cycles meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTable.hasOids.name=Has Oids meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTable.hasOids.description= meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTable.subTables.name=Sub Tables 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 e10d11916a8ef08fc3784db7b71eca66ad10ec41..0433cddcf4b4916744ab4e07e695ea84984a11d8 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 @@ -52,6 +52,7 @@ public class PostgreSequence extends PostgreTableBase implements DBSSequence, DB private Number minValue; private Number maxValue; private Number incrementBy; + private boolean isCycled; @Property(viewable = true, editable = true, updatable = true, order = 10) public Number getLastValue() { @@ -69,6 +70,10 @@ public class PostgreSequence extends PostgreTableBase implements DBSSequence, DB public Number getIncrementBy() { return incrementBy; } + @Property(viewable = true, editable = true, updatable = true, order = 14) + public boolean isCycled() { + return isCycled; + } } public static class AdditionalInfoValidator implements IPropertyCacheValidator { @Override @@ -102,14 +107,32 @@ public class PostgreSequence extends PostgreTableBase implements DBSSequence, DB private void loadAdditionalInfo(DBRProgressMonitor monitor) { try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Load sequence additional info")) { - try (JDBCPreparedStatement dbSeqStat = session.prepareStatement( - "SELECT last_value,min_value,max_value,increment_by from " + getFullyQualifiedName(DBPEvaluationContext.DML))) { - try (JDBCResultSet seqResults = dbSeqStat.executeQuery()) { - if (seqResults.next()) { - additionalInfo.lastValue = JDBCUtils.safeGetLong(seqResults, 1); - additionalInfo.minValue = JDBCUtils.safeGetLong(seqResults, 2); - additionalInfo.maxValue = JDBCUtils.safeGetLong(seqResults, 3); - additionalInfo.incrementBy = JDBCUtils.safeGetLong(seqResults, 4); + if (getDataSource().isServerVersionAtLeast(10, 0)) { + try (JDBCPreparedStatement dbSeqStat = session.prepareStatement( + "SELECT * from pg_catalog.pg_sequences WHERE schemaname=? AND sequencename=?")) { + dbSeqStat.setString(1, getSchema().getName()); + dbSeqStat.setString(2, getName()); + try (JDBCResultSet seqResults = dbSeqStat.executeQuery()) { + if (seqResults.next()) { + additionalInfo.lastValue = JDBCUtils.safeGetLong(seqResults, "last_value"); + additionalInfo.minValue = JDBCUtils.safeGetLong(seqResults, "min_value"); + additionalInfo.maxValue = JDBCUtils.safeGetLong(seqResults, "max_value"); + additionalInfo.incrementBy = JDBCUtils.safeGetLong(seqResults, "increment_by"); + additionalInfo.isCycled = JDBCUtils.safeGetBoolean(seqResults, "cycle"); + } + } + } + } else { + try (JDBCPreparedStatement dbSeqStat = session.prepareStatement( + "SELECT * from " + getFullyQualifiedName(DBPEvaluationContext.DML))) { + try (JDBCResultSet seqResults = dbSeqStat.executeQuery()) { + if (seqResults.next()) { + additionalInfo.lastValue = JDBCUtils.safeGetLong(seqResults, "last_value"); + additionalInfo.minValue = JDBCUtils.safeGetLong(seqResults, "min_value"); + additionalInfo.maxValue = JDBCUtils.safeGetLong(seqResults, "max_value"); + additionalInfo.incrementBy = JDBCUtils.safeGetLong(seqResults, "increment_by"); + additionalInfo.isCycled = JDBCUtils.safeGetBoolean(seqResults, "is_cycled"); + } } } } diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreTableBase.java b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreTableBase.java index 29e5440f52fac8212842258b875b97698b1882be..0b3fbf5fd56d7fcff8aa2e7ecb091a2fb473afee 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreTableBase.java +++ b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreTableBase.java @@ -96,7 +96,7 @@ public abstract class PostgreTableBase extends JDBCTable