Introduction
Expression indexes help speed up searches on calculated or transformed data without storing extra columns.
Jump into concepts and practice - no test required
CREATE INDEX index_name ON table_name ((expression));
CREATE INDEX idx_lower_name ON users ((lower(name)));
CREATE INDEX idx_first_letter ON products ((substring(name from 1 for 1)));
CREATE INDEX idx_price_plus_tax ON items ((price * 1.1));
CREATE TABLE employees (id SERIAL PRIMARY KEY, fullname TEXT); INSERT INTO employees (fullname) VALUES ('Alice Johnson'), ('Bob Smith'), ('alice cooper'); CREATE INDEX idx_lower_fullname ON employees ((lower(fullname))); -- Query using the expression index SELECT * FROM employees WHERE lower(fullname) = 'alice johnson';
expression index in PostgreSQL?username column in PostgreSQL?products(id INT, price NUMERIC) and the index:CREATE INDEX idx_discounted_price ON products ((price * 0.9));SELECT * FROM products WHERE price * 0.9 < 100;CREATE INDEX idx_expr ON sales (price * discount);city column in a locations table. Which expression index will best help?CREATE INDEX idx_city_prefix ON locations (???);