code: def copy_trial(trial_id: int) -> None:
      """
      copy a single trial with associated metrics using CTE.
      """
      trial_cols = get_table_col_names("trials") - {"id"}
      trial_cols_str = ", ".join(trial_cols)
      steps_cols = get_table_col_names("raw_steps") - {"id", "trial_id"}
      steps_cols_str = ", ".join(steps_cols)
      prefixed_steps_cols = ", ".join(
          [f"rs.{col}" for col in steps_cols]
      )
      validations_cols = get_table_col_names("raw_validations") - {
          "id",
          "trial_id",
      }
      validations_cols_str = ", ".join(validations_cols)
      prefixed_validations_cols = ", ".join(
          [f"rv.{col}" for col in validations_cols]
      )
  
      with db_cursor() as cur:
          query = f"""
  WITH replicated_trials AS (
  INSERT INTO trials ({trial_cols_str})
  SELECT {trial_cols_str}
  FROM trials
  WHERE id = %s
  RETURNING id
  ), replicated_steps AS (
  INSERT INTO raw_steps (trial_id, {steps_cols_str})
  SELECT rt.id, {prefixed_steps_cols}
  FROM replicated_trials rt
  JOIN raw_steps rs ON rs.trial_id = %s
  RETURNING trial_id, id AS new_step_id
  )
  INSERT INTO raw_validations (trial_id, {validations_cols_str})
  SELECT rt.id, {prefixed_validations_cols}
  FROM replicated_trials rt
  JOIN raw_validations rv ON rv.trial_id = %s;
          """
          cur.execute(query, (trial_id, trial_id, trial_id))
          cur.execute("COMMIT")
  
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 4 for calling a global function with example usage: copy_trial(trial_id) without return types