Tell us what’s happening:
So I’m at this part of the course. When I ran the insert_data.sh, only 2 rows were generated incorrectly (Major & Web Development). I tried looking over the code, based on all the hints, and the script should be fine(?) But I probably messed up the query lines somewhere. Lol please help this noob identify the issue.
I tried to run the issue through chatGPT (see quoted area below), but I don’t trust the provided answer.
It seems like the script is working correctly, as the table majors has three rows after running the script. The INSERT 0 1 message indicates that one row was inserted successfully. The first column of the result, major_id, is the primary key of the table, and it is automatically generated by the database. The second column, major, contains the major name. The echo $MAJOR_ID line should print the major_id of the inserted major. However, it seems that the MAJOR_ID variable is not being set correctly. In this case, the MAJOR_ID variable is assigned the result of the psql command, which is not what you expect. To fix this, you need to capture the output of the psql command and store it in the MAJOR_ID variable. To do this, you can use a command substitution, like this: > MAJOR_ID=$(echo $(psql -X --username=freecodecamp --dbname=students --no-align --tuples-only -c "SELECT major_id FROM majors WHERE major='$MAJOR';")) You can also modify the PSQL variable to include the echo command, like this: > PSQL="psql -X --username=freecodecamp --dbname=students --no-align --tuples-only -c 'SELECT major_id FROM majors WHERE major='\''$MAJOR'\'';'" > MAJOR_ID=$(eval $PSQL)
Your code so far
Edit:: Let me know if you need me to copy/paste lines of code from the script or wherever.
Screenshot of exercise prompt, script, and split terminal results for better viewing:
Screenshot of courses_test.csv
Your browser information:
User Agent is:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/188.8.131.52 Safari/537.36
Challenge: Learn SQL by Building a Student Database: Part 1 - Build a Student Database: Part 1
Link to the challenge: