Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit 0c32fe2

Browse files
committed
Make a unique temp table for each table type
Tables being copied have different structures so we name the tmp tables differently depending on the destination table.
1 parent 9a3e1ef commit 0c32fe2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pkg/pgmodel/ingestor/trace/writer.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,18 @@ func (t *traceWriterImpl) insertRows(ctx context.Context, table string, columns
391391
}
392392
}()
393393

394-
if _, err = tx.Exec(ctx, fmt.Sprintf("CREATE TEMPORARY TABLE IF NOT EXISTS _trace_writer_temp ON COMMIT DELETE ROWS AS TABLE _ps_trace.%s WITH NO DATA", table)); err != nil {
394+
tempTableName := pgx.Identifier{"_trace_temp_" + table}
395+
tempTableNameString := tempTableName.Sanitize()
396+
397+
if _, err = tx.Exec(ctx, fmt.Sprintf("CREATE TEMPORARY TABLE IF NOT EXISTS %s ON COMMIT DELETE ROWS AS TABLE _ps_trace.%s WITH NO DATA", tempTableNameString, table)); err != nil {
395398
return err
396399
}
397400

398-
if _, err = tx.CopyFrom(ctx, pgx.Identifier{"_trace_writer_temp"}, columns, pgx.CopyFromRows(data)); err != nil {
401+
if _, err = tx.CopyFrom(ctx, tempTableName, columns, pgx.CopyFromRows(data)); err != nil {
399402
return err
400403
}
401404

402-
if _, err = tx.Exec(ctx, fmt.Sprintf("INSERT INTO _ps_trace.%s(%[2]s) SELECT %[2]s FROM _trace_writer_temp ON CONFLICT DO NOTHING", table, strings.Join(columns, ","))); err != nil {
405+
if _, err = tx.Exec(ctx, fmt.Sprintf("INSERT INTO _ps_trace.%[1]s(%[2]s) SELECT %[2]s FROM %[3]s ON CONFLICT DO NOTHING", table, strings.Join(columns, ","), tempTableNameString)); err != nil {
403406
return err
404407
}
405408
return tx.Commit(ctx)

0 commit comments

Comments
 (0)