Index only rows that match a predicate.
Section: Create and use indexes
Create a partial index
sql
sql
CREATE INDEX idx_sessions_active ON sessions(user_id)
WHERE revoked_at IS NULL;Explanation
Partial indexes can be smaller and more selective than indexing the entire table.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Create and use indexes