feat(PostgreSQL): Get the PostgreSQL sequences

This commit is contained in:
Sylphy
2025-04-11 10:47:04 +08:00
parent d9779a4b2e
commit 557c43fede
12 changed files with 229 additions and 19 deletions

View File

@ -345,7 +345,7 @@ public class PostgreSQLMetaData extends DefaultMetaService implements MetaData {
stringBuilder.append("CREATE SEQUENCE ").append(nspname).append(".").append(relname).append("\n ");
if (databaseProductVersion >= 10.0){
if (databaseProductVersion >= 10.0) {
stringBuilder.append(" AS ").append(typname).append("\n ");
}
@ -379,4 +379,21 @@ public class PostgreSQLMetaData extends DefaultMetaService implements MetaData {
},
sequenceName, schemaName);
}
@Override
public List<SimpleSequence> sequences(Connection connection, String databaseName, String schemaName) {
List<SimpleSequence> simpleSequences = new ArrayList<>();
return SQLExecutor.getInstance().preExecute(connection, EXPORT_SEQUENCES_SQL, resultSet -> {
while (resultSet.next()) {
String relname = resultSet.getString("relname");
String comment = resultSet.getString("comment");
simpleSequences.add(SimpleSequence.builder()
.name(relname)
.comment(comment)
.build());
}
return simpleSequences;
},
schemaName);
}
}

View File

@ -665,4 +665,14 @@ public class SQLConst {
WHERE c.relname = ?
and n.nspname = ?;
""";
public static final String EXPORT_SEQUENCES_SQL = """
SELECT c.relname, obj_description(c.oid, 'pg_class') AS comment
FROM pg_sequence s
JOIN
pg_class c ON c.oid = s.seqrelid
JOIN
pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = ?;
""";
}