World Cup Database - Build a World Cup Database - Issue After Inserting Opponents

Tell us what’s happening:
I am at the start of the process, just inserting the team names into the teams table so that they can be populated with team ids before I continue with the insert into the games table.

I have my insert.sh file set to echo to the bash terminal what is happening and it all seems to be working fine. When I go into the psql terminal and type in

SELECT * FROM teams;

It displays the first 16 teams with a : following it. After that I have to press Enter multiple times to see each line and the last line displayed is a box with the word END in it.

After that, my psql terminal stops working and I cannot do anything with it. On the terminals view on the right hand side, it shows as a bash terminal for some reason.

Your code so far

Echo $($PSQL "TRUNCATE teams, games RESTART IDENTITY")

#read file
cat games.csv | while IFS="," read YEAR ROUND WINNER OPPONENT WINNER_GOALS OPPONENT_GOALS
do
# Ignore first line
  if [[ $YEAR != "year" ]]
  then
    # Get team ids

    # Get winner_id:
    WINNER_ID=$($PSQL "SELECT team_id FROM teams WHERE name='$WINNER'")
    
    # If not found:
    if [[ -z $WINNER_ID ]]
    then
      ADDED_TEAM=$($PSQL "INSERT INTO teams(name) VALUES('$WINNER')")
        
        # Echo to terminal:
        if [[ $ADDED_TEAM = "INSERT 0 1" ]]
        then
          echo Added $WINNER to teams
        fi
    fi

    # Get opponent_id:
    OPPONENT_ID=$($PSQL "SELECT team_id FROM teams WHERE name='$OPPONENT'")
    
    # If not found:
    if [[ -z $OPPONENT_ID ]]
    then ADDED=$($PSQL "INSERT INTO teams(name) VALUES('$OPPONENT')")
      
      # Echo to terminal
      if [[ $ADDED = "INSERT 0 1" ]]
      then
        echo Added $OPPONENT to teams
      fi
    fi

  fi
done

I am aware that I am not actually pulling the team ids at the moment after I insert them, I am just testing in stages.
Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36

Challenge: World Cup Database - Build a World Cup Database

Link to the challenge:

This is a normal pagination process.

If you make your terminal bigger you can avoid that (the terminal displays the number of lines it can fit then stops to let you read each time. But if it’s bigger it will bio display more without stopping)

How do I fix the terminal so that I can run further commands in it?

Thanks,

I’m not sure what happened to your terminal but you can start a new one.

The program you are using is called vscode I believe
here are instructions that may help you

(basically go to the hamburger menu and go to Terminal and create a new one)

That’s what I’ve been doing but I’m not sure what has been causing this error in my code.

If I don’t insert the opponents, then when I go through the teams, it displays all 13 of the winning teams in one go. This is still larger than the display of my terminal but it just displays them all at once without the pagination and then I have to scroll to see the ones above the line.

Apart from that, the main difference is that I can continue to use the psql terminal for other commands. There seems to be something wrong with my bash script for inserting opponents because after I do that, my teams table accepts only one select before it stops working but I can’t work out what the issue is. :frowning:

yes so just make your terminal larger when you are inside psql
(you can also look for a way to disable pagination, but just resize the terminal and it will work the same)

I’m not gonna comment on your scripts. The point I am trying to help with is once you connect to psql , pull open the terminal wider and run a simple select for example, you should be able to see the output without pagination (unless the output of the select is too long)

So the conclusion is, this is normal behaviour for the terminal.

Thanks for your help hbar1st but I think your misunderstanding the issue that I am having.

I don’t mind the pagination. Are you saying that it is normal behaviour for the psql server to be able to run only a single command after the insert? This is not how it was during the lessons and it is not the behaviour of the terminal when I don’t insert the opponents.

Not meaning to be argumentative, just unsure of how to fix it.

This is the part of what you said that I was saying is normal behavior and can be worked around by pulling open the terminal to a bigger size.

So at this point, beyond the select statement, you seem to be saying, that you are trying to run an insert command on psql command line.
Can you show the series of commands you are running and their output?
I don’t mind seeing a screenshot if that is the best way to do this.

Hi hbar1st,

You are correct.

I was mistaken about the way the pagination works.

I have entered teams manually without using the bash script and it does behave the same.

I have found out that pressing “;” and then “q” gets me out of the results and returns my terminal back to working.

Thanks for all your help!

1 Like