Periodic Table Database - Build a Periodic Table Database

Tell us what’s happening:
Hello the code is working as the project requires but I can’t get the test involving the element.sh script to pass.

Here is my script so far

#!/bin/bash

PSQL="psql -X --username=freecodecamp --dbname=periodic_table --tuples-only -c"


# if no argument is entered
if [[ -z $1 ]]
then
echo -e "Please provide an element as an argument."
exit
fi


# if argument is a number
if [[ ! $1 =~ ^[0-9]+$ ]]
then
ELEMENT_NAME=$($PSQL "SELECT name FROM elements WHERE name='$1'")
ELEMENT_DIGIT=$($PSQL "SELECT atomic_number FROM elements WHERE name='$1'")
ELEMENT_SYMBOL=$($PSQL "SELECT symbol FROM elements WHERE name='$1'")
ELEMENT_TYPE=$($PSQL "SELECT type FROM types FULL JOIN properties USING (type_id) FULL JOIN elements USING (atomic_number) WHERE name='$1'")
ATOMIC_MASS=$($PSQL "SELECT atomic_mass FROM properties FULL JOIN elements USING (atomic_number) WHERE name='$1'")
BOILING_POINT=$($PSQL "SELECT boiling_point_celsius FROM properties FULL JOIN elements USING (atomic_number) WHERE name='$1'")
MELTING_POINT=$($PSQL "SELECT melting_point_celsius FROM properties FULL JOIN elements USING (atomic_number) WHERE name='$1'")

  # if the query is not empty
  if [[ ! -z $ELEMENT_NAME ]];
  then
  echo $ELEMENT_NAME $ELEMENT_DIGIT $ELEMENT_SYMBOL $ELEMENT_TYPE $ATOMIC_MASS $BOILING_POINT $MELTING_POINT | while IFS=" |" read ELEMENT_NAME ELEMENT_DIGIT ELEMENT_SYMBOL ELEMENT_TYPE ATOMIC_MASS BOILING_POINT MELTING_POINT; do
  echo  "The element with atomic number $ELEMENT_DIGIT is $ELEMENT_NAME ($ELEMENT_SYMBOL). It's a $ELEMENT_TYPE, with a mass of $ATOMIC_MASS amu. $ELEMENT_NAME has a melting point of $MELTING_POINT celsius and a boiling point of $BOILING_POINT celsius."
  done
  
  else 

  # if the query is empty
  if [[ -z $ELEMENT_NAME ]];
  then

  ELEMENT_NAME=$($PSQL "SELECT name FROM elements WHERE symbol='$1' AND SYMBOL IS NOT NULL")
  ELEMENT_DIGIT=$($PSQL "SELECT atomic_number FROM elements WHERE symbol='$1'")
  ELEMENT_SYMBOL=$($PSQL "SELECT symbol FROM elements WHERE symbol='$1'")
  ELEMENT_TYPE=$($PSQL "SELECT type FROM types FULL JOIN properties USING (type_id) FULL JOIN elements USING (atomic_number) WHERE symbol='$1'")
  ATOMIC_MASS=$($PSQL "SELECT atomic_mass FROM properties FULL JOIN elements USING (atomic_number) WHERE symbol='$1'")
  BOILING_POINT=$($PSQL "SELECT boiling_point_celsius FROM properties FULL JOIN elements USING (atomic_number) WHERE symbol='$1'")
  MELTING_POINT=$($PSQL "SELECT melting_point_celsius FROM properties FULL JOIN elements USING (atomic_number) WHERE symbol='$1'")

  echo $ELEMENT_NAME $ELEMENT_DIGIT $ELEMENT_SYMBOL $ELEMENT_TYPE $ATOMIC_MASS $BOILING_POINT $MELTING_POINT | while IFS=" |" read ELEMENT_NAME ELEMENT_DIGIT ELEMENT_SYMBOL ELEMENT_TYPE ATOMIC_MASS BOILING_POINT MELTING_POINT; do
 echo  "The element with atomic number $ELEMENT_DIGIT is $ELEMENT_NAME ($ELEMENT_SYMBOL). It's a $ELEMENT_TYPE, with a mass of $ATOMIC_MASS amu. $ELEMENT_NAME has a melting point of $MELTING_POINT celsius and a boiling point of $BOILING_POINT celsius."
 done
 
  fi
 fi
fi


# If argument is not a number
if [[ $1 =~ ^[0-9]+$ ]]
then
ATOMIC_NUMBER=$($PSQL "SELECT name FROM elements WHERE atomic_number=$1")
ATOMIC_DIGIT=$($PSQL "SELECT atomic_number FROM elements WHERE atomic_number=$1")
ATOMIC_SYMBOL=$($PSQL "SELECT symbol FROM elements WHERE atomic_number=$1")
ATOMIC_TYPE=$($PSQL "SELECT type FROM types FULL JOIN properties USING (type_id) FULL JOIN elements USING (atomic_number) WHERE atomic_number=$1")
ATOMIC_MASS=$($PSQL "SELECT atomic_mass FROM properties WHERE atomic_number=$1")
BOILING_POINT=$($PSQL "SELECT boiling_point_celsius FROM properties WHERE atomic_number=$1")
MELTING_POINT=$($PSQL "SELECT melting_point_celsius FROM properties WHERE atomic_number=$1")
echo $ATOMIC_NUMBER $ATOMIC_DIGIT $ATOMIC_SYMBOL $ATOMIC_TYPE $ATOMIC_MASS $BOILING_POINT $MELTING_POINT | while IFS=" |" read ATOMIC_NAME ATOMIC_DIGIT ATOMIC_SYMBOL ATOMIC_TYPE ATOMIC_MASS BOILING_POINT MELTING_POINT; do
 echo  "The element with atomic number $ATOMIC_DIGIT is$ATOMIC_NUMBER ($ATOMIC_SYMBOL). It's a $ATOMIC_TYPE, with a mass of $ATOMIC_MASS amu. $ATOMIC_NUMBER has a melting point of $MELTING_POINT celsius and a boiling point of $BOILING_POINT celsius."
 done
