-- 24_jsonb_indexing_gin.sql
-- Banking Pattern Pack — PostgreSQL
-- Purpose: GIN indexing and queries on KYC JSONB.
-- 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;

-- GIN index for JSONB containment
CREATE INDEX IF NOT EXISTS kyc_profile_gin ON bank.kyc_profiles USING gin (profile jsonb_path_ops);

-- Fast query by key/value
SELECT * FROM bank.kyc_profiles WHERE profile @> '{"pan":"ABCDE1234F"}';
