Tell us what’s happening:
I am doing revision for this course in my own visual studio code for my own personal data.
When I add in the tuples-only-c line code and also the code after the get major ID comment in the insert_data.sh, the response is need user password and cannot proceed.
Even after I skipped using the tuples-only-c code and run the script with
./insert_data.sh
the response is $ ./insert_data.sh
./insert_data.sh: line 7: SELECT major_id FROM majors WHERE major=‘major’: command not found
May I know how to resolve this issue?
Your code so far
#!/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
# get major_id
MAJOR_ID=$($PSQL "SELECT major_id FROM majors WHERE major='$MAJOR'")
echo $MAJOR_ID
# if not found
if [[ -z $MAJOR_ID ]]
then
# insert major
INSERT_MAJOR_RESULT=$($PSQL "INSERT INTO majors(major) VALUES('$MAJOR')")
echo $INSERT_MAJOR_RESULT
# get new major_id
fi
# get course_id
# if not found
# insert course
# get new course_id
# insert into majors_courses
done
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 OPR/96.0.0.0
Challenge: Learn SQL by Building a Student Database: Part 1 - Build a Student Database: Part 1
I know the problem already. I need to have a laptop that I can download all the necessary related programs. Otherwise, the code that is function normally for the test here is not usable in the Visual Studio Code Program.