fi

** And here is my database dump **

-
-- PostgreSQL database dump
--

-- Dumped from database version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)
-- Dumped by pg_dump version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

DROP DATABASE periodic_table;
--
-- Name: periodic_table; Type: DATABASE; Schema: -; Owner: postgres
--

CREATE DATABASE periodic_table WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'C.UTF-8' LC_CTYPE = 'C.UTF-8';


ALTER DATABASE periodic_table OWNER TO postgres;

\connect periodic_table

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: elements; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.elements (
    atomic_number integer NOT NULL,
    symbol character varying(2) NOT NULL,
    name character varying(40) NOT NULL
);


ALTER TABLE public.elements OWNER TO freecodecamp;

--
-- Name: properties; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.properties (
    atomic_number integer NOT NULL,
    atomic_mass numeric NOT NULL,
    melting_point_celsius numeric NOT NULL,
    boiling_point_celsius numeric NOT NULL,
    type_id integer NOT NULL
);


ALTER TABLE public.properties OWNER TO freecodecamp;

--
-- Name: types; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.types (
    type_id integer NOT NULL,
    type character varying NOT NULL
);


ALTER TABLE public.types OWNER TO freecodecamp;

--
-- Data for Name: elements; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--

INSERT INTO public.elements VALUES (1, 'H', 'Hydrogen');
INSERT INTO public.elements VALUES (4, 'Be', 'Beryllium');
INSERT INTO public.elements VALUES (5, 'B', 'Boron');
INSERT INTO public.elements VALUES (6, 'C', 'Carbon');
INSERT INTO public.elements VALUES (7, 'N', 'Nitrogen');
INSERT INTO public.elements VALUES (8, 'O', 'Oxygen');
INSERT INTO public.elements VALUES (10, 'Ne', 'Neon');
INSERT INTO public.elements VALUES (9, 'F', 'Fluorine');
INSERT INTO public.elements VALUES (2, 'He', 'Helium');
INSERT INTO public.elements VALUES (3, 'Li', 'Lithium');


--
-- Data for Name: properties; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--

INSERT INTO public.properties VALUES (1, 1.008, -259.1, -252.9, 1);
INSERT INTO public.properties VALUES (2, 4.0026, -272.2, -269, 1);
INSERT INTO public.properties VALUES (3, 6.94, 180.54, 1342, 2);
INSERT INTO public.properties VALUES (4, 9.0122, 1287, 2470, 2);
INSERT INTO public.properties VALUES (5, 10.81, 2075, 4000, 3);
INSERT INTO public.properties VALUES (6, 12.011, 3550, 4027, 1);
INSERT INTO public.properties VALUES (7, 14.007, -210.1, -195.8, 1);
INSERT INTO public.properties VALUES (8, 15.999, -218, -183, 1);
INSERT INTO public.properties VALUES (10, 20.18, -248.6, -246.1, 1);
INSERT INTO public.properties VALUES (9, 18.998, -220, -188.1, 1);


--
-- Data for Name: types; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--

INSERT INTO public.types VALUES (1, 'nonmetal');
INSERT INTO public.types VALUES (2, 'metal');
INSERT INTO public.types VALUES (3, 'metalloid');


--
-- Name: elements elements_atomic_number_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.elements
    ADD CONSTRAINT elements_atomic_number_key UNIQUE (atomic_number);


--
-- Name: elements elements_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.elements
    ADD CONSTRAINT elements_pkey PRIMARY KEY (atomic_number);


--
-- Name: elements elements_symbol_name_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.elements
    ADD CONSTRAINT elements_symbol_name_key UNIQUE (symbol, name);


--
-- Name: properties properties_atomic_number_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.properties
    ADD CONSTRAINT properties_atomic_number_key UNIQUE (atomic_number);


--
-- Name: properties properties_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.properties
    ADD CONSTRAINT properties_pkey PRIMARY KEY (atomic_number);


--
-- Name: types types_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.types
    ADD CONSTRAINT types_pkey PRIMARY KEY (type_id);


--
-- Name: properties properties_atomic_number_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.properties
    ADD CONSTRAINT properties_atomic_number_fkey FOREIGN KEY (atomic_number) REFERENCES public.elements(atomic_number);


--
-- Name: properties properties_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.properties
    ADD CONSTRAINT properties_type_id_fkey FOREIGN KEY (type_id) REFERENCES public.types(type_id);


--
-- PostgreSQL database dump complete
--


Your browser information:

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

Challenge: Periodic Table Database - Build a Periodic Table Database

Link to the challenge:

Are you still having problems with this? I just finished this project, and found the code was very strict regarding what output you print. I outputted a simple title, and that made the test fail. You seem to have a few extra echo statements in there.