在忽略 Vertica 中的重音的同时对查询结果进行排序

Sorting query result while ignoring accents in Vertica

我正在 运行 对 select Vertica 7.1 中 table 的内容进行一个相当简单的查询,我对最后的排序有疑问。你看,table 以法语显示各种健康服务……所以自然地我碰巧有一些重音字符。例如,假设我在 table 和 运行 之后立即写入的查询中有以下数据:

//This is some sample data

Électrocardiogramme
Radiographie
Anesthésie
Équipement divers
Massothérapie
Encéphalogramme

//This is the query I run
select * from myTable order by Description

这就是我目前的结果:

Anesthésie
Encéphalogramme
Massothérapie
Radiographie
Électrocardiogramme
Équipement divers

如您所见,重音字符以“É”全部出现在列表末尾的方式打乱了排序。现在我明白了这一切背后的逻辑,因为在 UTF-8 table "E" 和“É”中是两个不同的字符,所有重音字符在技术上都出现 "after" 普通字母,因此结果显示多于。

但是,就我而言,我希望结果以这种方式呈现:

Anesthésie
Électrocardiogramme
Encéphalogramme
Équipement divers
Massothérapie
Radiographie

基本上,我希望 Vertica 将带重音的字符视为其无重音的对应字符。有没有办法在不改变 table?

中包含的数据的情况下做到这一点

您希望更改 COLLATION for the sort order. Based on the descriptions, I'm assuming French. You can find the full list of choices for collation names or locales here

SELECT * FROM myTable ORDER BY COLLATION(Description,'FRA')

为了更好地订购它们,您可以使用以下功能:

-使用排序函数

COLLATION ( 'expression' [ , 'locale_or_collation_name' ] )

或(不太干净)

select * from table 
order by replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(Description, 'é', 'e'), 'è', 'e'),'ê', 'e'), 'ë', 'e'), 'è', 'e'), 'ï','i'), 'î', 'i'), 'ô', 'o'), 'œ','oe'), 'à', 'a'), 'â', 'a'), 'ù', 'u'), 'û', 'u'), 'ü', 'u'), 'ÿ', 'y'), 'É', 'E'), 'È', 'E'),'Ê', 'E'), 'Ë', 'E'), 'Ë', 'E'), 'Ï','I'), 'Î', 'I'), 'Ô', 'O'), 'Œ','OE'), 'À', 'A'), 'Â', 'A'), 'Ù', 'U'), 'Û', 'U'), 'Ü', 'U'), 'Ÿ', 'Y')
  • 这最终会完成这项工作,但您必须嵌入任何其他重音选项。