Periodic Table Database - sql statement error - command not found

the following command is producing the result in the psql prompt

periodic_table=> SELECT atomic_number, atomic_mass, symbol, name, type, melting_point_celsius, boiling_point_celsius FROM elements LEFT JOIN properties USING (atomic_number) LEFT JOIN types USING (type_id) WHERE atomic_number=1;
 atomic_number | atomic_mass | symbol |   name   |   type   | melting_point_celsius | boiling_point_celsius 
---------------+-------------+--------+----------+----------+-----------------------+-----------------------
             1 |       1.008 | H      | Hydrogen | nonmetal |                -259.1 |                -252.9
(1 row)

but when run in the script, its producing error:

codeally@d4b9a6924b39:~/project/periodic_table$ ./element.sh 1
./element.sh: line 12: SELECT atomic_number, atomic_mass, symbol, name, type, melting_point_celsius, boiling_point_celsius FROM elements LEFT JOIN properties USING (atomic_number) LEFT JOIN types USING (type_id) WHERE atomic_number=1: command not found
I could not find that element in the database.
codeally@d4b9a6924b39:~/project/periodic_table$ 

any help?

Google “sql command not found when running shell script”

You need to get into the psql terminal.
Do you know how to do that? (It should have been part of your script I think?)

thanks tried to google it, there was a typo error with PSQL variable. but now getting:

codeally@ea7b7efac067:~/project/periodic_table$ ./element.sh 1
ERROR:  relation "types" does not exist
LINE 1: ...T JOIN properties USING (atomic_number) LEFT JOIN types USIN...
                                                             ^
I could not find that element in the database.

hi hbar1st;
do you mean

psql (12.9 (Ubuntu 12.9-2.pgdg20.04+1))
Type "help" for help.

periodic_table=> \c periodic_table
You are now connected to database "periodic_table" as user "freecodecamp".
periodic_table=> \d types;
                       Table "public.types"```

now the problem is with :


codeally@ea7b7efac067:~/project/periodic_table$ ./element.sh 1
ERROR:  relation "types" does not exist
LINE 1: ...T JOIN properties USING (atomic_number) LEFT JOIN types USIN...
                                                             ^

No. Looks like you already fixed your script though? (You said you fixed the psql variable)

1 Like