0
0
PostgreSQLquery~20 mins

Why PostgreSQL over other databases - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PostgreSQL Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why choose PostgreSQL for complex queries?

PostgreSQL is known for its advanced query capabilities. Which feature best explains why it handles complex queries better than many other databases?

AIt only supports simple SELECT statements without joins.
BIt supports window functions and common table expressions (CTEs) which simplify complex queries.
CIt lacks support for subqueries and nested queries.
DIt does not allow indexing on columns.
Attempts:
2 left
💡 Hint

Think about features that help break down and organize complex data retrieval.

query_result
intermediate
2:00remaining
What is the output of this PostgreSQL query?

Given the table employees(id, name, salary), what will this query return?

SELECT name FROM employees WHERE salary > 50000 ORDER BY salary DESC LIMIT 3;
PostgreSQL
CREATE TABLE employees (id INT, name TEXT, salary INT);
INSERT INTO employees VALUES (1, 'Alice', 60000), (2, 'Bob', 45000), (3, 'Carol', 70000), (4, 'Dave', 55000), (5, 'Eve', 50000);
ACarol, Alice, Dave
BAlice, Dave, Eve
CBob, Eve, Dave
DCarol, Bob, Alice
Attempts:
2 left
💡 Hint

Look for employees with salary above 50000, then order by salary descending and pick top 3.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this PostgreSQL query

Which option contains a syntax error in the PostgreSQL query?

SELECT * FROM users WHERE age => 30;
ASELECT * FROM users WHERE age => 30;
BSELECT * FROM users WHERE age >= 30;
CSELECT * FROM users WHERE age > 30;
DSELECT * FROM users WHERE age = 30;
Attempts:
2 left
💡 Hint

Check the comparison operator syntax carefully.

optimization
advanced
2:00remaining
Which indexing strategy improves query performance in PostgreSQL?

You have a large table with frequent queries filtering by a text column using pattern matching with LIKE 'abc%'. Which index type is best to speed up these queries?

ANo index, just rely on sequential scan
BA hash index on the text column
CA GIN index with trigram operators on the text column
DA B-tree index on the text column
Attempts:
2 left
💡 Hint

Think about indexes that support fast pattern matching.

🔧 Debug
expert
3:00remaining
Why does this PostgreSQL transaction cause a deadlock?

Two transactions run concurrently:

-- Transaction 1
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;
-- Transaction 2
BEGIN;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
COMMIT;

Why can this cause a deadlock?

ABecause the UPDATE statements have syntax errors.
BBecause PostgreSQL does not support transactions.
CBecause both transactions try to lock the same rows but in different order, causing a cycle.
DBecause the COMMIT statements are missing.
Attempts:
2 left
💡 Hint

Think about how locks are acquired on rows during updates.