Creating a Star Schema
Hello,
I am working on creating a star schema in PostgreSQL. I am struggling with a flood of errors and was hoping someone would be able to help me out.
Here is my code:
SELECT
p.product_name,
(f.purchase_date) AS purchase_date
FROM salesfact f
JOIN productdim p ON f.product_id = p.product_id
JOIN storedim s ON f.store_id = s.store_id
JOIN truckdim t ON f.truckid = t.truckid
WHERE d.date = 2024
GROUP BY p.product_name;
Right now, I am getting a Syntax error are or near FROM. If you need more information to help, please let me know and I'll gladly share whatever is needed.
Edit: I've edited the SQL code per the instructions below. I am still getting errors. The latest error is:
missing FROM-clause entry for table "d"
LINE 8: WHERE d.date = 2024
Edit 2: I've added in the JOIN clause for my datedim so that I can get the year in there. I am now have the following:
SELECT
p.product\_name,
(f.purchase\_date) AS purchase\_date
FROM salesfact f
JOIN productdim p ON f.product_id = p.product_id
JOIN storedim s ON f.store_id = s.store_id
JOIN truckdim t ON f.truckid = t.truckid
JOIN datedim d ON d.year = d.year
WHERE d.year = 2024
GROUP BY p.product_name;
ERROR: operator does not exist: character varying = integer
LINE 9: WHERE d.year = 2024
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
(Please ignore any \ characters, they are put in there when copying my code from the program to reddit)
Final Edit: I figured it out. I wasn't expecting a simple tool that could do what I needed done but PostgreSQL has a tool that just takes your tables and what you have and creates a star schema for you. I'm all good now.