PostgreSQL: 大文字と小文字を区別しない文字列比較 質問する

PostgreSQL: 大文字と小文字を区別しない文字列比較 質問する

PostgreSQL には、大文字と小文字を区別しない単純な比較機能はありますか?

交換したいもの:

SELECT id, user_name 
    FROM users 
        WHERE lower(email) IN (lower('[email protected]'), lower('[email protected]'));

たとえば次のようになります:

SELECT id, user_name 
    FROM users 
        WHERE email IGNORE_CASE_IN ('[email protected]', '[email protected]');

and演算子likeilike単一の値 (例) では機能しますが、セットでは機能しません。like '[email protected]'

ベストアンサー1

select * 
where email ilike '[email protected]'

ilikeは、大文字と小文字を区別しませlikeん。エスケープ文字には、replace()

where email ilike replace(replace(replace($1, '~', '~~'), '%', '~%'), '_', '~_') escape '~'

または、テキストをエスケープする関数を作成することもできます。テキストの配列の場合は、

where email ilike any(array['[email protected]', '[email protected]'])

おすすめ記事