code: def upsert_keys(session, key_table, keys):
      
      # Do nothing if empty
      if not keys:
          return
  
      for key_batch in _batch_postgres_query(
          key_table, [{"name": k[0], "candidate_classes": k[1]} for k in keys.items()]
      ):
          stmt = insert(key_table.__table__)
          stmt = stmt.on_conflict_do_update(
              constraint=key_table.__table__.primary_key,
              set_={
                  "name": stmt.excluded.get("name"),
                  "candidate_classes": stmt.excluded.get("candidate_classes"),
              },
          )
          while True:
              try:
                  session.execute(stmt, key_batch)
                  session.commit()
                  break
              except Exception as e:
                  logger.debug(e)
docs: Bulk add annotation keys to the specified table.
  
      :param key_table: The sqlalchemy class to insert into.
      :param keys: A map of {name: [candidate_classes]}.