I got stucked in the tutorial part where I need to truncate “majors” table and re-execute insert_data.sh. I did what it describes. The result shows 3 rows in the table as well, however the tutorial won’t pass. Can somebody telling me what is wrong here?
code in insert_data-sh
#!/bin/bash
# Script to insert data from courses.csv and students.csv into students database
PSQL="psql -X --username=freecodecamp --dbname=students --no-align --tuples-only -c"
cat courses_test.csv | while IFS="," read MAJOR COURSE
do
if [[ $MAJOR != "major" ]]
then
# get major_id
MAJOR_ID=$($PSQL "SELECT major_id FROM majors WHERE major='$MAJOR'")
# if not found
if [[ -z $MAJOR_ID ]]
then
# insert major
INSERT_MAJOR_RESULT=$($PSQL "INSERT INTO majors(major) VALUES('$MAJOR')")
if [[ $INSERT_MAJOR_RESULT == "INSERT 0 1" ]]
then
echo Inserted into majors, $MAJOR
fi
# get new major_id
fi
# get course_id
# if not found
# insert course
# get new course_id
# insert into majors_courses
fi
done
The hints were telling me the followings:
. Run your insert_data.sh script by executing it
Type ./insert_data.sh in the terminal and press enter
The majors table should have three rows after running the script. If it doesn’t, there might be something wrong in the script. You can use the reset button to reset the lesson and run the script again
I check and I got 3 rows after running the .sh file.
I even reset, (re) TRUNCATE the table and re-execute the .sh command. However it still not let me pass.
Can you please tell me what did I do wrong? or what is actually required from this step?
It looks like you are doing it right. Are the tests running automatically? If not, you should try both of those steps in the link I shared to reset the step and settings.
If they are - I’m not quite sure what the problem is. I would try those steps either way. I guess one other thing in the tests is that it checks that you entered the command from the project folder - I’m guessing you are doing that, but there’s a chance you aren’t. Can you share a screen shot?
The tests for that step check three things:
Your majors table has 3 rows
You entered ./insert_data.sh in the terminal
and that you entered that command from the project folder
Idk what was going on…today i log-in to test your suggestion.
Before that I wanted to see if I can make it work by following the hint.
and it works! Anyway thank you for being patience helping me out