From 33ad309eeb5b1f5a443c48c30c64d3e2b3576f68 Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Sun, 19 Oct 2025 20:51:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/infra/database/postgres.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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)