-- 26_trigram_search_names.sql
-- Banking Pattern Pack — PostgreSQL
-- Purpose: Fuzzy search for customer names (pg_trgm).
-- Context: Retail bank example with customers, accounts, transactions, cards, loans.
-- Date: 2025-08-18
-- Notes:
--   * Safe to read; run on a development DB.
--   * Requires: CREATE privileges; some files may need superuser for extensions.
--   * Search path set to 'bank' schema for clarity.
SET search_path = bank, public;

-- Fuzzy name search
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE INDEX IF NOT EXISTS customers_name_trgm ON bank.customers USING gin (full_name gin_trgm_ops);

-- Example query
SELECT * FROM bank.customers WHERE similarity(full_name, 'Asha Mehta') > 0.3 ORDER BY similarity(full_name, 'Asha Mehta') DESC;
