code: def duplicate_table_rows(
      cur: psycopg.Cursor, table: str, suffix: str = ""
  ) -> Generator[int, None, None]:
      """
      duplicate rows of a table and keep a mapping between old and new ids.
      `id` col is assumed to auto increment.
      return: number of new rows added
      """
      cols = get_table_col_names(table) - {"id"}
      cols_str = ", ".join(cols)
      values_str = ", ".join([table + "." + col for col in cols])
  
      query = f"""
  -- modify the target table to add a new col called og_id
  ALTER TABLE {table} ADD COLUMN og_id int;
  """
      cur.execute(query)
  
      query = f"""
  -- insert the replicated rows populating the og_id column with the original id
  INSERT INTO {table}( {cols_str}, og_id )
  SELECT {values_str}, {table}.id
  FROM {table}
  {suffix};
  """
      cur.execute(query)
      affected_rows = cur.rowcount
  
      query = f"""
  CREATE TEMP TABLE {table}_id_map AS
  SELECT id, og_id
  FROM {table}
  WHERE og_id IS NOT NULL;
  """
      cur.execute(query)
  
      yield affected_rows
  
      # tear down
      query = f"""
  -- drop the table
  -- DROP TABLE {table}_id_map; -- temp table
  -- drop the added column
  ALTER TABLE {table} DROP COLUMN og_id;
      """
      cur.execute(query)
  
file_path: determined/tools/scripts/replicate-metrics.py
imports: import concurrent.futures
  import contextlib
  import os
  import time
  from typing import Any, Dict, Generator, List, Set, Tuple, Union
  import psycopg
  from psycopg import sql
label_desc: Use image node_id 6 for calling a global function with example usage: duplicate_table_rows(cur, table, suffix) without return types