Giriş
Açıklaması şöyle
ILIKE, a specific operator for PostgreSQL, has the same features as the LIKE operator but is case-insensitive. If special characters defined for the LIKE operator (% and _) are not found within the search text, ILIKE can be used as a case-insensitive equality operator. Although using it for equality checks is incorrect, ILIKE is the most suitable solution when case-insensitive pattern matching is desired.
ILIKE için Trigram Index lazım
Açıklaması şöyle
If we must support ILIKE substring search, the best immediate fix is a trigram index:
Şöyle yaparız.
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE INDEX idx_users_username_trgm
ON users
USING GIN (username gin_trgm_ops);Açıklaması şöyle
Why this worksTrigram indexes break strings into 3-character chunksThey allow PostgreSQL to index LIKE, ILIKE, and fuzzy searchesThey drastically reduce scan time for substring queries
Örnek
Şöyle yaparız.
SELECTDISTINCT(event_type)FROMstorm_eventsWHEREevent_type ILIKE '%winter%'
Örnek
Şöyle yaparız. İ
SELECT DISTINCT x.address ->> 'long_name' AS country_nameFROM (SELECT jsonb_array_elements(b.address) AS addressFROM brand bWHERE jsonb_typeof(b.address) = 'array' -- !!!) xWHERE x.address ->> 'types' ILIKE ANY (ARRAY['%country%'::text]);
Hiç yorum yok:
Yorum Gönder