Number Guessing Game - Step 8 (Relational Database Certification)

Okay, I’m giving in and looking for a lifeline. I am only failing Step 8 of this project and I cannot figure out why. It’s been days. I’ve recoded this from scratch several times and I keep getting stuck on the same step sweat_smile::

If that username has been used before, it should print Welcome back, <username>! You have played <games_played> games, and your best game took <best_game> guesses. , with <username> being a users name from the database, <games_played> being the total number of games that user has played, and <best_game> being the fewest number of guesses it took that user to win the game

I am getting the desired output, and my tables are being updated properly, from what I can tell, but everything that I’ve tried has had the same result - including solutions from other forum posts from users being stuck on this step.

Any help would be highly appreciated.

Here is my number_guess.sh script:

#!/bin/bash

# Set variable for database connection
PSQL="psql --username=freecodecamp --dbname=number_guess -t --tuples-only --no-align -c"

function GET_USER_INFO {

  # Prompt user to enter their username
  echo "Enter your username:"
  read USERNAME

  # Check if this username is in the users table
  USER_ID=$($PSQL "select user_id from users where username = '$USERNAME'")

  if [[ ! -z $USER_ID ]]
  then
    # THIS SECTION NEEDS ATTENTION -- FAILING THIS STEP
    # If the user is a returning user:
    GAMES_PLAYED=$($PSQL "select games_played from users where user_id = $USER_ID" | sed 's/ //g');
    BEST_GAME=$($PSQL "select best_game from users where user_id = $USER_ID" | sed 's/ //g');
    echo -e "\nWelcome back, $USERNAME! You have played $GAMES_PLAYED games, and your best game took $BEST_GAME guesses."
  else
    # If the username does not exist:
    # Add new user to the users table
    INSERT_NEW_USER=$($PSQL "insert into users (username) values ('$USERNAME')")
    echo -e "\nWelcome, $USERNAME! It looks like this is your first time here."
  fi
}

function PLAY_GAME {

  # Generate secret number to guess
  SECRET_NUMBER=$(( RANDOM % 1000 + 1 ))

  # Set variable to track user's total number of guesses for game
  TOTAL_GUESSES=0

  # Prompt user to enter their first guess
  echo -e "\nGuess the secret number between 1 and 1000:"
  read GUESS

  function COMPARE {
    # Verify that the user's guess is an integer
    if [[ ! $GUESS =~ ^-?[0-9]+$ ]]
    then
      # If the user's guess is not an integer
      echo -e "\nThat is not an integer, guess again:"
      read GUESS
      COMPARE
    else
      # If user's guess is lower than the secret number
      if [[ $GUESS -lt $SECRET_NUMBER ]]
      then
        TOTAL_GUESSES=$(( $TOTAL_GUESSES + 1 ))
        echo -e "\nIt's higher than that, guess again:"
        read GUESS
        COMPARE
      # If user's guess is higher than the secret number
      elif [[ $GUESS -gt $SECRET_NUMBER ]]
      then
        TOTAL_GUESSES=$(( $TOTAL_GUESSES + 1 ))
        echo -e "\nIt's lower than that, guess again:"
        read GUESS
        COMPARE
      # If user's guess is correct
      else
        TOTAL_GUESSES=$(( $TOTAL_GUESSES + 1 ))       
        # Save game results to games table
        INSERT_GAME_RESULTS=$($PSQL "insert into games (user_id, total_guesses) values ($USER_ID, $TOTAL_GUESSES)")
        # Update games_played in users table
        UPDATE_GAMES_PLAYED=$($PSQL "update users set games_played = games_played + 1 where user_id = $USER_ID")
        # If new personal best, update best_game in users table
        if [[ $BEST_GAME == 0 || $TOTAL_GUESSES -lt $BEST_GAME ]]
        then
          UPDATE_BEST_GAME=$($PSQL "update users set best_game = $TOTAL_GUESSES where user_id = $USER_ID")
        fi
        # THIS SECTION NEEDS ATTENTION -- FAILING THIS STEP
        echo -e "\nYou guessed it in $TOTAL_GUESSES tries. The secret number was $SECRET_NUMBER. Nice job!"
        exit
      fi
    fi
  }

  COMPARE

}

GET_USER_INFO
PLAY_GAME

Here is my SQL dump:

--
-- PostgreSQL database dump
--

