Tell us what’s happening:
Describe your issue in detail here.
My insert_data.sh script works and is less than 20 seconds. The test won’t pass for some reason
Your code so far
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"
TRUNCATERESULT=$($PSQL "truncate table teams, games")
{ cat games.csv | cut -f3 -d, | sort | uniq; cat games.csv | cut -f4 -d, | sort | uniq; } | sort | uniq | while read TEAM
do
if [[ $TEAM != 'winner' && $TEAM != 'opponent' ]]
then
INSERTTEAM=$($PSQL "Insert into teams(name) values('$TEAM')")
fi
done
TEAMID=$($PSQL "select concat(name,'=', team_id) from teams")
arr=(`echo ${TEAMID}`);
cat games.csv | while IFS="," read YEAR ROUND WINNER OPPONENT WINNERGOALS OPPONENTGOALS
do
if [[ $YEAR != 'year' ]]
then
for i in "${arr[@]}"
do
if [[ $i =~ $WINNER ]]; then
IFS== read winner1 winner2 <<< $i
fi
if [[ $i =~ $OPPONENT ]]; then
IFS== read opponent1 opponent2 <<< $i
fi
done
INSERTWINNERRESULT=$($PSQL "Insert into games(year, round, winner_id, opponent_id, winner_goals, opponent_goals) values($YEAR, '$ROUND', $winner2, $opponent2, $WINNERGOALS, $OPPONENTGOALS)")
fi
done
fi
Nvm. I just need to move my code out of the default it statement provided
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36 Edg/101.0.1210.53
Challenge: Build a World Cup Database
Link to the challenge: