Worldcup database

Hi
is there any prettier way to populate the teams table something like
1 query, 1 if statement?
I was thinking something like

cat games.csv | while IFS="," read YEAR ROUND WINNER OPPONENT WINNER_GOALS OPPONENT_GOALS
do
  if [[ $YEAR != "year" ]]
  then
    #get team_id from winner or opponent
    TEAM_ID=$($PSQL "SELECT team_id FROM teams WHERE name='$WINNER' OR name="$OPPONENT'")
    if [[ -z $TEAM_ID ]]
    then
      INSERT_TEAM1_RESULT=$($PSQL "INSERT INTO teams(name) VALUES('$WINNER'), ('$OPPONENT")" )

but this one is not working for some reason, maybe the OR is being true for some combinations then skipping the insert where it should insert something
so I gave up and did two queries with 2 ifs but the performance is terrible, i guess

#! /bin/bash

if [[ $1 == "test" ]]
then
  PSQL="psql --username=postgres --dbname=worldcuptest -t --no-align -c"
else
  PSQL="psql --username=freecodecamp --dbname=worldcup -t --no-align -c"
fi

# Do not change code above this line. Use the PSQL variable above to query your database.
echo $($PSQL "TRUNCATE teams, games")
#looping over file to 
cat games.csv | while IFS="," read YEAR ROUND WINNER OPPONENT WINNER_GOALS OPPONENT_GOALS
do
  if [[ $YEAR != "year" ]]
  then
    #get team_id from winner
    TEAM_ID1=$($PSQL "SELECT team_id FROM teams WHERE name='$WINNER'")
    if [[ -z $TEAM_ID1  ]]
    then
      INSERT_TEAM1_RESULT=$($PSQL "INSERT INTO teams(name) VALUES('$WINNER')")
    fi
   #get team_id from opponent
  TEAM_ID2=$($PQSL "SELECT team_id FROM teams WHERE name='$OPPONENT'")
    if [[ -z $TEAM_ID2 ]]
    then
      INSERT_TEAM2_RESULT=$($PSQL "INSERT INTO teams(name) VALUES('$OPPONENT')")
    fi
  fi
done

When you said performance is terrible, what you mean?

I ran your code. It inserted the team names but I got error like this

Blockquote
“SELECT team_id FROM teams WHERE name=‘England’: command not found
ERROR: duplicate key value violates unique constraint “teams_name_key”
DETAIL: Key (name)=(England) already exists.”

Is that what you mean by terrible performance?

I meant it was running without errors, but it was very slow