World Cup Database - Build a World Cup Database Time limit

Hi, i cant complete the insert data but i can’t get it in 20 seconds, but i have seen some solutions from other people and they are very similar, so i don’t now if it’s my code or what

Could be the code yes.

I relaunch the application and it worked

here’s my code

#! /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 TABLE games, teams;”)

cat games.csv | while IFS=“,” read YEAR ROUND WINNER OPPO W_GOALS O_GOALS
do
if [[ $YEAR != ‘year’ ]]
then
TEAM_ID_W=$($PSQL “SELECT team_id FROM teams WHERE name=‘$WINNER’”)
if [[ -z $TEAM_ID_W ]]
then
INSERT_TEAM_RESULT=$($PSQL “INSERT INTO teams(name) VALUES(‘$WINNER’)”)
fi

TEAM_ID_L=$($PSQL “SELECT team_id FROM teams WHERE name=‘$OPPO’”)
if [[ -z $TEAM_ID_L ]]
then
INSERT_TEAM_RESULT=$($PSQL “INSERT INTO teams(name) VALUES(‘$OPPO’)”)
fi

TEAM_ID_W=$($PSQL "SELECT team_id FROM teams WHERE name='$WINNER'")
TEAM_ID_L=$($PSQL "SELECT team_id FROM teams WHERE name='$OPPO'")

INSERT_TEAM_RESULT=$($PSQL "INSERT INTO games(year,round,winner_id,opponent_id,winner_goals,opponent_goals) VALUES($YEAR,'$ROUND',$TEAM_ID_W,$TEAM_ID_L,$W_GOALS,$O_GOALS)")

fi
done

The application seems to get a bit slower sometimes

We have blurred this solution (with [spoiler][/spoiler] tags) so that users who have not completed this challenge can read the discussion in this thread without giving away the solution.