fix: qualify column names in PerfMetric upsert to avoid PG ambiguity#4684
fix: qualify column names in PerfMetric upsert to avoid PG ambiguity#4684SAY-5 wants to merge 1 commit intoQuantumNous:mainfrom
Conversation
PostgreSQL raises 'column reference is ambiguous' (SQLSTATE 42702) on ON CONFLICT DO UPDATE because unqualified column names match both the target row and EXCLUDED. Prefix with the table name so the existing value is referenced unambiguously. Compatible with MySQL and SQLite. Closes QuantumNous#4683 Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe ChangesSQL Column Reference Qualification
Estimated Code Review Effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📝 变更描述 / Description
PostgreSQL 在
ON CONFLICT DO UPDATE SET中将未限定的列名(如generation_ms)视为既可指目标表列,也可指EXCLUDED.generation_ms,触发column reference is ambiguous(SQLSTATE 42702),导致failed to flush perf metric bucket日志刷屏,性能指标无法写入。修复方法:在
UpsertPerfMetric的gorm.Expr累加表达式中显式使用perf_metrics.<col>限定符,明确引用目标表的现有值。MySQL 与 SQLite 同样接受tablename.column形式,无兼容性影响。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
go build ./model/与go vet ./model/通过📸 运行证明 / Proof of Work
生成的 SQL 片段(PG)由
变为
Summary by CodeRabbit