Skip to content
This repository was archived by the owner on Mar 30, 2023. It is now read-only.

Commit c9f0750

Browse files
Merge branch 'master' into production [no deploy]
2 parents f0d5a7a + ae3012b commit c9f0750

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

pg_conn.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,15 @@ func WriteTSPoints(ctx *Ctx, con *sql.DB, pts *TSPoints, mergeSeries string, mut
339339
}
340340
namesUA := strings.Join(namesU, ", ")
341341
argsUA := strings.Join(argsU, ", ")
342+
if len(namesU) > 1 {
343+
namesUA = "(" + namesUA + ")"
344+
argsUA = "(" + argsUA + ")"
345+
}
342346
argT := "$" + strconv.Itoa(i)
343347
vals = append(vals, p.t)
344348
q := fmt.Sprintf(
345349
"insert into \"%[1]s\"("+namesIA+") values("+argsIA+") "+
346-
"on conflict(time) do update set ("+namesUA+") = ("+argsUA+") "+
350+
"on conflict(time) do update set "+namesUA+" = "+argsUA+" "+
347351
"where \"%[1]s\".time = "+argT,
348352
name,
349353
)
@@ -374,13 +378,17 @@ func WriteTSPoints(ctx *Ctx, con *sql.DB, pts *TSPoints, mergeSeries string, mut
374378
}
375379
namesUA := strings.Join(namesU, ", ")
376380
argsUA := strings.Join(argsU, ", ")
381+
if len(namesU) > 1 {
382+
namesUA = "(" + namesUA + ")"
383+
argsUA = "(" + argsUA + ")"
384+
}
377385
argT := "$" + strconv.Itoa(i)
378386
argP := "$" + strconv.Itoa(i+1)
379387
vals = append(vals, p.t)
380388
vals = append(vals, p.period)
381389
q := fmt.Sprintf(
382390
"insert into \"%[1]s\"("+namesIA+") values("+argsIA+") "+
383-
"on conflict(time, period) do update set ("+namesUA+") = ("+argsUA+") "+
391+
"on conflict(time, period) do update set "+namesUA+" = "+argsUA+" "+
384392
"where \"%[1]s\".time = "+argT+" and \"%[1]s\".period = "+argP,
385393
name,
386394
)
@@ -410,6 +418,10 @@ func WriteTSPoints(ctx *Ctx, con *sql.DB, pts *TSPoints, mergeSeries string, mut
410418
}
411419
namesUA := strings.Join(namesU, ", ")
412420
argsUA := strings.Join(argsU, ", ")
421+
if len(namesU) > 1 {
422+
namesUA = "(" + namesUA + ")"
423+
argsUA = "(" + argsUA + ")"
424+
}
413425
argT := "$" + strconv.Itoa(i)
414426
argP := "$" + strconv.Itoa(i+1)
415427
argS := "$" + strconv.Itoa(i+2)
@@ -418,7 +430,7 @@ func WriteTSPoints(ctx *Ctx, con *sql.DB, pts *TSPoints, mergeSeries string, mut
418430
vals = append(vals, p.name)
419431
q := fmt.Sprintf(
420432
"insert into \"%[1]s\"("+namesIA+") values("+argsIA+") "+
421-
"on conflict(time, series, period) do update set ("+namesUA+") = ("+argsUA+") "+
433+
"on conflict(time, series, period) do update set "+namesUA+" = "+argsUA+" "+
422434
"where \"%[1]s\".time = "+argT+" and \"%[1]s\".period = "+argP+" and \"%[1]s\".series = "+argS,
423435
mergeS,
424436
)

0 commit comments

Comments
 (0)