Welcome back, young data master! You have come a very long way. In Module 1, you learned what a database is. In Module 2, you learned how to install PostgreSQL and create databases. In Module 3, you learned about joins, subqueries, views, and normalization. In Module 4, you learned about performance tuning and optimization. In Module 5, you learned about security, backup, and replication.
In this final module, we are going to learn about advanced SQL and advanced PostgreSQL features. We will learn about window functions. Window functions let you calculate running totals and rankings. We will learn about Common Table Expressions (CTEs). CTEs make complex queries easier to read. We will learn about JSON and JSONB. These let you store flexible data. We will learn about full-text search. This lets you search text like a search engine. We will learn about stored procedures. These are reusable pieces of code that live in the database. We will learn about triggers. Triggers run automatically when something happens. We will also learn about extensions and custom types.
Do not worry if some words sound big. We will explain everything in simple language. We will use stories, examples from Nigeria, examples from school, and examples from home. We will use pictures made from keyboard characters (ASCII art) to help you see what we mean. By the end of this module, you will know:
This module is long because it is a complete chapter, not just short notes. Take your time. Read one lesson at a time. Do the exercises. Ask questions. Practice on your computer. Are you ready? Let us begin!
After finishing this module, you should be able to:
Chidi was a 13-year-old boy who lived in Enugu, Nigeria. His school had a big exam. The teacher wanted to rank all the students from highest to lowest.
The teacher had a database with all the scores. But she did not know how to rank the students. She asked Chidi for help. Chidi remembered his PostgreSQL lessons.
"We can use a window function," Chidi said. "It will rank the students automatically."
The teacher was surprised. "What is a window function?" she asked.
Chidi explained, "A window function looks at a set of rows and calculates something for each row. For example, RANK() will give each student a rank based on their score."
Chidi wrote the query. In seconds, all the students were ranked. The teacher was very happy.
Moral of the story: Window functions make complex calculations easy. Anyone can learn to use them.
A window function is a function that calculates something for each row, but it looks at a "window" of other rows at the same time. It does not group rows like GROUP BY. It keeps all rows.
Window functions help you calculate running totals, rankings, and moving averages. They are very powerful for reports and analysis.
Imagine you are in a race. You want to know your position. A window function looks at all the runners and tells you your rank. It does not remove any runners. It just adds the rank to each runner.
A bank uses window functions to rank customers by their account balance.
A school uses window functions to rank students by their scores.
At home, you use window functions to rank your favourite recipes by rating.
In a Nigerian market, a trader uses window functions to rank goods by sales.
WINDOW FUNCTION: +----+----------+-------+ | ID | NAME | SCORE | +----+----------+-------+ | 1 | CHIKA | 85 | | 2 | EMEKA | 90 | | 3 | NGOZI | 78 | +----+----------+-------+ RANK() OVER (ORDER BY SCORE DESC): +----+----------+-------+------+ | ID | NAME | SCORE | RANK | +----+----------+-------+------+ | 2 | EMEKA | 90 | 1 | | 1 | CHIKA | 85 | 2 | | 3 | NGOZI | 78 | 3 | +----+----------+-------+------+
A window function calculates something for each row while looking at other rows. It does not remove rows like GROUP BY.
You learned what a window function is. You saw examples from home, school, and Nigeria. Now you know that window functions are powerful for calculations.
ROW_NUMBER gives each row a unique number. RANK gives each row a rank. Ties get the same rank, and the next rank is skipped. DENSE_RANK gives each row a rank. Ties get the same rank, and the next rank is not skipped.
These functions help you rank data. You can use them to find the top students, top customers, or top sales.
Imagine you have three students: Chika (85), Emeka (90), and Ngozi (85). ROW_NUMBER gives them numbers 1, 2, 3. RANK gives Emeka 1, Chika 2, Ngozi 2. DENSE_RANK gives Emeka 1, Chika 2, Ngozi 2.
A bank uses RANK to rank customers by balance.
A school uses RANK to rank students by score.
At home, you use RANK to rank recipes by rating.
In a Nigerian market, a trader uses RANK to rank goods by sales.
SELECT name, score,
ROW_NUMBER() OVER (ORDER BY score DESC) AS row_num,
RANK() OVER (ORDER BY score DESC) AS rank,
DENSE_RANK() OVER (ORDER BY score DESC) AS dense_rank
FROM students;
ROW_NUMBER, RANK, DENSE_RANK: +----------+-------+----------+------+------------+ | NAME | SCORE | ROW_NUM | RANK | DENSE_RANK | +----------+-------+----------+------+------------+ | EMEKA | 90 | 1 | 1 | 1 | | CHIKA | 85 | 2 | 2 | 2 | | NGOZI | 85 | 3 | 2 | 2 | +----------+-------+----------+------+------------+
ROW_NUMBER gives unique numbers. RANK and DENSE_RANK give ranks. RANK skips numbers after ties. DENSE_RANK does not skip.
You learned about ROW_NUMBER, RANK, and DENSE_RANK. You saw examples from home, school, and Nigeria. Now you can rank your data.
You can use SUM, AVG, and COUNT as window functions. They calculate totals, averages, and counts for each row while looking at other rows.
These functions help you calculate running totals and moving averages. They are very useful for reports.
Imagine you are saving money every week. You want to know your running total. SUM as a window function adds up all the weeks up to the current week.
A bank uses SUM as a window function to calculate a customer's running balance.
A school uses AVG as a window function to calculate a student's average score.
At home, you use COUNT as a window function to count your recipes.
In a Nigerian market, a trader uses SUM as a window function to calculate running sales.
SELECT sale_date, amount,
SUM(amount) OVER (ORDER BY sale_date) AS running_total,
AVG(amount) OVER (ORDER BY sale_date) AS moving_average,
COUNT(*) OVER () AS total_sales
FROM sales;
WINDOW AGGREGATES: +------------+--------+--------------+----------------+ | SALE_DATE | AMOUNT | RUNNING_TOTAL| MOVING_AVERAGE | +------------+--------+--------------+----------------+ | 2025-01-01 | 100 | 100 | 100 | | 2025-01-02 | 200 | 300 | 150 | | 2025-01-03 | 150 | 450 | 150 | +------------+--------+--------------+----------------+
SUM, AVG, and COUNT can be used as window functions. They calculate running totals, moving averages, and counts.
You learned about window aggregates. You saw examples from home, school, and Nigeria. Now you can calculate running totals and moving averages.
A Common Table Expression (CTE) is a temporary result set that you can use in a query. You write it with the WITH keyword. It makes complex queries easier to read.
CTEs break complex queries into smaller, easier-to-understand parts. They make your SQL cleaner.
Imagine you are writing a long story. You break it into chapters. Each chapter is easier to read. A CTE is like a chapter in your query.
A bank uses a CTE to calculate customer balances step by step.
A school uses a CTE to calculate student averages step by step.
At home, you use a CTE to calculate recipe ratings step by step.
In a Nigerian market, a trader uses a CTE to calculate sales totals step by step.
WITH high_scorers AS (
SELECT name, score
FROM students
WHERE score > 80
)
SELECT * FROM high_scorers;
CTE:
WITH high_scorers AS (
SELECT name, score FROM students WHERE score > 80
)
SELECT * FROM high_scorers;
RESULT:
+----------+-------+
| NAME | SCORE |
+----------+-------+
| CHIKA | 85 |
| EMEKA | 90 |
+----------+-------+
A CTE is a temporary result set. You write it with the WITH keyword. It makes complex queries easier to read.
You learned what a CTE is. You saw examples from home, school, and Nigeria. Now you can use CTEs to simplify your queries.
A recursive CTE is a CTE that calls itself. It is used to work with hierarchical data, like family trees or organisation charts.
Recursive CTEs help you solve problems that repeat. They are very useful for trees and graphs.
Imagine you want to list all your ancestors. You start with your parents. Then you list their parents. Then you list their parents' parents. A recursive CTE does this automatically.
A bank uses a recursive CTE to show the management hierarchy.
A school uses a recursive CTE to show the class hierarchy.
At home, you use a recursive CTE to show your family tree.
In a Nigerian market, a trader uses a recursive CTE to show product categories.
WITH RECURSIVE family_tree AS (
SELECT id, name, parent_id
FROM family
WHERE parent_id IS NULL
UNION ALL
SELECT f.id, f.name, f.parent_id
FROM family f
INNER JOIN family_tree ft ON f.parent_id = ft.id
)
SELECT * FROM family_tree;
RECURSIVE CTE:
[ GRANDPARENT ]
|
V
[ PARENT ]
|
V
[ CHILD ]
|
V
[ GRANDCHILD ]
A recursive CTE calls itself. It is used for hierarchical data.
You learned about recursive CTEs. You saw examples from home, school, and Nigeria. Now you can work with hierarchical data.
JSON stands for JavaScript Object Notation. It is a way to store data in a flexible format. JSONB is a binary version of JSON. It is faster and supports indexing.
JSON lets you store data that does not fit neatly into tables. It is very useful for modern applications.
Imagine you have a box. You can put anything inside. JSON is like that box. You can store names, numbers, lists, and even other boxes.
A bank uses JSON to store customer preferences.
A school uses JSON to store student hobbies.
At home, you use JSON to store recipe ingredients.
In a Nigerian market, a trader uses JSON to store product details.
CREATE TABLE products (
id SERIAL PRIMARY KEY,
name VARCHAR(50),
details JSONB
);
INSERT INTO products (name, details)
VALUES ('Rice', '{"price": 5000, "quantity": 100, "tags": ["food", "grain"]}');
SELECT details->>'price' AS price FROM products WHERE name = 'Rice';
JSON:
{
"name": "Rice",
"price": 5000,
"quantity": 100,
"tags": ["food", "grain"]
}
JSON is a flexible way to store data. JSONB is faster and supports indexing.
You learned about JSON and JSONB. You saw examples from home, school, and Nigeria. Now you can store flexible data.
You can query JSON data using special operators. The -> operator gets a JSON object. The ->> operator gets a text value.
Querying JSON helps you find data inside flexible structures. You can filter, sort, and join JSON data.
Imagine you have a box with many items. You want to find one item. You open the box and take out the item. Querying JSON is like that.
A bank queries JSON to find customers with a specific preference.
A school queries JSON to find students with a specific hobby.
At home, you query JSON to find recipes with a specific ingredient.
In a Nigerian market, a trader queries JSON to find products with a specific tag.
-- Get a JSON object SELECT details->'tags' FROM products; -- Get a text value SELECT details->>'price' FROM products; -- Filter by JSON value SELECT * FROM products WHERE details->>'price' = '5000'; -- Find products with a specific tag SELECT * FROM products WHERE details->'tags' ? 'food';
QUERYING JSON:
[ PRODUCTS TABLE ]
|
V
[ USE -> AND ->> ]
|
V
[ FIND DATA INSIDE JSON ]
|
V
[ RESULTS SHOWN ]
You can query JSON data using -> and ->>. You can filter, sort, and join JSON data.
You learned how to query JSON data. You saw examples from home, school, and Nigeria. Now you can find data inside JSON.
Full-text search is a way to search text like a search engine. It finds documents that contain certain words or phrases.
Regular search (LIKE) is slow and simple. Full-text search is fast and powerful. It can handle large amounts of text.
Imagine you have a big book. You want to find all pages that mention "rice". You look at the index at the back. Full-text search is like that index.
A bank uses full-text search to find customer complaints about a specific topic.
A school uses full-text search to find exam questions about a specific topic.
At home, you use full-text search to find recipes that mention "chicken".
In a Nigerian market, a trader uses full-text search to find products that match a customer's request.
-- Create a search index
CREATE INDEX idx_products_search ON products
USING GIN (to_tsvector('english', name || ' ' || details->>'description'));
-- Search
SELECT * FROM products
WHERE to_tsvector('english', name || ' ' || details->>'description')
@@ to_tsquery('english', 'rice & food');
FULL-TEXT SEARCH:
[ DOCUMENTS ]
|
V
[ CREATE SEARCH INDEX ]
|
V
[ SEARCH WITH to_tsquery ]
|
V
[ FIND MATCHING DOCUMENTS ]
Full-text search searches text like a search engine. It is fast and powerful.
You learned about full-text search. You saw examples from home, school, and Nigeria. Now you can search text quickly.
A stored procedure is a piece of code that is saved in the database. You can call it by name. It can take inputs and return outputs.
Stored procedures save time. They make code reusable. They can also improve security and performance.
Imagine you have a recipe. You write it once. You can cook it many times. A stored procedure is like that recipe.
A bank uses a stored procedure to calculate interest for all accounts.
A school uses a stored procedure to calculate student averages.
At home, you use a stored procedure to convert measurements.
In a Nigerian market, a trader uses a stored procedure to calculate discounts.
CREATE PROCEDURE add_sale(
p_item VARCHAR,
p_price NUMERIC,
p_quantity INTEGER
)
LANGUAGE plpgsql
AS $$
BEGIN
INSERT INTO sales (item, price, quantity)
VALUES (p_item, p_price, p_quantity);
END;
$$;
-- Call the procedure
CALL add_sale('Rice', 5000, 2);
STORED PROCEDURE:
[ CREATE PROCEDURE ]
|
V
[ SAVE IN DATABASE ]
|
V
[ CALL PROCEDURE ]
|
V
[ PROCEDURE RUNS ]
A stored procedure is a piece of code saved in the database. You can call it by name.
You learned about stored procedures. You saw examples from home, school, and Nigeria. Now you can create and use stored procedures.
A trigger is a piece of code that runs automatically when something happens. For example, when a row is inserted, updated, or deleted.
Triggers help you automate tasks. You can use them to keep data accurate.
Imagine you have a doorbell. When someone presses it, it rings. A trigger is like that doorbell. When something happens, it runs.
A bank uses a trigger to update a customer's balance when a transaction is added.
A school uses a trigger to update a student's average when a score is added.
At home, you use a trigger to update a recipe's rating when someone rates it.
In a Nigerian market, a trader uses a trigger to update stock when a sale is made.
CREATE FUNCTION update_stock()
RETURNS TRIGGER AS $$
BEGIN
UPDATE products
SET quantity = quantity - NEW.quantity
WHERE id = NEW.product_id;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER after_sale
AFTER INSERT ON sales
FOR EACH ROW
EXECUTE FUNCTION update_stock();
TRIGGER:
[ INSERT INTO SALES ]
|
V
[ TRIGGER RUNS AUTOMATICALLY ]
|
V
[ UPDATE PRODUCT STOCK ]
|
V
[ DATA IS ACCURATE ]
A trigger is a piece of code that runs automatically when something happens. It helps you automate tasks.
You learned about triggers. You saw examples from home, school, and Nigeria. Now you can create and use triggers.
An extension is a package that adds new features to PostgreSQL. You can install extensions to get new functions, data types, and tools.
Extensions let you do more with PostgreSQL. They save you from writing code from scratch.
Imagine you have a phone. You install apps to add new features. Extensions are like apps for PostgreSQL.
A bank uses the pg_stat_statements extension to monitor queries.
A school uses the PostGIS extension to store location data.
At home, you use the pg_trgm extension to search text quickly.
In a Nigerian bank, the pgcrypto extension is used to encrypt data.
-- List available extensions SELECT * FROM pg_available_extensions; -- Install an extension CREATE EXTENSION pg_stat_statements; -- Use the extension SELECT * FROM pg_stat_statements LIMIT 5;
EXTENSIONS:
[ POSTGRESQL ]
|
V
[ INSTALL EXTENSION ]
|
V
[ NEW FEATURES AVAILABLE ]
|
V
[ USE NEW FEATURES ]
An extension adds new features to PostgreSQL. You can install extensions to get new functions and tools.
You learned about extensions. You saw examples from home, school, and Nigeria. Now you can install and use extensions.
A custom type is a data type that you create yourself. You can use it to store complex data.
Custom types let you model your data exactly. They make your database more expressive.
Imagine you have a box of LEGO bricks. You can build anything you want. Custom types are like building your own LEGO bricks.
A bank uses a custom type to store addresses.
A school uses a custom type to store student names.
At home, you use a custom type to store recipe measurements.
In a Nigerian market, a trader uses a custom type to store product prices.
-- Create a custom type
CREATE TYPE address AS (
street VARCHAR,
city VARCHAR,
state VARCHAR,
zip_code VARCHAR
);
-- Use the custom type
CREATE TABLE customers (
id SERIAL PRIMARY KEY,
name VARCHAR(50),
home_address address
);
INSERT INTO customers (name, home_address)
VALUES ('Chika', ROW('123 Main St', 'Lagos', 'Lagos', '100001'));
CUSTOM TYPE:
[ CREATE TYPE address ]
|
V
[ SAVE IN DATABASE ]
|
V
[ USE address IN TABLE ]
|
V
[ STORE COMPLEX DATA ]
A custom type is a data type that you create yourself. You can use it to store complex data.
You learned about custom types. You saw examples from home, school, and Nigeria. Now you can create and use custom types.
Putting it all together means using all your advanced SQL skills. It means building powerful queries and applications.
A complete database uses many features. Putting it all together makes your database powerful.
Imagine you are building a house. You need bricks, cement, and wood. Putting it all together means building the house. In the same way, you build a powerful database with advanced SQL.
A bank puts it all together. It uses window functions, CTEs, JSON, and triggers.
A school puts it all together. It uses window functions, CTEs, and stored procedures.
At home, you put it all together. You use window functions, CTEs, and JSON.
In a Nigerian market, a trader puts it all together. The trader uses window functions, CTEs, and triggers.
PUTTING IT ALL TOGETHER:
[ WINDOW FUNCTIONS ]
|
V
[ CTEs ]
|
V
[ JSON AND JSONB ]
|
V
[ FULL-TEXT SEARCH ]
|
V
[ STORED PROCEDURES ]
|
V
[ TRIGGERS ]
|
V
[ EXTENSIONS AND CUSTOM TYPES ]
|
V
[ POWERFUL DATABASE! ๐ ]
Putting it all together means using all your advanced SQL skills. It makes your database powerful.
You learned how to put everything together. You saw examples from home, school, and Nigeria. Now you can build powerful databases.
Best practices are the best ways to do things. They help you write clean, efficient, and correct SQL.
Following best practices makes your code easier to read. It makes your queries faster. It reduces errors.
Imagine you are writing a letter. You use neat handwriting. You use correct spelling. Best practices in SQL are like neat handwriting and correct spelling.
A bank follows best practices. Queries are fast and accurate.
A school follows best practices. Data is clean and organised.
At home, you follow best practices. Your recipes are easy to find.
In a Nigerian market, a trader follows best practices. Sales records are accurate.
BEST PRACTICES FOR ADVANCED SQL:
[ MEANINGFUL NAMES ] --> [ USE CTEs ]
| |
V V
[ WINDOW FUNCTIONS ] --> [ USE JSONB ]
| |
V V
[ FULL-TEXT INDEXES ] --> [ STORED PROCEDURES ]
| |
V V
[ USE TRIGGERS CAREFULLY ] --> [ INSTALL NEEDED EXTENSIONS ]
| |
V V
[ USE CUSTOM TYPES ] --> [ TEST QUERIES ]
| |
V V
[ CLEAN, FAST, ACCURATE DATABASE ]
Best practices help you write clean, efficient, and correct SQL.
You learned best practices for advanced SQL. You saw a list of practices. Now you can write better SQL.
Your future as a PostgreSQL expert is full of possibilities. You can work as a database administrator, a data analyst, a developer, or a consultant.
You have learned a lot. Now you can use your skills to help people and build a career.
Imagine you have a map. The map shows many roads. You can choose which road to take. Your future as a PostgreSQL expert is like that. You can choose your path.
A PostgreSQL expert works for a bank. They design and maintain databases.
A PostgreSQL expert works for a school. They manage student data.
A PostgreSQL expert works from home. They help small businesses with their databases.
In Lagos, a PostgreSQL expert starts a company. They help banks, schools, and government offices with their databases.
| Career | What You Do | Where You Work |
|---|---|---|
| Database administrator | Install, configure, and maintain databases | Companies and government |
| Data analyst | Analyze data and create reports | Businesses and research |
| Database developer | Write queries and build database applications | Software companies |
| Database consultant | Advise companies on database design and performance | Consulting firms |
| Database trainer | Teach others about PostgreSQL | Schools and training centers |
| Database architect | Design large, complex database systems | Large organisations |
YOUR FUTURE:
[ FINISH COURSE ]
|
V
[ CHOOSE YOUR PATH ]
|
+------+------+------+------+------+
| | | | | |
V V V V V V
[ DBA ] [ ANALYST ] [ DEV ] [ CONSULTANT ] [ TRAINER ] [ ARCHITECT ]
| | | | | |
V V V V V V
[ HELP PEOPLE AND BUILD A CAREER ]
|
V
[ SUCCESS ๐ ]
Your future as a PostgreSQL expert is full of possibilities. You can choose from many career paths.
You learned about your future as a PostgreSQL expert. You saw a table of career paths. Now you know the many paths you can take.
| Word | Simple Definition |
|---|---|
| Window function | A function that calculates something for each row while looking at other rows. |
| ROW_NUMBER | A window function that gives each row a unique number. |
| RANK | A window function that gives each row a rank. Ties get the same rank, and the next rank is skipped. |
| DENSE_RANK | A window function that gives each row a rank. Ties get the same rank, and the next rank is not skipped. |
| CTE | Common Table Expression. A temporary result set used in a query. |
| Recursive CTE | A CTE that calls itself. Used for hierarchical data. |
| JSON | A flexible way to store data. |
| JSONB | A binary version of JSON. Faster and supports indexing. |
| Full-text search | A way to search text like a search engine. |
| Stored procedure | A piece of code saved in the database. |
| Trigger | A piece of code that runs automatically when something happens. |
| Extension | A package that adds new features to PostgreSQL. |
| Custom type | A data type that you create yourself. |
ADVANCED SQL
|
+---- WINDOW FUNCTIONS
|
+---- CTEs
|
+---- JSON AND JSONB
|
+---- FULL-TEXT SEARCH
|
+---- STORED PROCEDURES
|
+---- TRIGGERS
|
+---- EXTENSIONS AND CUSTOM TYPES
Step 1: Learn what a window function is. Step 2: Learn ROW_NUMBER, RANK, and DENSE_RANK. Step 3: Learn SUM, AVG, and COUNT as window functions. Step 4: Learn what a CTE is. Step 5: Learn recursive CTEs. Step 6: Learn what JSON and JSONB are. Step 7: Learn to query JSON data. Step 8: Learn what full-text search is. Step 9: Learn what a stored procedure is. Step 10: Learn what a trigger is. Step 11: Learn what extensions are. Step 12: Learn what custom types are. Step 13: Put it all together. Step 14: Learn best practices. Step 15: Plan your future.
WINDOW FUNCTION: +----+----------+-------+ | ID | NAME | SCORE | +----+----------+-------+ | 1 | CHIKA | 85 | | 2 | EMEKA | 90 | | 3 | NGOZI | 78 | +----+----------+-------+ RANK() OVER (ORDER BY SCORE DESC): +----+----------+-------+------+ | ID | NAME | SCORE | RANK | +----+----------+-------+------+ | 2 | EMEKA | 90 | 1 | | 1 | CHIKA | 85 | 2 | | 3 | NGOZI | 78 | 3 | +----+----------+-------+------+
| Feature | What It Does |
|---|---|
| Window functions | Calculate something for each row while looking at other rows |
| CTEs | Temporary result sets that make queries easier to read |
| JSON and JSONB | Store flexible data |
| Full-text search | Search text like a search engine |
| Stored procedures | Reusable pieces of code saved in the database |
| Triggers | Code that runs automatically when something happens |
| Extensions | Packages that add new features |
| Custom types | Data types that you create yourself |
| Feature | JSON | JSONB |
|---|---|---|
| Storage | Text | Binary |
| Speed | Slower | Faster |
| Indexing | Limited | Full support |
| Use case | Simple storage | Querying and indexing |
In this module, you learned about advanced SQL and PostgreSQL features. You learned about window functions. They calculate something for each row while looking at other rows. You learned about ROW_NUMBER, RANK, and DENSE_RANK. They help you rank data. You learned about SUM, AVG, and COUNT as window functions. They calculate running totals and moving averages.
You learned about Common Table Expressions (CTEs). They are temporary result sets that make queries easier to read. You learned about recursive CTEs. They call themselves and are used for hierarchical data. You learned about JSON and JSONB. They store flexible data. JSONB is faster and supports indexing. You learned how to query JSON data using -> and ->>.
You learned about full-text search. It searches text like a search engine. You learned about stored procedures. They are reusable pieces of code saved in the database. You learned about triggers. They run automatically when something happens. You learned about extensions. They add new features to PostgreSQL. You learned about custom types. They let you model your data exactly.
You learned how to put it all together. You learned best practices for advanced SQL. You learned about your future as a PostgreSQL expert.
Congratulations! You have finished the entire Certified PostgreSQL Expert course. You have learned so much. You are ready to build powerful databases and solve real problems. But remember: learning never stops. Keep practicing. Keep learning. Keep teaching others. You are now a Certified PostgreSQL Expert!
Match the word in Column A with the correct definition in Column B.
| Column A | Column B |
|---|---|
| 1. Window function | A. A temporary result set used in a query |
| 2. CTE | B. A flexible way to store data |
| 3. JSON | C. A function that calculates something for each row while looking at other rows |
| 4. Full-text search | D. A piece of code saved in the database |
| 5. Stored procedure | E. A way to search text like a search engine |
| 6. Trigger | F. A package that adds new features to PostgreSQL |
| 7. Extension | G. A piece of code that runs automatically when something happens |
| 8. Custom type | H. A data type that you create yourself |
Answers: 1-C, 2-A, 3-B, 4-E, 5-D, 6-G, 7-F, 8-H
Title: Design a School Database with Advanced Features
Instructions: In groups of 3 or 4, design a school database.
Use window functions to rank students. Use CTEs to calculate averages.
Use JSON to store student hobbies. Use a stored procedure to add scores.
Use a trigger to update averages. Present your design to the class.
Example:
Tables: students, scores, hobbies.
Window function: RANK() OVER (ORDER BY score DESC).
CTE: WITH avg_scores AS (SELECT student_id, AVG(score) FROM scores GROUP BY student_id).
JSON: hobbies JSONB.
Stored procedure: add_score(student_id, score).
Trigger: after INSERT ON scores, update student average.
Title: My Advanced SQL Plan
Instructions: Write a short plan for using advanced SQL features.
List at least 5 features you will use. Explain why each one is useful.
Example:
1. Use window functions to rank data.
2. Use CTEs to simplify complex queries.
3. Use JSONB to store flexible data.
4. Use full-text search to find text quickly.
5. Use stored procedures to reuse code.
Title: Build a Shop Database with Advanced Features
Materials: Computer with PostgreSQL installed.
Steps:
Assignment: For one week, practice using advanced SQL features. Keep a diary. Each day, write down:
At the end of the week, write a short report. Share it with your teacher or parent.
Congratulations! You have finished all six modules of the Certified PostgreSQL Expert course. You have learned so much:
You are now a Certified PostgreSQL Expert. You can design, build, and maintain powerful databases. You can solve real problems. You can help people and businesses. You can build a career in database administration, data analysis, development, consulting, or training.
But remember: learning never stops. Technology is always changing. Keep practicing. Keep learning. Keep teaching others. Stay curious. Stay kind. Stay safe.
You are now a Certified PostgreSQL Expert. Congratulations! ๐
End of Module 6. End of Course.