diff --git a/internal/infra/database/postgres.go b/internal/infra/database/postgres.go index 5b868c5..4069a5d 100644 --- a/internal/infra/database/postgres.go +++ b/internal/infra/database/postgres.go @@ -219,7 +219,8 @@ func (ps *PostgresStorage) applyCompressionPolicies() error { // 1. 开启表的压缩设置,并指定分段列 ps.logger.Infow("为表启用压缩设置", "table", tableName, "segment_by", policy.segmentColumn) - alterSQL := fmt.Sprintf("ALTER TABLE %s SET (timescaledb.compress, timescaledb.compress_segmentby = '%s');", tableName, policy.segmentColumn) + // 使用 + 而非Sprintf以规避goland静态检查报错 + alterSQL := "ALTER TABLE" + " " + tableName + " SET (timescaledb.compress, timescaledb.compress_segmentby = '" + policy.segmentColumn + "');" if err := ps.db.Exec(alterSQL).Error; err != nil { // 忽略错误,因为这个设置可能是不可变的,重复执行会报错 ps.logger.Warnw("启用压缩设置时遇到问题 (可能已设置,可忽略)", "table", tableName, "error", err)