0
0
PostgreSQLquery~10 mins

Partial indexes with WHERE clause in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a partial index on the "users" table for active users only.

PostgreSQL
CREATE INDEX idx_active_users ON users (last_login) WHERE [1];
Drag options to blanks, or click blank then click option'
Aage > 18
Bstatus = 'active'
Clast_login IS NOT NULL
Dcountry = 'US'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a condition unrelated to active users.
Omitting the WHERE clause for partial index.
2fill in blank
medium

Complete the code to create a partial index on the "orders" table for orders with status 'pending'.

PostgreSQL
CREATE INDEX idx_pending_orders ON orders (order_date) WHERE [1];
Drag options to blanks, or click blank then click option'
Astatus = 'pending'
Bstatus = 'shipped'
Camount > 100
Dcustomer_id IS NOT NULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'shipped' instead of 'pending' in the WHERE clause.
Indexing all orders without a WHERE clause.
3fill in blank
hard

Fix the error in the partial index creation for the "products" table to index only discontinued products.

PostgreSQL
CREATE INDEX idx_discontinued_products ON products (product_name) WHERE [1];
Drag options to blanks, or click blank then click option'
Adiscontinued = TRUE
Bdiscontinued = 'yes'
Cdiscontinued IS NULL
Ddiscontinued = FALSE
Attempts:
3 left
💡 Hint
Common Mistakes
Using string 'yes' instead of boolean TRUE.
Indexing products that are not discontinued.
4fill in blank
hard

Fill both blanks to create a partial index on the "employees" table for employees in the 'Sales' department with active status.

PostgreSQL
CREATE INDEX idx_active_sales ON employees (employee_id) WHERE [1] AND [2];
Drag options to blanks, or click blank then click option'
Adepartment = 'Sales'
Bstatus = 'active'
Cstatus = 'inactive'
Ddepartment = 'HR'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'HR' instead of 'Sales' for department.
Using 'inactive' instead of 'active' for status.
5fill in blank
hard

Fill all three blanks to create a partial index on the "tickets" table for open tickets assigned to user 'john_doe' with priority higher than 3.

PostgreSQL
CREATE INDEX idx_open_high_priority ON tickets (ticket_id) WHERE [1] AND [2] AND [3];
Drag options to blanks, or click blank then click option'
Astatus = 'open'
Bassigned_to = 'john_doe'
Cpriority > 3
Dpriority < 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'closed' instead of 'open' for status.
Using priority less than 3 instead of greater than 3.
Wrong assigned user name.