Bird
0
0

You attempt to create this partial index:

medium📝 Debug Q6 of 15
PostgreSQL - Indexing Strategies
You attempt to create this partial index:
CREATE INDEX idx_high_salary ON employees (salary) WHERE salary > 50000;
But PostgreSQL returns an error. What is the most probable reason?
AThe <code>WHERE</code> clause references the indexed column, which is not allowed
BThe index name conflicts with an existing table name
CThe <code>WHERE</code> clause uses a non-immutable function or expression
DPartial indexes cannot use comparison operators in the <code>WHERE</code> clause
Step-by-Step Solution
Solution:
  1. Step 1: Understand partial index restrictions

    PostgreSQL requires the WHERE clause to be immutable and deterministic.
  2. Step 2: Analyze the expression

    Using a constant comparison like salary > 50000 is allowed, but if the expression involved non-immutable functions, it would cause errors.
  3. Step 3: Consider error causes

    If the error occurs, it is likely due to a non-immutable function or expression in the WHERE clause.
  4. Final Answer:

    The WHERE clause uses a non-immutable function or expression -> Option C
  5. Quick Check:

    Partial index WHERE clause must be immutable [OK]
Quick Trick: WHERE clause must be immutable and deterministic [OK]
Common Mistakes:
  • Assuming indexed column cannot appear in WHERE clause
  • Ignoring immutability requirement
  • Confusing index name conflicts with errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes