我的locations
表格带有city
属性。这些是波兰城市名称,所以它可以是Łódź,Gdańsk等(带有非ascii字符的名字)。
如何搜索这些会给我这样结果的字段:
search_term => city
'Lodz' => 'Łódź'
'gdansk' => 'Gdańsk'
'Łodz' => 'Łódź'
答案 0 :(得分:1)
您可以使用translate()
,例如:
create or replace function lower_pl(text)
returns text language sql immutable as $$
select translate(lower($1), 'ąćęłńóśźż', 'acelnoszz')
$$;
测试:
create table cities (name text);
insert into cities values
('Łódź'), ('Gdańsk');
select *
from cities
where lower_pl(name) = lower_pl('Łodz');
name
------
Łódź
(1 row)