-- Dumped from database version 12.17 (Ubuntu 12.17-1.pgdg22.04+1)
-- Dumped by pg_dump version 12.17 (Ubuntu 12.17-1.pgdg22.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 number_guess;
--
-- Name: number_guess; Type: DATABASE; Schema: -; Owner: freecodecamp
--

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


ALTER DATABASE number_guess OWNER TO freecodecamp;

\connect number_guess

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: games; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.games (
    game_id integer NOT NULL,
    user_id integer NOT NULL,
    total_guesses integer DEFAULT 0
);


ALTER TABLE public.games OWNER TO freecodecamp;

--
-- Name: games_game_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.games_game_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.games_game_id_seq OWNER TO freecodecamp;

--
-- Name: games_game_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.games_game_id_seq OWNED BY public.games.game_id;


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

CREATE TABLE public.users (
    user_id integer NOT NULL,
    username character varying(22) NOT NULL,
    games_played integer DEFAULT 0,
    best_game integer DEFAULT 0
);


ALTER TABLE public.users OWNER TO freecodecamp;

--
-- Name: users_user_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.users_user_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.users_user_id_seq OWNER TO freecodecamp;

--
-- Name: users_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.users_user_id_seq OWNED BY public.users.user_id;


--
-- Name: games game_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.games ALTER COLUMN game_id SET DEFAULT nextval('public.games_game_id_seq'::regclass);


--
-- Name: users user_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.users ALTER COLUMN user_id SET DEFAULT nextval('public.users_user_id_seq'::regclass);


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

INSERT INTO public.games VALUES (7, 1, 9);
INSERT INTO public.games VALUES (8, 4, 267);
INSERT INTO public.games VALUES (9, 5, 667);
INSERT INTO public.games VALUES (10, 4, 88);
INSERT INTO public.games VALUES (11, 4, 804);
INSERT INTO public.games VALUES (12, 4, 325);
INSERT INTO public.games VALUES (13, 6, 859);
INSERT INTO public.games VALUES (14, 7, 62);
INSERT INTO public.games VALUES (15, 6, 481);
INSERT INTO public.games VALUES (16, 6, 281);
INSERT INTO public.games VALUES (17, 6, 564);
INSERT INTO public.games VALUES (18, 8, 582);
INSERT INTO public.games VALUES (19, 9, 712);
INSERT INTO public.games VALUES (20, 8, 833);
INSERT INTO public.games VALUES (21, 8, 172);
INSERT INTO public.games VALUES (22, 8, 182);
INSERT INTO public.games VALUES (23, 10, 539);
INSERT INTO public.games VALUES (24, 11, 426);
INSERT INTO public.games VALUES (25, 10, 518);
INSERT INTO public.games VALUES (26, 10, 317);
INSERT INTO public.games VALUES (27, 10, 45);
INSERT INTO public.games VALUES (28, 12, 581);
INSERT INTO public.games VALUES (29, 13, 688);
INSERT INTO public.games VALUES (30, 12, 831);
INSERT INTO public.games VALUES (31, 12, 964);
INSERT INTO public.games VALUES (32, 12, 366);
INSERT INTO public.games VALUES (33, 14, 577);
INSERT INTO public.games VALUES (34, 15, 438);
INSERT INTO public.games VALUES (35, 14, 512);
INSERT INTO public.games VALUES (36, 14, 921);
INSERT INTO public.games VALUES (37, 14, 566);
INSERT INTO public.games VALUES (38, 16, 585);
INSERT INTO public.games VALUES (39, 17, 354);
INSERT INTO public.games VALUES (40, 16, 462);
INSERT INTO public.games VALUES (41, 16, 848);
INSERT INTO public.games VALUES (42, 16, 618);
INSERT INTO public.games VALUES (43, 18, 530);
INSERT INTO public.games VALUES (44, 19, 599);
INSERT INTO public.games VALUES (45, 18, 532);
INSERT INTO public.games VALUES (46, 18, 215);
INSERT INTO public.games VALUES (47, 18, 64);
INSERT INTO public.games VALUES (48, 20, 55);
INSERT INTO public.games VALUES (49, 21, 795);
INSERT INTO public.games VALUES (50, 20, 303);
INSERT INTO public.games VALUES (51, 20, 388);
INSERT INTO public.games VALUES (52, 20, 988);
INSERT INTO public.games VALUES (53, 22, 103);
INSERT INTO public.games VALUES (54, 23, 187);
INSERT INTO public.games VALUES (55, 22, 700);
INSERT INTO public.games VALUES (56, 22, 126);
INSERT INTO public.games VALUES (57, 22, 859);
INSERT INTO public.games VALUES (58, 24, 583);
INSERT INTO public.games VALUES (59, 25, 412);
INSERT INTO public.games VALUES (60, 24, 312);
INSERT INTO public.games VALUES (61, 24, 427);
INSERT INTO public.games VALUES (62, 24, 307);
INSERT INTO public.games VALUES (63, 26, 223);
INSERT INTO public.games VALUES (64, 27, 691);
INSERT INTO public.games VALUES (65, 26, 616);
INSERT INTO public.games VALUES (66, 26, 267);
INSERT INTO public.games VALUES (67, 26, 958);
INSERT INTO public.games VALUES (68, 28, 117);
INSERT INTO public.games VALUES (69, 29, 620);
INSERT INTO public.games VALUES (70, 28, 752);
INSERT INTO public.games VALUES (71, 28, 722);
INSERT INTO public.games VALUES (72, 28, 956);
INSERT INTO public.games VALUES (73, 30, 209);
INSERT INTO public.games VALUES (74, 31, 573);
INSERT INTO public.games VALUES (75, 30, 96);
INSERT INTO public.games VALUES (76, 30, 544);
INSERT INTO public.games VALUES (77, 30, 815);
INSERT INTO public.games VALUES (78, 32, 106);
INSERT INTO public.games VALUES (79, 33, 673);
INSERT INTO public.games VALUES (80, 32, 556);
INSERT INTO public.games VALUES (81, 32, 691);
INSERT INTO public.games VALUES (82, 32, 231);
INSERT INTO public.games VALUES (83, 1, 8);
INSERT INTO public.games VALUES (84, 1, 11);
INSERT INTO public.games VALUES (85, 1, 4);
INSERT INTO public.games VALUES (86, 34, 263);
INSERT INTO public.games VALUES (87, 35, 615);
INSERT INTO public.games VALUES (88, 34, 706);
INSERT INTO public.games VALUES (89, 34, 677);
INSERT INTO public.games VALUES (90, 34, 516);
INSERT INTO public.games VALUES (91, 36, 36);
INSERT INTO public.games VALUES (92, 37, 890);
INSERT INTO public.games VALUES (93, 36, 872);
INSERT INTO public.games VALUES (94, 36, 751);
INSERT INTO public.games VALUES (95, 36, 882);
INSERT INTO public.games VALUES (96, 38, 96);
INSERT INTO public.games VALUES (97, 39, 269);
INSERT INTO public.games VALUES (98, 38, 920);
INSERT INTO public.games VALUES (99, 38, 379);
INSERT INTO public.games VALUES (100, 38, 597);


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

INSERT INTO public.users VALUES (17, 'user_1744991313352', 1, 354);
INSERT INTO public.users VALUES (3, 'user_1744990703676', 0, 0);
INSERT INTO public.users VALUES (2, 'user_1744990703677', 0, 0);
INSERT INTO public.users VALUES (1, 'Jerrel', 4, 4);
INSERT INTO public.users VALUES (16, 'user_1744991313353', 4, 462);
INSERT INTO public.users VALUES (5, 'user_1744990978138', 1, 667);
INSERT INTO public.users VALUES (4, 'user_1744990978139', 4, 88);
INSERT INTO public.users VALUES (19, 'user_1744991341461', 1, 599);
INSERT INTO public.users VALUES (7, 'user_1744991045229', 1, 62);
INSERT INTO public.users VALUES (35, 'user_1744993044222', 1, 615);
INSERT INTO public.users VALUES (18, 'user_1744991341462', 4, 64);
INSERT INTO public.users VALUES (6, 'user_1744991045230', 4, 281);
INSERT INTO public.users VALUES (34, 'user_1744993044223', 4, 263);
INSERT INTO public.users VALUES (9, 'user_1744991083063', 1, 712);
INSERT INTO public.users VALUES (21, 'user_1744991355514', 1, 795);
INSERT INTO public.users VALUES (8, 'user_1744991083064', 4, 172);
INSERT INTO public.users VALUES (37, 'user_1744993165749', 1, 0);
INSERT INTO public.users VALUES (20, 'user_1744991355515', 4, 55);
INSERT INTO public.users VALUES (11, 'user_1744991098169', 1, 426);
INSERT INTO public.users VALUES (36, 'user_1744993165750', 4, 0);
INSERT INTO public.users VALUES (10, 'user_1744991098170', 4, 45);
INSERT INTO public.users VALUES (23, 'user_1744992839273', 1, 187);
INSERT INTO public.users VALUES (13, 'user_1744991123101', 1, 688);
INSERT INTO public.users VALUES (22, 'user_1744992839274', 4, 103);
INSERT INTO public.users VALUES (12, 'user_1744991123102', 4, 366);
INSERT INTO public.users VALUES (15, 'user_1744991144107', 1, 438);
INSERT INTO public.users VALUES (25, 'user_1744992877451', 1, 412);
INSERT INTO public.users VALUES (39, 'user_1744993197478', 1, 269);
INSERT INTO public.users VALUES (14, 'user_1744991144108', 4, 512);
INSERT INTO public.users VALUES (38, 'user_1744993197479', 4, 96);
INSERT INTO public.users VALUES (24, 'user_1744992877452', 4, 307);
INSERT INTO public.users VALUES (27, 'user_1744992889592', 1, 691);
INSERT INTO public.users VALUES (26, 'user_1744992889593', 4, 223);
INSERT INTO public.users VALUES (29, 'user_1744992904379', 1, 620);
INSERT INTO public.users VALUES (28, 'user_1744992904380', 4, 117);
INSERT INTO public.users VALUES (31, 'user_1744992920545', 1, 573);
INSERT INTO public.users VALUES (30, 'user_1744992920546', 4, 96);
INSERT INTO public.users VALUES (33, 'user_1744992932857', 1, 673);
INSERT INTO public.users VALUES (32, 'user_1744992932858', 4, 106);


--
-- Name: games_game_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.games_game_id_seq', 100, true);


--
-- Name: users_user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.users_user_id_seq', 39, true);


--
-- Name: games games_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.games
    ADD CONSTRAINT games_pkey PRIMARY KEY (game_id);


--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_pkey PRIMARY KEY (user_id);


--
-- Name: games user_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.games
    ADD CONSTRAINT user_id_fk FOREIGN KEY (user_id) REFERENCES public.users(user_id);


--
-- PostgreSQL database dump complete
--

Lastly, here is the CodeRoad (Tests) Output:

FAILED TEST LOG
  ✘ SUBTASKS 1.1 :8 Your script should print the correct welcome message for returning users

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

assert(re.test(scriptOutput))

at Context.<anonymous> (test/1.1.test.js:98:5)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  ✘ SUBTASKS 1.1 :16 You should submit your project while on the "main" branch of your repository with a clean working tree

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

assert(/On branch main\s/.test(commandOutput) && /working tree clean/.test(commandOutput))

at Context.<anonymous> (test/1.1.test.js:164:5)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Thank you to anyone that is willing or able to help!

I’ve simplified my code:

#!/bin/bash

# Set variable for database connection
PSQL="psql --username=freecodecamp --dbname=number_guess -t --tuples-only --no-align -c"

function GET_USER_INFO {

  # Prompt user to enter their username
  echo "Enter your username:"
  read USERNAME

  # Check if this username is in the users table
  USER_ID=$($PSQL "select user_id from users where username = '$USERNAME'")

  if [[ ! -z $USER_ID ]]
  then
    # THIS SECTION NEEDS ATTENTION -- FAILING THIS STEP
    # If the user is a returning user:
    GAMES_PLAYED=$($PSQL "select count(*) from games where user_id = $USER_ID" | sed 's/ //g' );
    BEST_GAME=$($PSQL "select min(total_guesses) from games where user_id = $USER_ID" | sed 's/ //g' );
    echo -e "\nWelcome back, $USERNAME! You have played $GAMES_PLAYED games, and your best game took $BEST_GAME guesses."
  else
    # If the username does not exist, add new user to the users table
    INSERT_NEW_USER=$($PSQL "insert into users (username) values ('$USERNAME')")
    echo -e "\nWelcome, $USERNAME! It looks like this is your first time here."
  fi
}

function PLAY_GAME {

  # Generate secret number to guess
  SECRET_NUMBER=$(( RANDOM % 1000 + 1 ))

  # Set variable to track user's total number of guesses for game
  TOTAL_GUESSES=0

  # Prompt user to enter their first guess
  echo -e "\nGuess the secret number between 1 and 1000:"
  read GUESS

  function COMPARE {
    # Verify that the user's guess is an integer
    if [[ ! $GUESS =~ ^-?[0-9]+$ ]]
    then
      # If the user's guess is not an integer
      echo -e "\nThat is not an integer, guess again:"
      read GUESS
      COMPARE
    else
      # If user's guess is lower than the secret number
      if [[ $GUESS -lt $SECRET_NUMBER ]]
      then
        TOTAL_GUESSES=$(( $TOTAL_GUESSES + 1 ))
        echo -e "\nIt's higher than that, guess again:"
        read GUESS
        COMPARE
      # If user's guess is higher than the secret number
      elif [[ $GUESS -gt $SECRET_NUMBER ]]
      then
        TOTAL_GUESSES=$(( $TOTAL_GUESSES + 1 ))
        echo -e "\nIt's lower than that, guess again:"
        read GUESS
        COMPARE
      else
        # If user's guess is correct, save game results to games table and exit
        TOTAL_GUESSES=$(( $TOTAL_GUESSES + 1 ))       
        INSERT_GAME_RESULTS=$($PSQL "insert into games (user_id, total_guesses) values ($USER_ID, $TOTAL_GUESSES)")
        echo "You guessed it in $TOTAL_GUESSES tries. The secret number was $SECRET_NUMBER. Nice job!"
        exit
      fi
    fi
  }

  COMPARE

}

GET_USER_INFO
PLAY_GAME

Additionally, I have altered my users table to drop the games_played and best_game columns. I have updated the script to extract that info properly, without those columns. However, I am still stuck on Step 8. My output is printing out the sentence correctly, with the right number of games and least amount of guesses, but I am not passing that step.

Updated SQL dump:

--
-- PostgreSQL database dump
--

-- Dumped from database version 12.17 (Ubuntu 12.17-1.pgdg22.04+1)
-- Dumped by pg_dump version 12.17 (Ubuntu 12.17-1.pgdg22.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 number_guess;
--
-- Name: number_guess; Type: DATABASE; Schema: -; Owner: freecodecamp
--

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


ALTER DATABASE number_guess OWNER TO freecodecamp;

\connect number_guess

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: games; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.games (
    game_id integer NOT NULL,
    user_id integer NOT NULL,
    total_guesses integer DEFAULT 0
);


ALTER TABLE public.games OWNER TO freecodecamp;

--
-- Name: games_game_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.games_game_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.games_game_id_seq OWNER TO freecodecamp;

--
-- Name: games_game_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.games_game_id_seq OWNED BY public.games.game_id;


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

CREATE TABLE public.users (
    user_id integer NOT NULL,
    username character varying(22) NOT NULL
);


ALTER TABLE public.users OWNER TO freecodecamp;

--
-- Name: users_user_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.users_user_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.users_user_id_seq OWNER TO freecodecamp;

--
-- Name: users_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.users_user_id_seq OWNED BY public.users.user_id;


--
-- Name: games game_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.games ALTER COLUMN game_id SET DEFAULT nextval('public.games_game_id_seq'::regclass);


--
-- Name: users user_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.users ALTER COLUMN user_id SET DEFAULT nextval('public.users_user_id_seq'::regclass);


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


INSERT INTO public.games VALUES (1, 1, 9);
INSERT INTO public.games VALUES (2, 1, 8);
INSERT INTO public.games VALUES (3, 1, 11);
INSERT INTO public.games VALUES (4, 1, 4);
INSERT INTO public.games VALUES (5, 2, 9);
INSERT INTO public.games VALUES (6, 1, 7);
INSERT INTO public.games VALUES (7, 2, 9);


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

INSERT INTO public.users VALUES (1, 'Jerrel');
INSERT INTO public.users VALUES (2, 'Kyler');


--
-- Name: games_game_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.games_game_id_seq', 8, true);


--
-- Name: users_user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.users_user_id_seq', 3, true);


--
-- Name: games games_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.games
    ADD CONSTRAINT games_pkey PRIMARY KEY (game_id);


--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_pkey PRIMARY KEY (user_id);


--
-- Name: games user_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.games
    ADD CONSTRAINT user_id_fk FOREIGN KEY (user_id) REFERENCES public.users(user_id);


--
-- PostgreSQL database dump complete
--


Welcome back to the forum @rel407

If $USER_ID does not exist, then how can your logic retrieve the user stats?

Happy coding

1 Like

:man_facepalming: Whoopsies.

Nice catch! I can’t believe I missed that. I wonder if I missed that in all the previous versions as well. All tests are passing now. Thank you for your help @Teller!

1 Like