From faa0f1425ac754c8a04b4f62c18dce5f86c55d67 Mon Sep 17 00:00:00 2001 From: SAY-5 Date: Thu, 7 May 2026 05:58:57 -0700 Subject: [PATCH] fix: qualify column names in PerfMetric upsert to avoid ambiguity 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 #4683 Signed-off-by: SAY-5 --- model/perf_metric.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/model/perf_metric.go b/model/perf_metric.go index b4a6a924..dcc4a8bc 100644 --- a/model/perf_metric.go +++ b/model/perf_metric.go @@ -37,13 +37,13 @@ func UpsertPerfMetric(metric *PerfMetric) error { {Name: "bucket_ts"}, }, DoUpdates: clause.Assignments(map[string]interface{}{ - "request_count": gorm.Expr("request_count + ?", metric.RequestCount), - "success_count": gorm.Expr("success_count + ?", metric.SuccessCount), - "total_latency_ms": gorm.Expr("total_latency_ms + ?", metric.TotalLatencyMs), - "ttft_sum_ms": gorm.Expr("ttft_sum_ms + ?", metric.TtftSumMs), - "ttft_count": gorm.Expr("ttft_count + ?", metric.TtftCount), - "output_tokens": gorm.Expr("output_tokens + ?", metric.OutputTokens), - "generation_ms": gorm.Expr("generation_ms + ?", metric.GenerationMs), + "request_count": gorm.Expr("perf_metrics.request_count + ?", metric.RequestCount), + "success_count": gorm.Expr("perf_metrics.success_count + ?", metric.SuccessCount), + "total_latency_ms": gorm.Expr("perf_metrics.total_latency_ms + ?", metric.TotalLatencyMs), + "ttft_sum_ms": gorm.Expr("perf_metrics.ttft_sum_ms + ?", metric.TtftSumMs), + "ttft_count": gorm.Expr("perf_metrics.ttft_count + ?", metric.TtftCount), + "output_tokens": gorm.Expr("perf_metrics.output_tokens + ?", metric.OutputTokens), + "generation_ms": gorm.Expr("perf_metrics.generation_ms + ?", metric.GenerationMs), }), }).Create(metric).Error }