Hi people please help.
#! /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 queries.sh | while IFS="," read YEAR ROUND WINNER OPPONENT WINNER_GOALS OPPONENT_GOALS
do
# get winner teamnames
# exclude first row of column identifiers
if [[ $WINNER != "winner" ]]
then
#get the team name
WINNER_TEAM=$($PSQL "SELECT name FROM teams WHERE name='$WINNER'")
# if the team not found at new team
if [[ -z $WINNER_TEAM ]]
then
#insert new team
INSERT_WINNER_TEAM=$($PSQL "INSERT INTO teams(name) VALUES('$WINNER')")
#echo to check if team was added
if [[ $INSERT_WINNER_TEAM == "INSERT 0 1" ]]
then
echo $WINNER
fi
fi
fi
#exclude the first row of column identifiers
if [[ $OPPONENT != "opponent" ]]
then
# get the team name
OPPONENT_TEAM=$($PSQL "SELECT name FROM teams WHERE name='$OPPONENT'")
# if the opponent is not found
if [[ -z $OPPONENT_TEAM ]]
then
# insert opponent team
INSERT_OPPONENT_TEAM=$($PSQL "INSERT INTO teams(name) VALUES('$OPPONENT')")
# echo to tell us what was inserted
if [[ $INSERT_OPPONENT == "INSERT 0 1" ]]
then
echo $OPPONENT
fi
fi
fi
if [[ YEAR != "year" ]]
then
#WINNER_ID=$($PSQL "SELECT team_id FROM teams WHERE name='$WINNER'")
INSERT_GAME_DATA=$($PSQL "INSERT INTO games(year, round, winner, opponent, winner_goals, opponent_goals) VALUES ($YEAR, '$ROUND', $WINNER, $OPPONENT, $WINNER_GOALS, $OPPONENT_GOALS)")
fi
done
My code so far.
When I run my script this is the error: