Periodic Table Database: a mysterious error

HI. I’m doing the Periodic Table Database challenge. The verification system tells me that I passed all tests successfully, except one:

SUBTASKS 1.1 :25 Running your script with input that doesn’t exist should give the output described

It seems to me that the result I get is exactly the one requested by the user stories.

I attach two screen shots with the relevant passage of the user stories and the terminal session.

I also attach the “element.sh” and “periodic_table.sql” files.

#!/bin/bash

# Show informations about chemical elements

PSQL="psql --username=postgres --dbname=periodic_table -t -q --no-align -c"

# If you run `./element.sh`, it should output only `Please provide an element as an argument.` and finish running.
if [[ -z $1 ]]
then
  echo Please provide an element as an argument.
  exit
fi

SEARCH_FOR_SYMBOL() {
  # search for the symbol
  local QUERY_RESULT=$($PSQL "
  SELECT el.atomic_number, el.symbol, el.name, pr.atomic_mass, pr.melting_point_celsius, pr.boiling_point_celsius, t.type
  FROM elements AS el
  FULL JOIN properties AS pr ON el.atomic_number = pr.atomic_number
  FULL JOIN types AS t ON pr.type_id = t.type_id
  WHERE el.symbol = '$1';")
  # if symbol exists print the message
  if [[ ! -z $QUERY_RESULT ]]
  then
    read ATOMIC_NUMBER SYMBOL ELEMENT_NAME ATOMIC_MASS MELTING_POINT BOILING_POINT TYPE <<< $(echo $QUERY_RESULT | sed 's/[|]/ /g')
    echo The element with atomic number $ATOMIC_NUMBER is $ELEMENT_NAME \($SYMBOL\). It\'s a $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.
  else
    # else notify the absence of the symbol
    echo I could not find that element in the database.
  fi
  exit 0
}

SEARCH_FOR_ATOMIC_NUMBER() {
  # search for the atomic number
  local QUERY_RESULT=$($PSQL "
  SELECT el.atomic_number, el.symbol, el.name, pr.atomic_mass, pr.melting_point_celsius, pr.boiling_point_celsius, t.type
  FROM elements AS el
  FULL JOIN properties AS pr ON el.atomic_number = pr.atomic_number
  FULL JOIN types AS t ON pr.type_id = t.type_id
  WHERE pr.atomic_number = '$1';")
  # if symbol exists print the message
  if [[ ! -z $QUERY_RESULT ]]
  then
    read ATOMIC_NUMBER SYMBOL ELEMENT_NAME ATOMIC_MASS MELTING_POINT BOILING_POINT TYPE <<< $(echo $QUERY_RESULT | sed 's/[|]/ /g')
    echo The element with atomic number $ATOMIC_NUMBER is $ELEMENT_NAME \($SYMBOL\). It\'s a $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.
  else
    # else notify the absence of the symbol
    echo I could not find that element in the database.
  fi
  exit 0
}

SEARCH_FOR_ELEMENT_NAME() {
  # search for the element name
  local QUERY_RESULT=$($PSQL "
  SELECT el.atomic_number, el.symbol, el.name, pr.atomic_mass, pr.melting_point_celsius, pr.boiling_point_celsius, t.type
  FROM elements AS el
  FULL JOIN properties AS pr ON el.atomic_number = pr.atomic_number
  FULL JOIN types AS t ON pr.type_id = t.type_id
  WHERE el.name = '$1';")
  # if symbol exists print the message
  if [[ ! -z $QUERY_RESULT ]]
  then
    read ATOMIC_NUMBER SYMBOL ELEMENT_NAME ATOMIC_MASS MELTING_POINT BOILING_POINT TYPE <<< $(echo $QUERY_RESULT | sed 's/[|]/ /g')
    echo The element with atomic number $ATOMIC_NUMBER is $ELEMENT_NAME \($SYMBOL\). It\'s a $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.
  else
    # else notify the absence of the symbol
    echo I could not find that element in the database.
  fi
  exit 0
}

# check the structure of the parameter and choose an SQL command
if [[ $1 =~ ^[A-Z][a-z]?$ ]];
then
  SYMBOL=$1
  SEARCH_FOR_SYMBOL $SYMBOL
elif [[ $1 =~ ^[1-9][0-9]*$ ]]
then
  ATOMIC_NUMBER=$1
  SEARCH_FOR_ATOMIC_NUMBER $ATOMIC_NUMBER
elif [[ $1 =~ ^[A-Z][a-z]+$ && ${#1} -ge 3 ]]
then
  ELEMENT_NAME=$1
  SEARCH_FOR_ELEMENT_NAME $ELEMENT_NAME
fi
--
-- PostgreSQL database dump
--

-- Dumped from database version 12.19
-- Dumped by pg_dump version 12.19

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 IF EXISTS periodic_table;

CREATE DATABASE periodic_table WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'C' LC_CTYPE = 'C';

ALTER DATABASE periodic_table OWNER TO freecodecamp;

\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;

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;

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;

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

ALTER TABLE public.types OWNER TO freecodecamp;

INSERT INTO public.elements VALUES (1, 'H', 'Hydrogen');
INSERT INTO public.elements VALUES (2, 'He', 'Helium');
INSERT INTO public.elements VALUES (3, 'Li', 'Lithium');
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 (9, 'F', 'Fluorine');
INSERT INTO public.elements VALUES (10, 'Ne', 'Neon');

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

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

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

ALTER TABLE ONLY public.elements
    ADD CONSTRAINT elements_name_key UNIQUE (name);

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

ALTER TABLE ONLY public.elements
    ADD CONSTRAINT elements_symbol_key UNIQUE (symbol);

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

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

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

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

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

What could be the problem?

Hmm, I tried your script with literally random name, but there wasn’t displayed anything in response.

camper: /periodic_table$ ./element.sh random
camper: /periodic_table$ 

@sanity Ok, I solved the challenge, your observation was helpful in pinpointing the problem. Thank you.

But I must note that the error is in the user stories: the tests all pass even if the script replies “I could not find that element in the database” without having done any search in the database.

The correct sentence, in that case, should be: The format of the argument is incorrect and can not match any elements. Please enter a valid argument.